test_inspector-search-front.html (5189B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=835896 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 835896</title> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 11 <script type="application/javascript" src="inspector-helpers.js"></script> 12 <script type="application/javascript"> 13 "use strict"; 14 15 window.onload = function() { 16 SimpleTest.waitForExplicitFinish(); 17 18 let walkerFront = null; 19 let inspectorCommand = null; 20 21 // WalkerFront and Inspector Command specific tests. These aren't to exercise search 22 // edge cases so much as to test the state the Front maintains between 23 // searches. 24 25 addAsyncTest(async function setup() { 26 info("Setting up inspector and walker actors."); 27 28 const url = document.getElementById("inspectorContent").href; 29 30 const { commands } = await attachURL(url); 31 const target = commands.targetCommand.targetFront; 32 const inspector = await target.getFront("inspector"); 33 34 walkerFront = inspector.walker; 35 inspectorCommand = commands.inspectorCommand; 36 37 runNextTest(); 38 }); 39 40 addAsyncTest(async function testWalkerFrontDefaults() { 41 info("Testing search API using WalkerFront and Inspector Command."); 42 const nodes = await walkerFront.querySelectorAll(walkerFront.rootNode, "h2"); 43 const fronts = await nodes.items(); 44 45 const commandResult = await inspectorCommand.findNextNode(""); 46 ok(!commandResult, "Null result on front when searching for ''"); 47 48 let results = await inspectorCommand.findNextNode("h2"); 49 isDeeply(results, { 50 node: fronts[0], 51 resultsIndex: 0, 52 resultsLength: 3, 53 }, "Default options work"); 54 55 results = await inspectorCommand.findNextNode("h2", { }); 56 isDeeply(results, { 57 node: fronts[1], 58 resultsIndex: 1, 59 resultsLength: 3, 60 }, "Search works with empty options"); 61 62 // Clear search data to remove result state on the front 63 await inspectorCommand.findNextNode(""); 64 runNextTest(); 65 }); 66 67 addAsyncTest(async function testMultipleSearches() { 68 info("Testing search API using WalkerFront and Inspector Command (reverse=false)"); 69 const nodes = await walkerFront.querySelectorAll(walkerFront.rootNode, "h2"); 70 const fronts = await nodes.items(); 71 72 let results = await inspectorCommand.findNextNode("h2"); 73 isDeeply(results, { 74 node: fronts[0], 75 resultsIndex: 0, 76 resultsLength: 3, 77 }, "Search works with multiple results (reverse=false)"); 78 79 results = await inspectorCommand.findNextNode("h2"); 80 isDeeply(results, { 81 node: fronts[1], 82 resultsIndex: 1, 83 resultsLength: 3, 84 }, "Search works with multiple results (reverse=false)"); 85 86 results = await inspectorCommand.findNextNode("h2"); 87 isDeeply(results, { 88 node: fronts[2], 89 resultsIndex: 2, 90 resultsLength: 3, 91 }, "Search works with multiple results (reverse=false)"); 92 93 results = await inspectorCommand.findNextNode("h2"); 94 isDeeply(results, { 95 node: fronts[0], 96 resultsIndex: 0, 97 resultsLength: 3, 98 }, "Search works with multiple results (reverse=false)"); 99 100 // Clear search data to remove result state on the front 101 await inspectorCommand.findNextNode(""); 102 runNextTest(); 103 }); 104 105 addAsyncTest(async function testMultipleSearchesReverse() { 106 info("Testing search API using WalkerFront and Inspector Command (reverse=true)"); 107 const nodes = await walkerFront.querySelectorAll(walkerFront.rootNode, "h2"); 108 const fronts = await nodes.items(); 109 110 let results = await inspectorCommand.findNextNode("h2", {reverse: true}); 111 isDeeply(results, { 112 node: fronts[2], 113 resultsIndex: 2, 114 resultsLength: 3, 115 }, "Search works with multiple results (reverse=true)"); 116 117 results = await inspectorCommand.findNextNode("h2", {reverse: true}); 118 isDeeply(results, { 119 node: fronts[1], 120 resultsIndex: 1, 121 resultsLength: 3, 122 }, "Search works with multiple results (reverse=true)"); 123 124 results = await inspectorCommand.findNextNode("h2", {reverse: true}); 125 isDeeply(results, { 126 node: fronts[0], 127 resultsIndex: 0, 128 resultsLength: 3, 129 }, "Search works with multiple results (reverse=true)"); 130 131 results = await inspectorCommand.findNextNode("h2", {reverse: true}); 132 isDeeply(results, { 133 node: fronts[2], 134 resultsIndex: 2, 135 resultsLength: 3, 136 }, "Search works with multiple results (reverse=true)"); 137 138 results = await inspectorCommand.findNextNode("h2", {reverse: false}); 139 isDeeply(results, { 140 node: fronts[0], 141 resultsIndex: 0, 142 resultsLength: 3, 143 }, "Search works with multiple results (reverse=false)"); 144 145 // Clear search data to remove result state on the command 146 await inspectorCommand.findNextNode(""); 147 runNextTest(); 148 }); 149 150 runNextTest(); 151 }; 152 </script> 153 </head> 154 <body> 155 <a id="inspectorContent" target="_blank" href="inspector-search-data.html">Test Document</a> 156 <p id="display"></p> 157 <div id="content" style="display: none"> 158 159 </div> 160 <pre id="test"> 161 </pre> 162 </body> 163 </html>