Cookie Store API: Add more WPT coverage for Service Worker.

Bug: 729800
Change-Id: I5de81be0eb6cd2f90722e42655ce58ef52d3d26f
Reviewed-on: https://chromium-review.googlesource.com/831254
Reviewed-by: Joshua Bell <jsbell@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524860}
diff --git a/cookie-store/cookieStore_delete_arguments.tentative.html b/cookie-store/cookieStore_delete_arguments.tentative.window.js
similarity index 89%
rename from cookie-store/cookieStore_delete_arguments.tentative.html
rename to cookie-store/cookieStore_delete_arguments.tentative.window.js
index 962f13a..8f3f6f5 100644
--- a/cookie-store/cookieStore_delete_arguments.tentative.html
+++ b/cookie-store/cookieStore_delete_arguments.tentative.window.js
@@ -1,11 +1,3 @@
-<!doctype html>
-<meta charset="utf-8">
-<title>Async Cookies: cookieStore.delete() arguments and options</title>
-<link rel="help" href="https://github.com/WICG/cookie-store">
-<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
 'use strict';
 
 // Workaround because add_cleanup doesn't support async functions yet.
@@ -76,7 +68,7 @@
 }, 'cookieStore.delete with expires in options');
 
 promise_test(async testCase => {
-  const currentUrl = new URL(window.location.href);
+  const currentUrl = new URL(self.location.href);
   const currentDomain = currentUrl.hostname;
   await cookieStore.set(
       'cookie-name', 'cookie-value', { domain: currentDomain });
@@ -91,7 +83,7 @@
 }, 'cookieStore.delete with domain set to the current hostname');
 
 promise_test(async testCase => {
-  const currentUrl = new URL(window.location.href);
+  const currentUrl = new URL(self.location.href);
   const currentDomain = currentUrl.hostname;
   const subDomain = `sub.${currentDomain}`;
   await cookieStore.set(
@@ -108,7 +100,7 @@
 }, 'cookieStore.delete with domain set to a subdomain of the current hostname');
 
 promise_test(async testCase => {
-  const currentUrl = new URL(window.location.href);
+  const currentUrl = new URL(self.location.href);
   const currentDomain = currentUrl.hostname;
   await cookieStore.set(
       'cookie-name', 'cookie-value', { domain: currentDomain });
@@ -124,7 +116,7 @@
    'hostname');
 
 promise_test(async testCase => {
-  const currentUrl = new URL(window.location.href);
+  const currentUrl = new URL(self.location.href);
   const currentDomain = currentUrl.hostname;
   const subDomain = `sub.${currentDomain}`;
   await cookieStore.set(
@@ -143,7 +135,7 @@
 
 
 promise_test(async testCase => {
-  const currentUrl = new URL(window.location.href);
+  const currentUrl = new URL(self.location.href);
   const currentPath = currentUrl.pathname;
   const currentDirectory =
       currentPath.substr(0, currentPath.lastIndexOf('/') + 1);
@@ -160,7 +152,7 @@
 }, 'cookieStore.delete with path set to the current directory');
 
 promise_test(async testCase => {
-  const currentUrl = new URL(window.location.href);
+  const currentUrl = new URL(self.location.href);
   const currentPath = currentUrl.pathname;
   const currentDirectory =
       currentPath.substr(0, currentPath.lastIndexOf('/') + 1);
@@ -177,5 +169,3 @@
     await cookieStore.delete('cookie-name', { path: currentDirectory })
   });
 }, 'cookieStore.delete with path set to subdirectory of the current directory');
-
-</script>
diff --git a/cookie-store/cookieStore_getAll_arguments.tentative.html b/cookie-store/cookieStore_getAll_arguments.tentative.window.js
similarity index 92%
rename from cookie-store/cookieStore_getAll_arguments.tentative.html
rename to cookie-store/cookieStore_getAll_arguments.tentative.window.js
index 3066a99..650d6eb 100644
--- a/cookie-store/cookieStore_getAll_arguments.tentative.html
+++ b/cookie-store/cookieStore_getAll_arguments.tentative.window.js
@@ -1,11 +1,3 @@
-<!doctype html>
-<meta charset="utf-8">
-<title>Async Cookies: cookieStore.getAll() arguments and options</title>
-<link rel="help" href="https://github.com/WICG/cookie-store">
-<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
 'use strict';
 
 // Workaround because add_cleanup doesn't support async functions yet.
@@ -125,5 +117,3 @@
   await async_cleanup(() => cookieStore.delete('cookie-name'));
   await async_cleanup(() => cookieStore.delete('cookie-name-2'));
 }, 'cookieStore.getAll with matchType set to startsWith and name in options');
-
-</script>
diff --git a/cookie-store/document_getAll_set.tentative.html b/cookie-store/cookieStore_getAll_set_basic.tentative.window.js
similarity index 66%
rename from cookie-store/document_getAll_set.tentative.html
rename to cookie-store/cookieStore_getAll_set_basic.tentative.window.js
index 05a794b..a70c119 100644
--- a/cookie-store/document_getAll_set.tentative.html
+++ b/cookie-store/cookieStore_getAll_set_basic.tentative.window.js
@@ -1,11 +1,3 @@
-<!doctype html>
-<meta charset="utf-8">
-<title>Async Cookies: cookieStore.getAll() sees cookieStore.set() cookie</title>
-<link rel="help" href="https://github.com/WICG/cookie-store">
-<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
 'use strict';
 
 // Workaround because add_cleanup doesn't support async functions yet.
@@ -28,5 +20,3 @@
 
   await async_cleanup(() => cookieStore.delete('cookie-name'));
 }, 'cookieStore.getAll returns the cookie written by cookieStore.set');
