browser_dbg-scopes-mutations.js (2022B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 "use strict"; 6 7 add_task(async function () { 8 const dbg = await initDebugger("doc-script-mutate.html"); 9 10 const onPaused = waitForPaused(dbg, "script-mutate.js"); 11 invokeInTab("mutate"); 12 await onPaused; 13 14 is( 15 getScopeNodeLabel(dbg, 2), 16 "<this>", 17 'The second element in the scope panel is "<this>"' 18 ); 19 is( 20 getScopeNodeLabel(dbg, 4), 21 "phonebook", 22 'The fourth element in the scope panel is "phonebook"' 23 ); 24 25 info("Expand `phonebook`"); 26 await expandNode(dbg, 4); 27 is( 28 getScopeNodeLabel(dbg, 5), 29 "S", 30 'The fifth element in the scope panel is "S"' 31 ); 32 33 info("Expand `S`"); 34 await expandNode(dbg, 5); 35 is( 36 getScopeNodeLabel(dbg, 6), 37 "sarah", 38 'The sixth element in the scope panel is "sarah"' 39 ); 40 is( 41 getScopeNodeLabel(dbg, 7), 42 "serena", 43 'The seventh element in the scope panel is "serena"' 44 ); 45 46 info("Expand `sarah`"); 47 await expandNode(dbg, 6); 48 is( 49 getScopeNodeLabel(dbg, 7), 50 "lastName", 51 'The seventh element in the scope panel is now "lastName"' 52 ); 53 is( 54 getScopeNodeValue(dbg, 7), 55 '"Doe"', 56 'The "lastName" element has the expected "Doe" value' 57 ); 58 59 await resume(dbg); 60 await waitForPaused(dbg); 61 62 is( 63 getScopeNodeLabel(dbg, 2), 64 "<this>", 65 'The second element in the scope panel is "<this>"' 66 ); 67 is( 68 getScopeNodeLabel(dbg, 4), 69 "phonebook", 70 'The fourth element in the scope panel is "phonebook"' 71 ); 72 }); 73 74 function expandNode(dbg, index) { 75 const node = findElement(dbg, "scopeNode", index); 76 const objectInspector = node.closest(".object-inspector"); 77 const properties = objectInspector.querySelectorAll(".node").length; 78 findElement(dbg, "scopeNode", index).click(); 79 return waitUntil( 80 () => objectInspector.querySelectorAll(".node").length !== properties 81 ); 82 }