browser/metro/base/tests/mochitest/browser_findbar.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     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/. */
     6 "use strict";
     8 function test() {
     9   runTests();
    10 }
    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");
    19     EventUtils.synthesizeKey("f", { accelKey: true });
    20     yield waitForEvent(Elements.findbar, "transitionend");
    21     is(Elements.findbar.isShowing, true, "Show find bar with Ctrl-F");
    23     let textbox = document.getElementById("findbar-textbox");
    24     is(textbox.value, "", "Find bar is empty");
    26     EventUtils.sendString("bar");
    27     is(textbox.value, "bar", "Type 'bar' into find bar");
    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.");
    35     EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true });
    36     yield waitForEvent(Elements.findbar, "transitionend");
    37     is(Elements.findbar.isShowing, false, "Hide find bar with Esc");
    39     Browser.closeTab(tab);
    40   }
    41 });
    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");
    51     yield showNavBar();
    52     is(ContextUI.navbarVisible, true, "Navbar is visible");
    53     is(Elements.findbar.isShowing, false, "Find bar is still hidden");
    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");
    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");
    66     Browser.closeTab(tab);
    67   }
    68 });
    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");
    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");
    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");
    88     Browser.closeTab(tab);
    89   }
    90 });
    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");
    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");
   101     FindHelperUI.show();
   102     yield waitForCondition(() => FindHelperUI.isActive);
   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");
   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");
   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");
   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");
   128     // Cleanup.
   129     yield waitForTransitionEnd;
   130     Browser.closeTab(tab);
   131   }
   132 });

mercurial