Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/editing/spelling/context_click_select_misspelling.html |
| diff --git a/third_party/WebKit/LayoutTests/editing/spelling/context_click_select_misspelling.html b/third_party/WebKit/LayoutTests/editing/spelling/context_click_select_misspelling.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4d046e33489ee470da6be4aedaf784367b5f01ca |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/editing/spelling/context_click_select_misspelling.html |
| @@ -0,0 +1,58 @@ |
| +<!DOCTYPE html> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| +<script src="../assert_selection.js"></script> |
| +<script src="spellcheck_test.js"></script> |
| + |
| +<script> |
| +test(() => assert_not_equals(window.internals, undefined), |
| + 'This test requires internals to set editing behavior.'); |
| + |
| +test(() => assert_not_equals(window.eventSender, undefined), |
| + 'This test requires event sender to simulate keyboard and mouse actions.'); |
| + |
| +function assertContextClickSelection(input, offsetX, expected) { |
| + const document = input.ownerDocument; |
| + const x = document.offsetLeft + input.offsetLeft + offsetX; |
| + const y = document.offsetTop + input.offsetTop + input.offsetHeight / 2; |
| + eventSender.mouseMoveTo(x, y); |
| + eventSender.contextClick(); |
| + |
| + // Esc key to hide the context menu. |
| + eventSender.keyDown('Escape', null); |
| + |
| + assert_equals(document.getSelection().toString(), expected); |
| +} |
| + |
| +function contextClickSelectionTests(input) { |
| + // There seems to be some bug with testharness.js that, if the first test |
| + // completes before the next two tests start, the whole testharness is |
| + // considered as ran to complete and the next two tests are not evaluated. |
| + // Hence, we use async_test and defer the completion as a workaround. |
| + const platformIndependentTest = async_test( |
| + () => assertContextClickSelection(input, 40, 'wellcome'), |
|
yosin_UTC9
2016/10/27 01:44:46
We should avoid a magic number for coordinate, |in
|
| + 'Context clicking "wellcome" selects the misspelled word'); |
| + |
| + ['Win', 'Unix', 'Android', 'Mac'].forEach(platform => { |
| + internals.settings.setEditingBehavior(platform); |
| + const shouldSelect = platform === 'Mac'; |
| + test(() => assertContextClickSelection(input, 80, |
| + shouldSelect ? 'home' : ''), |
| + 'Context clicking "home" ' + |
| + `${shouldSelect ? 'selects' : 'does not select'} ` + |
| + `the correctly spelled word on ${platform}`); |
| + }) |
| + |
| + platformIndependentTest.done(); |
| +} |
| + |
| +spellcheck_test( |
| + '<input type="text" value="wellcome home.">', |
| + document => document.querySelector('input').focus(), |
| + '<input type="text" value="_wellcome_ home.">', |
| + { |
| + title: 'Mark misspelling in the initial text of an input field.', |
| + callback: sample => contextClickSelectionTests( |
| + sample.document.querySelector('input')) |
| + }); |
| +</script> |