Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/LayoutTests/editing/spelling/grammar-paste.html

Issue 2455533002: Convert editing/spelling/grammar-paste.html with spellcheck_test (Closed)
Patch Set: Remove garbage Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!doctype html> 1 <!doctype html>
2 <html>
3 <head>
4 <script src="../../resources/testharness.js"></script> 2 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script> 3 <script src="../../resources/testharnessreport.js"></script>
6 <script src="resources/util.js"></script> 4 <script src="../assert_selection.js"></script>
7 </head> 5 <script src="spellcheck_test.js"></script>
8 <body>
9 <div>
10 <textarea id="testTextArea"></textarea>
11 <input id="testInput" type="text"></input>
12 <div id="testEditable" contenteditable></div>
13 <div id="testSourcePlain">You has the right.</div>
14 <div id="testSourceDecorated">I have a<b>n ki</b>wi. I have no idea.</div>
15 <div id="testSourceMulti">I have an grape. I have an muscat. I don't know.</div>
16 </div>
17 <script> 6 <script>
18 var testTextArea = document.getElementById('testTextArea'); 7 function pasteHTMLToDest(document, html)
19 var testInput = document.getElementById('testInput');
20 var testEditable = document.getElementById('testEditable');
21 var testSourcePlain = document.getElementById('testSourcePlain');
22 var testSourceDecorated = document.getElementById('testSourceDecorated');
23 var testSourceMulti = document.getElementById('testSourceMulti');
24
25 var sel = window.getSelection();
26
27 function findFirstTextNode(node)
28 { 8 {
29 function iterToFindFirstTextNode(node) 9 document.getSelection().setClipboardData(html);
30 { 10 document.getElementById('dest').focus();
31 if (node instanceof Text) 11 document.execCommand('Paste');
32 return node;
33
34 var childNodes = node.childNodes;
35 for (var i = 0; i < childNodes.length; ++i) {
36 var n = iterToFindFirstTextNode(childNodes[i]);
37 if (n)
38 return n;
39 }
40
41 return null;
42 }
43
44
45 if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement)
46 return iterToFindFirstTextNode(internals.shadowRoot(node));
47 else
48 return iterToFindFirstTextNode(node);
49 } 12 }
50 13
51 function verifyMarker(node, expectedMarked) 14 spellcheck_test(
52 { 15 '<div contenteditable id="dest">|</div>',
53 if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) 16 document => pasteHTMLToDest(document, 'You has the right.'),
54 node.focus(); 17 '<div contenteditable id="dest">You ~has~ the right.</div>',
55 else 18 'Paste plain text into editable <div>.');
56 sel.selectAllChildren(node);
57 19
58 var textNode = findFirstTextNode(node); 20 spellcheck_test(
59 var num = internals.markerCountForNode(textNode, 'grammar'); 21 '<div contenteditable id="dest">|</div>',
60 assert_equals(num, expectedMarked.length); 22 document => pasteHTMLToDest(document,
23 'I have a<b>n ki</b>wi. I have no idea.'),
24 [
25 '<div contenteditable id="dest">',
26 'I have ~a~<b>~n~ ki</b>wi. I have no idea.',
27 '</div>'
28 ].join(''),
29 'Paste decorated text into editable <div>.');
61 30
62 for (var i = 0; i < num; ++i) { 31 spellcheck_test(
63 var range = internals.markerRangeForNode(textNode, 'grammar', i); 32 '<div contenteditable id="dest">|</div>',
64 assert_equals(range.toString(), expectedMarked[i]); 33 document => pasteHTMLToDest(
65 } 34 document, 'I have an grape. I have an muscat. I don\'t know.'),
66 } 35 [
36 '<div contenteditable id="dest">',
37 'I have ~an~ grape. I have ~an~ muscat. I don\'t know.',
38 '</div>'
39 ].join(''),
40 'Paste text with multiple errors into editable <div>.');
67 41
68 function pasteText(source, dest) 42 spellcheck_test(
69 { 43 '<input id="dest" type="text">|',
70 sel.selectAllChildren(source); 44 document => pasteHTMLToDest(document, 'You has the right.'),
71 document.execCommand('Copy'); 45 '<input id="dest" type="text" value="You ~has~ the right.">',
72 if (dest instanceof HTMLInputElement || dest instanceof HTMLTextAreaElement) { 46 'Paste plain text into <input>.');
73 dest.value = '';
74 dest.focus();
75 } else {
76 dest.innerHTML = '';
77 sel.selectAllChildren(dest);
78 }
79 document.execCommand('Paste');
80 };
81 47
82 var steps = [ 48 spellcheck_test(
83 () => pasteText(testSourcePlain, testEditable), 49 '<input id="dest" type="text">|',
84 () => pasteText(testSourceDecorated, testEditable), 50 document => pasteHTMLToDest(document,
85 () => pasteText(testSourceMulti, testEditable), 51 'I have a<b>n ki</b>wi. I have no idea.'),
52 '<input id="dest" type="text" value="I have ~an~ kiwi. I have no idea.">',
53 'Paste decorated text into <input>.');
86 54
87 () => pasteText(testSourcePlain, testInput), 55 spellcheck_test(
88 () => pasteText(testSourceDecorated, testInput), 56 '<input id="dest" type="text">|',
89 () => pasteText(testSourceMulti, testInput), 57 document => pasteHTMLToDest(
58 document, 'I have an grape. I have an muscat. I don\'t know.'),
59 '<input id="dest" type="text" ' +
60 'value="I have ~an~ grape. I have ~an~ muscat. I don\'t know.">',
61 'Paste text with multiple errors into <input>.');
90 62
91 () => pasteText(testSourcePlain, testTextArea), 63 spellcheck_test(
92 () => pasteText(testSourceDecorated, testTextArea), 64 '<textarea id="dest">|</textarea>',
93 () => pasteText(testSourceMulti, testTextArea) 65 document => pasteHTMLToDest(document, 'You has the right.'),
94 ]; 66 '<textarea id="dest">You ~has~ the right.</textarea>',
67 'Paste plain text into <textarea>.');
95 68
96 var assertions = [ 69 spellcheck_test(
97 () => verifyMarker(testEditable, ['has']), 70 '<textarea id="dest">|</textarea>',
98 () => verifyMarker(testEditable, ['a']), // Checks only 'a'. 71 document => pasteHTMLToDest(document,
99 () => verifyMarker(testEditable, ['an', 'an']), 72 'I have a<b>n ki</b>wi. I have no idea.'),
73 '<textarea id="dest">I have ~an~ kiwi. I have no idea.</textarea>',
74 'Paste decorated text into <textarea>.');
100 75
101 () => verifyMarker(testInput, ['has']), 76 spellcheck_test(
102 () => verifyMarker(testInput, ['an']), 77 '<textarea id="dest">|</textarea>',
103 () => verifyMarker(testInput, ['an', 'an']), 78 document => pasteHTMLToDest(
104 79 document, 'I have an grape. I have an muscat. I don\'t know.'),
105 () => verifyMarker(testTextArea, ['has']), 80 [
106 () => verifyMarker(testTextArea, ['an']), 81 '<textarea id="dest">',
107 () => verifyMarker(testTextArea, ['an', 'an']), 82 'I have ~an~ grape. I have ~an~ muscat. I don\'t know.',
108 ]; 83 '</textarea>'
109 84 ].join(''),
110 runSpellingTest(steps, assertions, 'Grammar checking for pasted text.'); 85 'Paste text with multiple errors into <textarea>.');
111 </script> 86 </script>
112 </body>
113 </html>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698