Bug 1373650. Update Report Site Issue button tests. r=gijs draft
authorMike Taylor <miket@mozilla.com>
Thu, 03 Aug 2017 15:35:21 -0500
changeset 620762 aa59366e04285861ca92df7245748afd7cd6364c
parent 620761 5fa6caeaedc83b79eb95add7837503c53f1b4b4c
child 620763 0c3a8cce555ecbe06db471c86b7a2775dc283d0c
push id72142
push userbmo:miket@mozilla.com
push dateThu, 03 Aug 2017 21:26:11 +0000
reviewersgijs
bugs1373650
milestone57.0a1
Bug 1373650. Update Report Site Issue button tests. r=gijs MozReview-Commit-ID: IFNvarOrYtc
browser/extensions/webcompat-reporter/test/browser/browser_button_state.js
browser/extensions/webcompat-reporter/test/browser/browser_report_site_issue.js
browser/extensions/webcompat-reporter/test/browser/head.js
--- a/browser/extensions/webcompat-reporter/test/browser/browser_button_state.js
+++ b/browser/extensions/webcompat-reporter/test/browser/browser_button_state.js
@@ -1,29 +1,23 @@
 const REPORTABLE_PAGE = "http://example.com/";
 const REPORTABLE_PAGE2 = "https://example.com/";
 const NONREPORTABLE_PAGE = "about:blank";
 
 /* Test that the Report Site Issue button is enabled for http and https tabs,
    on page load, or TabSelect, and disabled for everything else. */
 add_task(async function test_button_state_disabled() {
-  CustomizableUI.addWidgetToArea("webcompat-reporter-button", "nav-bar");
   let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, REPORTABLE_PAGE);
+  openPageActions();
   is(isButtonDisabled(), false, "Check that button is enabled for reportable schemes on tab load");
 
   let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, NONREPORTABLE_PAGE);
+  openPageActions();
   is(isButtonDisabled(), true, "Check that button is disabled for non-reportable schemes on tab load");
 
   let tab3 = await BrowserTestUtils.openNewForegroundTab(gBrowser, REPORTABLE_PAGE2);
+  openPageActions();
   is(isButtonDisabled(), false, "Check that button is enabled for reportable schemes on tab load");
 
-
-  await BrowserTestUtils.switchTab(gBrowser, tab2);
-  is(isButtonDisabled(), true, "Check that button is disabled for non-reportable schemes on TabSelect");
-
-  await BrowserTestUtils.switchTab(gBrowser, tab1);
-  is(isButtonDisabled(), false, "Check that button is enabled for reportable schemes on TabSelect");
-
-  CustomizableUI.reset();
   await BrowserTestUtils.removeTab(tab1);
   await BrowserTestUtils.removeTab(tab2);
   await BrowserTestUtils.removeTab(tab3);
 });
--- a/browser/extensions/webcompat-reporter/test/browser/browser_report_site_issue.js
+++ b/browser/extensions/webcompat-reporter/test/browser/browser_report_site_issue.js
@@ -1,23 +1,23 @@
 /* Test that clicking on the Report Site Issue button opens a new tab
    and sends a postMessaged blob to it. */
 add_task(async function test_screenshot() {
-  CustomizableUI.addWidgetToArea("webcompat-reporter-button", "nav-bar");
   requestLongerTimeout(2);
 
   // ./head.js sets the value for PREF_WC_REPORTER_ENDPOINT
   await SpecialPowers.pushPrefEnv({set: [[PREF_WC_REPORTER_ENDPOINT, NEW_ISSUE_PAGE]]});
 
   let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE);
 
-  let webcompatButton = document.getElementById("webcompat-reporter-button");
+  let webcompatButton = document.getElementById(WC_PAGE_ACTION_ID);
   ok(webcompatButton, "Report Site Issue button exists.");
 
   let newTabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
+  openPageActions();
   webcompatButton.click();
   let tab2 = await newTabPromise;
 
   await BrowserTestUtils.waitForContentEvent(tab2.linkedBrowser, "ScreenshotReceived", false, null, true);
 
   await ContentTask.spawn(tab2.linkedBrowser, {TEST_PAGE}, function(args) {
     let doc = content.document;
     let urlParam = doc.getElementById("url").innerText;
@@ -25,10 +25,9 @@ add_task(async function test_screenshot(
     is(urlParam, args.TEST_PAGE, "Reported page is correctly added to the url param");
 
     is(preview.innerText, "Pass", "A Blob object was successfully transferred to the test page.")
     ok(preview.style.backgroundImage.startsWith("url(\"data:image/png;base64,iVBOR"), "A green screenshot was successfully postMessaged");
   });
 
   await BrowserTestUtils.removeTab(tab2);
   await BrowserTestUtils.removeTab(tab1);
-  CustomizableUI.reset();
 });
--- a/browser/extensions/webcompat-reporter/test/browser/head.js
+++ b/browser/extensions/webcompat-reporter/test/browser/head.js
@@ -1,10 +1,17 @@
 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";
+
 function isButtonDisabled() {
-  return document.getElementById("webcompat-reporter-button").disabled;
+  return document.getElementById(WC_PAGE_ACTION_ID).disabled;
 }
+
+function openPageActions() {
+  var event = new MouseEvent("click");
+  BrowserPageActions.mainButtonClicked(event);
+}