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.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | let newWindows = []; |
michael@0 | 5 | |
michael@0 | 6 | function test() { |
michael@0 | 7 | waitForExplicitFinish(); |
michael@0 | 8 | let windowOne = openDialog(location, "", "chrome,all,dialog=no", "data:text/html,"); |
michael@0 | 9 | let windowTwo; |
michael@0 | 10 | |
michael@0 | 11 | whenWindowLoaded(windowOne, function () { |
michael@0 | 12 | windowOne.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
michael@0 | 13 | windowOne.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
michael@0 | 14 | |
michael@0 | 15 | windowTwo = openDialog(location, "", "chrome,all,dialog=no", "http://mochi.test:8888/"); |
michael@0 | 16 | whenWindowLoaded(windowTwo, function () { |
michael@0 | 17 | windowTwo.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
michael@0 | 18 | windowTwo.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
michael@0 | 19 | |
michael@0 | 20 | newWindows = [ windowOne, windowTwo ]; |
michael@0 | 21 | |
michael@0 | 22 | // show the tab view |
michael@0 | 23 | window.addEventListener("tabviewshown", onTabViewWindowLoaded, false); |
michael@0 | 24 | ok(!TabView.isVisible(), "Tab View is hidden"); |
michael@0 | 25 | TabView.toggle(); |
michael@0 | 26 | }, true); |
michael@0 | 27 | }); |
michael@0 | 28 | }, true); |
michael@0 | 29 | }); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function onTabViewWindowLoaded() { |
michael@0 | 33 | window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false); |
michael@0 | 34 | ok(TabView.isVisible(), "Tab View is visible"); |
michael@0 | 35 | |
michael@0 | 36 | let contentWindow = document.getElementById("tab-view").contentWindow; |
michael@0 | 37 | let search = contentWindow.document.getElementById("search"); |
michael@0 | 38 | let searchButton = contentWindow.document.getElementById("searchbutton"); |
michael@0 | 39 | |
michael@0 | 40 | ok(searchButton, "Search button exists"); |
michael@0 | 41 | |
michael@0 | 42 | let onSearchEnabled = function() { |
michael@0 | 43 | ok(search.style.display != "none", "Search is enabled"); |
michael@0 | 44 | contentWindow.removeEventListener( |
michael@0 | 45 | "tabviewsearchenabled", onSearchEnabled, false); |
michael@0 | 46 | searchTest(contentWindow); |
michael@0 | 47 | } |
michael@0 | 48 | contentWindow.addEventListener("tabviewsearchenabled", onSearchEnabled, false); |
michael@0 | 49 | // enter search mode |
michael@0 | 50 | EventUtils.sendMouseEvent({ type: "mousedown" }, searchButton, contentWindow); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | // conveniently combine local and other window tab results from a query |
michael@0 | 54 | function getMatchResults(contentWindow, query) { |
michael@0 | 55 | let matcher = new contentWindow.TabMatcher(query); |
michael@0 | 56 | let localMatchResults = matcher.matched(); |
michael@0 | 57 | let otherMatchResults = matcher.matchedTabsFromOtherWindows(); |
michael@0 | 58 | return localMatchResults.concat(otherMatchResults); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function searchTest(contentWindow) { |
michael@0 | 62 | let searchBox = contentWindow.document.getElementById("searchbox"); |
michael@0 | 63 | let matcher = null; |
michael@0 | 64 | let matchResults = []; |
michael@0 | 65 | |
michael@0 | 66 | // get the titles of tabs. |
michael@0 | 67 | let tabNames = []; |
michael@0 | 68 | |
michael@0 | 69 | let tabItems = contentWindow.TabItems.getItems(); |
michael@0 | 70 | is(tabItems.length, 1, "Have only one tab in the current window's tab items"); |
michael@0 | 71 | tabItems.forEach(function(tab) { |
michael@0 | 72 | tabNames.push(tab.$tabTitle[0].innerHTML); |
michael@0 | 73 | }); |
michael@0 | 74 | |
michael@0 | 75 | newWindows.forEach(function(win) { |
michael@0 | 76 | for(var i=0; i<win.gBrowser.tabs.length; ++i) { |
michael@0 | 77 | tabNames.push(win.gBrowser.tabs[i].label); |
michael@0 | 78 | } |
michael@0 | 79 | }); |
michael@0 | 80 | |
michael@0 | 81 | ok(tabNames[0] && tabNames[0].length > 2, |
michael@0 | 82 | "The title of tab item is longer than 2 chars") |
michael@0 | 83 | |
michael@0 | 84 | // empty string |
michael@0 | 85 | searchBox.setAttribute("value", ""); |
michael@0 | 86 | matchResults = getMatchResults(contentWindow, searchBox.getAttribute("value")); |
michael@0 | 87 | ok(matchResults.length == 0, "Match nothing if it's an empty string"); |
michael@0 | 88 | |
michael@0 | 89 | // one char |
michael@0 | 90 | searchBox.setAttribute("value", tabNames[0].charAt(0)); |
michael@0 | 91 | matchResults = getMatchResults(contentWindow, searchBox.getAttribute("value")); |
michael@0 | 92 | ok(matchResults.length == 0, |
michael@0 | 93 | "Match nothing if the length of search term is less than 2"); |
michael@0 | 94 | |
michael@0 | 95 | // the full title |
michael@0 | 96 | searchBox.setAttribute("value", tabNames[2]); |
michael@0 | 97 | matchResults = getMatchResults(contentWindow, searchBox.getAttribute("value")); |
michael@0 | 98 | is(matchResults.length, 1, |
michael@0 | 99 | "Match something when the whole title exists"); |
michael@0 | 100 | |
michael@0 | 101 | // part of titled |
michael@0 | 102 | searchBox.setAttribute("value", tabNames[0].substr(1)); |
michael@0 | 103 | contentWindow.Search.perform(); |
michael@0 | 104 | matchResults = getMatchResults(contentWindow, searchBox.getAttribute("value")); |
michael@0 | 105 | is(matchResults.length, 1, |
michael@0 | 106 | "Match something when a part of title exists"); |
michael@0 | 107 | |
michael@0 | 108 | cleanup(contentWindow); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | function cleanup(contentWindow) { |
michael@0 | 112 | contentWindow.Search.hide(null); |
michael@0 | 113 | |
michael@0 | 114 | let onTabViewHidden = function() { |
michael@0 | 115 | window.removeEventListener("tabviewhidden", onTabViewHidden, false); |
michael@0 | 116 | ok(!TabView.isVisible(), "Tab View is hidden"); |
michael@0 | 117 | let numToClose = newWindows.length; |
michael@0 | 118 | newWindows.forEach(function(win) { |
michael@0 | 119 | whenWindowObservesOnce(win, "domwindowclosed", function() { |
michael@0 | 120 | --numToClose; |
michael@0 | 121 | if(numToClose==0) { |
michael@0 | 122 | finish(); |
michael@0 | 123 | } |
michael@0 | 124 | }); |
michael@0 | 125 | win.close(); |
michael@0 | 126 | }); |
michael@0 | 127 | } |
michael@0 | 128 | window.addEventListener("tabviewhidden", onTabViewHidden, false); |
michael@0 | 129 | EventUtils.synthesizeKey("VK_RETURN", {}); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | function whenWindowObservesOnce(win, topic, func) { |
michael@0 | 133 | let windowWatcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] |
michael@0 | 134 | .getService(Components.interfaces.nsIWindowWatcher); |
michael@0 | 135 | let origWin = win; |
michael@0 | 136 | let origTopic = topic; |
michael@0 | 137 | let origFunc = func; |
michael@0 | 138 | function windowObserver(aSubject, aTopic, aData) { |
michael@0 | 139 | let theWin = aSubject.QueryInterface(Ci.nsIDOMWindow); |
michael@0 | 140 | if (origWin && theWin != origWin) |
michael@0 | 141 | return; |
michael@0 | 142 | if(aTopic == origTopic) { |
michael@0 | 143 | windowWatcher.unregisterNotification(windowObserver); |
michael@0 | 144 | origFunc.apply(this, []); |
michael@0 | 145 | } |
michael@0 | 146 | } |
michael@0 | 147 | windowWatcher.registerNotification(windowObserver); |
michael@0 | 148 | } |