browser/devtools/app-manager/test/test_remain_connected.html
author Birunthan Mohanathas <birunthan@mohanathas.com>
Mon, 05 May 2014 20:30:39 +0300
changeset 194024 4e27f466ebbb6578ab008f231f12a00917c2c718
parent 154113 84caf75159b2505779228b0dc71bd3de1b915f1f
permissions -rw-r--r--
Bug 995730 - Change xpcom/base/ to use 2 space indentation This also removes trailing whitespace in reindented files.

<!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");
      DebuggerServer.init(function () { return true; });
      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>