Backed out changeset 7969278ce39f (bug 1869884) for causing failures on browser_sanit...
[gecko.git] / browser / base / content / test / sanitize / browser_purgehistory_clears_sh.js
blobc75946bf2bccd425a7c1d2eb04011b6c298ed6bc
1 /* Any copyright is dedicated to the Public Domain.
2  * http://creativecommons.org/publicdomain/zero/1.0/ */
4 const url =
5   "https://example.org/browser/browser/base/content/test/sanitize/dummy_page.html";
7 // We will be removing the ["history"] option once we remove the
8 // old clear history dialog in Bug 1856418 - Remove all old clear data dialog boxes
9 let prefs = [["history"], ["historyAndFormData"]];
11 for (let itemsToClear of prefs) {
12   add_task(async function purgeHistoryTest() {
13     await BrowserTestUtils.withNewTab(
14       {
15         gBrowser,
16         url,
17       },
18       async function purgeHistoryTestInner(browser) {
19         let backButton = browser.ownerDocument.getElementById("Browser:Back");
20         let forwardButton =
21           browser.ownerDocument.getElementById("Browser:Forward");
23         ok(
24           !browser.webNavigation.canGoBack,
25           "Initial value for webNavigation.canGoBack"
26         );
27         ok(
28           !browser.webNavigation.canGoForward,
29           "Initial value for webNavigation.canGoBack"
30         );
31         ok(backButton.hasAttribute("disabled"), "Back button is disabled");
32         ok(
33           forwardButton.hasAttribute("disabled"),
34           "Forward button is disabled"
35         );
37         await SpecialPowers.spawn(browser, [], async function () {
38           let startHistory = content.history.length;
39           content.history.pushState({}, "");
40           content.history.pushState({}, "");
41           content.history.back();
42           await new Promise(function (r) {
43             content.onpopstate = r;
44           });
45           let newHistory = content.history.length;
46           Assert.equal(startHistory, 1, "Initial SHistory size");
47           Assert.equal(newHistory, 3, "New SHistory size");
48         });
50         ok(
51           browser.webNavigation.canGoBack,
52           "New value for webNavigation.canGoBack"
53         );
54         ok(
55           browser.webNavigation.canGoForward,
56           "New value for webNavigation.canGoForward"
57         );
58         ok(!backButton.hasAttribute("disabled"), "Back button was enabled");
59         ok(
60           !forwardButton.hasAttribute("disabled"),
61           "Forward button was enabled"
62         );
64         await Sanitizer.sanitize(itemsToClear);
66         await SpecialPowers.spawn(browser, [], async function () {
67           Assert.equal(content.history.length, 1, "SHistory correctly cleared");
68         });
70         ok(
71           !browser.webNavigation.canGoBack,
72           "webNavigation.canGoBack correctly cleared"
73         );
74         ok(
75           !browser.webNavigation.canGoForward,
76           "webNavigation.canGoForward correctly cleared"
77         );
78         ok(backButton.hasAttribute("disabled"), "Back button was disabled");
79         ok(
80           forwardButton.hasAttribute("disabled"),
81           "Forward button was disabled"
82         );
83       }
84     );
85   });