diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/inputmethod/mochitest/test_unload.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/inputmethod/mochitest/test_unload.html')
-rw-r--r-- | dom/inputmethod/mochitest/test_unload.html | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/dom/inputmethod/mochitest/test_unload.html b/dom/inputmethod/mochitest/test_unload.html new file mode 100644 index 000000000..bef9d1485 --- /dev/null +++ b/dom/inputmethod/mochitest/test_unload.html @@ -0,0 +1,167 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1122463 +https://bugzilla.mozilla.org/show_bug.cgi?id=820057 +--> +<head> + <title>Test focus when page unloads</title> + <script type="application/javascript;version=1.7" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <script type="application/javascript;version=1.7" src="inputmethod_common.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1122463">Mozilla Bug 1122463</a> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=820057">Mozilla Bug 820057</a> +<p id="display"></p> +<pre id="test"> +<script class="testbody" type="application/javascript;version=1.7"> + +inputmethod_setup(function() { + runTest(); +}); + +let appFrameScript = function appFrameScript() { + let form1 = content.document.body.firstElementChild; + let input1 = form1.firstElementChild; + let submit1 = form1.lastElementChild; + let input2; + + let cancelSubmit = function(evt) { + evt.preventDefault(); + }; + + // Content of the second page. + form1.action = 'file_test_unload_action.html'; + + let i = 1; + + input1.focus(); + + addMessageListener('test:next', function() { + i++; + switch (i) { + case 2: + // Click the submit button, trigger the submit event and make our + // installed event listener preventing the submission. + form1.addEventListener('submit', cancelSubmit); + submit1.click(); + + sendAsyncMessage('test:step'); + + break; + + case 3: + // Actually submit the form. + form1.removeEventListener('submit', cancelSubmit); + submit1.click(); + + break; + + case 4: + if (!content.document.body) { + content.onload = function() { + content.onload = null; + + let input2 = content.document.body.firstElementChild; + input2.focus(); + }; + + return; + } + + input2 = content.document.body.firstElementChild; + input2.focus(); + + break; + + case 5: + content.location.href = 'data:text/html,Hello!'; + + break; + } + }); +}; + +function runTest() { + let im = navigator.mozInputMethod; + + let i = 0; + function nextStep() { + let inputcontext = navigator.mozInputMethod.inputcontext; + + i++; + switch (i) { + // focus on the first input receives the first input context. + case 1: + ok(!!inputcontext, '1) Receving the first input context'); + is(inputcontext.textAfterCursor, 'First'); + + mm.sendAsyncMessage('test:next'); + break; + + // Cancelled submission should not cause us lost focus. + case 2: + ok(!!inputcontext, '2) Receving the first input context'); + is(inputcontext.textAfterCursor, 'First'); + + mm.sendAsyncMessage('test:next'); + break; + + // Real submit and page transition should cause us lost focus. + // XXX: Unless we could delay the page transition, we does not know if + // the inputcontext is lost because of the submit or the pagehide/beforeload + // event. + case 3: + is(inputcontext, null, '3) Receving null inputcontext'); + + mm.sendAsyncMessage('test:next'); + + break; + + // Regaining focus of input in the second page. + case 4: + ok(!!inputcontext, '4) Receving the second input context'); + is(inputcontext.textAfterCursor, 'Second'); + + mm.sendAsyncMessage('test:next'); + + break; + + // Page transition should cause us lost focus + case 5: + is(inputcontext, null, '5) Receving null inputcontext'); + + inputmethod_cleanup(); + + break; + } + } + + // Set current page as an input method. + SpecialPowers.wrap(im).setActive(true); + + let iframe = document.createElement('iframe'); + iframe.src = 'file_test_unload.html'; + iframe.setAttribute('mozbrowser', true); + document.body.appendChild(iframe); + + let mm = SpecialPowers.getBrowserFrameMessageManager(iframe); + im.oninputcontextchange = nextStep; + + let frameScriptLoaded = false; + iframe.addEventListener('mozbrowserloadend', function() { + if (frameScriptLoaded) + return; + + frameScriptLoaded = true; + mm.addMessageListener('test:step', nextStep); + mm.loadFrameScript('data:,(' + encodeURIComponent(appFrameScript.toString()) + ')();', false); + }); +} + +</script> +</pre> +</body> +</html> + |