browser/metro/base/tests/mochitest/browser_context_ui.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:f7a46b72efa2
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/ */
5
6 "use strict";
7
8 function test() {
9 runTests();
10 }
11
12 function doEdgeUIGesture() {
13 let event = document.createEvent("Events");
14 event.initEvent("MozEdgeUICompleted", true, false);
15 window.dispatchEvent(event);
16 }
17
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 }
24
25 function getpage(idx) {
26 return "http://mochi.test:8888/metro/browser/metro/base/tests/mochitest/" + "res/blankpage" + idx + ".html";
27 }
28
29 gTests.push({
30 desc: "Context UI on about:start",
31 run: function testAboutStart() {
32 let tab = yield addTab("about:start");
33
34 yield waitForCondition(function () {
35 return BrowserUI.isStartTabVisible;
36 });
37
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");
42
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");
48
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");
54
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");
60
61 is(BrowserUI.isStartTabVisible, true, "Start UI is still visible");
62
63 Browser.closeTab(tab, { forceClose: true });
64 }
65 });
66
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:");
75
76 doEdgeUIGesture();
77 is(ContextUI.navbarVisible, true, "Navbar is visible after one swipe");
78 is(ContextUI.tabbarVisible, true, "Tabbar is visble after one swipe");
79
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");
83
84 is(BrowserUI.isStartTabVisible, false, "Start UI is still not visible");
85
86 Browser.closeTab(tab, { forceClose: true });
87 }
88 });
89
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");
97
98 EventUtils.synthesizeKey('l', { accelKey: true });
99 is(ContextUI.navbarVisible, true, "Navbar is visible");
100 is(ContextUI.tabbarVisible, false, "Tab bar is not visible");
101
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");
107
108 edit.selectionEnd = 0;
109 is(edit.selectionStart, 0, "Location field is unselected");
110 is(edit.selectionEnd, 0, "Location field is unselected");
111
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");
115
116 Browser.closeTab(tab, { forceClose: true });
117 }
118 });
119
120 gTests.push({
121 desc: "taps vs context ui dismissal",
122 run: function () {
123 // off by default
124 InputSourceHelper.isPrecise = false;
125 InputSourceHelper.fireUpdate();
126
127 let tab = yield addTab("about:mozilla");
128
129 ok(ContextUI.navbarVisible, "navbar visible after open");
130
131 let navButtonDisplayPromise = waitForEvent(NavButtonSlider.back, "transitionend");
132
133 yield loadUriInActiveTab(getpage(1));
134
135 is(tab.browser.currentURI.spec, getpage(1), getpage(1));
136 ok(ContextUI.navbarVisible, "navbar visible after navigate 1");
137
138 yield loadUriInActiveTab(getpage(2));
139
140 is(tab.browser.currentURI.spec, getpage(2), getpage(2));
141 ok(ContextUI.navbarVisible, "navbar visible after navigate 2");
142
143 yield loadUriInActiveTab(getpage(3));
144
145 is(tab.browser.currentURI.spec, getpage(3), getpage(3));
146 ok(ContextUI.navbarVisible, "navbar visible after navigate 3");
147
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;
152
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");
156
157 is(tab.browser.currentURI.spec, getpage(2), getpage(2));
158
159 yield navForward();
160 yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(3); }, "getpage(3)");
161
162 is(tab.browser.currentURI.spec, getpage(3), getpage(3));
163 ok(ContextUI.navbarVisible, "navbar visible after navigate");
164
165 doEdgeUIGesture();
166
167 is(ContextUI.navbarVisible, true, "Navbar is visible after swipe");
168 is(ContextUI.tabbarVisible, true, "Tabbar is visible after swipe");
169
170 yield navBackViaNavButton();
171 yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(2); }, "getpage(2)");
172
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");
176
177 sendElementTap(window, window.document.documentElement);
178 yield waitForCondition2(function () { return !BrowserUI.navbarVisible; }, "!BrowserUI.navbarVisible");
179
180 is(ContextUI.tabbarVisible, false, "Tabbar is hidden after content tap");
181
182 yield navForward();
183 yield waitForCondition2(function () {
184 return tab.browser.currentURI.spec == getpage(3) && ContextUI.navbarVisible;
185 }, "getpage(3)");
186
187 is(tab.browser.currentURI.spec, getpage(3), getpage(3));
188 ok(ContextUI.navbarVisible, "navbar visible after navigate");
189
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");
193
194 is(tab.browser.currentURI.spec, getpage(2), getpage(2));
195 is(ContextUI.navbarVisible, true, "Navbar is visible after navigating back (overlay)");
196
197 ContextUI.dismiss();
198
199 let note = yield showNotification();
200 doEdgeUIGesture();
201 sendElementTap(window, note);
202
203 is(ContextUI.navbarVisible, true, "Navbar is visible after clicking notification close button");
204
205 removeNotifications();
206
207 Browser.closeTab(tab, { forceClose: true });
208 }
209 });
210
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");
215
216 // addTab will dismiss navbar, but lets check anyway.
217 ok(!ContextUI.navbarVisible, "navbar dismissed");
218
219 BrowserUI.doCommand("cmd_newTabKey");
220 let newTab = Browser.selectedTab;
221 yield newTab.pageShowPromise;
222
223 yield waitForCondition(() => ContextUI.navbarVisible);
224 ok(ContextUI.navbarVisible, "navbar visible");
225
226 let edit = document.getElementById("urlbar-edit");
227
228 ok(edit.focused, "Edit has focus");
229
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 }
235
236 ok(parent === edit, 'Active element is a descendant of urlbar');
237
238 Browser.closeTab(newTab, { forceClose: true });
239 Browser.closeTab(mozTab, { forceClose: true });
240 }
241 });
242
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");
247
248 yield hideNavBar();
249 ok(!ContextUI.navbarVisible, "navbar dismissed");
250
251 BrowserUI.doCommand("cmd_newTab");
252 let newTab = Browser.selectedTab;
253 yield newTab.pageShowPromise;
254
255 yield waitForCondition(() => ContextUI.navbarVisible);
256 ok(ContextUI.navbarVisible, "navbar visible");
257
258 let edit = document.getElementById("urlbar-edit");
259
260 ok(!edit.focused, "Edit is not focused");
261
262 Browser.closeTab(newTab, { forceClose: true });
263 Browser.closeTab(mozTab, { forceClose: true });
264 }
265 });
266
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.");
274
275 ContextUI.dismiss();
276 ok(!ContextUI.navbarVisible, "Navbar is dismissed and hidden.");
277
278 let locationHasChanged = false;
279 fireTabURLChanged(tab, locationHasChanged);
280 ok(!ContextUI.navbarVisible, "Navbar isn't shown on URL fragment change.");
281
282 locationHasChanged = true;
283 fireTabURLChanged(tab, locationHasChanged);
284 ok(ContextUI.navbarVisible, "Navbar is shown on actual URL change.");
285
286 Browser.closeTab(tab, { forceClose: true });
287 }
288 });

mercurial