Skip to content

Commit 54aaf25

Browse files
cmphilpotHarshitSohaney
authored andcommitted
Bug 1898356 - go back one page arrow (button) turns grey after clearing browsing & download history. r=hsohaney
Differential Revision: https://phabricator.services.mozilla.com/D259110
1 parent a96eb8d commit 54aaf25

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

browser/base/content/browser.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,16 +1025,21 @@ const gClickAndHoldListenersOnElement = {
10251025
},
10261026
};
10271027

1028+
// See bug 1898356 - Navigation buttons aren't being properly disabled
1029+
// when clearing the history. This is due that this callback is called
1030+
// before the panel is closed. By setting "wasdisabled" attribute instead
1031+
// of "disabled" attribute, we are sort of "lying" to `_updateMenuAndCommandState`
1032+
// that they where previously disabled, so it will not enable them.
10281033
const gSessionHistoryObserver = {
10291034
observe(subject, topic) {
10301035
if (topic != "browser:purge-session-history") {
10311036
return;
10321037
}
10331038

10341039
var backCommand = document.getElementById("Browser:Back");
1035-
backCommand.setAttribute("disabled", "true");
1040+
backCommand.setAttribute("wasdisabled", "true");
10361041
var fwdCommand = document.getElementById("Browser:Forward");
1037-
fwdCommand.setAttribute("disabled", "true");
1042+
fwdCommand.setAttribute("wasdisabled", "true");
10381043

10391044
// Clear undo history of the URL bar
10401045
gURLBar.editor.clearUndoRedo();

browser/base/content/test/backforward/browser.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
["browser_history_menu.js"]
44
fail-if = ["a11y_checks"] # Bug 1854233 navigator-toolbox may not be focusable
55
https_first_disabled = true
6+
7+
["browser_history_menu_clear.js"]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
https://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
"use strict";
5+
6+
add_task(async function test_back_button_disabled_after_history_clear() {
7+
// Start with a clean slate
8+
let tab = await BrowserTestUtils.openNewForegroundTab(
9+
gBrowser,
10+
"https://example.com/"
11+
);
12+
13+
registerCleanupFunction(() => {
14+
gBrowser.removeTab(tab);
15+
});
16+
17+
// Navigate to create session history
18+
BrowserTestUtils.startLoadingURIString(
19+
tab.linkedBrowser,
20+
"https://example.org/"
21+
);
22+
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
23+
24+
let backButton = document.getElementById("back-button");
25+
26+
// Wait for back button to be enabled
27+
await TestUtils.waitForCondition(
28+
() => !backButton.disabled,
29+
"Back button should be enabled with history"
30+
);
31+
32+
// Clear history using Sanitizer
33+
await Sanitizer.sanitize(["history"]);
34+
35+
// Check webNavigation state
36+
await TestUtils.waitForCondition(
37+
() => !tab.linkedBrowser.webNavigation.canGoBack,
38+
"webNavigation.canGoBack should be false after clearing"
39+
);
40+
41+
// Trigger UI update to reflect navigation state changes
42+
if (typeof gBrowser.updateBackForwardButtons === "function") {
43+
gBrowser.updateBackForwardButtons();
44+
} else {
45+
goUpdateCommand("Browser:Back");
46+
}
47+
48+
// Wait for UI to update
49+
await TestUtils.waitForCondition(
50+
() => backButton.hasAttribute("disabled"),
51+
"Back button should be disabled after clearing history"
52+
);
53+
54+
Assert.ok(
55+
backButton.hasAttribute("disabled"),
56+
"Back button should be disabled"
57+
);
58+
59+
// To check that arrow is 'grayed out'
60+
let computedStyle = window.getComputedStyle(backButton);
61+
Assert.equal(
62+
computedStyle.getPropertyValue("opacity"),
63+
"0.4", // the opacity value
64+
"Back button should appear grayed out when disabled"
65+
);
66+
});

0 commit comments

Comments
 (0)