var gFindResults = []; // Stub the method that instantiates nsIFind and does all the interaction with // the docShell to be searched through.
finderIterator._iterateDocument = function* () { for (let range of gFindResults) {
yield range;
}
};
Assert.equal(rangeCount, count, "Amount of ranges yielded should match!"); Assert.ok(!finderIterator.running, "Running state should match"); Assert.equal(
finderIterator._previousRanges.length,
rangeCount, "Ranges cache should match"
);
finderIterator.reset();
});
add_task(async function test_subframes() {
let findText = "test";
let rangeCount = 300;
prepareIterator(findText, rangeCount);
Assert.equal(rangeCount, count, "Amount of ranges yielded should match!"); Assert.ok(!finderIterator.running, "Running state should match"); Assert.equal(
finderIterator._previousRanges.length,
rangeCount, "Ranges cache should match"
);
finderIterator.reset();
});
add_task(async function test_valid_arguments() {
let findText = "foo";
let rangeCount = 20;
prepareIterator(findText, rangeCount);
let params = finderIterator._previousParams; Assert.ok(!params.linksOnly, "Default for linksOnly is false"); Assert.ok(!params.useCache, "Default for useCache is false"); Assert.equal(params.word, findText, "Words should match");
Assert.ok(finderIterator.running, "Yup, running we are"); Assert.equal(count, 0, "Number of ranges should match 0"); Assert.equal(
finderIterator.ranges.length,
0, "Number of ranges should match 0"
);
finderIterator.reset();
Assert.ok(!finderIterator.running, "Nope, running we are not"); Assert.equal(finderIterator.ranges.length, 0, "No ranges after reset"); Assert.equal(
finderIterator._previousRanges.length,
0, "No ranges after reset"
);
await whenDone;
Assert.equal(count, 0, "Number of ranges should match 0");
});
add_task(async function test_parallel_starts() {
let findText = "tak";
let rangeCount = 2143;
prepareIterator(findText, rangeCount);
// Start off the iterator.
let count = 0;
let whenDone = finderIterator.start({
caseSensitive: false,
entireWord: false,
finder: gMockFinder,
listener: {
onIteratorRangeFound() {
++count;
},
},
matchDiacritics: false,
word: findText,
});
await new Promise(resolve => gMockWindow.setTimeout(resolve, 100)); Assert.ok(finderIterator.running, "We ought to be running here");
// Let the iterator run for a little while longer before we assert the world.
await new Promise(resolve => gMockWindow.setTimeout(resolve, 10));
finderIterator.stop();
Assert.ok(!finderIterator.running, "Stop means stop");
await whenDone;
await whenDone2;
Assert.greater(
count,
finderIterator.kIterationSizeMax, "At least one range should've been found"
); Assert.less(count, rangeCount, "Not all ranges should've been found"); Assert.greater(
count2,
finderIterator.kIterationSizeMax, "At least one range should've been found"
); Assert.less(count2, rangeCount, "Not all ranges should've been found");
Assert.equal(
count2,
count, "The second start was later, but should have caught up"
);
finderIterator.reset();
});
add_task(async function test_allowDistance() {
let findText = "gup";
let rangeCount = 20;
prepareIterator(findText, rangeCount);
// Start off the iterator.
let count = 0;
let whenDone = finderIterator.start({
caseSensitive: false,
entireWord: false,
finder: gMockFinder,
listener: {
onIteratorRangeFound() {
++count;
},
},
matchDiacritics: false,
word: findText,
});
Assert.equal(
count,
rangeCount, "The first iterator invocation should yield all results"
); Assert.equal(
count2,
0, "The second iterator invocation should yield _no_ results"
); Assert.equal(
count3,
rangeCount, "The first iterator invocation should yield all results"
);
finderIterator.reset();
});
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.