summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_inspect.js
blob: 60176258b1b5f6465f92e66d4436f1c50230114b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/* import-globals-from helper-telemetry.js */
Services.scriptloader.loadSubScript(
  CHROME_URL_ROOT + "helper-telemetry.js",
  this
);

const TAB_URL = "data:text/html,<title>TEST_TAB</title>";

/**
 * Check that telemetry events are recorded when inspecting a target.
 */
add_task(async function () {
  setupTelemetryTest();

  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  const sessionId = getOpenEventSessionId();
  ok(!isNaN(sessionId), "Open event has a valid session id");

  info("Open a new background tab TEST_TAB");
  const backgroundTab1 = await addTab(TAB_URL, { background: true });

  info("Wait for the tab to appear in the debug targets with the correct name");
  await waitUntil(() => findDebugTargetByText("TEST_TAB", document));

  const { devtoolsTab } = await openAboutDevtoolsToolbox(
    document,
    tab,
    window,
    "TEST_TAB"
  );

  const evts = readAboutDebuggingEvents().filter(e => e.method === "inspect");
  is(evts.length, 1, "Exactly one Inspect event found");
  is(
    evts[0].extras.target_type,
    "TAB",
    "Inspect event has the expected target type"
  );
  is(
    evts[0].extras.runtime_type,
    "this-firefox",
    "Inspect event has the expected runtime type"
  );
  is(
    evts[0].extras.session_id,
    sessionId,
    "Inspect event has the expected session"
  );

  info("Close the about:devtools-toolbox tab");
  await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
  await waitForAboutDebuggingRequests(window.AboutDebugging.store);

  info("Remove first background tab");
  await removeTab(backgroundTab1);
  await waitUntil(() => !findDebugTargetByText("TEST_TAB", document));
  await waitForAboutDebuggingRequests(window.AboutDebugging.store);

  await removeTab(tab);
});