tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_inspector_switch-to-inspector-on-pick.js (3504B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Testing that clicking the pick button switches the toolbox to the inspector
      6 // panel.
      7 
      8 const TEST_URI =
      9  "data:text/html;charset=UTF-8,<!DOCTYPE html><script>console.log(`hello`)</script><p>Switch to inspector on pick</p>";
     10 const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
     11 
     12 const DATA = [
     13  {
     14    timestamp: 3562,
     15    category: "devtools.main",
     16    method: "enter",
     17    object: "webconsole",
     18    extra: {
     19      host: "bottom",
     20      start_state: "initial_panel",
     21      panel_name: "webconsole",
     22      cold: "true",
     23      message_count: "1",
     24      width: "1300",
     25    },
     26  },
     27  {
     28    timestamp: 3671,
     29    category: "devtools.main",
     30    method: "exit",
     31    object: "webconsole",
     32    extra: {
     33      host: "bottom",
     34      width: "1300",
     35      panel_name: "webconsole",
     36      next_panel: "inspector",
     37      reason: "inspect_dom",
     38    },
     39  },
     40  {
     41    timestamp: 3671,
     42    category: "devtools.main",
     43    method: "enter",
     44    object: "inspector",
     45    extra: {
     46      host: "bottom",
     47      start_state: "inspect_dom",
     48      panel_name: "inspector",
     49      cold: "true",
     50      width: "1300",
     51    },
     52  },
     53 ];
     54 
     55 add_task(async function () {
     56  // Let's reset the counts.
     57  Services.telemetry.clearEvents();
     58 
     59  // Ensure no events have been logged
     60  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
     61  ok(!snapshot.parent, "No events have been logged for the main process");
     62 
     63  const tab = await addTab(TEST_URI);
     64  const toolbox = await openToolbox(tab);
     65 
     66  await startPickerAndAssertSwitchToInspector(toolbox);
     67 
     68  info("Stopping element picker.");
     69  await toolbox.nodePicker.stop({ canceled: true });
     70 
     71  checkResults();
     72 });
     73 
     74 async function openToolbox(tab) {
     75  info("Opening webconsole.");
     76  return gDevTools.showToolboxForTab(tab, { toolId: "webconsole" });
     77 }
     78 
     79 async function startPickerAndAssertSwitchToInspector(toolbox) {
     80  info("Clicking element picker button.");
     81  const pickButton = toolbox.doc.querySelector("#command-button-pick");
     82  pickButton.click();
     83 
     84  info("Waiting for inspector to be selected.");
     85  await toolbox.once("inspector-selected");
     86  is(toolbox.currentToolId, "inspector", "Switched to the inspector");
     87 }
     88 
     89 function checkResults() {
     90  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
     91  const events = snapshot.parent.filter(
     92    event =>
     93      (event[1] === "devtools.main" && event[2] === "enter") ||
     94      event[2] === "exit"
     95  );
     96 
     97  for (const i in DATA) {
     98    const [timestamp, category, method, object, value, extra] = events[i];
     99    const expected = DATA[i];
    100 
    101    // ignore timestamp
    102    Assert.greater(timestamp, 0, "timestamp is greater than 0");
    103    is(category, expected.category, "category is correct");
    104    is(method, expected.method, "method is correct");
    105    is(object, expected.object, "object is correct");
    106    is(value, null, "value is correct");
    107    Assert.greater(Number(extra.width), 0, "width is greater than 0");
    108 
    109    checkExtra("host", extra, expected);
    110    checkExtra("start_state", extra, expected);
    111    checkExtra("reason", extra, expected);
    112    checkExtra("panel_name", extra, expected);
    113    checkExtra("next_panel", extra, expected);
    114    checkExtra("message_count", extra, expected);
    115    checkExtra("cold", extra, expected);
    116  }
    117 }
    118 
    119 function checkExtra(propName, extra, expected) {
    120  if (extra[propName]) {
    121    is(extra[propName], expected.extra[propName], `${propName} is correct`);
    122  }
    123 }