1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/embedding/test/test_nsFind.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,225 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=450048 1.8 +--> 1.9 +<head> 1.10 + <meta charset="UTF-8"> 1.11 + <title>Test for nsFind::Find()</title> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450048">Mozilla Bug 450048</a> 1.17 +<p id="display">This is the text to search i<b>n­t</b>o</p> 1.18 +<p id="quotes">"straight" and “curly” and ‘didn't’ and 'doesn’t'</p> 1.19 +<div id="content" style="display: none"> 1.20 + 1.21 +</div> 1.22 +<pre id="test"> 1.23 +<script type="application/javascript"> 1.24 + 1.25 +/** Test for Bug 450048 **/ 1.26 + 1.27 + // Check nsFind class and its nsIFind interface. 1.28 + 1.29 + var rf = SpecialPowers.Cc["@mozilla.org/embedcomp/rangefind;1"] 1.30 + .getService(SpecialPowers.Ci.nsIFind); 1.31 + 1.32 + var display = window.document.getElementById("display"); 1.33 + var searchRange = window.document.createRange(); 1.34 + searchRange.setStart(display, 0); 1.35 + searchRange.setEnd(display, display.childNodes.length); 1.36 + var startPt = searchRange; 1.37 + var endPt = searchRange; 1.38 + 1.39 + // Check |null| detection on |aPatText| parameter. 1.40 + try { 1.41 + rf.Find(null, searchRange, startPt, endPt); 1.42 + 1.43 + ok(false, "Missing NS_ERROR_NULL_POINTER exception"); 1.44 + } catch (e) { 1.45 + e = SpecialPowers.wrap(e); 1.46 + if (e.result == SpecialPowers.Cr.NS_ERROR_NULL_POINTER) { 1.47 + ok(true, null); 1.48 + } else { 1.49 + throw e; 1.50 + } 1.51 + } 1.52 + 1.53 + // Check |null| detection on |aSearchRange| parameter. 1.54 + try { 1.55 + rf.Find("", null, startPt, endPt); 1.56 + 1.57 + ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception"); 1.58 + } catch (e) { 1.59 + e = SpecialPowers.wrap(e); 1.60 + if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) { 1.61 + ok(true, null); 1.62 + } else { 1.63 + throw e; 1.64 + } 1.65 + } 1.66 + 1.67 + // Check |null| detection on |aStartPoint| parameter. 1.68 + try { 1.69 + rf.Find("", searchRange, null, endPt); 1.70 + 1.71 + ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception"); 1.72 + } catch (e) { 1.73 + e = SpecialPowers.wrap(e); 1.74 + if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) { 1.75 + ok(true, null); 1.76 + } else { 1.77 + throw e; 1.78 + } 1.79 + } 1.80 + 1.81 + // Check |null| detection on |aEndPoint| parameter. 1.82 + try { 1.83 + rf.Find("", searchRange, startPt, null); 1.84 + 1.85 + ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception"); 1.86 + } catch (e) { 1.87 + e = SpecialPowers.wrap(e); 1.88 + if (e.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) { 1.89 + ok(true, null); 1.90 + } else { 1.91 + throw e; 1.92 + } 1.93 + } 1.94 + 1.95 + var searchValue, retRange; 1.96 + 1.97 + rf.findBackwards = false; 1.98 + 1.99 + rf.caseSensitive = false; 1.100 + 1.101 + searchValue = "TexT"; 1.102 + retRange = rf.Find(searchValue, searchRange, startPt, endPt); 1.103 + ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)"); 1.104 + 1.105 + rf.caseSensitive = true; 1.106 + 1.107 + // searchValue = "TexT"; 1.108 + retRange = rf.Find(searchValue, searchRange, startPt, endPt); 1.109 + ok(!retRange, "\"" + searchValue + "\" found (caseSensitive)"); 1.110 + 1.111 + searchValue = "text"; 1.112 + retRange = rf.Find(searchValue, searchRange, startPt, endPt); 1.113 + ok(retRange, "\"" + searchValue + "\" not found"); 1.114 + 1.115 + // Matches |i<b>n­t</b>o|. 1.116 + searchValue = "into"; 1.117 + retRange = rf.Find(searchValue, searchRange, startPt, endPt); 1.118 + ok(retRange, "\"" + searchValue + "\" not found"); 1.119 + 1.120 + // Matches inside |search|. 1.121 + searchValue = "ear"; 1.122 + retRange = rf.Find(searchValue, searchRange, startPt, endPt); 1.123 + ok(retRange, "\"" + searchValue + "\" not found"); 1.124 + 1.125 + // Set new start point (to end of last search). 1.126 + startPt = retRange.endContainer.ownerDocument.createRange(); 1.127 + startPt.setStart(retRange.endContainer, retRange.endOffset); 1.128 + startPt.setEnd(retRange.endContainer, retRange.endOffset); 1.129 + 1.130 + searchValue = "t"; 1.131 + retRange = rf.Find(searchValue, searchRange, startPt, endPt); 1.132 + ok(retRange, "\"" + searchValue + "\" not found (forward)"); 1.133 + 1.134 + searchValue = "the"; 1.135 + retRange = rf.Find(searchValue, searchRange, startPt, endPt); 1.136 + ok(!retRange, "\"" + searchValue + "\" found (forward)"); 1.137 + 1.138 + rf.findBackwards = true; 1.139 + 1.140 + // searchValue = "the"; 1.141 + retRange = rf.Find(searchValue, searchRange, startPt, endPt); 1.142 + ok(retRange, "\"" + searchValue + "\" not found (backward)"); 1.143 + 1.144 + 1.145 + // Curly quotes and straight quotes should match. 1.146 + 1.147 + rf.caseSensitive = false; 1.148 + rf.findBackwards = false; 1.149 + 1.150 + function find(node, searchValue) { 1.151 + var range = document.createRange(); 1.152 + range.setStart(node, 0); 1.153 + range.setEnd(node, node.childNodes.length); 1.154 + return rf.Find(searchValue, range, range, range); 1.155 + } 1.156 + 1.157 + function assertFound(node, searchValue) { 1.158 + ok(find(node, searchValue), "\"" + searchValue + "\" not found"); 1.159 + } 1.160 + 1.161 + function assertNotFound(node, searchValue) { 1.162 + ok(!find(node, searchValue), "\"" + searchValue + "\" found"); 1.163 + } 1.164 + 1.165 + var quotes = document.getElementById("quotes"); 1.166 + 1.167 + assertFound(quotes, "\"straight\""); 1.168 + assertFound(quotes, "\u201Cstraight\u201D"); 1.169 + 1.170 + assertNotFound(quotes, "'straight'"); 1.171 + assertNotFound(quotes, "\u2018straight\u2019"); 1.172 + assertNotFound(quotes, "\u2019straight\u2018"); 1.173 + assertNotFound(quotes, ".straight."); 1.174 + 1.175 + assertFound(quotes, "\"curly\""); 1.176 + assertFound(quotes, "\u201Ccurly\u201D"); 1.177 + 1.178 + assertNotFound(quotes, "'curly'"); 1.179 + assertNotFound(quotes, "\u2018curly\u2019"); 1.180 + assertNotFound(quotes, ".curly."); 1.181 + 1.182 + assertFound(quotes, "didn't"); 1.183 + assertFound(quotes, "didn\u2018t"); 1.184 + assertFound(quotes, "didn\u2019t"); 1.185 + 1.186 + assertNotFound(quotes, "didnt"); 1.187 + assertNotFound(quotes, "didn t"); 1.188 + assertNotFound(quotes, "didn.t"); 1.189 + 1.190 + assertFound(quotes, "'didn't'"); 1.191 + assertFound(quotes, "'didn\u2018t'"); 1.192 + assertFound(quotes, "'didn\u2019t'"); 1.193 + assertFound(quotes, "\u2018didn't\u2019"); 1.194 + assertFound(quotes, "\u2019didn't\u2018"); 1.195 + assertFound(quotes, "\u2018didn't\u2018"); 1.196 + assertFound(quotes, "\u2019didn't\u2019"); 1.197 + assertFound(quotes, "\u2018didn\u2019t\u2019"); 1.198 + assertFound(quotes, "\u2019didn\u2018t\u2019"); 1.199 + assertFound(quotes, "\u2018didn\u2019t\u2018"); 1.200 + 1.201 + assertNotFound(quotes, "\"didn't\""); 1.202 + assertNotFound(quotes, "\u201Cdidn't\u201D"); 1.203 + 1.204 + assertFound(quotes, "doesn't"); 1.205 + assertFound(quotes, "doesn\u2018t"); 1.206 + assertFound(quotes, "doesn\u2019t"); 1.207 + 1.208 + assertNotFound(quotes, "doesnt"); 1.209 + assertNotFound(quotes, "doesn t"); 1.210 + assertNotFound(quotes, "doesn.t"); 1.211 + 1.212 + assertFound(quotes, "'doesn't'"); 1.213 + assertFound(quotes, "'doesn\u2018t'"); 1.214 + assertFound(quotes, "'doesn\u2019t'"); 1.215 + assertFound(quotes, "\u2018doesn't\u2019"); 1.216 + assertFound(quotes, "\u2019doesn't\u2018"); 1.217 + assertFound(quotes, "\u2018doesn't\u2018"); 1.218 + assertFound(quotes, "\u2019doesn't\u2019"); 1.219 + assertFound(quotes, "\u2018doesn\u2019t\u2019"); 1.220 + assertFound(quotes, "\u2019doesn\u2018t\u2019"); 1.221 + assertFound(quotes, "\u2018doesn\u2019t\u2018"); 1.222 + 1.223 + assertNotFound(quotes, "\"doesn't\""); 1.224 + assertNotFound(quotes, "\u201Cdoesn't\u201D"); 1.225 +</script> 1.226 +</pre> 1.227 +</body> 1.228 +</html>