summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabcrashed/browser_autoSubmitRequest.js
blob: b99e8a10b999a36b5b9ca281e77f96baac88c09f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
"use strict";

const PAGE =
  "data:text/html,<html><body>A%20regular,%20everyday,%20normal%20page.";
const AUTOSUBMIT_PREF = "browser.crashReports.unsubmittedCheck.autoSubmit2";

const { TabStateFlusher } = ChromeUtils.importESModule(
  "resource:///modules/sessionstore/TabStateFlusher.sys.mjs"
);

// 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(async function test_show_form() {
  await SpecialPowers.pushPrefEnv({
    set: [[AUTOSUBMIT_PREF, false]],
  });

  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: PAGE,
    },
    async function (browser) {
      // Make sure we've flushed the browser messages so that
      // we can restore it.
      await TabStateFlusher.flush(browser);

      // Now crash the browser.
      await BrowserTestUtils.crashFrame(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();

      await 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(async function test_show_form() {
  await SpecialPowers.pushPrefEnv({
    set: [[AUTOSUBMIT_PREF, true]],
  });

  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: PAGE,
    },
    async function (browser) {
      await TabStateFlusher.flush(browser);
      // Now crash the browser.
      await BrowserTestUtils.crashFrame(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();

      await 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."
      );
    }
  );
});

/**
 * Tests that we properly set the autoSubmit preference if the user is
 * presented with a tabcrashed page without a crash report.
 */
add_task(async function test_no_offer() {
  // We should default to sending the report.
  Assert.ok(TabCrashHandler.prefs.getBoolPref("sendReport"));

  await SpecialPowers.pushPrefEnv({
    set: [[AUTOSUBMIT_PREF, false]],
  });

  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: PAGE,
    },
    async function (browser) {
      await TabStateFlusher.flush(browser);

      // Make it so that it seems like no dump is available for the next crash.
      prepareNoDump();

      // Now crash the browser.
      await BrowserTestUtils.crashFrame(browser);

      let doc = browser.contentDocument;

      // Ensure the request to autosubmit is invisible, since there's no report.
      let requestRect = doc
        .getElementById("requestAutoSubmit")
        .getBoundingClientRect();
      Assert.equal(
        0,
        requestRect.height,
        "Request for autosubmission has no height"
      );
      Assert.equal(
        0,
        requestRect.width,
        "Request for autosubmission has no width"
      );

      // 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."
      );

      let restoreButton = doc.getElementById("restoreTab");
      restoreButton.click();

      await BrowserTestUtils.browserLoaded(browser, false, PAGE);

      // The autosubmission pref should now be set.
      Assert.ok(
        !Services.prefs.getBoolPref(AUTOSUBMIT_PREF),
        "Autosubmission pref should not have changed."
      );
    }
  );

  // We should not have changed the default value for sending the report.
  Assert.ok(TabCrashHandler.prefs.getBoolPref("sendReport"));
});