Bug 1300807 - Switch to using a uuid for the PageAction ID. r=kmag

MozReview-Commit-ID: 4jlz9gdUuQd

--HG--
extra : rebase_source : e264242501856f7859dd5ca85bc81093d7929a25
This commit is contained in:
Matthew Wein 2016-09-13 11:13:40 -07:00
Родитель 679d4fcd37
Коммит 7c9e612290
3 изменённых файлов: 24 добавлений и 14 удалений

Просмотреть файл

@ -32,7 +32,7 @@ function PageAction(options, extension) {
this.options = {
title: options.default_title || extension.name,
id: extension.id,
id: `{${extension.uuid}}`,
clickCallback: () => {
if (this.popupUrl) {
let win = Services.wm.getMostRecentWindow("navigator:browser");

Просмотреть файл

@ -6,10 +6,10 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/PageActions.jsm");
function isPageActionShown(extensionId) {
return PageActions.isShown(extensionId);
function isPageActionShown(uuid) {
return PageActions.isShown(uuid);
}
function clickPageAction(extensionId) {
PageActions.synthesizeClick(extensionId);
function clickPageAction(uuid) {
PageActions.synthesizeClick(uuid);
}

Просмотреть файл

@ -41,10 +41,15 @@ function background() {
browser.test.sendMessage("page-action-clicked");
});
browser.test.sendMessage("ready");
let extensionInfo = {
// Extract the assigned uuid from the background page url.
uuid: `{${window.location.hostname}}`,
};
browser.test.sendMessage("ready", extensionInfo);
}
add_task(function* test_contentscript() {
add_task(function* test_pageAction() {
let extension = ExtensionTestUtils.loadExtension({
background,
manifest: {
@ -55,6 +60,11 @@ add_task(function* test_contentscript() {
"18": "extension.png",
},
},
"applications": {
"gecko": {
"id": "foo@bar.com",
}
},
},
files: {
"extension.png": IMAGE_ARRAYBUFFER,
@ -62,26 +72,26 @@ add_task(function* test_contentscript() {
});
yield extension.startup();
yield extension.awaitMessage("ready");
let {uuid} = yield extension.awaitMessage("ready");
extension.sendMessage("pageAction-show");
yield extension.awaitMessage("page-action-shown");
ok(isPageActionShown(extension.id), "The PageAction should be shown");
ok(isPageActionShown(uuid), "The PageAction should be shown");
extension.sendMessage("pageAction-hide");
yield extension.awaitMessage("page-action-hidden");
ok(!isPageActionShown(extension.id), "The PageAction should be hidden");
ok(!isPageActionShown(uuid), "The PageAction should be hidden");
extension.sendMessage("pageAction-show");
yield extension.awaitMessage("page-action-shown");
ok(isPageActionShown(extension.id), "The PageAction should be shown");
ok(isPageActionShown(uuid), "The PageAction should be shown");
clickPageAction(extension.id);
clickPageAction(uuid);
yield extension.awaitMessage("page-action-clicked");
ok(isPageActionShown(extension.id), "The PageAction should still be shown after being clicked");
ok(isPageActionShown(uuid), "The PageAction should still be shown after being clicked");
yield extension.unload();
ok(!isPageActionShown(extension.id), "The PageAction should be removed after unload");
ok(!isPageActionShown(uuid), "The PageAction should be removed after unload");
});
</script>