summaryrefslogtreecommitdiff
path: root/toolkit/devtools/app-manager/test/test_remain_connected.html
blob: 819e3d6c073b52522c01f0fd8f20cced7a31e572 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>

<!--
Bug 912646 - Closing app toolbox causes phone to disconnect
-->

<html>

  <head>
    <meta charset="utf8">
    <title></title>

    <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
  </head>

  <body>

    <script type="application/javascript;version=1.8">
      const Cu = Components.utils;

      Cu.import("resource://gre/modules/devtools/dbg-server.jsm");

      if (!DebuggerServer.initialized) {
        DebuggerServer.init();
        DebuggerServer.addBrowserActors();
      }

      window.onload = function() {
        SimpleTest.waitForExplicitFinish();

        Cu.import("resource:///modules/devtools/gDevTools.jsm");

        const {devtools} =
          Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
        const {require} = devtools;

        const {Connection, ConnectionManager} =
          require("devtools/client/connection-manager");
        const ConnectionStore =
          require("devtools/app-manager/connection-store");

        let connection = ConnectionManager.createConnection();

        connection.host = null; // force pipe
        connection.port = null;

        let been_through_connecting = false;
        let been_through_connected = false;
        let been_through_disconnected = false;

        is(connection.status, Connection.Status.DISCONNECTED,
           "status updated (diconnected)");

        connection.once("connecting", () => {
          SimpleTest.executeSoon(() => {
            been_through_connecting = true;
            is(connection.status, Connection.Status.CONNECTING,
               "status updated (connecting)");
          })
        });

        connection.once("connected", () => {
          SimpleTest.executeSoon(() => {
            been_through_connected = true;
            is(connection.status, Connection.Status.CONNECTED,
               "status updated (connected)");
            cycleToolbox();
          })
        });

        function cycleToolbox() {
          connection.client.listTabs(response => {
            let options = {
              form: response.tabs[0],
              client: connection.client,
              chrome: true
            };
            devtools.TargetFactory.forRemoteTab(options).then(target => {
              let hostType = devtools.Toolbox.HostType.WINDOW;
              gDevTools.showToolbox(target,
                                    null,
                                    hostType).then(toolbox => {
                SimpleTest.executeSoon(() => {
                  toolbox.once("destroyed", onDestroyToolbox);
                  toolbox.destroy();
                });
              });
            });
          });
        }

        function onDestroyToolbox() {
          is(connection.status, Connection.Status.CONNECTED,
             "toolbox cycled, still connected");
          connection.disconnect();
        }

        connection.once("disconnected", () => {
          SimpleTest.executeSoon(() => {
            been_through_disconnected = true;
            is(connection.status, Connection.Status.DISCONNECTED,
               "status updated (disconnected)");
            connection.destroy();
            finishUp();
          })
        });

        function finishUp() {
          ok(been_through_connecting &&
             been_through_connected &&
             been_through_disconnected, "All updates happened");
          DebuggerServer.destroy();
          SimpleTest.finish();
        }

        connection.connect();
      }

    </script>
  </body>
</html>