mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 687220: Add test for event handlers on the xhr.upload object in workers. r=bent
This commit is contained in:
parent
c801967c20
commit
85d26cc74e
@ -23,9 +23,11 @@ Tests of DOM Worker Threads XHR(Bug 450452 )
|
||||
|
||||
var worker = new Worker("xhr_worker.js");
|
||||
|
||||
var gotUploadLoad = false, gotLoadend = false;
|
||||
|
||||
worker.onmessage = function(event) {
|
||||
is(event.target, worker);
|
||||
var args = eval(event.data);
|
||||
var args = event.data;
|
||||
switch (args.type) {
|
||||
case "progress": {
|
||||
ok(parseInt(args.current) <= parseInt(args.total));
|
||||
@ -33,12 +35,17 @@ Tests of DOM Worker Threads XHR(Bug 450452 )
|
||||
case "error": {
|
||||
ok(false, "XHR error: " + args.error);
|
||||
} break;
|
||||
case "upload.load": {
|
||||
gotUploadLoad = true;
|
||||
} break;
|
||||
case "load": {
|
||||
is(args.data, "A noisy noise annoys an oyster.");
|
||||
ok(gotUploadLoad, "Should have gotten upload load event");
|
||||
gotLoadend = true;
|
||||
is(args.data, "A noisy noise annoys an oyster.", "correct data");
|
||||
document.getElementById("content").textContent = args.data;
|
||||
} break;
|
||||
case "loadend": {
|
||||
ok(true, "Should have got loadend.");
|
||||
ok(gotLoadend, "Should have gotten load.");
|
||||
SimpleTest.finish();
|
||||
break;
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ function onload(event) {
|
||||
if (event.target.status != 200) {
|
||||
var message = { type: "error",
|
||||
error: event.target.status };
|
||||
postMessage(message.toSource());
|
||||
postMessage(message);
|
||||
}
|
||||
|
||||
var message = { type: "load",
|
||||
data: xhr.responseText };
|
||||
postMessage(message.toSource());
|
||||
postMessage(message);
|
||||
}
|
||||
|
||||
xhr.onload = onload;
|
||||
@ -26,7 +26,7 @@ xhr.removeEventListener("load", onload, false);
|
||||
if (!xhr.onload) {
|
||||
var message = { type: "error",
|
||||
error: "Lost message listener!" };
|
||||
postMessage(message.toSource());
|
||||
postMessage(message);
|
||||
}
|
||||
|
||||
xhr.addEventListener("error", function(event) {
|
||||
@ -35,7 +35,7 @@ xhr.addEventListener("error", function(event) {
|
||||
}
|
||||
var message = { type: "error",
|
||||
error: event.target.status };
|
||||
postMessage(message.toSource());
|
||||
postMessage(message);
|
||||
}, false);
|
||||
|
||||
function onprogress(event) {
|
||||
@ -45,7 +45,7 @@ function onprogress(event) {
|
||||
var message = { type: "progress",
|
||||
current: event.loaded,
|
||||
total: event.total };
|
||||
postMessage(message.toSource());
|
||||
postMessage(message);
|
||||
}
|
||||
xhr.addEventListener("progress", onprogress, false);
|
||||
|
||||
@ -54,15 +54,19 @@ xhr.removeEventListener("doopety", function(event) {}, false);
|
||||
|
||||
xhr.onloadend = function(event) {
|
||||
var message = { type: "loadend" };
|
||||
postMessage(message.toSource());
|
||||
postMessage(message);
|
||||
}
|
||||
|
||||
var upload = xhr.upload;
|
||||
upload.onprogress = function(event) { };
|
||||
upload.addEventListener("readystatechange", function(event) { }, false);
|
||||
upload.removeEventListener("readystatechange", function(event) { }, false);
|
||||
upload.addEventListener("foo", function(event) { }, false);
|
||||
upload.removeEventListener("foo", function(event) { }, false);
|
||||
upload.addEventListener("load", function(event) { }, false);
|
||||
upload.removeEventListener("readystatechange", function(event) { }, false);
|
||||
upload.removeEventListener("foo", function(event) { }, false);
|
||||
upload.onload = function(event) {
|
||||
var message = { type: "upload.load" };
|
||||
postMessage(message);
|
||||
}
|
||||
|
||||
onmessage = function(event) {
|
||||
if (xhr.DONE != 4 || XMLHttpRequest.DONE != 4) {
|
||||
@ -71,6 +75,6 @@ onmessage = function(event) {
|
||||
if (xhr.readystate > xhr.UNSENT) {
|
||||
throw "XHR already running!";
|
||||
}
|
||||
xhr.open("GET", event.data);
|
||||
xhr.send(null);
|
||||
xhr.open("POST", event.data);
|
||||
xhr.send("Data to send");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user