Bug 1309316 - Move about:tabcrashed tests into their own directory. r=Felipe
authorMike Conley <mconley@mozilla.com>
Thu, 10 Nov 2016 23:17:48 -0500
changeset 348872 3b3082d32c0de43b87750c31c39c1e0891e7fe9f
parent 348871 25412fab8aa517e000239d06bf261f60a2bc3f6b
child 348873 a80600db579d50ee38991545f93bff07a2fc86e4
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1309316
milestone52.0a1
Bug 1309316 - Move about:tabcrashed tests into their own directory. r=Felipe MozReview-Commit-ID: C3emEC3JbiL
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_aboutTabCrashed.js
browser/base/content/test/general/browser_aboutTabCrashed_clearEmail.js
browser/base/content/test/general/browser_aboutTabCrashed_showForm.js
browser/base/content/test/general/browser_aboutTabCrashed_withoutDump.js
browser/base/content/test/general/head.js
browser/base/content/test/tabcrashed/browser.ini
browser/base/content/test/tabcrashed/browser_clearEmail.js
browser/base/content/test/tabcrashed/browser_showForm.js
browser/base/content/test/tabcrashed/browser_shown.js
browser/base/content/test/tabcrashed/browser_withoutDump.js
browser/base/content/test/tabcrashed/head.js
browser/base/moz.build
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -479,22 +479,14 @@ tags = psm
 [browser_mcb_redirect.js]
 tags = mcb
 [browser_windowactivation.js]
 [browser_contextmenu_childprocess.js]
 [browser_bug963945.js]
 [browser_domFullscreen_fullscreenMode.js]
 tags = fullscreen
 [browser_menuButtonBadgeManager.js]
-[browser_aboutTabCrashed.js]
-skip-if = !e10s || !crashreporter
-[browser_aboutTabCrashed_clearEmail.js]
-skip-if = !e10s || !crashreporter
 [browser_newTabDrop.js]
 [browser_newWindowDrop.js]
-[browser_aboutTabCrashed_showForm.js]
-skip-if = !e10s || !crashreporter
-[browser_aboutTabCrashed_withoutDump.js]
-skip-if = !e10s
 [browser_csp_block_all_mixedcontent.js]
 tags = mcb
 [browser_newwindow_focus.js]
 skip-if = (os == "linux" && !e10s) # Bug 1263254 - Perma fails on Linux without e10s for some reason.
--- a/browser/base/content/test/general/head.js
+++ b/browser/base/content/test/general/head.js
@@ -986,114 +986,16 @@ function promiseOnBookmarkItemAdded(aExp
         Ci.nsINavBookmarkObserver,
       ])
     };
     info("Waiting for a bookmark to be added");
     PlacesUtils.bookmarks.addObserver(bookmarksObserver, false);
   });
 }
 
