Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Unified Diff: third_party/WebKit/LayoutTests/imported/wpt/clear-site-data/support/test_utils.js

Issue 2572333003: Import wpt@4970d7334aaf8977c5b617075aa48be1b6e482c7 (Closed)
Patch Set: Update TestExpectations Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+})();

Powered by Google App Engine
This is Rietveld 408576698