goog.testing.net.XhrIo
Classgoog.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
=}
.abort(opt_failureCode)
Abort the current XMLHttpRequest
opt_failureCode
{goog.net.ErrorCode
=}
.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
}
handler
{Function
|Object
}
opt_capture
{boolean
=}
opt_handlerScope
{Object
=}
.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
}
opt_scope
{Object
=}
.cleanup()
Disposes all non-disposed instances of goog.testing.net.XhrIo created by {@link goog.testing.net.XhrIo.send}.
.createXhr()
[protected]Creates a new XHR object.
XMLHttpRequest
|GearsHttpRequest
}
.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
}
boolean
}
.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.
void
}
.disposeInternal()
[protected]Inherited from goog.events.EventTarget
.
Unattach listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners, it should be something like this:
MyClass.prototype.disposeInternal = function() { MyClass.superClass_.disposeInternal.call(this); // Dispose logic for MyClass };
.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
string
}
.getDisposed
[deprecated]Deprecated. Use {@link #isDisposed} instead.
Inherited from goog.Disposable
.
boolean
}
.getLastContent()
Gets the last POST content that was requested.
string
|undefined
}
.getLastError()
Gets the last error message.
string
}
.getLastErrorCode()
Gets the last error message.
goog.net.ErrorCode
}
.getLastMethod()
Gets the last HTTP method that was requested.
string
|undefined
}
.getLastRequestHeaders()
Gets the headers of the last request.
Object
|goog.structs.Map
|undefined
}
.getLastUri()
Gets the last URI that was requested.
string
}
.getParentEventTarget()
Inherited from goog.events.EventTarget
.
Returns the parent of this event target to use for bubbling.
goog.events.EventTarget
}
.getReadyState()
Returns the readystate.
number
}
.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).
.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
}
string
|undefined
}
.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
=}
Object
}
.getResponseText()
Gets the response text from the Xhr object. Will only return correct result when called from the context of a callback.
string
}
.getResponseType()
Gets the desired type for the response.
goog.net.XhrIo.ResponseType
}
.getResponseXml()
Gets the response XML from the Xhr object. Will only return correct result when called from the context of a callback.
Document
}
.getSendInstances()
Returns an Array containing all non-disposed instances of goog.testing.net.XhrIo created by {@link goog.testing.net.XhrIo.send}.
Array
}
.getStatus()
Get the status from the Xhr object. Will only return correct result when called from the context of a callback.
number
}
.getStatusText()
Get the status text from the Xhr object. Will only return correct result when called from the context of a callback.
string
}
.getTimeoutInterval()
Returns the number of milliseconds after which an incomplete request will be aborted, or 0 if no timeout is set.
number
}
.getWithCredentials()
Gets whether a "credentialed" request is to be sent.
boolean
}
.headers
{goog.structs.Map
}Map of default headers to add to every request, use: XhrIo.headers.set(name, value)
.isActive()
boolean
}
.isComplete()
Has the request completed.
boolean
}
.isDisposed()
Inherited from goog.Disposable
.
boolean
}
.isSuccess()
Has the request compeleted with a success.
boolean
}
.registerDisposable(disposable)
Inherited from goog.Disposable
.
Associates a disposable object with this object so that they will be disposed together.
disposable
{goog.disposable.IDisposable
}
.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
}
handler
{Function
|Object
}
opt_capture
{boolean
=}
opt_handlerScope
{Object
=}
.send(url, opt_callback, opt_method, opt_content, opt_headers,
opt_timeoutInterval)
Simulates the static XhrIo send method.
url
{string
}
opt_callback
{Function
=}
opt_method
{string
=}
opt_content
{string
=}
opt_headers
{Object
|goog.structs.Map
=}
opt_timeoutInterval
{number
=}
.setParentEventTarget(parent)
Inherited from goog.events.EventTarget
.
Sets the parent of this event target to use for bubbling.
parent
{goog.events.EventTarget
?}
.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
}
.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
}
.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
}
.simulatePartialResponse(partialResponse, opt_headers)
Simulate receiving some bytes but the request not fully completing, and the XHR entering the 'INTERACTIVE' state.
partialResponse
{string
}
opt_headers
{Object
=}
.simulateReady()
Simulates the Xhr is ready for the next request.
.simulateReadyStateChange(readyState)
Simulates changing to the new ready state.
readyState
{number
}
.simulateResponse(statusCode, response, opt_headers)
Simulates receiving a response.
statusCode
{number
}
response
{string
|Document
|null
}
opt_headers
{Object
=}
.simulateTimeout()
Causes timeout events to be fired.