|
1 /* vim: set ts=2 et sw=2 tw=80: */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 "use strict"; |
|
7 |
|
8 function test() { |
|
9 runTests(); |
|
10 } |
|
11 |
|
12 gTests.push({ |
|
13 desc: "Access the find bar with the keyboard", |
|
14 run: function() { |
|
15 let tab = yield addTab(chromeRoot + "browser_findbar.html"); |
|
16 yield waitForCondition(() => BrowserUI.ready); |
|
17 is(Elements.findbar.isShowing, false, "Find bar is hidden by default"); |
|
18 |
|
19 EventUtils.synthesizeKey("f", { accelKey: true }); |
|
20 yield waitForEvent(Elements.findbar, "transitionend"); |
|
21 is(Elements.findbar.isShowing, true, "Show find bar with Ctrl-F"); |
|
22 |
|
23 let textbox = document.getElementById("findbar-textbox"); |
|
24 is(textbox.value, "", "Find bar is empty"); |
|
25 |
|
26 EventUtils.sendString("bar"); |
|
27 is(textbox.value, "bar", "Type 'bar' into find bar"); |
|
28 |
|
29 EventUtils.synthesizeKey("f", { accelKey: true}); |
|
30 yield waitForEvent(Elements.findbar, "transitionend"); |
|
31 ok(document.commandDispatcher.focusedElement, textbox.inputField, "textbox field is focused with Ctrl-F"); |
|
32 is(textbox.selectionStart, 0, "textbox field is selected with Ctrl-F."); |
|
33 is(textbox.selectionEnd, textbox.value.length, "textbox field is selected with Ctrl-F."); |
|
34 |
|
35 EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }); |
|
36 yield waitForEvent(Elements.findbar, "transitionend"); |
|
37 is(Elements.findbar.isShowing, false, "Hide find bar with Esc"); |
|
38 |
|
39 Browser.closeTab(tab); |
|
40 } |
|
41 }); |
|
42 |
|
43 gTests.push({ |
|
44 desc: "Findbar/navbar interaction", |
|
45 run: function() { |
|
46 let tab = yield addTab(chromeRoot + "browser_findbar.html"); |
|
47 yield waitForCondition(() => BrowserUI.ready); |
|
48 is(ContextUI.navbarVisible, false, "Navbar is hidden by default"); |
|
49 is(Elements.findbar.isShowing, false, "Find bar is hidden by default"); |
|
50 |
|
51 yield showNavBar(); |
|
52 is(ContextUI.navbarVisible, true, "Navbar is visible"); |
|
53 is(Elements.findbar.isShowing, false, "Find bar is still hidden"); |
|
54 |
|
55 EventUtils.synthesizeKey("f", { accelKey: true }); |
|
56 yield Promise.all([waitForEvent(Elements.navbar, "transitionend"), |
|
57 waitForEvent(Elements.findbar, "transitionend")]); |
|
58 is(ContextUI.navbarVisible, false, "Navbar is hidden"); |
|
59 is(Elements.findbar.isShowing, true, "Findbar is visible"); |
|
60 |
|
61 yield Promise.all([showNavBar(), |
|
62 waitForEvent(Elements.findbar, "transitionend")]); |
|
63 is(ContextUI.navbarVisible, true, "Navbar is visible again"); |
|
64 is(Elements.findbar.isShowing, false, "Find bar is hidden again"); |
|
65 |
|
66 Browser.closeTab(tab); |
|
67 } |
|
68 }); |
|
69 |
|
70 |
|
71 gTests.push({ |
|
72 desc: "Show and hide the find bar with mouse", |
|
73 run: function() { |
|
74 let tab = yield addTab(chromeRoot + "browser_findbar.html"); |
|
75 yield waitForCondition(() => BrowserUI.ready); |
|
76 is(Elements.findbar.isShowing, false, "Find bar is hidden by default"); |
|
77 |
|
78 yield showNavBar(); |
|
79 EventUtils.sendMouseEvent({ type: "click" }, "menu-button"); |
|
80 EventUtils.sendMouseEvent({ type: "click" }, "context-findinpage"); |
|
81 yield waitForEvent(Elements.findbar, "transitionend"); |
|
82 is(Elements.findbar.isShowing, true, "Show find bar with menu item"); |
|
83 |
|
84 EventUtils.synthesizeMouse(document.getElementById("findbar-close-button"), 1, 1, {}); |
|
85 yield waitForEvent(Elements.findbar, "transitionend"); |
|
86 is(Elements.findbar.isShowing, false, "Hide find bar with close button"); |
|
87 |
|
88 Browser.closeTab(tab); |
|
89 } |
|
90 }); |
|
91 |
|
92 gTests.push({ |
|
93 desc: "Text at bottom of screen is not obscured by findbar", |
|
94 run: function() { |
|
95 let textbox = document.getElementById("findbar-textbox"); |
|
96 |
|
97 let tab = yield addTab(chromeRoot + "browser_findbar.html"); |
|
98 yield waitForCondition(() => BrowserUI.ready); |
|
99 is(Elements.findbar.isShowing, false, "Find bar is hidden by default"); |
|
100 |
|
101 FindHelperUI.show(); |
|
102 yield waitForCondition(() => FindHelperUI.isActive); |
|
103 |
|
104 EventUtils.sendString("bottom"); |
|
105 let event = yield waitForEvent(window, "MozDeckOffsetChanged"); |
|
106 ok(!(event instanceof Error), "MozDeckOffsetChanged received (1)"); |
|
107 ok(event.detail > 0, "Browser deck shifted upward"); |
|
108 |
|
109 textbox.select(); |
|
110 EventUtils.sendString("bar"); |
|
111 event = yield waitForEvent(window, "MozDeckOffsetChanged"); |
|
112 ok(!(event instanceof Error), "MozDeckOffsetChanged received (2)"); |
|
113 is(event.detail, 0, "Browser deck shifted back to normal"); |
|
114 |
|
115 textbox.select(); |
|
116 EventUtils.sendString("bottom"); |
|
117 event = yield waitForEvent(window, "MozDeckOffsetChanged"); |
|
118 ok(!(event instanceof Error), "MozDeckOffsetChanged received (3)"); |
|
119 ok(event.detail > 0, "Browser deck shifted upward again"); |
|
120 |
|
121 let waitForDeckOffset = waitForEvent(window, "MozDeckOffsetChanged"); |
|
122 let waitForTransitionEnd = waitForEvent(Elements.findbar, "transitionend"); |
|
123 FindHelperUI.hide(); |
|
124 event = yield waitForDeckOffset; |
|
125 ok(!(event instanceof Error), "MozDeckOffsetChanged received (4)"); |
|
126 is(event.detail, 0, "Browser deck shifted back to normal when findbar hides"); |
|
127 |
|
128 // Cleanup. |
|
129 yield waitForTransitionEnd; |
|
130 Browser.closeTab(tab); |
|
131 } |
|
132 }); |