mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 945099 - Enhance basic download API mochitest with attribute checks. Relanding because of bad merge. r=aus
This commit is contained in:
parent
1fa8e0a538
commit
ac290d30ad
@ -24,6 +24,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=938023
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var index = -1;
|
||||
var todayDate = new Date();
|
||||
var baseServeURL = "http://mochi.test:8888/tests/dom/downloads/tests/";
|
||||
var baseDownloadPath = "/mnt/sdcard/downloads/";
|
||||
var lastKnownCurrentBytes = 0;
|
||||
|
||||
function next() {
|
||||
index += 1;
|
||||
@ -38,16 +42,58 @@ function next() {
|
||||
}
|
||||
}
|
||||
|
||||
function checkConsistentDownloadAttributes(download) {
|
||||
var href = document.getElementById("download1").getAttribute("href");
|
||||
var expectedServeURL = baseServeURL + href;
|
||||
var expectedDownloadPath = baseDownloadPath + "test.bin";
|
||||
|
||||
// bug 945323: Download path isn't honoring download attribute
|
||||
todo(download.path === expectedDownloadPath,
|
||||
"Download path = " + expectedDownloadPath);
|
||||
|
||||
// bug 948287: Accessing startTime attribute at download start fires
|
||||
// NS_ERROR_UNEXPECTED in emulator
|
||||
//ok(download.startTime >= todayDate,
|
||||
// "Download start time should be greater than or equal to today");
|
||||
|
||||
// bug 945366: Accessing error attribute at download start fires
|
||||
// NS_ERROR_UNEXPECTED in emulator
|
||||
//is(download.error, null, "Download does not have an error");
|
||||
|
||||
is(download.url, expectedServeURL,
|
||||
"Download URL = " + expectedServeURL);
|
||||
ok(download.id !== null, "Download id is defined");
|
||||
is(download.contentType, "application/octet-stream",
|
||||
"Download content type is application/octet-stream");
|
||||
}
|
||||
|
||||
function downloadChange(evt) {
|
||||
var download = evt.download;
|
||||
if (download.state == "succeeded") {
|
||||
ok(download.totalBytes == 1024, "Download size is 1024 bytes.");
|
||||
ok(download.contentType == "application/octet-stream",
|
||||
"contentType is application/octet-stream.");
|
||||
checkConsistentDownloadAttributes(download);
|
||||
is(download.totalBytes, 1024, "Download total size is 1024 bytes");
|
||||
|
||||
if (download.state === "succeeded") {
|
||||
is(download.currentBytes, 1024, "Download current size is 1024 bytes");
|
||||
SimpleTest.finish();
|
||||
} else if (download.state === "downloading") {
|
||||
ok(download.currentBytes > lastKnownCurrentBytes,
|
||||
"Download current size is larger than last download change event");
|
||||
lastKnownCurrentBytes = download.currentBytes;
|
||||
} else {
|
||||
ok(false, "Unexpected download state = " + download.state);
|
||||
}
|
||||
}
|
||||
|
||||
function downloadStart(evt) {
|
||||
var download = evt.download;
|
||||
checkConsistentDownloadAttributes(download);
|
||||
|
||||
is(download.currentBytes, 0, "Download current size is zero");
|
||||
is(download.state, "downloading", "Download state is downloading");
|
||||
|
||||
download.onstatechange = downloadChange;
|
||||
}
|
||||
|
||||
var steps = [
|
||||
// Start by setting the pref to true.
|
||||
function() {
|
||||
@ -61,11 +107,7 @@ var steps = [
|
||||
SpecialPowers.pushPermissions([
|
||||
{type: "downloads", allow: true, context: document}
|
||||
], function() {
|
||||
navigator.mozDownloadManager.ondownloadstart =
|
||||
function(evt) {
|
||||
ok(true, "Download started");
|
||||
evt.download.addEventListener("statechange", downloadChange);
|
||||
}
|
||||
navigator.mozDownloadManager.ondownloadstart = downloadStart;
|
||||
next();
|
||||
});
|
||||
},
|
||||
@ -82,3 +124,4 @@ next();
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user