The goog.testing.net.XhrIo Class

goog.testing.net.XhrIo
> goog.events.EventTarget
> goog.Disposable

goog.testing.net.XhrIo(opt_testQueue)

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.

opt_testQueue {goog.testing.TestQueue=}
Test queue for inserting test events.

.abort(opt_failureCode)

Abort the current XMLHttpRequest

opt_failureCode {goog.net.ErrorCode=}
Optional error code to use - defaults to ABORT.

.addEventListener(type, handler, opt_capture, opt_handlerScope)

Inherited from goog.events.EventTarget .

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. Supported for legacy but use goog.events.listen(src, type, handler) instead.

type {string}
The type of the event to listen for.
handler {Function|Object}
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture {boolean=}
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope {Object=}
Object in whose scope to call the listener.

.addOnDisposeCallback(callback, opt_scope)

Inherited from goog.Disposable .

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

callback {!Function}
The callback function.
opt_scope {Object=}
An optional scope to call the callback in.

.cleanup()

Disposes all non-disposed instances of goog.testing.net.XhrIo created by {@link goog.testing.net.XhrIo.send}.

@see
goog.net.XhrIo.cleanup

.creationStack {string}

Inherited from goog.Disposable .

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

.dispatchEvent(e)

Inherited from goog.events.EventTarget .

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.

e {string|Object|goog.events.Event}
Event object.
returns {boolean}
If anyone called preventDefault on the event object (or if any of the handlers returns false this will also return false.

.dispose()

Inherited from goog.Disposable .

Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

returns {void}
Nothing.

.getAllResponseHeaders()

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

returns {string}
The string containing all the response headers.

.getLastContent()

Gets the last POST content that was requested.

returns {string|undefined}
Last POST content or undefined if last request was a GET.

.getLastError()

Gets the last error message.

returns {string}
Last error message.

.getLastErrorCode()

Gets the last error message.

returns {goog.net.ErrorCode}
Last error code.

.getLastMethod()

Gets the last HTTP method that was requested.

returns {string|undefined}
Last HTTP method used by send.

.getLastRequestHeaders()

Gets the headers of the last request.

returns {Object|goog.structs.Map|undefined}
Last headers manually set in send call or undefined if no additional headers were specified.

.getLastUri()

Gets the last URI that was requested.

returns {string}
Last URI.

.getParentEventTarget()

Inherited from goog.events.EventTarget .

Returns the parent of this event target to use for bubbling.

returns {goog.events.EventTarget}
The parent EventTarget or null if there is no parent.

.getReadyState()

Returns the readystate.

returns {number}
goog.net.XmlHttp.ReadyState.*.

.getResponse()

Get the response as the type specificed by {@link #setResponseType}. At time of writing, this is only supported in very recent versions of WebKit (10.0.612.1 dev and later).

returns {*}
The response.

.getResponseHeader(key)

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

key {string}
The name of the response-header to retrieve.
returns {string|undefined}
The value of the response-header named key.

.getResponseJson(opt_xssiPrefix)

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.

opt_xssiPrefix {string=}
Optional XSSI prefix string to use for stripping of the response before parsing. This needs to be set only if your backend server prepends the same prefix string to the JSON response.
returns {Object}
JavaScript object.

.getResponseText()

Gets the response text from the Xhr object. Will only return correct result when called from the context of a callback.

returns {string}
Result from the server.

.getResponseType()

Gets the desired type for the response.

returns {goog.net.XhrIo.ResponseType}
The desired type for the response.

.getResponseXml()

Gets the response XML from the Xhr object. Will only return correct result when called from the context of a callback.

returns {Document}
Result from the server if it was XML.

.getSendInstances()

Returns an Array containing all non-disposed instances of goog.testing.net.XhrIo created by {@link goog.testing.net.XhrIo.send}.

returns {Array}
Array of goog.testing.net.XhrIo instances.

.getStatus()

Get the status from the Xhr object. Will only return correct result when called from the context of a callback.

returns {number}
Http status.

.getStatusText()

Get the status text from the Xhr object. Will only return correct result when called from the context of a callback.

returns {string}
Status text.

.getTimeoutInterval()

Returns the number of milliseconds after which an incomplete request will be aborted, or 0 if no timeout is set.

returns {number}
Timeout interval in milliseconds.

.getWithCredentials()

Gets whether a "credentialed" request is to be sent.

returns {boolean}
The desired type for the response.

.headers {goog.structs.Map}

Map of default headers to add to every request, use: XhrIo.headers.set(name, value)

.isActive()

returns {boolean}
Whether there is an active request.

.isComplete()

Has the request completed.

returns {boolean}
Whether the request has completed.

.isDisposed()

Inherited from goog.Disposable .

returns {boolean}
Whether the object has been disposed of.

.isSuccess()

Has the request compeleted with a success.

returns {boolean}
Whether the request compeleted successfully.

.registerDisposable(disposable)

Inherited from goog.Disposable .

Associates a disposable object with this object so that they will be disposed together.

disposable {goog.disposable.IDisposable}
that will be disposed when this object is disposed.

.removeEventListener(type, handler, opt_capture, opt_handlerScope)

Inherited from goog.events.EventTarget .

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.

type {string}
The type of the event to listen for.
handler {Function|Object}
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture {boolean=}
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope {Object=}
Object in whose scope to call the listener.

.send(url, opt_callback, opt_method, opt_content, opt_headers, opt_timeoutInterval)

Simulates the static XhrIo send method.

url {string}
Uri to make request to.
opt_callback {Function=}
Callback function for when request is complete.
opt_method {string=}
Send method, default: GET.
opt_content {string=}
Post data.
opt_headers {Object|goog.structs.Map=}
Map of headers to add to the request.
opt_timeoutInterval {number=}
Number of milliseconds after which an incomplete request will be aborted; 0 means no timeout is set.

.setParentEventTarget(parent)

Inherited from goog.events.EventTarget .

Sets the parent of this event target to use for bubbling.

parent {goog.events.EventTarget?}
Parent EventTarget (null if none).

.setResponseType(type)

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 {@link #getResponse}.

type {goog.net.XhrIo.ResponseType}
The desired type for the response.

.setTimeoutInterval(ms)

Sets the number of milliseconds after which an incomplete request will be aborted and a {@link goog.net.EventType.TIMEOUT} event raised; 0 means no timeout is set.

ms {number}
Timeout interval in milliseconds; 0 means none.

.setWithCredentials(withCredentials)

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.

withCredentials {boolean}
Whether this should be a "credentialed" request.

.simulatePartialResponse(partialResponse, opt_headers)

Simulate receiving some bytes but the request not fully completing, and the XHR entering the 'INTERACTIVE' state.

partialResponse {string}
A string to append to the response text.
opt_headers {Object=}
Simulated response headers.

.simulateReady()

Simulates the Xhr is ready for the next request.

.simulateReadyStateChange(readyState)

Simulates changing to the new ready state.

readyState {number}
Ready state to change to.

.simulateResponse(statusCode, response, opt_headers)

Simulates receiving a response.

statusCode {number}
Simulated status code.
response {string|Document|null}
Simulated response.
opt_headers {Object=}
Simulated response headers.

.simulateTimeout()

Causes timeout events to be fired.