Bug 1141041 - Add test to ensure that updating the Page Style menu works. r=jaws
authorMike Conley <mconley@mozilla.com>
Thu, 08 Oct 2015 17:09:43 -0400
changeset 300285 5916ad1372e7c564aa7fbf67ccb895bc4953b6eb
parent 300284 2e89754057bc81a916239a3d6342993bf453be1e
child 300286 84b20f66736b3959eb146286ea5a96bdb7c57b8e
push id6290
push usermstange@themasta.com
push dateMon, 12 Oct 2015 15:01:35 +0000
reviewersjaws
bugs1141041
milestone44.0a1
Bug 1141041 - Add test to ensure that updating the Page Style menu works. r=jaws
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_page_style_menu_update.js
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -340,16 +340,17 @@ skip-if = e10s # Bug 1100664 - test dire
 [browser_mixedcontent_securityflags.js]
 tags = mcb
 [browser_offlineQuotaNotification.js]
 skip-if = buildapp == 'mulet' || e10s # Bug 1093603 - test breaks with PopupNotifications.panel.firstElementChild is null
 [browser_overflowScroll.js]
 [browser_pageInfo.js]
 skip-if = buildapp == 'mulet'
 [browser_page_style_menu.js]
+[browser_page_style_menu_update.js]
 [browser_parsable_css.js]
 [browser_parsable_script.js]
 skip-if = asan || (os == 'linux' && !debug && (bits == 32)) # disabled on asan because of timeouts, and bug 1172468 for the linux 32-bit pgo issue.
 [browser_permissions.js]
 support-files =
   permissions.html
 [browser_pinnedTabs.js]
 [browser_plainTextLinks.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_page_style_menu_update.js
@@ -0,0 +1,68 @@
+"use strict";
+
+const PAGE = "http://example.com/browser/browser/base/content/test/general/page_style_sample.html";
+
+/**
+ * Stylesheets are updated for a browser after the pageshow event.
+ * This helper function returns a Promise that waits for that pageshow
+ * event, and then resolves on the next tick to ensure that gPageStyleMenu
+ * has had a chance to update the stylesheets.
+ *
+ * @param browser
+ *        The <xul:browser> to wait for.
+ * @return Promise
+ */
+function promiseStylesheetsUpdated(browser) {
+  return ContentTask.spawn(browser, { PAGE }, function*(args) {
+    return new Promise((resolve) => {
+      addEventListener("pageshow", function onPageShow(e) {
+        if (e.target.location == args.PAGE) {
+          removeEventListener("pageshow", onPageShow);
+          content.setTimeout(resolve, 0);
+        }
+      });
+    })
+  });
+}
+
+/**
+ * Tests that the Page Style menu shows the currently
+ * selected Page Style after a new one has been selected.
+ */
+add_task(function*() {
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank", false);
+  let browser = tab.linkedBrowser;
+
+  yield BrowserTestUtils.loadURI(browser, PAGE);
+  yield promiseStylesheetsUpdated(browser);
+
+  let menupopup = document.getElementById("pageStyleMenu").menupopup;
+  gPageStyleMenu.fillPopup(menupopup);
+
+  // page_style_sample.html should default us to selecting the stylesheet
+  // with the title "6" first.
+  let selected = menupopup.querySelector("menuitem[checked='true']");
+  is(selected.getAttribute("label"), "6", "Should have '6' stylesheet selected by default");
+
+  // Now select stylesheet "1"
+  let targets = menupopup.querySelectorAll("menuitem");
+  let target = menupopup.querySelector("menuitem[label='1']");
+  target.click();
+
+  // Now we need to wait for the content process to send its stylesheet
+  // update for the selected tab to the parent. Because messages are
+  // guaranteed to be sent in order, we'll make sure we do the check
+  // after the parent has been updated by yielding until the child
+  // has finished running a ContentTask for us.
+  yield ContentTask.spawn(browser, {}, function*() {
+    dump('\nJust wasting some time.\n');
+  });
+
+  gPageStyleMenu.fillPopup(menupopup);
+  // gPageStyleMenu empties out the menu between opens, so we need
+  // to get a new reference to the selected menuitem
+  selected = menupopup.querySelector("menuitem[checked='true']");
+  is(selected.getAttribute("label"), "1", "Should now have stylesheet 1 selected");
+
+  yield BrowserTestUtils.removeTab(tab);
+});
\ No newline at end of file