Bug 1455367 [wpt PR 10536] - Update fetch and service worker tests to allow same-origin redirects …, a=testonly
authorBen Kelly <bkelly@mozilla.com>
Sun, 29 Apr 2018 19:20:08 +0000
changeset 469819 372d779ec72010064f004df03914022d714b99bf
parent 469818 da9fc8721d47fe25c26371517829e6d8082cadb0
child 469820 700b6d955fb9f610edcca09e714febeacad5697c
push id9179
push userarchaeopteryx@coole-files.de
push dateThu, 03 May 2018 15:28:18 +0000
treeherdermozilla-beta@e6f9ade8bca7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1455367, 10536
milestone61.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 1455367 [wpt PR 10536] - Update fetch and service worker tests to allow same-origin redirects …, a=testonly Automatic update from web-platform-testsUpdate fetch and service worker tests to allow same-origin no-cors redirects #9039 wasn't quite aligned with the specification. -- wpt-commits: 50ba192e997e2bc5ffd9c6770ebf8d153eee1a46 wpt-pr: 10536
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/fetch/api/redirect/redirect-mode.js
testing/web-platform/tests/fetch/api/resources/cors-top.txt
testing/web-platform/tests/fetch/api/resources/cors-top.txt.headers
testing/web-platform/tests/service-workers/service-worker/fetch-event-redirect.https.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -273185,16 +273185,26 @@
      {}
     ]
    ],
    "fetch/api/resources/clean-stash.py": [
     [
      {}
     ]
    ],
