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.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | XPCOMUtils.defineLazyModuleGetter(this, "Promise", |
michael@0 | 6 | "resource://gre/modules/Promise.jsm"); |
michael@0 | 7 | XPCOMUtils.defineLazyModuleGetter(this, "Task", |
michael@0 | 8 | "resource://gre/modules/Task.jsm"); |
michael@0 | 9 | |
michael@0 | 10 | registerCleanupFunction(function() { |
michael@0 | 11 | // Ensure we don't pollute prefs for next tests. |
michael@0 | 12 | try { |
michael@0 | 13 | Services.prefs.clearUserPref("datareporting.healthreport.about.reportUrl"); |
michael@0 | 14 | let policy = Cc["@mozilla.org/datareporting/service;1"] |
michael@0 | 15 | .getService(Ci.nsISupports) |
michael@0 | 16 | .wrappedJSObject |
michael@0 | 17 | .policy; |
michael@0 | 18 | policy.recordHealthReportUploadEnabled(true, |
michael@0 | 19 | "Resetting after tests."); |
michael@0 | 20 | } catch (ex) {} |
michael@0 | 21 | }); |
michael@0 | 22 | |
michael@0 | 23 | let gTests = [ |
michael@0 | 24 | |
michael@0 | 25 | { |
michael@0 | 26 | desc: "Test the remote commands", |
michael@0 | 27 | setup: function () |
michael@0 | 28 | { |
michael@0 | 29 | Services.prefs.setCharPref("datareporting.healthreport.about.reportUrl", |
michael@0 | 30 | "https://example.com/browser/browser/base/content/test/general/healthreport_testRemoteCommands.html"); |
michael@0 | 31 | }, |
michael@0 | 32 | run: function () |
michael@0 | 33 | { |
michael@0 | 34 | let deferred = Promise.defer(); |
michael@0 | 35 | |
michael@0 | 36 | let policy = Cc["@mozilla.org/datareporting/service;1"] |
michael@0 | 37 | .getService(Ci.nsISupports) |
michael@0 | 38 | .wrappedJSObject |
michael@0 | 39 | .policy; |
michael@0 | 40 | |
michael@0 | 41 | let results = 0; |
michael@0 | 42 | try { |
michael@0 | 43 | let win = gBrowser.contentWindow; |
michael@0 | 44 | win.addEventListener("message", function testLoad(e) { |
michael@0 | 45 | if (e.data.type == "testResult") { |
michael@0 | 46 | ok(e.data.pass, e.data.info); |
michael@0 | 47 | results++; |
michael@0 | 48 | } |
michael@0 | 49 | else if (e.data.type == "testsComplete") { |
michael@0 | 50 | is(results, e.data.count, "Checking number of results received matches the number of tests that should have run"); |
michael@0 | 51 | win.removeEventListener("message", testLoad, false, true); |
michael@0 | 52 | deferred.resolve(); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | }, false, true); |
michael@0 | 56 | |
michael@0 | 57 | } catch(e) { |
michael@0 | 58 | ok(false, "Failed to get all commands"); |
michael@0 | 59 | deferred.reject(); |
michael@0 | 60 | } |
michael@0 | 61 | return deferred.promise; |
michael@0 | 62 | } |
michael@0 | 63 | }, |
michael@0 | 64 | |
michael@0 | 65 | |
michael@0 | 66 | ]; // gTests |
michael@0 | 67 | |
michael@0 | 68 | function test() |
michael@0 | 69 | { |
michael@0 | 70 | waitForExplicitFinish(); |
michael@0 | 71 | |
michael@0 | 72 | // xxxmpc leaving this here until we resolve bug 854038 and bug 854060 |
michael@0 | 73 | requestLongerTimeout(10); |
michael@0 | 74 | |
michael@0 | 75 | Task.spawn(function () { |
michael@0 | 76 | for (let test of gTests) { |
michael@0 | 77 | info(test.desc); |
michael@0 | 78 | test.setup(); |
michael@0 | 79 | |
michael@0 | 80 | yield promiseNewTabLoadEvent("about:healthreport"); |
michael@0 | 81 | |
michael@0 | 82 | yield test.run(); |
michael@0 | 83 | |
michael@0 | 84 | gBrowser.removeCurrentTab(); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | finish(); |
michael@0 | 88 | }); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | function promiseNewTabLoadEvent(aUrl, aEventType="load") |
michael@0 | 92 | { |
michael@0 | 93 | let deferred = Promise.defer(); |
michael@0 | 94 | let tab = gBrowser.selectedTab = gBrowser.addTab(aUrl); |
michael@0 | 95 | tab.linkedBrowser.addEventListener(aEventType, function load(event) { |
michael@0 | 96 | tab.linkedBrowser.removeEventListener(aEventType, load, true); |
michael@0 | 97 | let iframe = tab.linkedBrowser.contentDocument.getElementById("remote-report"); |
michael@0 | 98 | iframe.addEventListener("load", function frameLoad(e) { |
michael@0 | 99 | iframe.removeEventListener("load", frameLoad, false); |
michael@0 | 100 | deferred.resolve(); |
michael@0 | 101 | }, false); |
michael@0 | 102 | }, true); |
michael@0 | 103 | return deferred.promise; |
michael@0 | 104 | } |
michael@0 | 105 |