1<!DOCTYPE html>
2<html>
3<head>
4<script src="../../fast/js/resources/js-test-pre.js"></script>
5</head>
6<body>
7<div id="container">
8 <div id="destination" contentEditable></div>
9</div>
10
11<script>
12
13function verify(nretry)
14{
15 if (!nretry) {
16 finishJSTest();
17 return;
18 }
19
20 if (!internals.markerCountForNode(destination.childNodes[0], "spelling")) {
21 window.setTimeout(function() { verify(nretry - 1); }, 0);
22 return;
23 }
24
25 spellingMarkerRange = internals.markerRangeForNode(destination.childNodes[0], "spelling", 0);
26 shouldBeEqualToString("spellingMarkerRange.toString()", "wellcome");
27
28 window.getSelection().removeAllRanges();
29 shouldBeEqualToString("window.getSelection().toString()", "");
30
31 // Double-click the misspelled word without the trailing whitespace.
32 testRunner.setSelectTrailingWhitespaceEnabled(false);
33 var x = destination.offsetParent.offsetLeft + destination.offsetLeft + 40;
34 var y = destination.offsetParent.offsetTop + destination.offsetTop + destination.offsetHeight / 2;
35 eventSender.mouseMoveTo(x, y);
36 eventSender.mouseDown();
37 eventSender.mouseUp();
38 eventSender.mouseDown();
39 eventSender.mouseUp();
40
41 shouldBeEqualToString("window.getSelection().toString()", "wellcome_");
42
43 // Context click on "wellcome_" to show the context menu.
44 x = destination.offsetParent.offsetLeft + destination.offsetLeft + 40;
45 y = destination.offsetParent.offsetTop + destination.offsetTop + destination.offsetHeight / 2;
46 eventSender.mouseMoveTo(x, y);
47 contextMenuElements = eventSender.contextClick();
48 // Esc key to hide the context menu.
49 eventSender.keyDown(String.fromCharCode(0x001B), null);
50
51 spellingMarkerRange = internals.markerRangeForNode(destination.childNodes[0], "spelling", 0);
52 shouldBeEqualToString("spellingMarkerRange.toString()", "wellcome");
53 shouldBeEqualToString("window.getSelection().toString()", "wellcome_");
54 shouldBeEqualToString("contextMenuElements[contextMenuElements.length - 1]", "welcome");
55
56 window.getSelection().removeAllRanges();
57 shouldBeEqualToString("window.getSelection().toString()", "");
58
59 // Double-click the misspelled word with the trailing whitespace.
60 testRunner.setSelectTrailingWhitespaceEnabled(true);
61 var x = destination.offsetParent.offsetLeft + destination.offsetLeft + 40;
62 var y = destination.offsetParent.offsetTop + destination.offsetTop + destination.offsetHeight / 2;
63 eventSender.mouseMoveTo(x, y);
64 eventSender.mouseDown();
65 eventSender.mouseUp();
66 eventSender.mouseDown();
67 eventSender.mouseUp();
68
69 shouldBeEqualToString("window.getSelection().toString()", "wellcome_ ");
70
71 // Context click on "wellcome_ " to show the context menu.
72 x = destination.offsetParent.offsetLeft + destination.offsetLeft + 40;
73 y = destination.offsetParent.offsetTop + destination.offsetTop + destination.offsetHeight / 2;
74 eventSender.mouseMoveTo(x, y);
75 contextMenuElements = eventSender.contextClick();
76 // Esc key to hide the context menu.
77 eventSender.keyDown(String.fromCharCode(0x001B), null);
78
79 spellingMarkerRange = internals.markerRangeForNode(destination.childNodes[0], "spelling", 0);
80 shouldBeEqualToString("spellingMarkerRange.toString()", "wellcome");
81 shouldBeEqualToString("window.getSelection().toString()", "wellcome_ ");
82 shouldBeEqualToString("contextMenuElements[contextMenuElements.length - 1]", "welcome");
83
84 finishJSTest();
85}
86
87function test()
88{
89 jsTestIsAsync = true;
90 internals.settings.setUnifiedTextCheckerEnabled(true);
91 testRunner.setAsynchronousSpellCheckingEnabled(true);
92 testRunner.setSmartInsertDeleteEnabled(true);
93 var destination = document.getElementById("destination");
94 destination.focus();
95 document.execCommand("InsertText", false, "wellcome_ home.");
96 window.setTimeout(function() { verify(10); }, 0);
97}
98
99description("Spelling should work for double-clicked misspelled words with underscores. " +
100 "To test manually, type 'wellcome_ home.', double-click on 'wellcome_', and context-click on the selection. " +
101 "The test succeeds when the context menu shows spell check suggestions.");
102if (window.internals)
103 test();
104
105</script>
106<script src="../../fast/js/resources/js-test-post.js"></script>
107</body>
108</html>