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