michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() { michael@0: runTests(); michael@0: } michael@0: michael@0: gTests.push({ michael@0: desc: "Onscreen keyboard tests", michael@0: run: function() { michael@0: // By design, Metro apps can't show the keyboard programmatically, so we michael@0: // can't use the real keyboard in this test: michael@0: // http://msdn.microsoft.com/en-us/library/windows/apps/hh465404.aspx#user-driven_invocation michael@0: // michael@0: // Instead, we will use this mock object to simulate keyboard changes. michael@0: let originalUtils = Services.metro; michael@0: Services.metro = { michael@0: keyboardHeight: 0, michael@0: keyboardVisible: false michael@0: }; michael@0: registerCleanupFunction(function() { michael@0: Services.metro = originalUtils; michael@0: }); michael@0: michael@0: let tab = yield addTab(chromeRoot + "browser_onscreen_keyboard.html"); michael@0: // Explicitly dismiss the toolbar at the start, because it messes with the michael@0: // keyboard and sizing if it's dismissed later. michael@0: ContextUI.dismiss(); michael@0: michael@0: let doc = tab.browser.contentDocument; michael@0: let text = doc.getElementById("text") michael@0: let rect0 = text.getBoundingClientRect(); michael@0: let rect0browserY = Math.floor(tab.browser.ptClientToBrowser(rect0.left, rect0.top).y); michael@0: michael@0: // Simulate touch michael@0: SelectionHelperUI.attachToCaret(tab.browser, rect0.left + 5, rect0.top + 5); michael@0: michael@0: // "Show" the keyboard. michael@0: Services.metro.keyboardHeight = 100; michael@0: Services.metro.keyboardVisible = true; michael@0: Services.obs.notifyObservers(null, "metro_softkeyboard_shown", null); michael@0: michael@0: let event = yield waitForEvent(window, "MozDeckOffsetChanged"); michael@0: is(event.detail, 100, "deck offset by keyboard height"); michael@0: michael@0: let rect1 = text.getBoundingClientRect(); michael@0: let rect1browserY = Math.floor(tab.browser.ptClientToBrowser(rect1.left, rect1.top).y); michael@0: is(rect1browserY, rect0browserY + 100, "text field moves up by 100px"); michael@0: michael@0: // "Hide" the keyboard. michael@0: Services.metro.keyboardHeight = 0; michael@0: Services.metro.keyboardVisible = false; michael@0: Services.obs.notifyObservers(null, "metro_softkeyboard_hidden", null); michael@0: michael@0: yield waitForEvent(window, "MozDeckOffsetChanged"); michael@0: michael@0: finish(); michael@0: } michael@0: });