michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Cc["@mozilla.org/moz/jssubscript-loader;1"] michael@0: .getService(Ci.mozIJSSubScriptLoader) michael@0: .loadSubScript("chrome://mochikit/content/tests/SimpleTest/MockObjects.js", this); michael@0: michael@0: var mockTransferCallback; michael@0: michael@0: /** michael@0: * This "transfer" object implementation continues the currently running test michael@0: * when the download is completed, reporting true for success or false for michael@0: * failure as the first argument of the testRunner.continueTest function. michael@0: */ michael@0: function MockTransfer() { michael@0: this._downloadIsSuccessful = true; michael@0: } michael@0: michael@0: MockTransfer.prototype = { michael@0: QueryInterface: XPCOMUtils.generateQI([ michael@0: Ci.nsIWebProgressListener, michael@0: Ci.nsIWebProgressListener2, michael@0: Ci.nsITransfer, michael@0: ]), michael@0: michael@0: /* nsIWebProgressListener */ michael@0: onStateChange: function MTFC_onStateChange(aWebProgress, aRequest, michael@0: aStateFlags, aStatus) { michael@0: // If at least one notification reported an error, the download failed. michael@0: if (!Components.isSuccessCode(aStatus)) michael@0: this._downloadIsSuccessful = false; michael@0: michael@0: // If the download is finished michael@0: if ((aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) && michael@0: (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK)) michael@0: // Continue the test, reporting the success or failure condition. michael@0: mockTransferCallback(this._downloadIsSuccessful); michael@0: }, michael@0: onProgressChange: function () {}, michael@0: onLocationChange: function () {}, michael@0: onStatusChange: function MTFC_onStatusChange(aWebProgress, aRequest, aStatus, michael@0: aMessage) { michael@0: // If at least one notification reported an error, the download failed. michael@0: if (!Components.isSuccessCode(aStatus)) michael@0: this._downloadIsSuccessful = false; michael@0: }, michael@0: onSecurityChange: function () {}, michael@0: michael@0: /* nsIWebProgressListener2 */ michael@0: onProgressChange64: function () {}, michael@0: onRefreshAttempted: function () {}, michael@0: michael@0: /* nsITransfer */ michael@0: init: function() {}, michael@0: setSha256Hash: function() {}, michael@0: setSignatureInfo: function() {} michael@0: }; michael@0: michael@0: // Create an instance of a MockObjectRegisterer whose methods can be used to michael@0: // temporarily replace the default "@mozilla.org/transfer;1" object factory with michael@0: // one that provides the mock implementation above. To activate the mock object michael@0: // factory, call the "register" method. Starting from that moment, all the michael@0: // transfer objects that are requested will be mock objects, until the michael@0: // "unregister" method is called. michael@0: var mockTransferRegisterer = michael@0: new MockObjectRegisterer("@mozilla.org/transfer;1", MockTransfer);