goog.testing.net.XhrIo
Provided By | |
---|---|
Extends | |
All Implemented Interfaces |
Mock implementation of goog.net.XhrIo. This doesn't provide a mock implementation for all cases, but it's not too hard to add them as needed.
new XhrIo( opt_testQueue )
Parameters |
|
---|
Instance Methods
this.abort( opt_failureCode ) → void
void
Abort the current XMLHttpRequest
Overrides | |||||
---|---|---|---|---|---|
Parameters |
|
this.addEventListener( type, handler, opt_capture, opt_handlerScope ) → void
void
Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched.
warning Deprecated | Use |
---|
Defined by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
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.createXhr() → (goog.net.XhrLike|XMLHttpRequest)
(goog.net.XhrLike|XMLHttpRequest)
Creates a new XHR object.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.dispatchEvent( e ) → boolean
boolean
Dispatches an event (or event like object) and calls all listeners listening for events of this type. The type of the event is decided by the type property on the event object.
If any of the listeners returns false OR calls preventDefault then this function will return false. If one of the capture listeners calls stopPropagation, then the bubble listeners won't fire.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
this.dispose() → ?
?
Disposes of the object and its resources.
Overrides | ||
---|---|---|
Specified by | ||
Parameters | None. | |
Returns |
|
this.disposeInternal() → void
void
Nullifies all callbacks to reduce risks of leaks.
Defined by | |
---|---|
Overrides | |
Parameters | None. |
this.fireListeners<EVENTOBJ>( type, capture, eventObject ) → boolean
boolean
Fires all registered listeners in this listenable for the given type and capture mode, passing them the given eventObject. This does not perform actual capture/bubble. Only implementors of the interface should be using this.
Overrides | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||
Parameters |
| ||||||||||||
Returns |
|
this.getAllResponseHeaders() → string
string
Gets the text of all the headers in the response. Will only return correct result when called from the context of a callback and the request has completed
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getAllStreamingResponseHeaders() → string
string
Gets the text of all the headers in the response. As opposed to
#getAllResponseHeaders
, this method does not require that the request
has completed.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getDisposed() → boolean
boolean
warning Deprecated | Use |
---|
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getLastContent() → (ArrayBuffer|ArrayBufferView|Blob|Document|FormData|string|null|undefined)
(ArrayBuffer|ArrayBufferView|Blob|Document|FormData|string|null|undefined)
Gets the last POST content that was requested.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getLastError() → string
string
Get the last error message
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getLastErrorCode() → goog.net.ErrorCode
goog.net.ErrorCode
Gets the last error message.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getLastMethod() → (string|undefined)
(string|undefined)
Gets the last HTTP method that was requested.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getLastRequestHeaders() → (Object|null|undefined)
(Object|null|undefined)
Gets the headers of the last request.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getLastUri() → string
string
Gets the last URI that was requested.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getListener<SCOPE, EVENTOBJ>( type, listener, capture, opt_listenerScope ) → (goog.events.ListenableKey|null)
(goog.events.ListenableKey|null)
Gets the goog.events.ListenableKey for the event or null if no such listener is in use.
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.getListeners<EVENTOBJ>( type, capture ) → Array<goog.events.ListenableKey>
Array<goog.events.ListenableKey>
Gets all listeners in this listenable for the given type and capture mode.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||
Parameters |
| ||||||||
Returns |
|
this.getParentEventTarget() → (goog.events.Listenable|null)
(goog.events.Listenable|null)
Returns the parent of this event target to use for capture/bubble mechanism.
NOTE(chrishenry): The name reflects the original implementation of
custom event target (goog.events.EventTarget
). We decided
that changing the name is not worth it.
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.getProgressEventsEnabled() → boolean
boolean
Gets whether progress events are enabled.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getReadyState() → goog.net.XmlHttp.ReadyState
goog.net.XmlHttp.ReadyState
Returns the readystate.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getResponse() → *
*
Get the response as the type specificed by #setResponseType
. At time
of writing, this is only supported in very recent versions of WebKit
(10.0.612.1 dev and later).
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getResponseBody() → (Object|null)
(Object|null)
Gets the response body from the Xhr object. Will only return correct result when called from the context of a callback.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getResponseHeader( key ) → (string|undefined)
(string|undefined)
Get the value of the response-header with the given name from the Xhr object Will only return correct result when called from the context of a callback and the request has completed
Overrides | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
Returns all response headers as a key-value map. Multiple values for the same header key can be combined into one, separated by a comma and a space. Note that the native getResponseHeader method for retrieving a single header does a case insensitive match on the header name. This method does not include any case normalization logic, it will just return a key-value representation of the headers. See: http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getResponseJson( opt_xssiPrefix ) → (Object|undefined)
(Object|undefined)
Gets the response and evaluates it as JSON from the Xhr object. Will only return correct result when called from the context of a callback.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
| ||||
Throws |
|
this.getResponseText() → string
string
Gets the response text from the Xhr object. Will only return correct result when called from the context of a callback.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getResponseType() → goog.net.XhrIo.ResponseType
goog.net.XhrIo.ResponseType
Gets the desired type for the response.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getResponseXml() → (Document|null)
(Document|null)
Gets the response XML from the Xhr object. Will only return correct result when called from the context of a callback.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getStatus() → number
number
Get the status from the Xhr object. Will only return correct result when called from the context of a callback.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getStatusText() → string
string
Get the status text from the Xhr object. Will only return correct result when called from the context of a callback.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getStreamingResponseHeader( key ) → (string|null)
(string|null)
Get the value of the response-header with the given name from the Xhr object.
As opposed to #getResponseHeader
, this method does not require that
the request has completed.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
| ||||
Returns |
|
this.getTimeoutInterval() → number
number
Returns the number of milliseconds after which an incomplete request will be aborted, or 0 if no timeout is set.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getWithCredentials() → boolean
boolean
Gets whether a "credentialed" request is to be sent.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.hasListener<EVENTOBJ>( opt_type, opt_capture ) → boolean
boolean
Whether there is any active listeners matching the specified signature. If either the type or capture parameters are unspecified, the function will match on the remaining criteria.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||
Parameters |
| ||||||||
Returns |
|
this.isActive() → boolean
boolean
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.isComplete() → boolean
boolean
Has the request completed.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.isDisposed() → boolean
boolean
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.isSuccess() → boolean
boolean
Has the request compeleted with a success.
Overrides | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.listen<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → goog.events.ListenableKey
goog.events.ListenableKey
Adds an event listener. A listener can only be added once to an object and if it is added again the key for the listener is returned. Note that if the existing listener is a one-off listener (registered via listenOnce), it will no longer be a one-off listener after a call to listen().
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.listenOnce<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → goog.events.ListenableKey
goog.events.ListenableKey
Adds an event listener that is removed automatically after the listener fired once.
If an existing listener already exists, listenOnce will do nothing. In particular, if the listener was previously registered via listen(), listenOnce() will not turn the listener into a one-off listener. Similarly, if there is already an existing one-off listener, listenOnce does not modify the listeners (it is still a once listener).
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.registerDisposable( disposable ) → void
void
Associates a disposable object with this object so that they will be disposed together.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.removeAllListeners( opt_type ) → number
number
Removes all listeners from this listenable. If type is specified, it will only remove listeners of the particular type. otherwise all registered listeners will be removed.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
this.removeEventListener( type, handler, opt_capture, opt_handlerScope ) → void
void
Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.
warning Deprecated | Use |
---|
Defined by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.send( url, opt_method, opt_content, opt_headers ) → void
void
this.setParentEventTarget( parent ) → void
void
Sets the parent of this event target to use for capture/bubble mechanism.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setProgressEventsEnabled( enabled ) → void
void
Sets whether progress events are enabled for this request. Note that progress events require pre-flight OPTIONS request handling for CORS requests, and may cause trouble with older browsers. See goog.net.XhrIo.progressEventsEnabled_ for details.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
|
this.setResponseType( type ) → void
void
Sets the desired type for the response. At time of writing, this is only supported in very recent versions of WebKit (10.0.612.1 dev and later).
If this is used, the response may only be accessed via #getResponse
.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
|
this.setTargetForTesting( target ) → void
void
Sets the target to be used for event.target
when firing
event. Mainly used for testing. For example, see
goog.testing.events.mixinListenable
.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setTimeoutInterval( ms ) → void
void
Sets the number of milliseconds after which an incomplete request will be
aborted and a goog.net.EventType.TIMEOUT
event raised; 0 means no
timeout is set.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
|
this.setTrustToken( trustToken ) → void
void
Specify a Trust Tokens operation to execute alongside the request.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
|
this.setWithCredentials( withCredentials ) → void
void
Sets whether a "credentialed" request that is aware of cookie and authentication information should be made. This option is only supported by browsers that support HTTP Access Control. As of this writing, this option is not supported in IE.
Overrides | |||||
---|---|---|---|---|---|
Parameters |
|
this.simulatePartialResponse( partialResponse, opt_headers ) → void
void
this.simulateProgress( lengthComputable, loaded, total, opt_isDownload ) → void
void
this.simulateReady() → void
void
Simulates the Xhr is ready for the next request.
this.simulateReadyStateChange( readyState ) → void
void
Simulates changing to the new ready state.
Parameters |
|
---|
this.simulateResponse( statusCode, response, opt_headers ) → void
void
this.simulateTimeout() → void
void
Causes timeout events to be fired.
this.unlisten<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → boolean
boolean
Removes an event listener which was added with listen() or listenOnce().
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.unlistenByKey( key ) → boolean
boolean
Removes an event listener which was added with listen() by the key returned by listen().
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
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.
Map of default headers to add to every request, use: XhrIo.headers.set(name, value)
Overrides |
---|
Static Functions
XhrIo.cleanup() → void
void
Disposes all non-disposed instances of goog.testing.net.XhrIo created by
goog.testing.net.XhrIo.send
.
XhrIo.getSendInstances() → Array<goog.testing.net.XhrIo>
Array<goog.testing.net.XhrIo>
Returns an Array containing all non-disposed instances of
goog.testing.net.XhrIo created by goog.testing.net.XhrIo.send
.
Parameters | None. | ||
---|---|---|---|
Returns |
|
XhrIo.send( url, opt_callback, opt_method, opt_content, opt_headers, opt_timeoutInterval, opt_withCredentials ) → goog.testing.net.XhrIo
goog.testing.net.XhrIo
Simulates the static XhrIo send method.
Parameters |
| ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
Static Properties
Alias this array here to make mocking of goog.net.XhrIo easier.
XhrIo.allowUnsafeAccessToXhrIoOutsideCallbacks → boolean
boolean
To emulate the behavior of the actual XhrIo, we do not allow access to the XhrIo's properties outside the event callbacks. For backwards compatibility, we allow tests to allow access by setting this value to true.