Bug 1452315 [wpt PR 10298] - Cookie Store: rework tests for 'expires' option, a=testonly
authorJoshua Bell <jsbell@chromium.org>
Mon, 09 Apr 2018 22:29:15 +0000
changeset 413732 3c8a0973bc175a59fa0fb0b68440c8ac6d0408db
parent 413731 04639022a761c8731ff1eef60b124935df809765
child 413733 4b387daaf7deaee185cdcc0c8e9aa68c3aa2cc43
push id102161
push userjames@hoppipolla.co.uk
push dateSun, 15 Apr 2018 09:10:16 +0000
treeherdermozilla-inbound@ebfad4be630d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1452315, 10298, 729800, 994284, 548818
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 1452315 [wpt PR 10298] - Cookie Store: rework tests for 'expires' option, a=testonly Automatic update from web-platform-testsCookie Store: rework tests for 'expires' option Simplify/rework the tests for the 'expires' options. Don't run the tests with the special secure-only prefixes, as that's orthogonal to the behvior. In Chromium, this also reveals that support for HTTP date strings as 'expires' values, as described in the explainer[1] is not yet supported. [1] https://github.com/WICG/cookie-store/blob/gh-pages/explainer.md Bug: 729800 Change-Id: I015fd643f18b59c8294f9dc62d576682132795fd Reviewed-on: https://chromium-review.googlesource.com/994284 Commit-Queue: Joshua Bell <jsbell@chromium.org> Reviewed-by: Victor Costan <pwnall@chromium.org> Cr-Commit-Position: refs/heads/master@{#548818} wpt-commits: 8b9501b721963f2b3886f25e20f17a2afe6bc381 wpt-pr: 10298 wpt-commits: 8b9501b721963f2b3886f25e20f17a2afe6bc381 wpt-pr: 10298
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/cookie-store/cookieStore_set_expires_option.tentative.window.js
testing/web-platform/tests/cookie-store/expiration.tentative.html
testing/web-platform/tests/cookie-store/expiration.tentative.https.html
testing/web-platform/tests/cookie-store/resources/expiration.js
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -214368,21 +214368,16 @@
      {}
     ]
    ],
    "cookie-store/resources/document_cookie.js": [
     [
      {}
     ]
    ],
-   "cookie-store/resources/expiration.js": [
-    [
-     {}
-    ]
-   ],
    "cookie-store/resources/get_set_get_all.js": [
     [
      {}
     ]
    ],
    "cookie-store/resources/http_cookie_and_set_cookie_headers.js": [
     [
      {}
@@ -311864,16 +311859,22 @@
     ]
    ],
    "cookie-store/cookieStore_set_arguments.tentative.window.js": [
     [
      "/cookie-store/cookieStore_set_arguments.tentative.window.html",
      {}
     ]
    ],
+   "cookie-store/cookieStore_set_expires_option.tentative.window.js": [
+    [
+     "/cookie-store/cookieStore_set_expires_option.tentative.window.html",
+     {}
+    ]
+   ],
    "cookie-store/cookieStore_special_names.tentative.html": [
     [
      "/cookie-store/cookieStore_special_names.tentative.html",
      {}
     ]
    ],
    "cookie-store/cookieStore_special_names.tentative.https.html": [
     [
@@ -311906,28 +311907,16 @@
     ]
    ],
    "cookie-store/document_getAll_multiple.tentative.html": [
     [
      "/cookie-store/document_getAll_multiple.tentative.html",
      {}
     ]
    ],
