summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_simple-init.js
blob: 19d05811c3dc3c88687e3cd2db6841dba2312d9a (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Simple check if the network monitor starts up and shuts down properly.
 */

function test() {
  // These test suite functions are removed from the global scope inside a
  // cleanup function. However, we still need them.
  let gInfo = info;
  let gOk = ok;

  initNetMonitor(SIMPLE_URL).then(({ tab, monitor }) => {
    info("Starting test... ");

    is(tab.linkedBrowser.currentURI.spec, SIMPLE_URL,
      "The current tab's location is the correct one.");

    function checkIfInitialized(tag) {
      info(`Checking if initialization is ok (${tag}).`);

      ok(monitor._view,
        `The network monitor view object exists (${tag}).`);
      ok(monitor._controller,
        `The network monitor controller object exists (${tag}).`);
      ok(monitor._controller._startup,
        `The network monitor controller object exists and is initialized (${tag}).`);

      ok(monitor.isReady,
        `The network monitor panel appears to be ready (${tag}).`);

      ok(monitor._controller.tabClient,
        `There should be a tabClient available at this point (${tag}).`);
      ok(monitor._controller.webConsoleClient,
        `There should be a webConsoleClient available at this point (${tag}).`);
      ok(monitor._controller.timelineFront,
        `There should be a timelineFront available at this point (${tag}).`);
    }

    function checkIfDestroyed(tag) {
      gInfo("Checking if destruction is ok.");

      gOk(monitor._view,
        `The network monitor view object still exists (${tag}).`);
      gOk(monitor._controller,
        `The network monitor controller object still exists (${tag}).`);
      gOk(monitor._controller._shutdown,
        `The network monitor controller object still exists and is destroyed (${tag}).`);

      gOk(!monitor._controller.tabClient,
        `There shouldn't be a tabClient available after destruction (${tag}).`);
      gOk(!monitor._controller.webConsoleClient,
        `There shouldn't be a webConsoleClient available after destruction (${tag}).`);
      gOk(!monitor._controller.timelineFront,
        `There shouldn't be a timelineFront available after destruction (${tag}).`);
    }

    executeSoon(() => {
      checkIfInitialized(1);

      monitor._controller.startupNetMonitor()
        .then(() => {
          info("Starting up again shouldn't do anything special.");
          checkIfInitialized(2);
          return monitor._controller.connect();
        })
        .then(() => {
          info("Connecting again shouldn't do anything special.");
          checkIfInitialized(3);
          return teardown(monitor);
        })
        .then(finish);
    });

    registerCleanupFunction(() => {
      checkIfDestroyed(1);

      monitor._controller.shutdownNetMonitor()
        .then(() => {
          gInfo("Shutting down again shouldn't do anything special.");
          checkIfDestroyed(2);
          return monitor._controller.disconnect();
        })
        .then(() => {
          gInfo("Disconnecting again shouldn't do anything special.");
          checkIfDestroyed(3);
        });
    });
  });
}