Bug 1257861 - Test that we send cookies from XHRs in web workers when 3rd party cookies are disabled. r=sicking a=lizzard
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 06 Apr 2016 16:28:49 -0700
changeset 325724 9e99383b97c614ba0927ee7d76e9e837b7ffba1f
parent 325723 d3d6344cc744aee65be009f5c23287ae9e1ab1c8
child 325725 8b4d6477fd3e18d3995878f0d9dff41efa264cd4
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking, lizzard
bugs1257861
milestone47.0a2
Bug 1257861 - Test that we send cookies from XHRs in web workers when 3rd party cookies are disabled. r=sicking a=lizzard MozReview-Commit-ID: JdvVaPEeAbC
dom/workers/test/file_getcookie.sjs
dom/workers/test/mochitest.ini
dom/workers/test/test_xhr_3rdparty.html
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
@@ -222,16 +223,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]
 skip-if = buildapp == 'b2g'
 [test_xhr_timeout.html]
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>