Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / workers / resources / methods-async.js
blob5833be1163ee7e929fa61be5a862f25677e64169
1 importScripts("worker-pre.js");
3 onmessage = function(evt)
5 if (evt.data == "START")
6 start();
9 function log(message)
11 postMessage("log " + message);
14 function done()
16 postMessage("DONE");
19 function onReqAbort()
21 log('Abort event.');
24 function onSyncReqError()
26 log('Error event.');
29 // async
31 var asyncStep = 1;
33 function start()
35 req = new XMLHttpRequest();
36 req.onreadystatechange = processStateChange;
37 req.onerror = onSyncReqError;
38 req.onabort = onReqAbort;
39 req.open("GET", "methods.cgi", true);
40 req.send("");
43 function processStateChange()
45 if (req.readyState == 4){
46 if (req.status == 200){
47 if (asyncStep == 1) {
48 asyncStep = 2;
49 log('GET(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
50 req.open("GET", "methods.cgi", true);
51 req.send(null);
52 } else if (asyncStep == 2) {
53 asyncStep = 3;
54 log('GET(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
55 req.open("GET", "methods.cgi", true);
56 req.send("123");
57 } else if (asyncStep == 3) {
58 asyncStep = 4;
59 log('GET("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
60 req.open("POST", "methods.cgi", true);
61 req.send("");
62 } else if (asyncStep == 4) {
63 asyncStep = 5;
64 log('POST(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
65 req.open("POST", "methods.cgi", true);
66 req.send(null);
67 } else if (asyncStep == 5) {
68 asyncStep = 6;
69 log('POST(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
70 req.open("POST", "methods.cgi", true);
71 req.send("123");
72 } else if (asyncStep == 6) {
73 asyncStep = 7;
74 log('POST("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
75 req.open("PUT", "methods.cgi", true);
76 req.send("");
77 } else if (asyncStep == 7) {
78 asyncStep = 8;
79 log('PUT(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
80 req.open("PUT", "methods.cgi", true);
81 req.send(null);
82 } else if (asyncStep == 8) {
83 asyncStep = 9;
84 log('PUT(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
85 req.open("PUT", "methods.cgi", true);
86 req.send("123");
87 } else if (asyncStep == 9) {
88 asyncStep = 10;
89 log('PUT("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
90 req.open("DELETE", "methods.cgi", true);
91 req.send("");
92 } else if (asyncStep == 10) {
93 asyncStep = 11;
94 log('DELETE(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
95 req.open("DELETE", "methods.cgi", true);
96 req.send(null);
97 } else if (asyncStep == 11) {
98 asyncStep = 12;
99 log('DELETE(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
100 req.open("DELETE", "methods.cgi", true);
101 req.send("123");
102 } else if (asyncStep == 12) {
103 asyncStep = 13;
104 log('DELETE("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
105 req.open("HEAD", "methods.cgi", true);
106 req.send("");
107 } else if (asyncStep == 13) {
108 asyncStep = 14;
109 log('HEAD(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
110 req.open("HEAD", "methods.cgi", true);
111 req.send(null);
112 } else if (asyncStep == 14) {
113 asyncStep = 15;
114 log('HEAD(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
115 req.open("HEAD", "methods.cgi", true);
116 req.send("123");
117 } else if (asyncStep == 15) {
118 asyncStep = 16;
119 log('HEAD("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
120 req.open("WKFOOBAR", "methods.cgi", true);
121 req.send("");
122 } else if (asyncStep == 16) {
123 asyncStep = 17;
124 log('WKFOOBAR(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
125 req.open("WKFOOBAR", "methods.cgi", true);
126 req.send(null);
127 } else if (asyncStep == 17) {
128 asyncStep = 18;
129 log('WKFOOBAR(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
130 req.open("WKFOOBAR", "methods.cgi", true);
131 req.send("123");
132 } else if (asyncStep == 18) {
133 asyncStep = 19;
134 log('WKFOOBAR("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
135 req.open("SEARCH", "methods.cgi", true);
136 req.send("");
137 } else if (asyncStep == 19) {
138 asyncStep = 20;
139 log('SEARCH(""): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
140 req.open("SEARCH", "methods.cgi", true);
141 req.send(null);
142 } else if (asyncStep == 20) {
143 asyncStep = 21;
144 log('SEARCH(null): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
145 req.open("SEARCH", "methods.cgi", true);
146 req.send("123");
147 } else if (asyncStep == 21) {
148 log('SEARCH("123"): ' + req.getResponseHeader("REQMETHOD") + "(" + req.getResponseHeader("REQLENGTH") + " bytes), Content-Type: " + req.getResponseHeader("REQTYPE"));
149 done();
151 } else {
152 log("Error loading URL: status " + req.status);
153 done();