| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../../resources/testharness.js"></script> | 2 <script src="../../resources/testharness.js"></script> |
| 3 <script src="../../resources/testharnessreport.js"></script> | 3 <script src="../../resources/testharnessreport.js"></script> |
| 4 <script src="../assert_selection.js"></script> | 4 <script src="../assert_selection.js"></script> |
| 5 <script src="spellcheck_test.js"></script> | 5 <script src="spellcheck_test.js"></script> |
| 6 | 6 |
| 7 <script> | 7 <script> |
| 8 test(() => assert_not_equals(window.internals, undefined), | 8 test(() => assert_not_equals(window.internals, undefined), |
| 9 'This test requires internals to inspect INPUT elements.'); | 9 'This test requires internals to inspect INPUT elements.'); |
| 10 | 10 |
| 11 test(() => assert_not_equals(window.eventSender, undefined), | 11 test(() => assert_not_equals(window.eventSender, undefined), |
| 12 'This test requires event sender to simulate keyboard and mouse actions.'); | 12 'This test requires event sender to simulate keyboard and mouse actions.'); |
| 13 | 13 |
| 14 const kNumTests = 4; | 14 const kNumTests = 5; |
| 15 const heldTest = async_test( | 15 const heldTest = async_test( |
| 16 () => assert_true(true), | 16 () => assert_true(true), |
| 17 'Dummy async test for blocking test harness.', | 17 'Dummy async test for blocking test harness.', |
| 18 {finishCount: 0}); | 18 {finishCount: 0}); |
| 19 | 19 |
| 20 add_result_callback(testObj => { | 20 add_result_callback(testObj => { |
| 21 if (!testObj.properties.blockHeldTest) | 21 if (!testObj.properties.blockHeldTest) |
| 22 return; | 22 return; |
| 23 testObj.properties.sample.remove(); | 23 testObj.properties.sample.remove(); |
| 24 if (++heldTest.properties.finishCount === kNumTests) | 24 if (++heldTest.properties.finishCount === kNumTests) |
| 25 heldTest.done(); | 25 heldTest.done(); |
| 26 }); | 26 }); |
| 27 | 27 |
| 28 function findTextNode(node) { | 28 function findTextNode(node) { |
| 29 if (node.nodeName !== 'INPUT' && node.nodeName !== 'TEXTAREA') | 29 if (node.nodeName !== 'INPUT' && node.nodeName !== 'TEXTAREA') |
| 30 return node.firstChild; | 30 return node.firstChild; |
| 31 return internals.shadowRoot(node).getElementById('inner-editor').firstChild; | 31 return internals.shadowRoot(node).getElementById('inner-editor').firstChild; |
| 32 } | 32 } |
| 33 | 33 |
| 34 function assertContextClickSelection( | 34 function assertContextClickSelection( |
| 35 container, offset, expected, title, opt_suggestion) { | 35 container, offset, expected, title, opt_suggestion) { |
| 36 const document = container.ownerDocument; | 36 const document = container.ownerDocument; |
| 37 const textNode = findTextNode(container); | 37 const textNode = findTextNode(container); |
| 38 const range = document.createRange(); | 38 const range = document.createRange(); |
| 39 range.setStart(textNode, offset); | 39 range.setStart(textNode, offset); |
| 40 | 40 |
| 41 const rect = range.getClientRects()[0]; | 41 const rect = range.getClientRects()[0]; |
| 42 const x = document.offsetLeft + rect.left; | 42 const x = document.offsetLeft + rect.left + 2; |
| 43 const y = document.offsetTop + rect.top + rect.height / 2; | 43 const y = document.offsetTop + rect.top + rect.height / 2; |
| 44 eventSender.mouseMoveTo(x, y); | 44 eventSender.mouseMoveTo(x, y); |
| 45 const contextMenuElements = eventSender.contextClick(); | 45 const contextMenuElements = eventSender.contextClick(); |
| 46 | 46 |
| 47 // Esc key to hide the context menu. | 47 // Esc key to hide the context menu. |
| 48 eventSender.keyDown('Escape', null); | 48 eventSender.keyDown('Escape', null); |
| 49 | 49 |
| 50 assert_equals(document.getSelection().toString(), expected, title); | 50 assert_equals(document.getSelection().toString(), expected, title); |
| 51 | 51 |
| 52 if (opt_suggestion === undefined) | 52 if (opt_suggestion === undefined) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 }, | 87 }, |
| 88 'Context clicking misspelled word in INPUT selects the word.', | 88 'Context clicking misspelled word in INPUT selects the word.', |
| 89 {sample: sample, blockHeldTest: true}) | 89 {sample: sample, blockHeldTest: true}) |
| 90 }); | 90 }); |
| 91 | 91 |
| 92 spellcheck_test( | 92 spellcheck_test( |
| 93 '<div contenteditable>wellcome home.|</div>', | 93 '<div contenteditable>wellcome home.|</div>', |
| 94 '', | 94 '', |
| 95 '<div contenteditable>#wellcome# home.</div>', | 95 '<div contenteditable>#wellcome# home.</div>', |
| 96 { | 96 { |
| 97 title: 'Context click at boundary of misspelled word.', |
| 98 callback: sample => test(() => { |
| 99 const container = sample.document.querySelector('div'); |
| 100 const shouldSelect = isMac(navigator.platform); |
| 101 if (shouldSelect) { |
| 102 // On Mac, right-clicking immediately before a word will select it. |
| 103 assertContextClickSelection( |
| 104 container, 0, 'wellcome', |
| 105 'Context clicking immediately before "wellcome" selects it'); |
| 106 |
| 107 // De-select "wellcome"; otherwise, context-clicking immediately after
"wellcome" will |
| 108 // not change the selection (since it would select a space and not ano
ther word) |
| 109 container.ownerDocument.getSelection().removeAllRanges(); |
| 110 |
| 111 // On Mac, right-clicking immediately after a word will select the spa
ce after it. |
| 112 assertContextClickSelection( |
| 113 container, 8, ' ', |
| 114 'Context clicking immediately after "wellcome" selects the space aft
er it'); |
| 115 return; |
| 116 } |
| 117 |
| 118 assertContextClickSelection( |
| 119 container, 0, '', |
| 120 'Context clicking immediately before "wellcome" does not select it')
; |
| 121 |
| 122 assertContextClickSelection( |
| 123 container, 8, '', |
| 124 'Context clicking immediately after "wellcome" does not select it'); |
| 125 }, |
| 126 'Context clicking immediately before or after misspelled word in editable
DIV does not select it.', |
| 127 {sample: sample, blockHeldTest: true}) |
| 128 }); |
| 129 |
| 130 spellcheck_test( |
| 131 '<div contenteditable>wellcome home.|</div>', |
| 132 '', |
| 133 '<div contenteditable>#wellcome# home.</div>', |
| 134 { |
| 97 title: 'Mark initial misspelling "wellcome" in editable DIV.', | 135 title: 'Mark initial misspelling "wellcome" in editable DIV.', |
| 98 callback: sample => test(() => { | 136 callback: sample => test(() => { |
| 99 const container = sample.document.querySelector('div'); | 137 const container = sample.document.querySelector('div'); |
| 100 assertContextClickSelection( | 138 assertContextClickSelection( |
| 101 container, 4, 'wellcome', | 139 container, 4, 'wellcome', |
| 102 'Context clicking "wellcome" selects the misspelled word', | 140 'Context clicking "wellcome" selects the misspelled word', |
| 103 'welcome'); | 141 'welcome'); |
| 104 | 142 |
| 105 const shouldSelect = isMac(navigator.platform); | 143 const shouldSelect = isMac(navigator.platform); |
| 106 if (shouldSelect) { | 144 if (shouldSelect) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 const container = sample.document.querySelector('div'); | 182 const container = sample.document.querySelector('div'); |
| 145 assertContextClickSelection( | 183 assertContextClickSelection( |
| 146 container, 17, 'upper case', | 184 container, 17, 'upper case', |
| 147 'Context clicking "upper case" selects the misspelling.', | 185 'Context clicking "upper case" selects the misspelling.', |
| 148 'uppercase'); | 186 'uppercase'); |
| 149 }, | 187 }, |
| 150 'Context clicking multi-word misspelling "upper case" in editable DIV sele
cts the words.', | 188 'Context clicking multi-word misspelling "upper case" in editable DIV sele
cts the words.', |
| 151 {sample: sample, blockHeldTest: true}) | 189 {sample: sample, blockHeldTest: true}) |
| 152 }); | 190 }); |
| 153 </script> | 191 </script> |
| OLD | NEW |