Bug 1288768 - Better error reporting for network errors in workers - WPT, r=bz
☠☠ backed out by 7675a6d4b824 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Sat, 28 Jan 2017 15:40:08 +0100
changeset 378203 3361d527f683724d3d0f40a448cbef83cd2c7a87
parent 378202 d8b8219c20d6af7f37a7f69d5b83d9f1e644323a
child 378204 7675a6d4b824f29f4cb1fd68c1b7d712e2d6b8bc
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1288768
milestone54.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 1288768 - Better error reporting for network errors in workers - WPT, r=bz
dom/security/test/csp/file_child-src_worker-redirect.html
dom/security/test/general/test_block_script_wrong_mime.html
dom/workers/test/test_404.html
dom/workers/test/test_bug1036484.html
dom/workers/test/test_loadError.html
testing/web-platform/meta/content-security-policy/worker-src/dedicated-fallback.sub.html.ini
testing/web-platform/meta/content-security-policy/worker-src/shared-fallback.sub.html.ini
testing/web-platform/tests/workers/Worker_cross_origin_security_err.htm
testing/web-platform/tests/workers/constructors/SharedWorker/same-origin.html
testing/web-platform/tests/workers/constructors/Worker/same-origin.html
--- a/dom/security/test/csp/file_child-src_worker-redirect.html
+++ b/dom/security/test/csp/file_child-src_worker-redirect.html
@@ -18,21 +18,18 @@
     try {
       worker = new Worker('file_redirect_worker.sjs?path='
           + escape("/tests/dom/security/test/csp/file_child-src_worker.js")
           + "&redir=" + redir
           + "&page_id=" + page_id
           );
 
       worker.onerror = function(error) {
-        var msg = error.message;
-        if (msg.match(/^NetworkError/) || msg.match(/Failed to load worker script/)) {
-          // this means CSP blocked it
-          msg = "blocked";
-        }
+        // this means CSP blocked it
+        var msg = !("message" in error) ? "blocked" : e.message;
         window.parent.postMessage({id:page_id, message:msg}, 'http://mochi.test:8888');
         error.preventDefault();
       };
 
       worker.onmessage = function(ev) {
         window.parent.postMessage({id:page_id, message:"allowed"}, 'http://mochi.test:8888');
 
       };
--- a/dom/security/test/general/test_block_script_wrong_mime.html
+++ b/dom/security/test/general/test_block_script_wrong_mime.html
@@ -48,19 +48,16 @@ function testWorker([mime, shouldLoad]) 
     let worker = new Worker("file_block_script_wrong_mime_server.sjs?type=worker&mime="+mime);
     worker.onmessage = (event) => {
       ok(shouldLoad, `worker with mime '${mime}' should load`)
       is(event.data, "worker-loaded", "worker should send correct message");
       resolve();
     };
     worker.onerror = (error) => {
       ok(!shouldLoad, `worker with wrong mime '${mime}' should be blocked`);
-      let msg = error.message;
-      ok(msg.match(/^NetworkError/) || msg.match(/Failed to load worker script/),
-         "should gets correct error message");
       error.preventDefault();
       resolve();
     }
     worker.postMessage("dummy");
   });
 }
 
 // new Worker() with importScripts()
@@ -69,19 +66,16 @@ function testWorkerImportScripts([mime, 
     let worker = new Worker("file_block_script_wrong_mime_server.sjs?type=worker-import&mime="+mime);
     worker.onmessage = (event) => {
       ok(shouldLoad, `worker/importScripts with mime '${mime}' should load`)
       is(event.data, "worker-loaded", "worker should send correct message");
       resolve();
     };
     worker.onerror = (error) => {
       ok(!shouldLoad, `worker/importScripts with wrong mime '${mime}' should be blocked`);
-      let msg = error.message;
-      ok(msg.match(/^NetworkError/) || msg.match(/Failed to load worker script/),
-         "should gets correct error message");
       error.preventDefault();
       resolve();
     }
     worker.postMessage("dummy");
   });
 }
 
 SimpleTest.waitForExplicitFinish();
--- a/dom/workers/test/test_404.html
+++ b/dom/workers/test/test_404.html
@@ -20,22 +20,20 @@ Tests of DOM Worker Threads
 
   worker.onmessage = function(event) {
     ok(false, "Shouldn't ever get a message!");
     SimpleTest.finish();
   }
 
   worker.onerror = function(event) {
     is(event.target, worker);
-    is(event.message, 'NetworkError: Failed to load worker script at "nonexistent_worker.js"');
     event.preventDefault();
     SimpleTest.finish();
   };
 
   worker.postMessage("dummy");
 
   SimpleTest.waitForExplicitFinish();
 
 </script>
 </pre>
 </body>
 </html>
-
--- a/dom/workers/test/test_bug1036484.html
+++ b/dom/workers/test/test_bug1036484.html
@@ -20,17 +20,16 @@ function test(script) {
   var worker = new Worker(script);
 
   worker.onmessage = function(event) {
     ok(false, "Shouldn't ever get a message!");
   }
 
   worker.onerror = function(event) {
     is(event.target, worker);
-    ok(event.message.startsWith("NetworkError: Failed to load worker script"))
     event.preventDefault();
     runTests();
   };
 
   worker.postMessage("dummy");
 }
 
 var tests = [ '404_server.sjs', '404_server.sjs?js' ];
