browser_purgehistory_clears_sh.js (3049B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 const url = 5 "https://example.org/browser/browser/base/content/test/sanitize/dummy_page.html"; 6 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"], ["browsingHistoryAndDownloads"]]; 10 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"); 22 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 ); 36 37 await SpecialPowers.spawn(browser, [], async function () { 38 let startHistory = content.history.length; 39 content.document.notifyUserGestureActivation(); 40 content.history.pushState({}, ""); 41 content.document.notifyUserGestureActivation(); 42 content.history.pushState({}, ""); 43 content.document.notifyUserGestureActivation(); 44 45 content.history.back(); 46 await new Promise(function (r) { 47 content.onpopstate = r; 48 }); 49 let newHistory = content.history.length; 50 Assert.equal(startHistory, 1, "Initial SHistory size"); 51 Assert.equal(newHistory, 3, "New SHistory size"); 52 }); 53 54 ok( 55 browser.webNavigation.canGoBack, 56 "New value for webNavigation.canGoBack" 57 ); 58 ok( 59 browser.webNavigation.canGoForward, 60 "New value for webNavigation.canGoForward" 61 ); 62 ok(!backButton.hasAttribute("disabled"), "Back button was enabled"); 63 ok( 64 !forwardButton.hasAttribute("disabled"), 65 "Forward button was enabled" 66 ); 67 68 await Sanitizer.sanitize(itemsToClear); 69 70 await SpecialPowers.spawn(browser, [], async function () { 71 Assert.equal(content.history.length, 1, "SHistory correctly cleared"); 72 }); 73 74 ok( 75 !browser.webNavigation.canGoBack, 76 "webNavigation.canGoBack correctly cleared" 77 ); 78 ok( 79 !browser.webNavigation.canGoForward, 80 "webNavigation.canGoForward correctly cleared" 81 ); 82 ok(backButton.hasAttribute("disabled"), "Back button was disabled"); 83 ok( 84 forwardButton.hasAttribute("disabled"), 85 "Forward button was disabled" 86 ); 87 } 88 ); 89 }); 90 }