1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/app-manager/test/test_device_store.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +<!DOCTYPE html> 1.5 + 1.6 +<!-- 1.7 +Bug 901520 - [app manager] data store for device 1.8 +--> 1.9 + 1.10 +<html> 1.11 + 1.12 + <head> 1.13 + <meta charset="utf8"> 1.14 + <title></title> 1.15 + 1.16 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.17 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 1.18 + </head> 1.19 + 1.20 + <body> 1.21 + 1.22 + <script type="application/javascript;version=1.8" src="chrome://browser/content/devtools/app-manager/template.js"></script> 1.23 + <script type="application/javascript;version=1.8"> 1.24 + const Cu = Components.utils; 1.25 + Cu.import("resource://gre/modules/devtools/dbg-server.jsm"); 1.26 + DebuggerServer.init(function () { return true; }); 1.27 + DebuggerServer.addBrowserActors(); 1.28 + 1.29 + function compare(o1, o2, msg) { 1.30 + is(JSON.stringify(o1), JSON.stringify(o2), msg); 1.31 + } 1.32 + 1.33 + window.onload = function() { 1.34 + SimpleTest.waitForExplicitFinish(); 1.35 + 1.36 + Cu.import("resource://gre/modules/Services.jsm"); 1.37 + Cu.import("resource:///modules/devtools/gDevTools.jsm"); 1.38 + 1.39 + 1.40 + const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); 1.41 + const {require} = devtools; 1.42 + 1.43 + const {ConnectionManager} = require("devtools/client/connection-manager"); 1.44 + const DeviceStore = require("devtools/app-manager/device-store"); 1.45 + 1.46 + let {getDeviceFront} = devtools.require("devtools/server/actors/device"); 1.47 + 1.48 + let connection = ConnectionManager.createConnection(); 1.49 + let store = new DeviceStore(connection); 1.50 + 1.51 + connection.once("connected", function() { 1.52 + store.on("set", function check(event, path, value) { 1.53 + if (path.join(".") != "description") return; 1.54 + store.off("set", check); 1.55 + info("Connected"); 1.56 + connection.client.listTabs((resp) => { 1.57 + info("List tabs response"); 1.58 + let deviceFront = getDeviceFront(connection.client, resp); 1.59 + deviceFront.getDescription().then(json => { 1.60 + info("getDescription response: " + JSON.stringify(json)); 1.61 + json.dpi = Math.ceil(json.dpi); 1.62 + for (let key in json) { 1.63 + compare(json[key], store.object.description[key], "description." + key + " is valid"); 1.64 + compare(json[key], value[key], "description." + key + " is valid"); 1.65 + } 1.66 + connection.disconnect(); 1.67 + }).then(null, (error) => ok(false, "Error:" + error)); 1.68 + }); 1.69 + }); 1.70 + }); 1.71 + 1.72 + connection.once("disconnected", function() { 1.73 + compare(store.object, {description:{},permissions:[],tabs:[]}, "empty store after disconnect") 1.74 + connection.destroy(); 1.75 + DebuggerServer.destroy(); 1.76 + SimpleTest.finish(); 1.77 + }); 1.78 + 1.79 + compare(store.object, {description:{},permissions:[],tabs:[]}, "empty store before disconnect") 1.80 + 1.81 + connection.connect(); 1.82 + 1.83 + } 1.84 + 1.85 + </script> 1.86 + </body> 1.87 +</html>