Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=944397 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Basic test for InputMethod API.</title> |
michael@0 | 8 | <script type="application/javascript;version=1.7" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="application/javascript;version=1.7" src="inputmethod_common.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=944397">Mozilla Bug 944397</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <pre id="test"> |
michael@0 | 16 | <script class="testbody" type="application/javascript;version=1.7"> |
michael@0 | 17 | |
michael@0 | 18 | inputmethod_setup(function() { |
michael@0 | 19 | runTest(); |
michael@0 | 20 | }); |
michael@0 | 21 | |
michael@0 | 22 | // The frame script running in file_test_app.html. |
michael@0 | 23 | function appFrameScript() { |
michael@0 | 24 | let input = content.document.getElementById('test-input'); |
michael@0 | 25 | input.oninput = function() { |
michael@0 | 26 | sendAsyncMessage('test:InputMethod:oninput', { |
michael@0 | 27 | value: input.value |
michael@0 | 28 | }); |
michael@0 | 29 | }; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function runTest() { |
michael@0 | 33 | let app, keyboard; |
michael@0 | 34 | |
michael@0 | 35 | /** |
michael@0 | 36 | * So this test does the following: |
michael@0 | 37 | * 1. Create a mozbrowser iframe with a text field in it, and focus the text field |
michael@0 | 38 | * 2. 100ms. after loading we create new keyboard iframe, that will try to execute |
michael@0 | 39 | * replaceSurroundingText on the current active inputcontext |
michael@0 | 40 | * 3. That should trigger 'input' event on the said text field |
michael@0 | 41 | * 4. And if that happens we know everything is OK |
michael@0 | 42 | */ |
michael@0 | 43 | |
michael@0 | 44 | let path = location.pathname; |
michael@0 | 45 | let basePath = location.protocol + '//' + location.host + |
michael@0 | 46 | path.substring(0, path.lastIndexOf('/')); |
michael@0 | 47 | |
michael@0 | 48 | // STEP 1: Create an app frame to recieve keyboard inputs. |
michael@0 | 49 | function step1() { |
michael@0 | 50 | app = document.createElement('iframe'); |
michael@0 | 51 | app.src = basePath + '/file_test_app.html'; |
michael@0 | 52 | app.setAttribute('mozbrowser', true); |
michael@0 | 53 | document.body.appendChild(app); |
michael@0 | 54 | app.addEventListener('mozbrowserloadend', function() { |
michael@0 | 55 | let mm = SpecialPowers.getBrowserFrameMessageManager(app); |
michael@0 | 56 | mm.loadFrameScript('data:,(' + appFrameScript.toString() + ')();', false); |
michael@0 | 57 | mm.addMessageListener("test:InputMethod:oninput", function(ev) { |
michael@0 | 58 | step4(SpecialPowers.wrap(ev).json.value); |
michael@0 | 59 | }); |
michael@0 | 60 | |
michael@0 | 61 | step2(); |
michael@0 | 62 | }); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | function step2() { |
michael@0 | 66 | // STEP 2a: Create a browser frame to load the input method app. |
michael@0 | 67 | keyboard = document.createElement('iframe'); |
michael@0 | 68 | keyboard.setAttribute('mozbrowser', true); |
michael@0 | 69 | document.body.appendChild(keyboard); |
michael@0 | 70 | |
michael@0 | 71 | // STEP 2b: Grant input privileges to the keyboard iframe |
michael@0 | 72 | let imeUrl = basePath + '/file_inputmethod.html#data'; |
michael@0 | 73 | |
michael@0 | 74 | SpecialPowers.pushPermissions([{ |
michael@0 | 75 | type: 'input', |
michael@0 | 76 | allow: true, |
michael@0 | 77 | context: imeUrl |
michael@0 | 78 | }], function() { |
michael@0 | 79 | // STEP 2c: Tell Gecko to use this iframe as its keyboard app |
michael@0 | 80 | let req = keyboard.setInputMethodActive(true); |
michael@0 | 81 | |
michael@0 | 82 | req.onsuccess = function() { |
michael@0 | 83 | ok(true, 'setInputMethodActive succeeded.'); |
michael@0 | 84 | }; |
michael@0 | 85 | |
michael@0 | 86 | req.onerror = function() { |
michael@0 | 87 | ok(false, 'setInputMethodActive failed: ' + this.error.name); |
michael@0 | 88 | inputmethod_cleanup(); |
michael@0 | 89 | }; |
michael@0 | 90 | |
michael@0 | 91 | // STEP 3: Loads the input method app to the browser frame after a delay. |
michael@0 | 92 | setTimeout(function() { |
michael@0 | 93 | keyboard.src = imeUrl; |
michael@0 | 94 | }, 100); |
michael@0 | 95 | }); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | function step4(val) { |
michael@0 | 99 | ok(true, 'Keyboard input was received.'); |
michael@0 | 100 | is(val, '#dataYuan', 'Input value'); |
michael@0 | 101 | inputmethod_cleanup(); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | step1(); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | </script> |
michael@0 | 108 | </pre> |
michael@0 | 109 | </body> |
michael@0 | 110 | </html> |
michael@0 | 111 |