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