-
-</script>
diff --git a/cookie-store/cookieStore_get_arguments.tentative.html b/cookie-store/cookieStore_get_arguments.tentative.window.js
similarity index 88%
rename from cookie-store/cookieStore_get_arguments.tentative.html
rename to cookie-store/cookieStore_get_arguments.tentative.window.js
index 469cf4b..f50bb51 100644
--- a/cookie-store/cookieStore_get_arguments.tentative.html
+++ b/cookie-store/cookieStore_get_arguments.tentative.window.js
@@ -1,11 +1,3 @@
-<!doctype html>
-<meta charset="utf-8">
-<title>Async Cookies: cookieStore.get() arguments and options</title>
-<link rel="help" href="https://github.com/WICG/cookie-store">
-<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
 'use strict';
 
 // Workaround because add_cleanup doesn't support async functions yet.
@@ -92,5 +84,3 @@
 
   async_cleanup(() => cookieStore.delete('cookie-name'));
 }, 'cookieStore.get with matchType set to startsWith and name in options');
-
-</script>
diff --git a/cookie-store/document_get_delete.tentative.html b/cookie-store/cookieStore_get_delete_basic.tentative.window.js
similarity index 64%
rename from cookie-store/document_get_delete.tentative.html
rename to cookie-store/cookieStore_get_delete_basic.tentative.window.js
index ebb2c8f..e039d81 100644
--- a/cookie-store/document_get_delete.tentative.html
+++ b/cookie-store/cookieStore_get_delete_basic.tentative.window.js
@@ -1,11 +1,3 @@
-<!doctype html>
-<meta charset="utf-8">
-<title>Async Cookies: cookieStore.delete() impacts cookieStore.get()</title>
-<link rel="help" href="https://github.com/WICG/cookie-store">
-<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
 'use strict';
 
 // Workaround because add_cleanup doesn't support async functions yet.
@@ -25,6 +17,4 @@
   assert_equals(cookie, null);
 
   await async_cleanup(() => cookieStore.delete('cookie-name'));
-}, 'cookieStore.get returns null for a cookie deleted by cookieStore.delete');
-
-</script>
+}, 'cookieStore.get returns null for a cookie deleted by cookieStore.delete');
\ No newline at end of file
diff --git a/cookie-store/get_set.tentative.window.js b/cookie-store/cookieStore_get_set_basic.tentative.window.js
similarity index 100%
rename from cookie-store/get_set.tentative.window.js
rename to cookie-store/cookieStore_get_set_basic.tentative.window.js
diff --git a/cookie-store/cookieStore_has_arguments.tentative.html b/cookie-store/cookieStore_has_arguments.tentative.window.js
similarity index 89%
rename from cookie-store/cookieStore_has_arguments.tentative.html
rename to cookie-store/cookieStore_has_arguments.tentative.window.js
index c5d8d0b..443341e 100644
--- a/cookie-store/cookieStore_has_arguments.tentative.html
+++ b/cookie-store/cookieStore_has_arguments.tentative.window.js
@@ -1,11 +1,3 @@
-<!doctype html>
-<meta charset="utf-8">
-<title>Async Cookies: cookieStore.has() arguments and options</title>
-<link rel="help" href="https://github.com/WICG/cookie-store">
-<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
 'use strict';
 
 // Workaround because add_cleanup doesn't support async functions yet.
