Commit fe420dec authored by Leon Han's avatar Leon Han Committed by Commit Bot

[webnfc] Introduce NDEFRecordInit#id to support writing record id

The plan is:
1. Introduces NDEFRecord{Init}#id and supports reading.
   Already done by crrev.com/c/1861574.

2. Supports writing.
   This CL is focused on impl in Blink, with the following CLs focused
   on impl in Device Service.
     crrev.com/c/1910906
     crrev.com/c/1911385
     crrev.com/c/1915940
     crrev.com/c/1916261

3. Introduces NFCScanOptions#id and filters records by it when scanning.

4. Removes NDEFMessage{Init}#url and old impl of the author record.

The spec changes:
https://github.com/w3c/web-nfc/pull/338
https://github.com/w3c/web-nfc/pull/340
https://github.com/w3c/web-nfc/pull/446

BUG=520391

Change-Id: Ie6f5b2978f78676c3aa607d09e7ffd5bbb5005d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1928891Reviewed-by: default avatarFrançois Beaufort <beaufort.francois@gmail.com>
Reviewed-by: default avatarRijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Commit-Queue: Leon Han <leon.han@intel.com>
Cr-Commit-Position: refs/heads/master@{#720792}
parent 94d59873
...@@ -255,19 +255,21 @@ NDEFRecord* NDEFRecord::Create(const ExecutionContext* execution_context, ...@@ -255,19 +255,21 @@ NDEFRecord* NDEFRecord::Create(const ExecutionContext* execution_context,
return nullptr; return nullptr;
} }
NDEFRecord* instance = nullptr;
if (record_type == "empty") { if (record_type == "empty") {
// https://w3c.github.io/web-nfc/#mapping-empty-record-to-ndef // https://w3c.github.io/web-nfc/#mapping-empty-record-to-ndef
return MakeGarbageCollected<NDEFRecord>(record_type, instance =
WTF::Vector<uint8_t>()); MakeGarbageCollected<NDEFRecord>(record_type, WTF::Vector<uint8_t>());
} else if (record_type == "text") { } else if (record_type == "text") {
return CreateTextRecord(execution_context, init->encoding(), init->lang(), instance = CreateTextRecord(execution_context, init->encoding(),
init->data(), exception_state); init->lang(), init->data(), exception_state);
} else if (record_type == "url" || record_type == "absolute-url") { } else if (record_type == "url" || record_type == "absolute-url") {
return CreateUrlRecord(record_type, init->data(), exception_state); instance = CreateUrlRecord(record_type, init->data(), exception_state);
} else if (record_type == "mime") { } else if (record_type == "mime") {
return CreateMimeRecord(init->data(), init->mediaType(), exception_state); instance =
CreateMimeRecord(init->data(), init->mediaType(), exception_state);
} else if (record_type == "unknown") { } else if (record_type == "unknown") {
return CreateUnknownRecord(init->data(), exception_state); instance = CreateUnknownRecord(init->data(), exception_state);
} else if (record_type == "smart-poster") { } else if (record_type == "smart-poster") {
// TODO(https://crbug.com/520391): Support creating smart-poster records. // TODO(https://crbug.com/520391): Support creating smart-poster records.
exception_state.ThrowTypeError("smart-poster type is not supported yet"); exception_state.ThrowTypeError("smart-poster type is not supported yet");
...@@ -279,12 +281,18 @@ NDEFRecord* NDEFRecord::Create(const ExecutionContext* execution_context, ...@@ -279,12 +281,18 @@ NDEFRecord* NDEFRecord::Create(const ExecutionContext* execution_context,
// in either case we should try to create an external type record from // in either case we should try to create an external type record from
// |data|. // |data|.
String formated_type = ValidateCustomRecordType(record_type); String formated_type = ValidateCustomRecordType(record_type);
if (!formated_type.IsNull()) if (formated_type.IsNull()) {
return CreateExternalRecord(formated_type, init->data(), exception_state); exception_state.ThrowTypeError("Invalid NDEFRecord type.");
return nullptr;
}
instance =
CreateExternalRecord(formated_type, init->data(), exception_state);
} }
exception_state.ThrowTypeError("Invalid NDEFRecord type."); if (instance && init->hasId()) {
return nullptr; instance->id_ = init->id();
}
return instance;
} }
NDEFRecord::NDEFRecord(const String& record_type, NDEFRecord::NDEFRecord(const String& record_type,
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
] interface NDEFRecord { ] interface NDEFRecord {
readonly attribute USVString recordType; readonly attribute USVString recordType;
readonly attribute USVString? mediaType; readonly attribute USVString? mediaType;
readonly attribute USVString id; readonly attribute USVString? id;
readonly attribute USVString? encoding; readonly attribute USVString? encoding;
readonly attribute USVString? lang; readonly attribute USVString? lang;
readonly attribute DataView? data; readonly attribute DataView? data;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
dictionary NDEFRecordInit { dictionary NDEFRecordInit {
USVString recordType; USVString recordType;
USVString mediaType; USVString mediaType;
USVString id;
USVString encoding; USVString encoding;
USVString lang; USVString lang;
......
...@@ -27,6 +27,7 @@ function toMojoNDEFRecord(record) { ...@@ -27,6 +27,7 @@ function toMojoNDEFRecord(record) {
let nfcRecord = new device.mojom.NDEFRecord(); let nfcRecord = new device.mojom.NDEFRecord();
nfcRecord.recordType = record.recordType; nfcRecord.recordType = record.recordType;
nfcRecord.mediaType = record.mediaType; nfcRecord.mediaType = record.mediaType;
nfcRecord.id = record.id;
nfcRecord.data = toByteArray(record.data); nfcRecord.data = toByteArray(record.data);
if (record.data != null && record.data.records !== undefined) { if (record.data != null && record.data.records !== undefined) {
// |record.data| may be an NDEFMessageInit, i.e. the payload is a message. // |record.data| may be an NDEFMessageInit, i.e. the payload is a message.
...@@ -59,6 +60,12 @@ function toByteArray(data) { ...@@ -59,6 +60,12 @@ function toByteArray(data) {
function compareNDEFRecords(providedRecord, receivedRecord) { function compareNDEFRecords(providedRecord, receivedRecord) {
assert_equals(providedRecord.recordType, receivedRecord.recordType); assert_equals(providedRecord.recordType, receivedRecord.recordType);
if (providedRecord.id === undefined) {
assert_equals(null, receivedRecord.id);
} else {
assert_equals(providedRecord.id, receivedRecord.id);
}
if (providedRecord.mediaType === undefined) { if (providedRecord.mediaType === undefined) {
assert_equals(null, receivedRecord.mediaType); assert_equals(null, receivedRecord.mediaType);
} else { } else {
......
...@@ -18,29 +18,56 @@ ...@@ -18,29 +18,56 @@
test(() => { test(() => {
assert_throws(new TypeError, () => new NDEFRecord( assert_throws(new TypeError, () => new NDEFRecord(
createRecord('empty', test_text_data, 'text/plain')), createRecord('empty', test_text_data, test_record_id, 'text/plain')),
'mediaType does not apply for empty record type.'); 'mediaType does not apply for empty record type.');
assert_throws(new TypeError, () => new NDEFRecord( assert_throws(new TypeError, () => new NDEFRecord(
createRecord('text', test_text_data, 'text/plain')), createRecord('text', test_text_data, test_record_id, 'text/plain')),
'mediaType does not apply for text record type.'); 'mediaType does not apply for text record type.');
assert_throws(new TypeError, () => new NDEFRecord( assert_throws(new TypeError, () => new NDEFRecord(
createRecord('url', test_url_data, 'text/plain')), createRecord('url', test_url_data, test_record_id, 'text/plain')),
'mediaType does not apply for url record type.'); 'mediaType does not apply for url record type.');
assert_throws(new TypeError, () => new NDEFRecord( assert_throws(new TypeError, () => new NDEFRecord(
createRecord('absolute-url', test_url_data, 'text/plain')), createRecord('absolute-url', test_url_data, test_record_id, 'text/plain')),
'mediaType does not apply for absolute-url record type.'); 'mediaType does not apply for absolute-url record type.');
assert_throws(new TypeError, () => new NDEFRecord( assert_throws(new TypeError, () => new NDEFRecord(
createRecord('unknown', test_buffer_data, 'application/octet-stream')), createRecord('unknown', test_buffer_data, test_record_id, 'application/octet-stream')),
'mediaType does not apply for unknown record type.'); 'mediaType does not apply for unknown record type.');
assert_throws(new TypeError, () => new NDEFRecord( assert_throws(new TypeError, () => new NDEFRecord(
createRecord('foo.example.com:bar', test_buffer_data, 'application/octet-stream')), createRecord('foo.example.com:bar', test_buffer_data, test_record_id, 'application/octet-stream')),
'mediaType does not apply for external record type.'); 'mediaType does not apply for external record type.');
}, 'NDEFRecord constructor should only accept mediaType for mime record type'); }, 'NDEFRecord constructor should only accept mediaType for mime record type');
test(() => {
{
const record = new NDEFRecord(createRecord('text', test_text_data));
assert_equals(record.id, null, 'id');
}
{
const record = new NDEFRecord(createRecord('text', test_text_data, ''));
assert_equals(record.id, '', 'id');
}
{
const dummy_id = 'https://dummy_host/mypath/myid';
const record = new NDEFRecord(createRecord('text', test_text_data, dummy_id));
assert_equals(record.id, dummy_id, 'id');
}
{
const dummy_id = 'http://dummy_host/mypath/myid';
const record = new NDEFRecord(createRecord('text', test_text_data, dummy_id));
assert_equals(record.id, dummy_id, 'id');
}
{
const dummy_id = 'mypath/myid';
const record = new NDEFRecord(createRecord('text', test_text_data, dummy_id));
assert_equals(record.id, dummy_id, 'id');
}
}, 'NDEFRecord constructor with custom record ids');
test(() => { test(() => {
const record = new NDEFRecord(createTextRecord(test_text_data)); const record = new NDEFRecord(createTextRecord(test_text_data));
assert_equals(record.recordType, 'text', 'recordType'); assert_equals(record.recordType, 'text', 'recordType');
assert_equals(record.mediaType, null, 'mediaType'); assert_equals(record.mediaType, null, 'mediaType');
assert_equals(record.id, test_record_id, 'id');
assert_equals(record.encoding, 'utf-8', 'encoding'); assert_equals(record.encoding, 'utf-8', 'encoding');
assert_equals(record.lang, 'en', 'lang'); assert_equals(record.lang, 'en', 'lang');
const decoder = new TextDecoder(); const decoder = new TextDecoder();
...@@ -56,6 +83,7 @@ ...@@ -56,6 +83,7 @@
const record = new NDEFRecord(createTextRecord(uint8Array.buffer)); const record = new NDEFRecord(createTextRecord(uint8Array.buffer));
assert_equals(record.recordType, 'text', 'recordType'); assert_equals(record.recordType, 'text', 'recordType');
assert_equals(record.mediaType, null, 'mediaType'); assert_equals(record.mediaType, null, 'mediaType');
assert_equals(record.id, test_record_id, 'id');
assert_equals(record.encoding, 'utf-8', 'encoding'); assert_equals(record.encoding, 'utf-8', 'encoding');
assert_equals(record.lang, 'en', 'lang'); assert_equals(record.lang, 'en', 'lang');
const decoder = new TextDecoder(); const decoder = new TextDecoder();
...@@ -71,6 +99,7 @@ ...@@ -71,6 +99,7 @@
const record = new NDEFRecord(createTextRecord(uint8Array)); const record = new NDEFRecord(createTextRecord(uint8Array));
assert_equals(record.recordType, 'text', 'recordType'); assert_equals(record.recordType, 'text', 'recordType');
assert_equals(record.mediaType, null, 'mediaType'); assert_equals(record.mediaType, null, 'mediaType');
assert_equals(record.id, test_record_id, 'id');
assert_equals(record.encoding, 'utf-8', 'encoding'); assert_equals(record.encoding, 'utf-8', 'encoding');
assert_equals(record.lang, 'en', 'lang'); assert_equals(record.lang, 'en', 'lang');
const decoder = new TextDecoder(); const decoder = new TextDecoder();
...@@ -87,6 +116,7 @@ ...@@ -87,6 +116,7 @@
const record = new NDEFRecord(createTextRecord(test_text_data, encoding, lang)); const record = new NDEFRecord(createTextRecord(test_text_data, encoding, lang));
assert_equals(record.recordType, 'text', 'recordType'); assert_equals(record.recordType, 'text', 'recordType');
assert_equals(record.mediaType, null, 'mediaType'); assert_equals(record.mediaType, null, 'mediaType');
assert_equals(record.id, test_record_id, 'id');
assert_equals(record.encoding, encoding, 'encoding'); assert_equals(record.encoding, encoding, 'encoding');
assert_equals(record.lang, lang, 'lang'); assert_equals(record.lang, lang, 'lang');
const decoder = new TextDecoder(); const decoder = new TextDecoder();
...@@ -105,6 +135,7 @@ ...@@ -105,6 +135,7 @@
const record = new NDEFRecord(createTextRecord(test_text_data)); const record = new NDEFRecord(createTextRecord(test_text_data));
assert_equals(record.recordType, 'text', 'recordType'); assert_equals(record.recordType, 'text', 'recordType');
assert_equals(record.mediaType, null, 'mediaType'); assert_equals(record.mediaType, null, 'mediaType');
assert_equals(record.id, test_record_id, 'id');
assert_equals(record.encoding, 'utf-8', 'encoding'); assert_equals(record.encoding, 'utf-8', 'encoding');
assert_equals(record.lang, test_lang, 'lang'); assert_equals(record.lang, test_lang, 'lang');
const decoder = new TextDecoder(); const decoder = new TextDecoder();
...@@ -116,6 +147,7 @@ ...@@ -116,6 +147,7 @@
const record = new NDEFRecord(createUrlRecord(test_url_data)); const record = new NDEFRecord(createUrlRecord(test_url_data));
assert_equals(record.recordType, 'url', 'recordType'); assert_equals(record.recordType, 'url', 'recordType');
assert_equals(record.mediaType, null, 'mediaType'); assert_equals(record.mediaType, null, 'mediaType');
assert_equals(record.id, test_record_id, 'id');
const decoder = new TextDecoder(); const decoder = new TextDecoder();
assert_equals(decoder.decode(record.data), test_url_data, assert_equals(decoder.decode(record.data), test_url_data,
'data has the same content with the original dictionary'); 'data has the same content with the original dictionary');
...@@ -127,6 +159,7 @@ ...@@ -127,6 +159,7 @@
const record = new NDEFRecord(createUrlRecord(test_url_data, true)); const record = new NDEFRecord(createUrlRecord(test_url_data, true));
assert_equals(record.recordType, 'absolute-url', 'recordType'); assert_equals(record.recordType, 'absolute-url', 'recordType');
assert_equals(record.mediaType, null, 'mediaType'); assert_equals(record.mediaType, null, 'mediaType');
assert_equals(record.id, test_record_id, 'id');
const decoder = new TextDecoder(); const decoder = new TextDecoder();
assert_equals(decoder.decode(record.data), test_url_data, assert_equals(decoder.decode(record.data), test_url_data,
'data has the same content with the original dictionary'); 'data has the same content with the original dictionary');
...@@ -146,6 +179,7 @@ ...@@ -146,6 +179,7 @@
const record = new NDEFRecord(createMimeRecord(buffer)); const record = new NDEFRecord(createMimeRecord(buffer));
assert_equals(record.recordType, 'mime', 'recordType'); assert_equals(record.recordType, 'mime', 'recordType');
assert_equals(record.mediaType, 'application/octet-stream', 'mediaType'); assert_equals(record.mediaType, 'application/octet-stream', 'mediaType');
assert_equals(record.id, test_record_id, 'id');
assert_array_equals(new Uint8Array(record.data.buffer), [1, 2, 3, 4], assert_array_equals(new Uint8Array(record.data.buffer), [1, 2, 3, 4],
'data has the same content with the original buffer'); 'data has the same content with the original buffer');
assert_throws('NotSupportedError', () => record.toRecords(), assert_throws('NotSupportedError', () => record.toRecords(),
...@@ -156,6 +190,7 @@ ...@@ -156,6 +190,7 @@
let buffer_view = new Uint8Array(buffer, 1); let buffer_view = new Uint8Array(buffer, 1);
const record = new NDEFRecord(createMimeRecord(buffer_view)); const record = new NDEFRecord(createMimeRecord(buffer_view));
assert_equals(record.recordType, 'mime', 'recordType'); assert_equals(record.recordType, 'mime', 'recordType');
assert_equals(record.id, test_record_id, 'id');
assert_array_equals(new Uint8Array(record.data.buffer), [2, 3, 4], assert_array_equals(new Uint8Array(record.data.buffer), [2, 3, 4],
'data has the same content with the original buffer view'); 'data has the same content with the original buffer view');
assert_throws('NotSupportedError', () => record.toRecords(), assert_throws('NotSupportedError', () => record.toRecords(),
...@@ -167,6 +202,7 @@ ...@@ -167,6 +202,7 @@
const record = new NDEFRecord(createMimeRecordFromJson(test_json_data)); const record = new NDEFRecord(createMimeRecordFromJson(test_json_data));
assert_equals(record.recordType, 'mime', 'recordType'); assert_equals(record.recordType, 'mime', 'recordType');
assert_equals(record.mediaType, 'application/json', 'mediaType'); assert_equals(record.mediaType, 'application/json', 'mediaType');
assert_equals(record.id, test_record_id, 'id');
assert_object_equals(JSON.parse(new TextDecoder().decode(record.data)), assert_object_equals(JSON.parse(new TextDecoder().decode(record.data)),
test_json_data, test_json_data,
'data has the same content with the original json'); 'data has the same content with the original json');
...@@ -185,6 +221,7 @@ ...@@ -185,6 +221,7 @@
{ {
const record = new NDEFRecord(createUnknownRecord(buffer)); const record = new NDEFRecord(createUnknownRecord(buffer));
assert_equals(record.recordType, 'unknown', 'recordType'); assert_equals(record.recordType, 'unknown', 'recordType');
assert_equals(record.id, test_record_id, 'id');
assert_array_equals(new Uint8Array(record.data.buffer), [1, 2, 3, 4], assert_array_equals(new Uint8Array(record.data.buffer), [1, 2, 3, 4],
'data has the same content with the original buffer'); 'data has the same content with the original buffer');
assert_throws('NotSupportedError', () => record.toRecords(), assert_throws('NotSupportedError', () => record.toRecords(),
...@@ -195,6 +232,7 @@ ...@@ -195,6 +232,7 @@
let buffer_view = new Uint8Array(buffer, 1); let buffer_view = new Uint8Array(buffer, 1);
const record = new NDEFRecord(createUnknownRecord(buffer_view)); const record = new NDEFRecord(createUnknownRecord(buffer_view));
assert_equals(record.recordType, 'unknown', 'recordType'); assert_equals(record.recordType, 'unknown', 'recordType');
assert_equals(record.id, test_record_id, 'id');
assert_array_equals(new Uint8Array(record.data.buffer), [2, 3, 4], assert_array_equals(new Uint8Array(record.data.buffer), [2, 3, 4],
'data has the same content with the original buffer view'); 'data has the same content with the original buffer view');
assert_throws('NotSupportedError', () => record.toRecords(), assert_throws('NotSupportedError', () => record.toRecords(),
...@@ -211,9 +249,10 @@ ...@@ -211,9 +249,10 @@
new Uint8Array(buffer).set([1, 2, 3, 4]); new Uint8Array(buffer).set([1, 2, 3, 4]);
// Feed ArrayBuffer. // Feed ArrayBuffer.
{ {
const record = new NDEFRecord(createRecord('foo.eXamPle.coM:bAr*-', buffer)); const record = new NDEFRecord(createRecord('foo.eXamPle.coM:bAr*-', buffer, test_record_id));
assert_equals(record.recordType, 'foo.example.com:bAr*-', 'recordType'); assert_equals(record.recordType, 'foo.example.com:bAr*-', 'recordType');
assert_equals(record.mediaType, null, 'mediaType'); assert_equals(record.mediaType, null, 'mediaType');
assert_equals(record.id, test_record_id, 'id');
assert_array_equals(new Uint8Array(record.data.buffer), [1, 2, 3, 4], assert_array_equals(new Uint8Array(record.data.buffer), [1, 2, 3, 4],
'data has the same content with the original buffer'); 'data has the same content with the original buffer');
assert_equals(record.toRecords(), null, assert_equals(record.toRecords(), null,
...@@ -222,9 +261,11 @@ ...@@ -222,9 +261,11 @@
// Feed ArrayBufferView. // Feed ArrayBufferView.
{ {
let buffer_view = new Uint8Array(buffer, 1); let buffer_view = new Uint8Array(buffer, 1);
const record = new NDEFRecord(createRecord('foo.eXamPle.coM:bAr*-', buffer_view)); const record = new NDEFRecord(createRecord(
'foo.eXamPle.coM:bAr*-', buffer_view, test_record_id));
assert_equals(record.recordType, 'foo.example.com:bAr*-', 'recordType'); assert_equals(record.recordType, 'foo.example.com:bAr*-', 'recordType');
assert_equals(record.mediaType, null, 'mediaType'); assert_equals(record.mediaType, null, 'mediaType');
assert_equals(record.id, test_record_id, 'id');
assert_array_equals(new Uint8Array(record.data.buffer), [2, 3, 4], assert_array_equals(new Uint8Array(record.data.buffer), [2, 3, 4],
'data has the same content with the original buffer view'); 'data has the same content with the original buffer view');
assert_equals(record.toRecords(), null, assert_equals(record.toRecords(), null,
......
...@@ -64,6 +64,7 @@ const test_buffer_data = new ArrayBuffer(test_text_byte_array.length); ...@@ -64,6 +64,7 @@ const test_buffer_data = new ArrayBuffer(test_text_byte_array.length);
const test_buffer_view = new Uint8Array(test_buffer_data); const test_buffer_view = new Uint8Array(test_buffer_data);
test_buffer_view.set(test_text_byte_array); test_buffer_view.set(test_text_byte_array);
const fake_tag_serial_number = 'c0:45:00:02'; const fake_tag_serial_number = 'c0:45:00:02';
const test_record_id = '/test_path/test_id';
const NFCHWStatus = {}; const NFCHWStatus = {};
// OS-level NFC setting is ON // OS-level NFC setting is ON
...@@ -81,10 +82,12 @@ function createMessage(records) { ...@@ -81,10 +82,12 @@ function createMessage(records) {
} }
} }
function createRecord(recordType, data, mediaType, encoding, lang) { function createRecord(recordType, data, id, mediaType, encoding, lang) {
let record = {}; let record = {};
if (recordType !== undefined) if (recordType !== undefined)
record.recordType = recordType; record.recordType = recordType;
if (id !== undefined)
record.id = id;
if (mediaType !== undefined) if (mediaType !== undefined)
record.mediaType = mediaType; record.mediaType = mediaType;
if (encoding !== undefined) if (encoding !== undefined)
...@@ -97,28 +100,29 @@ function createRecord(recordType, data, mediaType, encoding, lang) { ...@@ -97,28 +100,29 @@ function createRecord(recordType, data, mediaType, encoding, lang) {
} }
function createTextRecord(data, encoding, lang) { function createTextRecord(data, encoding, lang) {
return createRecord('text', data, undefined, encoding, lang); return createRecord('text', data, test_record_id, undefined, encoding, lang);
} }
function createMimeRecordFromJson(json) { function createMimeRecordFromJson(json) {
return createRecord( return createRecord(
'mime', new TextEncoder('utf-8').encode(JSON.stringify(json)), 'mime', new TextEncoder('utf-8').encode(JSON.stringify(json)),
'application/json'); test_record_id, 'application/json');
} }
function createMimeRecord(buffer) { function createMimeRecord(buffer) {
return createRecord('mime', buffer, 'application/octet-stream'); return createRecord(
'mime', buffer, test_record_id, 'application/octet-stream');
} }
function createUnknownRecord(buffer) { function createUnknownRecord(buffer) {
return createRecord('unknown', buffer); return createRecord('unknown', buffer, test_record_id);
} }
function createUrlRecord(url, isAbsUrl) { function createUrlRecord(url, isAbsUrl) {
if (isAbsUrl) { if (isAbsUrl) {
return createRecord('absolute-url', url); return createRecord('absolute-url', url, test_record_id);
} }
return createRecord('url', url); return createRecord('url', url, test_record_id);
} }
function createNDEFPushOptions(target, ignoreRead) { function createNDEFPushOptions(target, ignoreRead) {
...@@ -135,9 +139,11 @@ function assertNDEFMessagesEqual(providedMessage, receivedMessage) { ...@@ -135,9 +139,11 @@ function assertNDEFMessagesEqual(providedMessage, receivedMessage) {
let provided = providedMessage; let provided = providedMessage;
if (providedMessage instanceof ArrayBuffer || if (providedMessage instanceof ArrayBuffer ||
ArrayBuffer.isView(providedMessage)) ArrayBuffer.isView(providedMessage))
provided = createMessage([createMimeRecord(providedMessage)]); provided = createMessage([createRecord(
'mime', providedMessage, undefined /* id */,
'application/octet-stream')]);
else if (typeof providedMessage === 'string') else if (typeof providedMessage === 'string')
provided = createMessage([createTextRecord(providedMessage)]); provided = createMessage([createRecord('text', providedMessage)]);
assert_equals(provided.records.length, receivedMessage.data.length, assert_equals(provided.records.length, receivedMessage.data.length,
'NDEFMessages must have same number of NDEFRecords'); 'NDEFMessages must have same number of NDEFRecords');
...@@ -161,6 +167,7 @@ function assertWebNDEFMessagesEqual(message, expectedMessage) { ...@@ -161,6 +167,7 @@ function assertWebNDEFMessagesEqual(message, expectedMessage) {
let expectedRecord = expectedMessage.records[i]; let expectedRecord = expectedMessage.records[i];
assert_equals(record.recordType, expectedRecord.recordType); assert_equals(record.recordType, expectedRecord.recordType);
assert_equals(record.mediaType, expectedRecord.mediaType); assert_equals(record.mediaType, expectedRecord.mediaType);
assert_equals(record.id, expectedRecord.id);
// Compares record data // Compares record data
assert_array_equals(new Uint8Array(record.data), assert_array_equals(new Uint8Array(record.data),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment