Bug 1484265 [wpt PR 12551] - Reland cache.addAll() duplicate VARY header WPT tests., a=testonly
authorBen Kelly <wanderview@chromium.org>
Wed, 22 Aug 2018 13:19:20 +0000
changeset 488197 a02fe67c7eee8a571cb3fecf340060caa6b0c93b
parent 488196 831848256863ad85768ac72bebbe75b633a7c50a
child 488198 9025cd12ce67c2c3ac66dd51fb811b7f6da7167c
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1484265, 12551, 720919, 1179942, 584105
milestone63.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 1484265 [wpt PR 12551] - Reland cache.addAll() duplicate VARY header WPT tests., a=testonly Automatic update from web-platform-testsReland cache.addAll() duplicate VARY header WPT tests. R=jsbell@chromium.org Bug: 720919 Change-Id: I88447c05f40937eb7f73cc2399ce5b1a025e1911 Reviewed-on: https://chromium-review.googlesource.com/1179942 Reviewed-by: Joshua Bell <jsbell@chromium.org> Commit-Queue: Ben Kelly <wanderview@chromium.org> Cr-Commit-Position: refs/heads/master@{#584105} -- wpt-commits: 184575d501a8286aabb4f95f8db34926559b7d8b wpt-pr: 12551
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/service-workers/cache-storage/resources/vary.py
testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-add.js
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -298713,16 +298713,21 @@
      {}
     ]
    ],
    "service-workers/cache-storage/resources/test-helpers.js": [
     [
      {}
     ]
    ],
