summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/test/browser_dbg_navigation.js
blob: 5549b524c199448b2cb3fa93a1ec0f899ad9a129 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Check tab attach/navigation.
 */

const TAB1_URL = EXAMPLE_URL + "doc_empty-tab-01.html";
const TAB2_FILE = "doc_empty-tab-02.html";
const TAB2_URL = EXAMPLE_URL + TAB2_FILE;

add_task(async () => {
  // Navigation events (navigate/will-navigate/tabNavigated) on the target no longer fire with server targets.
  // We should probably drop this test once we stop supporting client side targets (bug 1721852).
  await pushPref("devtools.target-switching.server.enabled", false);

  const tab = await addTab(TAB1_URL);
  const target = await createAndAttachTargetForTab(tab);

  await testNavigate(target);
  await testTargetDestroyed(target);
});

function testNavigate(target) {
  return new Promise(resolve => {
    let gotStartPacket = false;
    target.on("tabNavigated", function onTabNavigated(packet) {
      is(
        packet.url.split("/").pop(),
        TAB2_FILE,
        "Got a tab navigation notification."
      );

      info(JSON.stringify(packet));

      if (packet.state == "start") {
        ok(true, "Tab started to navigate.");
        gotStartPacket = true;
      } else if (gotStartPacket) {
        ok(true, "Tab finished navigating.");
        target.off("tabNavigated", onTabNavigated);
        resolve();
      }
    });

    BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TAB2_URL);
  });
}

async function testTargetDestroyed(target) {
  // We can't listen for tabDetached at it is received by Target first
  // and target is destroyed
  const onDetached = target.once("target-destroyed");

  removeTab(gBrowser.selectedTab);

  await onDetached;
  ok(true, "Got a tab detach notification.");
}