browser/devtools/app-manager/test/test_connection_store.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:0e21fd61be8f
1 <!DOCTYPE html>
2
3 <!--
4 Bug 901519 - [app manager] data store for connections
5 -->
6
7 <html>
8
9 <head>
10 <meta charset="utf8">
11 <title></title>
12
13 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
14 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
15 </head>
16
17 <body>
18
19 <div id="root">
20 <span id="status" template='{"type":"textContent","path":"status"}'></span>
21 <span id="host" template='{"type":"textContent","path":"host"}'></span>
22 <span id="port" template='{"type":"textContent","path":"port"}'></span>
23 </div>
24
25 <script type="application/javascript;version=1.8" src="chrome://browser/content/devtools/app-manager/template.js"></script>
26 <script type="application/javascript;version=1.8">
27 const Cu = Components.utils;
28 Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
29 DebuggerServer.init(function () { return true; });
30 DebuggerServer.addBrowserActors();
31
32 window.onload = function() {
33 SimpleTest.waitForExplicitFinish();
34
35 Cu.import("resource://gre/modules/Services.jsm");
36 Cu.import("resource:///modules/devtools/gDevTools.jsm");
37
38 const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
39 const {require} = devtools;
40
41 const {ConnectionManager} = require("devtools/client/connection-manager");
42 const ConnectionStore = require("devtools/app-manager/connection-store");
43
44 let connection = ConnectionManager.createConnection();
45 let store = new ConnectionStore(connection);
46
47 let root = document.querySelector("#root");
48 let status = root.querySelector("#status");
49 let host = root.querySelector("#host");
50 let port = root.querySelector("#port");
51 let template = new Template(root, store, () => {});
52 template.start();
53
54 connection.host = "foobar";
55 connection.port = 42;
56
57 is(host.textContent, "foobar", "host updated");
58 is(port.textContent, 42, "port updated");
59
60 let been_through_connecting = false;
61 let been_through_connected = false;
62 let been_through_disconnected = false;
63
64 is(status.textContent, "disconnected", "status updated (diconnected)");
65
66 connection.once("connecting", (e) => {
67 SimpleTest.executeSoon(() => {
68 been_through_connecting = true;
69 is(status.textContent, "connecting", "status updated (connecting)");
70 })
71 });
72
73 connection.once("connected", (e) => {
74 SimpleTest.executeSoon(() => {
75 been_through_connected = true;
76 is(status.textContent, "connected", "status updated (connected)");
77 connection.disconnect();
78 })
79 });
80
81 connection.once("disconnected", (e) => {
82 SimpleTest.executeSoon(() => {
83 been_through_disconnected = true;
84 is(status.textContent, "disconnected", "status updated (disconnected)");
85 connection.destroy();
86 finishup();
87 })
88 });
89
90 function finishup() {
91 ok(been_through_connecting &&
92 been_through_connected &&
93 been_through_disconnected, "All updates happened");
94 DebuggerServer.destroy();
95 SimpleTest.finish();
96 }
97
98 connection.host = null; // force pipe
99 connection.port = null;
100
101 connection.connect();
102 }
103
104 </script>
105 </body>
106 </html>

mercurial