diff --git a/dom/inputmethod/Keyboard.jsm b/dom/inputmethod/Keyboard.jsm index 14b56041be6..a0e5bde5707 100644 --- a/dom/inputmethod/Keyboard.jsm +++ b/dom/inputmethod/Keyboard.jsm @@ -103,7 +103,12 @@ this.Keyboard = { return; } - if (!mm.assertPermission("input")) { + let testing = false; + try { + testing = Services.prefs.getBoolPref("dom.mozInputMethod.testing"); + } catch (e) { + } + if (!testing && !mm.assertPermission("input")) { dump("Keyboard message " + msg.name + " from a content process with no 'input' privileges."); return; @@ -180,11 +185,9 @@ this.Keyboard = { handleFocusChange: function keyboardHandleFocusChange(msg) { this.forwardEvent('Keyboard:FocusChange', msg); - let browser = Services.wm.getMostRecentWindow("navigator:browser"); - // Chrome event, used also to render value selectors; that's why we need // the info about choices / min / max here as well... - browser.shell.sendChromeEvent({ + this.sendChromeEvent({ type: 'inputmethod-contextchange', inputType: msg.data.type, value: msg.data.value, @@ -219,15 +222,13 @@ this.Keyboard = { }, showInputMethodPicker: function keyboardShowInputMethodPicker() { - let browser = Services.wm.getMostRecentWindow("navigator:browser"); - browser.shell.sendChromeEvent({ + this.sendChromeEvent({ type: "inputmethod-showall" }); }, switchToNextInputMethod: function keyboardSwitchToNextInputMethod() { - let browser = Services.wm.getMostRecentWindow("navigator:browser"); - browser.shell.sendChromeEvent({ + this.sendChromeEvent({ type: "inputmethod-next" }); }, @@ -267,6 +268,13 @@ this.Keyboard = { this._layouts = layouts; ppmm.broadcastAsyncMessage('Keyboard:LayoutsChange', layouts); + }, + + sendChromeEvent: function(event) { + let browser = Services.wm.getMostRecentWindow("navigator:browser"); + if (browser && browser.shell) { + browser.shell.sendChromeEvent(event);; + } } }; diff --git a/dom/inputmethod/mochitest/file_test_app.html b/dom/inputmethod/mochitest/file_test_app.html new file mode 100644 index 00000000000..8cecee85333 --- /dev/null +++ b/dom/inputmethod/mochitest/file_test_app.html @@ -0,0 +1,10 @@ + + +
+ + + + diff --git a/dom/inputmethod/mochitest/inputmethod_common.js b/dom/inputmethod/mochitest/inputmethod_common.js new file mode 100644 index 00000000000..f5b3a90d68f --- /dev/null +++ b/dom/inputmethod/mochitest/inputmethod_common.js @@ -0,0 +1,32 @@ +function inputmethod_setup(callback) { + SimpleTest.waitForExplicitFinish(); + let appInfo = SpecialPowers.Cc['@mozilla.org/xre/app-info;1'] + .getService(SpecialPowers.Ci.nsIXULAppInfo); + if (appInfo.name != 'B2G') { + SpecialPowers.Cu.import("resource://gre/modules/Keyboard.jsm", this); + } + + let permissions = []; + ['input-manage', 'browser'].forEach(function(name) { + permissions.push({ + type: name, + allow: true, + context: document + }); + }); + + SpecialPowers.pushPermissions(permissions, function() { + let prefs = [ + ['dom.mozBrowserFramesEnabled', true], + // Enable navigator.mozInputMethod. + ['dom.mozInputMethod.enabled', true], + // Bypass the permission check for mozInputMethod API. + ['dom.mozInputMethod.testing', true] + ]; + SpecialPowers.pushPrefEnv({set: prefs}, callback); + }); +} + +function inputmethod_cleanup() { + SimpleTest.finish(); +} diff --git a/dom/inputmethod/mochitest/mochitest.ini b/dom/inputmethod/mochitest/mochitest.ini new file mode 100644 index 00000000000..84c391c2eb6 --- /dev/null +++ b/dom/inputmethod/mochitest/mochitest.ini @@ -0,0 +1,7 @@ +[DEFAULT] +support-files = + inputmethod_common.js + file_test_app.html + +[test_basic.html] + diff --git a/dom/inputmethod/mochitest/moz.build b/dom/inputmethod/mochitest/moz.build new file mode 100644 index 00000000000..3cf16eb0cfe --- /dev/null +++ b/dom/inputmethod/mochitest/moz.build @@ -0,0 +1,8 @@ +# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +MOCHITEST_MANIFESTS += ['mochitest.ini'] + diff --git a/dom/inputmethod/mochitest/test_basic.html b/dom/inputmethod/mochitest/test_basic.html new file mode 100644 index 00000000000..bcdfecb84c5 --- /dev/null +++ b/dom/inputmethod/mochitest/test_basic.html @@ -0,0 +1,137 @@ + + + + ++ ++ + + diff --git a/dom/inputmethod/moz.build b/dom/inputmethod/moz.build index e798c584285..3f68aa509c4 100644 --- a/dom/inputmethod/moz.build +++ b/dom/inputmethod/moz.build @@ -4,6 +4,8 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. +TEST_DIRS += ['mochitest'] + XPIDL_SOURCES += [ 'nsIB2GKeyboard.idl', ] diff --git a/testing/mochitest/android.json b/testing/mochitest/android.json index 41ff12af9b4..8e5febcb1b8 100644 --- a/testing/mochitest/android.json +++ b/testing/mochitest/android.json @@ -138,6 +138,7 @@ "dom/indexedDB/test/test_webapp_clearBrowserData_inproc_inproc.html": "No test app installed", "dom/indexedDB/test/test_webapp_clearBrowserData_inproc_oop.html": "No test app installed", "dom/indexedDB/test/test_webapp_clearBrowserData_oop_inproc.html": "No test app installed", + "dom/inputmethod": "Not supported on Android", "dom/network/tests/test_network_basics.html": "", "dom/permission/tests/test_permission_basics.html": "", "dom/mobilemessage/tests/test_sms_basics.html": "Bug 909036", diff --git a/testing/mochitest/androidx86.json b/testing/mochitest/androidx86.json index d093569dee5..aa9e15edf07 100644 --- a/testing/mochitest/androidx86.json +++ b/testing/mochitest/androidx86.json @@ -215,6 +215,7 @@ "dom/indexedDB/test/test_webapp_clearBrowserData_inproc_inproc.html": "No test app installed", "dom/indexedDB/test/test_webapp_clearBrowserData_inproc_oop.html": "No test app installed", "dom/indexedDB/test/test_webapp_clearBrowserData_oop_inproc.html": "No test app installed", + "dom/inputmethod": "Not supported on Android", "dom/media/tests/ipc/test_ipc.html": "x86 only bug 936226", "dom/network/tests/test_network_basics.html": "", "dom/permission/tests/test_permission_basics.html": "",