diff --git a/toolkit/components/aboutperformance/content/aboutPerformance.js b/toolkit/components/aboutperformance/content/aboutPerformance.js index b6e846baf845..67e0403f51c2 100644 --- a/toolkit/components/aboutperformance/content/aboutPerformance.js +++ b/toolkit/components/aboutperformance/content/aboutPerformance.js @@ -69,51 +69,30 @@ const MIN_PROPORTION_FOR_NOTICEABLE_IMPACT = .1; const MODE_GLOBAL = "global"; const MODE_RECENT = "recent"; -let tabFinder = { - update: function() { - this._map = new Map(); - let windows = Services.wm.getEnumerator("navigator:browser"); - while (windows.hasMoreElements()) { - let win = windows.getNext(); - let tabbrowser = win.gBrowser; - for (let browser of tabbrowser.browsers) { - let id = browser.outerWindowID; // May be `null` if the browser isn't loaded yet - if (id != null) { - this._map.set(id, browser); - } +/** + * Find the for a window id. + * + * This is useful e.g. for reloading or closing tabs. + * + * @return null If the xul:tab could not be found, e.g. if the + * windowId is that of a chrome window. + * @return {{tabbrowser: , tab: }} The + * tabbrowser and tab if the latter could be found. + */ +function findTabFromWindow(windowIds) { + let windows = Services.wm.getEnumerator("navigator:browser"); + while (windows.hasMoreElements()) { + let win = windows.getNext(); + let tabbrowser = win.gBrowser; + for (let windowId of windowIds) { + let foundBrowser = tabbrowser.getBrowserForOuterWindowID(windowId); + if (foundBrowser) { + return {tabbrowser, tab: tabbrowser.getTabForBrowser(foundBrowser)}; } } - }, - - /** - * Find the for a window id. - * - * This is useful e.g. for reloading or closing tabs. - * - * @return null If the xul:tab could not be found, e.g. if the - * windowId is that of a chrome window. - * @return {{tabbrowser: , tab: }} The - * tabbrowser and tab if the latter could be found. - */ - get: function(id) { - let browser = this._map.get(id); - if (!browser) { - return null; - } - let tabbrowser = browser.getTabBrowser(); - return {tabbrowser, tab:tabbrowser.getTabForBrowser(browser)}; - }, - - getAny: function(ids) { - for (let id of ids) { - let result = this.get(id); - if (result) { - return result; - } - } - return null; } -}; + return null; +} function wait(ms = 0) { return new Promise(resolve => setTimeout(resolve, ms)); @@ -246,13 +225,22 @@ Delta.prototype = { }, _initWebpage: function() { this._initialized = true; - let found = tabFinder.getAny(this.diff.windowIds); - if (!found || found.tab.linkedBrowser.contentTitle == null) { + if (!this.diff.title) { // Either this is not a real page or the page isn't restored yet. return; } - this.readableName = found.tab.linkedBrowser.contentTitle; + // Wallpaper hack. For some reason, about:performance (and only about:performance) + // appears twice in the list. Only one of them is a window. + + if (this.diff.title == document.title) { + if (!findTabFromWindow(this.diff.windowIds)) { + // Not a real page. + return; + } + } + + this.readableName = this.diff.title; this.fullName = this.diff.names.join(", "); this._show = true; }, @@ -451,7 +439,6 @@ var State = { throw new TypeError(); } - tabFinder.update(); // We rebuild the maps during each iteration to make sure that // we do not maintain references to groups that has been removed // (e.g. pages that have been closed). @@ -786,7 +773,7 @@ var View = { eltSpan.appendChild(eltCloseTab); let windowIds = delta.diff.windowIds; eltCloseTab.addEventListener("click", () => { - let found = tabFinder.getAny(windowIds); + let found = findTabFromWindow(windowIds); if (!found) { // Cannot find the tab. Maybe it is closed already? return; @@ -799,7 +786,7 @@ var View = { eltReloadTab.textContent = "Reload tab"; eltSpan.appendChild(eltReloadTab); eltReloadTab.addEventListener("click", () => { - let found = tabFinder.getAny(windowIds); + let found = findTabFromWindow(windowIds); if (!found) { // Cannot find the tab. Maybe it is closed already? return; @@ -842,7 +829,7 @@ var Control = { }, update: Task.async(function*() { let mode = this._displayMode; - if (this._autoRefreshInterval || !State._buffer[0]) { + if (this._autoRefreshInterval) { // Update the state only if we are not on pause. yield State.update(); } @@ -866,7 +853,6 @@ var Control = { Services.obs.notifyObservers(null, UPDATE_COMPLETE_TOPIC, mode); }), _setOptions: function(options) { - dump(`about:performance _setOptions ${JSON.stringify(options)}\n`); let eltRefresh = document.getElementById("check-autorefresh"); if ((options.autoRefresh > 0) != eltRefresh.checked) { eltRefresh.click(); diff --git a/toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js b/toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js index b8188cd80160..de829ff2ff06 100644 --- a/toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js +++ b/toolkit/components/aboutperformance/tests/browser/browser_aboutperformance.js @@ -226,10 +226,12 @@ var promiseExpectContent = Task.async(function*(options) { // Test that we can find the title of a webpage in about:performance add_task(function* test_find_title() { - for (let displayRecent of [true, false]) { - info(`Testing with autoRefresh, in ${displayRecent?"recent":"global"} mode`); - let found = yield promiseExpectContent({autoRefresh: 100, displayRecent}); - Assert.ok(found, `The page title appears when about:performance is set to auto-refresh`); + for (let autoRefresh of [100, -1]) { + for (let displayRecent of [true, false]) { + info(`Testing ${autoRefresh > 0?"with":"without"} autoRefresh, in ${displayRecent?"recent":"global"} mode`); + let found = yield promiseExpectContent({autoRefresh, displayRecent}); + Assert.equal(found, autoRefresh > 0, "The page title appears iff about:performance is set to auto-refresh"); + } } }); diff --git a/toolkit/components/perfmonitoring/tests/browser/browser_compartments.js b/toolkit/components/perfmonitoring/tests/browser/browser_compartments.js index 76d1b88dfac5..6fb9fec2137f 100644 --- a/toolkit/components/perfmonitoring/tests/browser/browser_compartments.js +++ b/toolkit/components/perfmonitoring/tests/browser/browser_compartments.js @@ -177,7 +177,7 @@ function monotinicity_tester(source, testName) { let key = item.groupId; if (map.has(key)) { let old = map.get(key); - Assert.ok(false, `Component ${key} has already been seen. Latest: ${item.addonId||item.name}, previous: ${old.addonId||old.name}`); + Assert.ok(false, `Component ${key} has already been seen. Latest: ${item.title||item.addonId||item.name}, previous: ${old.title||old.addonId||old.name}`); } map.set(key, item); } @@ -254,33 +254,10 @@ add_task(function* test() { let {snapshot: stats} = (yield promiseContentResponse(browser, "compartments-test:getStatistics", null)); - // Attach titles to components. - let titles = []; - let map = new Map(); - let windows = Services.wm.getEnumerator("navigator:browser"); - while (windows.hasMoreElements()) { - let window = windows.getNext(); - let tabbrowser = window.gBrowser; - for (let browser of tabbrowser.browsers) { - let id = browser.outerWindowID; // May be `null` if the browser isn't loaded yet - if (id != null) { - map.set(id, browser); - } - } - } + let titles = [for(stat of stats.componentsData) stat.title]; + for (let stat of stats.componentsData) { - if (!stat.windowId) { - continue; - } - let browser = map.get(stat.windowId); - if (!browser) { - continue; - } - let title = browser.contentTitle; - if (title) { - stat.title = title; - titles.push(title); - } + info(`Compartment: ${stat.name} => ${stat.title} (${stat.isSystem?"system":"web"})`); } // While the webpage consists in three compartments, we should see only