| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../resources/testharness.js"></script> |
| 3 <script src="../../resources/testharnessreport.js"></script> |
| 4 <script src="../assert_selection.js"></script> |
| 5 <script src="spellcheck_test.js"></script> |
| 6 |
| 7 <script> |
| 8 test(() => assert_not_equals(window.internals, undefined), |
| 9 'This test requires internals to set editing behavior.'); |
| 10 |
| 11 test(() => assert_not_equals(window.eventSender, undefined), |
| 12 'This test requires event sender to simulate keyboard and mouse actions.'); |
| 13 |
| 14 function assertContextClickSelection(input, offsetX, expected) { |
| 15 const document = input.ownerDocument; |
| 16 const x = document.offsetLeft + input.offsetLeft + offsetX; |
| 17 const y = document.offsetTop + input.offsetTop + input.offsetHeight / 2; |
| 18 eventSender.mouseMoveTo(x, y); |
| 19 eventSender.contextClick(); |
| 20 |
| 21 // Esc key to hide the context menu. |
| 22 eventSender.keyDown('Escape', null); |
| 23 |
| 24 assert_equals(document.getSelection().toString(), expected); |
| 25 } |
| 26 |
| 27 function getTextWidth(input) { |
| 28 const shadowRoot = internals.shadowRoot(input); |
| 29 const innerEditor = shadowRoot.firstChild; |
| 30 const text = innerEditor.firstChild; |
| 31 const range = input.ownerDocument.createRange(); |
| 32 range.selectNode(text); |
| 33 return range.getClientRects()[0].width; |
| 34 } |
| 35 |
| 36 function contextClickSelectionTests(input) { |
| 37 const textWidth = getTextWidth(input); |
| 38 |
| 39 // There seems to be some bug with testharness.js that, if the first test |
| 40 // completes before the next two tests start, the whole testharness is |
| 41 // considered as ran to complete and the subsequent tests are not evaluated. |
| 42 // Hence, we use async_test and defer the completion as a workaround. |
| 43 const heldTest = async_test( |
| 44 () => assertContextClickSelection(input, textWidth / 4, 'wellcome'), |
| 45 'Context clicking "wellcome" selects the misspelled word'); |
| 46 |
| 47 ['Win', 'Unix', 'Android', 'Mac'].forEach(platform => { |
| 48 internals.settings.setEditingBehavior(platform); |
| 49 const shouldSelect = platform === 'Mac'; |
| 50 test(() => assertContextClickSelection(input, textWidth * 3 / 4, |
| 51 shouldSelect ? 'home' : ''), |
| 52 'Context clicking "home" ' + |
| 53 `${shouldSelect ? 'selects' : 'does not select'} ` + |
| 54 `the correctly spelled word on ${platform}`); |
| 55 }) |
| 56 |
| 57 heldTest.done(); |
| 58 } |
| 59 |
| 60 spellcheck_test( |
| 61 '<input type="text" value="wellcome home.">', |
| 62 document => document.querySelector('input').focus(), |
| 63 '<input type="text" value="_wellcome_ home.">', |
| 64 { |
| 65 title: 'Mark misspelling in the initial text of an input field.', |
| 66 callback: sample => contextClickSelectionTests( |
| 67 sample.document.querySelector('input')) |
| 68 }); |
| 69 </script> |
| OLD | NEW |