toolkit/content/tests/browser/common/mockTransfer.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 Cc["@mozilla.org/moz/jssubscript-loader;1"]
michael@0 6 .getService(Ci.mozIJSSubScriptLoader)
michael@0 7 .loadSubScript("chrome://mochikit/content/tests/SimpleTest/MockObjects.js", this);
michael@0 8
michael@0 9 var mockTransferCallback;
michael@0 10
michael@0 11 /**
michael@0 12 * This "transfer" object implementation continues the currently running test
michael@0 13 * when the download is completed, reporting true for success or false for
michael@0 14 * failure as the first argument of the testRunner.continueTest function.
michael@0 15 */
michael@0 16 function MockTransfer() {
michael@0 17 this._downloadIsSuccessful = true;
michael@0 18 }
michael@0 19
michael@0 20 MockTransfer.prototype = {
michael@0 21 QueryInterface: XPCOMUtils.generateQI([
michael@0 22 Ci.nsIWebProgressListener,
michael@0 23 Ci.nsIWebProgressListener2,
michael@0 24 Ci.nsITransfer,
michael@0 25 ]),
michael@0 26
michael@0 27 /* nsIWebProgressListener */
michael@0 28 onStateChange: function MTFC_onStateChange(aWebProgress, aRequest,
michael@0 29 aStateFlags, aStatus) {
michael@0 30 // If at least one notification reported an error, the download failed.
michael@0 31 if (!Components.isSuccessCode(aStatus))
michael@0 32 this._downloadIsSuccessful = false;
michael@0 33
michael@0 34 // If the download is finished
michael@0 35 if ((aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) &&
michael@0 36 (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK))
michael@0 37 // Continue the test, reporting the success or failure condition.
michael@0 38 mockTransferCallback(this._downloadIsSuccessful);
michael@0 39 },
michael@0 40 onProgressChange: function () {},
michael@0 41 onLocationChange: function () {},
michael@0 42 onStatusChange: function MTFC_onStatusChange(aWebProgress, aRequest, aStatus,
michael@0 43 aMessage) {
michael@0 44 // If at least one notification reported an error, the download failed.
michael@0 45 if (!Components.isSuccessCode(aStatus))
michael@0 46 this._downloadIsSuccessful = false;
michael@0 47 },
michael@0 48 onSecurityChange: function () {},
michael@0 49
michael@0 50 /* nsIWebProgressListener2 */
michael@0 51 onProgressChange64: function () {},
michael@0 52 onRefreshAttempted: function () {},
michael@0 53
michael@0 54 /* nsITransfer */
michael@0 55 init: function() {},
michael@0 56 setSha256Hash: function() {},
michael@0 57 setSignatureInfo: function() {}
michael@0 58 };
michael@0 59
michael@0 60 // Create an instance of a MockObjectRegisterer whose methods can be used to
michael@0 61 // temporarily replace the default "@mozilla.org/transfer;1" object factory with
michael@0 62 // one that provides the mock implementation above. To activate the mock object
michael@0 63 // factory, call the "register" method. Starting from that moment, all the
michael@0 64 // transfer objects that are requested will be mock objects, until the
michael@0 65 // "unregister" method is called.
michael@0 66 var mockTransferRegisterer =
michael@0 67 new MockObjectRegisterer("@mozilla.org/transfer;1", MockTransfer);

mercurial