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