Index: third_party/WebKit/LayoutTests/imported/wpt/clear-site-data/support/test_utils.js |
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/clear-site-data/support/test_utils.js b/third_party/WebKit/LayoutTests/imported/wpt/clear-site-data/support/test_utils.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6aff373f23a46d1887689618104c86c144cef108 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/imported/wpt/clear-site-data/support/test_utils.js |
@@ -0,0 +1,89 @@ |
+var TestUtils = (function() { |
+ function randomString() { |
+ var result = ""; |
+ for (var i = 0; i < 5; i++) |
+ result += String.fromCharCode(97 + Math.floor(Math.random() * 26)); |
+ return result; |
+ }; |
+ |
+ /** |
+ * Representation of one datatype. |
+ * @typedef Datatype |
+ * @type{object} |
+ * @property{string} name Name of the datatype. |
+ * @method{function():Void} add A function to add an instance of the datatype. |
+ * @method{function():boolean} isEmpty A function that tests whether |
+ * the datatype's storage backend is empty. |
+ */ |
+ var Datatype; |
+ |
+ var TestUtils = {}; |
+ |
+ /** |
+ * All datatypes supported by Clear-Site-Data. |
+ * @param{Array.<Datatype>} |
+ */ |
+ TestUtils.DATATYPES = [ |
+ { |
+ "name": "cookies", |
+ "add": function() { |
+ return new Promise(function(resolve, reject) { |
+ document.cookie = randomString() + "=" + randomString(); |
+ resolve(); |
+ }); |
+ }, |
+ "isEmpty": function() { |
+ return new Promise(function(resolve, reject) { |
+ resolve(!document.cookie); |
+ }); |
+ } |
+ }, |
+ { |
+ "name": "storage", |
+ "add": function() { |
+ return new Promise(function(resolve, reject) { |
+ localStorage.setItem(randomString(), randomString()); |
+ resolve(); |
+ }); |
+ }, |
+ "isEmpty": function() { |
+ return new Promise(function(resolve, reject) { |
+ resolve(!localStorage.length); |
+ }); |
+ } |
+ } |
+ ]; |
+ |
+ /** |
+ * All possible combinations of datatypes. |
+ * @property {Array.<Array.<Datatype>>} |
+ */ |
+ TestUtils.COMBINATIONS = (function() { |
+ var combinations = []; |
+ for (var mask = 0; mask < (1 << TestUtils.DATATYPES.length); mask++) { |
+ var combination = []; |
+ |
+ for (var datatype = 0; |
+ datatype < TestUtils.DATATYPES.length; datatype++) { |
+ if (mask & (1 << datatype)) |
+ combination.push(TestUtils.DATATYPES[datatype]); |
+ } |
+ |
+ combinations.push(combination); |
+ } |
+ return combinations; |
+ })(); |
+ |
+ /** |
+ * Get the support server URL that returns a Clear-Site-Data header |
+ * to clear |datatypes|. |
+ * @param{Array.<Datatype>} datatypes The list of datatypes to be deleted. |
+ * @return string The URL to be queried. |
+ */ |
+ TestUtils.getClearSiteDataUrl = function(datatypes) { |
+ names = datatypes.map(function(e) { return e.name }); |
+ return "support/echo-clear-site-data.py?" + names.join("&"); |
+ } |
+ |
+ return TestUtils; |
+})(); |