mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 08:45:46 +00:00
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:
parent
f11090bde3
commit
00866fea33
@ -32,7 +32,7 @@ function PageAction(options, extension) {
|
|||||||
|
|
||||||
this.options = {
|
this.options = {
|
||||||
title: options.default_title || extension.name,
|
title: options.default_title || extension.name,
|
||||||
id: extension.id,
|
id: `{${extension.uuid}}`,
|
||||||
clickCallback: () => {
|
clickCallback: () => {
|
||||||
if (this.popupUrl) {
|
if (this.popupUrl) {
|
||||||
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
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");
|
Cu.import("resource://gre/modules/PageActions.jsm");
|
||||||
|
|
||||||
function isPageActionShown(extensionId) {
|
function isPageActionShown(uuid) {
|
||||||
return PageActions.isShown(extensionId);
|
return PageActions.isShown(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
function clickPageAction(extensionId) {
|
function clickPageAction(uuid) {
|
||||||
PageActions.synthesizeClick(extensionId);
|
PageActions.synthesizeClick(uuid);
|
||||||
}
|
}
|
||||||
|
@ -41,10 +41,15 @@ function background() {
|
|||||||
browser.test.sendMessage("page-action-clicked");
|
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({
|
let extension = ExtensionTestUtils.loadExtension({
|
||||||
background,
|
background,
|
||||||
manifest: {
|
manifest: {
|
||||||
@ -55,6 +60,11 @@ add_task(function* test_contentscript() {
|
|||||||
"18": "extension.png",
|
"18": "extension.png",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"applications": {
|
||||||
|
"gecko": {
|
||||||
|
"id": "foo@bar.com",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
files: {
|
files: {
|
||||||
"extension.png": IMAGE_ARRAYBUFFER,
|
"extension.png": IMAGE_ARRAYBUFFER,
|
||||||
@ -62,26 +72,26 @@ add_task(function* test_contentscript() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
yield extension.startup();
|
yield extension.startup();
|
||||||
yield extension.awaitMessage("ready");
|
let {uuid} = yield extension.awaitMessage("ready");
|
||||||
|
|
||||||
extension.sendMessage("pageAction-show");
|
extension.sendMessage("pageAction-show");
|
||||||
yield extension.awaitMessage("page-action-shown");
|
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");
|
extension.sendMessage("pageAction-hide");
|
||||||
yield extension.awaitMessage("page-action-hidden");
|
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");
|
extension.sendMessage("pageAction-show");
|
||||||
yield extension.awaitMessage("page-action-shown");
|
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");
|
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();
|
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>
|
</script>
|
||||||
|
|
||||||
|
@ -54,7 +54,12 @@ add_task(function* test_contentscript() {
|
|||||||
browser.test.sendMessage("page-action-onClicked-fired");
|
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() {
|
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.
|
// We don't need to set the popup when testing default_popup.
|
||||||
if (name != "default.html") {
|
if (name != "default.html") {
|
||||||
extension.sendMessage("page-action-set-popup", {name});
|
extension.sendMessage("page-action-set-popup", {name});
|
||||||
@ -124,7 +129,7 @@ add_task(function* test_contentscript() {
|
|||||||
extension.sendMessage("page-action-enable-onClicked-listener");
|
extension.sendMessage("page-action-enable-onClicked-listener");
|
||||||
yield extension.awaitMessage("page-action-onClicked-listener-enabled");
|
yield extension.awaitMessage("page-action-onClicked-listener-enabled");
|
||||||
|
|
||||||
clickPageAction(extension.id);
|
clickPageAction(uuid);
|
||||||
yield extension.awaitMessage("page-action-onClicked-fired");
|
yield extension.awaitMessage("page-action-onClicked-fired");
|
||||||
|
|
||||||
extension.sendMessage("page-action-disable-onClicked-listener");
|
extension.sendMessage("page-action-disable-onClicked-listener");
|
||||||
@ -132,7 +137,7 @@ add_task(function* test_contentscript() {
|
|||||||
} else {
|
} else {
|
||||||
ok(url.includes(name), "Calling pageAction.getPopup should return the correct popup URL when the popup is set.");
|
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");
|
let location = yield extension.awaitMessage("page-action-from-popup");
|
||||||
ok(location.includes(name), "The popup with the correct URL should be shown.");
|
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.startup();
|
||||||
yield extension.awaitMessage("ready");
|
let {uuid} = yield extension.awaitMessage("ready");
|
||||||
|
|
||||||
extension.sendMessage("page-action-show");
|
extension.sendMessage("page-action-show");
|
||||||
yield extension.awaitMessage("page-action-shown");
|
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("default.html", uuid);
|
||||||
yield testPopup("a.html");
|
yield testPopup("a.html", uuid);
|
||||||
yield testPopup("");
|
yield testPopup("", uuid);
|
||||||
yield testPopup("b.html");
|
yield testPopup("b.html", uuid);
|
||||||
|
|
||||||
yield extension.unload();
|
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>
|
</script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user