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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial