browser_jsterm_autocomplete_mapped_variables.js (4329B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Test that makes sure source mapped variables appear in autocompletion 5 // on an equal footing with variables from the generated source. 6 7 "use strict"; 8 9 const TEST_URI = 10 "http://example.com/browser/devtools/client/webconsole/" + 11 "test/browser/test-autocomplete-mapped.html"; 12 13 add_task(async function () { 14 await pushPref("devtools.debugger.map-scopes-enabled", true); 15 const hud = await openNewTabAndConsole(TEST_URI); 16 const { jsterm } = hud; 17 const { autocompletePopup: popup } = jsterm; 18 const toolbox = gDevTools.getToolboxForTab(gBrowser.selectedTab); 19 20 info("Opening Debugger and enabling map scopes"); 21 await openDebugger(); 22 const dbg = createDebuggerContext(toolbox); 23 24 info("Waiting for pause"); 25 // This calls firstCall() on the content page and waits for pause. (firstCall 26 // has a debugger statement) 27 await pauseDebugger(dbg); 28 29 await toolbox.selectTool("webconsole"); 30 await setInputValueForAutocompletion(hud, "valu"); 31 ok( 32 hasExactPopupLabels(popup, ["value", "valueOf", "values"]), 33 "Autocomplete popup displays original variable name" 34 ); 35 36 await setInputValueForAutocompletion(hud, "temp"); 37 const expectedLabels = ["temp", "temp2", "Temporal"]; 38 ok( 39 hasExactPopupLabels(popup, expectedLabels), 40 "Autocomplete popup displays original variable name when entering a complete variable name" 41 ); 42 43 await setInputValueForAutocompletion(hud, "t"); 44 ok( 45 hasPopupLabel(popup, "t"), 46 "Autocomplete popup displays generated variable name" 47 ); 48 49 await setInputValueForAutocompletion(hud, "value.to"); 50 ok( 51 hasPopupLabel(popup, "toString"), 52 "Autocomplete popup displays properties of original variable" 53 ); 54 55 await setInputValueForAutocompletion(hud, "imported.imp"); 56 ok( 57 hasPopupLabel(popup, "importResult"), 58 "Autocomplete popup displays properties of multi-part variable" 59 ); 60 61 let tooltip = await setInputValueForGetterConfirmDialog( 62 toolbox, 63 hud, 64 "getter." 65 ); 66 let labelEl = tooltip.querySelector(".confirm-label"); 67 is( 68 labelEl.textContent, 69 "Invoke getter getter to retrieve the property list?", 70 "Dialog has expected text content" 71 ); 72 73 info( 74 "Check that getter confirmation on a variable that maps to two getters invokes both getters" 75 ); 76 let onPopUpOpen = popup.once("popup-opened"); 77 EventUtils.synthesizeKey("KEY_Tab"); 78 await onPopUpOpen; 79 ok(popup.isOpen, "popup is open after Tab"); 80 ok(hasPopupLabel(popup, "getterResult"), "popup has expected items"); 81 82 info( 83 "Check that the getter confirmation dialog shows the original variable name" 84 ); 85 tooltip = await setInputValueForGetterConfirmDialog( 86 toolbox, 87 hud, 88 "localWithGetter.value." 89 ); 90 labelEl = tooltip.querySelector(".confirm-label"); 91 is( 92 labelEl.textContent, 93 "Invoke getter localWithGetter.value to retrieve the property list?", 94 "Dialog has expected text content" 95 ); 96 97 info( 98 "Check that hitting Tab does invoke the getter and return its properties" 99 ); 100 onPopUpOpen = popup.once("popup-opened"); 101 EventUtils.synthesizeKey("KEY_Tab"); 102 await onPopUpOpen; 103 ok(popup.isOpen, "popup is open after Tab"); 104 ok(hasPopupLabel(popup, "then"), "popup has expected items"); 105 info("got popup items: " + JSON.stringify(getAutocompletePopupLabels(popup))); 106 107 info( 108 "Check that authorizing an original getter applies to the generated getter" 109 ); 110 await setInputValueForAutocompletion(hud, "o.value."); 111 ok(hasPopupLabel(popup, "then"), "popup has expected items"); 112 113 await setInputValueForAutocompletion(hud, "(temp + temp2)."); 114 ok( 115 hasPopupLabel(popup, "toFixed"), 116 "Autocomplete popup displays properties of eagerly evaluated value" 117 ); 118 info("got popup items: " + JSON.stringify(getAutocompletePopupLabels(popup))); 119 120 info("Switch to the debugger and disabling map scopes"); 121 await toolbox.selectTool("jsdebugger"); 122 await toggleMapScopes(dbg); 123 await toolbox.selectTool("webconsole"); 124 125 await setInputValueForAutocompletion(hud, "tem"); 126 const autocompleteLabels = getAutocompletePopupLabels(popup); 127 ok( 128 !autocompleteLabels.includes("temp"), 129 "Autocomplete popup does not display mapped variables when mapping is disabled" 130 ); 131 132 await resume(dbg); 133 });