Chromium Code Reviews| 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..235f8907cdcf96617b1501731be65beb50c19722 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/external/wpt/html/editing/dnd/datastore/datatransfer-types.html |
| @@ -0,0 +1,70 @@ |
| +<!DOCTYPE html> |
| +<meta charset="utf-8"> |
| +<title>DataTransfer types attribute test</title> |
| +<link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#the-datatransfer-interface"> |
| +<script src="/resources/testharness.js"></script> |
| +<script src="/resources/testharnessreport.js"></script> |
| +<script> |
| +test(() => { |
| + const dt = new DataTransfer(); |
| + assert_true(Object.isFrozen(dt.types), "types must be a FrozenArray<>"); |
| + assert_true(Array.isArray(dt.types), "A FrozenArray<> must be an Array"); |
| + 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"); |
| + |
| + const dt2 = new DataTransfer(); |
| + assert_not_equals(dt2.types, dt.types, |
| + "Different DataTransfer objects must return different FrozenArrays"); |
| +}, "type's state on DataTransfer creation"); |
| + |
| +test(() => { |
| + const 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"); |
|
foolip
2017/05/15 15:11:02
Good test!
|
| + |
| +test(() => { |
| + const dt = new DataTransfer(); |
| + const types = dt.types; |
| + dt.types = 42; |
| + assert_equals(dt.types, types); |
| +}, "Verify type is a read-only attribute"); |
| +</script> |