-/**
- * For an nsIPropertyBag, returns the value for a given
- * key.
- *
- * @param bag
- *        The nsIPropertyBag to retrieve the value from
- * @param key
- *        The key that we want to get the value for from the
- *        bag
- * @returns The value corresponding to the key from the bag,
- *          or null if the value could not be retrieved (for
- *          example, if no value is set at that key).
-*/
-function getPropertyBagValue(bag, key) {
-  try {
-    let val = bag.getProperty(key);
-    return val;
-  } catch (e) {
-    if (e.result != Cr.NS_ERROR_FAILURE) {
-      throw e;
-    }
-  }
-
-  return null;
-}
-
-/**
- * Returns a Promise that resolves once a crash report has
- * been submitted. This function will also test the crash
- * reports extra data to see if it matches expectedExtra.
- *
- * @param expectedExtra (object)
- *        An Object whose key-value pairs will be compared
- *        against the key-value pairs in the extra data of the
- *        crash report. A test failure will occur if there is
- *        a mismatch.
- *
- *        If the value of the key-value pair is "null", this will
- *        be interpreted as "this key should not be included in the
- *        extra data", and will cause a test failure if it is detected
- *        in the crash report.
- *
- *        Note that this will ignore any keys that are not included
- *        in expectedExtra. It's possible that the crash report
- *        will contain other extra information that is not
- *        compared against.
- * @returns Promise
- */
-function promiseCrashReport(expectedExtra={}) {
-  return Task.spawn(function*() {
-    info("Starting wait on crash-report-status");
-    let [subject, ] =
-      yield TestUtils.topicObserved("crash-report-status", (unused, data) => {
-        return data == "success";
-      });
-    info("Topic observed!");
-
-    if (!(subject instanceof Ci.nsIPropertyBag2)) {
-      throw new Error("Subject was not a Ci.nsIPropertyBag2");
-    }
-
-    let remoteID = getPropertyBagValue(subject, "serverCrashID");
-    if (!remoteID) {
-      throw new Error("Report should have a server ID");
-    }
-
-    let file = Cc["@mozilla.org/file/local;1"]
-                 .createInstance(Ci.nsILocalFile);
-    file.initWithPath(Services.crashmanager._submittedDumpsDir);
-    file.append(remoteID + ".txt");
-    if (!file.exists()) {
-      throw new Error("Report should have been received by the server");
-    }
-
-    file.remove(false);
-
-    let extra = getPropertyBagValue(subject, "extra");
-    if (!(extra instanceof Ci.nsIPropertyBag2)) {
-      throw new Error("extra was not a Ci.nsIPropertyBag2");
-    }
-
-    info("Iterating crash report extra keys");
-    let enumerator = extra.enumerator;
-    while (enumerator.hasMoreElements()) {
-      let key = enumerator.getNext().QueryInterface(Ci.nsIProperty).name;
-      let value = extra.getPropertyAsAString(key);
-      if (key in expectedExtra) {
-        if (expectedExtra[key] == null) {
-          ok(false, `Got unexpected key ${key} with value ${value}`);
-        } else {
-          is(value, expectedExtra[key],
-             `Crash report had the right extra value for ${key}`);
-        }
-      }
-    }
-  });
-}
-
 function promiseErrorPageLoaded(browser) {
   return new Promise(resolve => {
     browser.addEventListener("DOMContentLoaded", function onLoad() {
       browser.removeEventListener("DOMContentLoaded", onLoad, false, true);
       resolve();
     }, false, true);
   });
 }
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabcrashed/browser.ini
@@ -0,0 +1,11 @@
+[DEFAULT]
+support-files =
+  head.js
+[browser_shown.js]
+skip-if = !e10s || !crashreporter
+[browser_clearEmail.js]
+skip-if = !e10s || !crashreporter
+[browser_showForm.js]
+skip-if = !e10s || !crashreporter
+[browser_withoutDump.js]
+skip-if = !e10s
rename from browser/base/content/test/general/browser_aboutTabCrashed_clearEmail.js
rename to browser/base/content/test/tabcrashed/browser_clearEmail.js
rename from browser/base/content/test/general/browser_aboutTabCrashed_showForm.js
rename to browser/base/content/test/tabcrashed/browser_showForm.js
--- a/browser/base/content/test/general/browser_aboutTabCrashed_showForm.js
+++ b/browser/base/content/test/tabcrashed/browser_showForm.js
@@ -14,17 +14,19 @@ requestLongerTimeout(2);
 add_task(function* test_show_form() {
   return BrowserTestUtils.withNewTab({
     gBrowser,
     url: PAGE,
   }, function*(browser) {
     // Flip the pref so that the checkbox should be checked
     // by default.
     let pref = TabCrashHandler.prefs.root + "sendReport";
-    yield pushPrefs([pref, true]);
+    yield SpecialPowers.pushPrefEnv({
+      set: [[pref, true]]
+    });
 
     // Now crash the browser.
     yield BrowserTestUtils.crashBrowser(browser);
 
     let doc = browser.contentDocument;
 
     // Ensure the checkbox is checked. We can safely reach into
     // the content since about:tabcrashed is an in-process URL.
rename from browser/base/content/test/general/browser_aboutTabCrashed.js
rename to browser/base/content/test/tabcrashed/browser_shown.js
rename from browser/base/content/test/general/browser_aboutTabCrashed_withoutDump.js
rename to browser/base/content/test/tabcrashed/browser_withoutDump.js
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabcrashed/head.js
@@ -0,0 +1,98 @@
+/**
+ * Returns a Promise that resolves once a crash report has
+ * been submitted. This function will also test the crash
+ * reports extra data to see if it matches expectedExtra.
+ *
+ * @param expectedExtra (object)
+ *        An Object whose key-value pairs will be compared
+ *        against the key-value pairs in the extra data of the
+ *        crash report. A test failure will occur if there is
+ *        a mismatch.
+ *
+ *        If the value of the key-value pair is "null", this will
+ *        be interpreted as "this key should not be included in the
+ *        extra data", and will cause a test failure if it is detected
+ *        in the crash report.
+ *
+ *        Note that this will ignore any keys that are not included
+ *        in expectedExtra. It's possible that the crash report
+ *        will contain other extra information that is not
+ *        compared against.
+ * @returns Promise
+ */
+function promiseCrashReport(expectedExtra={}) {
+  return Task.spawn(function*() {
+    info("Starting wait on crash-report-status");
+    let [subject, ] =
+      yield TestUtils.topicObserved("crash-report-status", (unused, data) => {
+        return data == "success";
+      });
+    info("Topic observed!");
+
+    if (!(subject instanceof Ci.nsIPropertyBag2)) {
+      throw new Error("Subject was not a Ci.nsIPropertyBag2");
+    }
+
+    let remoteID = getPropertyBagValue(subject, "serverCrashID");
+    if (!remoteID) {
+      throw new Error("Report should have a server ID");
+    }
+
+    let file = Cc["@mozilla.org/file/local;1"]
+                 .createInstance(Ci.nsILocalFile);
+    file.initWithPath(Services.crashmanager._submittedDumpsDir);
+    file.append(remoteID + ".txt");
+    if (!file.exists()) {
+      throw new Error("Report should have been received by the server");
+    }
+
+    file.remove(false);
+
+    let extra = getPropertyBagValue(subject, "extra");
+    if (!(extra instanceof Ci.nsIPropertyBag2)) {
+      throw new Error("extra was not a Ci.nsIPropertyBag2");
+    }
+
+    info("Iterating crash report extra keys");
+    let enumerator = extra.enumerator;
+    while (enumerator.hasMoreElements()) {
+      let key = enumerator.getNext().QueryInterface(Ci.nsIProperty).name;
+      let value = extra.getPropertyAsAString(key);
+      if (key in expectedExtra) {
+        if (expectedExtra[key] == null) {
+          ok(false, `Got unexpected key ${key} with value ${value}`);
+        } else {
+          is(value, expectedExtra[key],
+             `Crash report had the right extra value for ${key}`);
+        }
+      }
+    }
+  });
+}
+
+
+/**
+ * For an nsIPropertyBag, returns the value for a given
+ * key.
+ *
+ * @param bag
+ *        The nsIPropertyBag to retrieve the value from
+ * @param key
+ *        The key that we want to get the value for from the
+ *        bag
+ * @returns The value corresponding to the key from the bag,
+ *          or null if the value could not be retrieved (for
+ *          example, if no value is set at that key).
+*/
+function getPropertyBagValue(bag, key) {
+  try {
+    let val = bag.getProperty(key);
+    return val;
+  } catch (e) {
+    if (e.result != Cr.NS_ERROR_FAILURE) {
+      throw e;
+    }
+  }
+
+  return null;
+}
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -17,16 +17,17 @@ MOCHITEST_CHROME_MANIFESTS += [
 BROWSER_CHROME_MANIFESTS += [
     'content/test/alerts/browser.ini',
     'content/test/general/browser.ini',
     'content/test/newtab/browser.ini',
     'content/test/plugins/browser.ini',
     'content/test/popupNotifications/browser.ini',
     'content/test/referrer/browser.ini',
     'content/test/social/browser.ini',
+    'content/test/tabcrashed/browser.ini',
     'content/test/tabPrompts/browser.ini',
     'content/test/tabs/browser.ini',
     'content/test/urlbar/browser.ini',
     'content/test/webrtc/browser.ini',
 ]
 
 DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
 DEFINES['MOZ_APP_VERSION_DISPLAY'] = CONFIG['MOZ_APP_VERSION_DISPLAY']