mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 766263 - Part 2: Add a regression test. r=mak.
This commit is contained in:
parent
41924d2689
commit
0aecb71180
@ -12,6 +12,7 @@ include $(DEPTH)/config/autoconf.mk
|
|||||||
|
|
||||||
MOCHITEST_BROWSER_FILES = \
|
MOCHITEST_BROWSER_FILES = \
|
||||||
browser_basic_functionality.js \
|
browser_basic_functionality.js \
|
||||||
|
browser_first_download_panel.js \
|
||||||
head.js \
|
head.js \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set ts=2 et sw=2 tw=80: */
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure the downloads panel only opens automatically on the first
|
||||||
|
* download it notices. All subsequent downloads, even across sessions, should
|
||||||
|
* not open the panel automatically.
|
||||||
|
*/
|
||||||
|
function gen_test()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Ensure that state is reset in case previous tests didn't finish.
|
||||||
|
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.data.panelHasShownBefore = false;
|
||||||
|
|
||||||
|
prepareForPanelOpen();
|
||||||
|
DownloadsCommon.data._notifyNewDownload();
|
||||||
|
yield;
|
||||||
|
|
||||||
|
// If we got here, that means the panel opened.
|
||||||
|
DownloadsPanel.hidePanel();
|
||||||
|
|
||||||
|
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.data._notifyNewDownload();
|
||||||
|
yield waitFor(2);
|
||||||
|
} catch(e) {
|
||||||
|
ok(false, e);
|
||||||
|
} finally {
|
||||||
|
// Clean up when the test finishes.
|
||||||
|
for (let yy in gen_resetState()) yield;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call this to record a test failure for the next time the downloads panel
|
||||||
|
* opens.
|
||||||
|
*/
|
||||||
|
function panelShouldNotOpen()
|
||||||
|
{
|
||||||
|
// Hook to wait until the test data has been loaded.
|
||||||
|
let originalOnViewLoadCompleted = DownloadsPanel.onViewLoadCompleted;
|
||||||
|
DownloadsPanel.onViewLoadCompleted = function () {
|
||||||
|
DownloadsPanel.onViewLoadCompleted = originalOnViewLoadCompleted;
|
||||||
|
ok(false, "Should not have opened the downloads panel.");
|
||||||
|
};
|
||||||
|
}
|
@ -12,7 +12,8 @@
|
|||||||
|
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
||||||
"resource://gre/modules/FileUtils.jsm");
|
"resource://gre/modules/FileUtils.jsm");
|
||||||
|
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
|
||||||
|
"resource:///modules/DownloadsCommon.jsm");
|
||||||
const nsIDM = Ci.nsIDownloadManager;
|
const nsIDM = Ci.nsIDownloadManager;
|
||||||
|
|
||||||
let gTestTargetFile = FileUtils.getFile("TmpD", ["dm-ui-test.file"]);
|
let gTestTargetFile = FileUtils.getFile("TmpD", ["dm-ui-test.file"]);
|
||||||
@ -150,9 +151,13 @@ function gen_resetState()
|
|||||||
statement.finalize();
|
statement.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset any prefs that might have been changed.
|
||||||
|
Services.prefs.clearUserPref("browser.download.panel.shown");
|
||||||
|
|
||||||
// Ensure that the panel is closed and data is unloaded.
|
// Ensure that the panel is closed and data is unloaded.
|
||||||
DownloadsCommon.data.clear();
|
DownloadsCommon.data.clear();
|
||||||
DownloadsCommon.data._loadState = DownloadsCommon.data.kLoadNone;
|
DownloadsCommon.data._loadState = DownloadsCommon.data.kLoadNone;
|
||||||
|
DownloadsPanel.hidePanel();
|
||||||
|
|
||||||
// Wait for focus on the main window.
|
// Wait for focus on the main window.
|
||||||
waitForFocus(testRunner.continueTest);
|
waitForFocus(testRunner.continueTest);
|
||||||
@ -227,3 +232,41 @@ function gen_openPanel(aData)
|
|||||||
DownloadsPanel.showPanel();
|
DownloadsPanel.showPanel();
|
||||||
yield;
|
yield;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spin the event loop for aSeconds seconds, and then signal the test to
|
||||||
|
* continue.
|
||||||
|
*
|
||||||
|
* @param aSeconds the number of seconds to wait.
|
||||||
|
* @note This helper should _only_ be used when there's no valid event to
|
||||||
|
* listen to and one can't be made.
|
||||||
|
*/
|
||||||
|
function waitFor(aSeconds)
|
||||||
|
{
|
||||||
|
setTimeout(function() {
|
||||||
|
testRunner.continueTest();
|
||||||
|
}, aSeconds * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make it so that the next time the downloads panel opens, we signal to
|
||||||
|
* continue the test. This function needs to be called each time you want
|
||||||
|
* to wait for the panel to open.
|
||||||
|
*
|
||||||
|
* Example usage:
|
||||||
|
*
|
||||||
|
* prepareForPanelOpen();
|
||||||
|
* // Do something to open the panel
|
||||||
|
* yield;
|
||||||
|
* // We can assume the panel is open now.
|
||||||
|
*/
|
||||||
|
function prepareForPanelOpen()
|
||||||
|
{
|
||||||
|
// Hook to wait until the test data has been loaded.
|
||||||
|
let originalOnPopupShown = DownloadsPanel.onPopupShown;
|
||||||
|
DownloadsPanel.onPopupShown = function (aEvent) {
|
||||||
|
DownloadsPanel.onPopupShown = originalOnPopupShown;
|
||||||
|
DownloadsPanel.onPopupShown.apply(this, [aEvent]);
|
||||||
|
testRunner.continueTest();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user