michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let newWindows = []; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: let windowOne = openDialog(location, "", "chrome,all,dialog=no", "data:text/html,"); michael@0: let windowTwo; michael@0: michael@0: whenWindowLoaded(windowOne, function () { michael@0: windowOne.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { michael@0: windowOne.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); michael@0: michael@0: windowTwo = openDialog(location, "", "chrome,all,dialog=no", "http://mochi.test:8888/"); michael@0: whenWindowLoaded(windowTwo, function () { michael@0: windowTwo.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { michael@0: windowTwo.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); michael@0: michael@0: newWindows = [ windowOne, windowTwo ]; michael@0: michael@0: // show the tab view michael@0: window.addEventListener("tabviewshown", onTabViewWindowLoaded, false); michael@0: ok(!TabView.isVisible(), "Tab View is hidden"); michael@0: TabView.toggle(); michael@0: }, true); michael@0: }); michael@0: }, true); michael@0: }); michael@0: } michael@0: michael@0: function onTabViewWindowLoaded() { michael@0: window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false); michael@0: ok(TabView.isVisible(), "Tab View is visible"); michael@0: michael@0: let contentWindow = document.getElementById("tab-view").contentWindow; michael@0: let search = contentWindow.document.getElementById("search"); michael@0: let searchButton = contentWindow.document.getElementById("searchbutton"); michael@0: michael@0: ok(searchButton, "Search button exists"); michael@0: michael@0: let onSearchEnabled = function() { michael@0: ok(search.style.display != "none", "Search is enabled"); michael@0: contentWindow.removeEventListener( michael@0: "tabviewsearchenabled", onSearchEnabled, false); michael@0: searchTest(contentWindow); michael@0: } michael@0: contentWindow.addEventListener("tabviewsearchenabled", onSearchEnabled, false); michael@0: // enter search mode michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, searchButton, contentWindow); michael@0: } michael@0: michael@0: // conveniently combine local and other window tab results from a query michael@0: function getMatchResults(contentWindow, query) { michael@0: let matcher = new contentWindow.TabMatcher(query); michael@0: let localMatchResults = matcher.matched(); michael@0: let otherMatchResults = matcher.matchedTabsFromOtherWindows(); michael@0: return localMatchResults.concat(otherMatchResults); michael@0: } michael@0: michael@0: function searchTest(contentWindow) { michael@0: let searchBox = contentWindow.document.getElementById("searchbox"); michael@0: let matcher = null; michael@0: let matchResults = []; michael@0: michael@0: // get the titles of tabs. michael@0: let tabNames = []; michael@0: michael@0: let tabItems = contentWindow.TabItems.getItems(); michael@0: is(tabItems.length, 1, "Have only one tab in the current window's tab items"); michael@0: tabItems.forEach(function(tab) { michael@0: tabNames.push(tab.$tabTitle[0].innerHTML); michael@0: }); michael@0: michael@0: newWindows.forEach(function(win) { michael@0: for(var i=0; i 2, michael@0: "The title of tab item is longer than 2 chars") michael@0: michael@0: // empty string michael@0: searchBox.setAttribute("value", ""); michael@0: matchResults = getMatchResults(contentWindow, searchBox.getAttribute("value")); michael@0: ok(matchResults.length == 0, "Match nothing if it's an empty string"); michael@0: michael@0: // one char michael@0: searchBox.setAttribute("value", tabNames[0].charAt(0)); michael@0: matchResults = getMatchResults(contentWindow, searchBox.getAttribute("value")); michael@0: ok(matchResults.length == 0, michael@0: "Match nothing if the length of search term is less than 2"); michael@0: michael@0: // the full title michael@0: searchBox.setAttribute("value", tabNames[2]); michael@0: matchResults = getMatchResults(contentWindow, searchBox.getAttribute("value")); michael@0: is(matchResults.length, 1, michael@0: "Match something when the whole title exists"); michael@0: michael@0: // part of titled michael@0: searchBox.setAttribute("value", tabNames[0].substr(1)); michael@0: contentWindow.Search.perform(); michael@0: matchResults = getMatchResults(contentWindow, searchBox.getAttribute("value")); michael@0: is(matchResults.length, 1, michael@0: "Match something when a part of title exists"); michael@0: michael@0: cleanup(contentWindow); michael@0: } michael@0: michael@0: function cleanup(contentWindow) { michael@0: contentWindow.Search.hide(null); michael@0: michael@0: let onTabViewHidden = function() { michael@0: window.removeEventListener("tabviewhidden", onTabViewHidden, false); michael@0: ok(!TabView.isVisible(), "Tab View is hidden"); michael@0: let numToClose = newWindows.length; michael@0: newWindows.forEach(function(win) { michael@0: whenWindowObservesOnce(win, "domwindowclosed", function() { michael@0: --numToClose; michael@0: if(numToClose==0) { michael@0: finish(); michael@0: } michael@0: }); michael@0: win.close(); michael@0: }); michael@0: } michael@0: window.addEventListener("tabviewhidden", onTabViewHidden, false); michael@0: EventUtils.synthesizeKey("VK_RETURN", {}); michael@0: } michael@0: michael@0: function whenWindowObservesOnce(win, topic, func) { michael@0: let windowWatcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] michael@0: .getService(Components.interfaces.nsIWindowWatcher); michael@0: let origWin = win; michael@0: let origTopic = topic; michael@0: let origFunc = func; michael@0: function windowObserver(aSubject, aTopic, aData) { michael@0: let theWin = aSubject.QueryInterface(Ci.nsIDOMWindow); michael@0: if (origWin && theWin != origWin) michael@0: return; michael@0: if(aTopic == origTopic) { michael@0: windowWatcher.unregisterNotification(windowObserver); michael@0: origFunc.apply(this, []); michael@0: } michael@0: } michael@0: windowWatcher.registerNotification(windowObserver); michael@0: }