Skip to content

Commit

Permalink
Reland "[webnfc] Refactor/Refine impl for "Creating Web NFC message" …
Browse files Browse the repository at this point in the history
…algorithm"

This is a reland of 581b273e3743fcbd168775edfeebae8b092fc706

Original change's description:
> [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 <[email protected]>
> Reviewed-by: Daniel Cheng <[email protected]>
> Reviewed-by: Reilly Grant <[email protected]>
> Reviewed-by: Rijubrata Bhaumik <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#693539}

Bug: 520391,923974
TBR: dcheng@,reillyg@
Change-Id: I608e28638c0909c9d4f675774514cd990f9878c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1787557
Commit-Queue: Leon Han <[email protected]>
Reviewed-by: Kentaro Hara <[email protected]>
Cr-Commit-Position: refs/heads/master@{#693638}
  • Loading branch information
Leon Han authored and chromium-wpt-export-bot committed Sep 5, 2019
1 parent 716f0ac commit af74d60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
8 changes: 2 additions & 6 deletions web-nfc/NDEFRecord_constructor.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
22 changes: 9 additions & 13 deletions web-nfc/NFCWriter_push.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@
// 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()]),
Expand All @@ -59,16 +55,16 @@
[
// 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 = [
Expand Down Expand Up @@ -195,8 +191,8 @@
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();
Expand Down Expand Up @@ -251,8 +247,8 @@
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);
Expand Down

0 comments on commit af74d60

Please sign in to comment.