Skip to content

Commit

Permalink
Update some tests to work better
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraham committed Oct 15, 2013
1 parent 77e8e86 commit bf4843c
Show file tree
Hide file tree
Showing 83 changed files with 156 additions and 145 deletions.
14 changes: 7 additions & 7 deletions XMLHttpRequest/resources/conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ def main(request, response):
elif date:
response.headers.set("Last-Modified", date)

if ((match is not None and match == tag) or
(modified is not None and modified == date)):
response.status = (304, "SUPERCOOL")
return ""
else:
response.headers.set("Content-Type", "text/plain")
return "MAYBE NOT"
if ((match is not None and match == tag) or
(modified is not None and modified == date)):
response.status = (304, "SUPERCOOL")
return ""
else:
response.headers.set("Content-Type", "text/plain")
return "MAYBE NOT"
2 changes: 1 addition & 1 deletion XMLHttpRequest/resources/content.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def main(request, response):
headers = [("Content-type", "text/plain"),
("X-Request-Method", request.method),
("X-Request-Query", request.url_parts.query if request.urlparts.query else "NO"),
("X-Request-Query", request.url_parts.query if request.url_parts.query else "NO"),
("X-Request-Content-Length", request.headers.get("Content-Length", "NO")),
("X-Request-Content-Type", request.headers.get("Content-Type", "NO"))]

Expand Down
23 changes: 13 additions & 10 deletions XMLHttpRequest/resources/corsenabled.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import time

def main(request, response):
headers = [('Access-Control-Allow-Origin", "*'),
('Access-Control-Allow-Credentials", "true'),
('Access-Control-Allow-Methods", "GET, POST, PUT, FOO'),
('Access-Control-Allow-Headers", "x-test, x-foo'),
('Access-Control-Expose-Headers", "x-request-method, x-request-content-type, x-request-query, x-request-content-length')]
headers = [("Access-Control-Allow-Origin", "*"),
("Access-Control-Allow-Credentials", "true"),
("Access-Control-Allow-Methods", "GET, POST, PUT, FOO"),
("Access-Control-Allow-Headers", "x-test, x-foo"),
("Access-Control-Expose-Headers", "x-request-method, x-request-content-type, x-request-query, x-request-content-length")]

if 'delay' in request.GET:
time.sleep(int(request.GET['delay']))
if "delay" in request.GET:
delay = int(request.GET.first("delay"))
time.sleep(delay)

headers.append(("X-Request-Method", request.method))
headers.append(("X-Request-Query" . request.url_parts.query if request.urlparts.query else "NO"))
headers.append(("X-Request-Content-Length", request.headers.get("Content-Length", "NO"))
header.append(("X-Request-Content-Type", request.headers.get("Content-Type" "NO"))
headers.append(("X-Request-Query", request.url_parts.query if request.url_parts.query else "NO"))
headers.append(("X-Request-Content-Length", request.headers.get("Content-Length", "NO")))
headers.append(("X-Request-Content-Type", request.headers.get("Content-Type" "NO")))

return headers, "Test"
2 changes: 1 addition & 1 deletion XMLHttpRequest/resources/form.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def main(request, response):
echo "id:%s;value:%s;"(request.GET.first("id"), request.GET.first("value"))
return "id:%s;value:%s;" % (request.GET.first("id"), request.GET.first("value"))
8 changes: 4 additions & 4 deletions XMLHttpRequest/timeout-cors-async.htm
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
<script>
var test = async_test(document.title)
var client = new XMLHttpRequest()
client.open("GET", "http://www2."+location.hostname+(location.pathname.replace(/[^\/]+$/, '')+'resources/corsenabled.py')+"?delay=2&code=200")
client.open("GET", "http://www2." + location.hostname + (location.port ? ":" + location.port : "") +(location.pathname.replace(/[^\/]+$/, '')+'resources/corsenabled.py')+"?delay=2&code=200")
client.timeout = 100
client.addEventListener('timeout', function (e) {
test.step(function() {
assert_equals(e.type, 'timeout')
assert_equals(client.status, 4)
assert_equals(client.status, 0)
test.done()
})
})
})
client.addEventListener('load', function (e) {
test.step(function() {
assert_unreached('load event should not fire')
test.done()
})
})
})

client.send(null)
Expand Down
5 changes: 3 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{"host": "web-platform.test",
"ports":{"http":["auto", "auto"],
"ports":{"http":[8000, "auto"],
"https":["auto"],
"ws":["auto"]},
"external_domain":"w3c-test.org"}
"external_domain":"w3c-test.org",
"log_level":"debug"}
2 changes: 0 additions & 2 deletions cors/resources/cors-makeheader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json

def main(request, response):
print request.GET
origin = request.GET.first("origin", request.headers.get('origin'))

if "check" in request.GET:
Expand Down Expand Up @@ -45,7 +44,6 @@ def main(request, response):

if code >= 300 and code < 400:
response.headers.set("Location", request.GET.first('location'))
print response.headers

headers = {}
for name, values in request.headers.iteritems():
Expand Down
18 changes: 9 additions & 9 deletions eventsource/resources/cors-cookie.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
def main(request, response):
last_event_id = reqeuest.headers.get("last_event_id", "")
ident = request.GET('ident', "test")
last_event_id = request.headers.get("Last-Event-Id", "")
ident = request.GET.first('ident', "test")
cookie = "COOKIE" if ident in request.cookies else "NO_COOKIE"
origin = request.GET.first('origin', request.headers("origin"))
origin = request.GET.first('origin', request.headers["origin"])
credentials = request.GET.first('credentials', 'true')

