зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1313459 support CUI areas for browserAction, r=aswan
MozReview-Commit-ID: IoPOCv6M0qy --HG-- extra : rebase_source : 501d3bd94c7f2859c8c5b3b05667cdb35a679b62
This commit is contained in:
Родитель
970ca57ee7
Коммит
a226f9e310
|
@ -38,7 +38,14 @@ function isAncestorOrSelf(target, node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WeakMap[Extension -> BrowserAction]
|
// WeakMap[Extension -> BrowserAction]
|
||||||
var browserActionMap = new WeakMap();
|
const browserActionMap = new WeakMap();
|
||||||
|
|
||||||
|
const browserAreas = {
|
||||||
|
"navbar": CustomizableUI.AREA_NAVBAR,
|
||||||
|
"menupanel": CustomizableUI.AREA_PANEL,
|
||||||
|
"tabstrip": CustomizableUI.AREA_TABSTRIP,
|
||||||
|
"personaltoolbar": CustomizableUI.AREA_BOOKMARKS,
|
||||||
|
};
|
||||||
|
|
||||||
// Responsible for the browser_action section of the manifest as well
|
// Responsible for the browser_action section of the manifest as well
|
||||||
// as the associated popup.
|
// as the associated popup.
|
||||||
|
@ -62,6 +69,7 @@ function BrowserAction(options, extension) {
|
||||||
badgeBackgroundColor: null,
|
badgeBackgroundColor: null,
|
||||||
icon: IconDetails.normalize({path: options.default_icon}, extension),
|
icon: IconDetails.normalize({path: options.default_icon}, extension),
|
||||||
popup: options.default_popup || "",
|
popup: options.default_popup || "",
|
||||||
|
area: browserAreas[options.default_area || "navbar"],
|
||||||
};
|
};
|
||||||
|
|
||||||
this.browserStyle = options.browser_style || false;
|
this.browserStyle = options.browser_style || false;
|
||||||
|
@ -85,7 +93,7 @@ BrowserAction.prototype = {
|
||||||
removable: true,
|
removable: true,
|
||||||
label: this.defaults.title || this.extension.name,
|
label: this.defaults.title || this.extension.name,
|
||||||
tooltiptext: this.defaults.title || "",
|
tooltiptext: this.defaults.title || "",
|
||||||
defaultArea: CustomizableUI.AREA_NAVBAR,
|
defaultArea: this.defaults.area,
|
||||||
|
|
||||||
onBeforeCreated: document => {
|
onBeforeCreated: document => {
|
||||||
let view = document.createElementNS(XUL_NS, "panelview");
|
let view = document.createElementNS(XUL_NS, "panelview");
|
||||||
|
|
|
@ -31,6 +31,12 @@
|
||||||
"browser_style": {
|
"browser_style": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"optional": true
|
"optional": true
|
||||||
|
},
|
||||||
|
"default_area": {
|
||||||
|
"description": "Defines the location the browserAction will appear by default. The default location is navbar.",
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["navbar", "menupanel", "tabstrip", "personaltoolbar"],
|
||||||
|
"optional": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"optional": true
|
"optional": true
|
||||||
|
|
|
@ -24,6 +24,7 @@ support-files =
|
||||||
searchSuggestionEngine.sjs
|
searchSuggestionEngine.sjs
|
||||||
../../../../../toolkit/components/extensions/test/mochitest/head_webrequest.js
|
../../../../../toolkit/components/extensions/test/mochitest/head_webrequest.js
|
||||||
|
|
||||||
|
[browser_ext_browserAction_area.js]
|
||||||
[browser_ext_browserAction_context.js]
|
[browser_ext_browserAction_context.js]
|
||||||
[browser_ext_browserAction_disabled.js]
|
[browser_ext_browserAction_disabled.js]
|
||||||
[browser_ext_browserAction_pageAction_icon.js]
|
[browser_ext_browserAction_pageAction_icon.js]
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||||
|
/* vim: set sts=2 sw=2 et tw=80: */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var browserAreas = {
|
||||||
|
"navbar": CustomizableUI.AREA_NAVBAR,
|
||||||
|
"menupanel": CustomizableUI.AREA_PANEL,
|
||||||
|
"tabstrip": CustomizableUI.AREA_TABSTRIP,
|
||||||
|
"personaltoolbar": CustomizableUI.AREA_BOOKMARKS,
|
||||||
|
};
|
||||||
|
|
||||||
|
function* testInArea(area) {
|
||||||
|
let manifest = {
|
||||||
|
"browser_action": {
|
||||||
|
"default_popup": "popup.html",
|
||||||
|
"browser_style": true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (area) {
|
||||||
|
manifest.browser_action.default_area = area;
|
||||||
|
}
|
||||||
|
let extension = ExtensionTestUtils.loadExtension({
|
||||||
|
manifest,
|
||||||
|
files: {
|
||||||
|
"popup.html": `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html><head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<script src="popup.js"></script>
|
||||||
|
</head><body>
|
||||||
|
</body></html>
|
||||||
|
`,
|
||||||
|
|
||||||
|
"popup.js": function() {
|
||||||
|
window.onload = () => {
|
||||||
|
browser.test.sendMessage("from-popup");
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
yield extension.startup();
|
||||||
|
let widget = getBrowserActionWidget(extension);
|
||||||
|
let placement = CustomizableUI.getPlacementOfWidget(widget.id);
|
||||||
|
is(placement && placement.area, browserAreas[area || "navbar"], `widget located in correct area`);
|
||||||
|
|
||||||
|
clickBrowserAction(extension);
|
||||||
|
|
||||||
|
yield extension.awaitMessage("from-popup");
|
||||||
|
|
||||||
|
yield extension.unload();
|
||||||
|
}
|
||||||
|
|
||||||
|
add_task(function* testBrowserActionDefaultArea() {
|
||||||
|
yield testInArea();
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(function* testBrowserActionInToolbar() {
|
||||||
|
yield testInArea("navbar");
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(function* testBrowserActionInMenuPanel() {
|
||||||
|
yield testInArea("menupanel");
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(function* testBrowserActionInTabStrip() {
|
||||||
|
yield testInArea("tabstrip");
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(function* testBrowserActionInPersonalToolbar() {
|
||||||
|
CustomizableUI.setToolbarVisibility("PersonalToolbar", true);
|
||||||
|
yield testInArea("personaltoolbar");
|
||||||
|
CustomizableUI.setToolbarVisibility("PersonalToolbar", false);
|
||||||
|
});
|
Загрузка…
Ссылка в новой задаче