Unreviewed, rolling out r243551.
[WebKit-https.git] / LayoutTests / http / tests / xmlhttprequest / upload-onabort-progressevent-attributes.html
1 <html>
2 <head>
3 <title>Test case for bug 120828 (abort case)</title>
4 </head>
5 <body>
6 <p>Test case for <a href="https://bugs.webkit.org/show_bug.cgi?id=120828"> bug 120828</a>: Correctly set XHR loadend attributes (loaded and total).</p>
7 <p>Upload case: verify that abort and loadend events have their ProgressEvent attributes (loaded, total and lengthComputable) correctly set.</p>
8 <p id=console></p>
9 <script type="text/javascript">
10 if (window.testRunner) {
11     testRunner.dumpAsText();
12     testRunner.waitUntilDone();
13 }
14
15 var status = "PASS";
16 var total = 1;
17 var loaded = 1;
18 var uploadedData = "d";
19
20 function onProgressEvent(e)
21 {
22     if (!e.lengthComputable)
23         fail("Event " + e.type + " lengthComputable is false");
24     if (e.total != total || e.loaded != loaded)
25         fail("Event " + e.type + " total/loaded values not matching: " 
26             + "(" + e.loaded + " / " + e.total + "), expected (" + loaded + " / " + total + ")");
27 }
28
29 function onUnexpectedProgressEvent(e)
30 {
31     fail("unexpected ProgressEvent: " + e.type);
32 }
33
34 function fail(msg)
35 {
36     status = "FAILED: " + msg;
37     completeTest();
38     status = "";
39 }
40
41 function completeTest()
42 {
43     log(status);
44     if (window.testRunner)
45         testRunner.notifyDone();
46 }
47
48 function test()
49 {
50     var req = new XMLHttpRequest();
51     req.upload.onerror = onUnexpectedProgressEvent;
52     req.upload.onload = onUnexpectedProgressEvent;
53     req.upload.onabort = onProgressEvent;
54     req.upload.onprogress = function(e) {
55         onProgressEvent(e);
56         req.abort();
57     }
58     req.upload.onloadend = function(e) {
59         onProgressEvent(e);
60         completeTest();
61     }
62
63     req.open("POST", "resources/post-echo.cgi", true);
64     req.send(uploadedData);
65 }
66
67
68 function log(message)
69 {
70     var consoleElt = document.getElementById("console");
71     consoleElt.innerHTML += message + "<br/>";
72 }
73
74 test(); 
75
76 </script>
77 </body>
78 </html>