summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-storage-keys.js
blob: 4d7bc623f00dba0c46cb3f43d8305fb7636e9930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
if (self.importScripts) {
    importScripts('/resources/testharness.js');
    importScripts('../resources/testharness-helpers.js');
    importScripts('../resources/test-helpers.js');
}

var test_cache_list =
  ['', 'example', 'Another cache name', 'A', 'a', 'ex ample'];

promise_test(function(test) {
    return self.caches.keys()
      .then(function(keys) {
          assert_true(Array.isArray(keys),
                      'CacheStorage.keys should return an Array.');
          return Promise.all(keys.map(function(key) {
              return self.caches.delete(key);
            }));
        })
      .then(function() {
          return Promise.all(test_cache_list.map(function(key) {
              return self.caches.open(key);
            }));
        })

      .then(function() { return self.caches.keys(); })
      .then(function(keys) {
          assert_true(Array.isArray(keys),
                      'CacheStorage.keys should return an Array.');
          assert_array_equals(keys,
                              test_cache_list,
                              'CacheStorage.keys should only return ' +
                              'existing caches.');
        });
  }, 'CacheStorage keys');

done();