Bug 1257861 - Test that we send cookies from XHRs in web workers when 3rd party cookies are disabled. r=sicking
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 24 Mar 2016 17:17:01 -0700
changeset 290760 a0c84b4e0da24309d3a2a764202ca24e66f2d9ee
parent 290759 67e4eb38e3b818ab71bcfa170cab353b05c39a98
child 290761 e9954f2bede1212e7e0090e0b98acdb460c599f4
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs1257861
milestone48.0a1
Bug 1257861 - Test that we send cookies from XHRs in web workers when 3rd party cookies are disabled. r=sicking
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
@@ -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>