Bug 1417273. Use PageAction.setDisabled to enable/disable Report Site Issue button. r=adw
MozReview-Commit-ID: LPGtI3Qyv1k
--- a/browser/extensions/webcompat-reporter/content/WebCompatReporter.jsm
+++ b/browser/extensions/webcompat-reporter/content/WebCompatReporter.jsm
@@ -27,33 +27,30 @@ let WebCompatReporter = {
init() {
PageActions.addAction(new PageActions.Action({
id: "webcompat-reporter-button",
title: wcStrings.GetStringFromName("wc-reporter.label2"),
iconURL: "chrome://webcompat-reporter/skin/lightbulb.svg",
labelForHistogram: "webcompat",
onCommand: (e) => this.reportIssue(e.target.ownerGlobal),
- onShowingInPanel: (buttonNode) => this.onShowingInPanel(buttonNode)
+ onLocationChange: (window) => this.onLocationChange(window)
}));
},
uninit() {
let action = PageActions.actionForID("webcompat-reporter-button");
action.remove();
},
- onShowingInPanel(buttonNode) {
- let browser = buttonNode.ownerGlobal.gBrowser;
- let scheme = browser.currentURI.scheme;
- if (["http", "https"].includes(scheme)) {
- buttonNode.removeAttribute("disabled");
- } else {
- buttonNode.setAttribute("disabled", "true");
- }
+ onLocationChange(window) {
+ let action = PageActions.actionForID("webcompat-reporter-button");
+ let scheme = window.gBrowser.currentURI.scheme;
+ let isReportable = ["http", "https"].includes(scheme);
+ action.setDisabled(!isReportable, window);
},
// This method injects a framescript that should send back a screenshot blob
// of the top-level window of the currently selected tab, resolved as a
// Promise.
getScreenshot(gBrowser) {
const FRAMESCRIPT = "chrome://webcompat-reporter/content/tab-frame.js";
const TABDATA_MESSAGE = "WebCompat:SendTabData";
--- a/browser/extensions/webcompat-reporter/test/browser/browser_button_state.js
+++ b/browser/extensions/webcompat-reporter/test/browser/browser_button_state.js
@@ -19,8 +19,27 @@ add_task(async function test_button_stat
openPageActions();
await BrowserTestUtils.waitForEvent(BrowserPageActions.panelNode, "popupshown");
is(isButtonDisabled(), false, "Check that button is enabled for reportable schemes on tab load");
await BrowserTestUtils.removeTab(tab1);
await BrowserTestUtils.removeTab(tab2);
await BrowserTestUtils.removeTab(tab3);
});
+
+/* Test that the button is enabled or disabled when we expected it to be, when
+ pinned to the URL bar. */
+add_task(async function test_button_state_in_urlbar() {
+ pinToURLBar();
+ let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, REPORTABLE_PAGE);
+ is(isURLButtonEnabled(), true, "Check that button (in urlbar) is enabled for reportable schemes on tab load");
+
+ let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, NONREPORTABLE_PAGE);
+ is(isURLButtonEnabled(), false, "Check that button (in urlbar) is hidden for non-reportable schemes on tab load");
+
+ let tab3 = await BrowserTestUtils.openNewForegroundTab(gBrowser, REPORTABLE_PAGE2);
+ is(isURLButtonEnabled(), true, "Check that button (in urlbar) is enabled for reportable schemes on tab load");
+
+ unpinFromURLBar();
+ await BrowserTestUtils.removeTab(tab1);
+ await BrowserTestUtils.removeTab(tab2);
+ await BrowserTestUtils.removeTab(tab3);
+});
--- a/browser/extensions/webcompat-reporter/test/browser/head.js
+++ b/browser/extensions/webcompat-reporter/test/browser/head.js
@@ -1,17 +1,30 @@
const PREF_WC_REPORTER_ENABLED = "extensions.webcompat-reporter.enabled";
const PREF_WC_REPORTER_ENDPOINT = "extensions.webcompat-reporter.newIssueEndpoint";
const TEST_ROOT = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");
const TEST_PAGE = TEST_ROOT + "test.html";
const NEW_ISSUE_PAGE = TEST_ROOT + "webcompat.html";
const WC_PAGE_ACTION_ID = "pageAction-panel-webcompat-reporter-button";
+const WC_PAGE_ACTION_URLBAR_ID = "pageAction-urlbar-webcompat-reporter-button";
function isButtonDisabled() {
return document.getElementById(WC_PAGE_ACTION_ID).disabled;
}
+function isURLButtonEnabled() {
+ return document.getElementById(WC_PAGE_ACTION_URLBAR_ID) !== null;
+}
+
function openPageActions() {
var event = new MouseEvent("click");
BrowserPageActions.mainButtonClicked(event);
}
+
+function pinToURLBar() {
+ PageActions.actionForID("webcompat-reporter-button").pinnedToUrlbar = true;
+}
+
+function unpinFromURLBar() {
+ PageActions.actionForID("webcompat-reporter-button").pinnedToUrlbar = false;
+}