Bug 1132395 - URL.createObjectURL must be able to work with workers without parents, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 12 Feb 2015 14:20:08 +0100
changeset 255941 6aad679bbbc0f40da98a825b4353e6cc3730b906
parent 255940 9d71819980229382900a404d3a7f6ad050288b60
child 255942 c85e10ce7b0c4c4ba7e9568c7e8b3f14ca60add6
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1132395
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1132395 - URL.createObjectURL must be able to work with workers without parents, r=smaug
dom/workers/URL.cpp
dom/workers/test/bug1132395_sharedWorker.js
dom/workers/test/mochitest.ini
dom/workers/test/test_bug1132395.html
--- a/dom/workers/URL.cpp
+++ b/dom/workers/URL.cpp
@@ -130,17 +130,18 @@ public:
       doc = window->GetExtantDoc();
       if (!doc) {
         SetDOMStringToNull(mURL);
         return false;
       }
 
       principal = doc->NodePrincipal();
     } else {
-      MOZ_ASSERT_IF(!mWorkerPrivate->GetParent(), mWorkerPrivate->IsChromeWorker());
+      // We use the worker Principal in case this is a SharedWorker, a
+      // ChromeWorker or a ServiceWorker.
       principal = mWorkerPrivate->GetPrincipal();
     }
 
     nsCString url;
     nsresult rv = nsHostObjectProtocolHandler::AddDataEntry(
         NS_LITERAL_CSTRING(BLOBURI_SCHEME),
         mBlobImpl, principal, url);
 
@@ -186,17 +187,18 @@ public:
     if (window) {
       doc = window->GetExtantDoc();
       if (!doc) {
         return false;
       }
 
       principal = doc->NodePrincipal();
     } else {
-      MOZ_ASSERT_IF(!mWorkerPrivate->GetParent(), mWorkerPrivate->IsChromeWorker());
+      // We use the worker Principal in case this is a SharedWorker, a
+      // ChromeWorker or a ServiceWorker.
       principal = mWorkerPrivate->GetPrincipal();
     }
 
     NS_ConvertUTF16toUTF8 url(mURL);
 
     nsIPrincipal* urlPrincipal =
       nsHostObjectProtocolHandler::GetDataEntryPrincipal(url);
 
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/bug1132395_sharedWorker.js
@@ -0,0 +1,5 @@
+onconnect = function(evt) {
+  var blob = new Blob(['123'], { type: 'text/plain' });
+  var url = URL.createObjectURL(blob);
+  evt.ports[0].postMessage('alive \\o/');
+}
--- a/dom/workers/test/mochitest.ini
+++ b/dom/workers/test/mochitest.ini
@@ -93,16 +93,17 @@ support-files =
   test_worker_performance_now.js
   worker_driver.js
   worker_wrapper.js
   bug1060621_worker.js
   bug1062920_worker.js
   webSocket_sharedWorker.js
   bug1104064_worker.js
   worker_consoleAndBlobs.js
+  bug1132395_sharedWorker.js
 
 [test_404.html]
 [test_atob.html]
 [test_blobConstructor.html]
 [test_blobWorkers.html]
 [test_bug1002702.html]
 [test_bug949946.html]
 [test_bug1010784.html]
@@ -194,8 +195,9 @@ skip-if = buildapp == 'b2g' || toolkit =
 skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s #bug 982828
 [test_bug1062920.html]
 [test_bug978260.html]
 [test_webSocket_sharedWorker.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s #bug 982828
 [test_websocket_pref.html]
 [test_bug1104064.html]
 [test_consoleAndBlobs.html]
+[test_bug1132395.html]
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/test_bug1132395.html
@@ -0,0 +1,29 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for 1132395</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<script class="testbody" type="text/javascript">
+
+SpecialPowers.pushPrefEnv({ set: [["dom.workers.sharedWorkers.enabled", true]] }, function() {
+  var sw = new SharedWorker('bug1132395_sharedWorker.js');
+  sw.port.onmessage = function(event) {
+     ok(true, "We didn't crash.");
+    SimpleTest.finish();
+  }
+});
+
+SimpleTest.waitForExplicitFinish();
+
+</script>
+</pre>
+</body>
+</html>