@@ -98,5 +90,3 @@
 
   await async_cleanup(() => cookieStore.delete('cookie-name'));
 }, 'cookieStore.has with matchType set to startsWith and name in options');
-
-</script>
diff --git a/cookie-store/document_has.tentative.html b/cookie-store/cookieStore_has_basic.tentative.window.js
similarity index 72%
rename from cookie-store/document_has.tentative.html
rename to cookie-store/cookieStore_has_basic.tentative.window.js
index 9c2eb5b..0774a71 100644
--- a/cookie-store/document_has.tentative.html
+++ b/cookie-store/cookieStore_has_basic.tentative.window.js
@@ -1,11 +1,3 @@
-<!doctype html>
-<meta charset="utf-8">
-<title>Async Cookies: cookieStore.has()</title>
-<link rel="help" href="https://github.com/WICG/cookie-store">
-<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
 'use strict';
 
 // Workaround because add_cleanup doesn't support async functions yet.
@@ -31,5 +23,3 @@
 
   await async_cleanup(() => cookieStore.delete('cookie-name'));
 }, 'cookieStore.has returns false for cookie deleted by cookieStore.delete()');
-
-</script>
diff --git a/cookie-store/cookieStore_set_arguments.tentative.html b/cookie-store/cookieStore_set_arguments.tentative.window.js
similarity index 92%
rename from cookie-store/cookieStore_set_arguments.tentative.html
rename to cookie-store/cookieStore_set_arguments.tentative.window.js
index 7a16162..c256430 100644
--- a/cookie-store/cookieStore_set_arguments.tentative.html
+++ b/cookie-store/cookieStore_set_arguments.tentative.window.js
@@ -1,11 +1,3 @@
-<!doctype html>
-<meta charset="utf-8">
-<title>Async Cookies: cookieStore.set() arguments and options</title>
-<link rel="help" href="https://github.com/WICG/cookie-store">
-<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
 'use strict';
 
 // Workaround because add_cleanup doesn't support async functions yet.
@@ -118,7 +110,7 @@
 }, 'cookieStore.set with name and value in options and expires in the past');
 
 promise_test(async testCase => {
-  const currentUrl = new URL(window.location.href);
+  const currentUrl = new URL(self.location.href);
   const currentDomain = currentUrl.hostname;
   await cookieStore.delete('cookie-name', { domain: currentDomain });
 
@@ -134,7 +126,7 @@
 }, 'cookieStore.set with domain set to the current hostname');
 
 promise_test(async testCase => {
-  const currentUrl = new URL(window.location.href);
+  const currentUrl = new URL(self.location.href);
   const currentDomain = currentUrl.hostname;
   const subDomain = `sub.${currentDomain}`;
   await cookieStore.delete('cookie-name', { domain: currentDomain });
@@ -151,7 +143,7 @@
 }, 'cookieStore.set with domain set to a subdomain of the current hostname');
 
 promise_test(async testCase => {
-  const currentUrl = new URL(window.location.href);
+  const currentUrl = new URL(self.location.href);
   const currentDomain = currentUrl.hostname;
   await cookieStore.delete('cookie-name');
 
@@ -171,7 +163,7 @@
 }, 'cookieStore.set default domain is current hostname');
 
 promise_test(async testCase => {
-  const currentUrl = new URL(window.location.href);
+  const currentUrl = new URL(self.location.href);
   const currentPath = currentUrl.pathname;
   const currentDirectory =
       currentPath.substr(0, currentPath.lastIndexOf('/') + 1);
@@ -189,7 +181,7 @@
 }, 'cookieStore.set with path set to the current directory');
 
 promise_test(async testCase => {
-  const currentUrl = new URL(window.location.href);
+  const currentUrl = new URL(self.location.href);
   const currentPath = currentUrl.pathname;
   const currentDirectory =
       currentPath.substr(0, currentPath.lastIndexOf('/') + 1);
@@ -221,5 +213,3 @@
   await async_cleanup(() => cookieStore.delete('cookie-name'));
   await async_cleanup(() => cookieStore.delete('cookie-name', { path: '/' }));
 }, 'cookieStore.set default path is /');
