Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | |
| 6 <script src="resources/util.js"></script> | |
| 5 </head> | 7 </head> |
| 6 <body> | 8 <body> |
| 7 <p id="description"></p> | 9 <div> |
| 8 <div id="console"></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> | |
| 9 <script> | 17 <script> |
| 10 description('Grammar checking for pasted text.'); | 18 var testTextArea = document.getElementById('testTextArea'); |
| 11 | 19 var testInput = document.getElementById('testInput'); |
| 12 jsTestIsAsync = true; | 20 var testEditable = document.getElementById('testEditable'); |
| 13 | 21 var testSourcePlain = document.getElementById('testSourcePlain'); |
| 14 var testRoot = document.createElement("div"); | 22 var testSourceDecorated = document.getElementById('testSourceDecorated'); |
| 15 document.body.insertBefore(testRoot, document.body.firstChild); | 23 var testSourceMulti = document.getElementById('testSourceMulti'); |
| 16 | |
| 17 var testTextArea = document.createElement("textarea"); | |
| 18 testRoot.appendChild(testTextArea); | |
| 19 | |
| 20 var testInput = document.createElement("input"); | |
| 21 testInput.setAttribute("type", "text"); | |
| 22 testRoot.appendChild(testInput); | |
| 23 | |
| 24 var testEditable = document.createElement("div"); | |
| 25 testEditable.setAttribute("contentEditable", "true"); | |
| 26 testRoot.appendChild(testEditable); | |
| 27 | |
| 28 var testSourcePlain = document.createElement("div"); | |
| 29 testSourcePlain.innerHTML = "You has the right."; | |
| 30 testRoot.appendChild(testSourcePlain); | |
| 31 | |
| 32 var testSourceDecorated = document.createElement("div"); | |
| 33 testSourceDecorated.innerHTML = "I have a<b>n ki</b>wi. I have no idea."; | |
| 34 testRoot.appendChild(testSourceDecorated); | |
| 35 | |
| 36 var testSourceMulti = document.createElement("div"); | |
| 37 testSourceMulti.innerHTML = "I have an grape. I have an muscat. I don't know."; | |
| 38 testRoot.appendChild(testSourceMulti); | |
| 39 | 24 |
| 40 var sel = window.getSelection(); | 25 var sel = window.getSelection(); |
| 41 | 26 |
| 42 var tests = []; | |
| 43 | |
| 44 function done() | |
| 45 { | |
| 46 var next = tests.shift(); | |
| 47 if (next) | |
| 48 return window.setTimeout(next, 0); | |
| 49 testRoot.style.display = "none"; | |
| 50 finishJSTest(); | |
| 51 } | |
| 52 | |
| 53 function findFirstTextNode(node) | 27 function findFirstTextNode(node) |
| 54 { | 28 { |
| 55 function iterToFindFirstTextNode(node) | 29 function iterToFindFirstTextNode(node) |
| 56 { | 30 { |
| 57 if (node instanceof Text) | 31 if (node instanceof Text) |
| 58 return node; | 32 return node; |
| 59 | 33 |
| 60 var childNodes = node.childNodes; | 34 var childNodes = node.childNodes; |
| 61 for (var i = 0; i < childNodes.length; ++i) { | 35 for (var i = 0; i < childNodes.length; ++i) { |
| 62 var n = iterToFindFirstTextNode(childNodes[i]); | 36 var n = iterToFindFirstTextNode(childNodes[i]); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 75 } | 49 } |
| 76 | 50 |
| 77 function verifyMarker(node, expectedMarked) | 51 function verifyMarker(node, expectedMarked) |
| 78 { | 52 { |
| 79 if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) | 53 if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) |
| 80 node.focus(); | 54 node.focus(); |
| 81 else | 55 else |
| 82 sel.selectAllChildren(node); | 56 sel.selectAllChildren(node); |
| 83 | 57 |
| 84 var textNode = findFirstTextNode(node); | 58 var textNode = findFirstTextNode(node); |
| 85 var num = internals.markerCountForNode(textNode, "grammar"); | 59 var num = internals.markerCountForNode(textNode, 'grammar'); |
| 86 if (num != expectedMarked.length) | 60 assert_equals(num, expectedMarked.length); |
| 87 return false; | 61 |
| 88 for (var i = 0; i < num; ++i) { | 62 for (var i = 0; i < num; ++i) { |
| 89 var range = internals.markerRangeForNode(textNode, "grammar", i); | 63 var range = internals.markerRangeForNode(textNode, 'grammar', i); |
| 90 if (range.toString() != expectedMarked[i]) | 64 assert_equals(range.toString(), expectedMarked[i]); |
| 91 return false; | |
| 92 } | 65 } |
| 93 | |
| 94 var nodeContent = node instanceof HTMLInputElement || node instanceof HTMLTe xtAreaElement ? node.value : node.innerHTML; | |
| 95 testPassed(node.tagName + " ungrammatical phrase '" + expectedMarked + "' on '" + nodeContent + "'"); | |
| 96 | |
| 97 return true; | |
| 98 } | 66 } |
| 99 | 67 |
| 100 var destination = null; | 68 function pasteText(source, dest) |
| 101 var expectedMarked = null; | |
| 102 function pasteAndVerify(source, dest, expectedMarked) | |
| 103 { | 69 { |
| 104 sel.selectAllChildren(source); | 70 sel.selectAllChildren(source); |
| 105 document.execCommand("Copy"); | 71 document.execCommand("Copy"); |
|
yosin_UTC9
2016/08/12 01:45:42
Let's use single-quote in this file. Mixing single
Xiaocheng
2016/08/12 02:11:41
Done.
| |
| 106 if (dest instanceof HTMLInputElement || dest instanceof HTMLTextAreaElement) { | 72 if (dest instanceof HTMLInputElement || dest instanceof HTMLTextAreaElement) { |
| 107 dest.value = ""; | 73 dest.value = ""; |
| 108 dest.focus(); | 74 dest.focus(); |
| 109 } else { | 75 } else { |
| 110 dest.innerHTML = ""; | 76 dest.innerHTML = ""; |
| 111 sel.selectAllChildren(dest); | 77 sel.selectAllChildren(dest); |
| 112 } | 78 } |
| 113 document.execCommand("Paste"); | 79 document.execCommand("Paste"); |
| 114 | |
| 115 if (window.internals) { | |
| 116 destination = dest; | |
| 117 ungrammaticalPhrase = expectedMarked; | |
| 118 shouldBecomeEqual('verifyMarker(destination, ungrammaticalPhrase)', 'tru e', done); | |
| 119 } | |
| 120 }; | 80 }; |
| 121 | 81 |
| 122 tests.push(function() { pasteAndVerify(testSourcePlain, testEditable, ["has"]); }); | 82 var steps = [ |
| 123 tests.push(function() { pasteAndVerify(testSourceDecorated, testEditable, ["a"]) ; }); // Checks only 'a'. | 83 () => pasteText(testSourcePlain, testEditable), |
| 124 tests.push(function() { pasteAndVerify(testSourceMulti, testEditable, ["an", "an "]); }); | 84 () => pasteText(testSourceDecorated, testEditable), |
| 85 () => pasteText(testSourceMulti, testEditable), | |
| 125 | 86 |
| 126 tests.push(function() { pasteAndVerify(testSourcePlain, testInput, ["has"]); }); | 87 () => pasteText(testSourcePlain, testInput), |
| 127 tests.push(function() { pasteAndVerify(testSourceDecorated, testInput, ["an"]); }); | 88 () => pasteText(testSourceDecorated, testInput), |
| 128 tests.push(function() { pasteAndVerify(testSourceMulti, testInput, ["an", "an"]) ; }); | 89 () => pasteText(testSourceMulti, testInput), |
| 129 | 90 |
| 130 tests.push(function() { pasteAndVerify(testSourcePlain, testTextArea, ["has"]); }); | 91 () => pasteText(testSourcePlain, testTextArea), |
| 131 tests.push(function() { pasteAndVerify(testSourceDecorated, testTextArea, ["an"] ); }); | 92 () => pasteText(testSourceDecorated, testTextArea), |
| 132 tests.push(function() { pasteAndVerify(testSourceMulti, testTextArea, ["an", "an "]); }); | 93 () => pasteText(testSourceMulti, testTextArea) |
| 94 ]; | |
| 133 | 95 |
| 134 done(); | 96 var assertions = [ |
| 97 () => verifyMarker(testEditable, ["has"]), | |
| 98 () => verifyMarker(testEditable, ["a"]), // Checks only 'a'. | |
| 99 () => verifyMarker(testEditable, ["an", "an"]), | |
| 135 | 100 |
| 136 var successfullyParsed = true; | 101 () => verifyMarker(testInput, ["has"]), |
| 102 () => verifyMarker(testInput, ["an"]), | |
| 103 () => verifyMarker(testInput, ["an", "an"]), | |
| 104 | |
| 105 () => verifyMarker(testTextArea, ["has"]), | |
| 106 () => verifyMarker(testTextArea, ["an"]), | |
| 107 () => verifyMarker(testTextArea, ["an", "an"]), | |
| 108 ]; | |
| 109 | |
| 110 runSpellingTest(steps, assertions, 'Grammar checking for pasted text.'); | |
| 137 </script> | 111 </script> |
| 138 </body> | 112 </body> |
| 139 </html> | 113 </html> |
| OLD | NEW |