Bug 1538042 Part 2: Add tests of null character searches. r=mccr8
☠☠ backed out by 6c74ea8db80c ☠ ☠
authorBrad Werth <bwerth@mozilla.com>
Wed, 04 Sep 2019 22:59:25 +0000
changeset 491781 4035fee4dd33e16b02bee9bf7b5b14088fe80104
parent 491780 1baf8637bb47ab15639e010432fc72d36c540647
child 491782 082159fea41381907005f365bb5283c086d53c07
push id114033
push userccoroiu@mozilla.com
push dateThu, 05 Sep 2019 16:21:04 +0000
treeherdermozilla-inbound@3d7b9bf00bdb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1538042
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1538042 Part 2: Add tests of null character searches. r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D25293
dom/base/test/test_find.html
toolkit/components/windowcreator/test/test_nsFind.html
--- a/dom/base/test/test_find.html
+++ b/dom/base/test/test_find.html
@@ -117,16 +117,24 @@ let runTests = t.step_func_done(function
   // such.
   //
   // See bug 1442466 / bug 1510485 / bug 1505887.
   testFindable(false, "foo", function(document) {
     let input = document.createElement("input");
     input.value = "foo";
     document.documentElement.appendChild(input);
   }, "Native anonymous content isn't exposed in window.find");
+
+  testFindable(false, "\0", `
+    &#0;
+  `);
+
+  testFindable(true, "\0", function(document) {
+    document.documentElement.appendChild(document.createTextNode("\0"));
+  }, "Inserted null characters are findable");
 });
 
 window.onload = function() {
   let iframe = document.createElement("iframe");
   iframe.onload = runTests;
   iframe.srcdoc = "<!doctype html><html></html>";
   document.body.appendChild(iframe);
 };
--- a/toolkit/components/windowcreator/test/test_nsFind.html
+++ b/toolkit/components/windowcreator/test/test_nsFind.html
@@ -3,83 +3,43 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=450048
 -->
 <head>
   <meta charset="UTF-8">
   <title>Test for nsFind::Find()</title>
   <script src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450048">Mozilla Bug 450048</a>
-<p id="display">This is the text to search i<b>n&shy;t</b>o</p>
-<p id="quotes">"straight" and &ldquo;curly&rdquo; and &lsquo;didn't&rsquo; and 'doesn&rsquo;t'</p>
-<div id="content" style="display: none">
 
-</div>
-<pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 450048 **/
+SimpleTest.waitForExplicitFinish();
 
