Bug 1576104 [wpt PR 18633] - [webnfc] Refactor/Refine impl for "Creating Web NFC message" algorithm, a=testonly

Automatic update from web-platform-tests
[webnfc] Refactor/Refine impl for "Creating Web NFC message" algorithm

This CL implements strictly the "Creating Web NFC message" algorithm
described at http://w3c.github.io/web-nfc/#creating-web-nfc-message.

1.
Changes the Web IDL definition for NDEFRecordData from
"typedef (DOMString or unrestricted double or ArrayBuffer or Dictionary) NDEFRecordData;"
to
"typedef any NDEFRecordData;"

2.
Adds verification of NDEFRecordInit when creating NDEFRecord, i.e. makes
NDEFRecord ctor throw exceptions in case of invalid NDEFRecordInit.
Also, the same thing for NDEFMessage and NFCReadingEvent.

3.
Changes code flow for Step 10.9 of "9.10.1 The push() method" described
at https://w3c.github.io/web-nfc/#the-push-method.
"
Let output be the notation for the NDEF message to be created by UA, as
the result of passing message to create Web NFC message. If this throws
an exception, reject p with that exception and abort these steps.
"
Previously,
  NDEFMessageSource (NDEFMessageInit) -Validity check->
  -Mojo TypeConverter-> Mojom NDEFMessagePtr
Now,
  Remove "Validity check" and "Mojo TypeConverter" mentioned above,
  instead, we reuse the process of creating NDEFMessage from
  NDEFMessageSource (NDEFMessageInit), then the next step converting
  NDEFMessage to Mojom NDEFMessagePtr is quite an easy job.

BUG=520391

Change-Id: I628981e556f89ffdd0f883da0cfa99b20a6f8300
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1767719
Commit-Queue: Leon Han <leon.han@intel.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Rijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Cr-Commit-Position: refs/heads/master@{#693539}

--

wpt-commits: 685003d701e3c4154227758c65259c56662aa23d
wpt-pr: 18633
This commit is contained in:
Leon Han 2019-09-05 14:52:57 +00:00 коммит произвёл James Graham
Родитель 06e36b246c
Коммит 34de58af9f
2 изменённых файлов: 11 добавлений и 19 удалений

Просмотреть файл

@ -12,12 +12,8 @@
}, 'NDEFRecord constructor without init dict');
test(() => {
const record = new NDEFRecord(null);
assert_equals(record.recordType.length, 0, 'empty recordType');
assert_equals(record.mediaType.length, 0, 'empty mediaType');
assert_equals(record.toText(), null, 'toText() returns null');
assert_equals(record.toArrayBuffer(), null, 'toArrayBuffer() returns null');
assert_equals(record.toJSON(), null, 'toJSON() returns null');
assert_throws(new TypeError, () => new NDEFRecord(null),
"The record has neither type nor data.");
}, 'NDEFRecord constructor with null init dict');
test(() => {

Просмотреть файл

@ -23,19 +23,15 @@ const invalid_type_messages =
// NDEFRecord must have data.
createMessage([createTextRecord()]),
// NDEFRecord.data for 'text' record must be number or string.
// NDEFRecord.data for 'text' record must be a string.
createMessage([createTextRecord(test_buffer_data)]),
createMessage([createTextRecord(test_json_data)]),
createMessage([createTextRecord(test_number_data)]),
// https://w3c.github.io/web-nfc/#dfn-map-a-json-object-to-ndef
// NDEFRecord must have data.
createMessage([createJsonRecord()]),
// NDEFRecord.data for 'json' record must be object.
createMessage([createJsonRecord(test_buffer_data)]),
createMessage([createJsonRecord(test_number_data)]),
createMessage([createJsonRecord(test_text_data)]),
// https://w3c.github.io/web-nfc/#dfn-map-a-url-to-ndef
// NDEFRecord must have data.
createMessage([createUrlRecord()]),
@ -59,16 +55,16 @@ const invalid_syntax_messages =
[
// NDEFRecord.mediaType for 'text' record must be 'text/*'.
createMessage([createRecord('text', 'application/json',
test_number_data)]),
test_text_data)]),
// Data for 'url' record, must be a valid URL.
createMessage([createUrlRecord('Invalid URL:// Data')]),
// NDEFRecord.mediaType for 'json' record must be 'application/json' or
// starts with 'application/' and ends with '+json'.
// A JSON MIME type is any MIME type whose subtype ends in "+json" or
// whose essence is "application/json" or "text/json".
createMessage([createRecord('json', 'image/png', test_json_data)]),
createMessage([createRecord('json', 'application/x+y', test_json_data)]),
createMessage([createRecord('json', 'custom/app+json', test_json_data)]),
createMessage([createRecord('json', 'custom/app+jsonx', test_json_data)]),
];
const invalid_signals = [
@ -195,8 +191,8 @@ promise_test(async t => {
const writer = new NFCWriter();
const message = createMessage([createRecord('json','application/json',
{ get x(){ return this; } })]);
await promise_rejects(t, 'SyntaxError', writer.push(message));
}, "Reject promise with SyntaxError if 'json' record cannot be serialized.");
await promise_rejects(t, new TypeError(), writer.push(message));
}, "Reject promise with exceptions thrown from serializing the 'json' record data.");
promise_test(async t => {
const writer = new NFCWriter();
@ -251,8 +247,8 @@ nfc_test(async (t, mockNFC) => {
const writer = new NFCWriter();
let message = createMessage([createTextRecord(test_text_data),
createJsonRecord(test_json_data),
createJsonRecord(test_number_data),
createOpaqueRecord(test_buffer_data),
createTextRecord(test_number_data),
createUrlRecord(test_url_data)],
test_message_origin);
await writer.push(message);