headers = []
Expand All @@ -11,18 +11,18 @@ def main(request, response):
headers.append(("Access-Control-Allow-Origin", origin));

if credentials != 'none':
headers.append("Access-Control-Allow-Credentials", credentials);
headers.append(("Access-Control-Allow-Credentials", credentials));

if last_event_id == '':
headers.append(("Content-Type", "text/event-stream"))
response.set_cookie(ident, "COOKIE")
data = "id: 1\nretry: 200\ndata: first $cookie\n\n"
data = "id: 1\nretry: 200\ndata: first %s\n\n" % cookie
elif last_event_id == '1':
headers.append(("Content-Type", "text/event-stream"))
response.set_cookie(ident, "COOKIE" expires="Fri, 27 Jul 2001 02:47:11 UTC")
data = "id: 2\ndata: second $cookie\n\n"
response.set_cookie(ident, "COOKIE", expires="Fri, 27 Jul 2001 02:47:11 UTC")
data = "id: 2\ndata: second %s\n\n" % cookie
else:
headers.append(("Content-Type", "stop"))
echo "data: " + last_event_id + cookie + "\n\n";
data = "data: " + last_event_id + cookie + "\n\n";

return headers, body
return headers, data
11 changes: 6 additions & 5 deletions eventsource/resources/cors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from wptserve import pipes

def run_other(request, response, path):
#This is a terrible hack
Expand All @@ -8,10 +9,6 @@ def run_other(request, response, path):
return rv

def main(request, response):

print request.request_line
print request._raw_headers

origin = request.GET.first("origin", request.headers["origin"])
credentials = request.GET.first("credentials", "true")

Expand All @@ -24,7 +21,11 @@ def main(request, response):
"redirect",
"cache-control"]:
if handler == "cache-control":
return open("cache-control.event_source").read()
response.headers.set("Content-Type", "text/event-stream")
rv = open(os.path.join(request.doc_root, "eventsource", "resources", "cache-control.event_source")).read()
response.content = rv
pipes.sub(request, response)
return
elif handler == "redirect":
return run_other(request, response, os.path.join(request.doc_root, "common", "redirect.py"))
else:
Expand Down
2 changes: 0 additions & 2 deletions eventsource/resources/status-reconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ def main(request, response):

cookie_name = "request" + name

print request.cookies

if request.cookies.first(cookie_name, "") == status_code:
status = 200
response.delete_cookie(cookie_name)
Expand Down
2 changes: 1 addition & 1 deletion html/browsers/history/the-history-interface/008.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
assert_equals(location.href,beforehref.replace(/^(\w*:\/\/[^\/]*\/)[\w\W]*$/,'$1testing_ignore_me_404_2'));
}, 'history.replaceState URL resolving should be done relative to the document, not the script');
*/
var scriptlocation = 'http://www.w3c-test.org/' + location.pathname.split("/").slice(0,-1).join("/") + "/008.js";
var scriptlocation = 'http://www.' + location.host + location.pathname.split("/").slice(0,-1).join("/") + "/008.js";

if( location.protocol == 'file:' ) {
document.getElementsByTagName('p')[0].innerHTML = 'ERROR: This test cannot be run from file: (URL resolving will not work). It must be loaded over HTTP.';
Expand Down
4 changes: 2 additions & 2 deletions navigation-timing/test_navigation_type_backforward.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
Expand Down Expand Up @@ -36,7 +36,7 @@
{
case 1:
{
navigation_frame.location.href = '/web-platform-tests/master/navigation-timing/resources/blank_page_green_with_onunload.html';
navigation_frame.location.href = '/navigation-timing/resources/blank_page_green_with_onunload.html';
step++;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions navigation-timing/test_timing_attributes_order.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
Expand Down Expand Up @@ -30,7 +30,7 @@
{
case 1:
{
navigation_frame.location.href = '/web-platform-tests/master/navigation-timing/resources/blank_page_green.html';
navigation_frame.location.href = '/navigation-timing/resources/blank_page_green.html';
step++;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion navigation-timing/test_timing_server_redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ <h1>Description</h1>

<div id="log"></div>
<br />
<iframe id="frameContext" onload="onload_test();" src="/common/redirect.py?location=/web-platform-tests/master/navigation-timing/resources/blank_page_green.html" style="width: 250px; height: 250px;"></iframe>
<iframe id="frameContext" onload="onload_test();" src="/common/redirect.py?location=/navigation-timing/resources/blank_page_green.html" style="width: 250px; height: 250px;"></iframe>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'error', requests:[]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'error', requests:[{cors:origin, cookie:'no'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:origin, cookie:'no'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'error', requests:[{cors:origin, cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:origin, cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}, {cors:'no', cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}, {cors:'no', cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}, {cors:'no', cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}, {cors:'no', cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}, {cors:'no', cookie:'yes'}]};
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'load', requests:[{cors:'no', cookie:'yes'}, {cors:'no', cookie:'yes'}]};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src=/common/utils.js></script>
<script src=support/common.js></script>
<script src=support/common.js?pipe=sub></script>
<script>
var expected = {event:'error', requests:[{cors:origin, cookie:'no'}]}; // redirect not followed
</script>
Loading

0 comments on commit bf4843c

Please sign in to comment.