+async function runTests() {
   // Check nsFind class and its nsIFind interface.
 
+  // Inject some text that we'll search for later.
+  const INJECTED_NULL_TEXT = "injected null\0";
+  const nullcharsinjected = document.getElementById("nullcharsinjected");
+  const nulltextnode = document.createTextNode(INJECTED_NULL_TEXT);
+  nullcharsinjected.appendChild(nulltextnode);
+
+  await new Promise(resolve => window.requestAnimationFrame(resolve));
+
   var rf = SpecialPowers.Cc["@mozilla.org/embedcomp/rangefind;1"]
                         .getService(SpecialPowers.Ci.nsIFind);
 
   var display = window.document.getElementById("display");
   var searchRange = window.document.createRange();
   searchRange.setStart(display, 0);
   searchRange.setEnd(display, display.childNodes.length);
   var startPt = searchRange;
   var endPt = searchRange;
 
-  // Check |null| detection on |aSearchRange| parameter.
-  try {
-    rf.Find("", null, startPt, endPt);
-
-    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
-  } catch (e) {
-    let wrappedError = SpecialPowers.wrap(e);
-    if (wrappedError.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
-      ok(true, null);
-    } else {
-      throw wrappedError;
-    }
-  }
-
-  // Check |null| detection on |aStartPoint| parameter.
-  try {
-    rf.Find("", searchRange, null, endPt);
-
-    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
-  } catch (e) {
-    let wrappedError = SpecialPowers.wrap(e);
-    if (wrappedError.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
-      ok(true, null);
-    } else {
-      throw wrappedError;
-    }
-  }
-
-  // Check |null| detection on |aEndPoint| parameter.
-  try {
-    rf.Find("", searchRange, startPt, null);
-
-    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
-  } catch (e) {
-    let wrappedError = SpecialPowers.wrap(e);
-    if (wrappedError.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
-      ok(true, null);
-    } else {
-      throw wrappedError;
-    }
-  }
-
   var searchValue, retRange;
 
   rf.findBackwards = false;
 
   rf.caseSensitive = false;
 
   searchValue = "TexT";
   retRange = rf.Find(searchValue, searchRange, startPt, endPt);
@@ -119,35 +79,34 @@ https://bugzilla.mozilla.org/show_bug.cg
   ok(!retRange, "\"" + searchValue + "\" found (forward)");
 
   rf.findBackwards = true;
 
   // searchValue = "the";
   retRange = rf.Find(searchValue, searchRange, startPt, endPt);
   ok(retRange, "\"" + searchValue + "\" not found (backward)");
 
-
   // Curly quotes and straight quotes should match.
 
   rf.caseSensitive = false;
   rf.findBackwards = false;
 
   function find(node, value) {
     var range = document.createRange();
     range.setStart(node, 0);
     range.setEnd(node, node.childNodes.length);
     return rf.Find(value, range, range, range);
   }
 
   function assertFound(node, value) {
-    ok(find(node, value), "\"" + value + "\" not found");
+    ok(find(node, value), "\"" + value + "\" should be found");
   }
 
   function assertNotFound(node, value) {
-    ok(!find(node, value), "\"" + value + "\" found");
+    ok(!find(node, value), "\"" + value + "\" should not be found");
   }
 
   var quotes = document.getElementById("quotes");
 
   assertFound(quotes, "\"straight\"");
   assertFound(quotes, "\u201Cstraight\u201D");
 
   assertNotFound(quotes, "'straight'");
@@ -216,12 +175,81 @@ https://bugzilla.mozilla.org/show_bug.cg
   assertFound(quotes, "\u201Ccurly\u201D");
 
   assertFound(quotes, "\u2018didn't\u2019");
   assertNotFound(quotes, "'didn't'");
 
   assertFound(quotes, "'doesn\u2019t'");
   assertNotFound(quotes, "'doesn\u2018t'");
   assertNotFound(quotes, "'doesn't'");
+
+  // Embedded strings containing null characters can't be found, because
+  // the HTML parser converts them to \ufffd, which is the replacement
+  // character.
+  const nullcharsnative = document.getElementById("nullcharsnative");
+  assertFound(nullcharsnative, "native null\ufffd");
+
+  // Injected strings containing null characters can be found.
+  assertFound(nullcharsinjected, INJECTED_NULL_TEXT);
+
+  // Do these test at the end since they trigger failure screenshots in
+  // the test harness, and we want as much information as possible about
+  // any OTHER tests that may have already failed.
+
+  // Check |null| detection on |aSearchRange| parameter.
+  try {
+    rf.Find("", null, startPt, endPt);
+
+    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
+  } catch (e) {
+    let wrappedError = SpecialPowers.wrap(e);
+    if (wrappedError.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
+      ok(true, null);
+    } else {
+      throw wrappedError;
+    }
+  }
+
+  // Check |null| detection on |aStartPoint| parameter.
+  try {
+    rf.Find("", searchRange, null, endPt);
+
+    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
+  } catch (e) {
+    let wrappedError = SpecialPowers.wrap(e);
+    if (wrappedError.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
+      ok(true, null);
+    } else {
+      throw wrappedError;
+    }
+  }
+
+  // Check |null| detection on |aEndPoint| parameter.
+  try {
+    rf.Find("", searchRange, startPt, null);
+
+    ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
+  } catch (e) {
+    let wrappedError = SpecialPowers.wrap(e);
+    if (wrappedError.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {
+      ok(true, null);
+    } else {
+      throw wrappedError;
+    }
+  }
+
+  SimpleTest.finish();
+}
 </script>
+</head>
+<body onload="runTests()">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450048">Mozilla Bug 450048</a>
+<p id="display">This is the text to search i<b>n&shy;t</b>o</p>
+<p id="quotes">"straight" and &ldquo;curly&rdquo; and &lsquo;didn't&rsquo; and 'doesn&rsquo;t'</p>
+<p id="nullcharsnative">native null&#0;</p>
+<p id="nullcharsinjected"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
 </pre>
 </body>
 </html>