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 add_task(function* test_switchtab_override() {
6 let testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html";
8 info("Opening first tab");
9 let tab = gBrowser.addTab(testURL);
10 let deferred = Promise.defer();
11 whenTabLoaded(tab, deferred.resolve);
12 yield deferred.promise;
14 info("Opening and selecting second tab");
15 let secondTab = gBrowser.selectedTab = gBrowser.addTab();
16 registerCleanupFunction(() => {
17 try {
18 gBrowser.removeTab(tab);
19 gBrowser.removeTab(secondTab);
20 } catch(ex) { /* tabs may have already been closed in case of failure */ }
21 });
23 info("Wait for autocomplete")
24 deferred = Promise.defer();
25 let onSearchComplete = gURLBar.onSearchComplete;
26 registerCleanupFunction(() => {
27 gURLBar.onSearchComplete = onSearchComplete;
28 });
29 gURLBar.onSearchComplete = function () {
30 ok(gURLBar.popupOpen, "The autocomplete popup is correctly open");
31 onSearchComplete.apply(gURLBar);
32 deferred.resolve();
33 }
35 gURLBar.focus();
36 gURLBar.value = "dummy_pag";
37 EventUtils.synthesizeKey("e" , {});
38 yield deferred.promise;
40 info("Select first autocomplete popup entry");
41 EventUtils.synthesizeKey("VK_DOWN" , {});
42 ok(/moz-action:switchtab/.test(gURLBar.value), "switch to tab entry found");
44 info("Override switch-to-tab");
45 let deferred = Promise.defer();
46 // In case of failure this would switch tab.
47 let onTabSelect = event => {
48 deferred.reject(new Error("Should have overridden switch to tab"));
49 };
50 gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect, false);
51 registerCleanupFunction(() => {
52 gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect, false);
53 });
54 // Otherwise it would load the page.
55 whenTabLoaded(secondTab, deferred.resolve);
57 EventUtils.synthesizeKey("VK_SHIFT" , { type: "keydown" });
58 EventUtils.synthesizeKey("VK_RETURN" , { });
59 EventUtils.synthesizeKey("VK_SHIFT" , { type: "keyup" });
60 yield deferred.promise;
62 yield promiseClearHistory();
63 });