1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/tests/mochitest/browser_context_ui.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,288 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* Any copyright is dedicated to the Public Domain. 1.7 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.8 + 1.9 +"use strict"; 1.10 + 1.11 +function test() { 1.12 + runTests(); 1.13 +} 1.14 + 1.15 +function doEdgeUIGesture() { 1.16 + let event = document.createEvent("Events"); 1.17 + event.initEvent("MozEdgeUICompleted", true, false); 1.18 + window.dispatchEvent(event); 1.19 +} 1.20 + 1.21 +function fireTabURLChanged(tab, hasLocationChanged) { 1.22 + let urlChangedEvent = document.createEvent("UIEvents"); 1.23 + urlChangedEvent.initUIEvent("URLChanged", true, false, window, 1.24 + hasLocationChanged); 1.25 + tab.browser.dispatchEvent(urlChangedEvent); 1.26 +} 1.27 + 1.28 +function getpage(idx) { 1.29 + return "http://mochi.test:8888/metro/browser/metro/base/tests/mochitest/" + "res/blankpage" + idx + ".html"; 1.30 +} 1.31 + 1.32 +gTests.push({ 1.33 + desc: "Context UI on about:start", 1.34 + run: function testAboutStart() { 1.35 + let tab = yield addTab("about:start"); 1.36 + 1.37 + yield waitForCondition(function () { 1.38 + return BrowserUI.isStartTabVisible; 1.39 + }); 1.40 + 1.41 + is(BrowserUI.isStartTabVisible, true, "Start UI is displayed on about:start"); 1.42 + is(ContextUI.navbarVisible, true, "Navbar is displayed on about:start"); 1.43 + is(ContextUI.tabbarVisible, false, "Tabbar is not displayed initially"); 1.44 + is(ContextUI.contextAppbarVisible, false, "Appbar is not displayed initially"); 1.45 + 1.46 + // toggle on 1.47 + doEdgeUIGesture(); 1.48 + is(ContextUI.navbarVisible, true, "Navbar is still visible after one swipe"); 1.49 + is(ContextUI.tabbarVisible, true, "Tabbar is visible after one swipe"); 1.50 + is(ContextUI.contextAppbarVisible, false, "Appbar is hidden after one swipe"); 1.51 + 1.52 + // toggle off 1.53 + doEdgeUIGesture(); 1.54 + is(ContextUI.navbarVisible, true, "Navbar is still visible after second swipe"); 1.55 + is(ContextUI.tabbarVisible, false, "Tabbar is hidden after second swipe"); 1.56 + is(ContextUI.contextAppbarVisible, false, "Appbar is hidden after second swipe"); 1.57 + 1.58 + // sanity check - toggle on again 1.59 + doEdgeUIGesture(); 1.60 + is(ContextUI.navbarVisible, true, "Navbar is still visible after third swipe"); 1.61 + is(ContextUI.tabbarVisible, true, "Tabbar is visible after third swipe"); 1.62 + is(ContextUI.contextAppbarVisible, false, "Appbar is hidden after third swipe"); 1.63 + 1.64 + is(BrowserUI.isStartTabVisible, true, "Start UI is still visible"); 1.65 + 1.66 + Browser.closeTab(tab, { forceClose: true }); 1.67 + } 1.68 +}); 1.69 + 1.70 +gTests.push({ 1.71 + desc: "Context UI on a web page (about:)", 1.72 + run: function testAbout() { 1.73 + let tab = yield addTab("about:"); 1.74 + ContextUI.dismiss(); 1.75 + is(BrowserUI.isStartTabVisible, false, "Start UI is not visible on about:"); 1.76 + is(ContextUI.navbarVisible, false, "Navbar is not initially visible on about:"); 1.77 + is(ContextUI.tabbarVisible, false, "Tabbar is not initially visible on about:"); 1.78 + 1.79 + doEdgeUIGesture(); 1.80 + is(ContextUI.navbarVisible, true, "Navbar is visible after one swipe"); 1.81 + is(ContextUI.tabbarVisible, true, "Tabbar is visble after one swipe"); 1.82 + 1.83 + doEdgeUIGesture(); 1.84 + is(ContextUI.navbarVisible, false, "Navbar is not visible after second swipe"); 1.85 + is(ContextUI.tabbarVisible, false, "Tabbar is not visible after second swipe"); 1.86 + 1.87 + is(BrowserUI.isStartTabVisible, false, "Start UI is still not visible"); 1.88 + 1.89 + Browser.closeTab(tab, { forceClose: true }); 1.90 + } 1.91 +}); 1.92 + 1.93 +gTests.push({ 1.94 + desc: "Control-L keyboard shortcut", 1.95 + run: function testAbout() { 1.96 + let tab = yield addTab("about:"); 1.97 + ContextUI.dismiss(); 1.98 + is(ContextUI.navbarVisible, false, "Navbar is not initially visible"); 1.99 + is(ContextUI.tabbarVisible, false, "Tab bar is not initially visible"); 1.100 + 1.101 + EventUtils.synthesizeKey('l', { accelKey: true }); 1.102 + is(ContextUI.navbarVisible, true, "Navbar is visible"); 1.103 + is(ContextUI.tabbarVisible, false, "Tab bar is not visible"); 1.104 + 1.105 + let edit = document.getElementById("urlbar-edit"); 1.106 + is(edit.value, "about:", "Location field contains the page URL"); 1.107 + ok(document.commandDispatcher.focusedElement, edit.inputField, "Location field is focused"); 1.108 + is(edit.selectionStart, 0, "Location field is selected"); 1.109 + is(edit.selectionEnd, edit.value.length, "Location field is selected"); 1.110 + 1.111 + edit.selectionEnd = 0; 1.112 + is(edit.selectionStart, 0, "Location field is unselected"); 1.113 + is(edit.selectionEnd, 0, "Location field is unselected"); 1.114 + 1.115 + EventUtils.synthesizeKey('l', { accelKey: true }); 1.116 + is(edit.selectionStart, 0, "Location field is selected again"); 1.117 + is(edit.selectionEnd, edit.value.length, "Location field is selected again"); 1.118 + 1.119 + Browser.closeTab(tab, { forceClose: true }); 1.120 + } 1.121 +}); 1.122 + 1.123 +gTests.push({ 1.124 + desc: "taps vs context ui dismissal", 1.125 + run: function () { 1.126 + // off by default 1.127 + InputSourceHelper.isPrecise = false; 1.128 + InputSourceHelper.fireUpdate(); 1.129 + 1.130 + let tab = yield addTab("about:mozilla"); 1.131 + 1.132 + ok(ContextUI.navbarVisible, "navbar visible after open"); 1.133 + 1.134 + let navButtonDisplayPromise = waitForEvent(NavButtonSlider.back, "transitionend"); 1.135 + 1.136 + yield loadUriInActiveTab(getpage(1)); 1.137 + 1.138 + is(tab.browser.currentURI.spec, getpage(1), getpage(1)); 1.139 + ok(ContextUI.navbarVisible, "navbar visible after navigate 1"); 1.140 + 1.141 + yield loadUriInActiveTab(getpage(2)); 1.142 + 1.143 + is(tab.browser.currentURI.spec, getpage(2), getpage(2)); 1.144 + ok(ContextUI.navbarVisible, "navbar visible after navigate 2"); 1.145 + 1.146 + yield loadUriInActiveTab(getpage(3)); 1.147 + 1.148 + is(tab.browser.currentURI.spec, getpage(3), getpage(3)); 1.149 + ok(ContextUI.navbarVisible, "navbar visible after navigate 3"); 1.150 + 1.151 + // These transition in after we navigate. If we click on one of 1.152 + // them before they are visible they don't work, so wait for 1.153 + // display to occur. 1.154 + yield navButtonDisplayPromise; 1.155 + 1.156 + yield navBackViaNavButton(); 1.157 + yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(2); }, "getpage(2)"); 1.158 + yield waitForCondition2(function () { return ContextUI.navbarVisible; }, "ContextUI.navbarVisible"); 1.159 + 1.160 + is(tab.browser.currentURI.spec, getpage(2), getpage(2)); 1.161 + 1.162 + yield navForward(); 1.163 + yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(3); }, "getpage(3)"); 1.164 + 1.165 + is(tab.browser.currentURI.spec, getpage(3), getpage(3)); 1.166 + ok(ContextUI.navbarVisible, "navbar visible after navigate"); 1.167 + 1.168 + doEdgeUIGesture(); 1.169 + 1.170 + is(ContextUI.navbarVisible, true, "Navbar is visible after swipe"); 1.171 + is(ContextUI.tabbarVisible, true, "Tabbar is visible after swipe"); 1.172 + 1.173 + yield navBackViaNavButton(); 1.174 + yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(2); }, "getpage(2)"); 1.175 + 1.176 + is(tab.browser.currentURI.spec, getpage(2), getpage(2)); 1.177 + is(ContextUI.navbarVisible, true, "Navbar is visible after navigating back (overlay)"); 1.178 + yield waitForCondition2(function () { return !ContextUI.tabbarVisible; }, "!ContextUI.tabbarVisible"); 1.179 + 1.180 + sendElementTap(window, window.document.documentElement); 1.181 + yield waitForCondition2(function () { return !BrowserUI.navbarVisible; }, "!BrowserUI.navbarVisible"); 1.182 + 1.183 + is(ContextUI.tabbarVisible, false, "Tabbar is hidden after content tap"); 1.184 + 1.185 + yield navForward(); 1.186 + yield waitForCondition2(function () { 1.187 + return tab.browser.currentURI.spec == getpage(3) && ContextUI.navbarVisible; 1.188 + }, "getpage(3)"); 1.189 + 1.190 + is(tab.browser.currentURI.spec, getpage(3), getpage(3)); 1.191 + ok(ContextUI.navbarVisible, "navbar visible after navigate"); 1.192 + 1.193 + yield navBackViaNavButton(); 1.194 + yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(2); }, "getpage(2)"); 1.195 + yield waitForCondition2(function () { return !ContextUI.tabbarVisible; }, "!ContextUI.tabbarVisible"); 1.196 + 1.197 + is(tab.browser.currentURI.spec, getpage(2), getpage(2)); 1.198 + is(ContextUI.navbarVisible, true, "Navbar is visible after navigating back (overlay)"); 1.199 + 1.200 + ContextUI.dismiss(); 1.201 + 1.202 + let note = yield showNotification(); 1.203 + doEdgeUIGesture(); 1.204 + sendElementTap(window, note); 1.205 + 1.206 + is(ContextUI.navbarVisible, true, "Navbar is visible after clicking notification close button"); 1.207 + 1.208 + removeNotifications(); 1.209 + 1.210 + Browser.closeTab(tab, { forceClose: true }); 1.211 + } 1.212 +}); 1.213 + 1.214 +gTests.push({ 1.215 + desc: "Bug 907244 - Opening a new tab when the page has focus doesn't correctly focus the location bar", 1.216 + run: function () { 1.217 + let mozTab = yield addTab("about:mozilla"); 1.218 + 1.219 + // addTab will dismiss navbar, but lets check anyway. 1.220 + ok(!ContextUI.navbarVisible, "navbar dismissed"); 1.221 + 1.222 + BrowserUI.doCommand("cmd_newTabKey"); 1.223 + let newTab = Browser.selectedTab; 1.224 + yield newTab.pageShowPromise; 1.225 + 1.226 + yield waitForCondition(() => ContextUI.navbarVisible); 1.227 + ok(ContextUI.navbarVisible, "navbar visible"); 1.228 + 1.229 + let edit = document.getElementById("urlbar-edit"); 1.230 + 1.231 + ok(edit.focused, "Edit has focus"); 1.232 + 1.233 + // Lets traverse since node.contains() doesn't work for anonymous elements. 1.234 + let parent = document.activeElement; 1.235 + while(parent && parent != edit) { 1.236 + parent = parent.parentNode; 1.237 + } 1.238 + 1.239 + ok(parent === edit, 'Active element is a descendant of urlbar'); 1.240 + 1.241 + Browser.closeTab(newTab, { forceClose: true }); 1.242 + Browser.closeTab(mozTab, { forceClose: true }); 1.243 + } 1.244 +}); 1.245 + 1.246 +gTests.push({ 1.247 + desc: "Bug 933989 - New tab button in tab bar always sets focus to the url bar, triggering soft keyboard", 1.248 + run: function () { 1.249 + let mozTab = yield addTab("about:mozilla"); 1.250 + 1.251 + yield hideNavBar(); 1.252 + ok(!ContextUI.navbarVisible, "navbar dismissed"); 1.253 + 1.254 + BrowserUI.doCommand("cmd_newTab"); 1.255 + let newTab = Browser.selectedTab; 1.256 + yield newTab.pageShowPromise; 1.257 + 1.258 + yield waitForCondition(() => ContextUI.navbarVisible); 1.259 + ok(ContextUI.navbarVisible, "navbar visible"); 1.260 + 1.261 + let edit = document.getElementById("urlbar-edit"); 1.262 + 1.263 + ok(!edit.focused, "Edit is not focused"); 1.264 + 1.265 + Browser.closeTab(newTab, { forceClose: true }); 1.266 + Browser.closeTab(mozTab, { forceClose: true }); 1.267 + } 1.268 +}); 1.269 + 1.270 +gTests.push({ 1.271 + desc: "Bug 956576 - Location app bar pops up when fragment identifier " + 1.272 + "changes (URL stuff after hash / number sign).", 1.273 + run: function () { 1.274 + let tab = yield addTab("about:mozilla"); 1.275 + yield showNavBar(); 1.276 + ok(ContextUI.navbarVisible, "Navbar is initially visible."); 1.277 + 1.278 + ContextUI.dismiss(); 1.279 + ok(!ContextUI.navbarVisible, "Navbar is dismissed and hidden."); 1.280 + 1.281 + let locationHasChanged = false; 1.282 + fireTabURLChanged(tab, locationHasChanged); 1.283 + ok(!ContextUI.navbarVisible, "Navbar isn't shown on URL fragment change."); 1.284 + 1.285 + locationHasChanged = true; 1.286 + fireTabURLChanged(tab, locationHasChanged); 1.287 + ok(ContextUI.navbarVisible, "Navbar is shown on actual URL change."); 1.288 + 1.289 + Browser.closeTab(tab, { forceClose: true }); 1.290 + } 1.291 +});