mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 901520 - [app manager] data store for device. r=alex.poirot
This commit is contained in:
parent
55f76e3281
commit
34132fe255
94
browser/devtools/app-manager/device-store.js
Normal file
94
browser/devtools/app-manager/device-store.js
Normal file
@ -0,0 +1,94 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const ObservableObject = require("devtools/shared/observable-object");
|
||||
const {getDeviceFront} = require("devtools/server/actors/device");
|
||||
const {Connection} = require("devtools/client/connection-manager");
|
||||
|
||||
const {Cu} = require("chrome");
|
||||
|
||||
const _knownDeviceStores = new WeakMap();
|
||||
|
||||
let DeviceStore;
|
||||
|
||||
module.exports = DeviceStore = function(connection) {
|
||||
// If we already know about this connection,
|
||||
// let's re-use the existing store.
|
||||
if (_knownDeviceStores.has(connection)) {
|
||||
return _knownDeviceStores.get(connection);
|
||||
}
|
||||
|
||||
_knownDeviceStores.set(connection, this);
|
||||
|
||||
ObservableObject.call(this, {});
|
||||
|
||||
this._resetStore();
|
||||
|
||||
this._destroy = this._destroy.bind(this);
|
||||
this._onStatusChanged = this._onStatusChanged.bind(this);
|
||||
|
||||
this._connection = connection;
|
||||
this._connection.once(Connection.Events.DESTROYED, this._destroy);
|
||||
this._connection.on(Connection.Events.STATUS_CHANGED, this._onStatusChanged);
|
||||
this._onStatusChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
DeviceStore.prototype = {
|
||||
_destroy: function() {
|
||||
this._connection.off(Connection.Events.STATUS_CHANGED, this._onStatusChanged);
|
||||
_knownDeviceStores.delete(this._connection);
|
||||
this._connection = null;
|
||||
},
|
||||
|
||||
_resetStore: function() {
|
||||
this.object.description = {};
|
||||
this.object.permissions = [];
|
||||
},
|
||||
|
||||
_onStatusChanged: function() {
|
||||
if (this._connection.status == Connection.Status.CONNECTED) {
|
||||
this._listTabs();
|
||||
} else {
|
||||
this._resetStore();
|
||||
}
|
||||
},
|
||||
|
||||
_listTabs: function() {
|
||||
this._connection.client.listTabs((resp) => {
|
||||
this._deviceFront = getDeviceFront(this._connection.client, resp);
|
||||
this._feedStore();
|
||||
});
|
||||
},
|
||||
|
||||
_feedStore: function() {
|
||||
this._getDeviceDescription();
|
||||
this._getDevicePermissionsTable();
|
||||
},
|
||||
|
||||
_getDeviceDescription: function() {
|
||||
return this._deviceFront.getDescription()
|
||||
.then(json => {
|
||||
json.dpi = Math.ceil(json.dpi);
|
||||
this.object.description = json;
|
||||
});
|
||||
},
|
||||
|
||||
_getDevicePermissionsTable: function() {
|
||||
return this._deviceFront.getRawPermissionsTable()
|
||||
.then(json => {
|
||||
let permissionsTable = json.rawPermissionsTable;
|
||||
let permissionsArray = [];
|
||||
for (let name in permissionsTable) {
|
||||
permissionsArray.push({
|
||||
name: name,
|
||||
app: permissionsTable[name].app,
|
||||
privileged: permissionsTable[name].privileged,
|
||||
certified: permissionsTable[name].certified,
|
||||
});
|
||||
}
|
||||
this.object.permissions = permissionsArray;
|
||||
});
|
||||
},
|
||||
}
|
@ -13,6 +13,7 @@ include $(DEPTH)/config/autoconf.mk
|
||||
MOCHITEST_CHROME_FILES = \
|
||||
test_template.html \
|
||||
test_connection_store.html \
|
||||
test_device_store.html \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
84
browser/devtools/app-manager/test/test_device_store.html
Normal file
84
browser/devtools/app-manager/test/test_device_store.html
Normal file
@ -0,0 +1,84 @@
|
||||
<!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>
|
Loading…
Reference in New Issue
Block a user