summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/chrome/test_inspector-search-front.html
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/server/tests/chrome/test_inspector-search-front.html')
-rw-r--r--devtools/server/tests/chrome/test_inspector-search-front.html172
1 files changed, 172 insertions, 0 deletions
diff --git a/devtools/server/tests/chrome/test_inspector-search-front.html b/devtools/server/tests/chrome/test_inspector-search-front.html
new file mode 100644
index 0000000000..a8c24135b2
--- /dev/null
+++ b/devtools/server/tests/chrome/test_inspector-search-front.html
@@ -0,0 +1,172 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=835896
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 835896</title>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+ <script type="application/javascript" src="inspector-helpers.js"></script>
+ <script type="application/javascript">
+"use strict";
+
+window.onload = function() {
+ SimpleTest.waitForExplicitFinish();
+
+ let walkerFront = null;
+ let inspector = null;
+
+ // WalkerFront specific tests. These aren't to excercise search
+ // edge cases so much as to test the state the Front maintains between
+ // searches.
+ // See also test_inspector-search.html
+
+ addAsyncTest(async function setup() {
+ info("Setting up inspector and walker actors.");
+
+ const url = document.getElementById("inspectorContent").href;
+
+ const { target } = await attachURL(url);
+ inspector = await target.getFront("inspector");
+ walkerFront = inspector.walker;
+
+ runNextTest();
+ });
+
+ addAsyncTest(async function testWalkerFrontDefaults() {
+ info("Testing search API using WalkerFront.");
+ const nodes = await walkerFront.querySelectorAll(walkerFront.rootNode, "h2");
+ const fronts = await nodes.items();
+
+ const frontResult = await walkerFront.search("");
+ ok(!frontResult, "Null result on front when searching for ''");
+
+ let results = await walkerFront.search("h2");
+ isDeeply(results, {
+ node: fronts[0],
+ type: "search",
+ resultsIndex: 0,
+ resultsLength: 3,
+ }, "Default options work");
+
+ results = await walkerFront.search("h2", { });
+ isDeeply(results, {
+ node: fronts[1],
+ type: "search",
+ resultsIndex: 1,
+ resultsLength: 3,
+ }, "Search works with empty options");
+
+ // Clear search data to remove result state on the front
+ await walkerFront.search("");
+ runNextTest();
+ });
+
+ addAsyncTest(async function testMultipleSearches() {
+ info("Testing search API using WalkerFront (reverse=false)");
+ const nodes = await walkerFront.querySelectorAll(walkerFront.rootNode, "h2");
+ const fronts = await nodes.items();
+
+ let results = await walkerFront.search("h2");
+ isDeeply(results, {
+ node: fronts[0],
+ type: "search",
+ resultsIndex: 0,
+ resultsLength: 3,
+ }, "Search works with multiple results (reverse=false)");
+
+ results = await walkerFront.search("h2");
+ isDeeply(results, {
+ node: fronts[1],
+ type: "search",
+ resultsIndex: 1,
+ resultsLength: 3,
+ }, "Search works with multiple results (reverse=false)");
+
+ results = await walkerFront.search("h2");
+ isDeeply(results, {
+ node: fronts[2],
+ type: "search",
+ resultsIndex: 2,
+ resultsLength: 3,
+ }, "Search works with multiple results (reverse=false)");
+
+ results = await walkerFront.search("h2");
+ isDeeply(results, {
+ node: fronts[0],
+ type: "search",
+ resultsIndex: 0,
+ resultsLength: 3,
+ }, "Search works with multiple results (reverse=false)");
+
+ // Clear search data to remove result state on the front
+ await walkerFront.search("");
+ runNextTest();
+ });
+
+ addAsyncTest(async function testMultipleSearchesReverse() {
+ info("Testing search API using WalkerFront (reverse=true)");
+ const nodes = await walkerFront.querySelectorAll(walkerFront.rootNode, "h2");
+ const fronts = await nodes.items();
+
+ let results = await walkerFront.search("h2", {reverse: true});
+ isDeeply(results, {
+ node: fronts[2],
+ type: "search",
+ resultsIndex: 2,
+ resultsLength: 3,
+ }, "Search works with multiple results (reverse=true)");
+
+ results = await walkerFront.search("h2", {reverse: true});
+ isDeeply(results, {
+ node: fronts[1],
+ type: "search",
+ resultsIndex: 1,
+ resultsLength: 3,
+ }, "Search works with multiple results (reverse=true)");
+
+ results = await walkerFront.search("h2", {reverse: true});
+ isDeeply(results, {
+ node: fronts[0],
+ type: "search",
+ resultsIndex: 0,
+ resultsLength: 3,
+ }, "Search works with multiple results (reverse=true)");
+
+ results = await walkerFront.search("h2", {reverse: true});
+ isDeeply(results, {
+ node: fronts[2],
+ type: "search",
+ resultsIndex: 2,
+ resultsLength: 3,
+ }, "Search works with multiple results (reverse=true)");
+
+ results = await walkerFront.search("h2", {reverse: false});
+ isDeeply(results, {
+ node: fronts[0],
+ type: "search",
+ resultsIndex: 0,
+ resultsLength: 3,
+ }, "Search works with multiple results (reverse=false)");
+
+ // Clear search data to remove result state on the front
+ await walkerFront.search("");
+ runNextTest();
+ });
+
+ runNextTest();
+};
+ </script>
+</head>
+<body>
+<a id="inspectorContent" target="_blank" href="inspector-search-data.html">Test Document</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>