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 newTabs = []; |
michael@0 | 5 | |
michael@0 | 6 | // ---------- |
michael@0 | 7 | function test() { |
michael@0 | 8 | waitForExplicitFinish(); |
michael@0 | 9 | |
michael@0 | 10 | // set up our tabs |
michael@0 | 11 | let urlBase = "http://mochi.test:8888/browser/browser/components/tabview/test/"; |
michael@0 | 12 | let tabOne = gBrowser.addTab(urlBase + "search1.html"); |
michael@0 | 13 | let tabTwo = gBrowser.addTab(urlBase + "search2.html"); |
michael@0 | 14 | newTabs = [ tabOne, tabTwo ]; |
michael@0 | 15 | |
michael@0 | 16 | // make sure our tabs are loaded so their titles are right |
michael@0 | 17 | let stillToLoad = 0; |
michael@0 | 18 | let onLoad = function() { |
michael@0 | 19 | this.removeEventListener("load", onLoad, true); |
michael@0 | 20 | |
michael@0 | 21 | stillToLoad--; |
michael@0 | 22 | if (!stillToLoad) { |
michael@0 | 23 | // show the tab view |
michael@0 | 24 | window.addEventListener("tabviewshown", onTabViewWindowLoaded, false); |
michael@0 | 25 | ok(!TabView.isVisible(), "Tab View is hidden"); |
michael@0 | 26 | TabView.toggle(); |
michael@0 | 27 | } |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | newTabs.forEach(function(tab) { |
michael@0 | 31 | stillToLoad++; |
michael@0 | 32 | gBrowser.getBrowserForTab(tab).addEventListener("load", onLoad, true); |
michael@0 | 33 | }); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | // ---------- |
michael@0 | 37 | function onTabViewWindowLoaded() { |
michael@0 | 38 | window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false); |
michael@0 | 39 | ok(TabView.isVisible(), "Tab View is visible"); |
michael@0 | 40 | |
michael@0 | 41 | let contentWindow = document.getElementById("tab-view").contentWindow; |
michael@0 | 42 | let search = contentWindow.document.getElementById("search"); |
michael@0 | 43 | let searchButton = contentWindow.document.getElementById("searchbutton"); |
michael@0 | 44 | |
michael@0 | 45 | ok(searchButton, "Search button exists"); |
michael@0 | 46 | |
michael@0 | 47 | let onSearchEnabled = function() { |
michael@0 | 48 | contentWindow.removeEventListener( |
michael@0 | 49 | "tabviewsearchenabled", onSearchEnabled, false); |
michael@0 | 50 | |
michael@0 | 51 | ok(search.style.display != "none", "Search is enabled"); |
michael@0 | 52 | |
michael@0 | 53 | let searchBox = contentWindow.document.getElementById("searchbox"); |
michael@0 | 54 | ok(contentWindow.document.hasFocus() && |
michael@0 | 55 | contentWindow.document.activeElement == searchBox, |
michael@0 | 56 | "The search box has focus"); |
michael@0 | 57 | |
michael@0 | 58 | searchTest(contentWindow); |
michael@0 | 59 | } |
michael@0 | 60 | contentWindow.addEventListener("tabviewsearchenabled", onSearchEnabled, false); |
michael@0 | 61 | // enter search mode |
michael@0 | 62 | EventUtils.sendMouseEvent({ type: "mousedown" }, searchButton, contentWindow); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | // ---------- |
michael@0 | 66 | function searchTest(contentWindow) { |
michael@0 | 67 | let searchBox = contentWindow.document.getElementById("searchbox"); |
michael@0 | 68 | |
michael@0 | 69 | // force an update to make sure the correct titles are in the TabItems |
michael@0 | 70 | let tabItems = contentWindow.TabItems.getItems(); |
michael@0 | 71 | ok(tabItems.length == 3, "Have three tab items"); |
michael@0 | 72 | tabItems.forEach(function(tabItem) { |
michael@0 | 73 | contentWindow.TabItems._update(tabItem.tab); |
michael@0 | 74 | }); |
michael@0 | 75 | |
michael@0 | 76 | // empty string |
michael@0 | 77 | searchBox.setAttribute("value", ""); |
michael@0 | 78 | is(new contentWindow.TabMatcher( |
michael@0 | 79 | searchBox.getAttribute("value")).matched().length, 0, |
michael@0 | 80 | "Match nothing if it's an empty string"); |
michael@0 | 81 | |
michael@0 | 82 | // one char |
michael@0 | 83 | searchBox.setAttribute("value", "s"); |
michael@0 | 84 | is(new contentWindow.TabMatcher( |
michael@0 | 85 | searchBox.getAttribute("value")).matched().length, 0, |
michael@0 | 86 | "Match nothing if the length of search term is less than 2"); |
michael@0 | 87 | |
michael@0 | 88 | // the full title |
michael@0 | 89 | searchBox.setAttribute("value", "search test 1"); |
michael@0 | 90 | is(new contentWindow.TabMatcher( |
michael@0 | 91 | searchBox.getAttribute("value")).matched().length, 1, |
michael@0 | 92 | "Match something when the whole title exists"); |
michael@0 | 93 | |
michael@0 | 94 | // part of title |
michael@0 | 95 | searchBox.setAttribute("value", "search"); |
michael@0 | 96 | contentWindow.Search.perform(); |
michael@0 | 97 | is(new contentWindow.TabMatcher( |
michael@0 | 98 | searchBox.getAttribute("value")).matched().length, 2, |
michael@0 | 99 | "Match something when a part of title exists"); |
michael@0 | 100 | |
michael@0 | 101 | // unique part of a url |
michael@0 | 102 | searchBox.setAttribute("value", "search1.html"); |
michael@0 | 103 | contentWindow.Search.perform(); |
michael@0 | 104 | is(new contentWindow.TabMatcher( |
michael@0 | 105 | searchBox.getAttribute("value")).matched().length, 1, |
michael@0 | 106 | "Match something when a unique part of a url exists"); |
michael@0 | 107 | |
michael@0 | 108 | // common part of a url |
michael@0 | 109 | searchBox.setAttribute("value", "tabview"); |
michael@0 | 110 | contentWindow.Search.perform(); |
michael@0 | 111 | is(new contentWindow.TabMatcher( |
michael@0 | 112 | searchBox.getAttribute("value")).matched().length, 2, |
michael@0 | 113 | "Match something when a common part of a url exists"); |
michael@0 | 114 | |
michael@0 | 115 | cleanup(contentWindow); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | // ---------- |
michael@0 | 119 | function cleanup(contentWindow) { |
michael@0 | 120 | contentWindow.Search.hide(null); |
michael@0 | 121 | let onTabViewHidden = function() { |
michael@0 | 122 | window.removeEventListener("tabviewhidden", onTabViewHidden, false); |
michael@0 | 123 | ok(!TabView.isVisible(), "Tab View is hidden"); |
michael@0 | 124 | |
michael@0 | 125 | gBrowser.removeTab(newTabs[0]); |
michael@0 | 126 | gBrowser.removeTab(newTabs[1]); |
michael@0 | 127 | |
michael@0 | 128 | finish(); |
michael@0 | 129 | } |
michael@0 | 130 | window.addEventListener("tabviewhidden", onTabViewHidden, false); |
michael@0 | 131 | EventUtils.synthesizeKey("VK_RETURN", {}); |
michael@0 | 132 | } |