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