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

MozReview-Commit-ID: 4jlz9gdUuQd

--HG--
extra : transplant_source : %7B%96%12%EB%DF%FCvgv%25%15%EA1Z%E9%5BN%0FM%99
This commit is contained in:
Matthew Wein 2016-09-13 11:13:40 -07:00
Родитель f11090bde3
Коммит 00866fea33
4 изменённых файлов: 40 добавлений и 25 удалений

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

@ -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>

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

@ -54,7 +54,12 @@ add_task(function* test_contentscript() {
browser.test.sendMessage("page-action-onClicked-fired");
});
browser.test.sendMessage("ready");
let extensionInfo = {
// Extract the assigned uuid from the background page url.
uuid: `{${window.location.hostname}}`,
};
browser.test.sendMessage("ready", extensionInfo);
}
function popupScript() {
@ -107,7 +112,7 @@ add_task(function* test_contentscript() {
});
};
function* testPopup(name) {
function* testPopup(name, uuid) {
// We don't need to set the popup when testing default_popup.
if (name != "default.html") {
extension.sendMessage("page-action-set-popup", {name});
@ -124,7 +129,7 @@ add_task(function* test_contentscript() {
extension.sendMessage("page-action-enable-onClicked-listener");
yield extension.awaitMessage("page-action-onClicked-listener-enabled");
clickPageAction(extension.id);
clickPageAction(uuid);
yield extension.awaitMessage("page-action-onClicked-fired");
extension.sendMessage("page-action-disable-onClicked-listener");
@ -132,7 +137,7 @@ add_task(function* test_contentscript() {
} else {
ok(url.includes(name), "Calling pageAction.getPopup should return the correct popup URL when the popup is set.");
clickPageAction(extension.id);
clickPageAction(uuid);
let location = yield extension.awaitMessage("page-action-from-popup");
ok(location.includes(name), "The popup with the correct URL should be shown.");
@ -144,19 +149,19 @@ add_task(function* test_contentscript() {
}
yield extension.startup();
yield extension.awaitMessage("ready");
let {uuid} = yield extension.awaitMessage("ready");
extension.sendMessage("page-action-show");
yield extension.awaitMessage("page-action-shown");
ok(isPageActionShown(extension.id), "The PageAction should be shown.");
ok(isPageActionShown(uuid), "The PageAction should be shown.");
yield testPopup("default.html");
yield testPopup("a.html");
yield testPopup("");
yield testPopup("b.html");
yield testPopup("default.html", uuid);
yield testPopup("a.html", uuid);
yield testPopup("", uuid);
yield testPopup("b.html", uuid);
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>