-   "cookie-store/expiration.tentative.html": [
-    [
-     "/cookie-store/expiration.tentative.html",
-     {}
-    ]
-   ],
-   "cookie-store/expiration.tentative.https.html": [
-    [
-     "/cookie-store/expiration.tentative.https.html",
-     {}
-    ]
-   ],
    "cookie-store/get_set_get_all.tentative.html": [
     [
      "/cookie-store/get_set_get_all.tentative.html",
      {}
     ]
    ],
    "cookie-store/get_set_get_all.tentative.https.html": [
     [
@@ -424239,16 +424228,20 @@
   "cookie-store/cookieStore_in_detached_frame.tentative.html": [
    "600452c1a496b8335b27bd24943b8834e37bf4d5",
    "testharness"
   ],
   "cookie-store/cookieStore_set_arguments.tentative.window.js": [
    "27019d0e79b6754715a292f40e064de53daaf5e8",
    "testharness"
   ],
+  "cookie-store/cookieStore_set_expires_option.tentative.window.js": [
+   "1eb72c6868686177a34fdb69158d184f096887b5",
+   "testharness"
+  ],
   "cookie-store/cookieStore_special_names.tentative.html": [
    "77e2b68930a1d48a93d3c7e9e8fe6c4807aa36f8",
    "testharness"
   ],
   "cookie-store/cookieStore_special_names.tentative.https.html": [
    "9b1e212b7e3ad39a15aa03b5439c6f1e1aaa4292",
    "testharness"
   ],
@@ -424267,24 +424260,16 @@
   "cookie-store/document_cookie.tentative.https.html": [
    "447ba96e7bb23a0def44817e584891097bb81998",
    "testharness"
   ],
   "cookie-store/document_getAll_multiple.tentative.html": [
    "179f3ffe69715f9767ec2d2ef661c429fef52bc6",
    "testharness"
   ],
-  "cookie-store/expiration.tentative.html": [
-   "a4e8764c12e39068a4008ad0f12c982540565dbf",
-   "testharness"
-  ],
-  "cookie-store/expiration.tentative.https.html": [
-   "fff43dd4b66455e493c06d2a1e98333e8e9b2437",
-   "testharness"
-  ],
   "cookie-store/get_set_get_all.tentative.html": [
    "89c72f73d511ab3510653baebb7c77aab6441f35",
    "testharness"
   ],
   "cookie-store/get_set_get_all.tentative.https.html": [
    "e2164c6e423724be2f91d47c0fa4931944ebff4f",
    "testharness"
   ],
@@ -424347,20 +424332,16 @@
   "cookie-store/resources/delete_cookies.js": [
    "f698e4dcc887b7e6d231fa0e8aa2aba58c3bda73",
    "support"
   ],
   "cookie-store/resources/document_cookie.js": [
    "b34ad56a2afd7f52c52dd0777b15eac2d77c4856",
    "support"
   ],
-  "cookie-store/resources/expiration.js": [
-   "483b923b03a0a0787b73118fd3f3b9f5d269f5ae",
-   "support"
-  ],
   "cookie-store/resources/get_set_get_all.js": [
    "235f22721a73a617d0b14068c8e639e93232526a",
    "support"
   ],
   "cookie-store/resources/http_cookie_and_set_cookie_headers.js": [
    "12e0d0f889bbc298e47c2450b20df0fe86ffb566",
    "support"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/cookie-store/cookieStore_set_expires_option.tentative.window.js
@@ -0,0 +1,59 @@
+'use strict';
+
+// Workaround because add_cleanup doesn't support async functions yet.
+// See https://github.com/w3c/web-platform-tests/issues/6075
+async function async_cleanup(cleanup_function) {
+  try {
+    await cleanup_function();
+  } catch (e) {
+    // Errors in cleanup functions shouldn't result in test failures.
+  }
+}
+
+promise_test(async testCase => {
+  const inTwentyFourHours = new Date(Date.now() + 24 * 60 * 60 * 1000);
+
+  assert_equals(
+    await cookieStore.set(
+      'cookie-name', 'cookie-value', { expires: inTwentyFourHours }),
+    undefined);
+
+  const cookie = await cookieStore.get('cookie-name');
+  assert_equals(cookie.name, 'cookie-name');
+  assert_equals(cookie.value, 'cookie-value');
+
+  await async_cleanup(() => cookieStore.delete('cookie-name'));
+}, 'cookieStore.set with expires option: Date object');
+
+promise_test(async testCase => {
+  const inTwentyFourHours = Date.now() + 24 * 60 * 60 * 1000;
+
+  assert_equals(
+    await cookieStore.set(
+      'cookie-name', 'cookie-value', { expires: inTwentyFourHours }),
+    undefined);
+
+  const cookie = await cookieStore.get('cookie-name');
+  assert_equals(cookie.name, 'cookie-name');
+  assert_equals(cookie.value, 'cookie-value');
+
+  await async_cleanup(() => cookieStore.delete('cookie-name'));
+}, 'cookieStore.set with expires option: milliseconds since epoch object');
+
+promise_test(async testCase => {
+  const year = (new Date()).getUTCFullYear() + 1;
+  const date = new Date('07 Jun ' + year + ' 07:07:07 UTC');
+  const day = ('Sun Mon Tue Wed Thu Fri Sat'.split(' '))[date.getUTCDay()];
+  const nextJune = `${day}, 07 Jun ${year} + ' 07:07:07 GMT`;
+
+  assert_equals(
+    await cookieStore.set(
+      'cookie-name', 'cookie-value', { expires: nextJune }),
+    undefined);
+
+  const cookie = await cookieStore.get('cookie-name');
+  assert_equals(cookie.name, 'cookie-name');
+  assert_equals(cookie.value, 'cookie-value');
+
+  await async_cleanup(() => cookieStore.delete('cookie-name'));
+}, 'cookieStore.set with expires option: HTTP date string');
deleted file mode 100644
--- a/testing/web-platform/tests/cookie-store/expiration.tentative.html
+++ /dev/null
@@ -1,8 +0,0 @@
-<!DOCTYPE html>
-<meta charset="utf-8">
-<title>Async Cookies: expiration</title>
-<meta name="help" href="https://github.com/WICG/cookie-store/">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="resources/cookie-test-helpers.js"></script>
-<script src="resources/expiration.js"></script>
deleted file mode 100644
--- a/testing/web-platform/tests/cookie-store/expiration.tentative.https.html
+++ /dev/null
@@ -1,8 +0,0 @@
-<!DOCTYPE html>
-<meta charset="utf-8">
-<title>Async Cookies: expiration (HTTPS)</title>
-<meta name="help" href="https://github.com/WICG/cookie-store/">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="resources/cookie-test-helpers.js"></script>
-<script src="resources/expiration.js"></script>
deleted file mode 100644
--- a/testing/web-platform/tests/cookie-store/resources/expiration.js
+++ /dev/null
@@ -1,89 +0,0 @@
-'use strict';
-
-// Set the secure example.org-domain cookie __Secure-COOKIENAME with
-// value cookie-value on path /cgi-bin/ and 24 hour duration; domain
-// and path will be rewritten below.
-//
-// This uses a Date object for expiration.
-async function setOneDaySecureCookieWithDate() {
-  // one day ahead, ignoring a possible leap-second
-  let inTwentyFourHours = new Date(Date.now() + 24 * 60 * 60 * 1000);
-  await cookieStore.set('__Secure-COOKIENAME', 'cookie-value', {
-    path: kPath,
-    expires: inTwentyFourHours,
-    secure: true,
-    domain: location.hostname
-  });
-}
-
-// Set the secured example.org-domain cookie __Secure-COOKIENAME with
-// value cookie-value on path /cgi-bin/ and expiration in June of next
-// year; domain and path will be rewritten below.
-//
-// This uses an HTTP-style date string for expiration.
-async function setSecureCookieWithHttpLikeExpirationString() {
-  const year = (new Date()).getUTCFullYear() + 1;
-  const date = new Date('07 Jun ' + year + ' 07:07:07 UTC');
-  const day = ('Sun Mon Tue Wed Thu Fri Sat'.split(' '))[date.getUTCDay()];
-  await cookieStore.set('__Secure-COOKIENAME', 'cookie-value', {
-    path: kPath,
-    expires: day + ', 07 Jun ' + year + ' 07:07:07 GMT',
-    secure: true,
-    domain: location.hostname
-  });
-}
-
-// Set the unsecured example.org-domain cookie LEGACYCOOKIENAME with
-// value cookie-value on path /cgi-bin/ and 24 hour duration; domain
-// and path will be rewritten below.
-//
-// This uses milliseconds since the start of the Unix epoch for
-// expiration.
-async function setOneDayUnsecuredCookieWithMillisecondsSinceEpoch() {
-  // one day ahead, ignoring a possible leap-second
-  let inTwentyFourHours = Date.now() + 24 * 60 * 60 * 1000;
-  await cookieStore.set('LEGACYCOOKIENAME', 'cookie-value', {
-    path: kPath,
-    expires: inTwentyFourHours,
-    secure: false,
-    domain: location.hostname
-  });
-}
-
-// Delete the cookie written by
-// setOneDayUnsecuredCookieWithMillisecondsSinceEpoch.
-async function deleteUnsecuredCookieWithDomainAndPath() {
-  await cookieStore.delete('LEGACYCOOKIENAME', {
-    path: kPath,
-    secure: false,
-    domain: location.hostname
-  });
-}
-
-cookie_test(async testCase => {
-  await promise_rejects_when_unsecured(
-    testCase,
-    new TypeError(),
-    setOneDaySecureCookieWithDate(),
-    'Secure cookies only writable from secure contexts');
-
-  const eventPromise = observeNextCookieChangeEvent();
-
-  await setOneDayUnsecuredCookieWithMillisecondsSinceEpoch();
-  assert_equals(
-      await getCookieString('LEGACYCOOKIENAME'),
-      'LEGACYCOOKIENAME=cookie-value',
-      'Ensure unsecured cookie we set is visible');
-
-  await verifyCookieChangeEvent(
-    eventPromise,
-    {changed: [{name: 'LEGACYCOOKIENAME', value: 'cookie-value'}]},
-    'Ensure unsecured cookie we set is visible to observer');
-
-  await deleteUnsecuredCookieWithDomainAndPath();
-  await promise_rejects_when_unsecured(
-      testCase,
-      new TypeError(),
-      setSecureCookieWithHttpLikeExpirationString(),
-      'Secure cookies only writable from secure contexts');
-}, 'expiration');