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 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* Any copyright is dedicated to the Public Domain.
4 http://creativecommons.org/publicdomain/zero/1.0/ */
6 "use strict";
8 function test() {
9 runTests();
10 }
12 function doEdgeUIGesture() {
13 let event = document.createEvent("Events");
14 event.initEvent("MozEdgeUICompleted", true, false);
15 window.dispatchEvent(event);
16 }
18 function fireTabURLChanged(tab, hasLocationChanged) {
19 let urlChangedEvent = document.createEvent("UIEvents");
20 urlChangedEvent.initUIEvent("URLChanged", true, false, window,
21 hasLocationChanged);
22 tab.browser.dispatchEvent(urlChangedEvent);
23 }
25 function getpage(idx) {
26 return "http://mochi.test:8888/metro/browser/metro/base/tests/mochitest/" + "res/blankpage" + idx + ".html";
27 }
29 gTests.push({
30 desc: "Context UI on about:start",
31 run: function testAboutStart() {
32 let tab = yield addTab("about:start");
34 yield waitForCondition(function () {
35 return BrowserUI.isStartTabVisible;
36 });
38 is(BrowserUI.isStartTabVisible, true, "Start UI is displayed on about:start");
39 is(ContextUI.navbarVisible, true, "Navbar is displayed on about:start");
40 is(ContextUI.tabbarVisible, false, "Tabbar is not displayed initially");
41 is(ContextUI.contextAppbarVisible, false, "Appbar is not displayed initially");
43 // toggle on
44 doEdgeUIGesture();
45 is(ContextUI.navbarVisible, true, "Navbar is still visible after one swipe");
46 is(ContextUI.tabbarVisible, true, "Tabbar is visible after one swipe");
47 is(ContextUI.contextAppbarVisible, false, "Appbar is hidden after one swipe");
49 // toggle off
50 doEdgeUIGesture();
51 is(ContextUI.navbarVisible, true, "Navbar is still visible after second swipe");
52 is(ContextUI.tabbarVisible, false, "Tabbar is hidden after second swipe");
53 is(ContextUI.contextAppbarVisible, false, "Appbar is hidden after second swipe");
55 // sanity check - toggle on again
56 doEdgeUIGesture();
57 is(ContextUI.navbarVisible, true, "Navbar is still visible after third swipe");
58 is(ContextUI.tabbarVisible, true, "Tabbar is visible after third swipe");
59 is(ContextUI.contextAppbarVisible, false, "Appbar is hidden after third swipe");
61 is(BrowserUI.isStartTabVisible, true, "Start UI is still visible");
63 Browser.closeTab(tab, { forceClose: true });
64 }
65 });
67 gTests.push({
68 desc: "Context UI on a web page (about:)",
69 run: function testAbout() {
70 let tab = yield addTab("about:");
71 ContextUI.dismiss();
72 is(BrowserUI.isStartTabVisible, false, "Start UI is not visible on about:");
73 is(ContextUI.navbarVisible, false, "Navbar is not initially visible on about:");
74 is(ContextUI.tabbarVisible, false, "Tabbar is not initially visible on about:");
76 doEdgeUIGesture();
77 is(ContextUI.navbarVisible, true, "Navbar is visible after one swipe");
78 is(ContextUI.tabbarVisible, true, "Tabbar is visble after one swipe");
80 doEdgeUIGesture();
81 is(ContextUI.navbarVisible, false, "Navbar is not visible after second swipe");
82 is(ContextUI.tabbarVisible, false, "Tabbar is not visible after second swipe");
84 is(BrowserUI.isStartTabVisible, false, "Start UI is still not visible");
86 Browser.closeTab(tab, { forceClose: true });
87 }
88 });
90 gTests.push({
91 desc: "Control-L keyboard shortcut",
92 run: function testAbout() {
93 let tab = yield addTab("about:");
94 ContextUI.dismiss();
95 is(ContextUI.navbarVisible, false, "Navbar is not initially visible");
96 is(ContextUI.tabbarVisible, false, "Tab bar is not initially visible");
98 EventUtils.synthesizeKey('l', { accelKey: true });
99 is(ContextUI.navbarVisible, true, "Navbar is visible");
100 is(ContextUI.tabbarVisible, false, "Tab bar is not visible");
102 let edit = document.getElementById("urlbar-edit");
103 is(edit.value, "about:", "Location field contains the page URL");
104 ok(document.commandDispatcher.focusedElement, edit.inputField, "Location field is focused");
105 is(edit.selectionStart, 0, "Location field is selected");
106 is(edit.selectionEnd, edit.value.length, "Location field is selected");
108 edit.selectionEnd = 0;
109 is(edit.selectionStart, 0, "Location field is unselected");
110 is(edit.selectionEnd, 0, "Location field is unselected");
112 EventUtils.synthesizeKey('l', { accelKey: true });
113 is(edit.selectionStart, 0, "Location field is selected again");
114 is(edit.selectionEnd, edit.value.length, "Location field is selected again");
116 Browser.closeTab(tab, { forceClose: true });
117 }
118 });
120 gTests.push({
121 desc: "taps vs context ui dismissal",
122 run: function () {
123 // off by default
124 InputSourceHelper.isPrecise = false;
125 InputSourceHelper.fireUpdate();
127 let tab = yield addTab("about:mozilla");
129 ok(ContextUI.navbarVisible, "navbar visible after open");
131 let navButtonDisplayPromise = waitForEvent(NavButtonSlider.back, "transitionend");
133 yield loadUriInActiveTab(getpage(1));
135 is(tab.browser.currentURI.spec, getpage(1), getpage(1));
136 ok(ContextUI.navbarVisible, "navbar visible after navigate 1");
138 yield loadUriInActiveTab(getpage(2));
140 is(tab.browser.currentURI.spec, getpage(2), getpage(2));
141 ok(ContextUI.navbarVisible, "navbar visible after navigate 2");
143 yield loadUriInActiveTab(getpage(3));
145 is(tab.browser.currentURI.spec, getpage(3), getpage(3));
146 ok(ContextUI.navbarVisible, "navbar visible after navigate 3");
148 // These transition in after we navigate. If we click on one of
149 // them before they are visible they don't work, so wait for
150 // display to occur.
151 yield navButtonDisplayPromise;
153 yield navBackViaNavButton();
154 yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(2); }, "getpage(2)");
155 yield waitForCondition2(function () { return ContextUI.navbarVisible; }, "ContextUI.navbarVisible");
157 is(tab.browser.currentURI.spec, getpage(2), getpage(2));
159 yield navForward();
160 yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(3); }, "getpage(3)");
162 is(tab.browser.currentURI.spec, getpage(3), getpage(3));
163 ok(ContextUI.navbarVisible, "navbar visible after navigate");
165 doEdgeUIGesture();
167 is(ContextUI.navbarVisible, true, "Navbar is visible after swipe");
168 is(ContextUI.tabbarVisible, true, "Tabbar is visible after swipe");
170 yield navBackViaNavButton();
171 yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(2); }, "getpage(2)");
173 is(tab.browser.currentURI.spec, getpage(2), getpage(2));
174 is(ContextUI.navbarVisible, true, "Navbar is visible after navigating back (overlay)");
175 yield waitForCondition2(function () { return !ContextUI.tabbarVisible; }, "!ContextUI.tabbarVisible");
177 sendElementTap(window, window.document.documentElement);
178 yield waitForCondition2(function () { return !BrowserUI.navbarVisible; }, "!BrowserUI.navbarVisible");
180 is(ContextUI.tabbarVisible, false, "Tabbar is hidden after content tap");
182 yield navForward();
183 yield waitForCondition2(function () {
184 return tab.browser.currentURI.spec == getpage(3) && ContextUI.navbarVisible;
185 }, "getpage(3)");
187 is(tab.browser.currentURI.spec, getpage(3), getpage(3));
188 ok(ContextUI.navbarVisible, "navbar visible after navigate");
190 yield navBackViaNavButton();
191 yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(2); }, "getpage(2)");
192 yield waitForCondition2(function () { return !ContextUI.tabbarVisible; }, "!ContextUI.tabbarVisible");
194 is(tab.browser.currentURI.spec, getpage(2), getpage(2));
195 is(ContextUI.navbarVisible, true, "Navbar is visible after navigating back (overlay)");
197 ContextUI.dismiss();
199 let note = yield showNotification();
200 doEdgeUIGesture();
201 sendElementTap(window, note);
203 is(ContextUI.navbarVisible, true, "Navbar is visible after clicking notification close button");
205 removeNotifications();
207 Browser.closeTab(tab, { forceClose: true });
208 }
209 });
211 gTests.push({
212 desc: "Bug 907244 - Opening a new tab when the page has focus doesn't correctly focus the location bar",
213 run: function () {
214 let mozTab = yield addTab("about:mozilla");
216 // addTab will dismiss navbar, but lets check anyway.
217 ok(!ContextUI.navbarVisible, "navbar dismissed");
219 BrowserUI.doCommand("cmd_newTabKey");
220 let newTab = Browser.selectedTab;
221 yield newTab.pageShowPromise;
223 yield waitForCondition(() => ContextUI.navbarVisible);
224 ok(ContextUI.navbarVisible, "navbar visible");
226 let edit = document.getElementById("urlbar-edit");
228 ok(edit.focused, "Edit has focus");
230 // Lets traverse since node.contains() doesn't work for anonymous elements.
231 let parent = document.activeElement;
232 while(parent && parent != edit) {
233 parent = parent.parentNode;
234 }
236 ok(parent === edit, 'Active element is a descendant of urlbar');
238 Browser.closeTab(newTab, { forceClose: true });
239 Browser.closeTab(mozTab, { forceClose: true });
240 }
241 });
243 gTests.push({
244 desc: "Bug 933989 - New tab button in tab bar always sets focus to the url bar, triggering soft keyboard",
245 run: function () {
246 let mozTab = yield addTab("about:mozilla");
248 yield hideNavBar();
249 ok(!ContextUI.navbarVisible, "navbar dismissed");
251 BrowserUI.doCommand("cmd_newTab");
252 let newTab = Browser.selectedTab;
253 yield newTab.pageShowPromise;
255 yield waitForCondition(() => ContextUI.navbarVisible);
256 ok(ContextUI.navbarVisible, "navbar visible");
258 let edit = document.getElementById("urlbar-edit");
260 ok(!edit.focused, "Edit is not focused");
262 Browser.closeTab(newTab, { forceClose: true });
263 Browser.closeTab(mozTab, { forceClose: true });
264 }
265 });
267 gTests.push({
268 desc: "Bug 956576 - Location app bar pops up when fragment identifier " +
269 "changes (URL stuff after hash / number sign).",
270 run: function () {
271 let tab = yield addTab("about:mozilla");
272 yield showNavBar();
273 ok(ContextUI.navbarVisible, "Navbar is initially visible.");
275 ContextUI.dismiss();
276 ok(!ContextUI.navbarVisible, "Navbar is dismissed and hidden.");
278 let locationHasChanged = false;
279 fireTabURLChanged(tab, locationHasChanged);
280 ok(!ContextUI.navbarVisible, "Navbar isn't shown on URL fragment change.");
282 locationHasChanged = true;
283 fireTabURLChanged(tab, locationHasChanged);
284 ok(ContextUI.navbarVisible, "Navbar is shown on actual URL change.");
286 Browser.closeTab(tab, { forceClose: true });
287 }
288 });