1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/tests/mochitest/browser_onscreen_keyboard.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function test() { 1.9 + runTests(); 1.10 +} 1.11 + 1.12 +gTests.push({ 1.13 + desc: "Onscreen keyboard tests", 1.14 + run: function() { 1.15 + // By design, Metro apps can't show the keyboard programmatically, so we 1.16 + // can't use the real keyboard in this test: 1.17 + // http://msdn.microsoft.com/en-us/library/windows/apps/hh465404.aspx#user-driven_invocation 1.18 + // 1.19 + // Instead, we will use this mock object to simulate keyboard changes. 1.20 + let originalUtils = Services.metro; 1.21 + Services.metro = { 1.22 + keyboardHeight: 0, 1.23 + keyboardVisible: false 1.24 + }; 1.25 + registerCleanupFunction(function() { 1.26 + Services.metro = originalUtils; 1.27 + }); 1.28 + 1.29 + let tab = yield addTab(chromeRoot + "browser_onscreen_keyboard.html"); 1.30 + // Explicitly dismiss the toolbar at the start, because it messes with the 1.31 + // keyboard and sizing if it's dismissed later. 1.32 + ContextUI.dismiss(); 1.33 + 1.34 + let doc = tab.browser.contentDocument; 1.35 + let text = doc.getElementById("text") 1.36 + let rect0 = text.getBoundingClientRect(); 1.37 + let rect0browserY = Math.floor(tab.browser.ptClientToBrowser(rect0.left, rect0.top).y); 1.38 + 1.39 + // Simulate touch 1.40 + SelectionHelperUI.attachToCaret(tab.browser, rect0.left + 5, rect0.top + 5); 1.41 + 1.42 + // "Show" the keyboard. 1.43 + Services.metro.keyboardHeight = 100; 1.44 + Services.metro.keyboardVisible = true; 1.45 + Services.obs.notifyObservers(null, "metro_softkeyboard_shown", null); 1.46 + 1.47 + let event = yield waitForEvent(window, "MozDeckOffsetChanged"); 1.48 + is(event.detail, 100, "deck offset by keyboard height"); 1.49 + 1.50 + let rect1 = text.getBoundingClientRect(); 1.51 + let rect1browserY = Math.floor(tab.browser.ptClientToBrowser(rect1.left, rect1.top).y); 1.52 + is(rect1browserY, rect0browserY + 100, "text field moves up by 100px"); 1.53 + 1.54 + // "Hide" the keyboard. 1.55 + Services.metro.keyboardHeight = 0; 1.56 + Services.metro.keyboardVisible = false; 1.57 + Services.obs.notifyObservers(null, "metro_softkeyboard_hidden", null); 1.58 + 1.59 + yield waitForEvent(window, "MozDeckOffsetChanged"); 1.60 + 1.61 + finish(); 1.62 + } 1.63 +});