michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: let testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html"; michael@0: let tabSelected = false; michael@0: michael@0: // Open the base tab michael@0: let baseTab = gBrowser.addTab(testURL); michael@0: baseTab.linkedBrowser.addEventListener("load", function() { michael@0: // Wait for the tab to be fully loaded so matching happens correctly michael@0: if (baseTab.linkedBrowser.currentURI.spec == "about:blank") michael@0: return; michael@0: baseTab.linkedBrowser.removeEventListener("load", arguments.callee, true); michael@0: michael@0: let testTab = gBrowser.addTab(); michael@0: michael@0: // Select the testTab michael@0: gBrowser.selectedTab = testTab; michael@0: michael@0: // Ensure that this tab has no history entries michael@0: ok(testTab.linkedBrowser.sessionHistory.count < 2, michael@0: "The test tab has 1 or less history entries"); michael@0: // Ensure that this tab is on about:blank michael@0: is(testTab.linkedBrowser.currentURI.spec, "about:blank", michael@0: "The test tab is on about:blank"); michael@0: // Ensure that this tab's document has no child nodes michael@0: ok(!testTab.linkedBrowser.contentDocument.body.hasChildNodes(), michael@0: "The test tab has no child nodes"); michael@0: ok(!testTab.hasAttribute("busy"), michael@0: "The test tab doesn't have the busy attribute"); michael@0: michael@0: // Set the urlbar to include the moz-action michael@0: gURLBar.value = "moz-action:switchtab," + testURL; michael@0: // Focus the urlbar so we can press enter michael@0: gURLBar.focus(); michael@0: michael@0: // Functions for TabClose and TabSelect michael@0: function onTabClose(aEvent) { michael@0: gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, false); michael@0: // Make sure we get the TabClose event for testTab michael@0: is(aEvent.originalTarget, testTab, "Got the TabClose event for the right tab"); michael@0: // Confirm that we did select the tab michael@0: ok(tabSelected, "Confirming that the tab was selected"); michael@0: gBrowser.removeTab(baseTab); michael@0: finish(); michael@0: } michael@0: function onTabSelect(aEvent) { michael@0: gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect, false); michael@0: // Make sure we got the TabSelect event for baseTab michael@0: is(aEvent.originalTarget, baseTab, "Got the TabSelect event for the right tab"); michael@0: // Confirm that the selected tab is in fact base tab michael@0: is(gBrowser.selectedTab, baseTab, "We've switched to the correct tab"); michael@0: tabSelected = true; michael@0: } michael@0: michael@0: // Add the TabClose, TabSelect event listeners before we press enter michael@0: gBrowser.tabContainer.addEventListener("TabClose", onTabClose, false); michael@0: gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect, false); michael@0: michael@0: // Press enter! michael@0: EventUtils.synthesizeKey("VK_RETURN", {}); michael@0: }, true); michael@0: } michael@0: