Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> |
michael@0 | 5 | <title>Test for Cross Site XMLHttpRequest</title> |
michael@0 | 6 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body onload="initTest()"> |
michael@0 | 10 | <p id="display"> |
michael@0 | 11 | <iframe id=loader></iframe> |
michael@0 | 12 | </p> |
michael@0 | 13 | <div id="content" style="display: none"> |
michael@0 | 14 | |
michael@0 | 15 | </div> |
michael@0 | 16 | <pre id="test"> |
michael@0 | 17 | <script class="testbody" type="application/javascript;version=1.8"> |
michael@0 | 18 | |
michael@0 | 19 | const runPreflightTests = 1; |
michael@0 | 20 | const runCookieTests = 1; |
michael@0 | 21 | const runRedirectTests = 1; |
michael@0 | 22 | |
michael@0 | 23 | var gen; |
michael@0 | 24 | |
michael@0 | 25 | function initTest() { |
michael@0 | 26 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 27 | // Allow all cookies, then do the actual test initialization |
michael@0 | 28 | SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 0]]}, initTestCallback); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | function initTestCallback() { |
michael@0 | 32 | window.addEventListener("message", function(e) { |
michael@0 | 33 | gen.send(e.data); |
michael@0 | 34 | }, false); |
michael@0 | 35 | |
michael@0 | 36 | gen = runTest(); |
michael@0 | 37 | |
michael@0 | 38 | gen.next() |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function runTest() { |
michael@0 | 42 | var loader = document.getElementById('loader'); |
michael@0 | 43 | var loaderWindow = loader.contentWindow; |
michael@0 | 44 | loader.onload = function () { gen.next() }; |
michael@0 | 45 | |
michael@0 | 46 | // Test preflight-less requests |
michael@0 | 47 | basePath = "/tests/content/base/test/file_CrossSiteXHR_server.sjs?" |
michael@0 | 48 | baseURL = "http://mochi.test:8888" + basePath; |
michael@0 | 49 | |
michael@0 | 50 | // Test preflighted requests |
michael@0 | 51 | loader.src = "http://example.org/tests/content/base/test/file_CrossSiteXHR_inner.html"; |
michael@0 | 52 | origin = "http://example.org"; |
michael@0 | 53 | yield undefined; |
michael@0 | 54 | |
michael@0 | 55 | tests = [// Plain request |
michael@0 | 56 | { pass: 1, |
michael@0 | 57 | method: "GET", |
michael@0 | 58 | noAllowPreflight: 1, |
michael@0 | 59 | }, |
michael@0 | 60 | |
michael@0 | 61 | // undefined username |
michael@0 | 62 | { pass: 1, |
michael@0 | 63 | method: "GET", |
michael@0 | 64 | noAllowPreflight: 1, |
michael@0 | 65 | username: undefined |
michael@0 | 66 | }, |
michael@0 | 67 | |
michael@0 | 68 | // undefined username and password |
michael@0 | 69 | { pass: 1, |
michael@0 | 70 | method: "GET", |
michael@0 | 71 | noAllowPreflight: 1, |
michael@0 | 72 | username: undefined, |
michael@0 | 73 | password: undefined |
michael@0 | 74 | }, |
michael@0 | 75 | |
michael@0 | 76 | // nonempty username |
michael@0 | 77 | { pass: 0, |
michael@0 | 78 | method: "GET", |
michael@0 | 79 | noAllowPreflight: 1, |
michael@0 | 80 | username: "user", |
michael@0 | 81 | }, |
michael@0 | 82 | |
michael@0 | 83 | // nonempty password |
michael@0 | 84 | // XXXbz this passes for now, because we ignore passwords |
michael@0 | 85 | // without usernames in most cases. |
michael@0 | 86 | { pass: 1, |
michael@0 | 87 | method: "GET", |
michael@0 | 88 | noAllowPreflight: 1, |
michael@0 | 89 | password: "password", |
michael@0 | 90 | }, |
michael@0 | 91 | |
michael@0 | 92 | // Default allowed headers |
michael@0 | 93 | { pass: 1, |
michael@0 | 94 | method: "GET", |
michael@0 | 95 | headers: { "Content-Type": "text/plain", |
michael@0 | 96 | "Accept": "foo/bar", |
michael@0 | 97 | "Accept-Language": "sv-SE" }, |
michael@0 | 98 | noAllowPreflight: 1, |
michael@0 | 99 | }, |
michael@0 | 100 | { pass: 0, |
michael@0 | 101 | method: "GET", |
michael@0 | 102 | headers: { "Content-Type": "foo/bar", |
michael@0 | 103 | "Accept": "foo/bar", |
michael@0 | 104 | "Accept-Language": "sv-SE" }, |
michael@0 | 105 | noAllowPreflight: 1, |
michael@0 | 106 | }, |
michael@0 | 107 | |
michael@0 | 108 | // Custom headers |
michael@0 | 109 | { pass: 1, |
michael@0 | 110 | method: "GET", |
michael@0 | 111 | headers: { "x-my-header": "myValue" }, |
michael@0 | 112 | allowHeaders: "x-my-header", |
michael@0 | 113 | }, |
michael@0 | 114 | { pass: 1, |
michael@0 | 115 | method: "GET", |
michael@0 | 116 | headers: { "x-my-header": "myValue" }, |
michael@0 | 117 | allowHeaders: "X-My-Header", |
michael@0 | 118 | }, |
michael@0 | 119 | { pass: 1, |
michael@0 | 120 | method: "GET", |
michael@0 | 121 | headers: { "x-my-header": "myValue", |
michael@0 | 122 | "long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header": "secondValue" }, |
michael@0 | 123 | allowHeaders: "x-my-header, long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header-long-header", |
michael@0 | 124 | }, |
michael@0 | 125 | { pass: 1, |
michael@0 | 126 | method: "GET", |
michael@0 | 127 | headers: { "x-my%-header": "myValue" }, |
michael@0 | 128 | allowHeaders: "x-my%-header", |
michael@0 | 129 | }, |
michael@0 | 130 | { pass: 0, |
michael@0 | 131 | method: "GET", |
michael@0 | 132 | headers: { "x-my-header": "myValue" }, |
michael@0 | 133 | }, |
michael@0 | 134 | { pass: 0, |
michael@0 | 135 | method: "GET", |
michael@0 | 136 | headers: { "x-my-header": "" }, |
michael@0 | 137 | }, |
michael@0 | 138 | { pass: 0, |
michael@0 | 139 | method: "GET", |
michael@0 | 140 | headers: { "x-my-header": "myValue" }, |
michael@0 | 141 | allowHeaders: "", |
michael@0 | 142 | }, |
michael@0 | 143 | { pass: 0, |
michael@0 | 144 | method: "GET", |
michael@0 | 145 | headers: { "x-my-header": "myValue" }, |
michael@0 | 146 | allowHeaders: "y-my-header", |
michael@0 | 147 | }, |
michael@0 | 148 | { pass: 0, |
michael@0 | 149 | method: "GET", |
michael@0 | 150 | headers: { "x-my-header": "myValue" }, |
michael@0 | 151 | allowHeaders: "x-my-header y-my-header", |
michael@0 | 152 | }, |
michael@0 | 153 | { pass: 0, |
michael@0 | 154 | method: "GET", |
michael@0 | 155 | headers: { "x-my-header": "myValue" }, |
michael@0 | 156 | allowHeaders: "x-my-header, y-my-header z", |
michael@0 | 157 | }, |
michael@0 | 158 | { pass: 0, |
michael@0 | 159 | method: "GET", |
michael@0 | 160 | headers: { "x-my-header": "myValue" }, |
michael@0 | 161 | allowHeaders: "x-my-header, y-my-he(ader", |
michael@0 | 162 | }, |
michael@0 | 163 | { pass: 0, |
michael@0 | 164 | method: "GET", |
michael@0 | 165 | headers: { "myheader": "" }, |
michael@0 | 166 | allowMethods: "myheader", |
michael@0 | 167 | }, |
michael@0 | 168 | |
michael@0 | 169 | // Multiple custom headers |
michael@0 | 170 | { pass: 1, |
michael@0 | 171 | method: "GET", |
michael@0 | 172 | headers: { "x-my-header": "myValue", |
michael@0 | 173 | "second-header": "secondValue", |
michael@0 | 174 | "third-header": "thirdValue" }, |
michael@0 | 175 | allowHeaders: "x-my-header, second-header, third-header", |
michael@0 | 176 | }, |
michael@0 | 177 | { pass: 1, |
michael@0 | 178 | method: "GET", |
michael@0 | 179 | headers: { "x-my-header": "myValue", |
michael@0 | 180 | "second-header": "secondValue", |
michael@0 | 181 | "third-header": "thirdValue" }, |
michael@0 | 182 | allowHeaders: "x-my-header,second-header,third-header", |
michael@0 | 183 | }, |
michael@0 | 184 | { pass: 1, |
michael@0 | 185 | method: "GET", |
michael@0 | 186 | headers: { "x-my-header": "myValue", |
michael@0 | 187 | "second-header": "secondValue", |
michael@0 | 188 | "third-header": "thirdValue" }, |
michael@0 | 189 | allowHeaders: "x-my-header ,second-header ,third-header", |
michael@0 | 190 | }, |
michael@0 | 191 | { pass: 1, |
michael@0 | 192 | method: "GET", |
michael@0 | 193 | headers: { "x-my-header": "myValue", |
michael@0 | 194 | "second-header": "secondValue", |
michael@0 | 195 | "third-header": "thirdValue" }, |
michael@0 | 196 | allowHeaders: "x-my-header , second-header , third-header", |
michael@0 | 197 | }, |
michael@0 | 198 | { pass: 1, |
michael@0 | 199 | method: "GET", |
michael@0 | 200 | headers: { "x-my-header": "myValue", |
michael@0 | 201 | "second-header": "secondValue" }, |
michael@0 | 202 | allowHeaders: ", x-my-header, , ,, second-header, , ", |
michael@0 | 203 | }, |
michael@0 | 204 | { pass: 1, |
michael@0 | 205 | method: "GET", |
michael@0 | 206 | headers: { "x-my-header": "myValue", |
michael@0 | 207 | "second-header": "secondValue" }, |
michael@0 | 208 | allowHeaders: "x-my-header, second-header, unused-header", |
michael@0 | 209 | }, |
michael@0 | 210 | { pass: 0, |
michael@0 | 211 | method: "GET", |
michael@0 | 212 | headers: { "x-my-header": "myValue", |
michael@0 | 213 | "y-my-header": "secondValue" }, |
michael@0 | 214 | allowHeaders: "x-my-header", |
michael@0 | 215 | }, |
michael@0 | 216 | { pass: 0, |
michael@0 | 217 | method: "GET", |
michael@0 | 218 | headers: { "x-my-header": "", |
michael@0 | 219 | "y-my-header": "" }, |
michael@0 | 220 | allowHeaders: "x-my-header", |
michael@0 | 221 | }, |
michael@0 | 222 | |
michael@0 | 223 | // HEAD requests |
michael@0 | 224 | { pass: 1, |
michael@0 | 225 | method: "HEAD", |
michael@0 | 226 | noAllowPreflight: 1, |
michael@0 | 227 | }, |
michael@0 | 228 | |
michael@0 | 229 | // HEAD with safe headers |
michael@0 | 230 | { pass: 1, |
michael@0 | 231 | method: "HEAD", |
michael@0 | 232 | headers: { "Content-Type": "text/plain", |
michael@0 | 233 | "Accept": "foo/bar", |
michael@0 | 234 | "Accept-Language": "sv-SE" }, |
michael@0 | 235 | noAllowPreflight: 1, |
michael@0 | 236 | }, |
michael@0 | 237 | { pass: 0, |
michael@0 | 238 | method: "HEAD", |
michael@0 | 239 | headers: { "Content-Type": "foo/bar", |
michael@0 | 240 | "Accept": "foo/bar", |
michael@0 | 241 | "Accept-Language": "sv-SE" }, |
michael@0 | 242 | noAllowPreflight: 1, |
michael@0 | 243 | }, |
michael@0 | 244 | |
michael@0 | 245 | // HEAD with custom headers |
michael@0 | 246 | { pass: 1, |
michael@0 | 247 | method: "HEAD", |
michael@0 | 248 | headers: { "x-my-header": "myValue" }, |
michael@0 | 249 | allowHeaders: "x-my-header", |
michael@0 | 250 | }, |
michael@0 | 251 | { pass: 0, |
michael@0 | 252 | method: "HEAD", |
michael@0 | 253 | headers: { "x-my-header": "myValue" }, |
michael@0 | 254 | }, |
michael@0 | 255 | { pass: 0, |
michael@0 | 256 | method: "HEAD", |
michael@0 | 257 | headers: { "x-my-header": "myValue" }, |
michael@0 | 258 | allowHeaders: "", |
michael@0 | 259 | }, |
michael@0 | 260 | { pass: 0, |
michael@0 | 261 | method: "HEAD", |
michael@0 | 262 | headers: { "x-my-header": "myValue" }, |
michael@0 | 263 | allowHeaders: "y-my-header", |
michael@0 | 264 | }, |
michael@0 | 265 | { pass: 0, |
michael@0 | 266 | method: "HEAD", |
michael@0 | 267 | headers: { "x-my-header": "myValue" }, |
michael@0 | 268 | allowHeaders: "x-my-header y-my-header", |
michael@0 | 269 | }, |
michael@0 | 270 | |
michael@0 | 271 | // POST tests |
michael@0 | 272 | { pass: 1, |
michael@0 | 273 | method: "POST", |
michael@0 | 274 | body: "hi there", |
michael@0 | 275 | noAllowPreflight: 1, |
michael@0 | 276 | }, |
michael@0 | 277 | { pass: 1, |
michael@0 | 278 | method: "POST", |
michael@0 | 279 | }, |
michael@0 | 280 | { pass: 1, |
michael@0 | 281 | method: "POST", |
michael@0 | 282 | noAllowPreflight: 1, |
michael@0 | 283 | }, |
michael@0 | 284 | |
michael@0 | 285 | // POST with standard headers |
michael@0 | 286 | { pass: 1, |
michael@0 | 287 | method: "POST", |
michael@0 | 288 | body: "hi there", |
michael@0 | 289 | headers: { "Content-Type": "text/plain" }, |
michael@0 | 290 | noAllowPreflight: 1, |
michael@0 | 291 | }, |
michael@0 | 292 | { pass: 1, |
michael@0 | 293 | method: "POST", |
michael@0 | 294 | body: "hi there", |
michael@0 | 295 | headers: { "Content-Type": "multipart/form-data" }, |
michael@0 | 296 | noAllowPreflight: 1, |
michael@0 | 297 | }, |
michael@0 | 298 | { pass: 1, |
michael@0 | 299 | method: "POST", |
michael@0 | 300 | body: "hi there", |
michael@0 | 301 | headers: { "Content-Type": "application/x-www-form-urlencoded" }, |
michael@0 | 302 | noAllowPreflight: 1, |
michael@0 | 303 | }, |
michael@0 | 304 | { pass: 0, |
michael@0 | 305 | method: "POST", |
michael@0 | 306 | body: "hi there", |
michael@0 | 307 | headers: { "Content-Type": "foo/bar" }, |
michael@0 | 308 | }, |
michael@0 | 309 | { pass: 0, |
michael@0 | 310 | method: "POST", |
michael@0 | 311 | headers: { "Content-Type": "foo/bar" }, |
michael@0 | 312 | }, |
michael@0 | 313 | { pass: 1, |
michael@0 | 314 | method: "POST", |
michael@0 | 315 | body: "hi there", |
michael@0 | 316 | headers: { "Content-Type": "text/plain", |
michael@0 | 317 | "Accept": "foo/bar", |
michael@0 | 318 | "Accept-Language": "sv-SE" }, |
michael@0 | 319 | noAllowPreflight: 1, |
michael@0 | 320 | }, |
michael@0 | 321 | |
michael@0 | 322 | // POST with custom headers |
michael@0 | 323 | { pass: 1, |
michael@0 | 324 | method: "POST", |
michael@0 | 325 | body: "hi there", |
michael@0 | 326 | headers: { "Accept": "foo/bar", |
michael@0 | 327 | "Accept-Language": "sv-SE", |
michael@0 | 328 | "x-my-header": "myValue" }, |
michael@0 | 329 | allowHeaders: "x-my-header", |
michael@0 | 330 | }, |
michael@0 | 331 | { pass: 1, |
michael@0 | 332 | method: "POST", |
michael@0 | 333 | headers: { "Content-Type": "text/plain", |
michael@0 | 334 | "x-my-header": "myValue" }, |
michael@0 | 335 | allowHeaders: "x-my-header", |
michael@0 | 336 | }, |
michael@0 | 337 | { pass: 1, |
michael@0 | 338 | method: "POST", |
michael@0 | 339 | body: "hi there", |
michael@0 | 340 | headers: { "Content-Type": "text/plain", |
michael@0 | 341 | "x-my-header": "myValue" }, |
michael@0 | 342 | allowHeaders: "x-my-header", |
michael@0 | 343 | }, |
michael@0 | 344 | { pass: 1, |
michael@0 | 345 | method: "POST", |
michael@0 | 346 | body: "hi there", |
michael@0 | 347 | headers: { "Content-Type": "foo/bar", |
michael@0 | 348 | "x-my-header": "myValue" }, |
michael@0 | 349 | allowHeaders: "x-my-header, content-type", |
michael@0 | 350 | }, |
michael@0 | 351 | { pass: 0, |
michael@0 | 352 | method: "POST", |
michael@0 | 353 | body: "hi there", |
michael@0 | 354 | headers: { "Content-Type": "foo/bar" }, |
michael@0 | 355 | noAllowPreflight: 1, |
michael@0 | 356 | }, |
michael@0 | 357 | { pass: 0, |
michael@0 | 358 | method: "POST", |
michael@0 | 359 | body: "hi there", |
michael@0 | 360 | headers: { "Content-Type": "foo/bar", |
michael@0 | 361 | "x-my-header": "myValue" }, |
michael@0 | 362 | allowHeaders: "x-my-header", |
michael@0 | 363 | }, |
michael@0 | 364 | { pass: 1, |
michael@0 | 365 | method: "POST", |
michael@0 | 366 | headers: { "x-my-header": "myValue" }, |
michael@0 | 367 | allowHeaders: "x-my-header", |
michael@0 | 368 | }, |
michael@0 | 369 | { pass: 1, |
michael@0 | 370 | method: "POST", |
michael@0 | 371 | body: "hi there", |
michael@0 | 372 | headers: { "x-my-header": "myValue" }, |
michael@0 | 373 | allowHeaders: "x-my-header, $_%", |
michael@0 | 374 | }, |
michael@0 | 375 | |
michael@0 | 376 | // Other methods |
michael@0 | 377 | { pass: 1, |
michael@0 | 378 | method: "DELETE", |
michael@0 | 379 | allowMethods: "DELETE", |
michael@0 | 380 | }, |
michael@0 | 381 | { pass: 0, |
michael@0 | 382 | method: "DELETE", |
michael@0 | 383 | allowHeaders: "DELETE", |
michael@0 | 384 | }, |
michael@0 | 385 | { pass: 0, |
michael@0 | 386 | method: "DELETE", |
michael@0 | 387 | }, |
michael@0 | 388 | { pass: 0, |
michael@0 | 389 | method: "DELETE", |
michael@0 | 390 | allowMethods: "", |
michael@0 | 391 | }, |
michael@0 | 392 | { pass: 1, |
michael@0 | 393 | method: "DELETE", |
michael@0 | 394 | allowMethods: "POST, PUT, DELETE", |
michael@0 | 395 | }, |
michael@0 | 396 | { pass: 1, |
michael@0 | 397 | method: "DELETE", |
michael@0 | 398 | allowMethods: "POST, DELETE, PUT", |
michael@0 | 399 | }, |
michael@0 | 400 | { pass: 1, |
michael@0 | 401 | method: "DELETE", |
michael@0 | 402 | allowMethods: "DELETE, POST, PUT", |
michael@0 | 403 | }, |
michael@0 | 404 | { pass: 1, |
michael@0 | 405 | method: "DELETE", |
michael@0 | 406 | allowMethods: "POST ,PUT ,DELETE", |
michael@0 | 407 | }, |
michael@0 | 408 | { pass: 1, |
michael@0 | 409 | method: "DELETE", |
michael@0 | 410 | allowMethods: "POST,PUT,DELETE", |
michael@0 | 411 | }, |
michael@0 | 412 | { pass: 1, |
michael@0 | 413 | method: "DELETE", |
michael@0 | 414 | allowMethods: "POST , PUT , DELETE", |
michael@0 | 415 | }, |
michael@0 | 416 | { pass: 1, |
michael@0 | 417 | method: "DELETE", |
michael@0 | 418 | allowMethods: " ,, PUT ,, , , DELETE , ,", |
michael@0 | 419 | }, |
michael@0 | 420 | { pass: 0, |
michael@0 | 421 | method: "DELETE", |
michael@0 | 422 | allowMethods: "PUT", |
michael@0 | 423 | }, |
michael@0 | 424 | { pass: 0, |
michael@0 | 425 | method: "DELETE", |
michael@0 | 426 | allowMethods: "DELETEZ", |
michael@0 | 427 | }, |
michael@0 | 428 | { pass: 0, |
michael@0 | 429 | method: "DELETE", |
michael@0 | 430 | allowMethods: "DELETE PUT", |
michael@0 | 431 | }, |
michael@0 | 432 | { pass: 0, |
michael@0 | 433 | method: "DELETE", |
michael@0 | 434 | allowMethods: "DELETE, PUT Z", |
michael@0 | 435 | }, |
michael@0 | 436 | { pass: 0, |
michael@0 | 437 | method: "DELETE", |
michael@0 | 438 | allowMethods: "DELETE, PU(T", |
michael@0 | 439 | }, |
michael@0 | 440 | { pass: 0, |
michael@0 | 441 | method: "DELETE", |
michael@0 | 442 | allowMethods: "PUT DELETE", |
michael@0 | 443 | }, |
michael@0 | 444 | { pass: 0, |
michael@0 | 445 | method: "DELETE", |
michael@0 | 446 | allowMethods: "PUT Z, DELETE", |
michael@0 | 447 | }, |
michael@0 | 448 | { pass: 0, |
michael@0 | 449 | method: "DELETE", |
michael@0 | 450 | allowMethods: "PU(T, DELETE", |
michael@0 | 451 | }, |
michael@0 | 452 | { pass: 0, |
michael@0 | 453 | method: "MYMETHOD", |
michael@0 | 454 | allowMethods: "myMethod", |
michael@0 | 455 | }, |
michael@0 | 456 | { pass: 0, |
michael@0 | 457 | method: "PUT", |
michael@0 | 458 | allowMethods: "put", |
michael@0 | 459 | }, |
michael@0 | 460 | |
michael@0 | 461 | // Progress events |
michael@0 | 462 | { pass: 1, |
michael@0 | 463 | method: "POST", |
michael@0 | 464 | body: "hi there", |
michael@0 | 465 | headers: { "Content-Type": "text/plain" }, |
michael@0 | 466 | uploadProgress: "progress", |
michael@0 | 467 | }, |
michael@0 | 468 | { pass: 0, |
michael@0 | 469 | method: "POST", |
michael@0 | 470 | body: "hi there", |
michael@0 | 471 | headers: { "Content-Type": "text/plain" }, |
michael@0 | 472 | uploadProgress: "progress", |
michael@0 | 473 | noAllowPreflight: 1, |
michael@0 | 474 | }, |
michael@0 | 475 | |
michael@0 | 476 | // Status messages |
michael@0 | 477 | { pass: 1, |
michael@0 | 478 | method: "GET", |
michael@0 | 479 | noAllowPreflight: 1, |
michael@0 | 480 | status: 404, |
michael@0 | 481 | statusMessage: "nothin' here", |
michael@0 | 482 | }, |
michael@0 | 483 | { pass: 1, |
michael@0 | 484 | method: "GET", |
michael@0 | 485 | noAllowPreflight: 1, |
michael@0 | 486 | status: 401, |
michael@0 | 487 | statusMessage: "no can do", |
michael@0 | 488 | }, |
michael@0 | 489 | { pass: 1, |
michael@0 | 490 | method: "POST", |
michael@0 | 491 | body: "hi there", |
michael@0 | 492 | headers: { "Content-Type": "foo/bar" }, |
michael@0 | 493 | allowHeaders: "content-type", |
michael@0 | 494 | status: 500, |
michael@0 | 495 | statusMessage: "server boo", |
michael@0 | 496 | }, |
michael@0 | 497 | { pass: 1, |
michael@0 | 498 | method: "GET", |
michael@0 | 499 | noAllowPreflight: 1, |
michael@0 | 500 | status: 200, |
michael@0 | 501 | statusMessage: "Yes!!", |
michael@0 | 502 | }, |
michael@0 | 503 | { pass: 0, |
michael@0 | 504 | method: "GET", |
michael@0 | 505 | headers: { "x-my-header": "header value" }, |
michael@0 | 506 | allowHeaders: "x-my-header", |
michael@0 | 507 | preflightStatus: 400 |
michael@0 | 508 | }, |
michael@0 | 509 | { pass: 1, |
michael@0 | 510 | method: "GET", |
michael@0 | 511 | headers: { "x-my-header": "header value" }, |
michael@0 | 512 | allowHeaders: "x-my-header", |
michael@0 | 513 | preflightStatus: 200 |
michael@0 | 514 | }, |
michael@0 | 515 | { pass: 1, |
michael@0 | 516 | method: "GET", |
michael@0 | 517 | headers: { "x-my-header": "header value" }, |
michael@0 | 518 | allowHeaders: "x-my-header", |
michael@0 | 519 | preflightStatus: 204 |
michael@0 | 520 | }, |
michael@0 | 521 | |
michael@0 | 522 | // exposed headers |
michael@0 | 523 | { pass: 1, |
michael@0 | 524 | method: "GET", |
michael@0 | 525 | responseHeaders: { "x-my-header": "x header" }, |
michael@0 | 526 | exposeHeaders: "x-my-header", |
michael@0 | 527 | expectedResponseHeaders: ["x-my-header"], |
michael@0 | 528 | }, |
michael@0 | 529 | { pass: 0, |
michael@0 | 530 | method: "GET", |
michael@0 | 531 | origin: "http://invalid", |
michael@0 | 532 | responseHeaders: { "x-my-header": "x header" }, |
michael@0 | 533 | exposeHeaders: "x-my-header", |
michael@0 | 534 | expectedResponseHeaders: [], |
michael@0 | 535 | }, |
michael@0 | 536 | { pass: 1, |
michael@0 | 537 | method: "GET", |
michael@0 | 538 | responseHeaders: { "x-my-header": "x header" }, |
michael@0 | 539 | expectedResponseHeaders: [], |
michael@0 | 540 | }, |
michael@0 | 541 | { pass: 1, |
michael@0 | 542 | method: "GET", |
michael@0 | 543 | responseHeaders: { "x-my-header": "x header" }, |
michael@0 | 544 | exposeHeaders: "x-my-header y", |
michael@0 | 545 | expectedResponseHeaders: [], |
michael@0 | 546 | }, |
michael@0 | 547 | { pass: 1, |
michael@0 | 548 | method: "GET", |
michael@0 | 549 | responseHeaders: { "x-my-header": "x header" }, |
michael@0 | 550 | exposeHeaders: "y x-my-header", |
michael@0 | 551 | expectedResponseHeaders: [], |
michael@0 | 552 | }, |
michael@0 | 553 | { pass: 1, |
michael@0 | 554 | method: "GET", |
michael@0 | 555 | responseHeaders: { "x-my-header": "x header" }, |
michael@0 | 556 | exposeHeaders: "x-my-header, y-my-header z", |
michael@0 | 557 | expectedResponseHeaders: [], |
michael@0 | 558 | }, |
michael@0 | 559 | { pass: 1, |
michael@0 | 560 | method: "GET", |
michael@0 | 561 | responseHeaders: { "x-my-header": "x header" }, |
michael@0 | 562 | exposeHeaders: "x-my-header, y-my-hea(er", |
michael@0 | 563 | expectedResponseHeaders: [], |
michael@0 | 564 | }, |
michael@0 | 565 | { pass: 1, |
michael@0 | 566 | method: "GET", |
michael@0 | 567 | responseHeaders: { "x-my-header": "x header", |
michael@0 | 568 | "y-my-header": "y header" }, |
michael@0 | 569 | exposeHeaders: " , ,,y-my-header,z-my-header, ", |
michael@0 | 570 | expectedResponseHeaders: ["y-my-header"], |
michael@0 | 571 | }, |
michael@0 | 572 | { pass: 1, |
michael@0 | 573 | method: "GET", |
michael@0 | 574 | responseHeaders: { "Cache-Control": "cacheControl header", |
michael@0 | 575 | "Content-Language": "contentLanguage header", |
michael@0 | 576 | "Expires":"expires header", |
michael@0 | 577 | "Last-Modified":"lastModified header", |
michael@0 | 578 | "Pragma":"pragma header", |
michael@0 | 579 | "Unexpected":"unexpected header" }, |
michael@0 | 580 | expectedResponseHeaders: ["Cache-Control","Content-Language","Content-Type","Expires","Last-Modified","Pragma"], |
michael@0 | 581 | }, |
michael@0 | 582 | // Check that sending a body in the OPTIONS response works |
michael@0 | 583 | { pass: 1, |
michael@0 | 584 | method: "DELETE", |
michael@0 | 585 | allowMethods: "DELETE", |
michael@0 | 586 | preflightBody: "I'm a preflight response body", |
michael@0 | 587 | }, |
michael@0 | 588 | ]; |
michael@0 | 589 | |
michael@0 | 590 | if (!runPreflightTests) { |
michael@0 | 591 | tests = []; |
michael@0 | 592 | } |
michael@0 | 593 | |
michael@0 | 594 | for (test of tests) { |
michael@0 | 595 | var req = { |
michael@0 | 596 | url: baseURL + "allowOrigin=" + escape(test.origin || origin), |
michael@0 | 597 | method: test.method, |
michael@0 | 598 | headers: test.headers, |
michael@0 | 599 | uploadProgress: test.uploadProgress, |
michael@0 | 600 | body: test.body, |
michael@0 | 601 | responseHeaders: test.responseHeaders, |
michael@0 | 602 | }; |
michael@0 | 603 | |
michael@0 | 604 | if (test.pass) { |
michael@0 | 605 | req.url += "&origin=" + escape(origin) + |
michael@0 | 606 | "&requestMethod=" + test.method; |
michael@0 | 607 | } |
michael@0 | 608 | |
michael@0 | 609 | if ("username" in test) { |
michael@0 | 610 | req.username = test.username; |
michael@0 | 611 | } |
michael@0 | 612 | |
michael@0 | 613 | if ("password" in test) { |
michael@0 | 614 | req.password = test.password; |
michael@0 | 615 | } |
michael@0 | 616 | |
michael@0 | 617 | if (test.noAllowPreflight) |
michael@0 | 618 | req.url += "&noAllowPreflight"; |
michael@0 | 619 | |
michael@0 | 620 | if (test.pass && "headers" in test) { |
michael@0 | 621 | function isUnsafeHeader(name) { |
michael@0 | 622 | lName = name.toLowerCase(); |
michael@0 | 623 | return lName != "accept" && |
michael@0 | 624 | lName != "accept-language" && |
michael@0 | 625 | (lName != "content-type" || |
michael@0 | 626 | ["text/plain", |
michael@0 | 627 | "multipart/form-data", |
michael@0 | 628 | "application/x-www-form-urlencoded"] |
michael@0 | 629 | .indexOf(test.headers[name].toLowerCase()) == -1); |
michael@0 | 630 | } |
michael@0 | 631 | req.url += "&headers=" + escape(test.headers.toSource()); |
michael@0 | 632 | reqHeaders = |
michael@0 | 633 | escape([name for (name in test.headers)] |
michael@0 | 634 | .filter(isUnsafeHeader) |
michael@0 | 635 | .map(String.toLowerCase) |
michael@0 | 636 | .sort() |
michael@0 | 637 | .join(",")); |
michael@0 | 638 | req.url += reqHeaders ? "&requestHeaders=" + reqHeaders : ""; |
michael@0 | 639 | } |
michael@0 | 640 | if ("allowHeaders" in test) |
michael@0 | 641 | req.url += "&allowHeaders=" + escape(test.allowHeaders); |
michael@0 | 642 | if ("allowMethods" in test) |
michael@0 | 643 | req.url += "&allowMethods=" + escape(test.allowMethods); |
michael@0 | 644 | if (test.body) |
michael@0 | 645 | req.url += "&body=" + escape(test.body); |
michael@0 | 646 | if (test.status) { |
michael@0 | 647 | req.url += "&status=" + test.status; |
michael@0 | 648 | req.url += "&statusMessage=" + escape(test.statusMessage); |
michael@0 | 649 | } |
michael@0 | 650 | if (test.preflightStatus) |
michael@0 | 651 | req.url += "&preflightStatus=" + test.preflightStatus; |
michael@0 | 652 | if (test.responseHeaders) |
michael@0 | 653 | req.url += "&responseHeaders=" + escape(test.responseHeaders.toSource()); |
michael@0 | 654 | if (test.exposeHeaders) |
michael@0 | 655 | req.url += "&exposeHeaders=" + escape(test.exposeHeaders); |
michael@0 | 656 | if (test.preflightBody) |
michael@0 | 657 | req.url += "&preflightBody=" + escape(test.preflightBody); |
michael@0 | 658 | |
michael@0 | 659 | loaderWindow.postMessage(req.toSource(), origin); |
michael@0 | 660 | res = eval(yield); |
michael@0 | 661 | |
michael@0 | 662 | if (test.pass) { |
michael@0 | 663 | is(res.didFail, false, |
michael@0 | 664 | "shouldn't have failed in test for " + test.toSource()); |
michael@0 | 665 | if (test.status) { |
michael@0 | 666 | is(res.status, test.status, "wrong status in test for " + test.toSource()); |
michael@0 | 667 | is(res.statusText, test.statusMessage, "wrong status text for " + test.toSource()); |
michael@0 | 668 | } |
michael@0 | 669 | else { |
michael@0 | 670 | is(res.status, 200, "wrong status in test for " + test.toSource()); |
michael@0 | 671 | is(res.statusText, "OK", "wrong status text for " + test.toSource()); |
michael@0 | 672 | } |
michael@0 | 673 | if (test.method !== "HEAD") { |
michael@0 | 674 | is(res.responseXML, "<res>hello pass</res>", |
michael@0 | 675 | "wrong responseXML in test for " + test.toSource()); |
michael@0 | 676 | is(res.responseText, "<res>hello pass</res>\n", |
michael@0 | 677 | "wrong responseText in test for " + test.toSource()); |
michael@0 | 678 | is(res.events.join(","), |
michael@0 | 679 | "opening,rs1,sending,loadstart,rs2,rs3,rs4,load,loadend", |
michael@0 | 680 | "wrong responseText in test for " + test.toSource()); |
michael@0 | 681 | } |
michael@0 | 682 | else { |
michael@0 | 683 | is(res.responseXML, null, |
michael@0 | 684 | "wrong responseXML in test for " + test.toSource()); |
michael@0 | 685 | is(res.responseText, "", |
michael@0 | 686 | "wrong responseText in test for " + test.toSource()); |
michael@0 | 687 | is(res.events.join(","), |
michael@0 | 688 | "opening,rs1,sending,loadstart,rs2,rs4,load,loadend", |
michael@0 | 689 | "wrong responseText in test for " + test.toSource()); |
michael@0 | 690 | } |
michael@0 | 691 | if (test.responseHeaders) { |
michael@0 | 692 | for (header in test.responseHeaders) { |
michael@0 | 693 | if (test.expectedResponseHeaders.indexOf(header) == -1) { |
michael@0 | 694 | is(res.responseHeaders[header], null, |
michael@0 | 695 | "|xhr.getResponseHeader()|wrong response header (" + header + ") in test for " + |
michael@0 | 696 | test.toSource()); |
michael@0 | 697 | is(res.allResponseHeaders[header], null, |
michael@0 | 698 | "|xhr.getAllResponseHeaderss()|wrong response header (" + header + ") in test for " + |
michael@0 | 699 | test.toSource()); |
michael@0 | 700 | } |
michael@0 | 701 | else { |
michael@0 | 702 | is(res.responseHeaders[header], test.responseHeaders[header], |
michael@0 | 703 | "|xhr.getResponseHeader()|wrong response header (" + header + ") in test for " + |
michael@0 | 704 | test.toSource()); |
michael@0 | 705 | is(res.allResponseHeaders[header], test.responseHeaders[header], |
michael@0 | 706 | "|xhr.getAllResponseHeaderss()|wrong response header (" + header + ") in test for " + |
michael@0 | 707 | test.toSource()); |
michael@0 | 708 | } |
michael@0 | 709 | } |
michael@0 | 710 | } |
michael@0 | 711 | } |
michael@0 | 712 | else { |
michael@0 | 713 | is(res.didFail, true, |
michael@0 | 714 | "should have failed in test for " + test.toSource()); |
michael@0 | 715 | is(res.status, 0, "wrong status in test for " + test.toSource()); |
michael@0 | 716 | is(res.statusText, "", "wrong status text for " + test.toSource()); |
michael@0 | 717 | is(res.responseXML, null, |
michael@0 | 718 | "wrong responseXML in test for " + test.toSource()); |
michael@0 | 719 | is(res.responseText, "", |
michael@0 | 720 | "wrong responseText in test for " + test.toSource()); |
michael@0 | 721 | if (!res.sendThrew) { |
michael@0 | 722 | is(res.events.join(","), |
michael@0 | 723 | "opening,rs1,sending,loadstart,rs2,rs4,error,loadend", |
michael@0 | 724 | "wrong events in test for " + test.toSource()); |
michael@0 | 725 | } |
michael@0 | 726 | is(res.progressEvents, 0, |
michael@0 | 727 | "wrong events in test for " + test.toSource()); |
michael@0 | 728 | if (test.responseHeaders) { |
michael@0 | 729 | for (header in test.responseHeaders) { |
michael@0 | 730 | is(res.responseHeaders[header], null, |
michael@0 | 731 | "wrong response header (" + header + ") in test for " + |
michael@0 | 732 | test.toSource()); |
michael@0 | 733 | } |
michael@0 | 734 | } |
michael@0 | 735 | } |
michael@0 | 736 | } |
michael@0 | 737 | |
michael@0 | 738 | // Test cookie behavior |
michael@0 | 739 | tests = [{ pass: 1, |
michael@0 | 740 | method: "GET", |
michael@0 | 741 | withCred: 1, |
michael@0 | 742 | allowCred: 1, |
michael@0 | 743 | }, |
michael@0 | 744 | { pass: 0, |
michael@0 | 745 | method: "GET", |
michael@0 | 746 | withCred: 1, |
michael@0 | 747 | allowCred: 0, |
michael@0 | 748 | }, |
michael@0 | 749 | { pass: 0, |
michael@0 | 750 | method: "GET", |
michael@0 | 751 | withCred: 1, |
michael@0 | 752 | allowCred: 1, |
michael@0 | 753 | origin: "*", |
michael@0 | 754 | }, |
michael@0 | 755 | { pass: 1, |
michael@0 | 756 | method: "GET", |
michael@0 | 757 | withCred: 0, |
michael@0 | 758 | allowCred: 1, |
michael@0 | 759 | origin: "*", |
michael@0 | 760 | }, |
michael@0 | 761 | { pass: 1, |
michael@0 | 762 | method: "GET", |
michael@0 | 763 | setCookie: "a=1", |
michael@0 | 764 | withCred: 1, |
michael@0 | 765 | allowCred: 1, |
michael@0 | 766 | }, |
michael@0 | 767 | { pass: 1, |
michael@0 | 768 | method: "GET", |
michael@0 | 769 | cookie: "a=1", |
michael@0 | 770 | withCred: 1, |
michael@0 | 771 | allowCred: 1, |
michael@0 | 772 | }, |
michael@0 | 773 | { pass: 1, |
michael@0 | 774 | method: "GET", |
michael@0 | 775 | noCookie: 1, |
michael@0 | 776 | withCred: 0, |
michael@0 | 777 | allowCred: 1, |
michael@0 | 778 | }, |
michael@0 | 779 | { pass: 0, |
michael@0 | 780 | method: "GET", |
michael@0 | 781 | noCookie: 1, |
michael@0 | 782 | withCred: 1, |
michael@0 | 783 | allowCred: 1, |
michael@0 | 784 | }, |
michael@0 | 785 | { pass: 1, |
michael@0 | 786 | method: "GET", |
michael@0 | 787 | setCookie: "a=2", |
michael@0 | 788 | withCred: 0, |
michael@0 | 789 | allowCred: 1, |
michael@0 | 790 | }, |
michael@0 | 791 | { pass: 1, |
michael@0 | 792 | method: "GET", |
michael@0 | 793 | cookie: "a=1", |
michael@0 | 794 | withCred: 1, |
michael@0 | 795 | allowCred: 1, |
michael@0 | 796 | }, |
michael@0 | 797 | { pass: 1, |
michael@0 | 798 | method: "GET", |
michael@0 | 799 | setCookie: "a=2", |
michael@0 | 800 | withCred: 1, |
michael@0 | 801 | allowCred: 1, |
michael@0 | 802 | }, |
michael@0 | 803 | { pass: 1, |
michael@0 | 804 | method: "GET", |
michael@0 | 805 | cookie: "a=2", |
michael@0 | 806 | withCred: 1, |
michael@0 | 807 | allowCred: 1, |
michael@0 | 808 | }, |
michael@0 | 809 | ]; |
michael@0 | 810 | |
michael@0 | 811 | if (!runCookieTests) { |
michael@0 | 812 | tests = []; |
michael@0 | 813 | } |
michael@0 | 814 | |
michael@0 | 815 | for (test of tests) { |
michael@0 | 816 | req = { |
michael@0 | 817 | url: baseURL + "allowOrigin=" + escape(test.origin || origin), |
michael@0 | 818 | method: test.method, |
michael@0 | 819 | headers: test.headers, |
michael@0 | 820 | withCred: test.withCred, |
michael@0 | 821 | }; |
michael@0 | 822 | |
michael@0 | 823 | if (test.allowCred) |
michael@0 | 824 | req.url += "&allowCred"; |
michael@0 | 825 | |
michael@0 | 826 | if (test.setCookie) |
michael@0 | 827 | req.url += "&setCookie=" + escape(test.setCookie); |
michael@0 | 828 | if (test.cookie) |
michael@0 | 829 | req.url += "&cookie=" + escape(test.cookie); |
michael@0 | 830 | if (test.noCookie) |
michael@0 | 831 | req.url += "&noCookie"; |
michael@0 | 832 | |
michael@0 | 833 | if ("allowHeaders" in test) |
michael@0 | 834 | req.url += "&allowHeaders=" + escape(test.allowHeaders); |
michael@0 | 835 | if ("allowMethods" in test) |
michael@0 | 836 | req.url += "&allowMethods=" + escape(test.allowMethods); |
michael@0 | 837 | |
michael@0 | 838 | loaderWindow.postMessage(req.toSource(), origin); |
michael@0 | 839 | |
michael@0 | 840 | res = eval(yield); |
michael@0 | 841 | if (test.pass) { |
michael@0 | 842 | is(res.didFail, false, |
michael@0 | 843 | "shouldn't have failed in test for " + test.toSource()); |
michael@0 | 844 | is(res.status, 200, "wrong status in test for " + test.toSource()); |
michael@0 | 845 | is(res.statusText, "OK", "wrong status text for " + test.toSource()); |
michael@0 | 846 | is(res.responseXML, "<res>hello pass</res>", |
michael@0 | 847 | "wrong responseXML in test for " + test.toSource()); |
michael@0 | 848 | is(res.responseText, "<res>hello pass</res>\n", |
michael@0 | 849 | "wrong responseText in test for " + test.toSource()); |
michael@0 | 850 | is(res.events.join(","), |
michael@0 | 851 | "opening,rs1,sending,loadstart,rs2,rs3,rs4,load,loadend", |
michael@0 | 852 | "wrong responseText in test for " + test.toSource()); |
michael@0 | 853 | } |
michael@0 | 854 | else { |
michael@0 | 855 | is(res.didFail, true, |
michael@0 | 856 | "should have failed in test for " + test.toSource()); |
michael@0 | 857 | is(res.status, 0, "wrong status in test for " + test.toSource()); |
michael@0 | 858 | is(res.statusText, "", "wrong status text for " + test.toSource()); |
michael@0 | 859 | is(res.responseXML, null, |
michael@0 | 860 | "wrong responseXML in test for " + test.toSource()); |
michael@0 | 861 | is(res.responseText, "", |
michael@0 | 862 | "wrong responseText in test for " + test.toSource()); |
michael@0 | 863 | is(res.events.join(","), |
michael@0 | 864 | "opening,rs1,sending,loadstart,rs2,rs4,error,loadend", |
michael@0 | 865 | "wrong events in test for " + test.toSource()); |
michael@0 | 866 | is(res.progressEvents, 0, |
michael@0 | 867 | "wrong events in test for " + test.toSource()); |
michael@0 | 868 | } |
michael@0 | 869 | } |
michael@0 | 870 | |
michael@0 | 871 | // Make sure to clear cookies to avoid affecting other tests |
michael@0 | 872 | document.cookie = "a=; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT" |
michael@0 | 873 | is(document.cookie, "", "No cookies should be left over"); |
michael@0 | 874 | |
michael@0 | 875 | |
michael@0 | 876 | // Test redirects |
michael@0 | 877 | is(loader.src, "http://example.org/tests/content/base/test/file_CrossSiteXHR_inner.html"); |
michael@0 | 878 | is(origin, "http://example.org"); |
michael@0 | 879 | |
michael@0 | 880 | tests = [{ pass: 1, |
michael@0 | 881 | method: "GET", |
michael@0 | 882 | hops: [{ server: "http://example.com", |
michael@0 | 883 | allowOrigin: origin |
michael@0 | 884 | }, |
michael@0 | 885 | ], |
michael@0 | 886 | }, |
michael@0 | 887 | { pass: 0, |
michael@0 | 888 | method: "GET", |
michael@0 | 889 | hops: [{ server: "http://example.com", |
michael@0 | 890 | allowOrigin: origin |
michael@0 | 891 | }, |
michael@0 | 892 | { server: "http://example.org", |
michael@0 | 893 | allowOrigin: origin |
michael@0 | 894 | }, |
michael@0 | 895 | ], |
michael@0 | 896 | }, |
michael@0 | 897 | { pass: 1, |
michael@0 | 898 | method: "GET", |
michael@0 | 899 | hops: [{ server: "http://example.com", |
michael@0 | 900 | allowOrigin: origin |
michael@0 | 901 | }, |
michael@0 | 902 | { server: "http://example.org", |
michael@0 | 903 | allowOrigin: "*" |
michael@0 | 904 | }, |
michael@0 | 905 | ], |
michael@0 | 906 | }, |
michael@0 | 907 | { pass: 0, |
michael@0 | 908 | method: "GET", |
michael@0 | 909 | hops: [{ server: "http://example.com", |
michael@0 | 910 | allowOrigin: origin |
michael@0 | 911 | }, |
michael@0 | 912 | { server: "http://example.org", |
michael@0 | 913 | }, |
michael@0 | 914 | ], |
michael@0 | 915 | }, |
michael@0 | 916 | { pass: 1, |
michael@0 | 917 | method: "GET", |
michael@0 | 918 | hops: [{ server: "http://example.org", |
michael@0 | 919 | }, |
michael@0 | 920 | { server: "http://example.org", |
michael@0 | 921 | }, |
michael@0 | 922 | { server: "http://example.com", |
michael@0 | 923 | allowOrigin: origin |
michael@0 | 924 | }, |
michael@0 | 925 | ], |
michael@0 | 926 | }, |
michael@0 | 927 | { pass: 0, |
michael@0 | 928 | method: "GET", |
michael@0 | 929 | hops: [{ server: "http://example.org", |
michael@0 | 930 | }, |
michael@0 | 931 | { server: "http://example.org", |
michael@0 | 932 | }, |
michael@0 | 933 | { server: "http://example.com", |
michael@0 | 934 | allowOrigin: origin |
michael@0 | 935 | }, |
michael@0 | 936 | { server: "http://example.org", |
michael@0 | 937 | }, |
michael@0 | 938 | ], |
michael@0 | 939 | }, |
michael@0 | 940 | { pass: 0, |
michael@0 | 941 | method: "GET", |
michael@0 | 942 | hops: [{ server: "http://example.com", |
michael@0 | 943 | allowOrigin: origin |
michael@0 | 944 | }, |
michael@0 | 945 | { server: "http://test2.example.org:8000", |
michael@0 | 946 | allowOrigin: origin |
michael@0 | 947 | }, |
michael@0 | 948 | { server: "http://sub2.xn--lt-uia.example.org", |
michael@0 | 949 | allowOrigin: origin |
michael@0 | 950 | }, |
michael@0 | 951 | { server: "http://sub1.test1.example.org", |
michael@0 | 952 | allowOrigin: origin |
michael@0 | 953 | }, |
michael@0 | 954 | ], |
michael@0 | 955 | }, |
michael@0 | 956 | { pass: 0, |
michael@0 | 957 | method: "GET", |
michael@0 | 958 | hops: [{ server: "http://example.com", |
michael@0 | 959 | allowOrigin: origin |
michael@0 | 960 | }, |
michael@0 | 961 | { server: "http://test2.example.org:8000", |
michael@0 | 962 | allowOrigin: origin |
michael@0 | 963 | }, |
michael@0 | 964 | { server: "http://sub2.xn--lt-uia.example.org", |
michael@0 | 965 | allowOrigin: "*" |
michael@0 | 966 | }, |
michael@0 | 967 | { server: "http://sub1.test1.example.org", |
michael@0 | 968 | allowOrigin: "*" |
michael@0 | 969 | }, |
michael@0 | 970 | ], |
michael@0 | 971 | }, |
michael@0 | 972 | { pass: 1, |
michael@0 | 973 | method: "GET", |
michael@0 | 974 | hops: [{ server: "http://example.com", |
michael@0 | 975 | allowOrigin: origin |
michael@0 | 976 | }, |
michael@0 | 977 | { server: "http://test2.example.org:8000", |
michael@0 | 978 | allowOrigin: "*" |
michael@0 | 979 | }, |
michael@0 | 980 | { server: "http://sub2.xn--lt-uia.example.org", |
michael@0 | 981 | allowOrigin: "*" |
michael@0 | 982 | }, |
michael@0 | 983 | { server: "http://sub1.test1.example.org", |
michael@0 | 984 | allowOrigin: "*" |
michael@0 | 985 | }, |
michael@0 | 986 | ], |
michael@0 | 987 | }, |
michael@0 | 988 | { pass: 0, |
michael@0 | 989 | method: "GET", |
michael@0 | 990 | hops: [{ server: "http://example.com", |
michael@0 | 991 | allowOrigin: origin |
michael@0 | 992 | }, |
michael@0 | 993 | { server: "http://test2.example.org:8000", |
michael@0 | 994 | allowOrigin: origin |
michael@0 | 995 | }, |
michael@0 | 996 | { server: "http://sub2.xn--lt-uia.example.org", |
michael@0 | 997 | allowOrigin: "x" |
michael@0 | 998 | }, |
michael@0 | 999 | { server: "http://sub1.test1.example.org", |
michael@0 | 1000 | allowOrigin: origin |
michael@0 | 1001 | }, |
michael@0 | 1002 | ], |
michael@0 | 1003 | }, |
michael@0 | 1004 | { pass: 0, |
michael@0 | 1005 | method: "GET", |
michael@0 | 1006 | hops: [{ server: "http://example.com", |
michael@0 | 1007 | allowOrigin: origin |
michael@0 | 1008 | }, |
michael@0 | 1009 | { server: "http://test2.example.org:8000", |
michael@0 | 1010 | allowOrigin: origin |
michael@0 | 1011 | }, |
michael@0 | 1012 | { server: "http://sub2.xn--lt-uia.example.org", |
michael@0 | 1013 | allowOrigin: "*" |
michael@0 | 1014 | }, |
michael@0 | 1015 | { server: "http://sub1.test1.example.org", |
michael@0 | 1016 | allowOrigin: origin |
michael@0 | 1017 | }, |
michael@0 | 1018 | ], |
michael@0 | 1019 | }, |
michael@0 | 1020 | { pass: 0, |
michael@0 | 1021 | method: "GET", |
michael@0 | 1022 | hops: [{ server: "http://example.com", |
michael@0 | 1023 | allowOrigin: origin |
michael@0 | 1024 | }, |
michael@0 | 1025 | { server: "http://test2.example.org:8000", |
michael@0 | 1026 | allowOrigin: origin |
michael@0 | 1027 | }, |
michael@0 | 1028 | { server: "http://sub2.xn--lt-uia.example.org", |
michael@0 | 1029 | allowOrigin: "*" |
michael@0 | 1030 | }, |
michael@0 | 1031 | { server: "http://sub1.test1.example.org", |
michael@0 | 1032 | }, |
michael@0 | 1033 | ], |
michael@0 | 1034 | }, |
michael@0 | 1035 | { pass: 1, |
michael@0 | 1036 | method: "POST", |
michael@0 | 1037 | body: "hi there", |
michael@0 | 1038 | headers: { "Content-Type": "text/plain" }, |
michael@0 | 1039 | hops: [{ server: "http://example.org", |
michael@0 | 1040 | }, |
michael@0 | 1041 | { server: "http://example.com", |
michael@0 | 1042 | allowOrigin: origin, |
michael@0 | 1043 | }, |
michael@0 | 1044 | ], |
michael@0 | 1045 | }, |
michael@0 | 1046 | { pass: 0, |
michael@0 | 1047 | method: "POST", |
michael@0 | 1048 | body: "hi there", |
michael@0 | 1049 | headers: { "Content-Type": "text/plain", |
michael@0 | 1050 | "my-header": "myValue", |
michael@0 | 1051 | }, |
michael@0 | 1052 | hops: [{ server: "http://example.org", |
michael@0 | 1053 | }, |
michael@0 | 1054 | { server: "http://example.com", |
michael@0 | 1055 | allowOrigin: origin, |
michael@0 | 1056 | allowHeaders: "my-header", |
michael@0 | 1057 | }, |
michael@0 | 1058 | ], |
michael@0 | 1059 | }, |
michael@0 | 1060 | { pass: 0, |
michael@0 | 1061 | method: "DELETE", |
michael@0 | 1062 | hops: [{ server: "http://example.org", |
michael@0 | 1063 | }, |
michael@0 | 1064 | { server: "http://example.com", |
michael@0 | 1065 | allowOrigin: origin, |
michael@0 | 1066 | }, |
michael@0 | 1067 | ], |
michael@0 | 1068 | }, |
michael@0 | 1069 | { pass: 0, |
michael@0 | 1070 | method: "POST", |
michael@0 | 1071 | body: "hi there", |
michael@0 | 1072 | headers: { "Content-Type": "text/plain", |
michael@0 | 1073 | "my-header": "myValue", |
michael@0 | 1074 | }, |
michael@0 | 1075 | hops: [{ server: "http://example.com", |
michael@0 | 1076 | allowOrigin: origin, |
michael@0 | 1077 | }, |
michael@0 | 1078 | { server: "http://sub1.test1.example.org", |
michael@0 | 1079 | allowOrigin: origin, |
michael@0 | 1080 | }, |
michael@0 | 1081 | ], |
michael@0 | 1082 | }, |
michael@0 | 1083 | { pass: 0, |
michael@0 | 1084 | method: "DELETE", |
michael@0 | 1085 | hops: [{ server: "http://example.com", |
michael@0 | 1086 | allowOrigin: origin, |
michael@0 | 1087 | }, |
michael@0 | 1088 | { server: "http://sub1.test1.example.org", |
michael@0 | 1089 | allowOrigin: origin, |
michael@0 | 1090 | }, |
michael@0 | 1091 | ], |
michael@0 | 1092 | }, |
michael@0 | 1093 | { pass: 0, |
michael@0 | 1094 | method: "POST", |
michael@0 | 1095 | body: "hi there", |
michael@0 | 1096 | headers: { "Content-Type": "text/plain", |
michael@0 | 1097 | "my-header": "myValue", |
michael@0 | 1098 | }, |
michael@0 | 1099 | hops: [{ server: "http://example.com", |
michael@0 | 1100 | }, |
michael@0 | 1101 | { server: "http://sub1.test1.example.org", |
michael@0 | 1102 | allowOrigin: origin, |
michael@0 | 1103 | allowHeaders: "my-header", |
michael@0 | 1104 | }, |
michael@0 | 1105 | ], |
michael@0 | 1106 | }, |
michael@0 | 1107 | { pass: 1, |
michael@0 | 1108 | method: "POST", |
michael@0 | 1109 | body: "hi there", |
michael@0 | 1110 | headers: { "Content-Type": "text/plain" }, |
michael@0 | 1111 | hops: [{ server: "http://example.org", |
michael@0 | 1112 | }, |
michael@0 | 1113 | { server: "http://example.com", |
michael@0 | 1114 | allowOrigin: origin, |
michael@0 | 1115 | }, |
michael@0 | 1116 | ], |
michael@0 | 1117 | }, |
michael@0 | 1118 | { pass: 0, |
michael@0 | 1119 | method: "POST", |
michael@0 | 1120 | body: "hi there", |
michael@0 | 1121 | headers: { "Content-Type": "text/plain", |
michael@0 | 1122 | "my-header": "myValue", |
michael@0 | 1123 | }, |
michael@0 | 1124 | hops: [{ server: "http://example.com", |
michael@0 | 1125 | allowOrigin: origin, |
michael@0 | 1126 | allowHeaders: "my-header", |
michael@0 | 1127 | }, |
michael@0 | 1128 | { server: "http://example.org", |
michael@0 | 1129 | allowOrigin: origin, |
michael@0 | 1130 | allowHeaders: "my-header", |
michael@0 | 1131 | }, |
michael@0 | 1132 | ], |
michael@0 | 1133 | }, |
michael@0 | 1134 | ]; |
michael@0 | 1135 | |
michael@0 | 1136 | if (!runRedirectTests) { |
michael@0 | 1137 | tests = []; |
michael@0 | 1138 | } |
michael@0 | 1139 | |
michael@0 | 1140 | for (test of tests) { |
michael@0 | 1141 | req = { |
michael@0 | 1142 | url: test.hops[0].server + basePath + "hop=1&hops=" + |
michael@0 | 1143 | escape(test.hops.toSource()), |
michael@0 | 1144 | method: test.method, |
michael@0 | 1145 | headers: test.headers, |
michael@0 | 1146 | body: test.body, |
michael@0 | 1147 | }; |
michael@0 | 1148 | |
michael@0 | 1149 | if (test.pass) { |
michael@0 | 1150 | if (test.body) |
michael@0 | 1151 | req.url += "&body=" + escape(test.body); |
michael@0 | 1152 | } |
michael@0 | 1153 | |
michael@0 | 1154 | loaderWindow.postMessage(req.toSource(), origin); |
michael@0 | 1155 | |
michael@0 | 1156 | res = eval(yield); |
michael@0 | 1157 | if (test.pass) { |
michael@0 | 1158 | is(res.didFail, false, |
michael@0 | 1159 | "shouldn't have failed in test for " + test.toSource()); |
michael@0 | 1160 | is(res.status, 200, "wrong status in test for " + test.toSource()); |
michael@0 | 1161 | is(res.statusText, "OK", "wrong status text for " + test.toSource()); |
michael@0 | 1162 | is(res.responseXML, "<res>hello pass</res>", |
michael@0 | 1163 | "wrong responseXML in test for " + test.toSource()); |
michael@0 | 1164 | is(res.responseText, "<res>hello pass</res>\n", |
michael@0 | 1165 | "wrong responseText in test for " + test.toSource()); |
michael@0 | 1166 | is(res.events.join(","), |
michael@0 | 1167 | "opening,rs1,sending,loadstart,rs2,rs3,rs4,load,loadend", |
michael@0 | 1168 | "wrong responseText in test for " + test.toSource()); |
michael@0 | 1169 | } |
michael@0 | 1170 | else { |
michael@0 | 1171 | is(res.didFail, true, |
michael@0 | 1172 | "should have failed in test for " + test.toSource()); |
michael@0 | 1173 | is(res.status, 0, "wrong status in test for " + test.toSource()); |
michael@0 | 1174 | is(res.statusText, "", "wrong status text for " + test.toSource()); |
michael@0 | 1175 | is(res.responseXML, null, |
michael@0 | 1176 | "wrong responseXML in test for " + test.toSource()); |
michael@0 | 1177 | is(res.responseText, "", |
michael@0 | 1178 | "wrong responseText in test for " + test.toSource()); |
michael@0 | 1179 | is(res.events.join(","), |
michael@0 | 1180 | "opening,rs1,sending,loadstart,rs2,rs4,error,loadend", |
michael@0 | 1181 | "wrong events in test for " + test.toSource()); |
michael@0 | 1182 | is(res.progressEvents, 0, |
michael@0 | 1183 | "wrong progressevents in test for " + test.toSource()); |
michael@0 | 1184 | } |
michael@0 | 1185 | } |
michael@0 | 1186 | |
michael@0 | 1187 | |
michael@0 | 1188 | SimpleTest.finish(); |
michael@0 | 1189 | |
michael@0 | 1190 | yield undefined; |
michael@0 | 1191 | } |
michael@0 | 1192 | |
michael@0 | 1193 | </script> |
michael@0 | 1194 | </pre> |
michael@0 | 1195 | </body> |
michael@0 | 1196 | </html> |