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