1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug1003461-switchtab-override.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +add_task(function* test_switchtab_override() { 1.9 + let testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; 1.10 + 1.11 + info("Opening first tab"); 1.12 + let tab = gBrowser.addTab(testURL); 1.13 + let deferred = Promise.defer(); 1.14 + whenTabLoaded(tab, deferred.resolve); 1.15 + yield deferred.promise; 1.16 + 1.17 + info("Opening and selecting second tab"); 1.18 + let secondTab = gBrowser.selectedTab = gBrowser.addTab(); 1.19 + registerCleanupFunction(() => { 1.20 + try { 1.21 + gBrowser.removeTab(tab); 1.22 + gBrowser.removeTab(secondTab); 1.23 + } catch(ex) { /* tabs may have already been closed in case of failure */ } 1.24 + }); 1.25 + 1.26 + info("Wait for autocomplete") 1.27 + deferred = Promise.defer(); 1.28 + let onSearchComplete = gURLBar.onSearchComplete; 1.29 + registerCleanupFunction(() => { 1.30 + gURLBar.onSearchComplete = onSearchComplete; 1.31 + }); 1.32 + gURLBar.onSearchComplete = function () { 1.33 + ok(gURLBar.popupOpen, "The autocomplete popup is correctly open"); 1.34 + onSearchComplete.apply(gURLBar); 1.35 + deferred.resolve(); 1.36 + } 1.37 + 1.38 + gURLBar.focus(); 1.39 + gURLBar.value = "dummy_pag"; 1.40 + EventUtils.synthesizeKey("e" , {}); 1.41 + yield deferred.promise; 1.42 + 1.43 + info("Select first autocomplete popup entry"); 1.44 + EventUtils.synthesizeKey("VK_DOWN" , {}); 1.45 + ok(/moz-action:switchtab/.test(gURLBar.value), "switch to tab entry found"); 1.46 + 1.47 + info("Override switch-to-tab"); 1.48 + let deferred = Promise.defer(); 1.49 + // In case of failure this would switch tab. 1.50 + let onTabSelect = event => { 1.51 + deferred.reject(new Error("Should have overridden switch to tab")); 1.52 + }; 1.53 + gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect, false); 1.54 + registerCleanupFunction(() => { 1.55 + gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect, false); 1.56 + }); 1.57 + // Otherwise it would load the page. 1.58 + whenTabLoaded(secondTab, deferred.resolve); 1.59 + 1.60 + EventUtils.synthesizeKey("VK_SHIFT" , { type: "keydown" }); 1.61 + EventUtils.synthesizeKey("VK_RETURN" , { }); 1.62 + EventUtils.synthesizeKey("VK_SHIFT" , { type: "keyup" }); 1.63 + yield deferred.promise; 1.64 + 1.65 + yield promiseClearHistory(); 1.66 +});