bug 1268399 - add runtime.getBrowserInfo() method with AppInfo data
MozReview-Commit-ID: GvwFG0CyfR7
--- a/toolkit/components/extensions/ExtensionXPCShellUtils.jsm
+++ b/toolkit/components/extensions/ExtensionXPCShellUtils.jsm
@@ -264,32 +264,32 @@ var ExtensionTestUtils = {
Services.dirsvc.unregisterProvider(dirProvider);
this.currentScope = null;
});
},
addonManagerStarted: false,
+ mockAppInfo() {
+ const {updateAppInfo} = Cu.import("resource://testing-common/AppInfo.jsm", {});
+ updateAppInfo({
+ ID: "xpcshell@tests.mozilla.org",
+ name: "XPCShell",
+ version: "48",
+ platformVersion: "48",
+ });
+ },
+
startAddonManager() {
if (this.addonManagerStarted) {
return;
}
this.addonManagerStarted = true;
-
- let appInfo = {};
- Cu.import("resource://testing-common/AppInfo.jsm", appInfo);
-
- appInfo.updateAppInfo({
- ID: "xpcshell@tests.mozilla.org",
- name: "XPCShell",
- version: "48",
- platformVersion: "48",
- });
-
+ this.mockAppInfo();
let manager = Cc["@mozilla.org/addons/integration;1"].getService(Ci.nsIObserver)
.QueryInterface(Ci.nsITimerCallback);
manager.observe(null, "addons-startup", null);
},
loadExtension(data) {
let extension = Extension.generate(data);
--- a/toolkit/components/extensions/ext-runtime.js
+++ b/toolkit/components/extensions/ext-runtime.js
@@ -71,16 +71,22 @@ extensions.registerSchemaAPI("runtime",
get lastError() {
// TODO(robwu): Figure out how to make sure that errors in the parent
// process are propagated to the child process.
// lastError should not be accessed from the parent.
return context.lastError;
},
+ getBrowserInfo: function() {
+ const {name, vendor, version, appBuildID} = Services.appinfo;
+ const info = {name, vendor, version, buildID: appBuildID};
+ return Promise.resolve(info);
+ },
+
getPlatformInfo: function() {
return Promise.resolve(ExtensionUtils.PlatformInfo);
},
openOptionsPage: function() {
if (!extension.manifest.options_ui) {
return Promise.reject({message: "No `options_ui` declared"});
}
--- a/toolkit/components/extensions/schemas/runtime.json
+++ b/toolkit/components/extensions/schemas/runtime.json
@@ -85,16 +85,39 @@
"nacl_arch" : {
"unsupported": true,
"description": "The native client architecture. This may be different from arch on some platforms.",
"$ref": "PlatformNaclArch"
}
}
},
{
+ "id": "BrowserInfo",
+ "type": "object",
+ "description": "An object containing information about the current browser.",
+ "properties": {
+ "name": {
+ "type": "string",
+ "description": "The name of the browser, for example 'Firefox'."
+ },
+ "vendor": {
+ "type": "string",
+ "description": "The name of the browser vendor, for example 'Mozilla'."
+ },
+ "version": {
+ "type": "string",
+ "description": "The browser's version, for example '42.0.0' or '0.8.1pre'."
+ },
+ "buildID": {
+ "type": "string",
+ "description": "The browser's build ID/date, for example '20160101'."
+ }
+ }
+ },
+ {
"id": "RequestUpdateCheckStatus",
"type": "string",
"enum": ["throttled", "no_update", "update_available"],
"restrictions": ["content"],
"description": "Result of the update check."
},
{
"id": "OnInstalledReason",
@@ -363,16 +386,35 @@
"type": "any",
"description": "The response message sent by the native messaging host. If an error occurs while connecting to the native messaging host, the callback will be called with no arguments and $(ref:runtime.lastError) will be set to the error message."
}
]
}
]
},
{
+ "name": "getBrowserInfo",
+ "type": "function",
+ "description": "Returns information about the current browser.",
+ "async": "callback",
+ "parameters": [
+ {
+ "type": "function",
+ "name": "callback",
+ "description": "Called with results",
+ "parameters": [
+ {
+ "name": "browserInfo",
+ "$ref": "BrowserInfo"
+ }
+ ]
+ }
+ ]
+ },
+ {
"name": "getPlatformInfo",
"type": "function",
"description": "Returns information about the current platform.",
"async": "callback",
"parameters": [
{
"type": "function",
"name": "callback",
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_runtime_getBrowserInfo.js
@@ -0,0 +1,26 @@
+/* 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/. */
+"use strict";
+
+add_task(function* setup() {
+ ExtensionTestUtils.mockAppInfo();
+});
+
+add_task(function* test_getBrowserInfo() {
+ function background() {
+ browser.runtime.getBrowserInfo().then(info => {
+ browser.test.assertEq(info.name, "XPCShell", "name is valid");
+ browser.test.assertEq(info.vendor, "Mozilla", "vendor is Mozilla");
+ browser.test.assertEq(info.version, "48", "version is correct");
+ browser.test.assertEq(info.buildID, "20160315", "buildID is correct");
+
+ browser.test.notifyPass("runtime.getBrowserInfo");
+ });
+ }
+
+ const extension = ExtensionTestUtils.loadExtension({background});
+ yield extension.startup();
+ yield extension.awaitFinish("runtime.getBrowserInfo");
+ yield extension.unload();
+});
--- a/toolkit/components/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell.ini
@@ -38,16 +38,17 @@ skip-if = release_build
[test_ext_json_parser.js]
[test_ext_localStorage.js]
[test_ext_management.js]
[test_ext_manifest_content_security_policy.js]
[test_ext_manifest_incognito.js]
[test_ext_manifest_minimum_chrome_version.js]
[test_ext_onmessage_removelistener.js]
[test_ext_runtime_connect_no_receiver.js]
+[test_ext_runtime_getBrowserInfo.js]
[test_ext_runtime_getPlatformInfo.js]
[test_ext_runtime_sendMessage.js]
[test_ext_runtime_sendMessage_errors.js]
[test_ext_runtime_sendMessage_no_receiver.js]
[test_ext_runtime_sendMessage_self.js]
[test_ext_schemas.js]
[test_ext_schemas_api_injection.js]
[test_ext_schemas_restrictions.js]