2008-12-27 15:26:55 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
|
|
|
|
<title>Test for Cross Site XMLHttpRequest</title>
|
2009-05-06 13:46:04 -07:00
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
2008-12-27 15:26:55 -08:00
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body onload="gen.next()">
|
|
|
|
<p id="display">
|
|
|
|
<iframe id=loader></iframe>
|
|
|
|
</p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="application/javascript;version=1.8">
|
|
|
|
|
2009-02-24 11:46:51 -08:00
|
|
|
const runPreflightTests = 1;
|
|
|
|
const runCookieTests = 1;
|
|
|
|
const runRedirectTests = 1;
|
|
|
|
|
2008-12-27 15:26:55 -08:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
window.addEventListener("message", function(e) {
|
|
|
|
gen.send(e.data);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
gen = runTest();
|
|
|
|
|
|
|
|
function runTest() {
|
|
|
|
var loader = document.getElementById('loader');
|
|
|
|
var loaderWindow = loader.contentWindow;
|
|
|
|
loader.onload = function () { gen.next() };
|
|
|
|
|
|
|
|
// Test preflight-less requests
|
2009-01-21 14:50:28 -08:00
|
|
|
basePath = "/tests/content/base/test/file_CrossSiteXHR_server.sjs?"
|
2010-03-12 13:53:36 -08:00
|
|
|
baseURL = "http://mochi.test:8888" + basePath;
|
2009-02-24 11:46:51 -08:00
|
|
|
|
2008-12-27 15:26:55 -08:00
|
|
|
// Test preflighted requests
|
|
|
|
loader.src = "http://example.org/tests/content/base/test/file_CrossSiteXHR_inner.html";
|
|
|
|
origin = "http://example.org";
|
|
|
|
yield;
|
|
|
|
|
2010-10-04 17:41:07 -07:00
|
|
|
tests = [// Plain request
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
2009-01-21 14:50:28 -08:00
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
|
2010-11-30 10:18:15 -08:00
|
|
|
// undefined username
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
username: undefined
|
|
|
|
},
|
|
|
|
|
|
|
|
// undefined username and password
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
username: undefined,
|
|
|
|
password: undefined
|
|
|
|
},
|
|
|
|
|
|
|
|
// nonempty username
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
username: "user",
|
|
|
|
},
|
|
|
|
|
|
|
|
// nonempty password
|
|
|
|
// XXXbz this passes for now, because we ignore passwords
|
|
|
|
// without usernames in most cases.
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
password: "password",
|
|
|
|
},
|
|
|
|
|
2010-10-04 17:41:07 -07:00
|
|
|
// Default allowed headers
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "Content-Type": "text/plain",
|
|
|
|
"Accept": "foo/bar",
|
|
|
|
"Accept-Language": "sv-SE" },
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "Content-Type": "foo/bar",
|
2009-01-21 14:50:28 -08:00
|
|
|
"Accept": "foo/bar",
|
|
|
|
"Accept-Language": "sv-SE" },
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
|
|
|
|
// Custom headers
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "X-My-Header",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue",
|
|
|
|
"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" },
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my%-header": "myValue" },
|
|
|
|
allowHeaders: "x-my%-header",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "" },
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "y-my-header",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header y-my-header",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header, y-my-header z",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header, y-my-he(ader",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "myheader": "" },
|
|
|
|
allowMethods: "myheader",
|
|
|
|
},
|
|
|
|
|
|
|
|
// Multiple custom headers
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "x-my-header": "myValue",
|
|
|
|
"second-header": "secondValue",
|
|
|
|
"third-header": "thirdValue" },
|
|
|
|
allowHeaders: "x-my-header, second-header, third-header",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "x-my-header": "myValue",
|
|
|
|
"second-header": "secondValue",
|
|
|
|
"third-header": "thirdValue" },
|
|
|
|
allowHeaders: "x-my-header,second-header,third-header",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "x-my-header": "myValue",
|
|
|
|
"second-header": "secondValue",
|
|
|
|
"third-header": "thirdValue" },
|
|
|
|
allowHeaders: "x-my-header ,second-header ,third-header",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "x-my-header": "myValue",
|
|
|
|
"second-header": "secondValue",
|
|
|
|
"third-header": "thirdValue" },
|
|
|
|
allowHeaders: "x-my-header , second-header , third-header",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "x-my-header": "myValue",
|
|
|
|
"second-header": "secondValue" },
|
|
|
|
allowHeaders: ", x-my-header, , ,, second-header, , ",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "x-my-header": "myValue",
|
|
|
|
"second-header": "secondValue" },
|
|
|
|
allowHeaders: "x-my-header, second-header, unused-header",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "x-my-header": "myValue",
|
2010-10-04 17:41:07 -07:00
|
|
|
"y-my-header": "secondValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "",
|
|
|
|
"y-my-header": "" },
|
|
|
|
allowHeaders: "x-my-header",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
|
|
|
|
// HEAD requests
|
|
|
|
{ pass: 1,
|
|
|
|
method: "HEAD",
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
|
|
|
|
|
|
|
// HEAD with safe headers
|
|
|
|
{ pass: 1,
|
|
|
|
method: "HEAD",
|
|
|
|
headers: { "Content-Type": "text/plain",
|
|
|
|
"Accept": "foo/bar",
|
|
|
|
"Accept-Language": "sv-SE" },
|
2009-01-21 14:50:28 -08:00
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "HEAD",
|
|
|
|
headers: { "Content-Type": "foo/bar",
|
2008-12-27 15:26:55 -08:00
|
|
|
"Accept": "foo/bar",
|
|
|
|
"Accept-Language": "sv-SE" },
|
2009-01-21 14:50:28 -08:00
|
|
|
noAllowPreflight: 1,
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
|
|
|
|
// HEAD with custom headers
|
|
|
|
{ pass: 1,
|
|
|
|
method: "HEAD",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "HEAD",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "HEAD",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "HEAD",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "y-my-header",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "HEAD",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header y-my-header",
|
|
|
|
},
|
|
|
|
|
|
|
|
// POST tests
|
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
2009-01-13 22:53:43 -08:00
|
|
|
body: "hi there",
|
2008-12-27 15:26:55 -08:00
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
|
|
|
noAllowPreflight: 1,
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
|
|
|
|
// POST with standard headers
|
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
2009-01-13 22:53:43 -08:00
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "text/plain" },
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "multipart/form-data" },
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "POST",
|
2009-01-13 22:53:43 -08:00
|
|
|
body: "hi there",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "Content-Type": "foo/bar" },
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "POST",
|
|
|
|
headers: { "Content-Type": "foo/bar" },
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
2009-01-13 22:53:43 -08:00
|
|
|
body: "hi there",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "Content-Type": "text/plain",
|
|
|
|
"Accept": "foo/bar",
|
|
|
|
"Accept-Language": "sv-SE" },
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
|
|
|
|
// POST with custom headers
|
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
2009-01-13 22:53:43 -08:00
|
|
|
body: "hi there",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "Accept": "foo/bar",
|
|
|
|
"Accept-Language": "sv-SE",
|
|
|
|
"x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
|
|
|
headers: { "Content-Type": "text/plain",
|
|
|
|
"x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "Content-Type": "text/plain",
|
|
|
|
"x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "foo/bar",
|
|
|
|
"x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header, content-type",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "foo/bar" },
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "POST",
|
2009-01-13 22:53:43 -08:00
|
|
|
body: "hi there",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "Content-Type": "foo/bar",
|
|
|
|
"x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
2009-01-13 22:53:43 -08:00
|
|
|
body: "hi there",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header, $_%",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
|
|
|
|
// Other methods
|
|
|
|
{ pass: 1,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "DELETE",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
|
|
|
allowHeaders: "DELETE",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
|
|
|
allowMethods: "",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "POST, PUT, DELETE",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "POST, DELETE, PUT",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "DELETE, POST, PUT",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "POST ,PUT ,DELETE",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "POST,PUT,DELETE",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "POST , PUT , DELETE",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: " ,, PUT ,, , , DELETE , ,",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
2008-12-27 15:26:55 -08:00
|
|
|
allowMethods: "PUT",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "DELETEZ",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "DELETE PUT",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "DELETE, PUT Z",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "DELETE, PU(T",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "PUT DELETE",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "PUT Z, DELETE",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
2009-02-18 05:31:30 -08:00
|
|
|
allowMethods: "PU(T, DELETE",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "MYMETHOD",
|
2008-12-27 15:26:55 -08:00
|
|
|
allowMethods: "myMethod",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 0,
|
|
|
|
method: "PUT",
|
2008-12-27 15:26:55 -08:00
|
|
|
allowMethods: "put",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
|
|
|
|
// Progress events
|
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
2009-01-13 22:53:43 -08:00
|
|
|
body: "hi there",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "Content-Type": "text/plain" },
|
|
|
|
uploadProgress: "uploadprogress",
|
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
2009-01-13 22:53:43 -08:00
|
|
|
body: "hi there",
|
2008-12-27 15:26:55 -08:00
|
|
|
headers: { "Content-Type": "text/plain" },
|
2010-10-04 17:41:07 -07:00
|
|
|
uploadProgress: "progress",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "text/plain" },
|
|
|
|
uploadProgress: "uploadprogress",
|
2008-12-27 15:26:55 -08:00
|
|
|
noAllowPreflight: 1,
|
2010-10-04 17:41:07 -07:00
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "text/plain" },
|
2008-12-27 15:26:55 -08:00
|
|
|
uploadProgress: "progress",
|
2010-10-04 17:41:07 -07:00
|
|
|
noAllowPreflight: 1,
|
|
|
|
},
|
|
|
|
|
|
|
|
// Status messages
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
status: 404,
|
|
|
|
statusMessage: "nothin' here",
|
2008-12-27 15:26:55 -08:00
|
|
|
},
|
2010-10-04 17:41:07 -07:00
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
status: 401,
|
|
|
|
statusMessage: "no can do",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "foo/bar" },
|
|
|
|
allowHeaders: "content-type",
|
|
|
|
status: 500,
|
|
|
|
statusMessage: "server boo",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
noAllowPreflight: 1,
|
|
|
|
status: 200,
|
|
|
|
statusMessage: "Yes!!",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "header value" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
preflightStatus: 400
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "header value" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
preflightStatus: 200
|
|
|
|
},
|
|
|
|
|
2010-10-04 18:25:44 -07:00
|
|
|
// exposed headers
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
responseHeaders: { "x-my-header": "x header" },
|
|
|
|
exposeHeaders: "x-my-header",
|
|
|
|
expectedResponseHeaders: ["x-my-header"],
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
origin: "http://invalid",
|
|
|
|
responseHeaders: { "x-my-header": "x header" },
|
|
|
|
exposeHeaders: "x-my-header",
|
|
|
|
expectedResponseHeaders: [],
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
responseHeaders: { "x-my-header": "x header" },
|
|
|
|
expectedResponseHeaders: [],
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
responseHeaders: { "x-my-header": "x header" },
|
|
|
|
exposeHeaders: "x-my-header y",
|
|
|
|
expectedResponseHeaders: [],
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
responseHeaders: { "x-my-header": "x header" },
|
|
|
|
exposeHeaders: "y x-my-header",
|
|
|
|
expectedResponseHeaders: [],
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
responseHeaders: { "x-my-header": "x header" },
|
|
|
|
exposeHeaders: "x-my-header, y-my-header z",
|
|
|
|
expectedResponseHeaders: [],
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
responseHeaders: { "x-my-header": "x header" },
|
|
|
|
exposeHeaders: "x-my-header, y-my-hea(er",
|
|
|
|
expectedResponseHeaders: [],
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
responseHeaders: { "x-my-header": "x header",
|
|
|
|
"y-my-header": "y header" },
|
|
|
|
exposeHeaders: " , ,,y-my-header,z-my-header, ",
|
|
|
|
expectedResponseHeaders: ["y-my-header"],
|
|
|
|
},
|
2008-12-27 15:26:55 -08:00
|
|
|
];
|
|
|
|
|
2009-02-24 11:46:51 -08:00
|
|
|
if (!runPreflightTests) {
|
2010-10-04 17:41:07 -07:00
|
|
|
tests = [];
|
2009-02-24 11:46:51 -08:00
|
|
|
}
|
|
|
|
|
2010-10-04 17:41:07 -07:00
|
|
|
for each(test in tests) {
|
|
|
|
var req = {
|
2010-10-04 18:25:44 -07:00
|
|
|
url: baseURL + "allowOrigin=" + escape(test.origin || origin),
|
2008-12-27 15:26:55 -08:00
|
|
|
method: test.method,
|
|
|
|
headers: test.headers,
|
|
|
|
uploadProgress: test.uploadProgress,
|
2009-01-13 22:53:43 -08:00
|
|
|
body: test.body,
|
2010-10-04 18:25:44 -07:00
|
|
|
responseHeaders: test.responseHeaders,
|
2008-12-27 15:26:55 -08:00
|
|
|
};
|
|
|
|
|
2010-10-04 17:41:07 -07:00
|
|
|
if (test.pass) {
|
|
|
|
req.url += "&origin=" + escape(origin) +
|
|
|
|
"&requestMethod=" + test.method;
|
|
|
|
}
|
|
|
|
|
2010-11-30 10:18:15 -08:00
|
|
|
if ("username" in test) {
|
|
|
|
req.username = test.username;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("password" in test) {
|
|
|
|
req.password = test.password;
|
|
|
|
}
|
|
|
|
|
2008-12-27 15:26:55 -08:00
|
|
|
if (test.noAllowPreflight)
|
|
|
|
req.url += "&noAllowPreflight";
|
|
|
|
|
2010-10-04 17:41:07 -07:00
|
|
|
if (test.pass && "headers" in test) {
|
|
|
|
function isUnsafeHeader(name) {
|
|
|
|
lName = name.toLowerCase();
|
|
|
|
return lName != "accept" &&
|
|
|
|
lName != "accept-language" &&
|
|
|
|
(lName != "content-type" ||
|
|
|
|
["text/plain",
|
|
|
|
"multipart/form-data",
|
|
|
|
"application/x-www-form-urlencoded"]
|
|
|
|
.indexOf(test.headers[name].toLowerCase()) == -1);
|
|
|
|
}
|
2008-12-27 15:26:55 -08:00
|
|
|
req.url += "&headers=" + escape(test.headers.toSource());
|
|
|
|
reqHeaders =
|
2010-10-04 17:41:07 -07:00
|
|
|
escape([name for (name in test.headers)]
|
|
|
|
.filter(isUnsafeHeader)
|
|
|
|
.map(String.toLowerCase)
|
|
|
|
.sort()
|
|
|
|
.join(","));
|
2008-12-27 15:26:55 -08:00
|
|
|
req.url += reqHeaders ? "&requestHeaders=" + reqHeaders : "";
|
|
|
|
}
|
|
|
|
if ("allowHeaders" in test)
|
|
|
|
req.url += "&allowHeaders=" + escape(test.allowHeaders);
|
|
|
|
if ("allowMethods" in test)
|
|
|
|
req.url += "&allowMethods=" + escape(test.allowMethods);
|
2009-02-24 11:46:51 -08:00
|
|
|
if (test.body)
|
|
|
|
req.url += "&body=" + escape(test.body);
|
2010-10-04 17:41:07 -07:00
|
|
|
if (test.status) {
|
|
|
|
req.url += "&status=" + test.status;
|
|
|
|
req.url += "&statusMessage=" + escape(test.statusMessage);
|
|
|
|
}
|
|
|
|
if (test.preflightStatus)
|
|
|
|
req.url += "&preflightStatus=" + test.preflightStatus;
|
2010-10-04 18:25:44 -07:00
|
|
|
if (test.responseHeaders)
|
|
|
|
req.url += "&responseHeaders=" + escape(test.responseHeaders.toSource());
|
|
|
|
if (test.exposeHeaders)
|
|
|
|
req.url += "&exposeHeaders=" + escape(test.exposeHeaders);
|
2008-12-27 15:26:55 -08:00
|
|
|
|
|
|
|
loaderWindow.postMessage(req.toSource(), origin);
|
|
|
|
res = eval(yield);
|
2010-10-04 17:41:07 -07:00
|
|
|
|
|
|
|
if (test.pass) {
|
|
|
|
is(res.didFail, false,
|
|
|
|
"shouldn't have failed in test for " + test.toSource());
|
|
|
|
if (test.status) {
|
|
|
|
is(res.status, test.status, "wrong status in test for " + test.toSource());
|
|
|
|
is(res.statusText, test.statusMessage, "wrong status text for " + test.toSource());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
is(res.status, 200, "wrong status in test for " + test.toSource());
|
|
|
|
is(res.statusText, "OK", "wrong status text for " + test.toSource());
|
|
|
|
}
|
|
|
|
if (test.method !== "HEAD") {
|
|
|
|
is(res.responseXML, "<res>hello pass</res>",
|
|
|
|
"wrong responseXML in test for " + test.toSource());
|
|
|
|
is(res.responseText, "<res>hello pass</res>\n",
|
|
|
|
"wrong responseText in test for " + test.toSource());
|
|
|
|
is(res.events.join(","),
|
|
|
|
"opening,rs1,sending,rs1,loadstart,rs2,rs3,rs4,load",
|
|
|
|
"wrong responseText in test for " + test.toSource());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
is(res.responseXML, null,
|
|
|
|
"wrong responseXML in test for " + test.toSource());
|
|
|
|
is(res.responseText, "",
|
|
|
|
"wrong responseText in test for " + test.toSource());
|
|
|
|
is(res.events.join(","),
|
|
|
|
"opening,rs1,sending,rs1,loadstart,rs2,rs4,load",
|
|
|
|
"wrong responseText in test for " + test.toSource());
|
|
|
|
}
|
2010-10-04 18:25:44 -07:00
|
|
|
if (test.responseHeaders) {
|
|
|
|
for (header in test.responseHeaders) {
|
|
|
|
if (test.expectedResponseHeaders.indexOf(header) == -1) {
|
|
|
|
is(res.responseHeaders[header], null,
|
|
|
|
"wrong response header (" + header + ") in test for " +
|
|
|
|
test.toSource());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
is(res.responseHeaders[header], test.responseHeaders[header],
|
|
|
|
"wrong response header (" + header + ") in test for " +
|
|
|
|
test.toSource());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-21 14:50:28 -08:00
|
|
|
}
|
|
|
|
else {
|
2010-10-04 17:41:07 -07:00
|
|
|
is(res.didFail, true,
|
|
|
|
"should have failed in test for " + test.toSource());
|
|
|
|
is(res.status, 0, "wrong status in test for " + test.toSource());
|
2010-11-30 10:18:15 -08:00
|
|
|
is(res.statusText, "", "wrong status text for " + test.toSource());
|
2009-01-21 14:50:28 -08:00
|
|
|
is(res.responseXML, null,
|
|
|
|
"wrong responseXML in test for " + test.toSource());
|
|
|
|
is(res.responseText, "",
|
|
|
|
"wrong responseText in test for " + test.toSource());
|
2010-11-30 10:18:15 -08:00
|
|
|
if (!res.sendThrew) {
|
|
|
|
is(res.events.join(","),
|
|
|
|
"opening,rs1,sending,rs1,loadstart,rs2,rs4,error",
|
|
|
|
"wrong events in test for " + test.toSource());
|
|
|
|
}
|
2010-10-04 17:41:07 -07:00
|
|
|
is(res.progressEvents, 0,
|
|
|
|
"wrong events in test for " + test.toSource());
|
2010-10-04 18:25:44 -07:00
|
|
|
if (test.responseHeaders) {
|
|
|
|
for (header in test.responseHeaders) {
|
|
|
|
is(res.responseHeaders[header], null,
|
|
|
|
"wrong response header (" + header + ") in test for " +
|
|
|
|
test.toSource());
|
|
|
|
}
|
|
|
|
}
|
2009-01-21 14:50:28 -08:00
|
|
|
}
|
2008-12-27 15:26:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test cookie behavior
|
|
|
|
tests = [{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
withCred: 1,
|
|
|
|
allowCred: 1,
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
withCred: 1,
|
|
|
|
allowCred: 0,
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
withCred: 1,
|
|
|
|
allowCred: 1,
|
|
|
|
origin: "*",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
withCred: 0,
|
|
|
|
allowCred: 1,
|
|
|
|
origin: "*",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
setCookie: "a=1",
|
|
|
|
withCred: 1,
|
|
|
|
allowCred: 1,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
cookie: "a=1",
|
|
|
|
withCred: 1,
|
|
|
|
allowCred: 1,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
noCookie: 1,
|
|
|
|
withCred: 0,
|
|
|
|
allowCred: 1,
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
noCookie: 1,
|
|
|
|
withCred: 1,
|
|
|
|
allowCred: 1,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
setCookie: "a=2",
|
|
|
|
withCred: 0,
|
|
|
|
allowCred: 1,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
cookie: "a=1",
|
|
|
|
withCred: 1,
|
|
|
|
allowCred: 1,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
setCookie: "a=2",
|
|
|
|
withCred: 1,
|
|
|
|
allowCred: 1,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
cookie: "a=2",
|
|
|
|
withCred: 1,
|
|
|
|
allowCred: 1,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2009-02-24 11:46:51 -08:00
|
|
|
if (!runCookieTests) {
|
|
|
|
tests = [];
|
|
|
|
}
|
|
|
|
|
2008-12-27 15:26:55 -08:00
|
|
|
for each(test in tests) {
|
|
|
|
req = {
|
|
|
|
url: baseURL + "allowOrigin=" + escape(test.origin || origin),
|
|
|
|
method: test.method,
|
|
|
|
headers: test.headers,
|
|
|
|
withCred: test.withCred,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (test.allowCred)
|
|
|
|
req.url += "&allowCred";
|
|
|
|
|
|
|
|
if (test.setCookie)
|
|
|
|
req.url += "&setCookie=" + escape(test.setCookie);
|
|
|
|
if (test.cookie)
|
|
|
|
req.url += "&cookie=" + escape(test.cookie);
|
|
|
|
if (test.noCookie)
|
|
|
|
req.url += "&noCookie";
|
|
|
|
|
|
|
|
if ("allowHeaders" in test)
|
|
|
|
req.url += "&allowHeaders=" + escape(test.allowHeaders);
|
|
|
|
if ("allowMethods" in test)
|
|
|
|
req.url += "&allowMethods=" + escape(test.allowMethods);
|
|
|
|
|
|
|
|
loaderWindow.postMessage(req.toSource(), origin);
|
|
|
|
|
|
|
|
res = eval(yield);
|
|
|
|
if (test.pass) {
|
|
|
|
is(res.didFail, false,
|
|
|
|
"shouldn't have failed in test for " + test.toSource());
|
|
|
|
is(res.status, 200, "wrong status in test for " + test.toSource());
|
2010-03-16 16:23:45 -07:00
|
|
|
is(res.statusText, "OK", "wrong status text for " + test.toSource());
|
2008-12-27 15:26:55 -08:00
|
|
|
is(res.responseXML, "<res>hello pass</res>",
|
|
|
|
"wrong responseXML in test for " + test.toSource());
|
|
|
|
is(res.responseText, "<res>hello pass</res>\n",
|
|
|
|
"wrong responseText in test for " + test.toSource());
|
|
|
|
is(res.events.join(","),
|
|
|
|
"opening,rs1,sending,rs1,loadstart,rs2,rs3,rs4,load",
|
|
|
|
"wrong responseText in test for " + test.toSource());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
is(res.didFail, true,
|
|
|
|
"should have failed in test for " + test.toSource());
|
|
|
|
is(res.status, 0, "wrong status in test for " + test.toSource());
|
2010-11-30 10:18:15 -08:00
|
|
|
is(res.statusText, "", "wrong status text for " + test.toSource());
|
2008-12-27 15:26:55 -08:00
|
|
|
is(res.responseXML, null,
|
|
|
|
"wrong responseXML in test for " + test.toSource());
|
|
|
|
is(res.responseText, "",
|
|
|
|
"wrong responseText in test for " + test.toSource());
|
|
|
|
is(res.events.join(","),
|
|
|
|
"opening,rs1,sending,rs1,loadstart,rs2,rs4,error",
|
|
|
|
"wrong events in test for " + test.toSource());
|
|
|
|
is(res.progressEvents, 0,
|
|
|
|
"wrong events in test for " + test.toSource());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-21 14:50:28 -08:00
|
|
|
// Test redirects
|
|
|
|
is(loader.src, "http://example.org/tests/content/base/test/file_CrossSiteXHR_inner.html");
|
|
|
|
is(origin, "http://example.org");
|
|
|
|
|
|
|
|
tests = [{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
hops: [{ server: "http://example.com",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
hops: [{ server: "http://example.com",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://example.org",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
hops: [{ server: "http://example.com",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://example.org",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
hops: [{ server: "http://example.org",
|
|
|
|
},
|
|
|
|
{ server: "http://example.org",
|
|
|
|
},
|
|
|
|
{ server: "http://example.com",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
hops: [{ server: "http://example.org",
|
|
|
|
},
|
|
|
|
{ server: "http://example.org",
|
|
|
|
},
|
|
|
|
{ server: "http://example.com",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://example.org",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
hops: [{ server: "http://example.com",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://test2.example.org:8000",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://sub2.xn--lt-uia.example.org",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://sub1.test1.example.org",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
hops: [{ server: "http://example.com",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://test2.example.org:8000",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://sub2.xn--lt-uia.example.org",
|
|
|
|
allowOrigin: "x"
|
|
|
|
},
|
|
|
|
{ server: "http://sub1.test1.example.org",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
hops: [{ server: "http://example.com",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://test2.example.org:8000",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://sub2.xn--lt-uia.example.org",
|
|
|
|
allowOrigin: "*"
|
|
|
|
},
|
|
|
|
{ server: "http://sub1.test1.example.org",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
hops: [{ server: "http://example.com",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://test2.example.org:8000",
|
|
|
|
allowOrigin: origin
|
|
|
|
},
|
|
|
|
{ server: "http://sub2.xn--lt-uia.example.org",
|
|
|
|
allowOrigin: "*"
|
|
|
|
},
|
|
|
|
{ server: "http://sub1.test1.example.org",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2009-02-24 11:46:51 -08:00
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "text/plain" },
|
|
|
|
hops: [{ server: "http://example.org",
|
|
|
|
},
|
|
|
|
{ server: "http://example.com",
|
|
|
|
allowOrigin: origin,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "text/plain",
|
|
|
|
"my-header": "myValue",
|
|
|
|
},
|
|
|
|
hops: [{ server: "http://example.org",
|
|
|
|
},
|
|
|
|
{ server: "http://example.com",
|
|
|
|
allowOrigin: origin,
|
|
|
|
allowHeaders: "my-header",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
|
|
|
hops: [{ server: "http://example.org",
|
|
|
|
},
|
|
|
|
{ server: "http://example.com",
|
|
|
|
allowOrigin: origin,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "text/plain",
|
|
|
|
"my-header": "myValue",
|
|
|
|
},
|
|
|
|
hops: [{ server: "http://example.com",
|
|
|
|
allowOrigin: origin,
|
|
|
|
},
|
|
|
|
{ server: "http://sub1.test1.example.org",
|
|
|
|
allowOrigin: origin,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "DELETE",
|
|
|
|
hops: [{ server: "http://example.com",
|
|
|
|
allowOrigin: origin,
|
|
|
|
},
|
|
|
|
{ server: "http://sub1.test1.example.org",
|
|
|
|
allowOrigin: origin,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "text/plain",
|
|
|
|
"my-header": "myValue",
|
|
|
|
},
|
|
|
|
hops: [{ server: "http://example.com",
|
|
|
|
},
|
|
|
|
{ server: "http://sub1.test1.example.org",
|
|
|
|
allowOrigin: origin,
|
|
|
|
allowHeaders: "my-header",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "text/plain" },
|
|
|
|
hops: [{ server: "http://example.org",
|
|
|
|
},
|
|
|
|
{ server: "http://example.com",
|
|
|
|
allowOrigin: origin,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "POST",
|
|
|
|
body: "hi there",
|
|
|
|
headers: { "Content-Type": "text/plain",
|
|
|
|
"my-header": "myValue",
|
|
|
|
},
|
|
|
|
hops: [{ server: "http://example.com",
|
|
|
|
allowOrigin: origin,
|
|
|
|
allowHeaders: "my-header",
|
|
|
|
},
|
|
|
|
{ server: "http://example.org",
|
|
|
|
allowOrigin: origin,
|
|
|
|
allowHeaders: "my-header",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2009-01-21 14:50:28 -08:00
|
|
|
];
|
|
|
|
|
2009-02-24 11:46:51 -08:00
|
|
|
if (!runRedirectTests) {
|
|
|
|
tests = [];
|
|
|
|
}
|
|
|
|
|
2009-01-21 14:50:28 -08:00
|
|
|
for each(test in tests) {
|
|
|
|
req = {
|
|
|
|
url: test.hops[0].server + basePath + "hop=1&hops=" +
|
|
|
|
escape(test.hops.toSource()),
|
|
|
|
method: test.method,
|
2009-02-24 11:46:51 -08:00
|
|
|
headers: test.headers,
|
|
|
|
body: test.body,
|
2009-01-21 14:50:28 -08:00
|
|
|
};
|
|
|
|
|
2009-02-24 11:46:51 -08:00
|
|
|
if (test.pass) {
|
|
|
|
if (test.body)
|
|
|
|
req.url += "&body=" + escape(test.body);
|
|
|
|
}
|
|
|
|
|
2009-01-21 14:50:28 -08:00
|
|
|
loaderWindow.postMessage(req.toSource(), origin);
|
|
|
|
|
|
|
|
res = eval(yield);
|
|
|
|
if (test.pass) {
|
|
|
|
is(res.didFail, false,
|
|
|
|
"shouldn't have failed in test for " + test.toSource());
|
|
|
|
is(res.status, 200, "wrong status in test for " + test.toSource());
|
2010-03-16 16:23:45 -07:00
|
|
|
is(res.statusText, "OK", "wrong status text for " + test.toSource());
|
2009-01-21 14:50:28 -08:00
|
|
|
is(res.responseXML, "<res>hello pass</res>",
|
|
|
|
"wrong responseXML in test for " + test.toSource());
|
|
|
|
is(res.responseText, "<res>hello pass</res>\n",
|
|
|
|
"wrong responseText in test for " + test.toSource());
|
|
|
|
is(res.events.join(","),
|
|
|
|
"opening,rs1,sending,rs1,loadstart,rs2,rs3,rs4,load",
|
|
|
|
"wrong responseText in test for " + test.toSource());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
is(res.didFail, true,
|
|
|
|
"should have failed in test for " + test.toSource());
|
|
|
|
is(res.status, 0, "wrong status in test for " + test.toSource());
|
2010-11-30 10:18:15 -08:00
|
|
|
is(res.statusText, "", "wrong status text for " + test.toSource());
|
2009-01-21 14:50:28 -08:00
|
|
|
is(res.responseXML, null,
|
|
|
|
"wrong responseXML in test for " + test.toSource());
|
|
|
|
is(res.responseText, "",
|
|
|
|
"wrong responseText in test for " + test.toSource());
|
|
|
|
is(res.events.join(","),
|
|
|
|
"opening,rs1,sending,rs1,loadstart,rs2,rs4,error",
|
|
|
|
"wrong events in test for " + test.toSource());
|
|
|
|
is(res.progressEvents, 0,
|
2009-02-24 11:46:51 -08:00
|
|
|
"wrong progressevents in test for " + test.toSource());
|
2009-01-21 14:50:28 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-27 15:26:55 -08:00
|
|
|
SimpleTest.finish();
|
|
|
|
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|