Removed 'anonymous' from namespace, added whitespace in thread_restrictions.cc
[chromium-blink-merge.git] / content / test / data / loader / async_resource_handler.html
blob64b8c4d301293ee218ae3aaf8b7b56b5b54cf131
1 <html>
2 <head>
3 <script>
4 var ranProgressHandler = false;
5 var completedUpload = false;
7 var asyncXHR;
8 var lastSeenProgress = 0;
9 var data;
11 function sendResults(failures) {
12 var resultString = failures.length ? failures.join('\n') : "success";
13 window.domAutomationController.send(resultString);
16 function progressListener(e) {
17 var progress = e.loaded;
18 var failureList = [];
20 // The |progress| event should not be called after the |load| event.
21 // e.loaded should never hold the same value twice.
22 if (completedUpload)
23 failureList.push('Progress event occurred after load event.');
24 if (progress <= lastSeenProgress)
25 failureList.push('No forward upload progress between events.');
26 if (e.total != data.length)
27 failureList.push('Upload total does not match payload size.');
28 if (progress > e.total)
29 failureList.push('Upload progress exceeds payload size.');
31 if (failureList.length)
32 sendResults(failureList);
34 lastSeenProgress = progress;
35 ranProgressHandler = true;
38 function completedUpload(e) {
39 completedUpload = true;
42 function onFinished(e) {
43 var failureList = [];
44 if (!ranProgressHandler)
45 failureList.push('Finished upload without firing a progress event.');
46 if (lastSeenProgress != data.length)
47 failureList.push('Final progress event before data transfer completed.');
48 if (this.responseText != 'hello') {
49 failureList.push(
50 'Receieved responseText: \'' + this.responseText +'\'. Expected: \'hello\'.');
52 sendResults(failureList);
55 function onError(e) {
56 sendResults(['Received an XHR error event.']);
59 function WaitForAsyncXHR(url, payloadSize) {
60 // Build a long string, fast.
61 // Note: payloadSize will be of the form 2*3^x.
62 data = 'yo';
63 while(data.length !== payloadSize) {
64 data = data + data + data;
66 asyncXHR = new XMLHttpRequest();
67 asyncXHR.addEventListener('load', onFinished);
68 asyncXHR.addEventListener('error', onError);
70 asyncXHR.upload.addEventListener('progress', progressListener);
71 asyncXHR.upload.addEventListener('load', completedUpload);
73 asyncXHR.open('POST', url, true);
75 asyncXHR.setRequestHeader('Content-Type', 'text/plain');
76 asyncXHR.send(data);
78 </script>
79 </head>
80 <body>
81 This page sends an asynchronous XMLHttpRequest on calling WaitForAsyncXHR(url).
82 </body>
83 </html>