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

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:61976d2c48e7
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/. */
4
5 function test() {
6 runTests();
7 }
8
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 });
25
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();
30
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);
35
36 // Simulate touch
37 SelectionHelperUI.attachToCaret(tab.browser, rect0.left + 5, rect0.top + 5);
38
39 // "Show" the keyboard.
40 Services.metro.keyboardHeight = 100;
41 Services.metro.keyboardVisible = true;
42 Services.obs.notifyObservers(null, "metro_softkeyboard_shown", null);
43
44 let event = yield waitForEvent(window, "MozDeckOffsetChanged");
45 is(event.detail, 100, "deck offset by keyboard height");
46
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");
50
51 // "Hide" the keyboard.
52 Services.metro.keyboardHeight = 0;
53 Services.metro.keyboardVisible = false;
54 Services.obs.notifyObservers(null, "metro_softkeyboard_hidden", null);
55
56 yield waitForEvent(window, "MozDeckOffsetChanged");
57
58 finish();
59 }
60 });

mercurial