Bug 1257861 - Test that we send cookies from XHRs in web workers when 3rd party cookies are disabled. r=sicking
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/file_getcookie.sjs
@@ -0,0 +1,15 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+function handleRequest(request, response) {
+ try {
+ var cookie = request.getHeader("Cookie");
+ } catch (e) {
+ cookie = "EMPTY_COOKIE";
+ }
+
+ // avoid confusing cache behaviors.
+ response.setHeader("Cache-Control", "no-cache", false);
+ response.setHeader("Content-type", "text/plain", false);
+ response.setStatusLine(request.httpVersion, "200", "OK");
+ response.write(cookie);
+}
--- a/dom/workers/test/mochitest.ini
+++ b/dom/workers/test/mochitest.ini
@@ -20,16 +20,17 @@ support-files =
csp_worker.js
404_server.sjs
errorPropagation_iframe.html
errorPropagation_worker.js
errorwarning_worker.js
eventDispatch_worker.js
fibonacci_worker.js
file_bug1010784_worker.js
+ file_getcookie.sjs
foreign.js
importForeignScripts_worker.js
importScripts_mixedcontent.html
importScripts_worker.js
importScripts_worker_imported1.js
importScripts_worker_imported2.js
importScripts_worker_imported3.js
importScripts_worker_imported4.js
@@ -237,16 +238,17 @@ skip-if = buildapp == 'b2g' # no https o
skip-if = buildapp == 'b2g' || toolkit == 'android' #bug 982828
[test_webSocket_sharedWorker.html]
skip-if = buildapp == 'b2g' || toolkit == 'android' #bug 982828
[test_worker_interfaces.html]
[test_worker_performance_now.html]
[test_workersDisabled.html]
[test_xhr.html]
[test_xhr2.html]
+[test_xhr_3rdparty.html]
[test_xhr_headers.html]
[test_xhr_implicit_cancel.html]
[test_xhr_parameters.html]
skip-if = buildapp == 'b2g'
[test_xhr_responseURL.html]
[test_xhr_system.html]
[test_xhr_cors_redirect.html]
skip-if = buildapp == 'b2g'
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/test_xhr_3rdparty.html
@@ -0,0 +1,74 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<!--
+Tests of DOM Worker Threads XHR(Bug 450452 )
+-->
+<head>
+ <title>Test for DOM Worker Threads XHR (Bug 450452 )</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=450452">DOM Worker Threads XHR (Bug 450452)</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+ var worker = new Worker("xhr_worker.js");
+
+ var gotUploadLoad = false, gotLoadend = false;
+
+ worker.onmessage = function(event) {
+ is(event.target, worker);
+ var args = event.data;
+ switch (args.type) {
+ case "progress": {
+ ok(parseInt(args.current) <= parseInt(args.total));
+ } break;
+ case "error": {
+ ok(false, "XHR error: " + args.error);
+ } break;
+ case "upload.load": {
+ gotUploadLoad = true;
+ } break;
+ case "load": {
+ ok(gotUploadLoad, "Should have gotten upload load event");
+ gotLoadend = true;
+ todo_is(args.data, "a=cookie_is_set", "correct data");
+ document.getElementById("content").textContent = args.data;
+ } break;
+ case "loadend": {
+ ok(gotLoadend, "Should have gotten load.");
+ SimpleTest.finish();
+ break;
+ }
+ default: {
+ ok(false, "Unexpected message");
+ SimpleTest.finish();
+ }
+ }
+ };
+
+ worker.onerror = function(event) {
+ is(event.target, worker);
+ ok(false, "Worker had an error:" + event.message);
+ SimpleTest.finish();
+ }
+
+ document.cookie = "a=cookie_is_set";
+ SpecialPowers.pushPrefEnv({ set: [[ "network.cookie.cookieBehavior", 1 ]] },
+ () => worker.postMessage("file_getcookie.sjs"));
+
+ SimpleTest.waitForExplicitFinish();
+
+</script>
+</pre>
+</body>
+</html>