|
1 <!DOCTYPE html> |
|
2 |
|
3 <!-- |
|
4 Bug 912646 - Closing app toolbox causes phone to disconnect |
|
5 --> |
|
6 |
|
7 <html> |
|
8 |
|
9 <head> |
|
10 <meta charset="utf8"> |
|
11 <title></title> |
|
12 |
|
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> |
|
16 |
|
17 <body> |
|
18 |
|
19 <script type="application/javascript;version=1.8"> |
|
20 const Cu = Components.utils; |
|
21 |
|
22 Cu.import("resource://gre/modules/devtools/dbg-server.jsm"); |
|
23 DebuggerServer.init(function () { return true; }); |
|
24 DebuggerServer.addBrowserActors(); |
|
25 |
|
26 window.onload = function() { |
|
27 SimpleTest.waitForExplicitFinish(); |
|
28 |
|
29 Cu.import("resource:///modules/devtools/gDevTools.jsm"); |
|
30 |
|
31 const {devtools} = |
|
32 Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); |
|
33 const {require} = devtools; |
|
34 |
|
35 const {Connection, ConnectionManager} = |
|
36 require("devtools/client/connection-manager"); |
|
37 const ConnectionStore = |
|
38 require("devtools/app-manager/connection-store"); |
|
39 |
|
40 let connection = ConnectionManager.createConnection(); |
|
41 |
|
42 connection.host = null; // force pipe |
|
43 connection.port = null; |
|
44 |
|
45 let been_through_connecting = false; |
|
46 let been_through_connected = false; |
|
47 let been_through_disconnected = false; |
|
48 |
|
49 is(connection.status, Connection.Status.DISCONNECTED, |
|
50 "status updated (diconnected)"); |
|
51 |
|
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 }); |
|
59 |
|
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 }); |
|
68 |
|
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 } |
|
89 |
|
90 function onDestroyToolbox() { |
|
91 is(connection.status, Connection.Status.CONNECTED, |
|
92 "toolbox cycled, still connected"); |
|
93 connection.disconnect(); |
|
94 } |
|
95 |
|
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 }); |
|
105 |
|
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 } |
|
113 |
|
114 connection.connect(); |
|
115 } |
|
116 |
|
117 </script> |
|
118 </body> |
|
119 </html> |