2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-02-22 00:35:59 -08:00
|
|
|
|
2008-04-09 10:34:32 -07:00
|
|
|
/**
|
|
|
|
* Test bug 406857 to make sure a download's referrer doesn't disappear when
|
|
|
|
* retrying the download.
|
|
|
|
*/
|
|
|
|
|
2010-04-24 00:39:16 -07:00
|
|
|
const HTTP_SERVER_PORT = 4444;
|
|
|
|
|
2008-06-16 09:58:28 -07:00
|
|
|
function run_test()
|
2008-02-22 00:35:59 -08:00
|
|
|
{
|
|
|
|
let dm = Cc["@mozilla.org/download-manager;1"].
|
|
|
|
getService(Ci.nsIDownloadManager);
|
|
|
|
let db = dm.DBConnection;
|
2012-08-14 07:06:12 -07:00
|
|
|
var httpserv = new HttpServer();
|
2010-04-24 00:39:16 -07:00
|
|
|
httpserv.start(HTTP_SERVER_PORT);
|
2008-02-22 00:35:59 -08:00
|
|
|
|
|
|
|
let stmt = db.createStatement(
|
|
|
|
"INSERT INTO moz_downloads (source, target, state, referrer) " +
|
|
|
|
"VALUES (?1, ?2, ?3, ?4)");
|
|
|
|
|
|
|
|
// Download from the test http server
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(0, "http://localhost:"+HTTP_SERVER_PORT+"/httpd.js");
|
2008-02-22 00:35:59 -08:00
|
|
|
|
|
|
|
// Download to a temp local file
|
|
|
|
let file = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
|
|
|
|
file.append("retry");
|
|
|
|
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(1, Cc["@mozilla.org/network/io-service;1"].
|
2008-02-22 00:35:59 -08:00
|
|
|
getService(Ci.nsIIOService).newFileURI(file).spec);
|
|
|
|
|
|
|
|
// Start it as canceled
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(2, dm.DOWNLOAD_CANCELED);
|
2008-02-22 00:35:59 -08:00
|
|
|
|
|
|
|
// Add a referrer to make sure it doesn't disappear
|
|
|
|
let referrer = "http://referrer.goes/here";
|
2011-03-31 10:19:32 -07:00
|
|
|
stmt.bindByIndex(3, referrer);
|
2008-02-22 00:35:59 -08:00
|
|
|
|
|
|
|
// Add it!
|
|
|
|
stmt.execute();
|
|
|
|
stmt.finalize();
|
|
|
|
|
|
|
|
let listener = {
|
|
|
|
onDownloadStateChange: function(aState, aDownload)
|
|
|
|
{
|
|
|
|
switch (aDownload.state) {
|
|
|
|
case dm.DOWNLOAD_DOWNLOADING:
|
2008-06-16 09:58:28 -07:00
|
|
|
do_check_eq(aDownload.referrer.spec, referrer);
|
2008-02-22 00:35:59 -08:00
|
|
|
break;
|
|
|
|
case dm.DOWNLOAD_FINISHED:
|
2008-06-16 09:58:28 -07:00
|
|
|
do_check_eq(aDownload.referrer.spec, referrer);
|
2008-02-22 00:35:59 -08:00
|
|
|
|
|
|
|
dm.removeListener(listener);
|
2008-04-09 10:34:32 -07:00
|
|
|
try { file.remove(false); } catch(e) { /* stupid windows box */ }
|
2010-04-24 00:39:16 -07:00
|
|
|
httpserv.stop(do_test_finished);
|
2008-02-22 00:35:59 -08:00
|
|
|
break;
|
2009-08-01 00:49:57 -07:00
|
|
|
case dm.DOWNLOAD_FAILED:
|
|
|
|
case dm.DOWNLOAD_CANCELED:
|
2010-04-24 00:39:16 -07:00
|
|
|
httpserv.stop(function () {});
|
2009-08-01 00:49:57 -07:00
|
|
|
do_throw("Unexpected download state change received, state: " +
|
|
|
|
aDownload.state);
|
|
|
|
break;
|
2008-02-22 00:35:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
dm.addListener(listener);
|
|
|
|
|
2008-06-16 09:58:28 -07:00
|
|
|
// Retry the download, and wait.
|
|
|
|
dm.retryDownload(1);
|
2008-02-22 00:35:59 -08:00
|
|
|
|
2008-06-16 09:58:28 -07:00
|
|
|
do_test_pending();
|
2008-02-22 00:35:59 -08:00
|
|
|
}
|