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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/app-manager/test/test_connection_store.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +<!DOCTYPE html>
     1.5 +
     1.6 +<!--
     1.7 +Bug 901519 - [app manager] data store for connections
     1.8 +-->
     1.9 +
    1.10 +<html>
    1.11 +
    1.12 +  <head>
    1.13 +    <meta charset="utf8">
    1.14 +    <title></title>
    1.15 +
    1.16 +    <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.17 +    <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
    1.18 +  </head>
    1.19 +
    1.20 +  <body>
    1.21 +
    1.22 +    <div id="root">
    1.23 +      <span id="status" template='{"type":"textContent","path":"status"}'></span>
    1.24 +      <span id="host" template='{"type":"textContent","path":"host"}'></span>
    1.25 +      <span id="port" template='{"type":"textContent","path":"port"}'></span>
    1.26 +    </div>
    1.27 +
    1.28 +    <script type="application/javascript;version=1.8" src="chrome://browser/content/devtools/app-manager/template.js"></script>
    1.29 +    <script type="application/javascript;version=1.8">
    1.30 +      const Cu = Components.utils;
    1.31 +      Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
    1.32 +      DebuggerServer.init(function () { return true; });
    1.33 +      DebuggerServer.addBrowserActors();
    1.34 +
    1.35 +      window.onload = function() {
    1.36 +        SimpleTest.waitForExplicitFinish();
    1.37 +
    1.38 +        Cu.import("resource://gre/modules/Services.jsm");
    1.39 +        Cu.import("resource:///modules/devtools/gDevTools.jsm");
    1.40 +
    1.41 +        const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
    1.42 +        const {require} = devtools;
    1.43 +
    1.44 +        const {ConnectionManager} = require("devtools/client/connection-manager");
    1.45 +        const ConnectionStore = require("devtools/app-manager/connection-store");
    1.46 +
    1.47 +        let connection = ConnectionManager.createConnection();
    1.48 +        let store = new ConnectionStore(connection);
    1.49 +
    1.50 +        let root = document.querySelector("#root");
    1.51 +        let status = root.querySelector("#status");
    1.52 +        let host = root.querySelector("#host");
    1.53 +        let port = root.querySelector("#port");
    1.54 +        let template = new Template(root, store, () => {});
    1.55 +        template.start();
    1.56 +
    1.57 +        connection.host = "foobar";
    1.58 +        connection.port = 42;
    1.59 +
    1.60 +        is(host.textContent, "foobar", "host updated");
    1.61 +        is(port.textContent, 42, "port updated");
    1.62 +
    1.63 +        let been_through_connecting = false;
    1.64 +        let been_through_connected = false;
    1.65 +        let been_through_disconnected = false;
    1.66 +
    1.67 +        is(status.textContent, "disconnected", "status updated (diconnected)");
    1.68 +
    1.69 +        connection.once("connecting", (e) => {
    1.70 +          SimpleTest.executeSoon(() => {
    1.71 +            been_through_connecting = true;
    1.72 +            is(status.textContent, "connecting", "status updated (connecting)");
    1.73 +          })
    1.74 +        });
    1.75 +
    1.76 +        connection.once("connected", (e) => {
    1.77 +          SimpleTest.executeSoon(() => {
    1.78 +            been_through_connected = true;
    1.79 +            is(status.textContent, "connected", "status updated (connected)");
    1.80 +            connection.disconnect();
    1.81 +          })
    1.82 +        });
    1.83 +
    1.84 +        connection.once("disconnected", (e) => {
    1.85 +          SimpleTest.executeSoon(() => {
    1.86 +            been_through_disconnected = true;
    1.87 +            is(status.textContent, "disconnected", "status updated (disconnected)");
    1.88 +            connection.destroy();
    1.89 +            finishup();
    1.90 +          })
    1.91 +        });
    1.92 +
    1.93 +        function finishup() {
    1.94 +          ok(been_through_connecting &&
    1.95 +            been_through_connected &&
    1.96 +            been_through_disconnected, "All updates happened");
    1.97 +          DebuggerServer.destroy();
    1.98 +          SimpleTest.finish();
    1.99 +        }
   1.100 +
   1.101 +        connection.host = null; // force pipe
   1.102 +        connection.port = null;
   1.103 +
   1.104 +        connection.connect();
   1.105 +      }
   1.106 +
   1.107 +    </script>
   1.108 +  </body>
   1.109 +</html>

mercurial