gecko-dev/browser/devtools/app-manager/test/test_device_store.html

85 lines
2.9 KiB
HTML

<!DOCTYPE html>
<!--
Bug 901520 - [app manager] data store for device
-->
<html>
<head>
<meta charset="utf8">
<title></title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body>
<script type="application/javascript;version=1.8" src="chrome://browser/content/devtools/app-manager/template.js"></script>
<script type="application/javascript;version=1.8">
const Cu = Components.utils;
Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
DebuggerServer.init(function () { return true; });
DebuggerServer.addBrowserActors();
function compare(o1, o2, msg) {
is(JSON.stringify(o1), JSON.stringify(o2), msg);
}
window.onload = function() {
SimpleTest.waitForExplicitFinish();
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource:///modules/devtools/gDevTools.jsm");
const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
const {require} = devtools;
const {ConnectionManager} = require("devtools/client/connection-manager");
const DeviceStore = require("devtools/app-manager/device-store");
let {getDeviceFront} = devtools.require("devtools/server/actors/device");
let connection = ConnectionManager.createConnection();
let store = new DeviceStore(connection);
connection.once("connected", function() {
store.on("set", function check(event, path, value) {
if (path.join(".") != "description") return;
store.off("set", check);
info("Connected");
connection.client.listTabs((resp) => {
info("List tabs response");
let deviceFront = getDeviceFront(connection.client, resp);
deviceFront.getDescription().then(json => {
info("getDescription response: " + JSON.stringify(json));
json.dpi = Math.ceil(json.dpi);
for (let key in json) {
compare(json[key], store.object.description[key], "description." + key + " is valid");
compare(json[key], value[key], "description." + key + " is valid");
}
connection.disconnect();
}).then(null, (error) => ok(false, "Error:" + error));
});
});
});
connection.once("disconnected", function() {
compare(store.object, {description:{},permissions:[]}, "empty store after disconnect")
connection.destroy();
DebuggerServer.destroy();
SimpleTest.finish();
});
compare(store.object, {description:{},permissions:[]}, "empty store before disconnect")
connection.connect();
}
</script>
</body>
</html>