michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: function test() { michael@0: runTests(); michael@0: } michael@0: michael@0: gTests.push({ michael@0: desc: "Access the find bar with the keyboard", michael@0: run: function() { michael@0: let tab = yield addTab(chromeRoot + "browser_findbar.html"); michael@0: yield waitForCondition(() => BrowserUI.ready); michael@0: is(Elements.findbar.isShowing, false, "Find bar is hidden by default"); michael@0: michael@0: EventUtils.synthesizeKey("f", { accelKey: true }); michael@0: yield waitForEvent(Elements.findbar, "transitionend"); michael@0: is(Elements.findbar.isShowing, true, "Show find bar with Ctrl-F"); michael@0: michael@0: let textbox = document.getElementById("findbar-textbox"); michael@0: is(textbox.value, "", "Find bar is empty"); michael@0: michael@0: EventUtils.sendString("bar"); michael@0: is(textbox.value, "bar", "Type 'bar' into find bar"); michael@0: michael@0: EventUtils.synthesizeKey("f", { accelKey: true}); michael@0: yield waitForEvent(Elements.findbar, "transitionend"); michael@0: ok(document.commandDispatcher.focusedElement, textbox.inputField, "textbox field is focused with Ctrl-F"); michael@0: is(textbox.selectionStart, 0, "textbox field is selected with Ctrl-F."); michael@0: is(textbox.selectionEnd, textbox.value.length, "textbox field is selected with Ctrl-F."); michael@0: michael@0: EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true }); michael@0: yield waitForEvent(Elements.findbar, "transitionend"); michael@0: is(Elements.findbar.isShowing, false, "Hide find bar with Esc"); michael@0: michael@0: Browser.closeTab(tab); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Findbar/navbar interaction", michael@0: run: function() { michael@0: let tab = yield addTab(chromeRoot + "browser_findbar.html"); michael@0: yield waitForCondition(() => BrowserUI.ready); michael@0: is(ContextUI.navbarVisible, false, "Navbar is hidden by default"); michael@0: is(Elements.findbar.isShowing, false, "Find bar is hidden by default"); michael@0: michael@0: yield showNavBar(); michael@0: is(ContextUI.navbarVisible, true, "Navbar is visible"); michael@0: is(Elements.findbar.isShowing, false, "Find bar is still hidden"); michael@0: michael@0: EventUtils.synthesizeKey("f", { accelKey: true }); michael@0: yield Promise.all([waitForEvent(Elements.navbar, "transitionend"), michael@0: waitForEvent(Elements.findbar, "transitionend")]); michael@0: is(ContextUI.navbarVisible, false, "Navbar is hidden"); michael@0: is(Elements.findbar.isShowing, true, "Findbar is visible"); michael@0: michael@0: yield Promise.all([showNavBar(), michael@0: waitForEvent(Elements.findbar, "transitionend")]); michael@0: is(ContextUI.navbarVisible, true, "Navbar is visible again"); michael@0: is(Elements.findbar.isShowing, false, "Find bar is hidden again"); michael@0: michael@0: Browser.closeTab(tab); michael@0: } michael@0: }); michael@0: michael@0: michael@0: gTests.push({ michael@0: desc: "Show and hide the find bar with mouse", michael@0: run: function() { michael@0: let tab = yield addTab(chromeRoot + "browser_findbar.html"); michael@0: yield waitForCondition(() => BrowserUI.ready); michael@0: is(Elements.findbar.isShowing, false, "Find bar is hidden by default"); michael@0: michael@0: yield showNavBar(); michael@0: EventUtils.sendMouseEvent({ type: "click" }, "menu-button"); michael@0: EventUtils.sendMouseEvent({ type: "click" }, "context-findinpage"); michael@0: yield waitForEvent(Elements.findbar, "transitionend"); michael@0: is(Elements.findbar.isShowing, true, "Show find bar with menu item"); michael@0: michael@0: EventUtils.synthesizeMouse(document.getElementById("findbar-close-button"), 1, 1, {}); michael@0: yield waitForEvent(Elements.findbar, "transitionend"); michael@0: is(Elements.findbar.isShowing, false, "Hide find bar with close button"); michael@0: michael@0: Browser.closeTab(tab); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Text at bottom of screen is not obscured by findbar", michael@0: run: function() { michael@0: let textbox = document.getElementById("findbar-textbox"); michael@0: michael@0: let tab = yield addTab(chromeRoot + "browser_findbar.html"); michael@0: yield waitForCondition(() => BrowserUI.ready); michael@0: is(Elements.findbar.isShowing, false, "Find bar is hidden by default"); michael@0: michael@0: FindHelperUI.show(); michael@0: yield waitForCondition(() => FindHelperUI.isActive); michael@0: michael@0: EventUtils.sendString("bottom"); michael@0: let event = yield waitForEvent(window, "MozDeckOffsetChanged"); michael@0: ok(!(event instanceof Error), "MozDeckOffsetChanged received (1)"); michael@0: ok(event.detail > 0, "Browser deck shifted upward"); michael@0: michael@0: textbox.select(); michael@0: EventUtils.sendString("bar"); michael@0: event = yield waitForEvent(window, "MozDeckOffsetChanged"); michael@0: ok(!(event instanceof Error), "MozDeckOffsetChanged received (2)"); michael@0: is(event.detail, 0, "Browser deck shifted back to normal"); michael@0: michael@0: textbox.select(); michael@0: EventUtils.sendString("bottom"); michael@0: event = yield waitForEvent(window, "MozDeckOffsetChanged"); michael@0: ok(!(event instanceof Error), "MozDeckOffsetChanged received (3)"); michael@0: ok(event.detail > 0, "Browser deck shifted upward again"); michael@0: michael@0: let waitForDeckOffset = waitForEvent(window, "MozDeckOffsetChanged"); michael@0: let waitForTransitionEnd = waitForEvent(Elements.findbar, "transitionend"); michael@0: FindHelperUI.hide(); michael@0: event = yield waitForDeckOffset; michael@0: ok(!(event instanceof Error), "MozDeckOffsetChanged received (4)"); michael@0: is(event.detail, 0, "Browser deck shifted back to normal when findbar hides"); michael@0: michael@0: // Cleanup. michael@0: yield waitForTransitionEnd; michael@0: Browser.closeTab(tab); michael@0: } michael@0: });