browser_telemetry_activate_rdm.js (2919B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 const URL = "data:text/html;charset=utf8,browser_telemetry_activate_rdm.js"; 6 const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS; 7 const DATA = [ 8 { 9 timestamp: null, 10 category: "devtools.main", 11 method: "activate", 12 object: "responsive_design", 13 value: null, 14 extra: { 15 host: "none", 16 width: "1300", 17 }, 18 }, 19 { 20 timestamp: null, 21 category: "devtools.main", 22 method: "deactivate", 23 object: "responsive_design", 24 value: null, 25 extra: { 26 host: "none", 27 width: "1300", 28 }, 29 }, 30 { 31 timestamp: null, 32 category: "devtools.main", 33 method: "activate", 34 object: "responsive_design", 35 value: null, 36 extra: { 37 host: "bottom", 38 width: "1300", 39 }, 40 }, 41 { 42 timestamp: null, 43 category: "devtools.main", 44 method: "deactivate", 45 object: "responsive_design", 46 value: null, 47 extra: { 48 host: "bottom", 49 width: "1300", 50 }, 51 }, 52 ]; 53 54 addRDMTask( 55 null, 56 async function () { 57 // Let's reset the counts. 58 Services.telemetry.clearEvents(); 59 60 // Ensure no events have been logged 61 const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true); 62 ok(!snapshot.parent, "No events have been logged for the main process"); 63 64 const tab = await addTab(URL); 65 66 await openCloseRDM(tab); 67 await gDevTools.showToolboxForTab(tab, { toolId: "inspector" }); 68 await openCloseRDM(tab); 69 await checkResults(); 70 }, 71 { onlyPrefAndTask: true } 72 ); 73 74 async function openCloseRDM(tab) { 75 const { ui } = await openRDM(tab); 76 await waitForDeviceAndViewportState(ui); 77 78 const clientClosed = waitForClientClose(ui); 79 80 closeRDM(tab, { 81 reason: "TabClose", 82 }); 83 84 // This flag is set at the end of `ResponsiveUI.destroy`. If it is true 85 // without waiting for `closeRDM` above, then we must have closed 86 // synchronously. 87 is(ui.destroyed, true, "RDM closed synchronously"); 88 89 await clientClosed; 90 } 91 92 async function checkResults() { 93 const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true); 94 const events = snapshot.parent.filter( 95 event => 96 event[1] === "devtools.main" && 97 (event[2] === "activate" || event[2] === "deactivate") 98 ); 99 100 for (const i in events) { 101 const [timestamp, category, method, object, value, extra] = events[i]; 102 103 const expected = DATA[i]; 104 105 // ignore timestamp 106 Assert.greater(timestamp, 0, "timestamp is greater than 0"); 107 is(category, expected.category, "category is correct"); 108 is(method, expected.method, "method is correct"); 109 is(object, expected.object, "object is correct"); 110 is(value, expected.value, "value is correct"); 111 112 // extras 113 is(extra.host, expected.extra.host, "host is correct"); 114 Assert.greater(Number(extra.width), 0, "width is greater than 0"); 115 } 116 }