PageRenderTime 24ms CodeModel.GetById 2ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/embedding/test/test_nsFind.html

http://github.com/zpao/v8monkey
HTML | 127 lines | 96 code | 28 blank | 3 comment | 0 complexity | 3361cf6910eb512fdedd9f4dc293f0af MD5 | raw file
  1<!DOCTYPE HTML>
  2<html>
  3<!--
  4https://bugzilla.mozilla.org/show_bug.cgi?id=450048
  5-->
  6<head>
  7  <title>Test for nsFind::Find()</title>
  8  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 10</head>
 11<body>
 12<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450048">Mozilla Bug 450048</a>
 13<p id="display">This is the text to search i<b>n&shy;t</b>o</p>
 14<div id="content" style="display: none">
 15  
 16</div>
 17<pre id="test">
 18<script type="application/javascript">
 19
 20/** Test for Bug 450048 **/
 21
 22  // Check nsFind class and its nsIFind interface.
 23
 24  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 25
 26  var rf = Components.classes["@mozilla.org/embedcomp/rangefind;1"]
 27                     .getService(Components.interfaces.nsIFind);
 28
 29  var display = window.document.getElementById("display");
 30  var searchRange = window.document.createRange();
 31  searchRange.setStart(display, 0);
 32  searchRange.setEnd(display, display.childNodes.length);
 33  var startPt = searchRange;
 34  var endPt = searchRange;
 35
 36  // Check |null| detection on |aPatText| parameter.
 37  try {
 38    rf.Find(null, searchRange, startPt, endPt);
 39
 40    ok(false, "Missing NS_ERROR_NULL_POINTER exception");
 41  } catch (e if (e instanceof Components.interfaces.nsIException &&
 42                 e.result == Components.results.NS_ERROR_NULL_POINTER)) {
 43    ok(true, null);
 44  }
 45
 46  // Check |null| detection on |aSearchRange| parameter.
 47  try {
 48    rf.Find("", null, startPt, endPt);
 49
 50    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
 51  } catch (e if (e instanceof Components.interfaces.nsIException &&
 52                 e.result == Components.results.NS_ERROR_ILLEGAL_VALUE)) {
 53    ok(true, null);
 54  }
 55
 56  // Check |null| detection on |aStartPoint| parameter.
 57  try {
 58    rf.Find("", searchRange, null, endPt);
 59
 60    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
 61  } catch (e if (e instanceof Components.interfaces.nsIException &&
 62                 e.result == Components.results.NS_ERROR_ILLEGAL_VALUE)) {
 63    ok(true, null);
 64  }
 65
 66  // Check |null| detection on |aEndPoint| parameter.
 67  try {
 68    rf.Find("", searchRange, startPt, null);
 69
 70    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
 71  } catch (e if (e instanceof Components.interfaces.nsIException &&
 72                 e.result == Components.results.NS_ERROR_ILLEGAL_VALUE)) {
 73    ok(true, null);
 74  }
 75
 76  var searchValue, retRange;
 77
 78  rf.findBackwards = false;
 79
 80  rf.caseSensitive = false;
 81
 82  searchValue = "TexT";
 83  retRange = rf.Find(searchValue, searchRange, startPt, endPt);
 84  ok(retRange, "\"" + searchValue + "\" not found (not caseSensitive)");
 85
 86  rf.caseSensitive = true;
 87
 88  // searchValue = "TexT";
 89  retRange = rf.Find(searchValue, searchRange, startPt, endPt);
 90  ok(!retRange, "\"" + searchValue + "\" found (caseSensitive)");
 91
 92  searchValue = "text";
 93  retRange = rf.Find(searchValue, searchRange, startPt, endPt);
 94  ok(retRange, "\"" + searchValue + "\" not found");
 95
 96  // Matches |i<b>n&shy;t</b>o|.
 97  searchValue = "into";
 98  retRange = rf.Find(searchValue, searchRange, startPt, endPt);
 99  ok(retRange, "\"" + searchValue + "\" not found");
100
101  // Matches inside |search|.
102  searchValue = "ear";
103  retRange = rf.Find(searchValue, searchRange, startPt, endPt);
104  ok(retRange, "\"" + searchValue + "\" not found");
105
106  // Set new start point (to end of last search).
107  startPt = retRange.endContainer.ownerDocument.createRange();
108  startPt.setStart(retRange.endContainer, retRange.endOffset);
109  startPt.setEnd(retRange.endContainer, retRange.endOffset);
110
111  searchValue = "t";
112  retRange = rf.Find(searchValue, searchRange, startPt, endPt);
113  ok(retRange, "\"" + searchValue + "\" not found (forward)");
114
115  searchValue = "the";
116  retRange = rf.Find(searchValue, searchRange, startPt, endPt);
117  ok(!retRange, "\"" + searchValue + "\" found (forward)");
118
119  rf.findBackwards = true;
120
121  // searchValue = "the";
122  retRange = rf.Find(searchValue, searchRange, startPt, endPt);
123  ok(retRange, "\"" + searchValue + "\" not found (backward)");
124</script>
125</pre>
126</body>
127</html>