Bug 1309316 - Add tests for autosubmission request in about:tabcrashed. r=Felipe
authorMike Conley <mconley@mozilla.com>
Fri, 11 Nov 2016 01:58:35 -0500
changeset 348873 a80600db579d50ee38991545f93bff07a2fc86e4
parent 348872 3b3082d32c0de43b87750c31c39c1e0891e7fe9f
child 348874 44af2c3d71ea627858f269f61c80a82800e6ffe1
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 - Add tests for autosubmission request in about:tabcrashed. r=Felipe MozReview-Commit-ID: 9EWat5WJzCp
browser/base/content/test/tabcrashed/browser.ini
browser/base/content/test/tabcrashed/browser_autoSubmitRequest.js
--- a/browser/base/content/test/tabcrashed/browser.ini
+++ b/browser/base/content/test/tabcrashed/browser.ini
@@ -4,8 +4,10 @@ support-files =
 [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
+[browser_autoSubmitRequest.js]
+skip-if = !e10s
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabcrashed/browser_autoSubmitRequest.js
@@ -0,0 +1,97 @@
+"use strict";
+
+const PAGE = "data:text/html,<html><body>A%20regular,%20everyday,%20normal%20page.";
+const AUTOSUBMIT_PREF = "browser.crashReports.unsubmittedCheck.autoSubmit";
+
+const {TabStateFlusher} =
+  Cu.import("resource:///modules/sessionstore/TabStateFlusher.jsm", {});
+
+// On debug builds, crashing tabs results in much thinking, which
+// slows down the test and results in intermittent test timeouts,
+// so we'll pump up the expected timeout for this test.
+requestLongerTimeout(2);
+
+/**
+ * Tests that if the user is not configured to autosubmit
+ * backlogged crash reports, that we offer to do that, and
+ * that the user can accept that offer.
+ */
+add_task(function* test_show_form() {
+  yield SpecialPowers.pushPrefEnv({
+    set: [[AUTOSUBMIT_PREF, false]],
+  })
+
+  return BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: PAGE,
+  }, function*(browser) {
+    // Make sure we've flushed the browser messages so that
+    // we can restore it.
+    yield TabStateFlusher.flush(browser);
+
+    // Now crash the browser.
+    yield BrowserTestUtils.crashBrowser(browser);
+
+    let doc = browser.contentDocument;
+
+    // Ensure the request is visible. We can safely reach into
+    // the content since about:tabcrashed is an in-process URL.
+    let requestAutoSubmit = doc.getElementById("requestAutoSubmit");
+    Assert.ok(!requestAutoSubmit.hidden,
+              "Request for autosubmission is visible.");
+
+    // Since the pref is set to false, the checkbox should be
+    // unchecked.
+    let autoSubmit = doc.getElementById("autoSubmit");
+    Assert.ok(!autoSubmit.checked,
+              "Checkbox for autosubmission is not checked.")
+
+    // Check the checkbox, and then restore the tab.
+    autoSubmit.checked = true;
+    let restoreButton = doc.getElementById("restoreTab");
+    restoreButton.click();
+
+    yield BrowserTestUtils.browserLoaded(browser, false, PAGE);
+
+    // The autosubmission pref should now be set.
+    Assert.ok(Services.prefs.getBoolPref(AUTOSUBMIT_PREF),
+              "Autosubmission pref should have been set.");
+  });
+});
+
+/**
+ * Tests that if the user is autosubmitting backlogged crash reports
+ * that we don't make the offer again.
+ */
+add_task(function* test_show_form() {
+  yield SpecialPowers.pushPrefEnv({
+    set: [[AUTOSUBMIT_PREF, true]],
+  })
+
+  return BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: PAGE,
+  }, function*(browser) {
+    yield TabStateFlusher.flush(browser);
+    // Now crash the browser.
+    yield BrowserTestUtils.crashBrowser(browser);
+
+    let doc = browser.contentDocument;
+
+    // Ensure the request is NOT visible. We can safely reach into
+    // the content since about:tabcrashed is an in-process URL.
+    let requestAutoSubmit = doc.getElementById("requestAutoSubmit");
+    Assert.ok(requestAutoSubmit.hidden,
+              "Request for autosubmission is not visible.");
+
+    // Restore the tab.
+    let restoreButton = doc.getElementById("restoreTab");
+    restoreButton.click();
+
+    yield BrowserTestUtils.browserLoaded(browser, false, PAGE);
+
+    // The autosubmission pref should still be set to true.
+    Assert.ok(Services.prefs.getBoolPref(AUTOSUBMIT_PREF),
+              "Autosubmission pref should have been set.");
+  });
+});