browser_webconsole_telemetry_execute_js.js (3194B)
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 // Tests that the console record the execute_js telemetry event with expected data 6 // when evaluating expressions. 7 8 "use strict"; 9 10 const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8>Test execute_js telemetry event`; 11 const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS; 12 13 add_task(async function () { 14 // Let's reset the counts. 15 Services.telemetry.clearEvents(); 16 17 // Ensure no events have been logged 18 const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true); 19 ok(!snapshot.parent, "No events have been logged for the main process"); 20 21 const hud = await openNewTabAndConsole(TEST_URI); 22 23 info("Evaluate a single line"); 24 await keyboardExecuteAndWaitForResultMessage(hud, `"single line"`, ""); 25 26 info("Evaluate another single line"); 27 await keyboardExecuteAndWaitForResultMessage(hud, `"single line 2"`, ""); 28 29 info("Evaluate multiple lines"); 30 await keyboardExecuteAndWaitForResultMessage(hud, `"n"\n.trim()`, ""); 31 32 info("Switch to editor mode"); 33 await toggleLayout(hud); 34 35 info("Evaluate a single line in editor mode"); 36 await keyboardExecuteAndWaitForResultMessage(hud, `"single line 3"`, ""); 37 38 info("Evaluate multiple lines in editor mode"); 39 await keyboardExecuteAndWaitForResultMessage( 40 hud, 41 `"y"\n.trim()\n.trim()`, 42 "" 43 ); 44 45 info("Evaluate multiple lines again in editor mode"); 46 await keyboardExecuteAndWaitForResultMessage(hud, `"x"\n.trim()`, ""); 47 48 checkEventTelemetry([ 49 getTelemetryEventData({ lines: 1, input: "inline" }), 50 getTelemetryEventData({ lines: 1, input: "inline" }), 51 getTelemetryEventData({ lines: 2, input: "inline" }), 52 getTelemetryEventData({ lines: 1, input: "multiline" }), 53 getTelemetryEventData({ lines: 3, input: "multiline" }), 54 getTelemetryEventData({ lines: 2, input: "multiline" }), 55 ]); 56 57 info("Switch back to inline mode"); 58 await toggleLayout(hud); 59 }); 60 61 function checkEventTelemetry(expectedData) { 62 const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true); 63 const events = snapshot.parent.filter( 64 event => 65 event[1] === "devtools.main" && 66 event[2] === "execute_js" && 67 event[3] === "webconsole" && 68 event[4] === null 69 ); 70 71 for (const [i, expected] of expectedData.entries()) { 72 const [timestamp, category, method, object, value, extra] = events[i]; 73 74 // ignore timestamp 75 Assert.greater(timestamp, 0, "timestamp is greater than 0"); 76 is(category, expected.category, "'category' is correct"); 77 is(method, expected.method, "'method' is correct"); 78 is(object, expected.object, "'object' is correct"); 79 is(value, expected.value, "'value' is correct"); 80 is(parseInt(extra.lines, 10), expected.extra.lines, "'lines' is correct"); 81 is(extra.input, expected.extra.input, "'input' is correct"); 82 } 83 } 84 85 function getTelemetryEventData(extra) { 86 return { 87 timestamp: null, 88 category: "devtools.main", 89 method: "execute_js", 90 object: "webconsole", 91 value: null, 92 extra, 93 }; 94 }