goog.testing.messaging.MockMessageChannel
Provided By | |
---|---|
Extends | |
All Implemented Interfaces |
Class for unit-testing code that communicates over a MessageChannel.
new MockMessageChannel( mockControl )
Parameters |
|
---|
Instance Methods
this.addOnDisposeCallback<T>( callback, opt_scope ) → void
void
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added. If a callback is added to an already disposed Disposable, it will be called immediately.
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.connect( opt_connectCb ) → void
void
Initiates the channel connection. When this method is called, all the information needed to connect the channel has to be available.
Implementers should only require this method to be called if the channel needs to be configured in some way between when it's created and when it becomes active. Otherwise, the channel should be immediately active and this method should do nothing but immediately call opt_connectCb.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
|
Converts the message payload into the format expected by the registered service (either JSON or string).
Defined by | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||||||
Returns |
|
this.deliver( serviceName, payload ) → void
void
Delivers a message to the appropriate service. This is meant to be called by subclasses when they receive messages.
This method takes into account both explicitly-registered and default services, as well as making sure that JSON payloads are decoded when necessary. If the subclass is capable of passing objects as payloads, those objects can be passed in to this method directly. Otherwise, the (potentially JSON-encoded) strings should be passed in.
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.dispose() → ?
?
Sets a flag indicating that this is disposed.
Overrides | ||
---|---|---|
Specified by | ||
Parameters | None. | |
Returns |
|
this.disposeInternal() → void
void
Performs appropriate cleanup. See description of goog.disposable.IDisposable
for examples. Classes that extend goog.Disposable
should override this
method. Not reentrant. To avoid calling it twice, it must only be called from
the subclass' disposeInternal
method. Everywhere else the public dispose
method must be used. For example:
mypackage.MyClass = function() { mypackage.MyClass.base(this, 'constructor'); // Constructor logic specific to MyClass. ... }; goog.inherits(mypackage.MyClass, goog.Disposable); mypackage.MyClass.prototype.disposeInternal = function() { // Dispose logic specific to MyClass. ... // Call superclass's disposeInternal at the end of the subclass's, like // in C++, to avoid hard-to-catch issues. mypackage.MyClass.base(this, 'disposeInternal'); };
Defined by | |
---|---|
Overrides | |
Parameters | None. |
this.getDisposed() → boolean
boolean
warning Deprecated | Use |
---|
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
Find the service object for a given service name. If there's no service explicitly registered, but there is a default service, a service object is constructed for it.
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
| ||||||||
Returns |
|
this.isConnected() → boolean
boolean
Gets whether the channel is connected.
If #connect
is not required for this class, this should always return
true. Otherwise, this should return true by the time the callback passed to
#connect
has been called and always after that.
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.isDisposed() → boolean
boolean
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.receive( serviceName, payload ) → void
void
this.registerDefaultService( callback ) → void
void
Registers a service to be called when a message is received that doesn't match any other services.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
|
this.registerDisposable( disposable ) → void
void
Associates a disposable object with this object so that they will be disposed together.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.registerService( serviceName, callback, opt_objectPayload ) → void
void
Registers a service to be called when a message is received.
Implementers shouldn't impose any restrictions on the service names that may
be registered. If some services are needed as control codes,
goog.messaging.MultiMessageChannel
can be used to safely split the
channel into "public" and "control" virtual channels.
Overrides | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||
Parameters |
|
this.send( serviceName, payload ) → void
void
A mock send function. Actually an instance of
goog.testing.FunctionMock
.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||
Parameters |
|
Instance Properties
this.creationStack → (string|undefined)
(string|undefined)
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
this.disposed → boolean
boolean
Whether the channel has been disposed.
this.logger → (goog.log.Logger|null)
(goog.log.Logger|null)
Logger for this class.