Index: third_party/WebKit/LayoutTests/external/wpt/clear-site-data/support/test_utils.js |
diff --git a/third_party/WebKit/LayoutTests/external/wpt/clear-site-data/support/test_utils.js b/third_party/WebKit/LayoutTests/external/wpt/clear-site-data/support/test_utils.js |
index 6aff373f23a46d1887689618104c86c144cef108..ff19b17d0f30c89c6b58ae6c0318f0e6e8ed94c7 100644 |
--- a/third_party/WebKit/LayoutTests/external/wpt/clear-site-data/support/test_utils.js |
+++ b/third_party/WebKit/LayoutTests/external/wpt/clear-site-data/support/test_utils.js |
@@ -6,6 +6,9 @@ var TestUtils = (function() { |
return result; |
}; |
+ /** @string The base URL this test. */ |
+ var base_url = location.origin + "/clear-site-data/"; |
Mike West
2017/05/30 07:45:17
Can you add cross-origin tests as well, since I th
msramek
2017/05/30 09:11:12
Of course, but I'd like to do that in a separate C
Mike West
2017/05/30 11:01:30
Sure. Happy to see more CLs. :)
|
+ |
/** |
* Representation of one datatype. |
* @typedef Datatype |
@@ -51,7 +54,36 @@ var TestUtils = (function() { |
resolve(!localStorage.length); |
}); |
} |
- } |
+ }, |
+ { |
+ "name": "cache", |
+ "add": function() { |
+ // Request a resource from the get_resource_to_cache.py server. |
+ // The server is instructed to return a high "CacheControl: max-age" |
Mike West
2017/05/30 07:45:17
Nit: `cache-control`
msramek
2017/05/30 09:11:12
Done. Also capitalized it here and elsewhere for c
|
+ // header value, to ensure that this resource will really be added |
+ // to the cache. |
+ return fetch(base_url + "support/get-resource-to-cache.py"); |
+ }, |
+ "isEmpty": function() { |
+ return new Promise(function(resolve, reject) { |
+ // Request the resource with the "Cache-Control: only-if-cached" |
+ // header. If the request suceeds, the resource must have been found |
+ // in the cache. Since not all user agents support this header value, |
+ // the get-resource-to-cache.py server is instructed to respond with |
+ // status code 500 if it sees such a request. |
+ var fetch_options = { |
+ "headers": new Headers({ "cache-control": "only-if-cached" }), |
+ }; |
+ |
+ fetch(base_url + "support/get-resource-to-cache.py", fetch_options) |
+ .then(function(response) { |
+ resolve(response.status == 500 /* Internal server error. */); |
+ }).catch(function() { |
+ resolve(true); |
Mike West
2017/05/30 07:45:17
Why would you resolve with `true` if the fetch fai
msramek
2017/05/30 09:11:12
If the fetch fails, it means that we're dealing wi
Mike West
2017/05/30 11:01:31
Ah. I see. A comment to that effect might be helpf
|
+ }); |
+ }); |
+ } |
+ }, |
]; |
/** |
@@ -82,7 +114,7 @@ var TestUtils = (function() { |
*/ |
TestUtils.getClearSiteDataUrl = function(datatypes) { |
names = datatypes.map(function(e) { return e.name }); |
- return "support/echo-clear-site-data.py?" + names.join("&"); |
+ return base_url + "support/echo-clear-site-data.py?" + names.join("&"); |
} |
return TestUtils; |