File: test_connection_store.html

package info (click to toggle)
iceweasel 31.6.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,368,576 kB
  • sloc: cpp: 3,692,968; ansic: 1,797,194; python: 193,401; java: 180,622; asm: 133,557; xml: 89,288; sh: 71,748; perl: 22,087; makefile: 21,687; objc: 4,014; yacc: 1,995; pascal: 1,292; lex: 950; exp: 449; lisp: 228; awk: 211; php: 113; sed: 43; csh: 31; ada: 16; ruby: 3
file content (106 lines) | stat: -rw-r--r-- 3,545 bytes parent folder | download | duplicates (5)
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
<!DOCTYPE html>

<!--
Bug 901519 - [app manager] data store for connections
-->

<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>

    <div id="root">
      <span id="status" template='{"type":"textContent","path":"status"}'></span>
      <span id="host" template='{"type":"textContent","path":"host"}'></span>
      <span id="port" template='{"type":"textContent","path":"port"}'></span>
    </div>

    <script type="application/javascript;version=1.8" src="chrome://browser/content/devtools/app-manager/template.js"></script>
    <script type="application/javascript;version=1.8">
      const Cu = Components.utils;
      Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
      DebuggerServer.init(function () { return true; });
      DebuggerServer.addBrowserActors();

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

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

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

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

        let connection = ConnectionManager.createConnection();
        let store = new ConnectionStore(connection);

        let root = document.querySelector("#root");
        let status = root.querySelector("#status");
        let host = root.querySelector("#host");
        let port = root.querySelector("#port");
        let template = new Template(root, store, () => {});
        template.start();

        connection.host = "foobar";
        connection.port = 42;

        is(host.textContent, "foobar", "host updated");
        is(port.textContent, 42, "port updated");

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

        is(status.textContent, "disconnected", "status updated (diconnected)");

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

        connection.once("connected", (e) => {
          SimpleTest.executeSoon(() => {
            been_through_connected = true;
            is(status.textContent, "connected", "status updated (connected)");
            connection.disconnect();
          })
        });

        connection.once("disconnected", (e) => {
          SimpleTest.executeSoon(() => {
            been_through_disconnected = true;
            is(status.textContent, "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.host = null; // force pipe
        connection.port = null;

        connection.connect();
      }

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