Skip to content
Permalink
Browse files
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:

Canonical link: https://commits.webkit.org/194498@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223284 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
youennf authored and webkit-commit-queue committed Oct 13, 2017
1 parent 96825b4 commit 34b19f064a8764149b5870092e26786c9071124a
Showing 3 changed files with 38 additions and 91 deletions.
@@ -1,3 +1,16 @@
2017-10-13 Youenn Fablet <youenn@apple.com>

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 <wenson_hsieh@apple.com>

"text/html" data is not exposed when dragging and dropping across origins
@@ -16,53 +16,20 @@
});
}, "Cleaning existing caches");

function waitFor(delay)
{
return new Promise(resolve => {
setTimeout(resolve, delay);
});
}

async function validateCachesEmptyness(expected, counter)
{
var keys = await self.caches.keys();
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" }));

var isEmpty = keys.length === 0;
if (isEmpty === expected)
return true;
if (!window.testRunner)
return Promise.reject("test runner needed");
testRunner.clearDOMCache();

if (counter > 10)
return false;

await waitFor(100);
if (!counter)
counter = 0;
return validateCachesEmptyness(expected, ++counter);
}
var keys = await self.caches.keys();
assert_equals(keys.length, 0, "keys should be empty");

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>
@@ -16,57 +16,24 @@
});
}, "Cleaning existing caches");

function waitFor(delay)
{
return new Promise(resolve => {
setTimeout(resolve, delay);
});
}

async function validateCachesEmptyness(expected, counter)
{
var keys = await self.caches.keys();
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" }));

var isEmpty = keys.length === 0;
if (isEmpty === expected)
return true;
if (!window.testRunner)
return Promise.reject("test runner needed");
testRunner.clearDOMCache('https://localhost:80');

if (counter > 10)
return false;
var keys = await self.caches.keys();
assert_not_equals(keys.length, 0, "keys should not be empty");

await waitFor(100);
if (!counter)
counter = 0;
return validateCachesEmptyness(expected, ++counter);
}
testRunner.clearDOMCache(window.location.origin);
keys = await self.caches.keys();
assert_equals(keys.length, 0, "keys should be empty");

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>

0 comments on commit 34b19f0

Please sign in to comment.