Bug 1395074 - Clear browserAction tab data on navigation r=mixedpuppy

MozReview-Commit-ID: 4hugj2q84Rd

--HG--
extra : rebase_source : 519303dcd0261acf5945160bc749f03878c00f07
This commit is contained in:
Mark Striemer 2017-09-26 16:06:06 -05:00
Родитель 4b3928036f
Коммит ff49d47ca1
2 изменённых файлов: 28 добавлений и 14 удалений

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

@ -118,9 +118,19 @@ this.browserAction = class extends ExtensionAPI {
this.tabContext = new TabContext(tab => Object.create(this.defaults),
extension);
// eslint-disable-next-line mozilla/balanced-listeners
this.tabContext.on("location-change", this.handleLocationChange.bind(this));
this.build();
}
handleLocationChange(eventType, tab, fromBrowse) {
if (fromBrowse) {
this.tabContext.clear(tab);
this.updateOnChange(tab);
}
}
onShutdown(reason) {
browserActionMap.delete(this.extension);

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

@ -214,6 +214,12 @@ add_task(async function testTabSwitchContext() {
"title": "Default Title 2",
"badge": "d2",
"badgeBackgroundColor": [0, 0xff, 0, 0xff]},
{"icon": browser.runtime.getURL("default-2.png"),
"popup": browser.runtime.getURL("default-2.html"),
"title": "Default Title 2",
"badge": "d2",
"badgeBackgroundColor": [0, 0xff, 0, 0xff],
"disabled": false},
];
return [
@ -251,20 +257,6 @@ add_task(async function testTabSwitchContext() {
await expectDefaults(details[0]);
expect(details[2]);
},
expect => {
browser.test.log("Navigate to a new page. Expect no changes.");
// TODO: This listener should not be necessary, but the |tabs.update|
// callback currently fires too early in e10s windows.
browser.tabs.onUpdated.addListener(function listener(tabId, changed) {
if (tabId == tabs[1] && changed.url) {
browser.tabs.onUpdated.removeListener(listener);
expect(details[2]);
}
});
browser.tabs.update(tabs[1], {url: "about:blank?1"});
},
async expect => {
browser.test.log("Switch back to the first tab. Expect previously set properties.");
await browser.tabs.update(tabs[0], {active: true});
@ -296,6 +288,18 @@ add_task(async function testTabSwitchContext() {
await expectDefaults(details[3]);
expect(details[2]);
},
expect => {
browser.test.log("Navigate to a new page. Expect defaults.");
browser.tabs.onUpdated.addListener(function listener(tabId, changed) {
if (tabId == tabs[1] && changed.url) {
browser.tabs.onUpdated.removeListener(listener);
expect(details[6]);
}
});
browser.tabs.update(tabs[1], {url: "about:blank?1"});
},
async expect => {
browser.test.log("Delete tab, switch back to tab 1. Expect previous results again.");
await browser.tabs.remove(tabs[1]);