|
1 <!DOCTYPE html> |
|
2 |
|
3 <!-- |
|
4 Bug 901520 - [app manager] data store for device |
|
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" src="chrome://browser/content/devtools/app-manager/template.js"></script> |
|
20 <script type="application/javascript;version=1.8"> |
|
21 const Cu = Components.utils; |
|
22 Cu.import("resource://gre/modules/devtools/dbg-server.jsm"); |
|
23 DebuggerServer.init(function () { return true; }); |
|
24 DebuggerServer.addBrowserActors(); |
|
25 |
|
26 function compare(o1, o2, msg) { |
|
27 is(JSON.stringify(o1), JSON.stringify(o2), msg); |
|
28 } |
|
29 |
|
30 window.onload = function() { |
|
31 SimpleTest.waitForExplicitFinish(); |
|
32 |
|
33 Cu.import("resource://gre/modules/Services.jsm"); |
|
34 Cu.import("resource:///modules/devtools/gDevTools.jsm"); |
|
35 |
|
36 |
|
37 const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); |
|
38 const {require} = devtools; |
|
39 |
|
40 const {ConnectionManager} = require("devtools/client/connection-manager"); |
|
41 const DeviceStore = require("devtools/app-manager/device-store"); |
|
42 |
|
43 let {getDeviceFront} = devtools.require("devtools/server/actors/device"); |
|
44 |
|
45 let connection = ConnectionManager.createConnection(); |
|
46 let store = new DeviceStore(connection); |
|
47 |
|
48 connection.once("connected", function() { |
|
49 store.on("set", function check(event, path, value) { |
|
50 if (path.join(".") != "description") return; |
|
51 store.off("set", check); |
|
52 info("Connected"); |
|
53 connection.client.listTabs((resp) => { |
|
54 info("List tabs response"); |
|
55 let deviceFront = getDeviceFront(connection.client, resp); |
|
56 deviceFront.getDescription().then(json => { |
|
57 info("getDescription response: " + JSON.stringify(json)); |
|
58 json.dpi = Math.ceil(json.dpi); |
|
59 for (let key in json) { |
|
60 compare(json[key], store.object.description[key], "description." + key + " is valid"); |
|
61 compare(json[key], value[key], "description." + key + " is valid"); |
|
62 } |
|
63 connection.disconnect(); |
|
64 }).then(null, (error) => ok(false, "Error:" + error)); |
|
65 }); |
|
66 }); |
|
67 }); |
|
68 |
|
69 connection.once("disconnected", function() { |
|
70 compare(store.object, {description:{},permissions:[],tabs:[]}, "empty store after disconnect") |
|
71 connection.destroy(); |
|
72 DebuggerServer.destroy(); |
|
73 SimpleTest.finish(); |
|
74 }); |
|
75 |
|
76 compare(store.object, {description:{},permissions:[],tabs:[]}, "empty store before disconnect") |
|
77 |
|
78 connection.connect(); |
|
79 |
|
80 } |
|
81 |
|
82 </script> |
|
83 </body> |
|
84 </html> |