Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/bindings/record-type.html |
| diff --git a/third_party/WebKit/LayoutTests/bindings/record-type.html b/third_party/WebKit/LayoutTests/bindings/record-type.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a7ec86daaafac2881361568786dbb2179439a126 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/bindings/record-type.html |
| @@ -0,0 +1,142 @@ |
| +<!DOCTYPE html> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script> |
| + /* assert_array_equals() uses same_value() to compare each item, but |
| + * Object.entries() returns an array of arrays, so we need to compare |
| + * each item with assert_array_equals instead. */ |
| + function assert_record_equals(obj, expected, description) { |
|
Yuki
2017/03/09 10:10:08
nit: s/obj/actual/
Raphael Kubo da Costa (rakuco)
2017/03/09 16:08:34
Done.
|
| + for (let i = 0; i < expected.length; ++i) { |
| + assert_array_equals(Object.entries(obj)[i], expected[i], description); |
| + } |
| + } |
| + |
| + test(() => { |
| + let recordTest = internals.recordTest(); |
| + |
| + assert_throws(new TypeError(), () => { |
| + recordTest.setStringLongRecord(null); |
| + }, "Converting null to record should be rejected."); |
| + assert_throws(new TypeError(), () => { |
| + recordTest.setStringLongRecord(undefined); |
| + }, "Converting undefined to record should be rejected."); |
| + recordTest.setNullableStringLongRecord(null); |
| + assert_equals(recordTest.getNullableStringLongRecord(), |
| + null, "Passing null to a nullable record works"); |
| + recordTest.setNullableStringLongRecord(undefined); |
| + assert_equals(recordTest.getNullableStringLongRecord(), |
| + null, "Passing undefined to a nullable record works"); |
| + }, "Test handling of null and undefined records"); |
| + |
| + test(() => { |
| + let recordTest = internals.recordTest(); |
| + |
| + recordTest.setStringLongRecord({a: true, false: null, c: "foo"}); |
| + assert_record_equals(recordTest.getStringLongRecord(), |
| + [['a', 1], ['false', 0], ['c', 0]], |
| + "Types are properly coerced to the record's types"); |
| + }, "Test type conversion"); |
| + |
| + test(() => { |
| + let recordTest = internals.recordTest(); |
| + |
| + recordTest.setStringLongRecord({false: 1, [false]: 42}); |
| + assert_record_equals(recordTest.getStringLongRecord(), [['false', 42]], |
| + "Key types are coerced and never repeated"); |
| + }, "Test duplicate keys"); |
| + |
| + test(() => { |
| + let recordTest = internals.recordTest(); |
| + |
| + recordTest.setStringLongRecord({z: 42, foo: -5, ABC: 0}); |
| + assert_record_equals(recordTest.getStringLongRecord(), |
| + [['z', 42], ['foo', -5], ['ABC', 0]], |
| + "Keys are not sorted"); |
| + }, "Test mapping order"); |
| + |
| + test(() => { |
| + let recordTest = internals.recordTest(); |
| + |
| + assert_throws(new TypeError(), () => { |
| + recordTest.setByteStringByteStringRecord({'a': 'bc', '\uFFFF': 'foo'}); |
| + }, "Invalid ByteString key must throw a TypeError"); |
| + assert_throws(new TypeError(), () => { |
| + recordTest.setByteStringByteStringRecord({'xy': 'z', 'foo': '\uFFFF'}); |
| + }, "Invalid ByteString value must throw a TypeError"); |
| + }, "Test ByteString validation"); |
| + |
| + test(() => { |
| + let recordTest = internals.recordTest(); |
| + |
| + recordTest.setStringLongRecord({'foo': 0}); |
| + let record = recordTest.getStringLongRecord(); |
| + assert_record_equals(record, [['foo', 0]]); |
| + |
| + record.baz = 'quux'; |
| + assert_equals(Object.keys(recordTest.getStringLongRecord()).length, 1, |
| + "Changing a returned record does not change the record"); |
| + assert_record_equals(recordTest.getStringLongRecord(), [['foo', 0]], |
| + "Changing a returned record does not change the record"); |
| + |
| + assert_record_equals(recordTest.getStringLongRecord(), |
| + Object.entries(recordTest.getStringLongRecord()), |
| + "Record getters always return the same elements"); |
| + assert_not_equals(recordTest.getStringLongRecord(), recordTest.getStringLongRecord(), |
| + "Record getters always return a new copy"); |
| + }, "Test records are passed by value"); |
| + |
| + test(() => { |
| + let recordTest = internals.recordTest(); |
| + |
| + assert_false(recordTest.unionReceivedARecord(true), |
| + "Passing 'true' should convert the union to boolean"); |
| + assert_false(recordTest.unionReceivedARecord(false), |
| + "Passing 'false' should convert the union to boolean"); |
| + assert_false(recordTest.unionReceivedARecord(42), |
| + "Passing a number should convert the union to boolean"); |
| + assert_true(recordTest.unionReceivedARecord([1, 2, 3]), |
| + "Passing an array should convert the union to a record"); |
| + assert_true(recordTest.unionReceivedARecord({}), |
| + "Passing an object should conver the union to a record"); |
| + }, "Test unions resolve records"); |
| + |
| + test(() => { |
| + let recordTest = internals.recordTest(); |
| + |
| + let elem = document.createElement('p'); |
| + recordTest.setStringElementRecord({'elem': elem}); |
| + assert_equals(recordTest.getStringElementRecord().elem, elem, |
| + "The same Oilpan-based value was stored in the record"); |
|
Yuki
2017/03/09 10:10:08
nit: s/Oilpan-based value/DOM object/
Raphael Kubo da Costa (rakuco)
2017/03/09 16:08:34
Done.
|
| + assert_not_equals(recordTest.getStringElementRecord().elem, |
| + document.createElement('p'), |
| + "The same Oilpan-based value was stored in the record"); |
| + |
| + elem = document.createElement('br'); |
| + assert_not_equals(recordTest.getStringElementRecord().elem, elem, |
| + "Changing the original value does not change the record value"); |
| + }, "Test Oilpan-based types"); |
|
Yuki
2017/03/09 10:10:08
nit: s/Oilpan-based/DOM Object/
Raphael Kubo da Costa (rakuco)
2017/03/09 16:08:34
Done.
|
| + |
| + test(() => { |
| + let recordTest = internals.recordTest(); |
| + let getterAlias = recordTest.getUSVStringUSVStringBooleanRecordRecord; |
| + |
| + recordTest.setUSVStringUSVStringBooleanRecordRecord({'foo': {'bar': true}, 'quux': {'baz': false}}); |
| + let records = recordTest.getUSVStringUSVStringBooleanRecordRecord(); |
| + assert_array_equals(Object.keys(records), ['foo', 'quux'], |
| + "Nested record types have the correct keys"); |
| + assert_record_equals(records.foo, [['bar', true]]); |
| + assert_record_equals(records.quux, [['baz', false]]); |
| + }, "Test nested record types"); |
| + |
| + test(() => { |
| + let recordTest = internals.recordTest(); |
| + |
| + let record = recordTest.returnStringByteStringSequenceRecord(); |
| + assert_array_equals(Object.keys(record), ['foo', 'bar']); |
| + assert_array_equals(record.foo, ['hello, world', 'hi, mom']); |
| + assert_array_equals(record.bar, ['goodbye, mom']); |
| + |
| + let other_record = recordTest.returnStringByteStringSequenceRecord(); |
| + assert_not_equals(record, other_record, "A new object is returned each time"); |
| + }, "Test sequences in records"); |
| +</script> |