From 1d3fa122996e943d3d9080720a20eca2c4103267 Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Thu, 15 Mar 2012 23:28:22 +0100 Subject: [PATCH] Bug 735574 - Extremely frequent leak of 1 BackstagePass, 2 Mutex, 9 ProxyListener coming from fx-team; r=dietrich --- .../test/newtab/browser_newtab_block.js | 6 +-- browser/base/content/test/newtab/head.js | 39 +++++++++++++------ browser/modules/NewTabUtils.jsm | 10 +++-- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/browser/base/content/test/newtab/browser_newtab_block.js b/browser/base/content/test/newtab/browser_newtab_block.js index 6bb168333f6..97a83b4e186 100644 --- a/browser/base/content/test/newtab/browser_newtab_block.js +++ b/browser/base/content/test/newtab/browser_newtab_block.js @@ -25,7 +25,7 @@ function runTests() { checkGrid("0,1,2,3,7,8,9,,"); // we removed a pinned site - reset(); + yield restore(); setLinks("0,1,2,3,4,5,6,7,8"); setPinnedLinks(",1"); @@ -37,7 +37,7 @@ function runTests() { // we remove the last site on the grid (which is pinned) and expect the gap // to be re-filled and the new site to be unpinned - reset(); + yield restore(); setLinks("0,1,2,3,4,5,6,7,8,9"); setPinnedLinks(",,,,,,,,8"); @@ -49,7 +49,7 @@ function runTests() { // we remove the first site on the grid with the last one pinned. all cells // but the last one should shift to the left and a new site fades in - reset(); + yield restore(); setLinks("0,1,2,3,4,5,6,7,8,9"); setPinnedLinks(",,,,,,,,8"); diff --git a/browser/base/content/test/newtab/head.js b/browser/base/content/test/newtab/head.js index c4c7cb24c17..2c8bddf39b1 100644 --- a/browser/base/content/test/newtab/head.js +++ b/browser/base/content/test/newtab/head.js @@ -10,8 +10,6 @@ Cu.import("resource:///modules/NewTabUtils.jsm", tmp); let NewTabUtils = tmp.NewTabUtils; registerCleanupFunction(function () { - reset(); - while (gBrowser.tabs.length > 1) gBrowser.removeTab(gBrowser.tabs[1]); @@ -57,8 +55,29 @@ let TestRunner = { try { TestRunner._iter.next(); } catch (e if e instanceof StopIteration) { - finish(); + TestRunner.finish(); } + }, + + /** + * Finishes all tests and cleans up. + */ + finish: function () { + function cleanupAndFinish() { + // Restore the old provider. + NewTabUtils.links._provider = originalProvider; + + whenPagesUpdated(finish); + NewTabUtils.restore(); + } + + let callbacks = NewTabUtils.links._populateCallbacks; + let numCallbacks = callbacks.length; + + if (numCallbacks) + callbacks.splice(0, numCallbacks, cleanupAndFinish); + else + cleanupAndFinish(); } }; @@ -106,13 +125,11 @@ function setPinnedLinks(aLinksPattern) { } /** - * Resets the lists of blocked and pinned links and clears the storage. + * Restore the grid state. */ -function reset() { - NewTabUtils.reset(); - - // Restore the old provider to prevent memory leaks. - NewTabUtils.links._provider = originalProvider; +function restore() { + whenPagesUpdated(); + NewTabUtils.restore(); } /** @@ -269,11 +286,11 @@ function simulateDrop(aDropTarget, aDragSource) { /** * Resumes testing when all pages have been updated. */ -function whenPagesUpdated() { +function whenPagesUpdated(aCallback) { let page = { update: function () { NewTabUtils.allPages.unregister(this); - executeSoon(TestRunner.next); + executeSoon(aCallback || TestRunner.next); } }; diff --git a/browser/modules/NewTabUtils.jsm b/browser/modules/NewTabUtils.jsm index 072b970a370..e2fff6cd50e 100644 --- a/browser/modules/NewTabUtils.jsm +++ b/browser/modules/NewTabUtils.jsm @@ -550,7 +550,7 @@ let Links = { * Resets the links cache. */ resetCache: function Links_resetCache() { - this._links = []; + this._links = null; }, /** @@ -584,13 +584,17 @@ let Links = { */ let NewTabUtils = { /** - * Resets the NewTabUtils module, its links and its storage. + * Restores all sites that have been removed from the grid. */ - reset: function NewTabUtils_reset() { + restore: function NewTabUtils_restore() { Storage.clear(); Links.resetCache(); PinnedLinks.resetCache(); BlockedLinks.resetCache(); + + Links.populateCache(function () { + AllPages.update(); + }, true); }, allPages: AllPages,