Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebKit CORS tests (originally from r102004) #117

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions cors/access-control-and-redirects.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<p>Tests that redirects between origins are never allowed, even when access control is involved.</p>
<p>Per the spec, these test cases should be allowed, but cross-origin redirects are currently unsupported in WebCore.</p>

<pre id="console"></pre>
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}

function log(message)
{
document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
}

function runTest(url, expectSyncSuccess, expectAsyncSuccess)
{
log("Testing " + url + " (sync)");
log("Expecting success: " + expectSyncSuccess);

var req = new XMLHttpRequest();
req.open("GET", url, false);

try {
req.send(null);
log((expectSyncSuccess ? "PASS" : "FAIL") + ": " + req.responseText);
} catch (ex) {
log((expectSyncSuccess ? "FAIL" : "PASS") + ": " + ex);
}

log("Testing " + url + "(async)");
log("Expecting success: " + expectAsyncSuccess);

req = new XMLHttpRequest();
req.open("GET", url, true);
req.onload = function() {
log((expectAsyncSuccess ? "PASS" : "FAIL") + ": " + req.responseText);
nextTest();
}
req.onerror = function() {
log((expectAsyncSuccess ? "FAIL" : "PASS") + ": " + req.status);
nextTest();
}
req.send(null);
}

var tests = [
["/resources/redirect.php?url=http://localhost:8000/xmlhttprequest/resources/access-control-basic-allow.cgi", false, false],
["http://localhost:8000/resources/redirect.php?url=http://127.0.0.1:8000/xmlhttprequest/resources/access-control-basic-allow.cgi", false, false],
["http://localhost:8000/resources/redirect.php?url=http://localhost:8000/xmlhttprequest/resources/access-control-basic-allow.cgi", false, false]
]

var currentTest = 0;

function nextTest() {
if (currentTest < tests.length)
runTest.apply(null, tests[currentTest++]);
else if (window.layoutTestController)
layoutTestController.notifyDone();
}

nextTest();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<html>
<body>
<pre id='console'></pre>
<script type="text/javascript">
function log(message)
{
document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
}

if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}

window.addEventListener("message", function(evt) {
if (evt.data == "done") {
layoutTestController.notifyDone();
return;
}

log(evt.data);
}, false);
</script>
<iframe src='data:text/html,
<script>
(function() {
var xhr = new XMLHttpRequest;

try {
xhr.open("GET", "http://localhost:8000/xmlhttprequest/resources/access-control-basic-allow-access-control-origin-header.cgi", false);
} catch(e) {
parent.postMessage("FAIL: Exception thrown. Cross-domain access is not allowed in open. [" + e.message + "].", "*");
return;
}

try {
xhr.send();
} catch(e) {
parent.postMessage("FAIL: Exception thrown. Cross-domain access is not allowed in send. [" + e.message + "].", "*");
return;
}

parent.postMessage(xhr.responseText, "*");
})();
parent.postMessage("done", "*");
</script>'>
</body>
</html>
34 changes: 34 additions & 0 deletions cors/access-control-basic-allow-access-control-origin-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<html>
<body>
<pre id='console'></pre>
<script type="text/javascript">
function log(message)
{
document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
}

if (window.layoutTestController)
layoutTestController.dumpAsText();

(function() {
var xhr = new XMLHttpRequest;

try {
xhr.open("GET", "http://localhost:8000/xmlhttprequest/resources/access-control-basic-allow-access-control-origin-header.cgi", false);
} catch(e) {
log("FAIL: Exception thrown. Cross-domain access is not allowed in 'open'. [" + e.message + "].");
return;
}

try {
xhr.send();
} catch(e) {
log("FAIL: Exception thrown. Cross-domain access is not allowed in 'send'. [" + e.message + "].");
return;
}

log(xhr.responseText);
})();
</script>
</body>
</html>
40 changes: 40 additions & 0 deletions cors/access-control-basic-allow-async.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<html>
<body>
<pre id='console'></pre>
<script type="text/javascript">
function log(message)
{
document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
}

