From fc951d200a78fc97342ee0e99aa2949365aca71c Mon Sep 17 00:00:00 2001
From: Tom Tung <shes050117@gmail.com>
Date: Thu, 17 Sep 2020 13:02:46 +0000
Subject: [PATCH] Bug 1654531 - Remove the support for cache option from
 cache.match; r=dom-workers-and-storage-reviewers,webidl,asuth,baku

Fix the test cases for "Cache.match does not support cacheName option"

Depends on D84502

Differential Revision: https://phabricator.services.mozilla.com/D84503
---
 dom/cache/CacheStorage.cpp                        |  2 +-
 dom/cache/CacheStorage.h                          |  2 +-
 dom/cache/TypeUtils.cpp                           | 15 +++++++++++----
 dom/cache/TypeUtils.h                             |  4 ++++
 dom/webidl/Cache.webidl                           |  1 -
 dom/webidl/CacheStorage.webidl                    |  6 +++++-
 .../serviceworker/cache-match.https.html.ini      |  3 ---
 .../window/cache-match.https.html.ini             |  3 ---
 .../worker/cache-match.https.html.ini             |  3 ---
 9 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/dom/cache/CacheStorage.cpp b/dom/cache/CacheStorage.cpp
index 02f3119d277d9..8ed53a0ce87db 100644
--- a/dom/cache/CacheStorage.cpp
+++ b/dom/cache/CacheStorage.cpp
@@ -314,7 +314,7 @@ CacheStorage::CacheStorage(nsresult aFailureResult)
 
 already_AddRefed<Promise> CacheStorage::Match(
     JSContext* aCx, const RequestOrUSVString& aRequest,
-    const CacheQueryOptions& aOptions, ErrorResult& aRv) {
+    const MultiCacheQueryOptions& aOptions, ErrorResult& aRv) {
   NS_ASSERT_OWNINGTHREAD(CacheStorage);
 
   if (!HasStorageAccess()) {
diff --git a/dom/cache/CacheStorage.h b/dom/cache/CacheStorage.h
index 5d854731d2a63..74770216a9c62 100644
--- a/dom/cache/CacheStorage.h
+++ b/dom/cache/CacheStorage.h
@@ -55,7 +55,7 @@ class CacheStorage final : public nsISupports,
   // webidl interface methods
   already_AddRefed<Promise> Match(JSContext* aCx,
                                   const RequestOrUSVString& aRequest,
-                                  const CacheQueryOptions& aOptions,
+                                  const MultiCacheQueryOptions& aOptions,
                                   ErrorResult& aRv);
   already_AddRefed<Promise> Has(const nsAString& aKey, ErrorResult& aRv);
   already_AddRefed<Promise> Open(const nsAString& aKey, ErrorResult& aRv);
diff --git a/dom/cache/TypeUtils.cpp b/dom/cache/TypeUtils.cpp
index 52d933ae6b257..83ea0b99ad81a 100644
--- a/dom/cache/TypeUtils.cpp
+++ b/dom/cache/TypeUtils.cpp
@@ -6,8 +6,10 @@
 
 #include "mozilla/dom/cache/TypeUtils.h"
 
+#include "mozilla/StaticPrefs_extensions.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/CacheBinding.h"
+#include "mozilla/dom/CacheStorageBinding.h"
 #include "mozilla/dom/FetchTypes.h"
 #include "mozilla/dom/InternalRequest.h"
 #include "mozilla/dom/Request.h"
@@ -19,16 +21,15 @@
 #include "mozilla/ipc/PBackgroundChild.h"
 #include "mozilla/ipc/PFileDescriptorSetChild.h"
 #include "mozilla/ipc/InputStreamUtils.h"
-#include "mozilla/StaticPrefs_extensions.h"
 #include "nsCOMPtr.h"
+#include "nsCRT.h"
+#include "nsHttp.h"
 #include "nsIIPCSerializableInputStream.h"
-#include "nsQueryObject.h"
 #include "nsPromiseFlatString.h"
+#include "nsQueryObject.h"
 #include "nsStreamUtils.h"
 #include "nsString.h"
 #include "nsURLParsers.h"
-#include "nsCRT.h"
-#include "nsHttp.h"
 
 namespace mozilla {
 namespace dom {
@@ -243,6 +244,12 @@ void TypeUtils::ToCacheQueryParams(CacheQueryParams& aOut,
   aOut.ignoreSearch() = aIn.mIgnoreSearch;
   aOut.ignoreMethod() = aIn.mIgnoreMethod;
   aOut.ignoreVary() = aIn.mIgnoreVary;
+}
+
+// static
+void TypeUtils::ToCacheQueryParams(CacheQueryParams& aOut,
+                                   const MultiCacheQueryOptions& aIn) {
+  ToCacheQueryParams(aOut, static_cast<const CacheQueryOptions&>(aIn));
   aOut.cacheNameSet() = aIn.mCacheName.WasPassed();
   if (aOut.cacheNameSet()) {
     aOut.cacheName() = aIn.mCacheName.Value();
diff --git a/dom/cache/TypeUtils.h b/dom/cache/TypeUtils.h
index ede919f55a5c0..628a7f8bcd504 100644
--- a/dom/cache/TypeUtils.h
+++ b/dom/cache/TypeUtils.h
@@ -27,6 +27,7 @@ class AutoIPCStream;
 namespace dom {
 
 struct CacheQueryOptions;
+struct MultiCacheQueryOptions;
 class InternalHeaders;
 class InternalRequest;
 class InternalResponse;
@@ -88,6 +89,9 @@ class TypeUtils {
 
   void ToCacheQueryParams(CacheQueryParams& aOut, const CacheQueryOptions& aIn);
 
+  void ToCacheQueryParams(CacheQueryParams& aOut,
+                          const MultiCacheQueryOptions& aIn);
+
   already_AddRefed<Response> ToResponse(const CacheResponse& aIn);
 
   SafeRefPtr<InternalRequest> ToInternalRequest(const CacheRequest& aIn);
diff --git a/dom/webidl/Cache.webidl b/dom/webidl/Cache.webidl
index e1ca5fdc3bae2..92aaf2d79c9e8 100644
--- a/dom/webidl/Cache.webidl
+++ b/dom/webidl/Cache.webidl
@@ -33,7 +33,6 @@ dictionary CacheQueryOptions {
   boolean ignoreSearch = false;
   boolean ignoreMethod = false;
   boolean ignoreVary = false;
-  DOMString cacheName;
 };
 
 dictionary CacheBatchOperation {
diff --git a/dom/webidl/CacheStorage.webidl b/dom/webidl/CacheStorage.webidl
index ceced431f8bdd..e1100bdfedd74 100644
--- a/dom/webidl/CacheStorage.webidl
+++ b/dom/webidl/CacheStorage.webidl
@@ -19,7 +19,7 @@ interface CacheStorage {
   constructor(CacheStorageNamespace namespace, Principal principal);
 
   [NewObject]
-  Promise<Response> match(RequestInfo request, optional CacheQueryOptions options = {});
+  Promise<Response> match(RequestInfo request, optional MultiCacheQueryOptions options = {});
   [NewObject]
   Promise<boolean> has(DOMString cacheName);
   [NewObject]
@@ -30,6 +30,10 @@ interface CacheStorage {
   Promise<sequence<DOMString>> keys();
 };
 
+dictionary MultiCacheQueryOptions : CacheQueryOptions {
+  DOMString cacheName;
+};
+
 // chrome-only, gecko specific extension
 enum CacheStorageNamespace {
   "content", "chrome"
diff --git a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-match.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-match.https.html.ini
index 9e7414d3dd031..3c80d41c5a7a5 100644
--- a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-match.https.html.ini
+++ b/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-match.https.html.ini
@@ -1,7 +1,4 @@
 [cache-match.https.html]
-  [Cache.match does not support cacheName option]
-    expected: FAIL
-
   [MIME type should be frozen at response construction.]
     expected: FAIL
 
diff --git a/testing/web-platform/meta/service-workers/cache-storage/window/cache-match.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/window/cache-match.https.html.ini
index 9e7414d3dd031..3c80d41c5a7a5 100644
--- a/testing/web-platform/meta/service-workers/cache-storage/window/cache-match.https.html.ini
+++ b/testing/web-platform/meta/service-workers/cache-storage/window/cache-match.https.html.ini
@@ -1,7 +1,4 @@
 [cache-match.https.html]
-  [Cache.match does not support cacheName option]
-    expected: FAIL
-
   [MIME type should be frozen at response construction.]
     expected: FAIL
 
diff --git a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-match.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/worker/cache-match.https.html.ini
index 9e7414d3dd031..3c80d41c5a7a5 100644
--- a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-match.https.html.ini
+++ b/testing/web-platform/meta/service-workers/cache-storage/worker/cache-match.https.html.ini
@@ -1,7 +1,4 @@
 [cache-match.https.html]
-  [Cache.match does not support cacheName option]
-    expected: FAIL
-
   [MIME type should be frozen at response construction.]
     expected: FAIL
 
-- 
GitLab