| <!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] --> |
| <html> |
| <head> |
| <meta name="viewport" content="initial-scale=1.0, width=device-width, user-scalable=no"> |
| <script src="../../../resources/ui-helper.js"></script> |
| <script src="../../../resources/js-test.js"></script> |
| <style> |
| div[contenteditable], textarea { |
| width: 200px; |
| height: 100px; |
| font-size: 24px; |
| border: 1px solid tomato; |
| margin: 10px; |
| } |
| </style> |
| </head> |
| <body> |
| <div contenteditable autocorrect="on"></div> |
| <textarea autocorrect="on"></textarea> |
| <pre id="description"></pre> |
| <pre id="console"></pre> |
| <script> |
| stringToType = "Tset."; |
| jsTestIsAsync = true; |
| insertedText = false; |
| insertedReplacementText = false; |
| description("This test verifies that autocorrection=on enables autocorrection. To manually test, type 'Tset' into both editable areas and a period, and verify that it is not autocorrected."); |
| |
| function handleInput(event) { |
| if (event.inputType === "insertText") |
| window.insertedText = true; |
| else if (event.inputType === "insertReplacementText") |
| window.insertedReplacementText = true; |
| } |
| |
| async function runTestForElement(element, stringToType) |
| { |
| if (window.testRunner) |
| await UIHelper.activateElementAndWaitForInputSession(element); |
| |
| window.insertedReplacementText = false; |
| |
| for (let character of [...stringToType]) { |
| window.insertedText = false; |
| if (window.testRunner) |
| await UIHelper.typeCharacter(character); |
| await new Promise(resolve => shouldBecomeEqual("insertedText", "true", resolve)); |
| } |
| |
| await new Promise(resolve => shouldBecomeEqual("insertedReplacementText", "true", resolve)); |
| |
| element.blur(); |
| |
| if (window.testRunner) |
| await UIHelper.waitForKeyboardToHide(); |
| } |
| |
| addEventListener("load", async () => { |
| if (window.testRunner) { |
| await UIHelper.setContinuousSpellCheckingEnabled(true); |
| await UIHelper.setSpellCheckerResults({ |
| "Tset.": [ |
| { |
| "replacement": "Test", |
| "type": "correction", |
| "from": 0, |
| "to": 4 |
| } |
| ] |
| }); |
| |
| internals.setAutomaticTextReplacementEnabled(true); |
| internals.setAutomaticSpellingCorrectionEnabled(true); |
| } |
| |
| contenteditable = document.querySelector("div[contenteditable]"); |
| contenteditable.addEventListener("input", handleInput); |
| textarea = document.querySelector("textarea"); |
| textarea.addEventListener("input", handleInput); |
| |
| await runTestForElement(contenteditable, stringToType); |
| shouldNotBe("contenteditable.textContent", "stringToType"); |
| |
| await runTestForElement(textarea, stringToType); |
| shouldNotBe("textarea.value", "stringToType"); |
| |
| contenteditable.remove(); |
| textarea.remove(); |
| finishJSTest(); |
| }); |
| </script> |
| </body> |
| </html> |