-
-</script>
diff --git a/cookie-store/serviceworker_cookieStore_arguments.js b/cookie-store/serviceworker_cookieStore_arguments.js
new file mode 100644
index 0000000..0ffe6f8
--- /dev/null
+++ b/cookie-store/serviceworker_cookieStore_arguments.js
@@ -0,0 +1,14 @@
+self.GLOBAL = {
+  isWindow: function() { return false; },
+  isWorker: function() { return true; },
+};
+importScripts("/resources/testharness.js");
+
+importScripts(
+    "cookieStore_delete_arguments.tentative.window.js",
+    "cookieStore_get_arguments.tentative.window.js",
+    "cookieStore_getAll_arguments.tentative.window.js",
+    "cookieStore_has_arguments.tentative.window.js",
+    "cookieStore_set_arguments.tentative.window.js");
+
+done();
diff --git a/cookie-store/serviceworker_cookiestore_basic.tentative.https.html b/cookie-store/serviceworker_cookieStore_arguments.tentative.https.html
similarity index 63%
copy from cookie-store/serviceworker_cookiestore_basic.tentative.https.html
copy to cookie-store/serviceworker_cookieStore_arguments.tentative.https.html
index 0c3f681..06c9501 100644
--- a/cookie-store/serviceworker_cookiestore_basic.tentative.https.html
+++ b/cookie-store/serviceworker_cookieStore_arguments.tentative.https.html
@@ -1,6 +1,8 @@
 <!doctype html>
 <meta charset="utf-8">
-<title>Async Cookies: cookieStore.get() sees cookieStore.set() cookie in ServiceWorker</title>
+<title>Async Cookies: cookieStore API argument handling in ServiceWorker</title>
+<link rel="help" href="https://github.com/WICG/cookie-store">
+<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script>
@@ -13,7 +15,7 @@
   if (registration)
     await registration.unregister();
   registration = await navigator.serviceWorker.register(
-      'serviceworker_cookiestore_basic.js', {scope});
+      'serviceworker_cookieStore_arguments.js', {scope});
 
   fetch_tests_from_worker(registration.installing);
 })();
diff --git a/cookie-store/serviceworker_cookieStore_basic.js b/cookie-store/serviceworker_cookieStore_basic.js
new file mode 100644
index 0000000..0d8039f
--- /dev/null
+++ b/cookie-store/serviceworker_cookieStore_basic.js
@@ -0,0 +1,13 @@
+self.GLOBAL = {
+  isWindow: function() { return false; },
+  isWorker: function() { return true; },
+};
+importScripts("/resources/testharness.js");
+
+importScripts(
+    "cookieStore_get_delete_basic.tentative.window.js",
+    "cookieStore_get_set_basic.tentative.window.js",
+    "cookieStore_getAll_set_basic.tentative.window.js",
+    "cookieStore_has_basic.tentative.window.js");
+
+done();
diff --git a/cookie-store/serviceworker_cookiestore_basic.tentative.https.html b/cookie-store/serviceworker_cookieStore_basic.tentative.https.html
similarity index 65%
rename from cookie-store/serviceworker_cookiestore_basic.tentative.https.html
rename to cookie-store/serviceworker_cookieStore_basic.tentative.https.html
index 0c3f681..d4385d6 100644
--- a/cookie-store/serviceworker_cookiestore_basic.tentative.https.html
+++ b/cookie-store/serviceworker_cookieStore_basic.tentative.https.html
@@ -1,6 +1,8 @@
 <!doctype html>
 <meta charset="utf-8">
-<title>Async Cookies: cookieStore.get() sees cookieStore.set() cookie in ServiceWorker</title>
+<title>Async Cookies: cookieStore basic API in ServiceWorker</title>
+<link rel="help" href="https://github.com/WICG/cookie-store">
+<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script>
@@ -13,7 +15,7 @@
   if (registration)
     await registration.unregister();
   registration = await navigator.serviceWorker.register(
-      'serviceworker_cookiestore_basic.js', {scope});
+      'serviceworker_cookieStore_basic.js', {scope});
 
   fetch_tests_from_worker(registration.installing);
 })();
diff --git a/cookie-store/serviceworker_cookiestore_basic.js b/cookie-store/serviceworker_cookiestore_basic.js
deleted file mode 100644
index 13b973e..0000000
--- a/cookie-store/serviceworker_cookiestore_basic.js
+++ /dev/null
@@ -1,9 +0,0 @@
-self.GLOBAL = {
-  isWindow: function() { return false; },
-  isWorker: function() { return true; },
-};
-importScripts("/resources/testharness.js");
-
-importScripts("get_set.tentative.window.js");
-
-done();