test_logpoint-02.js (2543B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Check that conditions are respected when specified in a logpoint. 8 */ 9 10 const Resources = require("resource://devtools/server/actors/resources/index.js"); 11 12 add_task( 13 threadFrontTest(async ({ threadActor, threadFront, debuggee, client }) => { 14 let lastMessage, lastExpression; 15 const { targetActor } = threadActor; 16 // Only Workers are evaluating through the WebConsoleActor. 17 // Tabs will be evaluating directly via the frame object. 18 targetActor._consoleActor = { 19 evaluateJS(expression) { 20 lastExpression = expression; 21 }, 22 }; 23 24 // And then listen for resource RDP event. 25 // Bug 1646677: But we should probably migrate this test to ResourceCommand so that 26 // we don't have to hack the server side via Resource.watchResources call. 27 targetActor.on( 28 "resources-available-array", 29 ([[resourceType, resources]]) => { 30 if (resourceType == Resources.TYPES.CONSOLE_MESSAGE) { 31 lastMessage = resources[0]; 32 } 33 } 34 ); 35 36 // But both tabs and processes will be going through the ConsoleMessages module 37 // We force watching for console message first, 38 await Resources.watchResources(targetActor, [ 39 Resources.TYPES.CONSOLE_MESSAGE, 40 ]); 41 42 const packet = await executeOnNextTickAndWaitForPause( 43 () => evalCode(debuggee), 44 threadFront 45 ); 46 47 const source = await getSourceById(threadFront, packet.frame.where.actor); 48 49 // Set a logpoint which should invoke console.log. 50 threadFront.setBreakpoint( 51 { 52 sourceUrl: source.url, 53 line: 4, 54 }, 55 { logValue: "a", condition: "a === 5" } 56 ); 57 await client.waitForRequestsToSettle(); 58 59 // Execute the rest of the code. 60 await threadFront.resume(); 61 62 // NOTE: logpoints evaluated in a worker have a lastExpression 63 if (lastMessage) { 64 Assert.equal(lastMessage.level, "logPoint"); 65 Assert.equal(lastMessage.arguments[0], 5); 66 Assert.ok(/\d+\.\d+/.test(lastMessage.timeStamp)); 67 } else { 68 Assert.equal(lastExpression.text, "console.log(...[a])"); 69 Assert.equal(lastExpression.lineNumber, 4); 70 } 71 }) 72 ); 73 74 function evalCode(debuggee) { 75 /* eslint-disable */ 76 Cu.evalInSandbox( 77 "debugger;\n" + // 1 78 "var a = 1;\n" + // 2 79 "while (a < 10) {\n" + // 3 80 " a++;\n" + // 4 81 "}", 82 debuggee, 83 "1.8", 84 "test.js", 85 1 86 ); 87 /* eslint-enable */ 88 }