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 | /* 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 | function test() { |
michael@0 | 6 | waitForExplicitFinish(); |
michael@0 | 7 | |
michael@0 | 8 | let testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; |
michael@0 | 9 | |
michael@0 | 10 | function testOnWindow(aOptions, aCallback) { |
michael@0 | 11 | whenNewWindowLoaded(aOptions, function(aWin) { |
michael@0 | 12 | // execute should only be called when need, like when you are opening |
michael@0 | 13 | // web pages on the test. If calling executeSoon() is not necesary, then |
michael@0 | 14 | // call whenNewWindowLoaded() instead of testOnWindow() on your test. |
michael@0 | 15 | executeSoon(function() aCallback(aWin)); |
michael@0 | 16 | }); |
michael@0 | 17 | }; |
michael@0 | 18 | |
michael@0 | 19 | testOnWindow({}, function(aNormalWindow) { |
michael@0 | 20 | testOnWindow({private: true}, function(aPrivateWindow) { |
michael@0 | 21 | runTest(aNormalWindow, aPrivateWindow, false, function() { |
michael@0 | 22 | aNormalWindow.close(); |
michael@0 | 23 | aPrivateWindow.close(); |
michael@0 | 24 | testOnWindow({}, function(aNormalWindow) { |
michael@0 | 25 | testOnWindow({private: true}, function(aPrivateWindow) { |
michael@0 | 26 | runTest(aPrivateWindow, aNormalWindow, false, function() { |
michael@0 | 27 | aNormalWindow.close(); |
michael@0 | 28 | aPrivateWindow.close(); |
michael@0 | 29 | testOnWindow({private: true}, function(aPrivateWindow) { |
michael@0 | 30 | runTest(aPrivateWindow, aPrivateWindow, false, function() { |
michael@0 | 31 | aPrivateWindow.close(); |
michael@0 | 32 | testOnWindow({}, function(aNormalWindow) { |
michael@0 | 33 | runTest(aNormalWindow, aNormalWindow, true, function() { |
michael@0 | 34 | aNormalWindow.close(); |
michael@0 | 35 | finish(); |
michael@0 | 36 | }); |
michael@0 | 37 | }); |
michael@0 | 38 | }); |
michael@0 | 39 | }); |
michael@0 | 40 | }); |
michael@0 | 41 | }); |
michael@0 | 42 | }); |
michael@0 | 43 | }); |
michael@0 | 44 | }); |
michael@0 | 45 | }); |
michael@0 | 46 | |
michael@0 | 47 | function runTest(aSourceWindow, aDestWindow, aExpectSuccess, aCallback) { |
michael@0 | 48 | // Open the base tab |
michael@0 | 49 | let baseTab = aSourceWindow.gBrowser.addTab(testURL); |
michael@0 | 50 | baseTab.linkedBrowser.addEventListener("load", function() { |
michael@0 | 51 | // Wait for the tab to be fully loaded so matching happens correctly |
michael@0 | 52 | if (baseTab.linkedBrowser.currentURI.spec == "about:blank") |
michael@0 | 53 | return; |
michael@0 | 54 | baseTab.linkedBrowser.removeEventListener("load", arguments.callee, true); |
michael@0 | 55 | |
michael@0 | 56 | let testTab = aDestWindow.gBrowser.addTab(); |
michael@0 | 57 | |
michael@0 | 58 | waitForFocus(function() { |
michael@0 | 59 | // Select the testTab |
michael@0 | 60 | aDestWindow.gBrowser.selectedTab = testTab; |
michael@0 | 61 | |
michael@0 | 62 | // Ensure that this tab has no history entries |
michael@0 | 63 | ok(testTab.linkedBrowser.sessionHistory.count < 2, |
michael@0 | 64 | "The test tab has 1 or less history entries"); |
michael@0 | 65 | // Ensure that this tab is on about:blank |
michael@0 | 66 | is(testTab.linkedBrowser.currentURI.spec, "about:blank", |
michael@0 | 67 | "The test tab is on about:blank"); |
michael@0 | 68 | // Ensure that this tab's document has no child nodes |
michael@0 | 69 | ok(!testTab.linkedBrowser.contentDocument.body.hasChildNodes(), |
michael@0 | 70 | "The test tab has no child nodes"); |
michael@0 | 71 | ok(!testTab.hasAttribute("busy"), |
michael@0 | 72 | "The test tab doesn't have the busy attribute"); |
michael@0 | 73 | |
michael@0 | 74 | // Set the urlbar to include the moz-action |
michael@0 | 75 | aDestWindow.gURLBar.value = "moz-action:switchtab," + testURL; |
michael@0 | 76 | // Focus the urlbar so we can press enter |
michael@0 | 77 | aDestWindow.gURLBar.focus(); |
michael@0 | 78 | |
michael@0 | 79 | // We want to see if the switchtab action works. If it does, the |
michael@0 | 80 | // current tab will get closed, and that's what we detect with the |
michael@0 | 81 | // TabClose handler. If pressing enter triggers a load in that tab, |
michael@0 | 82 | // then the load handler will get called. Neither of these are |
michael@0 | 83 | // the desired effect here. So if the test goes successfully, it is |
michael@0 | 84 | // the timeout handler which gets called. |
michael@0 | 85 | // |
michael@0 | 86 | // The reason that we can't avoid the timeout here is because we are |
michael@0 | 87 | // trying to test something which should not happen, so we just need |
michael@0 | 88 | // to wait for a while and then check whether any bad things have |
michael@0 | 89 | // happened. |
michael@0 | 90 | |
michael@0 | 91 | function onTabClose(aEvent) { |
michael@0 | 92 | aDestWindow.gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, false); |
michael@0 | 93 | aDestWindow.gBrowser.removeEventListener("load", onLoad, false); |
michael@0 | 94 | clearTimeout(timeout); |
michael@0 | 95 | // Should only happen when we expect success |
michael@0 | 96 | ok(aExpectSuccess, "Tab closed as expected"); |
michael@0 | 97 | aCallback(); |
michael@0 | 98 | } |
michael@0 | 99 | function onLoad(aEvent) { |
michael@0 | 100 | aDestWindow.gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, false); |
michael@0 | 101 | aDestWindow.gBrowser.removeEventListener("load", onLoad, false); |
michael@0 | 102 | clearTimeout(timeout); |
michael@0 | 103 | // Should only happen when we expect success |
michael@0 | 104 | ok(aExpectSuccess, "Tab loaded as expected"); |
michael@0 | 105 | aCallback(); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | aDestWindow.gBrowser.tabContainer.addEventListener("TabClose", onTabClose, false); |
michael@0 | 109 | aDestWindow.gBrowser.addEventListener("load", onLoad, false); |
michael@0 | 110 | let timeout = setTimeout(function() { |
michael@0 | 111 | aDestWindow.gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, false); |
michael@0 | 112 | aDestWindow.gBrowser.removeEventListener("load", onLoad, false); |
michael@0 | 113 | aCallback(); |
michael@0 | 114 | }, 500); |
michael@0 | 115 | |
michael@0 | 116 | // Press enter! |
michael@0 | 117 | EventUtils.synthesizeKey("VK_RETURN", {}); |
michael@0 | 118 | }, aDestWindow); |
michael@0 | 119 | }, true); |
michael@0 | 120 | } |
michael@0 | 121 | } |
michael@0 | 122 |