123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- goog.provide('goog.net.MockIFrameIo');
- goog.require('goog.events.EventTarget');
- goog.require('goog.json');
- goog.require('goog.net.ErrorCode');
- goog.require('goog.net.EventType');
- goog.require('goog.net.IframeIo');
- goog.forwardDeclare('goog.testing.TestQueue');
- goog.net.MockIFrameIo = function(testQueue) {
- goog.events.EventTarget.call(this);
-
- this.testQueue_ = testQueue;
- };
- goog.inherits(goog.net.MockIFrameIo, goog.events.EventTarget);
- goog.net.MockIFrameIo.prototype.active_ = false;
- goog.net.MockIFrameIo.prototype.lastContent_ = '';
- goog.net.MockIFrameIo.prototype.lastErrorCode_ = goog.net.ErrorCode.NO_ERROR;
- goog.net.MockIFrameIo.prototype.lastError_ = '';
- goog.net.MockIFrameIo.prototype.lastCustomError_ = null;
- goog.net.MockIFrameIo.prototype.lastUri_ = null;
- goog.net.MockIFrameIo.prototype.errorChecker_;
- goog.net.MockIFrameIo.prototype.success_;
- goog.net.MockIFrameIo.prototype.complete_;
- goog.net.MockIFrameIo.prototype.send = function(
- uri, opt_method, opt_noCache, opt_data) {
- if (this.active_) {
- throw Error('[goog.net.IframeIo] Unable to send, already active.');
- }
- this.testQueue_.enqueue(['s', uri, opt_method, opt_noCache, opt_data]);
- this.complete_ = false;
- this.active_ = true;
- };
- goog.net.MockIFrameIo.prototype.sendFromForm = function(
- form, opt_uri, opt_noCache) {
- if (this.active_) {
- throw Error('[goog.net.IframeIo] Unable to send, already active.');
- }
- this.testQueue_.enqueue(['s', form, opt_uri, opt_noCache]);
- this.complete_ = false;
- this.active_ = true;
- };
- goog.net.MockIFrameIo.prototype.abort = function(opt_failureCode) {
- if (this.active_) {
- this.testQueue_.enqueue(['a', opt_failureCode]);
- this.complete_ = false;
- this.active_ = false;
- this.success_ = false;
- this.lastErrorCode_ = opt_failureCode || goog.net.ErrorCode.ABORT;
- this.dispatchEvent(goog.net.EventType.ABORT);
- this.simulateReady();
- }
- };
- goog.net.MockIFrameIo.prototype.simulateIncrementalData = function(data) {
- this.dispatchEvent(new goog.net.IframeIo.IncrementalDataEvent(data));
- };
- goog.net.MockIFrameIo.prototype.simulateDone = function(errorCode) {
- if (errorCode) {
- this.success_ = false;
- this.lastErrorCode_ = goog.net.ErrorCode.HTTP_ERROR;
- this.lastError_ = this.getLastError();
- this.dispatchEvent(goog.net.EventType.ERROR);
- } else {
- this.success_ = true;
- this.lastErrorCode_ = goog.net.ErrorCode.NO_ERROR;
- this.dispatchEvent(goog.net.EventType.SUCCESS);
- }
- this.complete_ = true;
- this.dispatchEvent(goog.net.EventType.COMPLETE);
- };
- goog.net.MockIFrameIo.prototype.simulateReady = function() {
- this.dispatchEvent(goog.net.EventType.READY);
- };
- goog.net.MockIFrameIo.prototype.isComplete = function() {
- return this.complete_;
- };
- goog.net.MockIFrameIo.prototype.isSuccess = function() {
- return this.success_;
- };
- goog.net.MockIFrameIo.prototype.isActive = function() {
- return this.active_;
- };
- goog.net.MockIFrameIo.prototype.getResponseText = function() {
- return this.lastContent_;
- };
- goog.net.MockIFrameIo.prototype.getResponseJson = function() {
- return goog.json.parse(this.lastContent_);
- };
- goog.net.MockIFrameIo.prototype.getLastUri = function() {
- return this.lastUri_;
- };
- goog.net.MockIFrameIo.prototype.getLastErrorCode = function() {
- return this.lastErrorCode_;
- };
- goog.net.MockIFrameIo.prototype.getLastError = function() {
- return goog.net.ErrorCode.getDebugMessage(this.lastErrorCode_);
- };
- goog.net.MockIFrameIo.prototype.getLastCustomError = function() {
- return this.lastCustomError_;
- };
- goog.net.MockIFrameIo.prototype.setErrorChecker = function(fn) {
- this.errorChecker_ = fn;
- };
- goog.net.MockIFrameIo.prototype.getErrorChecker = function() {
- return this.errorChecker_;
- };
|