mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1218474 - Improve the referrer checks in worker mochitests, r=bkelly
This commit is contained in:
parent
1bcd4d95d4
commit
61abf8e5dc
@ -112,6 +112,7 @@ support-files =
|
||||
performance_observer.html
|
||||
sharedWorker_ports.js
|
||||
sharedWorker_lifetime.js
|
||||
worker_referrer.js
|
||||
|
||||
[test_404.html]
|
||||
[test_atob.html]
|
||||
|
@ -2,10 +2,14 @@ function handleRequest(request, response)
|
||||
{
|
||||
if (request.queryString == "result") {
|
||||
response.write(getState("referer"));
|
||||
} else {
|
||||
setState("referer", "INVALID");
|
||||
} else if (request.queryString == "worker") {
|
||||
response.setHeader("Content-Type", "text/javascript", false);
|
||||
response.write("onmessage = function() { postMessage(42); }");
|
||||
setState("referer", request.getHeader("referer"));
|
||||
} else if (request.queryString == 'import') {
|
||||
setState("referer", request.getHeader("referer"));
|
||||
response.write("'hello world'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,19 +15,42 @@
|
||||
<pre id="test"></pre>
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
var worker = new Worker("referrer.sjs");
|
||||
worker.onmessage = function() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'referrer.sjs?result', true);
|
||||
xhr.onload = function() {
|
||||
is(xhr.responseText, location.href, "The referrer has been sent.");
|
||||
SimpleTest.finish();
|
||||
function test_mainScript() {
|
||||
var worker = new Worker("referrer.sjs?worker");
|
||||
worker.onmessage = function() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'referrer.sjs?result', true);
|
||||
xhr.onload = function() {
|
||||
is(xhr.responseText, location.href, "The referrer has been sent.");
|
||||
next();
|
||||
}
|
||||
xhr.send();
|
||||
}
|
||||
xhr.send();
|
||||
worker.postMessage(42);
|
||||
}
|
||||
|
||||
function test_importScript() {
|
||||
var worker = new Worker("worker_referrer.js");
|
||||
worker.onmessage = function(e) {
|
||||
is(e.data, location.href.replace("test_referrer.html", "worker_referrer.js"), "The referrer has been sent.");
|
||||
next();
|
||||
}
|
||||
worker.postMessage(42);
|
||||
}
|
||||
|
||||
var tests = [ test_mainScript, test_importScript ];
|
||||
function next() {
|
||||
if (!tests.length) {
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
var test = tests.shift();
|
||||
test();
|
||||
}
|
||||
worker.postMessage(42);
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
next();
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
|
9
dom/workers/test/worker_referrer.js
Normal file
9
dom/workers/test/worker_referrer.js
Normal file
@ -0,0 +1,9 @@
|
||||
onmessage = function() {
|
||||
importScripts(['referrer.sjs?import']);
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'referrer.sjs?result', true);
|
||||
xhr.onload = function() {
|
||||
postMessage(xhr.responseText);
|
||||
}
|
||||
xhr.send();
|
||||
}
|
Loading…
Reference in New Issue
Block a user