mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-13 20:14:57 -10:00
Bug 1494135 add pinned option to page_action manifest, r=aswan
Differential Revision: https://phabricator.services.mozilla.com/D7098
This commit is contained in:
1 parent
3dbeb8fd13
commit
13261826f5
4 files changed
+62
-5
No files matched your search
@@ -65,6 +65,7 @@ this.pageAction = class extends ExtensionAPI {
|
||||
hideMatches,
|
||||
title: options.default_title || extension.name,
|
||||
popup: options.default_popup || "",
|
||||
pinned: options.pinned,
|
||||
};
|
||||
|
||||
this.browserStyle = options.browser_style;
|
||||
@@ -87,7 +88,7 @@ this.pageAction = class extends ExtensionAPI {
|
||||
extensionID: extension.id,
|
||||
title: this.defaults.title,
|
||||
iconURL: this.defaults.icon,
|
||||
pinnedToUrlbar: true,
|
||||
pinnedToUrlbar: this.defaults.pinned,
|
||||
disabled: !this.defaults.show,
|
||||
onCommand: (event, buttonNode) => {
|
||||
this.handleClick(event.target.ownerGlobal);
|
||||
|
||||
@@ -44,6 +44,11 @@
|
||||
"optional": true,
|
||||
"minItems": 1,
|
||||
"items": { "$ref": "MatchPatternRestricted" }
|
||||
},
|
||||
"pinned": {
|
||||
"type": "boolean",
|
||||
"optional": true,
|
||||
"default": true
|
||||
}
|
||||
},
|
||||
"optional": true
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
/* vim: set sts=2 sw=2 et tw=80: */
|
||||
"use strict";
|
||||
|
||||
ChromeUtils.import("resource:///modules/PageActions.jsm");
|
||||
|
||||
add_task(async function test_pageAction_basic() {
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
@@ -49,6 +51,10 @@ add_task(async function test_pageAction_basic() {
|
||||
await extension.startup();
|
||||
await extension.awaitMessage("page-action-shown");
|
||||
|
||||
let elem = await getPageActionButton(extension);
|
||||
let parent = window.document.getElementById("page-action-buttons");
|
||||
is(elem && elem.parentNode, parent, `pageAction pinned to urlbar ${elem.parentNode.getAttribute("id")}`);
|
||||
|
||||
clickPageAction(extension);
|
||||
|
||||
await extension.awaitMessage("popup");
|
||||
@@ -58,3 +64,45 @@ add_task(async function test_pageAction_basic() {
|
||||
SimpleTest.endMonitorConsole();
|
||||
await waitForConsole;
|
||||
});
|
||||
|
||||
add_task(async function test_pageAction_pinned() {
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
"page_action": {
|
||||
"default_popup": "popup.html",
|
||||
"pinned": false,
|
||||
},
|
||||
},
|
||||
|
||||
files: {
|
||||
"popup.html": `
|
||||
<!DOCTYPE html>
|
||||
<html><body>
|
||||
</body></html>
|
||||
`,
|
||||
},
|
||||
|
||||
background: function() {
|
||||
browser.tabs.query({active: true, currentWindow: true}, tabs => {
|
||||
let tabId = tabs[0].id;
|
||||
|
||||
browser.pageAction.show(tabId).then(() => {
|
||||
browser.test.sendMessage("page-action-shown");
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
await extension.startup();
|
||||
await extension.awaitMessage("page-action-shown");
|
||||
|
||||
let elem = await getPageActionButton(extension);
|
||||
is(elem && elem.parentNode, null, "pageAction is not pinned to urlbar");
|
||||
|
||||
// There are plenty of tests for the main action button, we just verify
|
||||
// that we've properly set the pinned value to false.
|
||||
let action = PageActions.actionForID(makeWidgetId(extension.id));
|
||||
ok(action && !action.pinnedToUrlbar, "pageAction is in main pageaction menu");
|
||||
|
||||
await extension.unload();
|
||||
});
|
||||
@@ -5,7 +5,7 @@
|
||||
/* exported CustomizableUI makeWidgetId focusWindow forceGC
|
||||
* getBrowserActionWidget
|
||||
* clickBrowserAction clickPageAction
|
||||
* getBrowserActionPopup getPageActionPopup
|
||||
* getBrowserActionPopup getPageActionPopup getPageActionButton
|
||||
* closeBrowserAction closePageAction
|
||||
* promisePopupShown promisePopupHidden
|
||||
* openContextMenu closeContextMenu
|
||||
@@ -417,7 +417,7 @@ function closeChromeContextMenu(menuId, itemToSelect, win = window) {
|
||||
}
|
||||
|
||||
async function openActionContextMenu(extension, kind, win = window) {
|
||||
// See comment from clickPageAction below.
|
||||
// See comment from getPageActionButton below.
|
||||
SetPageProxyState("valid");
|
||||
await promiseAnimationFrame(win);
|
||||
let buttonID;
|
||||
@@ -450,7 +450,7 @@ function getPageActionPopup(extension, win = window) {
|
||||
return win.document.getElementById(panelId);
|
||||
}
|
||||
|
||||
async function clickPageAction(extension, win = window) {
|
||||
async function getPageActionButton(extension, win = window) {
|
||||
// This would normally be set automatically on navigation, and cleared
|
||||
// when the user types a value into the URL bar, to show and hide page
|
||||
// identity info and icons such as page action buttons.
|
||||
@@ -463,8 +463,11 @@ async function clickPageAction(extension, win = window) {
|
||||
|
||||
let pageActionId = BrowserPageActions.urlbarButtonNodeIDForActionID(makeWidgetId(extension.id));
|
||||
|
||||
let elem = win.document.getElementById(pageActionId);
|
||||
return win.document.getElementById(pageActionId);
|
||||
}
|
||||
|
||||
async function clickPageAction(extension, win = window) {
|
||||
let elem = await getPageActionButton(extension, win);
|
||||
EventUtils.synthesizeMouseAtCenter(elem, {}, win);
|
||||
return new Promise(SimpleTest.executeSoon);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user