summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/cache-storage/cache-storage-keys.https.any.js
blob: f19522be1b437d619b356b5b0290679a8f391866 (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
// META: title=CacheStorage.keys
// META: global=window,worker
// META: script=./resources/test-helpers.js
// META: timeout=long

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();