Bug 1308608 - test that opening about:rights from about:home actually works, r?mikedeboer draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 07 Oct 2016 21:26:21 +0100
changeset 422295 0a08efd9a350d1979a532d223443555a7b924828
parent 422188 ea8624a9b11e89b831b830cef70c47ae67ccead1
child 533301 f1ea73f856968b6a7ca52ffbb1909b9f5cc33d51
push id31736
push usergijskruitbosch@gmail.com
push dateFri, 07 Oct 2016 20:27:46 +0000
reviewersmikedeboer
bugs1308608
milestone52.0a1
Bug 1308608 - test that opening about:rights from about:home actually works, r?mikedeboer MozReview-Commit-ID: 7nIXmw1n26f
browser/base/content/test/general/browser_aboutHome.js
--- a/browser/base/content/test/general/browser_aboutHome.js
+++ b/browser/base/content/test/general/browser_aboutHome.js
@@ -161,30 +161,38 @@ add_task(function* () {
          args.expectedVersion,
          "cached-version is correct");
       ok(snippetsMap.has("snippets-last-update"), "last-update still exists");
     }, { expectedVersion: AboutHomeUtils.snippetsVersion });
 });
 
 add_task(function* () {
   info("Check if the 'Know Your Rights' default snippet is shown when " +
-    "'browser.rights.override' pref is set");
+    "'browser.rights.override' pref is set and that its link works");
 
   Services.prefs.setBoolPref("browser.rights.override", false);
 
   ok(AboutHomeUtils.showKnowYourRights, "AboutHomeUtils.showKnowYourRights should be TRUE");
 
   yield withSnippetsMap(null, function* () {
     let doc = content.document;
     let snippetsElt = doc.getElementById("snippets");
     ok(snippetsElt, "Found snippets element");
-    is(snippetsElt.getElementsByTagName("a")[0].href, "about:rights",
-      "Snippet link is present.");
+    let linkEl = snippetsElt.querySelector("a");
+    is(linkEl.href, "about:rights", "Snippet link is present.");
+  }, null, function* () {
+    let loadPromise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, "about:rights");
+    yield BrowserTestUtils.synthesizeMouseAtCenter("a[href='about:rights']", {
+      button: 0
+    }, gBrowser.selectedBrowser);
+    yield loadPromise;
+    is(gBrowser.currentURI.spec, "about:rights", "about:rights should have opened.");
   });
 
+
   Services.prefs.clearUserPref("browser.rights.override");
 });
 
 add_task(function* () {
   info("Check if the 'Know Your Rights' default snippet is NOT shown when " +
     "'browser.rights.override' pref is NOT set");
 
   Services.prefs.setBoolPref("browser.rights.override", true);
@@ -559,19 +567,25 @@ add_task(function* () {
 });
 
 /**
  * Cleans up snippets and ensures that by default we don't try to check for
  * remote snippets since that may cause network bustage or slowness.
  *
  * @param aSetupFn
  *        The setup function to be run.
+ * @param testFn
+ *        the content task to run
+ * @param testArgs (optional)
+ *        the parameters to pass to the content task
+ * @param parentFn (optional)
+ *        the function to run in the parent after the content task has completed.
  * @return {Promise} resolved when the snippets are ready.  Gets the snippets map.
  */
-function* withSnippetsMap(setupFn, testFn, testArgs = null) {
+function* withSnippetsMap(setupFn, testFn, testArgs = null, parentFn = null) {
   let setupFnSource;
   if (setupFn) {
     setupFnSource = setupFn.toSource();
   }
 
   yield BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" }, function* (browser) {
     let promiseAfterLocationChange = () => {
       return ContentTask.spawn(browser, {
@@ -634,16 +648,19 @@ function* withSnippetsMap(setupFn, testF
 
     // Set the URL to 'about:home' here to allow capturing the 'AboutHomeLoadSnippets'
     // event.
     browser.loadURI("about:home");
     // Wait for LocationChange.
     yield promise;
 
     yield ContentTask.spawn(browser, testArgs, testFn);
+    if (parentFn) {
+      yield parentFn();
+    }
   });
 }
 
 function promiseContentSearchChange(browser, newEngineName) {
   return ContentTask.spawn(browser, { newEngineName }, function* (args) {
     return new Promise(resolve => {
       content.addEventListener("ContentSearchService", function listener(aEvent) {
         if (aEvent.detail.type == "CurrentState" &&