browser/metro/base/tests/mochitest/browser_onscreen_keyboard.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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 function test() {
     6   runTests();
     7 }
     9 gTests.push({
    10   desc: "Onscreen keyboard tests",
    11   run: function() {
    12     // By design, Metro apps can't show the keyboard programmatically, so we
    13     // can't use the real keyboard in this test:
    14     // http://msdn.microsoft.com/en-us/library/windows/apps/hh465404.aspx#user-driven_invocation
    15     //
    16     // Instead, we will use this mock object to simulate keyboard changes.
    17     let originalUtils = Services.metro;
    18     Services.metro = {
    19       keyboardHeight: 0,
    20       keyboardVisible: false
    21     };
    22     registerCleanupFunction(function() {
    23       Services.metro = originalUtils;
    24     });
    26     let tab = yield addTab(chromeRoot + "browser_onscreen_keyboard.html");
    27     // Explicitly dismiss the toolbar at the start, because it messes with the
    28     // keyboard and sizing if it's dismissed later.
    29     ContextUI.dismiss();
    31     let doc = tab.browser.contentDocument;
    32     let text = doc.getElementById("text")
    33     let rect0 = text.getBoundingClientRect();
    34     let rect0browserY = Math.floor(tab.browser.ptClientToBrowser(rect0.left, rect0.top).y);
    36     // Simulate touch
    37     SelectionHelperUI.attachToCaret(tab.browser, rect0.left + 5, rect0.top + 5);
    39     // "Show" the keyboard.
    40     Services.metro.keyboardHeight = 100;
    41     Services.metro.keyboardVisible = true;
    42     Services.obs.notifyObservers(null, "metro_softkeyboard_shown", null);
    44     let event = yield waitForEvent(window, "MozDeckOffsetChanged");
    45     is(event.detail, 100, "deck offset by keyboard height");
    47     let rect1 = text.getBoundingClientRect();
    48     let rect1browserY = Math.floor(tab.browser.ptClientToBrowser(rect1.left, rect1.top).y);
    49     is(rect1browserY, rect0browserY + 100, "text field moves up by 100px");
    51     // "Hide" the keyboard.
    52     Services.metro.keyboardHeight = 0;
    53     Services.metro.keyboardVisible = false;
    54     Services.obs.notifyObservers(null, "metro_softkeyboard_hidden", null);
    56     yield waitForEvent(window, "MozDeckOffsetChanged");
    58     finish();
    59   }
    60 });

mercurial