browser/base/content/test/general/browser_bug1003461-switchtab-override.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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

mercurial