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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/tests/mochitest/browser_findbar.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     1.4 +/* vim: set ts=2 et sw=2 tw=80: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +"use strict";
    1.10 +
    1.11 +function test() {
    1.12 +  runTests();
    1.13 +}
    1.14 +
    1.15 +gTests.push({
    1.16 +  desc: "Access the find bar with the keyboard",
    1.17 +  run: function() {
    1.18 +    let tab = yield addTab(chromeRoot + "browser_findbar.html");
    1.19 +    yield waitForCondition(() => BrowserUI.ready);
    1.20 +    is(Elements.findbar.isShowing, false, "Find bar is hidden by default");
    1.21 +
    1.22 +    EventUtils.synthesizeKey("f", { accelKey: true });
    1.23 +    yield waitForEvent(Elements.findbar, "transitionend");
    1.24 +    is(Elements.findbar.isShowing, true, "Show find bar with Ctrl-F");
    1.25 +
    1.26 +    let textbox = document.getElementById("findbar-textbox");
    1.27 +    is(textbox.value, "", "Find bar is empty");
    1.28 +
    1.29 +    EventUtils.sendString("bar");
    1.30 +    is(textbox.value, "bar", "Type 'bar' into find bar");
    1.31 +
    1.32 +    EventUtils.synthesizeKey("f", { accelKey: true});
    1.33 +    yield waitForEvent(Elements.findbar, "transitionend");
    1.34 +    ok(document.commandDispatcher.focusedElement, textbox.inputField, "textbox field is focused with Ctrl-F");
    1.35 +    is(textbox.selectionStart, 0, "textbox field is selected with Ctrl-F.");
    1.36 +    is(textbox.selectionEnd, textbox.value.length, "textbox field is selected with Ctrl-F.");
    1.37 +    
    1.38 +    EventUtils.synthesizeKey("VK_ESCAPE", { accelKey: true });
    1.39 +    yield waitForEvent(Elements.findbar, "transitionend");
    1.40 +    is(Elements.findbar.isShowing, false, "Hide find bar with Esc");
    1.41 +
    1.42 +    Browser.closeTab(tab);
    1.43 +  }
    1.44 +});
    1.45 +
    1.46 +gTests.push({
    1.47 +  desc: "Findbar/navbar interaction",
    1.48 +  run: function() {
    1.49 +    let tab = yield addTab(chromeRoot + "browser_findbar.html");
    1.50 +    yield waitForCondition(() => BrowserUI.ready);
    1.51 +    is(ContextUI.navbarVisible, false, "Navbar is hidden by default");
    1.52 +    is(Elements.findbar.isShowing, false, "Find bar is hidden by default");
    1.53 +
    1.54 +    yield showNavBar();
    1.55 +    is(ContextUI.navbarVisible, true, "Navbar is visible");
    1.56 +    is(Elements.findbar.isShowing, false, "Find bar is still hidden");
    1.57 +
    1.58 +    EventUtils.synthesizeKey("f", { accelKey: true });
    1.59 +    yield Promise.all([waitForEvent(Elements.navbar, "transitionend"),
    1.60 +                       waitForEvent(Elements.findbar, "transitionend")]);
    1.61 +    is(ContextUI.navbarVisible, false, "Navbar is hidden");
    1.62 +    is(Elements.findbar.isShowing, true, "Findbar is visible");
    1.63 +
    1.64 +    yield Promise.all([showNavBar(),
    1.65 +                       waitForEvent(Elements.findbar, "transitionend")]);
    1.66 +    is(ContextUI.navbarVisible, true, "Navbar is visible again");
    1.67 +    is(Elements.findbar.isShowing, false, "Find bar is hidden again");
    1.68 +
    1.69 +    Browser.closeTab(tab);
    1.70 +  }
    1.71 +});
    1.72 +
    1.73 +
    1.74 +gTests.push({
    1.75 +  desc: "Show and hide the find bar with mouse",
    1.76 +  run: function() {
    1.77 +    let tab = yield addTab(chromeRoot + "browser_findbar.html");
    1.78 +    yield waitForCondition(() => BrowserUI.ready);
    1.79 +    is(Elements.findbar.isShowing, false, "Find bar is hidden by default");
    1.80 +
    1.81 +    yield showNavBar();
    1.82 +    EventUtils.sendMouseEvent({ type: "click" }, "menu-button");
    1.83 +    EventUtils.sendMouseEvent({ type: "click" }, "context-findinpage");
    1.84 +    yield waitForEvent(Elements.findbar, "transitionend");
    1.85 +    is(Elements.findbar.isShowing, true, "Show find bar with menu item");
    1.86 +
    1.87 +    EventUtils.synthesizeMouse(document.getElementById("findbar-close-button"), 1, 1, {});
    1.88 +    yield waitForEvent(Elements.findbar, "transitionend");
    1.89 +    is(Elements.findbar.isShowing, false, "Hide find bar with close button");
    1.90 +
    1.91 +    Browser.closeTab(tab);
    1.92 +  }
    1.93 +});
    1.94 +
    1.95 +gTests.push({
    1.96 +  desc: "Text at bottom of screen is not obscured by findbar",
    1.97 +  run: function() {
    1.98 +    let textbox = document.getElementById("findbar-textbox");
    1.99 +
   1.100 +    let tab = yield addTab(chromeRoot + "browser_findbar.html");
   1.101 +    yield waitForCondition(() => BrowserUI.ready);
   1.102 +    is(Elements.findbar.isShowing, false, "Find bar is hidden by default");
   1.103 +
   1.104 +    FindHelperUI.show();
   1.105 +    yield waitForCondition(() => FindHelperUI.isActive);
   1.106 +
   1.107 +    EventUtils.sendString("bottom");
   1.108 +    let event = yield waitForEvent(window, "MozDeckOffsetChanged");
   1.109 +    ok(!(event instanceof Error), "MozDeckOffsetChanged received (1)");
   1.110 +    ok(event.detail > 0, "Browser deck shifted upward");
   1.111 +
   1.112 +    textbox.select();
   1.113 +    EventUtils.sendString("bar");
   1.114 +    event = yield waitForEvent(window, "MozDeckOffsetChanged");
   1.115 +    ok(!(event instanceof Error), "MozDeckOffsetChanged received (2)");
   1.116 +    is(event.detail, 0, "Browser deck shifted back to normal");
   1.117 +
   1.118 +    textbox.select();
   1.119 +    EventUtils.sendString("bottom");
   1.120 +    event = yield waitForEvent(window, "MozDeckOffsetChanged");
   1.121 +    ok(!(event instanceof Error), "MozDeckOffsetChanged received (3)");
   1.122 +    ok(event.detail > 0, "Browser deck shifted upward again");
   1.123 +
   1.124 +    let waitForDeckOffset = waitForEvent(window, "MozDeckOffsetChanged");
   1.125 +    let waitForTransitionEnd = waitForEvent(Elements.findbar, "transitionend");
   1.126 +    FindHelperUI.hide();
   1.127 +    event = yield waitForDeckOffset;
   1.128 +    ok(!(event instanceof Error), "MozDeckOffsetChanged received (4)");
   1.129 +    is(event.detail, 0, "Browser deck shifted back to normal when findbar hides");
   1.130 +
   1.131 +    // Cleanup.
   1.132 +    yield waitForTransitionEnd;
   1.133 +    Browser.closeTab(tab);
   1.134 +  }
   1.135 +});

mercurial