Chromium Code Reviews| 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; |
|
rlanday
2017/06/10 06:20:39
If we move the x coord here over not 1 but 2 pixel
Xiaocheng
2017/06/12 19:06:26
So the root cause seems to incorrect coordinate ca
| |
| 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.', | |
|
Xiaocheng
2017/06/10 01:02:51
nit: The title should be "Setup of context clickin
| |
| 98 callback: sample => test(() => { | |
| 99 const container = sample.document.querySelector('div'); | |
| 100 const shouldSelect = isMac(navigator.platform); | |
| 101 | |
| 102 assertContextClickSelection( | |
| 103 container, 0, '', | |
|
rlanday
2017/06/10 00:40:05
Note: we might want to modify this test so the mis
Xiaocheng
2017/06/10 01:02:51
If the behavior on Mac is different when the missp
Xiaocheng
2017/06/10 01:07:30
Wait... Let's investigate first why the behavior i
| |
| 104 'Context clicking immediately before "wellcome" does not select it') ; | |
| 105 | |
| 106 // On Mac, right-clicking immediately after a word will select the space after it. | |
| 107 if (shouldSelect) { | |
| 108 assertContextClickSelection( | |
| 109 container, 8, ' ', | |
| 110 'Context clicking immediately after "wellcome" selects the space aft er it'); | |
| 111 return; | |
| 112 } | |
| 113 | |
| 114 assertContextClickSelection( | |
| 115 container, 8, '', | |
| 116 'Context clicking immediately after "wellcome" does not select it'); | |
| 117 }, | |
| 118 'Context clicking immediately before or after misspelled word in editable DIV does not select it.', | |
| 119 {sample: sample, blockHeldTest: true}) | |
| 120 }); | |
| 121 | |
| 122 spellcheck_test( | |
| 123 '<div contenteditable>wellcome home.|</div>', | |
| 124 '', | |
| 125 '<div contenteditable>#wellcome# home.</div>', | |
| 126 { | |
| 97 title: 'Mark initial misspelling "wellcome" in editable DIV.', | 127 title: 'Mark initial misspelling "wellcome" in editable DIV.', |
| 98 callback: sample => test(() => { | 128 callback: sample => test(() => { |
| 99 const container = sample.document.querySelector('div'); | 129 const container = sample.document.querySelector('div'); |
| 100 assertContextClickSelection( | 130 assertContextClickSelection( |
| 101 container, 4, 'wellcome', | 131 container, 4, 'wellcome', |
| 102 'Context clicking "wellcome" selects the misspelled word', | 132 'Context clicking "wellcome" selects the misspelled word', |
| 103 'welcome'); | 133 'welcome'); |
| 104 | 134 |
| 105 const shouldSelect = isMac(navigator.platform); | 135 const shouldSelect = isMac(navigator.platform); |
| 106 if (shouldSelect) { | 136 if (shouldSelect) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 const container = sample.document.querySelector('div'); | 174 const container = sample.document.querySelector('div'); |
| 145 assertContextClickSelection( | 175 assertContextClickSelection( |
| 146 container, 17, 'upper case', | 176 container, 17, 'upper case', |
| 147 'Context clicking "upper case" selects the misspelling.', | 177 'Context clicking "upper case" selects the misspelling.', |
| 148 'uppercase'); | 178 'uppercase'); |
| 149 }, | 179 }, |
| 150 'Context clicking multi-word misspelling "upper case" in editable DIV sele cts the words.', | 180 'Context clicking multi-word misspelling "upper case" in editable DIV sele cts the words.', |
| 151 {sample: sample, blockHeldTest: true}) | 181 {sample: sample, blockHeldTest: true}) |
| 152 }); | 182 }); |
| 153 </script> | 183 </script> |
| OLD | NEW |