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 | const DUMMY = "browser/browser/base/content/test/general/dummy_page.html"; |
michael@0 | 6 | |
michael@0 | 7 | function loadNewTab(aURL, aCallback) { |
michael@0 | 8 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 9 | gBrowser.loadURI(aURL); |
michael@0 | 10 | |
michael@0 | 11 | gBrowser.selectedBrowser.addEventListener("load", function() { |
michael@0 | 12 | if (gBrowser.selectedBrowser.currentURI.spec != aURL) |
michael@0 | 13 | return; |
michael@0 | 14 | gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); |
michael@0 | 15 | |
michael@0 | 16 | aCallback(gBrowser.selectedTab); |
michael@0 | 17 | }, true); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | function getIdentityMode() { |
michael@0 | 21 | return document.getElementById("identity-box").className; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | var TESTS = [ |
michael@0 | 25 | function test_webpage() { |
michael@0 | 26 | let oldTab = gBrowser.selectedTab; |
michael@0 | 27 | |
michael@0 | 28 | loadNewTab("http://example.com/" + DUMMY, function(aNewTab) { |
michael@0 | 29 | is(getIdentityMode(), "unknownIdentity", "Identity should be unknown"); |
michael@0 | 30 | |
michael@0 | 31 | gBrowser.selectedTab = oldTab; |
michael@0 | 32 | is(getIdentityMode(), "unknownIdentity", "Identity should be unknown"); |
michael@0 | 33 | |
michael@0 | 34 | gBrowser.selectedTab = aNewTab; |
michael@0 | 35 | is(getIdentityMode(), "unknownIdentity", "Identity should be unknown"); |
michael@0 | 36 | |
michael@0 | 37 | gBrowser.removeTab(aNewTab); |
michael@0 | 38 | |
michael@0 | 39 | runNextTest(); |
michael@0 | 40 | }); |
michael@0 | 41 | }, |
michael@0 | 42 | |
michael@0 | 43 | function test_blank() { |
michael@0 | 44 | let oldTab = gBrowser.selectedTab; |
michael@0 | 45 | |
michael@0 | 46 | loadNewTab("about:blank", function(aNewTab) { |
michael@0 | 47 | is(getIdentityMode(), "unknownIdentity", "Identity should be unknown"); |
michael@0 | 48 | |
michael@0 | 49 | gBrowser.selectedTab = oldTab; |
michael@0 | 50 | is(getIdentityMode(), "unknownIdentity", "Identity should be unknown"); |
michael@0 | 51 | |
michael@0 | 52 | gBrowser.selectedTab = aNewTab; |
michael@0 | 53 | is(getIdentityMode(), "unknownIdentity", "Identity should be unknown"); |
michael@0 | 54 | |
michael@0 | 55 | gBrowser.removeTab(aNewTab); |
michael@0 | 56 | |
michael@0 | 57 | runNextTest(); |
michael@0 | 58 | }); |
michael@0 | 59 | }, |
michael@0 | 60 | |
michael@0 | 61 | function test_chrome() { |
michael@0 | 62 | let oldTab = gBrowser.selectedTab; |
michael@0 | 63 | |
michael@0 | 64 | // Since users aren't likely to type in full chrome URLs, we won't show |
michael@0 | 65 | // the positive security indicator on it, but we will show it on about:addons. |
michael@0 | 66 | loadNewTab("chrome://mozapps/content/extensions/extensions.xul", function(aNewTab) { |
michael@0 | 67 | is(getIdentityMode(), "unknownIdentity", "Identity should be unknown"); |
michael@0 | 68 | |
michael@0 | 69 | gBrowser.selectedTab = oldTab; |
michael@0 | 70 | is(getIdentityMode(), "unknownIdentity", "Identity should be unknown"); |
michael@0 | 71 | |
michael@0 | 72 | gBrowser.selectedTab = aNewTab; |
michael@0 | 73 | is(getIdentityMode(), "unknownIdentity", "Identity should be unknown"); |
michael@0 | 74 | |
michael@0 | 75 | gBrowser.removeTab(aNewTab); |
michael@0 | 76 | |
michael@0 | 77 | runNextTest(); |
michael@0 | 78 | }); |
michael@0 | 79 | }, |
michael@0 | 80 | |
michael@0 | 81 | function test_https() { |
michael@0 | 82 | let oldTab = gBrowser.selectedTab; |
michael@0 | 83 | |
michael@0 | 84 | loadNewTab("https://example.com/" + DUMMY, function(aNewTab) { |
michael@0 | 85 | is(getIdentityMode(), "verifiedDomain", "Identity should be verified"); |
michael@0 | 86 | |
michael@0 | 87 | gBrowser.selectedTab = oldTab; |
michael@0 | 88 | is(getIdentityMode(), "unknownIdentity", "Identity should be unknown"); |
michael@0 | 89 | |
michael@0 | 90 | gBrowser.selectedTab = aNewTab; |
michael@0 | 91 | is(getIdentityMode(), "verifiedDomain", "Identity should be verified"); |
michael@0 | 92 | |
michael@0 | 93 | gBrowser.removeTab(aNewTab); |
michael@0 | 94 | |
michael@0 | 95 | runNextTest(); |
michael@0 | 96 | }); |
michael@0 | 97 | }, |
michael@0 | 98 | |
michael@0 | 99 | function test_addons() { |
michael@0 | 100 | let oldTab = gBrowser.selectedTab; |
michael@0 | 101 | |
michael@0 | 102 | loadNewTab("about:addons", function(aNewTab) { |
michael@0 | 103 | is(getIdentityMode(), "chromeUI", "Identity should be chrome"); |
michael@0 | 104 | |
michael@0 | 105 | gBrowser.selectedTab = oldTab; |
michael@0 | 106 | is(getIdentityMode(), "unknownIdentity", "Identity should be unknown"); |
michael@0 | 107 | |
michael@0 | 108 | gBrowser.selectedTab = aNewTab; |
michael@0 | 109 | is(getIdentityMode(), "chromeUI", "Identity should be chrome"); |
michael@0 | 110 | |
michael@0 | 111 | gBrowser.removeTab(aNewTab); |
michael@0 | 112 | |
michael@0 | 113 | runNextTest(); |
michael@0 | 114 | }); |
michael@0 | 115 | } |
michael@0 | 116 | ]; |
michael@0 | 117 | |
michael@0 | 118 | var gTestStart = null; |
michael@0 | 119 | |
michael@0 | 120 | function runNextTest() { |
michael@0 | 121 | if (gTestStart) |
michael@0 | 122 | info("Test part took " + (Date.now() - gTestStart) + "ms"); |
michael@0 | 123 | |
michael@0 | 124 | if (TESTS.length == 0) { |
michael@0 | 125 | finish(); |
michael@0 | 126 | return; |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | info("Running " + TESTS[0].name); |
michael@0 | 130 | gTestStart = Date.now(); |
michael@0 | 131 | TESTS.shift()(); |
michael@0 | 132 | }; |
michael@0 | 133 | |
michael@0 | 134 | function test() { |
michael@0 | 135 | waitForExplicitFinish(); |
michael@0 | 136 | |
michael@0 | 137 | runNextTest(); |
michael@0 | 138 | } |