browser_webconsole_location_logpoint_debugger_link.js (4914B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Test clicking locations of logpoint logs and errors will open corresponding 5 // conditional panels in the debugger. 6 7 "use strict"; 8 9 // Allow more time since we now wait for CM6 document updates to complete 10 requestLongerTimeout(2); 11 12 const BASE_URI = 13 "https://example.com/browser/devtools/client/webconsole/test/browser/"; 14 const TEST_URI = BASE_URI + "test-location-debugger-link-logpoint.html"; 15 const TEST_JS_URI = BASE_URI + "test-location-debugger-link-logpoint-1.js"; 16 const TEST_JS_URI2 = BASE_URI + "test-location-debugger-link-logpoint-2.js"; 17 18 add_task(async function () { 19 // On e10s, the exception thrown in test-location-debugger-link-errors.js 20 // is triggered in child process and is ignored by test harness 21 if (!Services.appinfo.browserTabsRemoteAutostart) { 22 expectUncaughtException(); 23 } 24 25 // Eliminate interference from "saved" breakpoints 26 // when running the test multiple times 27 await clearDebuggerPreferences(); 28 const hud = await openNewTabAndConsole(TEST_URI); 29 30 info("Open the Debugger panel"); 31 await openDebugger(); 32 33 const toolbox = hud.toolbox; 34 const dbg = createDebuggerContext(toolbox); 35 await selectSource(dbg, "test-location-debugger-link-logpoint-1.js"); 36 37 info("Add a logpoint with an invalid expression"); 38 await setLogPoint(dbg, 7, "undefinedVariable"); 39 40 info("Add a logpoint with a valid expression"); 41 await setLogPoint(dbg, 8, "`a is ${a}`"); 42 43 await assertLogBreakpoint(dbg, 7); 44 await assertLogBreakpoint(dbg, 8); 45 46 info("Close the file in the debugger"); 47 await closeTab(dbg, "test-location-debugger-link-logpoint-1.js"); 48 49 info("Selecting the console"); 50 await toolbox.selectTool("webconsole"); 51 52 info("Call the function"); 53 await invokeInTab("add"); 54 55 info("Wait for two messages"); 56 await waitFor(() => findAllMessages(hud).length === 2); 57 58 await testOpenInDebugger(hud, { 59 text: "undefinedVariable is not defined", 60 typeSelector: ".logPointError", 61 url: TEST_JS_URI, 62 line: 7, 63 column: 13, 64 logPointExpr: "undefinedVariable", 65 }); 66 67 info("Selecting the console again"); 68 await toolbox.selectTool("webconsole"); 69 await testOpenInDebugger(hud, { 70 text: "a is 1", 71 typeSelector: ".logPoint", 72 url: TEST_JS_URI, 73 line: 8, 74 column: 13, 75 logPointExpr: "`a is ${a}`", 76 }); 77 78 // Test clicking location of a removed logpoint, or a newly added breakpoint 79 // at an old logpoint's location will only highlight its line 80 info("Remove the logpoints"); 81 const source = await findSource( 82 dbg, 83 "test-location-debugger-link-logpoint-1.js" 84 ); 85 await removeBreakpoint(dbg, source.id, 7); 86 await removeBreakpoint(dbg, source.id, 8); 87 await addBreakpoint(dbg, "test-location-debugger-link-logpoint-1.js", 8); 88 89 info("Selecting the console"); 90 await toolbox.selectTool("webconsole"); 91 await testOpenInDebugger(hud, { 92 text: "undefinedVariable is not defined", 93 typeSelector: ".logPointError", 94 url: TEST_JS_URI, 95 line: 7, 96 column: 13, 97 }); 98 99 info("Selecting the console again"); 100 await toolbox.selectTool("webconsole"); 101 await testOpenInDebugger(hud, { 102 text: "a is 1", 103 typeSelector: ".logPoint", 104 url: TEST_JS_URI, 105 line: 8, 106 column: 13, 107 }); 108 }); 109 110 // Test clicking locations of logpoints from different files 111 add_task(async function () { 112 if (!Services.appinfo.browserTabsRemoteAutostart) { 113 expectUncaughtException(); 114 } 115 116 await clearDebuggerPreferences(); 117 const hud = await openNewTabAndConsole(TEST_URI); 118 119 info("Open the Debugger panel"); 120 await openDebugger(); 121 122 const toolbox = hud.toolbox; 123 const dbg = createDebuggerContext(toolbox); 124 125 info("Add a logpoint to the first file"); 126 await selectSource(dbg, "test-location-debugger-link-logpoint-1.js"); 127 128 await setLogPoint(dbg, 8, "`a is ${a}`"); 129 130 info("Add a logpoint to the second file"); 131 await selectSource(dbg, "test-location-debugger-link-logpoint-2.js"); 132 133 await setLogPoint(dbg, 8, "`c is ${c}`"); 134 135 info("Selecting the console"); 136 await toolbox.selectTool("webconsole"); 137 138 info("Call the function from the first file"); 139 await invokeInTab("add"); 140 141 info("Wait for the first message"); 142 await waitFor(() => findAllMessages(hud).length === 1); 143 await testOpenInDebugger(hud, { 144 text: "a is 1", 145 typeSelector: ".logPoint", 146 url: TEST_JS_URI, 147 line: 8, 148 column: 13, 149 logPointExpr: "`a is ${a}`", 150 }); 151 152 info("Selecting the console again"); 153 await toolbox.selectTool("webconsole"); 154 155 info("Call the function from the second file"); 156 await invokeInTab("subtract"); 157 158 info("Wait for the second message"); 159 await waitFor(() => findAllMessages(hud).length === 2); 160 await testOpenInDebugger(hud, { 161 text: "c is 1", 162 typeSelector: ".logPoint", 163 url: TEST_JS_URI2, 164 line: 8, 165 column: 13, 166 logPointExpr: "`c is ${c}`", 167 }); 168 });