if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}

function processStateChange()
{
if (xhr.readyState == xhr.DONE) {
log(xhr.responseText);
if (window.layoutTestController)
layoutTestController.notifyDone();
}
}

function errorHandler()
{
log("FAIL: Network error.");
if (window.layoutTestController)
layoutTestController.notifyDone();
}

var xhr = new XMLHttpRequest;
xhr.onreadystatechange = processStateChange;
xhr.onerror = errorHandler;

xhr.open("GET", "http://localhost:8000/xmlhttprequest/resources/access-control-basic-allow.cgi", true);
xhr.send();

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<html>
<body>
<pre id='console'></pre>
<script type="text/javascript">
function log(message)
{
document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
}

if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}

function errorHandler(event)
{
log("FAIL: Network error. ");
if (window.layoutTestController)
layoutTestController.notifyDone();
}

var filename = "filename=preflightCacheInvalidationByHeader.txt";

var xhr = new XMLHttpRequest;
xhr.onerror = errorHandler;

start = function()
{
// Temp file removed. We can start the test now.
if (xhr.readyState == xhr.DONE) {
firstRequest();
}
}

xhr.open("GET", "/resources/reset-temp-file.php?" + filename, true);
xhr.onreadystatechange = start;
xhr.send();

function firstRequest()
{
xhr.onreadystatechange = function()
{
if (xhr.readyState == xhr.DONE) {
log(xhr.responseText);
log("PASS: First request complete");
secondRequest();
}
}

xhr.open("PUT", "http://localhost:8000/xmlhttprequest/resources/access-control-basic-preflight-cache-invalidation.php?" + filename, true);
xhr.send();
}

function secondRequest()
{
xhr.onreadystatechange = function()
{
if (xhr.readyState == xhr.DONE) {
log(xhr.responseText);
log("PASS: Second request complete");
if (window.layoutTestController)
layoutTestController.notifyDone();
}
}

// Send a header not included in the inital cache.
xhr.open("PUT", "http://localhost:8000/xmlhttprequest/resources/access-control-basic-preflight-cache-invalidation.php?" + filename, true);
xhr.setRequestHeader("x-webkit-test", "headerValue");
xhr.send();
}

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<html>
<body>
<pre id='console'></pre>
<script type="text/javascript">
function log(message)
{
document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
}

if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}

function errorHandler(event)
{
log("FAIL: Network error. ");
if (window.layoutTestController)
layoutTestController.notifyDone();
}

var filename = "filename=preflightCacheInvalidationByMethod.txt";

var xhr = new XMLHttpRequest;
xhr.onerror = errorHandler;

start = function()
{
// Temp file removed. We can start the test now.
if (xhr.readyState == xhr.DONE) {
firstRequest();
}
}

xhr.open("GET", "/resources/reset-temp-file.php?" + filename, true);
xhr.onreadystatechange = start;
xhr.send();

function firstRequest()
{
xhr.onreadystatechange = function()
{
if (xhr.readyState == xhr.DONE) {
log(xhr.responseText);
log("PASS: First request complete");
secondRequest();
}
}

xhr.open("PUT", "http://localhost:8000/xmlhttprequest/resources/access-control-basic-preflight-cache-invalidation.php?" + filename, true);
xhr.send();
}

function secondRequest()
{
xhr.onreadystatechange = function()
{
if (xhr.readyState == xhr.DONE) {
log(xhr.responseText);
log("PASS: Second request complete");
if (window.layoutTestController)
layoutTestController.notifyDone();
}
}

// Send a method not included in the initial cache.
xhr.open("XMETHOD", "http://localhost:8000/xmlhttprequest/resources/access-control-basic-preflight-cache-invalidation.php?" + filename, true);
xhr.send();
}

</script>
</body>
</html>
Loading