Backed out changeset 31d5dca2a3b4 (bug 801232) because of leaks

This commit is contained in:
Ehsan Akhgari 2012-12-06 14:01:35 -05:00
parent 2f2d76a5a5
commit c7fd5aa176
8 changed files with 88 additions and 257 deletions

View File

@ -44,8 +44,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "DownloadUtils",
"resource://gre/modules/DownloadUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
"resource:///modules/DownloadsCommon.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
////////////////////////////////////////////////////////////////////////////////
//// DownloadsPanel
@ -109,7 +107,7 @@ const DownloadsPanel = {
DownloadsOverlayLoader.ensureOverlayLoaded(this.kDownloadsOverlay,
function DP_I_callback() {
DownloadsViewController.initialize();
DownloadsCommon.getData(window).addView(DownloadsView);
DownloadsCommon.data.addView(DownloadsView);
DownloadsPanel._attachEventListeners();
aCallback();
});
@ -132,7 +130,7 @@ const DownloadsPanel = {
this.hidePanel();
DownloadsViewController.terminate();
DownloadsCommon.getData(window).removeView(DownloadsView);
DownloadsCommon.data.removeView(DownloadsView);
this._unattachEventListeners();
this._state = this.kStateUninitialized;
@ -232,7 +230,7 @@ const DownloadsPanel = {
this._state = this.kStateShown;
// Since at most one popup is open at any given time, we can set globally.
DownloadsCommon.getIndicatorData(window).attentionSuppressed = true;
DownloadsCommon.indicatorData.attentionSuppressed = true;
// Ensure that an item is selected when the panel is focused.
if (DownloadsView.richListBox.itemCount > 0 &&
@ -251,7 +249,7 @@ const DownloadsPanel = {
}
// Since at most one popup is open at any given time, we can set globally.
DownloadsCommon.getIndicatorData(window).attentionSuppressed = false;
DownloadsCommon.indicatorData.attentionSuppressed = false;
// Allow the anchor to be hidden.
DownloadsButton.releaseAnchor();
@ -1112,11 +1110,7 @@ const DownloadsViewController = {
{
// Handle commands that are not selection-specific.
if (aCommand == "downloadsCmd_clearList") {
if (PrivateBrowsingUtils.isWindowPrivate(window)) {
return Services.downloads.canCleanUpPrivate;
} else {
return Services.downloads.canCleanUp;
}
return Services.downloads.canCleanUp;
}
// Other commands are selection-specific.
@ -1163,11 +1157,7 @@ const DownloadsViewController = {
commands: {
downloadsCmd_clearList: function DVC_downloadsCmd_clearList()
{
if (PrivateBrowsingUtils.isWindowPrivate(window)) {
Services.downloads.cleanUpPrivate();
} else {
Services.downloads.cleanUp();
}
Services.downloads.cleanUp();
}
}
};
@ -1181,7 +1171,7 @@ const DownloadsViewController = {
*/
function DownloadsViewItemController(aElement) {
let downloadGuid = aElement.getAttribute("downloadGuid");
this.dataItem = DownloadsCommon.getData(window).dataItems[downloadGuid];
this.dataItem = DownloadsCommon.data.dataItems[downloadGuid];
}
DownloadsViewItemController.prototype = {
@ -1467,10 +1457,10 @@ const DownloadsSummary = {
return this._active;
}
if (aActive) {
DownloadsCommon.getSummary(window, DownloadsView.kItemCountLimit)
DownloadsCommon.getSummary(DownloadsView.kItemCountLimit)
.addView(this);
} else {
DownloadsCommon.getSummary(window, DownloadsView.kItemCountLimit)
DownloadsCommon.getSummary(DownloadsView.kItemCountLimit)
.removeView(this);
DownloadsFooter.showingSummary = false;
}

View File

@ -286,7 +286,7 @@ const DownloadsIndicatorView = {
this._initialized = true;
window.addEventListener("unload", this.onWindowUnload, false);
DownloadsCommon.getIndicatorData(window).addView(this);
DownloadsCommon.indicatorData.addView(this);
},
/**
@ -300,7 +300,7 @@ const DownloadsIndicatorView = {
this._initialized = false;
window.removeEventListener("unload", this.onWindowUnload, false);
DownloadsCommon.getIndicatorData(window).removeView(this);
DownloadsCommon.indicatorData.removeView(this);
// Reset the view properties, so that a neutral indicator is displayed if we
// are visible only temporarily as an anchor.
@ -327,7 +327,7 @@ const DownloadsIndicatorView = {
// If the view is initialized, we need to update the elements now that
// they are finally available in the document.
if (this._initialized) {
DownloadsCommon.getIndicatorData(window).refreshView(this);
DownloadsCommon.indicatorData.refreshView(this);
}
aCallback();
@ -508,7 +508,7 @@ const DownloadsIndicatorView = {
{
if (DownloadsCommon.useToolkitUI) {
// The panel won't suppress attention for us, we need to clear now.
DownloadsCommon.getIndicatorData(window).attention = false;
DownloadsCommon.indicatorData.attention = false;
BrowserDownloadsUI();
} else {
DownloadsPanel.showPanel();

View File

@ -56,10 +56,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
"resource://gre/modules/PluralForm.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "DownloadUtils",
"resource://gre/modules/DownloadUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
"resource:///modules/RecentWindow.jsm");
const nsIDM = Ci.nsIDownloadManager;
@ -177,95 +173,37 @@ this.DownloadsCommon = {
},
/**
* Get access to one of the DownloadsData or PrivateDownloadsData objects,
* depending on the privacy status of the window in question.
* Returns a reference to the DownloadsData singleton.
*
* @param aWindow
* The browser window which owns the download button.
* This does not need to be a lazy getter, since no initialization is required
* at present.
*/
getData: function DC_getData(aWindow) {
if (PrivateBrowsingUtils.isWindowPrivate(aWindow)) {
return PrivateDownloadsData;
} else {
return DownloadsData;
}
},
get data() DownloadsData,
/**
* Initializes the data link for both the private and non-private downloads
* data objects.
* Returns a reference to the DownloadsData singleton.
*
* @param aDownloadManagerService
* Reference to the service implementing nsIDownloadManager. We need
* this because getService isn't available for us when this method is
* called, and we must ensure to register our listeners before the
* getService call for the Download Manager returns.
* This does not need to be a lazy getter, since no initialization is required
* at present.
*/
initializeAllDataLinks: function DC_initializeAllDataLinks(aDownloadManagerService) {
DownloadsData.initializeDataLink(aDownloadManagerService);
PrivateDownloadsData.initializeDataLink(aDownloadManagerService);
},
/**
* Terminates the data link for both the private and non-private downloads
* data objects.
*/
terminateAllDataLinks: function DC_terminateAllDataLinks() {
DownloadsData.terminateDataLink();
PrivateDownloadsData.terminateDataLink();
},
/**
* Reloads the specified kind of downloads from the non-private store.
* This method must only be called when Private Browsing Mode is disabled.
*
* @param aActiveOnly
* True to load only active downloads from the database.
*/
ensureAllPersistentDataLoaded:
function DC_ensureAllPersistentDataLoaded(aActiveOnly) {
DownloadsData.ensurePersistentDataLoaded(aActiveOnly);
},
/**
* Get access to one of the DownloadsIndicatorData or
* PrivateDownloadsIndicatorData objects, depending on the privacy status of
* the window in question.
*/
getIndicatorData: function DC_getIndicatorData(aWindow) {
if (PrivateBrowsingUtils.isWindowPrivate(aWindow)) {
return PrivateDownloadsIndicatorData;
} else {
return DownloadsIndicatorData;
}
},
get indicatorData() DownloadsIndicatorData,
/**
* Returns a reference to the DownloadsSummaryData singleton - creating one
* in the process if one hasn't been instantiated yet.
*
* @param aWindow
* The browser window which owns the download button.
* @param aNumToExclude
* The number of items on the top of the downloads list to exclude
* from the summary.
*/
getSummary: function DC_getSummary(aWindow, aNumToExclude)
{
if (PrivateBrowsingUtils.isWindowPrivate(aWindow)) {
if (this._privateSummary) {
return this._privateSummary;
}
return this._privateSummary = new DownloadsSummaryData(true, aNumToExclude);
} else {
if (this._summary) {
return this._summary;
}
return this._summary = new DownloadsSummaryData(false, aNumToExclude);
}
},
_summary: null,
_privateSummary: null,
getSummary: function DC_getSummary(aNumToExclude)
{
if (this._summary) {
return this._summary;
}
return this._summary = new DownloadsSummaryData(aNumToExclude);
},
/**
* Given an iterable collection of DownloadDataItems, generates and returns
@ -416,33 +354,8 @@ XPCOMUtils.defineLazyGetter(DownloadsCommon, "isWinVistaOrHigher", function () {
* service. Consumers will see an empty list of downloads until the service is
* actually started. This is useful to display a neutral progress indicator in
* the main browser window until the autostart timeout elapses.
*
* Note that DownloadsData and PrivateDownloadsData are two equivalent singleton
* objects, one accessing non-private downloads, and the other accessing private
* ones.
*/
function DownloadsDataCtor(aPrivate) {
this._isPrivate = aPrivate;
// This Object contains all the available DownloadsDataItem objects, indexed by
// their globally unique identifier. The identifiers of downloads that have
// been removed from the Download Manager data are still present, however the
// associated objects are replaced with the value "null". This is required to
// prevent race conditions when populating the list asynchronously.
this.dataItems = {};
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
// While operating in Private Browsing Mode, persistent data items are parked
// here until we return to the normal mode.
this._persistentDataItems = {};
#endif
// Array of view objects that should be notified when the available download
// data changes.
this._views = [];
}
DownloadsDataCtor.prototype = {
const DownloadsData = {
/**
* Starts receiving events for current downloads.
*
@ -455,12 +368,10 @@ DownloadsDataCtor.prototype = {
initializeDataLink: function DD_initializeDataLink(aDownloadManagerService)
{
// Start receiving real-time events.
aDownloadManagerService.addPrivacyAwareListener(this);
aDownloadManagerService.addListener(this);
Services.obs.addObserver(this, "download-manager-remove-download-guid", false);
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
Services.obs.addObserver(this, "download-manager-database-type-changed",
false);
#endif
},
/**
@ -471,9 +382,7 @@ DownloadsDataCtor.prototype = {
this._terminateDataAccess();
// Stop receiving real-time events.
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
Services.obs.removeObserver(this, "download-manager-database-type-changed");
#endif
Services.obs.removeObserver(this, "download-manager-remove-download-guid");
Services.downloads.removeListener(this);
},
@ -481,6 +390,12 @@ DownloadsDataCtor.prototype = {
//////////////////////////////////////////////////////////////////////////////
//// Registration of views
/**
* Array of view objects that should be notified when the available download
* data changes.
*/
_views: [],
/**
* Adds an object to be notified when the available download data changes.
* The specified object is initialized with the currently available downloads.
@ -539,6 +454,21 @@ DownloadsDataCtor.prototype = {
//////////////////////////////////////////////////////////////////////////////
//// In-memory downloads data store
/**
* Object containing all the available DownloadsDataItem objects, indexed by
* their numeric download identifier. The identifiers of downloads that have
* been removed from the Download Manager data are still present, however the
* associated objects are replaced with the value "null". This is required to
* prevent race conditions when populating the list asynchronously.
*/
dataItems: {},
/**
* While operating in Private Browsing Mode, persistent data items are parked
* here until we return to the normal mode.
*/
_persistentDataItems: {},
/**
* Clears the loaded data.
*/
@ -661,9 +591,7 @@ DownloadsDataCtor.prototype = {
// Reload the list using the Download Manager service. The list is
// returned in no particular order.
let downloads = this._isPrivate ?
Services.downloads.activePrivateDownloads :
Services.downloads.activeDownloads;
let downloads = Services.downloads.activeDownloads;
while (downloads.hasMoreElements()) {
let download = downloads.getNext().QueryInterface(Ci.nsIDownload);
this._getOrAddDataItem(download, true);
@ -681,10 +609,7 @@ DownloadsDataCtor.prototype = {
// columns are read in the _initFromDataRow method of DownloadsDataItem.
// Order by descending download identifier so that the most recent
// downloads are notified first to the listening views.
let dbConnection = this._isPrivate ?
Services.downloads.privateDBConnection :
Services.downloads.DBConnection;
let statement = dbConnection.createAsyncStatement(
let statement = Services.downloads.DBConnection.createAsyncStatement(
"SELECT guid, target, name, source, referrer, state, "
+ "startTime, endTime, currBytes, maxBytes "
+ "FROM moz_downloads "
@ -789,7 +714,6 @@ DownloadsDataCtor.prototype = {
}
break;
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
case "download-manager-database-type-changed":
let pbs = Cc["@mozilla.org/privatebrowsing;1"]
.getService(Ci.nsIPrivateBrowsingService);
@ -807,7 +731,6 @@ DownloadsDataCtor.prototype = {
// already invalidated by the previous calls.
this._views.forEach(this._updateView, this);
break;
#endif
}
},
@ -816,12 +739,6 @@ DownloadsDataCtor.prototype = {
onDownloadStateChange: function DD_onDownloadStateChange(aState, aDownload)
{
if (aDownload.isPrivate != this._isPrivate) {
// Ignore the downloads with a privacy status other than what we are
// tracking.
return;
}
// When a new download is added, it may have the same identifier of a
// download that we previously deleted during this session, and we also
// want to provide a visible indication that the download started.
@ -867,12 +784,6 @@ DownloadsDataCtor.prototype = {
aCurTotalProgress,
aMaxTotalProgress, aDownload)
{
if (aDownload.isPrivate != this._isPrivate) {
// Ignore the downloads with a privacy status other than what we are
// tracking.
return;
}
let dataItem = this._getOrAddDataItem(aDownload, false);
if (!dataItem) {
return;
@ -922,7 +833,7 @@ DownloadsDataCtor.prototype = {
}
// Show the panel in the most recent browser window, if present.
let browserWin = RecentWindow.getMostRecentBrowserWindow({ private: this._isPrivate });
let browserWin = gBrowserGlue.getMostRecentBrowserWindow();
if (!browserWin) {
return;
}
@ -939,14 +850,6 @@ DownloadsDataCtor.prototype = {
}
};
XPCOMUtils.defineLazyGetter(this, "PrivateDownloadsData", function() {
return new DownloadsDataCtor(true);
});
XPCOMUtils.defineLazyGetter(this, "DownloadsData", function() {
return new DownloadsDataCtor(false);
});
////////////////////////////////////////////////////////////////////////////////
//// DownloadsDataItem
@ -1213,18 +1116,8 @@ const DownloadsViewPrototype = {
/**
* Array of view objects that should be notified when the available status
* data changes.
*
* SUBCLASSES MUST OVERRIDE THIS PROPERTY.
*/
_views: null,
/**
* Determines whether this view object is over the private or non-private
* downloads.
*
* SUBCLASSES MUST OVERRIDE THIS PROPERTY.
*/
_isPrivate: false,
_views: [],
/**
* Adds an object to be notified when the available status data changes.
@ -1238,11 +1131,7 @@ const DownloadsViewPrototype = {
{
// Start receiving events when the first of our views is registered.
if (this._views.length == 0) {
if (this._isPrivate) {
PrivateDownloadsData.addView(this);
} else {
DownloadsData.addView(this);
}
DownloadsCommon.data.addView(this);
}
this._views.push(aView);
@ -1278,11 +1167,7 @@ const DownloadsViewPrototype = {
// Stop receiving events when the last of our views is unregistered.
if (this._views.length == 0) {
if (this._isPrivate) {
PrivateDownloadsData.removeView(this);
} else {
DownloadsData.removeView(this);
}
DownloadsCommon.data.removeView(this);
}
},
@ -1406,10 +1291,7 @@ const DownloadsViewPrototype = {
* actually started. This is useful to display a neutral progress indicator in
* the main browser window until the autostart timeout elapses.
*/
function DownloadsIndicatorDataCtor(aPrivate) {
this._isPrivate = aPrivate;
}
DownloadsIndicatorDataCtor.prototype = {
const DownloadsIndicatorData = {
__proto__: DownloadsViewPrototype,
/**
@ -1491,25 +1373,23 @@ DownloadsIndicatorDataCtor.prototype = {
*/
getViewItem: function DID_getViewItem(aDataItem)
{
let data = this._isPrivate ? PrivateDownloadsIndicatorData
: DownloadsIndicatorData;
return Object.freeze({
onStateChange: function DIVI_onStateChange()
{
if (aDataItem.state == nsIDM.DOWNLOAD_FINISHED ||
aDataItem.state == nsIDM.DOWNLOAD_FAILED) {
data.attention = true;
DownloadsIndicatorData.attention = true;
}
// Since the state of a download changed, reset the estimated time left.
data._lastRawTimeLeft = -1;
data._lastTimeLeft = -1;
DownloadsIndicatorData._lastRawTimeLeft = -1;
DownloadsIndicatorData._lastTimeLeft = -1;
data._updateViews();
DownloadsIndicatorData._updateViews();
},
onProgressChange: function DIVI_onProgressChange()
{
data._updateViews();
DownloadsIndicatorData._updateViews();
}
});
},
@ -1609,9 +1489,7 @@ DownloadsIndicatorDataCtor.prototype = {
*/
_activeDataItems: function DID_activeDataItems()
{
let dataItems = this._isPrivate ? PrivateDownloadsData.dataItems
: DownloadsData.dataItems;
for each (let dataItem in dataItems) {
for each (let dataItem in DownloadsCommon.data.dataItems) {
if (dataItem && dataItem.inProgress) {
yield dataItem;
}
@ -1651,15 +1529,7 @@ DownloadsIndicatorDataCtor.prototype = {
this._counter = DownloadsCommon.formatTimeLeft(this._lastTimeLeft);
}
}
};
XPCOMUtils.defineLazyGetter(this, "PrivateDownloadsIndicatorData", function() {
return new DownloadsIndicatorDataCtor(true);
});
XPCOMUtils.defineLazyGetter(this, "DownloadsIndicatorData", function() {
return new DownloadsIndicatorDataCtor(false);
});
}
////////////////////////////////////////////////////////////////////////////////
//// DownloadsSummaryData
@ -1671,18 +1541,16 @@ XPCOMUtils.defineLazyGetter(this, "DownloadsIndicatorData", function() {
* constructed with aNumToExclude equal to 3, then that DownloadsSummaryData
* would produce a summary of the last 2 downloads.
*
* @param aIsPrivate
* True if the browser window which owns the download button is a private
* window.
* @param aNumToExclude
* The number of items to exclude from the summary, starting from the
* top of the list.
*/
function DownloadsSummaryData(aIsPrivate, aNumToExclude) {
function DownloadsSummaryData(aNumToExclude) {
this._numToExclude = aNumToExclude;
// Since we can have multiple instances of DownloadsSummaryData, we
// override these values from the prototype so that each instance can be
// completely separated from one another.
this._views = [];
this._loading = false;
this._dataItems = [];
@ -1706,9 +1574,6 @@ function DownloadsSummaryData(aIsPrivate, aNumToExclude) {
this._description = "";
this._numActive = 0;
this._percentComplete = -1;
this._isPrivate = aIsPrivate;
this._views = [];
}
DownloadsSummaryData.prototype = {

View File

@ -31,22 +31,16 @@ XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
XPCOMUtils.defineLazyServiceGetter(this, "gSessionStartup",
"@mozilla.org/browser/sessionstartup;1",
"nsISessionStartup");
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
XPCOMUtils.defineLazyServiceGetter(this, "gPrivateBrowsingService",
"@mozilla.org/privatebrowsing;1",
"nsIPrivateBrowsingService");
#endif
const kObservedTopics = [
"sessionstore-windows-restored",
"sessionstore-browser-state-restored",
"download-manager-initialized",
"download-manager-change-retention",
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
"last-pb-context-exited",
#else
"private-browsing-transition-complete",
#endif
"browser-lastwindow-close-granted",
"quit-application",
"profile-change-teardown",
@ -119,8 +113,8 @@ DownloadsStartup.prototype = {
// Start receiving events for active and new downloads before we return
// from this observer function. We can't defer the execution of this
// step, to ensure that we don't lose events raised in the meantime.
DownloadsCommon.initializeAllDataLinks(
aSubject.QueryInterface(Ci.nsIDownloadManager));
DownloadsCommon.data.initializeDataLink(
aSubject.QueryInterface(Ci.nsIDownloadManager));
this._downloadsServiceInitialized = true;
@ -145,13 +139,11 @@ DownloadsStartup.prototype = {
}
break;
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
case "private-browsing-transition-complete":
// Ensure that persistent data is reloaded only when the database
// connection is available again.
this._ensureDataLoaded();
break;
#endif
case "browser-lastwindow-close-granted":
// When using the panel interface, downloads that are already completed
@ -166,16 +158,6 @@ DownloadsStartup.prototype = {
}
break;
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
case "last-pb-context-exited":
// Similar to the above notification, but for private downloads.
if (this._downloadsServiceInitialized &&
!DownloadsCommon.useToolkitUI) {
Services.downloads.cleanUpPrivate();
}
break;
#endif
case "quit-application":
// When the application is shutting down, we must free all resources in
// addition to cleaning up completed downloads. If the Download Manager
@ -187,7 +169,7 @@ DownloadsStartup.prototype = {
break;
}
DownloadsCommon.terminateAllDataLinks();
DownloadsCommon.data.terminateDataLink();
// When using the panel interface, downloads that are already completed
// should be removed when quitting the application.
@ -276,18 +258,15 @@ DownloadsStartup.prototype = {
*/
_ensureDataLoaded: function DS_ensureDataLoaded()
{
if (!this._downloadsServiceInitialized
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
|| gPrivateBrowsingService.privateBrowsingEnabled
#endif
) {
if (!this._downloadsServiceInitialized ||
gPrivateBrowsingService.privateBrowsingEnabled) {
return;
}
// If the previous session has been already restored, then we ensure that
// all the downloads are loaded. Otherwise, we only ensure that the active
// downloads from the previous session are loaded.
DownloadsCommon.ensureAllPersistentDataLoaded(!this._recoverAllDownloads);
DownloadsCommon.data.ensurePersistentDataLoaded(!this._recoverAllDownloads);
}
};

View File

@ -11,14 +11,11 @@ include $(DEPTH)/config/autoconf.mk
EXTRA_COMPONENTS = \
BrowserDownloads.manifest \
DownloadsStartup.js \
DownloadsUI.js \
$(NULL)
EXTRA_PP_COMPONENTS = \
DownloadsStartup.js \
$(NULL)
EXTRA_PP_JS_MODULES = \
EXTRA_JS_MODULES = \
DownloadsCommon.jsm \
$(NULL)

View File

@ -33,13 +33,13 @@ function gen_test()
try {
// Ensure that state is reset in case previous tests didn't finish.
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield;
for (let yy in gen_resetState()) yield;
// Populate the downloads database with the data required by this test.
for (let yy in gen_addDownloadRows(DownloadData)) yield;
// Open the user interface and wait for data to be fully loaded.
for (let yy in gen_openPanel(DownloadsCommon.getData(window))) yield;
for (let yy in gen_openPanel()) yield;
// Test item data and count. This also tests the ordering of the display.
let richlistbox = document.getElementById("downloadsListBox");
@ -57,6 +57,6 @@ function gen_test()
}
} finally {
// Clean up when the test finishes.
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield;
for (let yy in gen_resetState()) yield;
}
}

View File

@ -12,32 +12,32 @@ function gen_test()
{
try {
// Ensure that state is reset in case previous tests didn't finish.
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield;
for (let yy in gen_resetState()) yield;
// With this set to false, we should automatically open the panel
// the first time a download is started.
DownloadsCommon.getData(window).panelHasShownBefore = false;
DownloadsCommon.data.panelHasShownBefore = false;
prepareForPanelOpen();
DownloadsCommon.getData(window)._notifyNewDownload();
DownloadsCommon.data._notifyNewDownload();
yield;
// If we got here, that means the panel opened.
DownloadsPanel.hidePanel();
ok(DownloadsCommon.getData(window).panelHasShownBefore,
ok(DownloadsCommon.data.panelHasShownBefore,
"Should have recorded that the panel was opened on a download.")
// Next, make sure that if we start another download, we don't open
// the panel automatically.
panelShouldNotOpen();
DownloadsCommon.getData(window)._notifyNewDownload();
DownloadsCommon.data._notifyNewDownload();
yield waitFor(2);
} catch(e) {
ok(false, e);
} finally {
// Clean up when the test finishes.
for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield;
for (let yy in gen_resetState()) yield;
}
}

View File

@ -130,7 +130,7 @@ var testRunner = {
// for (let yy in gen_example("Parameter")) yield;
//
function gen_resetState(aData)
function gen_resetState()
{
let statement = Services.downloads.DBConnection.createAsyncStatement(
"DELETE FROM moz_downloads");
@ -155,8 +155,8 @@ function gen_resetState(aData)
Services.prefs.clearUserPref("browser.download.panel.shown");
// Ensure that the panel is closed and data is unloaded.
aData.clear();
aData._loadState = aData.kLoadNone;
DownloadsCommon.data.clear();
DownloadsCommon.data._loadState = DownloadsCommon.data.kLoadNone;
DownloadsPanel.hidePanel();
// Wait for focus on the main window.
@ -224,7 +224,7 @@ function gen_openPanel(aData)
};
// Start loading all the downloads from the database asynchronously.
aData.ensurePersistentDataLoaded(false);
DownloadsCommon.data.ensurePersistentDataLoaded(false);
// Wait for focus on the main window.
waitForFocus(testRunner.continueTest);