browser_jsterm_helper_dollar_dollar.js (2273B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TEST_URI = `data:text/html,<!DOCTYPE html> 7 <main> 8 <ul> 9 <li>First</li> 10 <li>Second</li> 11 </ul> 12 <ul id="myList"> 13 <li id="myListItem1" class="inMyList">First</li> 14 <li id="myListItem2" class="inMyList">Second</li> 15 </ul> 16 <aside>Sidebar</aside> 17 </main> 18 `; 19 20 add_task(async function () { 21 const hud = await openNewTabAndConsole(TEST_URI); 22 23 // Place the mouse on the top left corner to avoid triggering an highlighter request 24 // to the server. See Bug 1535082. 25 EventUtils.synthesizeMouse( 26 hud.ui.outputNode, 27 0, 28 0, 29 { type: "mousemove" }, 30 hud.iframeWindow 31 ); 32 33 let message = await executeAndWaitForResultMessage( 34 hud, 35 "$$('main')", 36 "Array [ main ]" 37 ); 38 ok(message, "`$$('main')` worked"); 39 40 message = await executeAndWaitForResultMessage( 41 hud, 42 "$$('main > ul > li')", 43 "Array(4) [ li, li, li#myListItem1.inMyList, li#myListItem2.inMyList ]" 44 ); 45 ok(message, "`$$('main > ul > li')` worked"); 46 47 message = await executeAndWaitForResultMessage( 48 hud, 49 "$$('main > ul > li').map(el => el.tagName).join(' - ')", 50 "LI - LI - LI - LI" 51 ); 52 ok(message, "`$$` result can be used right away"); 53 54 message = await executeAndWaitForResultMessage(hud, "$$('div')", "Array []"); 55 ok(message, "`$$('div')` returns an empty array"); 56 57 message = await executeAndWaitForErrorMessage( 58 hud, 59 "$$(':foo')", 60 "':foo' is not a valid selector" 61 ); 62 ok(message, "`$$(':foo')` returns an error message"); 63 64 message = await executeAndWaitForResultMessage( 65 hud, 66 "$$('li', document.querySelector('ul#myList'))", 67 "Array [ li#myListItem1.inMyList, li#myListItem2.inMyList ]" 68 ); 69 ok(message, "`$$('li', document.querySelector('ul#myList'))` worked"); 70 71 message = await executeAndWaitForErrorMessage( 72 hud, 73 "$$('li', $(':foo'))", 74 "':foo' is not a valid selector" 75 ); 76 ok(message, "`$$('li', $(':foo'))` returns an error message"); 77 78 message = await executeAndWaitForResultMessage( 79 hud, 80 "$$('li', $('div'))", 81 "Array(4) [ li, li, li#myListItem1.inMyList, li#myListItem2.inMyList ]" 82 ); 83 ok(message, "`$$('li', $('div'))` worked"); 84 });