| 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..0948ab5e21d75eee5ec0b689399e05f4f997bada 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,12 @@ var TestUtils = (function() {
|
| return result;
|
| };
|
|
|
| + /** @string The base URL this test. */
|
| + var base_url = location.origin + "/clear-site-data/";
|
| +
|
| + /** @string Name of the resource to be tested for cache emptiness. */
|
| + var cached_resource_name;
|
| +
|
| /**
|
| * Representation of one datatype.
|
| * @typedef Datatype
|
| @@ -19,6 +25,19 @@ var TestUtils = (function() {
|
|
|
| var TestUtils = {};
|
|
|
| + /**
|
| + * Sets the name of the resource used to test cache emptiness.
|
| + * @param{string} name Name of the resource.
|
| + */
|
| + TestUtils.setCachedResourceName = function(name) {
|
| + cached_resource_name = name;
|
| + };
|
| +
|
| + /** Randomly changes the name of the resource used to test cache emptiness. */
|
| + TestUtils.bustCache = function() {
|
| + TestUtils.setCachedResourceName(randomString());
|
| + };
|
| +
|
| /**
|
| * All datatypes supported by Clear-Site-Data.
|
| * @param{Array.<Datatype>}
|
| @@ -51,7 +70,39 @@ 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 "Cache-Control: max-age"
|
| + // header value, to ensure that this resource will really be added
|
| + // to the cache.
|
| + return fetch(base_url + "support/get-resource-to-cache.py?" +
|
| + cached_resource_name);
|
| + },
|
| + "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?" +
|
| + cached_resource_name,
|
| + fetch_options)
|
| + .then(function(response) {
|
| + resolve(response.status == 500 /* Internal server error. */);
|
| + }).catch(function() {
|
| + resolve(true);
|
| + });
|
| + });
|
| + }
|
| + },
|
| ];
|
|
|
| /**
|
| @@ -82,7 +133,8 @@ 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?cached_resource_name=" +
|
| + cached_resource_name + "&" + names.join("&");
|
| }
|
|
|
| return TestUtils;
|
|
|