2008-12-04 23:59:05 -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-04 23:59:05 -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.7">
|
|
|
|
|
|
|
|
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() };
|
|
|
|
|
|
|
|
loader.src = "http://example.org/tests/content/base/test/file_CrossSiteXHR_inner.html";
|
|
|
|
origin = "http://example.org";
|
|
|
|
yield;
|
|
|
|
|
|
|
|
tests = [{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
cacheTime: 3600
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue",
|
|
|
|
"y-my-header": "second" },
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "y-my-header": "hello" },
|
|
|
|
allowHeaders: "y-my-header",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "y-my-header": "hello" },
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "y-my-header": "hello" },
|
2009-02-17 14:10:50 -08:00
|
|
|
allowHeaders: "y-my-header,x-my-header",
|
2008-12-04 23:59:05 -08:00
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue",
|
|
|
|
"y-my-header": "second" },
|
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
cacheTime: 2
|
|
|
|
},
|
|
|
|
{ pause: 2.1 },
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header, y-my-header",
|
|
|
|
cacheTime: 3600
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "y-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "z-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
cacheTime: "\t 3600 \t ",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
cacheTime: "3600 3",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
cacheTime: "asdf",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "first-header": "myValue" },
|
|
|
|
allowHeaders: "first-header",
|
|
|
|
cacheTime: 2,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "second-header": "myValue" },
|
|
|
|
allowHeaders: "second-header",
|
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "third-header": "myValue" },
|
|
|
|
allowHeaders: "third-header",
|
|
|
|
cacheTime: 2,
|
|
|
|
},
|
|
|
|
{ pause: 2.1 },
|
2009-02-17 14:10:50 -08:00
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "second-header": "myValue" },
|
|
|
|
},
|
2008-12-04 23:59:05 -08:00
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "first-header": "myValue" },
|
|
|
|
},
|
2009-02-17 14:10:50 -08:00
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "first-header": "myValue" },
|
|
|
|
allowHeaders: "first-header",
|
|
|
|
cacheTime: 2,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "second-header": "myValue" },
|
|
|
|
allowHeaders: "second-header",
|
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "third-header": "myValue" },
|
|
|
|
allowHeaders: "third-header",
|
|
|
|
cacheTime: 2,
|
|
|
|
},
|
|
|
|
{ pause: 2.1 },
|
2008-12-04 23:59:05 -08:00
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "second-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "third-header": "myValue" },
|
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 0,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
2008-12-04 23:59:05 -08:00
|
|
|
},
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
|
|
|
allowMethods: "DELETE",
|
2008-12-04 23:59:05 -08:00
|
|
|
cacheTime: 3600
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
2008-12-04 23:59:05 -08:00
|
|
|
},
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
2008-12-04 23:59:05 -08:00
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "PATCH",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "PATCH",
|
|
|
|
allowMethods: "PATCH",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "PATCH",
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "PATCH",
|
|
|
|
allowMethods: "PATCH",
|
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "PATCH",
|
|
|
|
},
|
2009-02-17 14:10:50 -08:00
|
|
|
{ pass: 0,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
2008-12-04 23:59:05 -08:00
|
|
|
},
|
|
|
|
{ pass: 0,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "PUT",
|
2008-12-04 23:59:05 -08:00
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 0,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
2008-12-04 23:59:05 -08:00
|
|
|
},
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
|
|
|
allowMethods: "DELETE",
|
2008-12-04 23:59:05 -08:00
|
|
|
cacheTime: 2
|
|
|
|
},
|
|
|
|
{ pause: 2.1 },
|
|
|
|
{ pass: 0,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
2008-12-04 23:59:05 -08:00
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
|
|
|
allowMethods: "DELETE, PUT",
|
2008-12-04 23:59:05 -08:00
|
|
|
cacheTime: 3600
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
2008-12-04 23:59:05 -08:00
|
|
|
},
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "PUT",
|
2008-12-04 23:59:05 -08:00
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "PATCH",
|
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
|
|
|
method: "FIRST",
|
|
|
|
allowMethods: "FIRST",
|
|
|
|
cacheTime: 2,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "SECOND",
|
|
|
|
allowMethods: "SECOND",
|
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "THIRD",
|
|
|
|
allowMethods: "THIRD",
|
|
|
|
cacheTime: 2,
|
|
|
|
},
|
|
|
|
{ pause: 2.1 },
|
2009-02-17 14:10:50 -08:00
|
|
|
{ pass: 1,
|
|
|
|
method: "SECOND",
|
|
|
|
},
|
2008-12-04 23:59:05 -08:00
|
|
|
{ pass: 0,
|
|
|
|
method: "FIRST",
|
|
|
|
},
|
2009-02-17 14:10:50 -08:00
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
|
|
|
method: "FIRST",
|
|
|
|
allowMethods: "FIRST",
|
|
|
|
cacheTime: 2,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "SECOND",
|
|
|
|
allowMethods: "SECOND",
|
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "THIRD",
|
|
|
|
allowMethods: "THIRD",
|
|
|
|
cacheTime: 2,
|
|
|
|
},
|
|
|
|
{ pause: 2.1 },
|
2008-12-04 23:59:05 -08:00
|
|
|
{ pass: 1,
|
|
|
|
method: "SECOND",
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "THIRD",
|
|
|
|
},
|
2009-02-17 14:10:50 -08:00
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "x-value" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "x-value" }
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "y-my-header": "y-value" }
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "x-value" }
|
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "x-value" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "x-value" },
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "PUT",
|
2009-02-17 14:10:50 -08:00
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "x-value" },
|
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "x-value" },
|
|
|
|
allowHeaders: "x-my-header",
|
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "x-value" },
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
noOrigin: 1,
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
headers: { "x-my-header": "x-value" },
|
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
|
|
|
allowMethods: "DELETE",
|
2009-02-17 14:10:50 -08:00
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE"
|
2009-02-17 14:10:50 -08:00
|
|
|
},
|
|
|
|
{ pass: 0,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "PUT"
|
2009-02-17 14:10:50 -08:00
|
|
|
},
|
|
|
|
{ pass: 0,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE"
|
2009-02-17 14:10:50 -08:00
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
|
|
|
allowMethods: "DELETE",
|
2009-02-17 14:10:50 -08:00
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE"
|
2009-02-17 14:10:50 -08:00
|
|
|
},
|
|
|
|
{ pass: 0,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
2009-02-17 14:10:50 -08:00
|
|
|
headers: { "my-header": "value" },
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE"
|
2009-02-17 14:10:50 -08:00
|
|
|
},
|
|
|
|
{ newTest: "*******" },
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE",
|
|
|
|
allowMethods: "DELETE",
|
2009-02-17 14:10:50 -08:00
|
|
|
cacheTime: 3600,
|
|
|
|
},
|
|
|
|
{ pass: 1,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE"
|
2009-02-17 14:10:50 -08:00
|
|
|
},
|
|
|
|
{ pass: 0,
|
|
|
|
method: "GET",
|
|
|
|
noOrigin: 1,
|
|
|
|
},
|
|
|
|
{ pass: 0,
|
2009-02-18 05:31:30 -08:00
|
|
|
method: "DELETE"
|
2009-02-17 14:10:50 -08:00
|
|
|
},
|
2008-12-04 23:59:05 -08:00
|
|
|
];
|
|
|
|
|
2010-03-12 13:53:36 -08:00
|
|
|
baseURL = "http://mochi.test:8888/tests/content/base/test/" +
|
2008-12-04 23:59:05 -08:00
|
|
|
"file_CrossSiteXHR_cache_server.sjs?";
|
2009-02-17 14:10:50 -08:00
|
|
|
setStateURL = baseURL + "setState=";
|
2008-12-04 23:59:05 -08:00
|
|
|
|
|
|
|
var unique = Date.now();
|
|
|
|
for each (test in tests) {
|
|
|
|
if (test.newTest) {
|
|
|
|
unique++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (test.pause) {
|
|
|
|
setTimeout(function() { gen.next() }, test.pause * 1000);
|
|
|
|
yield;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
req = {
|
2009-02-17 14:10:50 -08:00
|
|
|
url: baseURL + "c=" + unique,
|
2008-12-04 23:59:05 -08:00
|
|
|
method: test.method,
|
|
|
|
headers: test.headers,
|
|
|
|
};
|
|
|
|
|
2009-02-17 14:10:50 -08:00
|
|
|
sec = { allowOrigin: test.noOrigin ? "" : origin,
|
|
|
|
allowHeaders: test.allowHeaders,
|
|
|
|
allowMethods: test.allowMethods,
|
|
|
|
cacheTime: test.cacheTime };
|
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("POST", setStateURL + escape(sec.toSource()), false);
|
|
|
|
xhr.send();
|
2008-12-04 23:59:05 -08:00
|
|
|
|
|
|
|
loaderWindow.postMessage(req.toSource(), origin);
|
|
|
|
|
|
|
|
res = eval(yield);
|
|
|
|
|
|
|
|
testName = test.toSource() + " (index " + tests.indexOf(test) + ")";
|
|
|
|
|
|
|
|
if (test.pass) {
|
|
|
|
is(res.didFail, false,
|
|
|
|
"shouldn't have failed in test for " + testName);
|
|
|
|
is(res.status, 200, "wrong status in test for " + testName);
|
|
|
|
is(res.responseXML, "<res>hello pass</res>",
|
|
|
|
"wrong responseXML in test for " + testName);
|
|
|
|
is(res.responseText, "<res>hello pass</res>\n",
|
|
|
|
"wrong responseText in test for " + testName);
|
|
|
|
is(res.events.join(","),
|
|
|
|
"opening,rs1,sending,rs1,loadstart,rs2,rs3,rs4,load",
|
|
|
|
"wrong events in test for " + testName);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
is(res.didFail, true,
|
|
|
|
"should have failed in test for " + testName);
|
|
|
|
is(res.status, 0, "wrong status in test for " + testName);
|
|
|
|
is(res.responseXML, null,
|
|
|
|
"wrong responseXML in test for " + testName);
|
|
|
|
is(res.responseText, "",
|
|
|
|
"wrong responseText in test for " + testName);
|
|
|
|
is(res.events.join(","),
|
|
|
|
"opening,rs1,sending,rs1,loadstart,rs2,rs4,error",
|
|
|
|
"wrong events in test for " + testName);
|
|
|
|
is(res.progressEvents, 0,
|
|
|
|
"wrong events in test for " + testName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|