+   "service-workers/cache-storage/resources/vary.py": [
+    [
+     {}
+    ]
+   ],
    "service-workers/cache-storage/script-tests/cache-abort.js": [
     [
      {}
     ]
    ],
    "service-workers/cache-storage/script-tests/cache-add.js": [
     [
      {}
@@ -630471,22 +630476,26 @@
   "service-workers/cache-storage/resources/simple.txt": [
    "9e3cb91fb9b95d6e51de85b82e6f86e92f59ac6d",
    "support"
   ],
   "service-workers/cache-storage/resources/test-helpers.js": [
    "050ac0b542455ceb53ed36038af5b9b0810977cf",
    "support"
   ],
+  "service-workers/cache-storage/resources/vary.py": [
+   "59e39bc2ae730a4cd3e1376dd003c9ffada4ed4a",
+   "support"
+  ],
   "service-workers/cache-storage/script-tests/cache-abort.js": [
    "ec4130fded29e0070828092c2546dc46456d8fdc",
    "support"
   ],
   "service-workers/cache-storage/script-tests/cache-add.js": [
-   "c03faeb0e83723eab64e648e600ba0612873d404",
+   "a482c42eaeb2a902a36b1d6aecd306e8ed4b4ebf",
    "support"
   ],
   "service-workers/cache-storage/script-tests/cache-delete.js": [
    "3cf9aeb4c23a9f7ad1d5433f2d5f4e46e4e8fdd1",
    "support"
   ],
   "service-workers/cache-storage/script-tests/cache-keys.js": [
    "a94c18f873c8b75c6faaa3a10d54ac58cf7c7c00",
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/cache-storage/resources/vary.py
@@ -0,0 +1,25 @@
+def main(request, response):
+  if "clear-vary-value-override-cookie" in request.GET:
+    response.unset_cookie("vary-value-override")
+    return "vary cookie cleared"
+
+  set_cookie_vary = request.GET.first("set-vary-value-override-cookie",
+                                      default="")
+  if set_cookie_vary:
+    response.set_cookie("vary-value-override", set_cookie_vary)
+    return "vary cookie set"
+
+  # If there is a vary-value-override cookie set, then use its value
+  # for the VARY header no matter what the query string is set to.  This
+  # override is necessary to test the case when two URLs are identical
+  # (including query), but differ by VARY header.
+  cookie_vary = request.cookies.get("vary-value-override");
+  if cookie_vary:
+    response.headers.set("vary", cookie_vary)
+  else:
+    # If there is no cookie, then use the query string value, if present.
+    query_vary = request.GET.first("vary", default="")
+    if query_vary:
+      response.headers.set("vary", query_vary)
+
+  return "vary response"
--- a/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-add.js
+++ b/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-add.js
@@ -262,9 +262,89 @@ cache_test(function(cache, test) {
     return promise_rejects(
       test,
       'InvalidStateError',
       cache.addAll([request, request]),
       'Cache.addAll should throw InvalidStateError if the same request is added ' +
       'twice.');
   }, 'Cache.addAll called with the same Request object specified twice');
 
+cache_test(async function(cache, test) {
+    const url = '../resources/vary.py?vary=x-shape';
+    let requests = [
+      new Request(url, { headers: { 'x-shape': 'circle' }}),
+      new Request(url, { headers: { 'x-shape': 'square' }}),
+    ];
+    let result = await cache.addAll(requests);
+    assert_equals(result, undefined, 'Cache.addAll() should succeed');
+  }, 'Cache.addAll should succeed when entries differ by vary header');
+
+cache_test(async function(cache, test) {
+    const url = '../resources/vary.py?vary=x-shape';
+    let requests = [
+      new Request(url, { headers: { 'x-shape': 'circle' }}),
+      new Request(url, { headers: { 'x-shape': 'circle' }}),
+    ];
+    await promise_rejects(
+      test,
+      'InvalidStateError',
+      cache.addAll(requests),
+      'Cache.addAll() should reject when entries are duplicate by vary header');
+  }, 'Cache.addAll should reject when entries are duplicate by vary header');
+
+// VARY header matching is asymmetric.  Determining if two entries are duplicate
+// depends on which entry's response is used in the comparison.  The target
+// response's VARY header determines what request headers are examined.  This
+// test verifies that Cache.addAll() duplicate checking handles this asymmetric
+// behavior correctly.
+cache_test(async function(cache, test) {
+    const base_url = '../resources/vary.py';
+
+    // Define a request URL that sets a VARY header in the
+    // query string to be echoed back by the server.
+    const url = base_url + '?vary=x-size';
+
+    // Set a cookie to override the VARY header of the response
+    // when the request is made with credentials.  This will
+    // take precedence over the query string vary param.  This
+    // is a bit confusing, but it's necessary to construct a test
+    // where the URL is the same, but the VARY headers differ.
+    //
+    // Note, the test could also pass this information in additional
+    // request headers.  If the cookie approach becomes too unwieldy
+    // this test could be rewritten to use that technique.
+    await fetch(base_url + '?set-vary-value-override-cookie=x-shape');
+    test.add_cleanup(_ => fetch(base_url + '?clear-vary-value-override-cookie'));
+
+    let requests = [
+      // This request will result in a Response with a "Vary: x-shape"
+      // header.  This *will not* result in a duplicate match with the
+      // other entry.
+      new Request(url, { headers: { 'x-shape': 'circle',
+                                    'x-size': 'big' },
+                         credentials: 'same-origin' }),
+
+      // This request will result in a Response with a "Vary: x-size"
+      // header.  This *will* result in a duplicate match with the other
+      // entry.
+      new Request(url, { headers: { 'x-shape': 'square',
+                                    'x-size': 'big' },
+                         credentials: 'omit' }),
+    ];
+    await promise_rejects(
+      test,
+      'InvalidStateError',
+      cache.addAll(requests),
+      'Cache.addAll() should reject when one entry has a vary header ' +
+      'matching an earlier entry.');
+
+    // Test the reverse order now.
+    await promise_rejects(
+      test,
+      'InvalidStateError',
+      cache.addAll(requests.reverse()),
+      'Cache.addAll() should reject when one entry has a vary header ' +
+      'matching a later entry.');
+
+  }, 'Cache.addAll should reject when one entry has a vary header ' +
+     'matching another entry');
+
 done();