michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: function test() { michael@0: runTests(); michael@0: } michael@0: michael@0: function doEdgeUIGesture() { michael@0: let event = document.createEvent("Events"); michael@0: event.initEvent("MozEdgeUICompleted", true, false); michael@0: window.dispatchEvent(event); michael@0: } michael@0: michael@0: function fireTabURLChanged(tab, hasLocationChanged) { michael@0: let urlChangedEvent = document.createEvent("UIEvents"); michael@0: urlChangedEvent.initUIEvent("URLChanged", true, false, window, michael@0: hasLocationChanged); michael@0: tab.browser.dispatchEvent(urlChangedEvent); michael@0: } michael@0: michael@0: function getpage(idx) { michael@0: return "http://mochi.test:8888/metro/browser/metro/base/tests/mochitest/" + "res/blankpage" + idx + ".html"; michael@0: } michael@0: michael@0: gTests.push({ michael@0: desc: "Context UI on about:start", michael@0: run: function testAboutStart() { michael@0: let tab = yield addTab("about:start"); michael@0: michael@0: yield waitForCondition(function () { michael@0: return BrowserUI.isStartTabVisible; michael@0: }); michael@0: michael@0: is(BrowserUI.isStartTabVisible, true, "Start UI is displayed on about:start"); michael@0: is(ContextUI.navbarVisible, true, "Navbar is displayed on about:start"); michael@0: is(ContextUI.tabbarVisible, false, "Tabbar is not displayed initially"); michael@0: is(ContextUI.contextAppbarVisible, false, "Appbar is not displayed initially"); michael@0: michael@0: // toggle on michael@0: doEdgeUIGesture(); michael@0: is(ContextUI.navbarVisible, true, "Navbar is still visible after one swipe"); michael@0: is(ContextUI.tabbarVisible, true, "Tabbar is visible after one swipe"); michael@0: is(ContextUI.contextAppbarVisible, false, "Appbar is hidden after one swipe"); michael@0: michael@0: // toggle off michael@0: doEdgeUIGesture(); michael@0: is(ContextUI.navbarVisible, true, "Navbar is still visible after second swipe"); michael@0: is(ContextUI.tabbarVisible, false, "Tabbar is hidden after second swipe"); michael@0: is(ContextUI.contextAppbarVisible, false, "Appbar is hidden after second swipe"); michael@0: michael@0: // sanity check - toggle on again michael@0: doEdgeUIGesture(); michael@0: is(ContextUI.navbarVisible, true, "Navbar is still visible after third swipe"); michael@0: is(ContextUI.tabbarVisible, true, "Tabbar is visible after third swipe"); michael@0: is(ContextUI.contextAppbarVisible, false, "Appbar is hidden after third swipe"); michael@0: michael@0: is(BrowserUI.isStartTabVisible, true, "Start UI is still visible"); michael@0: michael@0: Browser.closeTab(tab, { forceClose: true }); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Context UI on a web page (about:)", michael@0: run: function testAbout() { michael@0: let tab = yield addTab("about:"); michael@0: ContextUI.dismiss(); michael@0: is(BrowserUI.isStartTabVisible, false, "Start UI is not visible on about:"); michael@0: is(ContextUI.navbarVisible, false, "Navbar is not initially visible on about:"); michael@0: is(ContextUI.tabbarVisible, false, "Tabbar is not initially visible on about:"); michael@0: michael@0: doEdgeUIGesture(); michael@0: is(ContextUI.navbarVisible, true, "Navbar is visible after one swipe"); michael@0: is(ContextUI.tabbarVisible, true, "Tabbar is visble after one swipe"); michael@0: michael@0: doEdgeUIGesture(); michael@0: is(ContextUI.navbarVisible, false, "Navbar is not visible after second swipe"); michael@0: is(ContextUI.tabbarVisible, false, "Tabbar is not visible after second swipe"); michael@0: michael@0: is(BrowserUI.isStartTabVisible, false, "Start UI is still not visible"); michael@0: michael@0: Browser.closeTab(tab, { forceClose: true }); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Control-L keyboard shortcut", michael@0: run: function testAbout() { michael@0: let tab = yield addTab("about:"); michael@0: ContextUI.dismiss(); michael@0: is(ContextUI.navbarVisible, false, "Navbar is not initially visible"); michael@0: is(ContextUI.tabbarVisible, false, "Tab bar is not initially visible"); michael@0: michael@0: EventUtils.synthesizeKey('l', { accelKey: true }); michael@0: is(ContextUI.navbarVisible, true, "Navbar is visible"); michael@0: is(ContextUI.tabbarVisible, false, "Tab bar is not visible"); michael@0: michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: is(edit.value, "about:", "Location field contains the page URL"); michael@0: ok(document.commandDispatcher.focusedElement, edit.inputField, "Location field is focused"); michael@0: is(edit.selectionStart, 0, "Location field is selected"); michael@0: is(edit.selectionEnd, edit.value.length, "Location field is selected"); michael@0: michael@0: edit.selectionEnd = 0; michael@0: is(edit.selectionStart, 0, "Location field is unselected"); michael@0: is(edit.selectionEnd, 0, "Location field is unselected"); michael@0: michael@0: EventUtils.synthesizeKey('l', { accelKey: true }); michael@0: is(edit.selectionStart, 0, "Location field is selected again"); michael@0: is(edit.selectionEnd, edit.value.length, "Location field is selected again"); michael@0: michael@0: Browser.closeTab(tab, { forceClose: true }); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "taps vs context ui dismissal", michael@0: run: function () { michael@0: // off by default michael@0: InputSourceHelper.isPrecise = false; michael@0: InputSourceHelper.fireUpdate(); michael@0: michael@0: let tab = yield addTab("about:mozilla"); michael@0: michael@0: ok(ContextUI.navbarVisible, "navbar visible after open"); michael@0: michael@0: let navButtonDisplayPromise = waitForEvent(NavButtonSlider.back, "transitionend"); michael@0: michael@0: yield loadUriInActiveTab(getpage(1)); michael@0: michael@0: is(tab.browser.currentURI.spec, getpage(1), getpage(1)); michael@0: ok(ContextUI.navbarVisible, "navbar visible after navigate 1"); michael@0: michael@0: yield loadUriInActiveTab(getpage(2)); michael@0: michael@0: is(tab.browser.currentURI.spec, getpage(2), getpage(2)); michael@0: ok(ContextUI.navbarVisible, "navbar visible after navigate 2"); michael@0: michael@0: yield loadUriInActiveTab(getpage(3)); michael@0: michael@0: is(tab.browser.currentURI.spec, getpage(3), getpage(3)); michael@0: ok(ContextUI.navbarVisible, "navbar visible after navigate 3"); michael@0: michael@0: // These transition in after we navigate. If we click on one of michael@0: // them before they are visible they don't work, so wait for michael@0: // display to occur. michael@0: yield navButtonDisplayPromise; michael@0: michael@0: yield navBackViaNavButton(); michael@0: yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(2); }, "getpage(2)"); michael@0: yield waitForCondition2(function () { return ContextUI.navbarVisible; }, "ContextUI.navbarVisible"); michael@0: michael@0: is(tab.browser.currentURI.spec, getpage(2), getpage(2)); michael@0: michael@0: yield navForward(); michael@0: yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(3); }, "getpage(3)"); michael@0: michael@0: is(tab.browser.currentURI.spec, getpage(3), getpage(3)); michael@0: ok(ContextUI.navbarVisible, "navbar visible after navigate"); michael@0: michael@0: doEdgeUIGesture(); michael@0: michael@0: is(ContextUI.navbarVisible, true, "Navbar is visible after swipe"); michael@0: is(ContextUI.tabbarVisible, true, "Tabbar is visible after swipe"); michael@0: michael@0: yield navBackViaNavButton(); michael@0: yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(2); }, "getpage(2)"); michael@0: michael@0: is(tab.browser.currentURI.spec, getpage(2), getpage(2)); michael@0: is(ContextUI.navbarVisible, true, "Navbar is visible after navigating back (overlay)"); michael@0: yield waitForCondition2(function () { return !ContextUI.tabbarVisible; }, "!ContextUI.tabbarVisible"); michael@0: michael@0: sendElementTap(window, window.document.documentElement); michael@0: yield waitForCondition2(function () { return !BrowserUI.navbarVisible; }, "!BrowserUI.navbarVisible"); michael@0: michael@0: is(ContextUI.tabbarVisible, false, "Tabbar is hidden after content tap"); michael@0: michael@0: yield navForward(); michael@0: yield waitForCondition2(function () { michael@0: return tab.browser.currentURI.spec == getpage(3) && ContextUI.navbarVisible; michael@0: }, "getpage(3)"); michael@0: michael@0: is(tab.browser.currentURI.spec, getpage(3), getpage(3)); michael@0: ok(ContextUI.navbarVisible, "navbar visible after navigate"); michael@0: michael@0: yield navBackViaNavButton(); michael@0: yield waitForCondition2(function () { return tab.browser.currentURI.spec == getpage(2); }, "getpage(2)"); michael@0: yield waitForCondition2(function () { return !ContextUI.tabbarVisible; }, "!ContextUI.tabbarVisible"); michael@0: michael@0: is(tab.browser.currentURI.spec, getpage(2), getpage(2)); michael@0: is(ContextUI.navbarVisible, true, "Navbar is visible after navigating back (overlay)"); michael@0: michael@0: ContextUI.dismiss(); michael@0: michael@0: let note = yield showNotification(); michael@0: doEdgeUIGesture(); michael@0: sendElementTap(window, note); michael@0: michael@0: is(ContextUI.navbarVisible, true, "Navbar is visible after clicking notification close button"); michael@0: michael@0: removeNotifications(); michael@0: michael@0: Browser.closeTab(tab, { forceClose: true }); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Bug 907244 - Opening a new tab when the page has focus doesn't correctly focus the location bar", michael@0: run: function () { michael@0: let mozTab = yield addTab("about:mozilla"); michael@0: michael@0: // addTab will dismiss navbar, but lets check anyway. michael@0: ok(!ContextUI.navbarVisible, "navbar dismissed"); michael@0: michael@0: BrowserUI.doCommand("cmd_newTabKey"); michael@0: let newTab = Browser.selectedTab; michael@0: yield newTab.pageShowPromise; michael@0: michael@0: yield waitForCondition(() => ContextUI.navbarVisible); michael@0: ok(ContextUI.navbarVisible, "navbar visible"); michael@0: michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: michael@0: ok(edit.focused, "Edit has focus"); michael@0: michael@0: // Lets traverse since node.contains() doesn't work for anonymous elements. michael@0: let parent = document.activeElement; michael@0: while(parent && parent != edit) { michael@0: parent = parent.parentNode; michael@0: } michael@0: michael@0: ok(parent === edit, 'Active element is a descendant of urlbar'); michael@0: michael@0: Browser.closeTab(newTab, { forceClose: true }); michael@0: Browser.closeTab(mozTab, { forceClose: true }); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Bug 933989 - New tab button in tab bar always sets focus to the url bar, triggering soft keyboard", michael@0: run: function () { michael@0: let mozTab = yield addTab("about:mozilla"); michael@0: michael@0: yield hideNavBar(); michael@0: ok(!ContextUI.navbarVisible, "navbar dismissed"); michael@0: michael@0: BrowserUI.doCommand("cmd_newTab"); michael@0: let newTab = Browser.selectedTab; michael@0: yield newTab.pageShowPromise; michael@0: michael@0: yield waitForCondition(() => ContextUI.navbarVisible); michael@0: ok(ContextUI.navbarVisible, "navbar visible"); michael@0: michael@0: let edit = document.getElementById("urlbar-edit"); michael@0: michael@0: ok(!edit.focused, "Edit is not focused"); michael@0: michael@0: Browser.closeTab(newTab, { forceClose: true }); michael@0: Browser.closeTab(mozTab, { forceClose: true }); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Bug 956576 - Location app bar pops up when fragment identifier " + michael@0: "changes (URL stuff after hash / number sign).", michael@0: run: function () { michael@0: let tab = yield addTab("about:mozilla"); michael@0: yield showNavBar(); michael@0: ok(ContextUI.navbarVisible, "Navbar is initially visible."); michael@0: michael@0: ContextUI.dismiss(); michael@0: ok(!ContextUI.navbarVisible, "Navbar is dismissed and hidden."); michael@0: michael@0: let locationHasChanged = false; michael@0: fireTabURLChanged(tab, locationHasChanged); michael@0: ok(!ContextUI.navbarVisible, "Navbar isn't shown on URL fragment change."); michael@0: michael@0: locationHasChanged = true; michael@0: fireTabURLChanged(tab, locationHasChanged); michael@0: ok(ContextUI.navbarVisible, "Navbar is shown on actual URL change."); michael@0: michael@0: Browser.closeTab(tab, { forceClose: true }); michael@0: } michael@0: });