Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 var TestUtils = (function() { | 1 var TestUtils = (function() { |
| 2 function randomString() { | 2 function randomString() { |
| 3 var result = ""; | 3 var result = ""; |
| 4 for (var i = 0; i < 5; i++) | 4 for (var i = 0; i < 5; i++) |
| 5 result += String.fromCharCode(97 + Math.floor(Math.random() * 26)); | 5 result += String.fromCharCode(97 + Math.floor(Math.random() * 26)); |
| 6 return result; | 6 return result; |
| 7 }; | 7 }; |
| 8 | 8 |
| 9 /** @string The base URL this test. */ | |
| 10 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. :)
| |
| 11 | |
| 9 /** | 12 /** |
| 10 * Representation of one datatype. | 13 * Representation of one datatype. |
| 11 * @typedef Datatype | 14 * @typedef Datatype |
| 12 * @type{object} | 15 * @type{object} |
| 13 * @property{string} name Name of the datatype. | 16 * @property{string} name Name of the datatype. |
| 14 * @method{function():Void} add A function to add an instance of the datatype. | 17 * @method{function():Void} add A function to add an instance of the datatype. |
| 15 * @method{function():boolean} isEmpty A function that tests whether | 18 * @method{function():boolean} isEmpty A function that tests whether |
| 16 * the datatype's storage backend is empty. | 19 * the datatype's storage backend is empty. |
| 17 */ | 20 */ |
| 18 var Datatype; | 21 var Datatype; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 44 return new Promise(function(resolve, reject) { | 47 return new Promise(function(resolve, reject) { |
| 45 localStorage.setItem(randomString(), randomString()); | 48 localStorage.setItem(randomString(), randomString()); |
| 46 resolve(); | 49 resolve(); |
| 47 }); | 50 }); |
| 48 }, | 51 }, |
| 49 "isEmpty": function() { | 52 "isEmpty": function() { |
| 50 return new Promise(function(resolve, reject) { | 53 return new Promise(function(resolve, reject) { |
| 51 resolve(!localStorage.length); | 54 resolve(!localStorage.length); |
| 52 }); | 55 }); |
| 53 } | 56 } |
| 54 } | 57 }, |
| 58 { | |
| 59 "name": "cache", | |
| 60 "add": function() { | |
| 61 // Request a resource from the get_resource_to_cache.py server. | |
| 62 // 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
| |
| 63 // header value, to ensure that this resource will really be added | |
| 64 // to the cache. | |
| 65 return fetch(base_url + "support/get-resource-to-cache.py"); | |
| 66 }, | |
| 67 "isEmpty": function() { | |
| 68 return new Promise(function(resolve, reject) { | |
| 69 // Request the resource with the "Cache-Control: only-if-cached" | |
| 70 // header. If the request suceeds, the resource must have been found | |
| 71 // in the cache. Since not all user agents support this header value, | |
| 72 // the get-resource-to-cache.py server is instructed to respond with | |
| 73 // status code 500 if it sees such a request. | |
| 74 var fetch_options = { | |
| 75 "headers": new Headers({ "cache-control": "only-if-cached" }), | |
| 76 }; | |
| 77 | |
| 78 fetch(base_url + "support/get-resource-to-cache.py", fetch_options) | |
| 79 .then(function(response) { | |
| 80 resolve(response.status == 500 /* Internal server error. */); | |
| 81 }).catch(function() { | |
| 82 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
| |
| 83 }); | |
| 84 }); | |
| 85 } | |
| 86 }, | |
| 55 ]; | 87 ]; |
| 56 | 88 |
| 57 /** | 89 /** |
| 58 * All possible combinations of datatypes. | 90 * All possible combinations of datatypes. |
| 59 * @property {Array.<Array.<Datatype>>} | 91 * @property {Array.<Array.<Datatype>>} |
| 60 */ | 92 */ |
| 61 TestUtils.COMBINATIONS = (function() { | 93 TestUtils.COMBINATIONS = (function() { |
| 62 var combinations = []; | 94 var combinations = []; |
| 63 for (var mask = 0; mask < (1 << TestUtils.DATATYPES.length); mask++) { | 95 for (var mask = 0; mask < (1 << TestUtils.DATATYPES.length); mask++) { |
| 64 var combination = []; | 96 var combination = []; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 75 })(); | 107 })(); |
| 76 | 108 |
| 77 /** | 109 /** |
| 78 * Get the support server URL that returns a Clear-Site-Data header | 110 * Get the support server URL that returns a Clear-Site-Data header |
| 79 * to clear |datatypes|. | 111 * to clear |datatypes|. |
| 80 * @param{Array.<Datatype>} datatypes The list of datatypes to be deleted. | 112 * @param{Array.<Datatype>} datatypes The list of datatypes to be deleted. |
| 81 * @return string The URL to be queried. | 113 * @return string The URL to be queried. |
| 82 */ | 114 */ |
| 83 TestUtils.getClearSiteDataUrl = function(datatypes) { | 115 TestUtils.getClearSiteDataUrl = function(datatypes) { |
| 84 names = datatypes.map(function(e) { return e.name }); | 116 names = datatypes.map(function(e) { return e.name }); |
| 85 return "support/echo-clear-site-data.py?" + names.join("&"); | 117 return base_url + "support/echo-clear-site-data.py?" + names.join("&"); |
| 86 } | 118 } |
| 87 | 119 |
| 88 return TestUtils; | 120 return TestUtils; |
| 89 })(); | 121 })(); |
| OLD | NEW |