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

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

mercurial