browser/devtools/app-manager/test/test_remain_connected.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

     1 <!DOCTYPE html>
     3 <!--
     4 Bug 912646 - Closing app toolbox causes phone to disconnect
     5 -->
     7 <html>
     9   <head>
    10     <meta charset="utf8">
    11     <title></title>
    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>
    17   <body>
    19     <script type="application/javascript;version=1.8">
    20       const Cu = Components.utils;
    22       Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
    23       DebuggerServer.init(function () { return true; });
    24       DebuggerServer.addBrowserActors();
    26       window.onload = function() {
    27         SimpleTest.waitForExplicitFinish();
    29         Cu.import("resource:///modules/devtools/gDevTools.jsm");
    31         const {devtools} =
    32           Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
    33         const {require} = devtools;
    35         const {Connection, ConnectionManager} =
    36           require("devtools/client/connection-manager");
    37         const ConnectionStore =
    38           require("devtools/app-manager/connection-store");
    40         let connection = ConnectionManager.createConnection();
    42         connection.host = null; // force pipe
    43         connection.port = null;
    45         let been_through_connecting = false;
    46         let been_through_connected = false;
    47         let been_through_disconnected = false;
    49         is(connection.status, Connection.Status.DISCONNECTED,
    50            "status updated (diconnected)");
    52         connection.once("connecting", () => {
    53           SimpleTest.executeSoon(() => {
    54             been_through_connecting = true;
    55             is(connection.status, Connection.Status.CONNECTING,
    56                "status updated (connecting)");
    57           })
    58         });
    60         connection.once("connected", () => {
    61           SimpleTest.executeSoon(() => {
    62             been_through_connected = true;
    63             is(connection.status, Connection.Status.CONNECTED,
    64                "status updated (connected)");
    65             cycleToolbox();
    66           })
    67         });
    69         function cycleToolbox() {
    70           connection.client.listTabs(response => {
    71             let options = {
    72               form: response.tabs[0],
    73               client: connection.client,
    74               chrome: true
    75             };
    76             devtools.TargetFactory.forRemoteTab(options).then(target => {
    77               let hostType = devtools.Toolbox.HostType.WINDOW;
    78               gDevTools.showToolbox(target,
    79                                     null,
    80                                     hostType).then(toolbox => {
    81                 SimpleTest.executeSoon(() => {
    82                   toolbox.once("destroyed", onDestroyToolbox);
    83                   toolbox.destroy();
    84                 });
    85               });
    86             });
    87           });
    88         }
    90         function onDestroyToolbox() {
    91           is(connection.status, Connection.Status.CONNECTED,
    92              "toolbox cycled, still connected");
    93           connection.disconnect();
    94         }
    96         connection.once("disconnected", () => {
    97           SimpleTest.executeSoon(() => {
    98             been_through_disconnected = true;
    99             is(connection.status, Connection.Status.DISCONNECTED,
   100                "status updated (disconnected)");
   101             connection.destroy();
   102             finishUp();
   103           })
   104         });
   106         function finishUp() {
   107           ok(been_through_connecting &&
   108              been_through_connected &&
   109              been_through_disconnected, "All updates happened");
   110           DebuggerServer.destroy();
   111           SimpleTest.finish();
   112         }
   114         connection.connect();
   115       }
   117     </script>
   118   </body>
   119 </html>

mercurial