+   "fetch/api/resources/cors-top.txt": [
+    [
+     {}
+    ]
+   ],
+   "fetch/api/resources/cors-top.txt.headers": [
+    [
+     {}
+    ]
+   ],
    "fetch/api/resources/data.json": [
     [
      {}
     ]
    ],
    "fetch/api/resources/echo-content.py": [
     [
      {}
@@ -555854,17 +555864,17 @@
    "bccd984f902bcfde3882c6202995b5efba82b792",
    "testharness"
   ],
   "fetch/api/redirect/redirect-mode.html": [
    "60ef7b28da442f7b7f008368606f7d6ef4560adc",
    "testharness"
   ],
   "fetch/api/redirect/redirect-mode.js": [
-   "ab6cc5b089f5d1a0ea08de94556793fcfe638be3",
+   "8553fa7a2d2df7e4b14b6fdd9dedd5856645beb4",
    "support"
   ],
   "fetch/api/redirect/redirect-origin-worker.html": [
    "b3bc9e04ce8a6a5383b4a93dbe092b84af0f6b7d",
    "testharness"
   ],
   "fetch/api/redirect/redirect-origin.html": [
    "7a56a9a4ebdf1d6cec0a5dfcfee9b8d53434c7aa",
@@ -556109,16 +556119,24 @@
   "fetch/api/resources/cache.py": [
    "fe01c89d7bef1b6385f29250a0b458024b3e28ca",
    "support"
   ],
   "fetch/api/resources/clean-stash.py": [
    "beeda08c43c04dcef5c8d0f4f5d4f2c661bbee57",
    "support"
   ],
+  "fetch/api/resources/cors-top.txt": [
+   "af2c7b4ca07ae6c74d261bc745e174df8ab3ffef",
+   "support"
+  ],
+  "fetch/api/resources/cors-top.txt.headers": [
+   "90d51a5e46cc58404dd5ec1e9e4e10934a6c0707",
+   "support"
+  ],
   "fetch/api/resources/data.json": [
    "6418064de426ecf8f0e508c751e60a0079ba044d",
    "support"
   ],
   "fetch/api/resources/echo-content.py": [
    "edc7a1d75d7c438ca3cca59f81d03058b3c2758f",
    "support"
   ],
@@ -597854,17 +597872,17 @@
    "00c90429203c85ae8f10a6a6604cdf9619524f06",
    "testharness"
   ],
   "service-workers/service-worker/fetch-event-network-error.https.html": [
    "07b81a0af207ee0723a9abae90e49482701f8935",
    "testharness"
   ],
   "service-workers/service-worker/fetch-event-redirect.https.html": [
-   "66ee27f8b1cb6bc2c8394b027d878132d3aa1c24",
+   "ef22d17c284af2354e25644d9cb20256265fbb0a",
    "testharness"
   ],
   "service-workers/service-worker/fetch-event-referrer-policy.https.html": [
    "48c31881c1933ae05cbd3d782754c5202c6b055c",
    "testharness"
   ],
   "service-workers/service-worker/fetch-event-respond-with-argument.https.html": [
    "ce7e7cf76aace24a92d455cdb6b54fc9048960e8",
--- a/testing/web-platform/tests/fetch/api/redirect/redirect-mode.js
+++ b/testing/web-platform/tests/fetch/api/redirect/redirect-mode.js
@@ -1,42 +1,52 @@
 if (this.document === undefined) {
   importScripts("/resources/testharness.js");
   importScripts("/common/get-host-info.sub.js")
 }
 
-var redirectUrl = get_host_info().HTTPS_ORIGIN + "/fetch/api/resources/redirect.py";
-var redirectLocation = "top.txt";
+var redirectLocation = "cors-top.txt";
 
-function testRedirect(redirectStatus, redirectMode, corsMode) {
-  var url = redirectUrl;
+function testRedirect(origin, redirectStatus, redirectMode, corsMode) {
+  var url = new URL("../resources/redirect.py", self.location);
+  if (origin === "cross-origin") {
+    url.host = get_host_info().REMOTE_HOST;
+  }
+
   var urlParameters = "?redirect_status=" + redirectStatus;
   urlParameters += "&location=" + encodeURIComponent(redirectLocation);
 
   var requestInit = {redirect: redirectMode, mode: corsMode};
 
   promise_test(function(test) {
-    if (redirectMode === "error" || (corsMode === "no-cors" && redirectMode !== "follow"))
+    if (redirectMode === "error" ||
+        (corsMode === "no-cors" && redirectMode !== "follow" && origin !== "same-origin"))
       return promise_rejects(test, new TypeError(), fetch(url + urlParameters, requestInit));
     if (redirectMode === "manual")
       return fetch(url + urlParameters, requestInit).then(function(resp) {
         assert_equals(resp.status, 0, "Response's status is 0");
         assert_equals(resp.type, "opaqueredirect", "Response's type is opaqueredirect");
         assert_equals(resp.statusText, "", "Response's statusText is \"\"");
         assert_equals(resp.url, url + urlParameters, "Response URL should be the original one");
       });
     if (redirectMode === "follow")
       return fetch(url + urlParameters, requestInit).then(function(resp) {
-        assert_true(new URL(resp.url).pathname.endsWith(redirectLocation), "Response's url should be the redirected one");
-        assert_equals(resp.status, 200, "Response's status is 200");
+        if (corsMode !== "no-cors" || origin === "same-origin") {
+          assert_true(new URL(resp.url).pathname.endsWith(redirectLocation), "Response's url should be the redirected one");
+          assert_equals(resp.status, 200, "Response's status is 200");
+        } else {
+          assert_equals(resp.type, "opaque", "Response is opaque");
+        }
       });
     assert_unreached(redirectMode + " is no a valid redirect mode");
-  }, "Redirect " + statusCode + " in " + redirectMode + " redirect and " + mode + " mode");
+  }, origin + " redirect " + redirectStatus + " in " + redirectMode + " redirect and " + corsMode + " mode");
 }
 
-for (var statusCode of [301, 302, 303, 307, 308]) {
-  for (var redirect of ["error", "manual", "follow"]) {
-    for (var mode of ["cors", "no-cors"])
-      testRedirect(statusCode, redirect, mode);
+for (var origin of ["same-origin", "cross-origin"]) {
+  for (var statusCode of [301, 302, 303, 307, 308]) {
+    for (var redirect of ["error", "manual", "follow"]) {
+      for (var mode of ["cors", "no-cors"])
+        testRedirect(origin, statusCode, redirect, mode);
+    }
   }
 }
 
 done();
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/fetch/api/resources/cors-top.txt
@@ -0,0 +1,1 @@
+top
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/fetch/api/resources/cors-top.txt.headers
@@ -0,0 +1,1 @@
+Access-Control-Allow-Origin: *
--- a/testing/web-platform/tests/service-workers/service-worker/fetch-event-redirect.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/fetch-event-redirect.https.html
@@ -207,52 +207,63 @@ promise_test(function(t) {
     redirect_dest: 'same-origin',
     url_credentials: false,
     expected_type: 'opaqueredirect',
     expected_redirected: false,
     request_init: {
       redirect: 'manual',
       mode: 'no-cors'
     },
-    should_reject: true
+    should_reject: false
   });
 }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
-   'same-origin without credentials should fail');
+   'same-origin without credentials should succeed opaqueredirect interception ' +
+   'and response should not be redirected');
 
 promise_test(function(t) {
   return redirect_fetch_test(t, {
     name: 'nonav-manual-nocors-redirects-to-nocors-nocreds',
     redirect_dest: 'no-cors',
     url_credentials: false,
     expected_type: 'opaqueredirect',
     expected_redirected: false,
     request_init: {
       redirect: 'manual',
       mode: 'no-cors'
     },
-    should_reject: true
+    // This should succeed because its redirecting from same-origin to
+    // cross-origin.  Since the same-origin URL provides the location
+    // header the manual redirect mode should result in an opaqueredirect
+    // response.
+    should_reject: false
   });
 }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
-   'no-cors without credentials should fail');
+   'no-cors without credentials should succeed opaqueredirect interception ' +
+   'and response should not be redirected');
 
 promise_test(function(t) {
   return redirect_fetch_test(t, {
     name: 'nonav-manual-nocors-redirects-to-cors-nocreds',
     redirect_dest: 'cors',
     url_credentials: false,
     expected_type: 'opaqueredirect',
     expected_redirected: false,
     request_init: {
       redirect: 'manual',
       mode: 'no-cors'
     },
-    should_reject: true
+    // This should succeed because its redirecting from same-origin to
+    // cross-origin.  Since the same-origin URL provides the location
+    // header the manual redirect mode should result in an opaqueredirect
+    // response.
+    should_reject: false
   });
 }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
-   'cors without credentials should fail');
+   'cors without credentials should succeed opaqueredirect interception ' +
+   'and response should not be redirected');
 
 promise_test(function(t) {
   return redirect_fetch_test(t, {
     name: 'nonav-manual-cors-redirects-to-sameorigin-creds',
     redirect_dest: 'same-origin',
     url_credentials: true,
     expected_type: 'opaqueredirect',
     expected_redirected: false,
@@ -357,52 +368,63 @@ promise_test(function(t) {
     redirect_dest: 'same-origin',
     url_credentials: true,
     expected_type: 'opaqueredirect',
     expected_redirected: false,
     request_init: {
       redirect: 'manual',
       mode: 'no-cors'
     },
-    should_reject: true
+    should_reject: false
   });
 }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
-   'same-origin with credentials should fail');
+   'same-origin with credentials should succeed opaqueredirect interception ' +
+   'and response should not be redirected');
 
 promise_test(function(t) {
   return redirect_fetch_test(t, {
     name: 'nonav-manual-nocors-redirects-to-nocors-creds',
     redirect_dest: 'no-cors',
     url_credentials: true,
     expected_type: 'opaqueredirect',
     expected_redirected: false,
     request_init: {
       redirect: 'manual',
       mode: 'no-cors'
     },
-    should_reject: true
+    // This should succeed because its redirecting from same-origin to
+    // cross-origin.  Since the same-origin URL provides the location
+    // header the manual redirect mode should result in an opaqueredirect
+    // response.
+    should_reject: false
   });
 }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
-   'no-cors with credentials should fail');
+   'no-cors with credentials should succeed opaqueredirect interception ' +
+   'and response should not be redirected');
 
 promise_test(function(t) {
   return redirect_fetch_test(t, {
     name: 'nonav-manual-nocors-redirects-to-cors-creds',
     redirect_dest: 'cors',
     url_credentials: true,
     expected_type: 'opaqueredirect',
     expected_redirected: false,
     request_init: {
       redirect: 'manual',
       mode: 'no-cors'
     },
-    should_reject: true
+    // This should succeed because its redirecting from same-origin to
+    // cross-origin.  Since the same-origin URL provides the location
+    // header the manual redirect mode should result in an opaqueredirect
+    // response.
+    should_reject: false
   });
 }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
-   'cors with credentials should fail');
+   'cors with credentials should succeed opaqueredirect interception ' +
+   'and response should not be redirected');
 
 promise_test(function(t) {
   return redirect_fetch_test(t, {
     name: 'nonav-follow-cors-redirects-to-sameorigin-nocreds',
     redirect_dest: 'same-origin',
     url_credentials: false,
     expected_type: 'basic',
     expected_redirected: true,