Title: [223284] trunk/LayoutTests
Revision
223284
Author
[email protected]
Date
2017-10-13 10:19:06 -0700 (Fri, 13 Oct 2017)

Log Message

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

Patch by Youenn Fablet <[email protected]> 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:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (223283 => 223284)


--- trunk/LayoutTests/ChangeLog	2017-10-13 17:14:22 UTC (rev 223283)
+++ trunk/LayoutTests/ChangeLog	2017-10-13 17:19:06 UTC (rev 223284)
@@ -1,3 +1,16 @@
+2017-10-13  Youenn Fablet  <[email protected]>
+
+        Modernize LayoutTests/http/tests/cache-storage/cache-clearing-*.https.html
+        https://bugs.webkit.org/show_bug.cgi?id=178245
+
+        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:
+
 2017-10-13  Wenson Hsieh  <[email protected]>
 
         "text/html" data is not exposed when dragging and dropping across origins

Modified: trunk/LayoutTests/http/tests/cache-storage/cache-clearing-all.https.html (223283 => 223284)


--- trunk/LayoutTests/http/tests/cache-storage/cache-clearing-all.https.html	2017-10-13 17:14:22 UTC (rev 223283)
+++ trunk/LayoutTests/http/tests/cache-storage/cache-clearing-all.https.html	2017-10-13 17:19:06 UTC (rev 223284)
@@ -16,53 +16,20 @@
     });
 }, "Cleaning existing caches");
 
-function waitFor(delay)
-{
-    return new Promise(resolve => {
-        setTimeout(resolve, delay);
-    });
-}
+promise_test(async (test) => {
+    var cache = await self.caches.open("test-cache-records-persistency");
+    await cache.put("https://example.com/foo", new Response("body", { statusText: "status" }));
 
-async function validateCachesEmptyness(expected, counter)
-{
+    if (!window.testRunner)
+        return Promise.reject("test runner needed");
+    testRunner.clearDOMCache();
+
     var keys = await self.caches.keys();
+    assert_equals(keys.length, 0, "keys should be empty");
 
-    var isEmpty = keys.length === 0;
-    if (isEmpty === expected)
-        return true;
-
-    if (counter > 10)
-        return false;
-
-    await waitFor(100);
-    if (!counter)
-        counter = 0;
-    return validateCachesEmptyness(expected, ++counter);
-}
-
-promise_test(() => {
-    var test_url = 'https://example.com/foo';
-    var cache;
-    var cache_keys;
-    var first_response = new Response("Old body", { statusText: 'Old status' });
-    var alternate_response = new Response("New body", { statusText: 'New status' });
-    return self.caches.open("test-cache-records-persistency").then(c => {
-        cache = c;
-    }).then(() => {
-        return cache.put(test_url, first_response);
-    }).then(() => {
-        if (!window.testRunner)
-            return Promise.reject("test runner needed");
-        testRunner.clearDOMCache();
-        return validateCachesEmptyness(true);
-    }).then(result => {
-        assert_true(result, "caches should be empty");
-        return self.caches.open("test-cache-records-persistency");
-    }).then(cache => {
-        return cache.keys();
-    }).then(keys => {
-        assert_equals(keys.length, 0, "records should be empty");
-    });
+    cache = await self.caches.open("test-cache-records-persistency");
+    keys = await cache.keys();
+    assert_equals(keys.length, 0, "records should be empty");
 }, 'Clearing all disk cache');
     </script>
 </body>

Modified: trunk/LayoutTests/http/tests/cache-storage/cache-clearing-origin.https.html (223283 => 223284)


--- trunk/LayoutTests/http/tests/cache-storage/cache-clearing-origin.https.html	2017-10-13 17:14:22 UTC (rev 223283)
+++ trunk/LayoutTests/http/tests/cache-storage/cache-clearing-origin.https.html	2017-10-13 17:19:06 UTC (rev 223284)
@@ -16,57 +16,24 @@
     });
 }, "Cleaning existing caches");
 
-function waitFor(delay)
-{
-    return new Promise(resolve => {
-        setTimeout(resolve, delay);
-    });
-}
+promise_test(async test => {
+    var cache = await self.caches.open("test-cache-records-persistency");
+    await cache.put("https://example.com/foo", new Response("body", { statusText: "status" }));
 
-async function validateCachesEmptyness(expected, counter)
-{
+    if (!window.testRunner)
+        return Promise.reject("test runner needed");
+    testRunner.clearDOMCache('https://localhost:80');
+
     var keys = await self.caches.keys();
+    assert_not_equals(keys.length, 0, "keys should not be empty");
 
-    var isEmpty = keys.length === 0;
-    if (isEmpty === expected)
-        return true;
+    testRunner.clearDOMCache(window.location.origin);
+    keys = await self.caches.keys();
+    assert_equals(keys.length, 0, "keys should be empty");
 
-    if (counter > 10)
-        return false;
-
-    await waitFor(100);
-    if (!counter)
-        counter = 0;
-    return validateCachesEmptyness(expected, ++counter);
-}
-
-promise_test(() => {
-    var test_url = 'https://example.com/foo';
-    var cache;
-    var cache_keys;
-    var first_response = new Response("Old body", { statusText: 'Old status' });
-    var alternate_response = new Response("New body", { statusText: 'New status' });
-    return self.caches.open("test-cache-records-persistency").then(c => {
-        cache = c;
-    }).then(() => {
-        return cache.put(test_url, first_response);
-    }).then(() => {
-        if (!window.testRunner)
-            return Promise.reject("test runner needed");
-        testRunner.clearDOMCache('https://localhost:80');
-        return validateCachesEmptyness(false);
-    }).then(result => {
-        assert_true(result, "caches should not be empty");
-        testRunner.clearDOMCache(window.location.origin);
-        return validateCachesEmptyness(true);
-    }).then(result => {
-        assert_true(result, "caches should be empty");
-        return self.caches.open("test-cache-records-persistency");
-    }).then(cache => {
-        return cache.keys();
-    }).then(keys => {
-        assert_equals(keys.length, 0, "records should be empty");
-    });
+    cache = await self.caches.open("test-cache-records-persistency");
+    keys = await cache.keys();
+    assert_equals(keys.length, 0, "records should be empty");
 }, 'Clearing disk cache of a given origin');
     </script>
 </body>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to