browser_jsterm_autocomplete_in_debugger_stackframe.js (4451B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Test that makes sure web console autocomplete happens in the user-selected 5 // stackframe from the js debugger. 6 7 "use strict"; 8 9 const TEST_URI = 10 "http://example.com/browser/devtools/client/webconsole/" + 11 "test/browser/test-autocomplete-in-stackframe.html"; 12 13 requestLongerTimeout(20); 14 15 add_task(async function () { 16 const hud = await openNewTabAndConsole(TEST_URI); 17 const { jsterm } = hud; 18 const { autocompletePopup: popup } = jsterm; 19 20 const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab); 21 22 const jstermComplete = value => setInputValueForAutocompletion(hud, value); 23 24 // Test that document.title gives string methods. Native getters must execute. 25 await jstermComplete("document.title."); 26 27 const newItemsLabels = getAutocompletePopupLabels(popup); 28 ok(!!newItemsLabels.length, "'document.title.' gave a list of suggestions"); 29 ok(newItemsLabels.includes("substr"), `results do contain "substr"`); 30 ok( 31 newItemsLabels.includes("toLowerCase"), 32 `results do contain "toLowerCase"` 33 ); 34 ok(newItemsLabels.includes("strike"), `results do contain "strike"`); 35 36 // Test if 'foo' gives 'foo1' but not 'foo2' or 'foo3' 37 await jstermComplete("foo"); 38 ok( 39 hasExactPopupLabels(popup, ["foo1", "foo1Obj"]), 40 `"foo" gave the expected suggestions` 41 ); 42 43 // Test if 'foo1Obj.' gives 'prop1' and 'prop2' 44 await jstermComplete("foo1Obj."); 45 checkInputCompletionValue(hud, "method", "foo1Obj completion"); 46 ok( 47 hasExactPopupLabels(popup, ["method", "prop1", "prop2"]), 48 `"foo1Obj." gave the expected suggestions` 49 ); 50 51 // Test if 'foo1Obj.prop2.' gives 'prop21' 52 await jstermComplete("foo1Obj.prop2."); 53 ok( 54 hasPopupLabel(popup, "prop21"), 55 `"foo1Obj.prop2." gave the expected suggestions` 56 ); 57 await closeAutocompletePopup(hud); 58 59 info("Opening Debugger"); 60 await openDebugger(); 61 const dbg = createDebuggerContext(toolbox); 62 63 info("Waiting for pause"); 64 await pauseDebugger(dbg); 65 const stackFrames = dbg.selectors.getCurrentThreadFrames(); 66 67 info("Opening Console again"); 68 await toolbox.selectTool("webconsole"); 69 70 // Test if 'this.' gives 'method', 'prop1', and 'prop2', not global variables, since we are paused in 71 // `foo1Obj.method()` (called by `secondCall`) 72 await jstermComplete("this."); 73 ok( 74 hasExactPopupLabels(popup, ["method", "prop1", "prop2"]), 75 `"this." gave the expected suggestions` 76 ); 77 78 await selectFrame(dbg, stackFrames[1]); 79 80 // Test if 'foo' gives 'foo3' and 'foo1' but not 'foo2', since we are now in the `secondCall` 81 // frame (called by `firstCall`, which we call in `pauseDebugger`). 82 await jstermComplete("foo"); 83 ok( 84 hasExactPopupLabels(popup, ["foo1", "foo1Obj", "foo3", "foo3Obj"]), 85 `"foo." gave the expected suggestions` 86 ); 87 88 // Test that 'shadowed.' autocompletes properties from the local variable named "shadowed". 89 await jstermComplete("shadowed."); 90 ok( 91 hasExactPopupLabels(popup, ["bar"]), 92 `"shadowed." gave the expected suggestions` 93 ); 94 95 await openDebugger(); 96 97 // Select the frame for the `firstCall` function. 98 await selectFrame(dbg, stackFrames[2]); 99 100 info("openConsole"); 101 await toolbox.selectTool("webconsole"); 102 103 // Test if 'foo' gives 'foo2' and 'foo1' but not 'foo3', since we are now in the 104 // `firstCall` frame. 105 await jstermComplete("foo"); 106 ok( 107 hasExactPopupLabels(popup, ["foo1", "foo1Obj", "foo2", "foo2Obj"]), 108 `"foo" gave the expected suggestions` 109 ); 110 111 // Test that 'shadowed.' autocompletes properties from the global variable named "shadowed". 112 await jstermComplete("shadowed."); 113 ok( 114 hasExactPopupLabels(popup, ["foo"]), 115 `"shadowed." gave the expected suggestions` 116 ); 117 118 // Test if 'foo2Obj.' gives 'prop1' 119 await jstermComplete("foo2Obj."); 120 ok(hasPopupLabel(popup, "prop1"), `"foo2Obj." returns "prop1"`); 121 122 // Test if 'foo2Obj.prop1.' gives 'prop11' 123 await jstermComplete("foo2Obj.prop1."); 124 ok(hasPopupLabel(popup, "prop11"), `"foo2Obj.prop1" returns "prop11"`); 125 126 // Test if 'foo2Obj.prop1.prop11.' gives suggestions for a string,i.e. 'length' 127 await jstermComplete("foo2Obj.prop1.prop11."); 128 ok(hasPopupLabel(popup, "length"), `results do contain "length"`); 129 130 // Test if 'foo2Obj[0].' throws no errors. 131 await jstermComplete("foo2Obj[0]."); 132 is(getAutocompletePopupLabels(popup).length, 0, "no items for foo2Obj[0]"); 133 });