Bug 1764452 - Avoid tabs.onUpdated events for 'attention' when value doesn't change. r=Gijs,mixedpuppy

Differential Revision: https://phabricator.services.mozilla.com/D143553
This commit is contained in:
Oriol Brufau 2022-04-21 08:30:07 +00:00
Родитель 3452b7574c
Коммит 56b156bf6a
6 изменённых файлов: 22 добавлений и 28 удалений

Просмотреть файл

@ -129,6 +129,15 @@
return gBrowser.tabContainer;
}
set attention(val) {
if (val == this.hasAttribute("attention")) {
return;
}
this.toggleAttribute("attention", val);
gBrowser._tabAttrModified(this, ["attention"]);
}
set _visuallySelected(val) {
if (val == (this.getAttribute("visuallyselected") == "true")) {
return;

Просмотреть файл

@ -1183,8 +1183,7 @@
this.updateTitlebar();
newTab.removeAttribute("titlechanged");
newTab.removeAttribute("attention");
this._tabAttrModified(newTab, ["attention"]);
newTab.attention = false;
// The tab has been selected, it's not unselected anymore.
// (1) Call the current tab's finishUnselectedTabHoverTimer()
@ -5924,8 +5923,7 @@
// For null principals, we bail immediately and don't show the checkbox:
if (!promptPrincipal || promptPrincipal.isNullPrincipal) {
tabForEvent.setAttribute("attention", "true");
this._tabAttrModified(tabForEvent, ["attention"]);
tabForEvent.attention = true;
return;
}
@ -5946,8 +5944,7 @@
tabPrompt.onNextPromptShowAllowFocusCheckboxFor(
promptPrincipal
);
tabForEvent.setAttribute("attention", "true");
this._tabAttrModified(tabForEvent, ["attention"]);
tabForEvent.attention = true;
return;
}
}

Просмотреть файл

@ -36,8 +36,7 @@ add_task(async function test_old_modal_ui() {
);
let openedTabGotAttentionPromise = BrowserTestUtils.waitForAttribute(
"attention",
openedTab,
"true"
openedTab
);
// switch away from that tab again - this triggers the alert.
await BrowserTestUtils.switchTab(gBrowser, firstTab);
@ -45,8 +44,8 @@ add_task(async function test_old_modal_ui() {
await openedTabGotAttentionPromise;
// check for attention attribute
is(
openedTab.getAttribute("attention"),
"true",
openedTab.hasAttribute("attention"),
true,
"Tab with alert should have 'attention' attribute."
);
ok(!openedTab.selected, "Tab with alert should not be selected");
@ -148,8 +147,7 @@ add_task(async function test_new_modal_ui() {
);
let openedTabGotAttentionPromise = BrowserTestUtils.waitForAttribute(
"attention",
openedTab,
"true"
openedTab
);
// switch away from that tab again - this triggers the alert.
await BrowserTestUtils.switchTab(gBrowser, firstTab);
@ -157,8 +155,8 @@ add_task(async function test_new_modal_ui() {
await openedTabGotAttentionPromise;
// check for attention attribute
is(
openedTab.getAttribute("attention"),
"true",
openedTab.hasAttribute("attention"),
true,
"Tab with alert should have 'attention' attribute."
);
ok(!openedTab.selected, "Tab with alert should not be selected");

Просмотреть файл

@ -4403,7 +4403,7 @@ BrowserGlue.prototype = {
} else {
tab = win.gBrowser.addWebTab(URI.uri);
}
tab.setAttribute("attention", true);
tab.attention = true;
return tab;
};
@ -4502,7 +4502,7 @@ BrowserGlue.prototype = {
} else {
tab = win.gBrowser.addWebTab(url);
}
tab.setAttribute("attention", true);
tab.attention = true;
let clickCallback = (subject, topic, data) => {
if (topic != "alertclickcallback") {
return;

Просмотреть файл

@ -755,7 +755,7 @@ class Tab extends TabBase {
}
get attention() {
return this.nativeTab.getAttribute("attention") === "true";
return this.nativeTab.hasAttribute("attention");
}
get audible() {

Просмотреть файл

@ -9,21 +9,12 @@ add_task(async function test_onCreated_active() {
permissions: ["tabs"],
},
async background() {
let created = false;
let tabIds = (await browser.tabs.query({})).map(t => t.id);
browser.tabs.onCreated.addListener(tab => {
created = tab.id;
browser.tabs.remove(tab.id);
browser.test.sendMessage("onCreated", tab);
});
// We always get at least one onUpdated event when creating tabs.
browser.tabs.onUpdated.addListener((tabId, changes, tab) => {
// ignore tabs created prior to extension startup
if (tabIds.includes(tabId)) {
return;
}
browser.test.assertTrue(created, tabId, "tab created before updated");
browser.test.notifyPass("onUpdated");
browser.test.fail("unexpected tabs.onUpdated during tab creation");
});
browser.test.sendMessage("ready");
},
@ -35,7 +26,6 @@ add_task(async function test_onCreated_active() {
let tab = await extension.awaitMessage("onCreated");
is(true, tab.active, "Tab should be active");
await extension.awaitFinish("onUpdated");
await extension.unload();
});