Cache Storage: Fix null deref with explicit undefined passed

Given the IDL definition of two methods with args of the form
(optional request, optional options), the bindings code expects two
overloads in the implementation. The bindings code maps calls to the
overloads differently if an explicit undefined is passed for request
with no options vs. an explicit undefined is passed with an options
arg, and the code wasn't expecting
the request to be null.

Bug: 1232955
Change-Id: I2ea29151dfaf4e764f221200ef4acb4784334a34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3059555
Auto-Submit: Joshua Bell <jsbell@chromium.org>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Reviewed-by: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906793}
diff --git a/service-workers/cache-storage/script-tests/cache-keys.js b/service-workers/cache-storage/script-tests/cache-keys.js
index a94c18f..94b34d1 100644
--- a/service-workers/cache-storage/script-tests/cache-keys.js
+++ b/service-workers/cache-storage/script-tests/cache-keys.js
@@ -161,24 +161,30 @@
       .then(function(result) {
           assert_request_array_equals(
             result,
-            [
-              entries.a.request,
-              entries.b.request,
-              entries.a_with_query.request,
-              entries.A.request,
-              entries.a_https.request,
-              entries.a_org.request,
-              entries.cat.request,
-              entries.catmandu.request,
-              entries.cat_num_lives.request,
-              entries.cat_in_the_hat.request,
-              entries.non_2xx_response.request,
-              entries.error_response.request
-            ],
+            simple_entries.map(entry => entry.request),
             'Cache.keys without parameters should match all entries.');
         });
   }, 'Cache.keys without parameters');
 
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+    return cache.keys(undefined)
+      .then(function(result) {
+          assert_request_array_equals(
+            result,
+            simple_entries.map(entry => entry.request),
+            'Cache.keys with undefined request should match all entries.');
+        });
+  }, 'Cache.keys with explicitly undefined request');
+
+cache_test(cache => {
+    return cache.keys(undefined, {})
+      .then(requests => {
+          assert_equals(
+            requests.length, 0,
+            'Cache.keys should resolve to an empty array for an empty cache');
+        });
+  }, 'Cache.keys with explicitly undefined request and empty options');
+
 prepopulated_cache_test(vary_entries, function(cache, entries) {
     return cache.keys()
       .then(function(result) {
diff --git a/service-workers/cache-storage/script-tests/cache-matchAll.js b/service-workers/cache-storage/script-tests/cache-matchAll.js
index b7c7bd6..438ddeb 100644
--- a/service-workers/cache-storage/script-tests/cache-matchAll.js
+++ b/service-workers/cache-storage/script-tests/cache-matchAll.js
@@ -158,24 +158,31 @@
       .then(function(result) {
           assert_response_array_equals(
             result,
-            [
-              entries.a.response,
-              entries.b.response,
-              entries.a_with_query.response,
-              entries.A.response,
-              entries.a_https.response,
-              entries.a_org.response,
-              entries.cat.response,
-              entries.catmandu.response,
-              entries.cat_num_lives.response,
-              entries.cat_in_the_hat.response,
-              entries.non_2xx_response.response,
-              entries.error_response.response
-            ],
+            simple_entries.map(entry => entry.response),
             'Cache.matchAll without parameters should match all entries.');
         });
   }, 'Cache.matchAll without parameters');
 
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+    return cache.matchAll(undefined)
+      .then(result => {
+          assert_response_array_equals(
+            result,
+            simple_entries.map(entry => entry.response),
+            'Cache.matchAll with undefined request should match all entries.');
+        });
+  }, 'Cache.matchAll with explicitly undefined request');
+
+prepopulated_cache_test(simple_entries, function(cache, entries) {
+  return cache.matchAll(undefined, {})
+      .then(result => {
+          assert_response_array_equals(
+            result,
+            simple_entries.map(entry => entry.response),
+            'Cache.matchAll with undefined request should match all entries.');
+        });
+  }, 'Cache.matchAll with explicitly undefined request and empty options');
+
 prepopulated_cache_test(vary_entries, function(cache, entries) {
     return cache.matchAll('http://example.com/c')
       .then(function(result) {