Bug 1538042 Part 2: Add tests of null character searches. r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D25293

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brad Werth 2019-09-04 22:59:25 +00:00
Родитель 4887367dee
Коммит b9e615d3bd
2 изменённых файлов: 89 добавлений и 53 удалений

Просмотреть файл

@ -122,6 +122,14 @@ let runTests = t.step_func_done(function() {
input.value = "foo";
document.documentElement.appendChild(input);
}, "Native anonymous content isn't exposed in window.find");
testFindable(false, "\0", `
�
`);
testFindable(true, "\0", function(document) {
document.documentElement.appendChild(document.createTextNode("\0"));
}, "Inserted null characters are findable");
});
window.onload = function() {

Просмотреть файл

@ -8,21 +8,23 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=450048
<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);
@ -33,48 +35,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=450048
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;
@ -124,7 +84,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=450048
retRange = rf.Find(searchValue, searchRange, startPt, endPt);
ok(retRange, "\"" + searchValue + "\" not found (backward)");
// Curly quotes and straight quotes should match.
rf.caseSensitive = false;
@ -138,11 +97,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=450048
}
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");
@ -221,7 +180,76 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=450048
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>