--- a/dom/workers/test/test_loadError.html
+++ b/dom/workers/test/test_loadError.html
@@ -8,59 +8,55 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 "use strict";
 
-var loadErrorMessage = 'SecurityError: Failed to load worker script at "about:blank"';
-
 function nextTest() {
   (function(){
     function workerfunc() {
       var subworker = new Worker("about:blank");
       subworker.onerror = function(e) {
         e.preventDefault();
-        postMessage(e.message);
+        postMessage("ERROR");
       }
     }
     var b = new Blob([workerfunc+'workerfunc();']);
     var u = URL.createObjectURL(b);
     function callworker(i) {
       try {
         var w = new Worker(u);
         URL.revokeObjectURL(u);
         is(i, 0, 'worker creation succeeded');
       } catch (e) {
         is(i, 1, 'worker creation failed');
         SimpleTest.finish();
         return;
       }
       w.onmessage = function(e) {
-        is(e.data, loadErrorMessage,
+        is(e.data, "ERROR",
            "Should catch the error when loading inner script");
         if (++i < 2) callworker(i);
         else SimpleTest.finish();
       };
       w.onerrror = function(e) {
         ok(false, "Should not get any errors from this worker");
       }
     }
     callworker(0);
   })();
 }
 
 try {
   var worker = new Worker("about:blank");
   worker.onerror = function(e) {
     e.preventDefault();
-    is(e.message, loadErrorMessage,
-       "Should get the right error from the toplevel script");
     nextTest();
   }
 
   worker.onmessage = function(event) {
     ok(false, "Shouldn't get a message!");
     SimpleTest.finish();
   }
 } catch (e) {
--- a/testing/web-platform/meta/content-security-policy/worker-src/dedicated-fallback.sub.html.ini
+++ b/testing/web-platform/meta/content-security-policy/worker-src/dedicated-fallback.sub.html.ini
@@ -1,9 +1,8 @@
 [dedicated-fallback.sub.html]
   type: testharness
-  expected: ERROR
   [Same-origin dedicated worker allowed by host-source expression.]
     expected: FAIL
 
   [blob: dedicated worker allowed by 'blob:'.]
     expected: FAIL
 
--- a/testing/web-platform/meta/content-security-policy/worker-src/shared-fallback.sub.html.ini
+++ b/testing/web-platform/meta/content-security-policy/worker-src/shared-fallback.sub.html.ini
@@ -1,9 +1,8 @@
 [shared-fallback.sub.html]
   type: testharness
-  expected: ERROR
   [Same-origin dedicated worker allowed by 'self'.]
     expected: FAIL
 
   [blob: dedicated worker allowed by 'blob:'.]
     expected: FAIL
 
--- a/testing/web-platform/tests/workers/Worker_cross_origin_security_err.htm
+++ b/testing/web-platform/tests/workers/Worker_cross_origin_security_err.htm
@@ -3,15 +3,15 @@
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <div id=log></div>
 <script>
 async_test(function(t) {
   try {
     var w = new Worker("ftp://example.org/support/WorkerBasic.js");
     w.onerror = t.step_func_done(function(e) {
-      assert_true(e instanceof ErrorEvent);
+      assert_true(e instanceof Event);
     });
   } catch (e) {
     t.step_func_done(function(e) { assert_true(true); });
   }
 });
 </script>
--- a/testing/web-platform/tests/workers/constructors/SharedWorker/same-origin.html
+++ b/testing/web-platform/tests/workers/constructors/SharedWorker/same-origin.html
@@ -11,17 +11,17 @@
 // Needed to prevent a race condition if a worker throws an exception that may or may
 // not propogate to the window before the tests finish
 setup({allow_uncaught_exception: true});
 
 function testSharedWorkerHelper(t, script) {
   try {
     var worker = new SharedWorker(script, '');
     worker.onerror = t.step_func_done(function(e) {
-      assert_true(e instanceof ErrorEvent);
+      assert_true(e instanceof Event);
     });
   } catch (e) {
     t.step_func_done(function(e) { assert_true(true); });
   }
 }
 
 test(function() {
   assert_throws("SecurityError", function() { new SharedWorker('unsupported:', ''); });
--- a/testing/web-platform/tests/workers/constructors/Worker/same-origin.html
+++ b/testing/web-platform/tests/workers/constructors/Worker/same-origin.html
@@ -9,17 +9,17 @@
 // Needed to prevent a race condition if a worker throws an exception that may or may
 // not propogate to the window before the tests finish
 setup({allow_uncaught_exception: true});
 
 function testSharedWorkerHelper(t, script) {
   try {
     var worker = new SharedWorker(script, '');
     worker.onerror = t.step_func_done(function(e) {
-      assert_true(e instanceof ErrorEvent);
+      assert_true(e instanceof Event);
     });
   } catch (e) {
     t.step_func_done(function(e) { assert_true(true); });
   }
 }
 
 test(function() {
   assert_throws("SecurityError", function() { new Worker('unsupported:'); });