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

Unified Diff: third_party/WebKit/LayoutTests/external/wpt/html/editing/dnd/datastore/datatransfer-types.html

Issue 2875013002: DataTransfer: Make |types| be a FrozenArray<DOMString>. (Closed)
Patch Set: Add new test, use CachedAttribute Created 3 years, 7 months 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/external/wpt/html/editing/dnd/datastore/datatransfer-types.html
diff --git a/third_party/WebKit/LayoutTests/external/wpt/html/editing/dnd/datastore/datatransfer-types.html b/third_party/WebKit/LayoutTests/external/wpt/html/editing/dnd/datastore/datatransfer-types.html
new file mode 100644
index 0000000000000000000000000000000000000000..e235516e13f77926d2ea3383a9c1366cc151c070
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/html/editing/dnd/datastore/datatransfer-types.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>DataTransfer types attribute test</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
jsbell 2017/05/12 17:07:35 A spec link is nice to have (but not strictly requ
+<script>
+test(() => {
+ let dt = new DataTransfer();
jsbell 2017/05/12 17:07:35 nit: could be const (here and below)
+ assert_true(Object.isFrozen(dt.types), "types must be a FrozenArray<>");
jsbell 2017/05/12 17:07:35 Do we want to assert_true(Array.isArray(dt.types))
+ assert_equals(dt.types.length, 0, "types must be originally empty");
+ assert_equals(dt.types, dt.types,
+ "types must return the same object when the data store item list has not changed");
+
+ let dt2 = new DataTransfer();
+ assert_not_equals(dt2.types, dt.types,
+ "Different DataTransfer objects must return different FrozenArrays");
+}, "type's state on DataTransfer creation");
+
+test(() => {
+ let dt = new DataTransfer();
+ dt.setData("text/plain", "foo");
+
+ let old_types = dt.types;
+ assert_equals(old_types, dt.types);
+
+ // Replacing the text/plain item causes the underlying data store item list
+ // to change, so types will return a new FrozenArray.
+ dt.setData("text/plain", "bar");
+ assert_equals(dt.types.length, 1);
+ assert_not_equals(old_types, dt.types);
+ old_types = dt.types;
+
+ // Adding a new item causes the underlying data store item list to change, so
+ // types will return a new FrozenArray.
+ dt.setData("text/uri-list", "baz quux");
+ assert_equals(dt.types.length, 2);
+ assert_not_equals(old_types, dt.types);
+
+ // Removing the text/uri-list item causes the underlying data store item list
+ // to change, so even though the item list only has a text/plain item, types
+ // will return a new FrozenArray that does not match |old_types|.
+ dt.clearData("text/uri-list");
+ assert_equals(dt.types.length, 1);
+ assert_not_equals(old_types, dt.types);
+ old_types = dt.types;
+
+ // This clearData() call did not change the underlying item list, so types is
+ // still the same as |old_types|.
+ dt.clearData("text/uri-list");
+ assert_equals(dt.types.length, 1);
+ assert_equals(old_types, dt.types);
+
+ dt.clearData();
+ old_types = dt.types;
+
+ // Clearing an already empty list does not change the underlying item list,
+ // so types is stil the same as |old_types|.
+ dt.clearData();
+ assert_equals(old_types, dt.types);
+}, "type's identity");
+
+test(() => {
+ let dt = new DataTransfer();
+ let types = dt.types;
+ dt.types = 42;
+ assert_equals(dt.types, types);
+}, "Verify type is a read-only attribute");
+</script>

Powered by Google App Engine
This is Rietveld 408576698