зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1205221 - Fix chrome.tabs.onUpdate event doesn't be fired correctly when tab's attribute is changed. r=billm
--HG-- extra : transplant_source : %B7%2C%06e%0E%0F/%C3%E5-F%A1M%9B%C3%8F%060%95S
This commit is contained in:
Родитель
dd7668ef22
Коммит
dba190796b
|
@ -127,7 +127,7 @@ extensions.registerAPI((extension, context) => {
|
|||
}
|
||||
};
|
||||
|
||||
WindowListManager.addOpenListener(windowListener, false);
|
||||
WindowListManager.addOpenListener(windowListener);
|
||||
AllWindowEvents.addListener("TabOpen", listener);
|
||||
return () => {
|
||||
WindowListManager.removeOpenListener(windowListener);
|
||||
|
@ -195,7 +195,9 @@ extensions.registerAPI((extension, context) => {
|
|||
let tab = gBrowser.getTabForBrowser(browser);
|
||||
let tabId = TabManager.getId(tab);
|
||||
let [needed, changeInfo] = sanitize(extension, {status});
|
||||
fire(tabId, changeInfo, TabManager.convert(extension, tab));
|
||||
if (needed) {
|
||||
fire(tabId, changeInfo, TabManager.convert(extension, tab));
|
||||
}
|
||||
},
|
||||
|
||||
onLocationChange(browser, webProgress, request, locationURI, flags) {
|
||||
|
|
|
@ -424,7 +424,7 @@ global.WindowListManager = {
|
|||
}
|
||||
},
|
||||
|
||||
addOpenListener(listener, fireOnExisting = true) {
|
||||
addOpenListener(listener) {
|
||||
if (this._openListeners.length == 0 && this._closeListeners.length == 0) {
|
||||
Services.ww.registerNotification(this);
|
||||
}
|
||||
|
@ -433,8 +433,6 @@ global.WindowListManager = {
|
|||
for (let window of this.browserWindows(true)) {
|
||||
if (window.document.readyState != "complete") {
|
||||
window.addEventListener("load", this);
|
||||
} else if (fireOnExisting) {
|
||||
listener(window);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -462,7 +460,7 @@ global.WindowListManager = {
|
|||
|
||||
handleEvent(event) {
|
||||
let window = event.target.defaultView;
|
||||
window.removeEventListener("load", this.loadListener);
|
||||
window.removeEventListener("load", this);
|
||||
if (window.document.documentElement.getAttribute("windowtype") != "navigator:browser") {
|
||||
return;
|
||||
}
|
||||
|
@ -504,7 +502,9 @@ global.AllWindowEvents = {
|
|||
return WindowListManager.addCloseListener(listener);
|
||||
}
|
||||
|
||||
let needOpenListener = this._listeners.size == 0;
|
||||
if (this._listeners.size == 0) {
|
||||
WindowListManager.addOpenListener(this.openListener);
|
||||
}
|
||||
|
||||
if (!this._listeners.has(type)) {
|
||||
this._listeners.set(type, new Set());
|
||||
|
@ -512,10 +512,7 @@ global.AllWindowEvents = {
|
|||
let list = this._listeners.get(type);
|
||||
list.add(listener);
|
||||
|
||||
if (needOpenListener) {
|
||||
WindowListManager.addOpenListener(this.openListener, false);
|
||||
}
|
||||
|
||||
// Register listener on all existing windows.
|
||||
for (let window of WindowListManager.browserWindows()) {
|
||||
this.addWindowListener(window, type, listener);
|
||||
}
|
||||
|
@ -537,6 +534,7 @@ global.AllWindowEvents = {
|
|||
}
|
||||
}
|
||||
|
||||
// Unregister listener from all existing windows.
|
||||
for (let window of WindowListManager.browserWindows()) {
|
||||
if (type == "progress") {
|
||||
window.gBrowser.removeTabsProgressListener(listener);
|
||||
|
|
|
@ -76,3 +76,93 @@ add_task(function* () {
|
|||
|
||||
yield BrowserTestUtils.closeWindow(win1);
|
||||
});
|
||||
|
||||
function* do_test_update(background) {
|
||||
let win1 = yield BrowserTestUtils.openNewBrowserWindow();
|
||||
|
||||
yield focusWindow(win1);
|
||||
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
"permissions": ["tabs"]
|
||||
},
|
||||
|
||||
background: background,
|
||||
});
|
||||
|
||||
yield Promise.all([
|
||||
yield extension.startup(),
|
||||
yield extension.awaitFinish("finish")
|
||||
]);
|
||||
|
||||
yield extension.unload();
|
||||
|
||||
yield BrowserTestUtils.closeWindow(win1);
|
||||
}
|
||||
|
||||
add_task(function* test_pinned() {
|
||||
yield do_test_update(function background() {
|
||||
// Create a new tab for testing update.
|
||||
browser.tabs.create(null, function(tab) {
|
||||
browser.tabs.onUpdated.addListener(function onUpdated(tabId, changeInfo) {
|
||||
// Check callback
|
||||
browser.test.assertEq(tabId, tab.id, "Check tab id");
|
||||
browser.test.log("onUpdate: " + JSON.stringify(changeInfo));
|
||||
if ("pinned" in changeInfo) {
|
||||
browser.test.assertTrue(changeInfo.pinned, "Check changeInfo.pinned");
|
||||
browser.tabs.onUpdated.removeListener(onUpdated);
|
||||
// Remove created tab.
|
||||
browser.tabs.remove(tabId);
|
||||
browser.test.notifyPass("finish");
|
||||
return;
|
||||
}
|
||||
});
|
||||
browser.tabs.update(tab.id, {pinned: true});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
add_task(function* test_unpinned() {
|
||||
yield do_test_update(function background() {
|
||||
// Create a new tab for testing update.
|
||||
browser.tabs.create({pinned: true}, function(tab) {
|
||||
browser.tabs.onUpdated.addListener(function onUpdated(tabId, changeInfo) {
|
||||
// Check callback
|
||||
browser.test.assertEq(tabId, tab.id, "Check tab id");
|
||||
browser.test.log("onUpdate: " + JSON.stringify(changeInfo));
|
||||
if ("pinned" in changeInfo) {
|
||||
browser.test.assertFalse(changeInfo.pinned, "Check changeInfo.pinned");
|
||||
browser.tabs.onUpdated.removeListener(onUpdated);
|
||||
// Remove created tab.
|
||||
browser.tabs.remove(tabId);
|
||||
browser.test.notifyPass("finish");
|
||||
return;
|
||||
}
|
||||
});
|
||||
browser.tabs.update(tab.id, {pinned: false});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
add_task(function* test_url() {
|
||||
yield do_test_update(function background() {
|
||||
// Create a new tab for testing update.
|
||||
browser.tabs.create(null, function(tab) {
|
||||
browser.tabs.onUpdated.addListener(function onUpdated(tabId, changeInfo) {
|
||||
// Check callback
|
||||
browser.test.assertEq(tabId, tab.id, "Check tab id");
|
||||
browser.test.log("onUpdate: " + JSON.stringify(changeInfo));
|
||||
if ("url" in changeInfo) {
|
||||
browser.test.assertEq("about:preferences", changeInfo.url,
|
||||
"Check changeInfo.url");
|
||||
browser.tabs.onUpdated.removeListener(onUpdated);
|
||||
// Remove created tab.
|
||||
browser.tabs.remove(tabId);
|
||||
browser.test.notifyPass("finish");
|
||||
return;
|
||||
}
|
||||
});
|
||||
browser.tabs.update(tab.id, {url: "about:preferences"});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче