Changeset 223284 in webkit


Ignore:
Timestamp:
Oct 13, 2017 10:19:06 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Modernize LayoutTests/http/tests/cache-storage/cache-clearing-*.https.html
https://bugs.webkit.org/show_bug.cgi?id=178245

Patch by Youenn Fablet <youenn@apple.com> on 2017-10-13
Reviewed by Chris Dumez.

Using await/async to improve the testing.
Taking benefit of clearDOMCache to wait for completion to simplify both tests as well.

  • http/tests/cache-storage/cache-clearing-all.https.html:
  • http/tests/cache-storage/cache-clearing-origin.https.html:
Location:
trunk/LayoutTests
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r223278 r223284  
     12017-10-13  Youenn Fablet  <youenn@apple.com>
     2
     3        Modernize LayoutTests/http/tests/cache-storage/cache-clearing-*.https.html
     4        https://bugs.webkit.org/show_bug.cgi?id=178245
     5
     6        Reviewed by Chris Dumez.
     7
     8        Using await/async to improve the testing.
     9        Taking benefit of clearDOMCache to wait for completion to simplify both tests as well.
     10
     11        * http/tests/cache-storage/cache-clearing-all.https.html:
     12        * http/tests/cache-storage/cache-clearing-origin.https.html:
     13
    1142017-10-13  Wenson Hsieh  <wenson_hsieh@apple.com>
    215
  • trunk/LayoutTests/http/tests/cache-storage/cache-clearing-all.https.html

    r223265 r223284  
    1717}, "Cleaning existing caches");
    1818
    19 function waitFor(delay)
    20 {
    21     return new Promise(resolve => {
    22         setTimeout(resolve, delay);
    23     });
    24 }
     19promise_test(async (test) => {
     20    var cache = await self.caches.open("test-cache-records-persistency");
     21    await cache.put("https://example.com/foo", new Response("body", { statusText: "status" }));
    2522
    26 async function validateCachesEmptyness(expected, counter)
    27 {
     23    if (!window.testRunner)
     24        return Promise.reject("test runner needed");
     25    testRunner.clearDOMCache();
     26
    2827    var keys = await self.caches.keys();
     28    assert_equals(keys.length, 0, "keys should be empty");
    2929
    30     var isEmpty = keys.length === 0;
    31     if (isEmpty === expected)
    32         return true;
    33 
    34     if (counter > 10)
    35         return false;
    36 
    37     await waitFor(100);
    38     if (!counter)
    39         counter = 0;
    40     return validateCachesEmptyness(expected, ++counter);
    41 }
    42 
    43 promise_test(() => {
    44     var test_url = 'https://example.com/foo';
    45     var cache;
    46     var cache_keys;
    47     var first_response = new Response("Old body", { statusText: 'Old status' });
    48     var alternate_response = new Response("New body", { statusText: 'New status' });
    49     return self.caches.open("test-cache-records-persistency").then(c => {
    50         cache = c;
    51     }).then(() => {
    52         return cache.put(test_url, first_response);
    53     }).then(() => {
    54         if (!window.testRunner)
    55             return Promise.reject("test runner needed");
    56         testRunner.clearDOMCache();
    57         return validateCachesEmptyness(true);
    58     }).then(result => {
    59         assert_true(result, "caches should be empty");
    60         return self.caches.open("test-cache-records-persistency");
    61     }).then(cache => {
    62         return cache.keys();
    63     }).then(keys => {
    64         assert_equals(keys.length, 0, "records should be empty");
    65     });
     30    cache = await self.caches.open("test-cache-records-persistency");
     31    keys = await cache.keys();
     32    assert_equals(keys.length, 0, "records should be empty");
    6633}, 'Clearing all disk cache');
    6734    </script>
  • trunk/LayoutTests/http/tests/cache-storage/cache-clearing-origin.https.html

    r223265 r223284  
    1717}, "Cleaning existing caches");
    1818
    19 function waitFor(delay)
    20 {
    21     return new Promise(resolve => {
    22         setTimeout(resolve, delay);
    23     });
    24 }
     19promise_test(async test => {
     20    var cache = await self.caches.open("test-cache-records-persistency");
     21    await cache.put("https://example.com/foo", new Response("body", { statusText: "status" }));
    2522
    26 async function validateCachesEmptyness(expected, counter)
    27 {
     23    if (!window.testRunner)
     24        return Promise.reject("test runner needed");
     25    testRunner.clearDOMCache('https://localhost:80');
     26
    2827    var keys = await self.caches.keys();
     28    assert_not_equals(keys.length, 0, "keys should not be empty");
    2929
    30     var isEmpty = keys.length === 0;
    31     if (isEmpty === expected)
    32         return true;
     30    testRunner.clearDOMCache(window.location.origin);
     31    keys = await self.caches.keys();
     32    assert_equals(keys.length, 0, "keys should be empty");
    3333
    34     if (counter > 10)
    35         return false;
    36 
    37     await waitFor(100);
    38     if (!counter)
    39         counter = 0;
    40     return validateCachesEmptyness(expected, ++counter);
    41 }
    42 
    43 promise_test(() => {
    44     var test_url = 'https://example.com/foo';
    45     var cache;
    46     var cache_keys;
    47     var first_response = new Response("Old body", { statusText: 'Old status' });
    48     var alternate_response = new Response("New body", { statusText: 'New status' });
    49     return self.caches.open("test-cache-records-persistency").then(c => {
    50         cache = c;
    51     }).then(() => {
    52         return cache.put(test_url, first_response);
    53     }).then(() => {
    54         if (!window.testRunner)
    55             return Promise.reject("test runner needed");
    56         testRunner.clearDOMCache('https://localhost:80');
    57         return validateCachesEmptyness(false);
    58     }).then(result => {
    59         assert_true(result, "caches should not be empty");
    60         testRunner.clearDOMCache(window.location.origin);
    61         return validateCachesEmptyness(true);
    62     }).then(result => {
    63         assert_true(result, "caches should be empty");
    64         return self.caches.open("test-cache-records-persistency");
    65     }).then(cache => {
    66         return cache.keys();
    67     }).then(keys => {
    68         assert_equals(keys.length, 0, "records should be empty");
    69     });
     34    cache = await self.caches.open("test-cache-records-persistency");
     35    keys = await cache.keys();
     36    assert_equals(keys.length, 0, "records should be empty");
    7037}, 'Clearing disk cache of a given origin');
    7138    </script>
Note: See TracChangeset for help on using the changeset viewer.