Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / editing / text-iterator / findString.html
1 <meta charset="utf-8">
2 <div id="container"></div>
3 <pre id="console" style="visibility: hidden;"></pre>
4 <script>
5     function log(message)
6     {
7         document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
8     }
9
10     function testFindString(text, target, options, expectedRanges)
11     {
12         log("Searching for \u2018" + target + "\u2019 " + (text.length <= 64 ? "in \u2018" + text + "\u2019 " : "in long string ") + "with options [" + options.join(", ") + "]:");
13
14         var container = document.getElementById("container");
15         container.innerHTML = text;
16         document.body.offsetTop;
17         var selection = getSelection();
18         selection.empty();
19
20         var expectedRange;
21         while (expectedRange = expectedRanges.shift()) {
22             var found = testRunner.findString(target, options);
23             if (found) {
24                 var actualRange = [selection.baseOffset, selection.extentOffset];
25                 if (expectedRange[0] !== actualRange[0] || expectedRange[1] !== actualRange[1])
26                     log("FAIL: Expected a match at " + expectedRange + " but got a match at " + actualRange + " instead.");
27                 else
28                     log("PASS: Got a match at " + expectedRange + " as expected.");
29             } else if (expectedRange.length)
30                 log("FAIL: Expected " + expectedRange + " but got no match.");
31             else
32                 log("PASS: Got no match as expected.");
33         }
34         container.innerText = "";
35         log("");
36     }
37
38     testRunner.dumpAsText();
39
40     testFindString("Lorem ipsum dolor sit amet", "o", [], [[1, 2], [13, 14], [15, 16], []]);
41     testFindString("Lorem ipsum dolor sit amet", "o", ["WrapAround"], [[1, 2], [13, 14], [15, 16], [1, 2]]);
42     testFindString("Lorem ipsum dolor sit amet", "o", ["Backwards"], [[15, 16], [13, 14], [1, 2], []]);
43     testFindString("Lorem ipsum dolor sit amet", "o", ["Backwards", "WrapAround"], [[15, 16], [13, 14], [1, 2], [15, 16]]);
44     testFindString("Lorem ipsum dolor sit amet", "O", [], [[]]);
45     testFindString("Lorem ipsum dolor sit amet", "O", ["CaseInsensitive"], [[1, 2], [13, 14], [15, 16]]);
46
47     testFindString("insurmountable mountain", "mount", [], [[5, 10], [15, 20], []]);
48     testFindString("insurmountable mountain", "mount", ["AtWordStarts"], [[15, 20], []]);
49
50     testFindString("cocoa", "co", [], [[0, 2], [2, 4], []]);
51     testFindString("cocoa", "co", ["AtWordStarts"], [[0, 2], []]);
52
53     testFindString("webkit.org", "org", ["AtWordStarts"], [[7, 10]]);
54     testFindString("webkit.org", ".org", ["AtWordStarts"], [[6, 10], []]);
55
56     testFindString("webkit.org", "rg", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
57     testFindString("webkit.org", "org", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[7, 10], []]);
58     testFindString("webkit.org", ".org", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[6, 10], []]);
59     testFindString("webkit.org", "t.org", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
60
61     testFindString("WebKit", "it", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
62     testFindString("WebKit", "Kit", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[3, 6], []]);
63     testFindString("WebKit", "bKit", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
64
65     testFindString("XMLHTTPRequest", "equest", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
66     testFindString("XMLHTTPRequest", "Request", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[7, 14], []]);
67     testFindString("XMLHTTPRequest", "PRequest", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
68
69     testFindString("LP64", "64", ["AtWordStarts"], [[]]);
70     testFindString("LP64", "4", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
71     testFindString("LP64", "64", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[2, 4], []]);
72     testFindString("LP64", "P64", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
73
74     testFindString("\u8d77\u52d5\u6226\u58eb", "\u52d5\u6226\u58eb", ["AtWordStarts"], [[1, 4], []]);
75     testFindString("\u8d77\u52d5\u6226\u58eb", "\u6226\u58eb", ["AtWordStarts"], [[2, 4], []]);
76     testFindString("\u8d77\u52d5\u6226\u58eb", "\u58eb", ["AtWordStarts"], [[3, 4], []]);
77
78     const searchBufferSize = 8192;
79     const searchBufferOverlapSize = searchBufferSize / 4;
80     const searchBufferUnoverlappedSize = searchBufferSize - searchBufferOverlapSize;
81     var bufferSizedString = "X";
82     while (bufferSizedString.length < searchBufferSize)
83         bufferSizedString += bufferSizedString;
84     bufferSizedString = bufferSizedString.substring(0, searchBufferSize);
85
86     testFindString(bufferSizedString.substring(0, searchBufferUnoverlappedSize - 2) + " ba a" + bufferSizedString, "a", ["AtWordStarts"], [[searchBufferUnoverlappedSize + 2, searchBufferUnoverlappedSize + 3], []]);
87
88     var thaiWords = [
89         "\u0e01\u0e23",
90         "\u0e1b\u0e39\u0e40\u0e25",
91         "\u0e01\u0e0a",
92         "\u0e01\u0e0a\u0e01\u0e23", // thaiWords[2] + thaiWords[0]
93         "\u0e01\u0e23\u0e01\u0e0a", // thaiWords[0] + thaiWords[2]
94         "\u0e1a\u0e07\u0e01\u0e0a", // ends with thaiWords[2]
95     ];
96
97     testFindString(thaiWords.join(""), thaiWords[0], [], [[0, 2], [10, 12], [12, 14], []]);
98     testFindString(thaiWords.join(""), thaiWords[0], ["AtWordStarts"], [[0, 2], [12, 14], []]);
99
100     testFindString(thaiWords.join(""), thaiWords[2], [], [[6, 8], [8, 10], [14, 16], [18, 20], []]);
101     testFindString(thaiWords.join(""), thaiWords[2], ["AtWordStarts"], [[6, 8], [8, 10], []]);
102
103     testFindString(bufferSizedString.substring(0, searchBufferUnoverlappedSize) + thaiWords.join("") + bufferSizedString, thaiWords[0], [], [[searchBufferUnoverlappedSize, searchBufferUnoverlappedSize + 2], [searchBufferUnoverlappedSize + 10, searchBufferUnoverlappedSize + 12], [searchBufferUnoverlappedSize + 12, searchBufferUnoverlappedSize + 14], []]);
104     testFindString(bufferSizedString.substring(0, searchBufferUnoverlappedSize) + thaiWords.join("") + bufferSizedString, thaiWords[0], ["AtWordStarts"], [[searchBufferUnoverlappedSize + 12, searchBufferUnoverlappedSize + 14], []]);
105     testFindString(bufferSizedString.substring(0, searchBufferUnoverlappedSize - 1) + " " + thaiWords.join("") + bufferSizedString, thaiWords[0], ["AtWordStarts"], [[searchBufferUnoverlappedSize, searchBufferUnoverlappedSize + 2], [searchBufferUnoverlappedSize + 12, searchBufferUnoverlappedSize + 14], []]);
106     testFindString(bufferSizedString.substring(0, searchBufferUnoverlappedSize - 3) + " " + thaiWords[4] + bufferSizedString, thaiWords[2], ["AtWordStarts"], [[]]);
107
108     testFindString("Spaces, the final frontier", " ", ["AtWordStarts"], [[7, 8], [11, 12], [17, 18], []]);
109     testFindString("Use an @import rule", "@", ["AtWordStarts"], [[7, 8], []]);
110     testFindString("If ((x + 5) * 2) = 14, then x = 2", "(x", ["AtWordStarts"], [[4, 6], []]);
111
112     testFindString("hello<img src='../resources/abe.png'>world", "lowo", [], [[3, 2], []]);
113
114     document.getElementById("console").style.removeProperty("visibility");
115 </script>