Commit 877b5d06 authored by Leon Han's avatar Leon Han Committed by Commit Bot

[webnfc] Combine 'opaque' and 'json' types as 'mime' for TNF_MIME_MEDIA

Before, we have both 'opaque' and 'json' NDEFRecord for reading/writing
TNF_MIME_MEDIA records, and we just serialize the JSON object provided
by users to get the payload bytes for the 'json' NDEFRecord.

Now with the goal of making web nfc more of a low level API, this CL
unifies them as a new 'mime' type that serves for reading/writing
TNF_MIME_MEDIA records.
  TNF_MIME_MEDIA  <--->  'mime' type NDEFRecord

The spec change:
https://github.com/w3c/web-nfc/pull/373

BUG=520391

Change-Id: If4052c70e48100185e72cb07da8363f5de92b4b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1896154Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Leon Han <leon.han@intel.com>
Cr-Commit-Position: refs/heads/master@{#712409}
parent e07a406b
...@@ -26,7 +26,6 @@ public final class NdefMessageUtils { ...@@ -26,7 +26,6 @@ public final class NdefMessageUtils {
private static final String AUTHOR_RECORD_DOMAIN = "w3.org"; private static final String AUTHOR_RECORD_DOMAIN = "w3.org";
private static final String AUTHOR_RECORD_TYPE = "A"; private static final String AUTHOR_RECORD_TYPE = "A";
private static final String TEXT_MIME = "text/plain"; private static final String TEXT_MIME = "text/plain";
private static final String JSON_MIME = "application/json";
private static final String OCTET_STREAM_MIME = "application/octet-stream"; private static final String OCTET_STREAM_MIME = "application/octet-stream";
private static final String ENCODING_UTF8 = "utf-8"; private static final String ENCODING_UTF8 = "utf-8";
private static final String ENCODING_UTF16 = "utf-16"; private static final String ENCODING_UTF16 = "utf-16";
...@@ -35,8 +34,7 @@ public final class NdefMessageUtils { ...@@ -35,8 +34,7 @@ public final class NdefMessageUtils {
public static final String RECORD_TYPE_TEXT = "text"; public static final String RECORD_TYPE_TEXT = "text";
public static final String RECORD_TYPE_URL = "url"; public static final String RECORD_TYPE_URL = "url";
public static final String RECORD_TYPE_ABSOLUTE_URL = "absolute-url"; public static final String RECORD_TYPE_ABSOLUTE_URL = "absolute-url";
public static final String RECORD_TYPE_JSON = "json"; public static final String RECORD_TYPE_MIME = "mime";
public static final String RECORD_TYPE_OPAQUE = "opaque";
public static final String RECORD_TYPE_UNKNOWN = "unknown"; public static final String RECORD_TYPE_UNKNOWN = "unknown";
public static final String RECORD_TYPE_SMART_POSTER = "smart-poster"; public static final String RECORD_TYPE_SMART_POSTER = "smart-poster";
...@@ -120,8 +118,7 @@ public final class NdefMessageUtils { ...@@ -120,8 +118,7 @@ public final class NdefMessageUtils {
byte[] payload = createPayloadForTextRecord(record); byte[] payload = createPayloadForTextRecord(record);
return new android.nfc.NdefRecord(android.nfc.NdefRecord.TNF_WELL_KNOWN, return new android.nfc.NdefRecord(android.nfc.NdefRecord.TNF_WELL_KNOWN,
android.nfc.NdefRecord.RTD_TEXT, null, payload); android.nfc.NdefRecord.RTD_TEXT, null, payload);
case RECORD_TYPE_JSON: case RECORD_TYPE_MIME:
case RECORD_TYPE_OPAQUE:
return android.nfc.NdefRecord.createMime(record.mediaType, record.data); return android.nfc.NdefRecord.createMime(record.mediaType, record.data);
case RECORD_TYPE_UNKNOWN: case RECORD_TYPE_UNKNOWN:
return new android.nfc.NdefRecord( return new android.nfc.NdefRecord(
...@@ -210,15 +207,11 @@ public final class NdefMessageUtils { ...@@ -210,15 +207,11 @@ public final class NdefMessageUtils {
/** /**
/** /**
* Constructs MIME or JSON NdefRecord * Constructs mime NdefRecord
*/ */
private static NdefRecord createMIMERecord(String mediaType, byte[] payload) { private static NdefRecord createMIMERecord(String mediaType, byte[] payload) {
NdefRecord nfcRecord = new NdefRecord(); NdefRecord nfcRecord = new NdefRecord();
if (mediaType.equals(JSON_MIME)) { nfcRecord.recordType = RECORD_TYPE_MIME;
nfcRecord.recordType = RECORD_TYPE_JSON;
} else {
nfcRecord.recordType = RECORD_TYPE_OPAQUE;
}
nfcRecord.mediaType = mediaType; nfcRecord.mediaType = mediaType;
nfcRecord.data = payload; nfcRecord.data = payload;
return nfcRecord; return nfcRecord;
......
...@@ -36,8 +36,7 @@ public final class NdefMessageValidator { ...@@ -36,8 +36,7 @@ public final class NdefMessageValidator {
if (record == null) return false; if (record == null) return false;
if (record.recordType.equals(NdefMessageUtils.RECORD_TYPE_EMPTY)) return true; if (record.recordType.equals(NdefMessageUtils.RECORD_TYPE_EMPTY)) return true;
if (record.data == null) return false; if (record.data == null) return false;
if ((record.recordType.equals(NdefMessageUtils.RECORD_TYPE_JSON) if (record.recordType.equals(NdefMessageUtils.RECORD_TYPE_MIME)
|| record.recordType.equals(NdefMessageUtils.RECORD_TYPE_OPAQUE))
&& (record.mediaType == null || record.mediaType.isEmpty())) { && (record.mediaType == null || record.mediaType.isEmpty())) {
return false; return false;
} }
......
...@@ -294,28 +294,28 @@ public class NFCTest { ...@@ -294,28 +294,28 @@ public class NFCTest {
assertEquals(LANG_EN_US, utf16TextMojoNdefMessage.data[0].lang); assertEquals(LANG_EN_US, utf16TextMojoNdefMessage.data[0].lang);
assertEquals(TEST_TEXT, new String(utf16TextMojoNdefMessage.data[0].data, "UTF-16")); assertEquals(TEST_TEXT, new String(utf16TextMojoNdefMessage.data[0].data, "UTF-16"));
// Test MIME record conversion. // Test mime record conversion with "text/plain" mime type.
android.nfc.NdefMessage mimeNdefMessage = android.nfc.NdefMessage mimeNdefMessage =
new android.nfc.NdefMessage(android.nfc.NdefRecord.createMime( new android.nfc.NdefMessage(android.nfc.NdefRecord.createMime(
TEXT_MIME, ApiCompatibilityUtils.getBytesUtf8(TEST_TEXT))); TEXT_MIME, ApiCompatibilityUtils.getBytesUtf8(TEST_TEXT)));
NdefMessage mimeMojoNdefMessage = NdefMessageUtils.toNdefMessage(mimeNdefMessage); NdefMessage mimeMojoNdefMessage = NdefMessageUtils.toNdefMessage(mimeNdefMessage);
assertNull(mimeMojoNdefMessage.url); assertNull(mimeMojoNdefMessage.url);
assertEquals(1, mimeMojoNdefMessage.data.length); assertEquals(1, mimeMojoNdefMessage.data.length);
assertEquals(NdefMessageUtils.RECORD_TYPE_OPAQUE, mimeMojoNdefMessage.data[0].recordType); assertEquals(NdefMessageUtils.RECORD_TYPE_MIME, mimeMojoNdefMessage.data[0].recordType);
assertEquals(TEXT_MIME, mimeMojoNdefMessage.data[0].mediaType); assertEquals(TEXT_MIME, mimeMojoNdefMessage.data[0].mediaType);
assertEquals(true, mimeMojoNdefMessage.data[0].id.isEmpty()); assertEquals(true, mimeMojoNdefMessage.data[0].id.isEmpty());
assertNull(mimeMojoNdefMessage.data[0].encoding); assertNull(mimeMojoNdefMessage.data[0].encoding);
assertNull(mimeMojoNdefMessage.data[0].lang); assertNull(mimeMojoNdefMessage.data[0].lang);
assertEquals(TEST_TEXT, new String(mimeMojoNdefMessage.data[0].data)); assertEquals(TEST_TEXT, new String(mimeMojoNdefMessage.data[0].data));
// Test JSON record conversion. // Test mime record conversion with "application/json" mime type.
android.nfc.NdefMessage jsonNdefMessage = android.nfc.NdefMessage jsonNdefMessage =
new android.nfc.NdefMessage(android.nfc.NdefRecord.createMime( new android.nfc.NdefMessage(android.nfc.NdefRecord.createMime(
JSON_MIME, ApiCompatibilityUtils.getBytesUtf8(TEST_JSON))); JSON_MIME, ApiCompatibilityUtils.getBytesUtf8(TEST_JSON)));
NdefMessage jsonMojoNdefMessage = NdefMessageUtils.toNdefMessage(jsonNdefMessage); NdefMessage jsonMojoNdefMessage = NdefMessageUtils.toNdefMessage(jsonNdefMessage);
assertNull(jsonMojoNdefMessage.url); assertNull(jsonMojoNdefMessage.url);
assertEquals(1, jsonMojoNdefMessage.data.length); assertEquals(1, jsonMojoNdefMessage.data.length);
assertEquals(NdefMessageUtils.RECORD_TYPE_JSON, jsonMojoNdefMessage.data[0].recordType); assertEquals(NdefMessageUtils.RECORD_TYPE_MIME, jsonMojoNdefMessage.data[0].recordType);
assertEquals(JSON_MIME, jsonMojoNdefMessage.data[0].mediaType); assertEquals(JSON_MIME, jsonMojoNdefMessage.data[0].mediaType);
assertEquals(true, jsonMojoNdefMessage.data[0].id.isEmpty()); assertEquals(true, jsonMojoNdefMessage.data[0].id.isEmpty());
assertNull(jsonMojoNdefMessage.data[0].encoding); assertNull(jsonMojoNdefMessage.data[0].encoding);
...@@ -363,7 +363,7 @@ public class NFCTest { ...@@ -363,7 +363,7 @@ public class NFCTest {
NdefMessage webMojoNdefMessage = NdefMessageUtils.toNdefMessage(webNdefMessage); NdefMessage webMojoNdefMessage = NdefMessageUtils.toNdefMessage(webNdefMessage);
assertEquals(TEST_URL, webMojoNdefMessage.url); assertEquals(TEST_URL, webMojoNdefMessage.url);
assertEquals(1, webMojoNdefMessage.data.length); assertEquals(1, webMojoNdefMessage.data.length);
assertEquals(NdefMessageUtils.RECORD_TYPE_JSON, webMojoNdefMessage.data[0].recordType); assertEquals(NdefMessageUtils.RECORD_TYPE_MIME, webMojoNdefMessage.data[0].recordType);
assertEquals(JSON_MIME, webMojoNdefMessage.data[0].mediaType); assertEquals(JSON_MIME, webMojoNdefMessage.data[0].mediaType);
assertNull(webMojoNdefMessage.data[0].encoding); assertNull(webMojoNdefMessage.data[0].encoding);
assertNull(webMojoNdefMessage.data[0].lang); assertNull(webMojoNdefMessage.data[0].lang);
...@@ -468,9 +468,9 @@ public class NFCTest { ...@@ -468,9 +468,9 @@ public class NFCTest {
assertEquals(android.nfc.NdefRecord.TNF_EXTERNAL_TYPE, assertEquals(android.nfc.NdefRecord.TNF_EXTERNAL_TYPE,
utf16TextNdefMessage.getRecords()[1].getTnf()); utf16TextNdefMessage.getRecords()[1].getTnf());
// Test MIME record conversion. // Test mime record conversion with "text/plain" mime type.
NdefRecord mimeMojoNdefRecord = new NdefRecord(); NdefRecord mimeMojoNdefRecord = new NdefRecord();
mimeMojoNdefRecord.recordType = NdefMessageUtils.RECORD_TYPE_OPAQUE; mimeMojoNdefRecord.recordType = NdefMessageUtils.RECORD_TYPE_MIME;
mimeMojoNdefRecord.mediaType = TEXT_MIME; mimeMojoNdefRecord.mediaType = TEXT_MIME;
mimeMojoNdefRecord.data = ApiCompatibilityUtils.getBytesUtf8(TEST_TEXT); mimeMojoNdefRecord.data = ApiCompatibilityUtils.getBytesUtf8(TEST_TEXT);
NdefMessage mimeMojoNdefMessage = createMojoNdefMessage(TEST_URL, mimeMojoNdefRecord); NdefMessage mimeMojoNdefMessage = createMojoNdefMessage(TEST_URL, mimeMojoNdefRecord);
...@@ -484,9 +484,9 @@ public class NFCTest { ...@@ -484,9 +484,9 @@ public class NFCTest {
assertEquals( assertEquals(
android.nfc.NdefRecord.TNF_EXTERNAL_TYPE, mimeNdefMessage.getRecords()[1].getTnf()); android.nfc.NdefRecord.TNF_EXTERNAL_TYPE, mimeNdefMessage.getRecords()[1].getTnf());
// Test JSON record conversion. // Test mime record conversion with "application/json" mime type.
NdefRecord jsonMojoNdefRecord = new NdefRecord(); NdefRecord jsonMojoNdefRecord = new NdefRecord();
jsonMojoNdefRecord.recordType = NdefMessageUtils.RECORD_TYPE_OPAQUE; jsonMojoNdefRecord.recordType = NdefMessageUtils.RECORD_TYPE_MIME;
jsonMojoNdefRecord.mediaType = JSON_MIME; jsonMojoNdefRecord.mediaType = JSON_MIME;
jsonMojoNdefRecord.data = ApiCompatibilityUtils.getBytesUtf8(TEST_JSON); jsonMojoNdefRecord.data = ApiCompatibilityUtils.getBytesUtf8(TEST_JSON);
NdefMessage jsonMojoNdefMessage = createMojoNdefMessage(TEST_URL, jsonMojoNdefRecord); NdefMessage jsonMojoNdefMessage = createMojoNdefMessage(TEST_URL, jsonMojoNdefRecord);
......
...@@ -210,53 +210,13 @@ static NDEFRecord* CreateUrlRecord(const String& record_type, ...@@ -210,53 +210,13 @@ static NDEFRecord* CreateUrlRecord(const String& record_type,
GetUTF8DataFromString(url)); GetUTF8DataFromString(url));
} }
static NDEFRecord* CreateJsonRecord(const String& media_type, static NDEFRecord* CreateMimeRecord(const String& media_type,
const ScriptValue& data, const ScriptValue& data,
ExceptionState& exception_state) { ExceptionState& exception_state) {
// https://w3c.github.io/web-nfc/#mapping-json-to-ndef
if (data.IsEmpty()) {
exception_state.ThrowTypeError(
"The data for 'json' NDEFRecord is missing.");
return nullptr;
}
// ExtractMIMETypeFromMediaType() ignores parameters of the MIME type.
String mime_type = ExtractMIMETypeFromMediaType(AtomicString(media_type));
if (mime_type.IsEmpty()) {
mime_type = "application/json";
} else if (mime_type != "application/json" && mime_type != "text/json" &&
!mime_type.EndsWithIgnoringASCIICase("+json")) {
// According to https://mimesniff.spec.whatwg.org/#json-mime-type, a JSON
// MIME type is any MIME type whose subtype ends in "+json" or whose
// essence is "application/json" or "text/json".
exception_state.ThrowDOMException(DOMExceptionCode::kSyntaxError,
"Invalid media type for 'json' record.");
return nullptr;
}
// Serialize JSON to bytes, rethrow any exceptions.
v8::Local<v8::String> jsonString;
v8::TryCatch try_catch(data.GetIsolate());
if (!v8::JSON::Stringify(data.GetIsolate()->GetCurrentContext(),
data.V8Value())
.ToLocal(&jsonString)) {
DCHECK(try_catch.HasCaught());
exception_state.RethrowV8Exception(try_catch.Exception());
return nullptr;
}
return MakeGarbageCollected<NDEFRecord>(
"json", mime_type,
GetUTF8DataFromString(
ToBlinkString<String>(jsonString, kDoNotExternalize)));
}
static NDEFRecord* CreateOpaqueRecord(const String& media_type,
const ScriptValue& data,
ExceptionState& exception_state) {
// https://w3c.github.io/web-nfc/#mapping-binary-data-to-ndef // https://w3c.github.io/web-nfc/#mapping-binary-data-to-ndef
if (data.IsEmpty() || !data.V8Value()->IsArrayBuffer()) { if (!IsBufferSource(data)) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"The data for 'opaque' NDEFRecord must be an ArrayBuffer."); "The data for 'mime' NDEFRecord must be a BufferSource.");
return nullptr; return nullptr;
} }
...@@ -265,13 +225,8 @@ static NDEFRecord* CreateOpaqueRecord(const String& media_type, ...@@ -265,13 +225,8 @@ static NDEFRecord* CreateOpaqueRecord(const String& media_type,
if (mime_type.IsEmpty()) { if (mime_type.IsEmpty()) {
mime_type = "application/octet-stream"; mime_type = "application/octet-stream";
} }
DOMArrayBuffer* array_buffer = return MakeGarbageCollected<NDEFRecord>("mime", mime_type,
V8ArrayBuffer::ToImpl(data.V8Value().As<v8::Object>()); GetBytesOfBufferSource(data));
WTF::Vector<uint8_t> bytes;
bytes.Append(static_cast<uint8_t*>(array_buffer->Data()),
array_buffer->ByteLength());
return MakeGarbageCollected<NDEFRecord>("opaque", mime_type,
std::move(bytes));
} }
static NDEFRecord* CreateUnknownRecord(const String& media_type, static NDEFRecord* CreateUnknownRecord(const String& media_type,
...@@ -322,10 +277,8 @@ NDEFRecord* NDEFRecord::Create(const ExecutionContext* execution_context, ...@@ -322,10 +277,8 @@ NDEFRecord* NDEFRecord::Create(const ExecutionContext* execution_context,
v8::Local<v8::Value> data = init->data().V8Value(); v8::Local<v8::Value> data = init->data().V8Value();
if (data->IsString()) { if (data->IsString()) {
record_type = "text"; record_type = "text";
} else if (data->IsArrayBuffer()) {
record_type = "opaque";
} else { } else {
record_type = "json"; record_type = "mime";
} }
} else { } else {
record_type = init->recordType(); record_type = init->recordType();
...@@ -343,10 +296,8 @@ NDEFRecord* NDEFRecord::Create(const ExecutionContext* execution_context, ...@@ -343,10 +296,8 @@ NDEFRecord* NDEFRecord::Create(const ExecutionContext* execution_context,
} else if (record_type == "url" || record_type == "absolute-url") { } else if (record_type == "url" || record_type == "absolute-url") {
return CreateUrlRecord(record_type, init->mediaType(), init->data(), return CreateUrlRecord(record_type, init->mediaType(), init->data(),
exception_state); exception_state);
} else if (record_type == "json") { } else if (record_type == "mime") {
return CreateJsonRecord(init->mediaType(), init->data(), exception_state); return CreateMimeRecord(init->mediaType(), init->data(), exception_state);
} else if (record_type == "opaque") {
return CreateOpaqueRecord(init->mediaType(), init->data(), exception_state);
} else if (record_type == "unknown") { } else if (record_type == "unknown") {
return CreateUnknownRecord(init->mediaType(), init->data(), return CreateUnknownRecord(init->mediaType(), init->data(),
exception_state); exception_state);
...@@ -391,7 +342,7 @@ NDEFRecord::NDEFRecord(const ExecutionContext* execution_context, ...@@ -391,7 +342,7 @@ NDEFRecord::NDEFRecord(const ExecutionContext* execution_context,
payload_data_(GetUTF8DataFromString(text)) {} payload_data_(GetUTF8DataFromString(text)) {}
NDEFRecord::NDEFRecord(WTF::Vector<uint8_t> payload_data) NDEFRecord::NDEFRecord(WTF::Vector<uint8_t> payload_data)
: record_type_("opaque"), : record_type_("mime"),
media_type_("application/octet-stream"), media_type_("application/octet-stream"),
payload_data_(std::move(payload_data)) {} payload_data_(std::move(payload_data)) {}
...@@ -445,8 +396,7 @@ DOMArrayBuffer* NDEFRecord::arrayBuffer() const { ...@@ -445,8 +396,7 @@ DOMArrayBuffer* NDEFRecord::arrayBuffer() const {
record_type_ == "url" || record_type_ == "absolute-url") { record_type_ == "url" || record_type_ == "absolute-url") {
return nullptr; return nullptr;
} }
DCHECK(record_type_ == "json" || record_type_ == "opaque" || DCHECK(record_type_ == "mime" || record_type_ == "unknown" ||
record_type_ == "unknown" ||
!ValidateCustomRecordType(record_type_).IsNull()); !ValidateCustomRecordType(record_type_).IsNull());
return DOMArrayBuffer::Create(payload_data_.data(), payload_data_.size()); return DOMArrayBuffer::Create(payload_data_.data(), payload_data_.size());
...@@ -458,8 +408,7 @@ ScriptValue NDEFRecord::json(ScriptState* script_state, ...@@ -458,8 +408,7 @@ ScriptValue NDEFRecord::json(ScriptState* script_state,
record_type_ == "url" || record_type_ == "absolute-url") { record_type_ == "url" || record_type_ == "absolute-url") {
return ScriptValue::CreateNull(script_state->GetIsolate()); return ScriptValue::CreateNull(script_state->GetIsolate());
} }
DCHECK(record_type_ == "json" || record_type_ == "opaque" || DCHECK(record_type_ == "mime" || record_type_ == "unknown" ||
record_type_ == "unknown" ||
!ValidateCustomRecordType(record_type_).IsNull()); !ValidateCustomRecordType(record_type_).IsNull());
ScriptState::Scope scope(script_state); ScriptState::Scope scope(script_state);
......
...@@ -33,7 +33,7 @@ class MODULES_EXPORT NDEFRecord final : public ScriptWrappable { ...@@ -33,7 +33,7 @@ class MODULES_EXPORT NDEFRecord final : public ScriptWrappable {
// Construct a "text" record from a string. // Construct a "text" record from a string.
explicit NDEFRecord(const ExecutionContext*, const String&); explicit NDEFRecord(const ExecutionContext*, const String&);
// Construct a "opaque" record from the raw payload bytes. // Construct a "mime" record from the raw payload bytes.
explicit NDEFRecord(WTF::Vector<uint8_t> payload_data); explicit NDEFRecord(WTF::Vector<uint8_t> payload_data);
NDEFRecord(const String&, const String&, WTF::Vector<uint8_t>); NDEFRecord(const String&, const String&, WTF::Vector<uint8_t>);
......
...@@ -16,56 +16,49 @@ const NDEFReaderOptionTests = ...@@ -16,56 +16,49 @@ const NDEFReaderOptionTests =
desc: "Test that reading data succeed when NDEFScanOptions'" + desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to 'empty'.", " recordType is set to 'empty'.",
scanOptions: {recordType: "empty"}, scanOptions: {recordType: "empty"},
unmatchedScanOptions: {recordType: "json"}, unmatchedScanOptions: {recordType: "mime"},
message: createMessage([createRecord('empty', '')]) message: createMessage([createRecord('empty', '')])
}, },
{ {
desc: "Test that reading data succeed when NDEFScanOptions'" + desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to 'json'.", " recordType is set to 'mime'.",
scanOptions: {recordType: "json"}, scanOptions: {recordType: "mime"},
unmatchedScanOptions: {recordType: "url"}, unmatchedScanOptions: {recordType: "url"},
message: createMessage([createJsonRecord(test_json_data)]) message: createMessage([createMimeRecord(test_buffer_data)])
},
{
desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to 'opaque'.",
scanOptions: {recordType: "opaque"},
unmatchedScanOptions: {recordType: "json"},
message: createMessage([createOpaqueRecord(test_buffer_data)])
}, },
{ {
desc: "Test that reading data succeed when NDEFScanOptions'" + desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to 'unknown'.", " recordType is set to 'unknown'.",
scanOptions: {recordType: "unknown"}, scanOptions: {recordType: "unknown"},
unmatchedScanOptions: {recordType: "json"}, unmatchedScanOptions: {recordType: "mime"},
message: createMessage([createUnknownRecord(test_buffer_data)]) message: createMessage([createUnknownRecord(test_buffer_data)])
}, },
{ {
desc: "Test that reading data succeed when NDEFScanOptions'" + desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to 'text'.", " recordType is set to 'text'.",
scanOptions: {recordType: "text"}, scanOptions: {recordType: "text"},
unmatchedScanOptions: {recordType: "json"}, unmatchedScanOptions: {recordType: "url"},
message: createMessage([createTextRecord(test_text_data)]) message: createMessage([createTextRecord(test_text_data)])
}, },
{ {
desc: "Test that reading data succeed when NDEFScanOptions'" + desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to 'url'.", " recordType is set to 'url'.",
scanOptions: {recordType: "url"}, scanOptions: {recordType: "url"},
unmatchedScanOptions: {recordType: "json"}, unmatchedScanOptions: {recordType: "absolute-url"},
message: createMessage([createUrlRecord(test_url_data)]) message: createMessage([createUrlRecord(test_url_data)])
}, },
{ {
desc: "Test that reading data succeed when NDEFScanOptions'" + desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to 'absolute-url'.", " recordType is set to 'absolute-url'.",
scanOptions: {recordType: "absolute-url"}, scanOptions: {recordType: "absolute-url"},
unmatchedScanOptions: {recordType: "json"}, unmatchedScanOptions: {recordType: "url"},
message: createMessage([createUrlRecord(test_url_data, true)]) message: createMessage([createUrlRecord(test_url_data, true)])
}, },
{ {
desc: "Test that reading data succeed when NDEFScanOptions'" + desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to a custom type for external type records.", " recordType is set to a custom type for external type records.",
scanOptions: {recordType: "w3.org:xyz"}, scanOptions: {recordType: "w3.org:xyz"},
unmatchedScanOptions: {recordType: "opaque"}, unmatchedScanOptions: {recordType: "mime"},
message: createMessage([createRecord('w3.org:xyz', 'application/octet-stream', message: createMessage([createRecord('w3.org:xyz', 'application/octet-stream',
test_buffer_data)]) test_buffer_data)])
}, },
...@@ -82,7 +75,7 @@ const NDEFReaderOptionTests = ...@@ -82,7 +75,7 @@ const NDEFReaderOptionTests =
" sources correctly.", " sources correctly.",
scanOptions: {mediaType: "application/octet-stream"}, scanOptions: {mediaType: "application/octet-stream"},
unmatchedScanOptions: {mediaType: "application/json"}, unmatchedScanOptions: {mediaType: "application/json"},
message: createMessage([createOpaqueRecord(test_buffer_data)]) message: createMessage([createMimeRecord(test_buffer_data)])
} }
]; ];
...@@ -93,21 +86,14 @@ const ReadMultiMessagesTests = ...@@ -93,21 +86,14 @@ const ReadMultiMessagesTests =
" correctly with NDEFScanOptions' recordType is set to 'empty'.", " correctly with NDEFScanOptions' recordType is set to 'empty'.",
scanOptions: {recordType: "empty"}, scanOptions: {recordType: "empty"},
message: createMessage([createRecord('empty', '')]), message: createMessage([createRecord('empty', '')]),
unmatchedMessage: createMessage([createJsonRecord(test_json_data)]), unmatchedMessage: createMessage([createMimeRecordFromJson(test_json_data)]),
},
{
desc: "Test that filtering 'json' record from different messages" +
" correctly with NDEFScanOptions' recordType is set to 'json'.",
scanOptions: {recordType: "json"},
message: createMessage([createJsonRecord(test_json_data)]),
unmatchedMessage: createMessage([createUrlRecord(test_url_data)])
}, },
{ {
desc: "Test that filtering 'opaque' record from different messages" + desc: "Test that filtering 'mime' record from different messages" +
" correctly with NDEFScanOptions' recordType is set to 'opaque'.", " correctly with NDEFScanOptions' recordType is set to 'mime'.",
scanOptions: {recordType: "opaque"}, scanOptions: {recordType: "mime"},
message: createMessage([createOpaqueRecord(test_buffer_data)]), message: createMessage([createMimeRecord(test_buffer_data)]),
unmatchedMessage: createMessage([createJsonRecord(test_json_data)]) unmatchedMessage: createMessage([createUnknownRecord(test_buffer_data)])
}, },
{ {
desc: "Test that filtering 'unknown' record from different messages" + desc: "Test that filtering 'unknown' record from different messages" +
...@@ -155,11 +141,11 @@ const ReadMultiMessagesTests = ...@@ -155,11 +141,11 @@ const ReadMultiMessagesTests =
records: [createUrlRecord(test_url_data)]} records: [createUrlRecord(test_url_data)]}
}, },
{ {
desc: "Test that filtering 'opaque' record from different messages" + desc: "Test that filtering 'mime' record from different messages" +
" correctly with NDEFScanOptions' mediaType set.", " correctly with NDEFScanOptions' mediaType set.",
scanOptions: {mediaType: "application/octet-stream"}, scanOptions: {mediaType: "application/octet-stream"},
message: createMessage([createOpaqueRecord(test_buffer_data)]), message: createMessage([createMimeRecord(test_buffer_data)]),
unmatchedMessage: createMessage([createJsonRecord(test_json_data)]) unmatchedMessage: createMessage([createMimeRecordFromJson(test_json_data)])
} }
]; ];
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
}, 'NDEFReadingEvent constructor without init dict'); }, 'NDEFReadingEvent constructor without init dict');
test(() => { test(() => {
const message = createMessage([createJsonRecord(test_json_data)]); const message = createMessage([createMimeRecordFromJson(test_buffer_data)]);
const event = new NDEFReadingEvent('type', {serialNumber: null, message: message}); const event = new NDEFReadingEvent('type', {serialNumber: null, message: message});
assert_equals(event.serialNumber, '', 'serialNumber'); assert_equals(event.serialNumber, '', 'serialNumber');
}, 'NDEFReadingEvent constructor with null serialNumber'); }, 'NDEFReadingEvent constructor with null serialNumber');
test(() => { test(() => {
const message = createMessage([createJsonRecord(test_json_data)]); const message = createMessage([createMimeRecordFromJson(test_buffer_data)]);
const event = new NDEFReadingEvent('type', {message: message}); const event = new NDEFReadingEvent('type', {message: message});
assert_equals(event.serialNumber, '', 'serialNumber'); assert_equals(event.serialNumber, '', 'serialNumber');
}, 'NDEFReadingEvent constructor with serialNumber not present'); }, 'NDEFReadingEvent constructor with serialNumber not present');
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
}, 'NDEFReadingEvent constructor with null message'); }, 'NDEFReadingEvent constructor with null message');
test(() => { test(() => {
const message = createMessage([createJsonRecord(test_json_data)]); const message = createMessage([createMimeRecord(test_buffer_data)]);
const event = new NDEFReadingEvent('type', {serialNumber: '', message: message}); const event = new NDEFReadingEvent('type', {serialNumber: '', message: message});
assert_equals(event.type, 'type', 'type'); assert_equals(event.type, 'type', 'type');
assert_equals(event.serialNumber, '', 'serialNumber'); assert_equals(event.serialNumber, '', 'serialNumber');
......
...@@ -108,12 +108,16 @@ ...@@ -108,12 +108,16 @@
}, 'NDEFRecord constructor with absolute-url record type'); }, 'NDEFRecord constructor with absolute-url record type');
test(() => { test(() => {
assert_throws(new TypeError, () => new NDEFRecord(
createMimeRecord("A string is not a BufferSource")),
'Only BufferSource is allowed to be the record data.');
let buffer = new ArrayBuffer(4); let buffer = new ArrayBuffer(4);
let buffer_view = new Uint8Array(buffer); let buffer_view = new Uint8Array(buffer);
let original_data = new Uint8Array([1, 2, 3, 4]); let original_data = new Uint8Array([1, 2, 3, 4]);
buffer_view.set(original_data); buffer_view.set(original_data);
const record = new NDEFRecord(createOpaqueRecord(buffer)); const record = new NDEFRecord(createMimeRecord(buffer));
assert_equals(record.recordType, 'opaque', 'recordType'); assert_equals(record.recordType, 'mime', 'recordType');
assert_equals(record.mediaType, 'application/octet-stream', 'mediaType'); assert_equals(record.mediaType, 'application/octet-stream', 'mediaType');
assert_array_equals(new Uint8Array(record.data.buffer), original_data, assert_array_equals(new Uint8Array(record.data.buffer), original_data,
'data has the same content with the original buffer'); 'data has the same content with the original buffer');
...@@ -140,11 +144,11 @@ ...@@ -140,11 +144,11 @@
'Modifying the original buffer does not affect arrayBuffer() content'); 'Modifying the original buffer does not affect arrayBuffer() content');
assert_array_equals(new Uint8Array(data_3), original_data, assert_array_equals(new Uint8Array(data_3), original_data,
'Modifying the original buffer does not affect arrayBuffer() content'); 'Modifying the original buffer does not affect arrayBuffer() content');
}, 'NDEFRecord constructor with opaque record type'); }, 'NDEFRecord constructor with mime record type and stream data');
test(() => { test(() => {
const record = new NDEFRecord(createJsonRecord(test_json_data)); const record = new NDEFRecord(createMimeRecordFromJson(test_json_data));
assert_equals(record.recordType, 'json', 'recordType'); assert_equals(record.recordType, 'mime', 'recordType');
assert_equals(record.mediaType, 'application/json', 'mediaType'); assert_equals(record.mediaType, 'application/json', 'mediaType');
const data_1 = record.json(); const data_1 = record.json();
...@@ -159,7 +163,7 @@ ...@@ -159,7 +163,7 @@
'json() again returns another new object'); 'json() again returns another new object');
assert_object_equals(data_2, test_json_data, assert_object_equals(data_2, test_json_data,
'json() has the same content with the original dictionary'); 'json() has the same content with the original dictionary');
}, 'NDEFRecord constructor with JSON record type'); }, 'NDEFRecord constructor with mime record type and json data');
test(() => { test(() => {
assert_throws(new TypeError, () => new NDEFRecord( assert_throws(new TypeError, () => new NDEFRecord(
......
...@@ -12,11 +12,10 @@ PASS NDEFWriter.push should fail with TypeError when invalid negative timeout va ...@@ -12,11 +12,10 @@ PASS NDEFWriter.push should fail with TypeError when invalid negative timeout va
PASS NDEFWriter.push should fail with TimeoutError when timer expires. PASS NDEFWriter.push should fail with TimeoutError when timer expires.
PASS Reject promise with NotSupportedError if NFC message size exceeds 32KB. PASS Reject promise with NotSupportedError if NFC message size exceeds 32KB.
PASS Reject promise with SyntaxError if WebNFC Id cannot be created from provided URL. PASS Reject promise with SyntaxError if WebNFC Id cannot be created from provided URL.
PASS Reject promise with exceptions thrown from serializing the 'json' record data.
PASS NDEFWriter.push should fail with TypeError when invalid target value is provided. PASS NDEFWriter.push should fail with TypeError when invalid target value is provided.
PASS Test that WebNFC API is not accessible from iframe context. PASS Test that WebNFC API is not accessible from iframe context.
PASS NDEFWriter.push should succeed when NFC HW is enabled PASS NDEFWriter.push should succeed when NFC HW is enabled
PASS NDEFWriter.push NDEFMessage containing text, json, opaque, unknown, url, absolute-url and external records with default NDEFPushOptions. PASS NDEFWriter.push NDEFMessage containing text, mime, unknown, url, absolute-url and external records with default NDEFPushOptions.
PASS Test that NDEFWriter.push succeeds when message is DOMString. PASS Test that NDEFWriter.push succeeds when message is DOMString.
PASS Test that NDEFWriter.push succeeds when message is ArrayBuffer. PASS Test that NDEFWriter.push succeeds when message is ArrayBuffer.
PASS Test that NDEFWriter.push succeeds when message is ArrayBufferView. PASS Test that NDEFWriter.push succeeds when message is ArrayBufferView.
...@@ -27,11 +26,9 @@ PASS NDEFWriter.push should read data when ignoreRead is false. ...@@ -27,11 +26,9 @@ PASS NDEFWriter.push should read data when ignoreRead is false.
PASS NDEFWriter.push should ignore reading data when ignoreRead is true. PASS NDEFWriter.push should ignore reading data when ignoreRead is true.
PASS NDEFWriter.push should replace all previously configured push operations. PASS NDEFWriter.push should replace all previously configured push operations.
PASS Test that recordType should be set to 'text' if NDEFRecordInit.record's recordType is undefined and NDEFRecordInit.record's data is DOMString. PASS Test that recordType should be set to 'text' if NDEFRecordInit.record's recordType is undefined and NDEFRecordInit.record's data is DOMString.
PASS Test that recordType should be set to 'opaque' if NDEFRecordInit.record's recordType is undefined and NDEFRecordInit.record's data is ArrayBuffer. PASS Test that recordType should be set to 'mime' if NDEFRecordInit.record's recordType is undefined and NDEFRecordInit.record's data is not DOMString.
PASS Test that recordType should be set to 'json' if NDEFRecordInit.record's recordType is undefined and NDEFRecordInit.record's data is not DOMString or ArrayBuffer.
PASS Test that mediaType should be set to 'text/plain' if NDEFRecordInit.record's recordType is 'text' and NDEFRecordInit.record's mediaType is undefined. PASS Test that mediaType should be set to 'text/plain' if NDEFRecordInit.record's recordType is 'text' and NDEFRecordInit.record's mediaType is undefined.
PASS Test that mediaType should be set to 'application/octet-stream' if NDEFRecordInit.record's recordType is 'opaque' and NDEFRecordInit.record's mediaType is undefined. PASS Test that mediaType should be set to 'application/octet-stream' if NDEFRecordInit.record's recordType is 'mime' and NDEFRecordInit.record's mediaType is undefined.
PASS Test that mediaType should be set to 'application/json' if NDEFRecordInit.record's recordType is 'json' and NDEFRecordInit.record's mediaType is undefined.
PASS Test that mediaType should be set to 'application/octet-stream' if NDEFRecordInit.record's recordType is external type and NDEFRecordInit.record's mediaType is undefined. PASS Test that mediaType should be set to 'application/octet-stream' if NDEFRecordInit.record's recordType is external type and NDEFRecordInit.record's mediaType is undefined.
PASS NDEFWriter.push should fail when the NFC device does not expose NDEF technology. PASS NDEFWriter.push should fail when the NFC device does not expose NDEF technology.
PASS NDEFWriter.push should succeed to push data to an unformatted NFC device when the NDEFPushOptions.overwrite is false. PASS NDEFWriter.push should succeed to push data to an unformatted NFC device when the NDEFPushOptions.overwrite is false.
......
...@@ -39,10 +39,6 @@ const invalid_type_messages = ...@@ -39,10 +39,6 @@ const invalid_type_messages =
// NDEFRecord.lang length for 'text' record must be lower than 64. // NDEFRecord.lang length for 'text' record must be lower than 64.
createMessage([createTextRecord(test_text_data, undefined /* encoding */, [...Array(64)].map(_ => 'a'))]), createMessage([createTextRecord(test_text_data, undefined /* encoding */, [...Array(64)].map(_ => 'a'))]),
// https://w3c.github.io/web-nfc/#dfn-map-a-json-object-to-ndef
// NDEFRecord must have data.
createMessage([createJsonRecord()]),
// https://w3c.github.io/web-nfc/#dfn-map-a-url-to-ndef // https://w3c.github.io/web-nfc/#dfn-map-a-url-to-ndef
// NDEFRecord must have data. // NDEFRecord must have data.
createMessage([createUrlRecord()]), createMessage([createUrlRecord()]),
...@@ -63,12 +59,12 @@ const invalid_type_messages = ...@@ -63,12 +59,12 @@ const invalid_type_messages =
// https://w3c.github.io/web-nfc/#dfn-map-binary-data-to-ndef // https://w3c.github.io/web-nfc/#dfn-map-binary-data-to-ndef
// NDEFRecord must have data. // NDEFRecord must have data.
createMessage([createOpaqueRecord()]), createMessage([createMimeRecord()]),
// NDEFRecord.data for 'opaque' record must be ArrayBuffer. // NDEFRecord.data for 'mime' record must be BufferSource.
createMessage([createOpaqueRecord(test_text_data)]), createMessage([createMimeRecord(test_text_data)]),
createMessage([createOpaqueRecord(test_number_data)]), createMessage([createMimeRecord(test_number_data)]),
createMessage([createOpaqueRecord(test_json_data)]), createMessage([createMimeRecord(test_json_data)]),
// NDEFRecord must have data. // NDEFRecord must have data.
createMessage([createUnknownRecord()]), createMessage([createUnknownRecord()]),
...@@ -88,7 +84,7 @@ const invalid_type_messages = ...@@ -88,7 +84,7 @@ const invalid_type_messages =
createMessage([createRecord('w3.org:xyz', '', test_json_data)]), createMessage([createRecord('w3.org:xyz', '', test_json_data)]),
// https://w3c.github.io/web-nfc/#the-ndefrecordtype-string // https://w3c.github.io/web-nfc/#the-ndefrecordtype-string
// The record type is neither a known type ('text', 'json' etc.) nor a // The record type is neither a known type ('text', 'mime' etc.) nor a
// valid custom type for an external type record. // valid custom type for an external type record.
createMessage([createRecord('unmatched_type', '', test_buffer_data)]) createMessage([createRecord('unmatched_type', '', test_buffer_data)])
]; ];
...@@ -102,12 +98,6 @@ const invalid_syntax_messages = ...@@ -102,12 +98,6 @@ const invalid_syntax_messages =
// Data for 'url' or 'absolute-url' record, must be a valid URL. // Data for 'url' or 'absolute-url' record, must be a valid URL.
createMessage([createUrlRecord('Invalid URL:// Data')]), createMessage([createUrlRecord('Invalid URL:// Data')]),
createMessage([createUrlRecord('Invalid URL:// Data', true)]), createMessage([createUrlRecord('Invalid URL:// Data', true)]),
// 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+jsonx', test_json_data)]),
]; ];
const invalid_signals = [ const invalid_signals = [
...@@ -247,13 +237,6 @@ promise_test(async t => { ...@@ -247,13 +237,6 @@ promise_test(async t => {
}, "Reject promise with SyntaxError if WebNFC Id cannot be created from \ }, "Reject promise with SyntaxError if WebNFC Id cannot be created from \
provided URL."); provided URL.");
promise_test(async t => {
const writer = new NDEFWriter();
const message = createMessage([createRecord('json','application/json',
{ get x(){ return this; } })]);
await promise_rejects(t, new TypeError(), writer.push(message));
}, "Reject promise with exceptions thrown from serializing the 'json' record data.");
promise_test(async t => { promise_test(async t => {
const writer = new NDEFWriter(); const writer = new NDEFWriter();
await promise_rejects( await promise_rejects(
...@@ -306,9 +289,8 @@ nfc_test(async () => { ...@@ -306,9 +289,8 @@ nfc_test(async () => {
nfc_test(async (t, mockNFC) => { nfc_test(async (t, mockNFC) => {
const writer = new NDEFWriter(); const writer = new NDEFWriter();
let message = createMessage([createTextRecord(test_text_data), let message = createMessage([createTextRecord(test_text_data),
createJsonRecord(test_json_data), createMimeRecordFromJson(test_json_data),
createJsonRecord(test_number_data), createMimeRecord(test_buffer_data),
createOpaqueRecord(test_buffer_data),
createUnknownRecord(test_buffer_data), createUnknownRecord(test_buffer_data),
createUrlRecord(test_url_data), createUrlRecord(test_url_data),
createUrlRecord(test_url_data, true), createUrlRecord(test_url_data, true),
...@@ -316,7 +298,7 @@ nfc_test(async (t, mockNFC) => { ...@@ -316,7 +298,7 @@ nfc_test(async (t, mockNFC) => {
test_message_origin); test_message_origin);
await writer.push(message); await writer.push(message);
assertNDEFMessagesEqual(message, mockNFC.pushedMessage()); assertNDEFMessagesEqual(message, mockNFC.pushedMessage());
}, "NDEFWriter.push NDEFMessage containing text, json, opaque, unknown, url, absolute-url \ }, "NDEFWriter.push NDEFMessage containing text, mime, unknown, url, absolute-url \
and external records with default NDEFPushOptions."); and external records with default NDEFPushOptions.");
nfc_test(async (t, mockNFC) => { nfc_test(async (t, mockNFC) => {
...@@ -427,17 +409,8 @@ nfc_test(async (t, mockNFC) => { ...@@ -427,17 +409,8 @@ nfc_test(async (t, mockNFC) => {
const writer = new NDEFWriter(); const writer = new NDEFWriter();
await writer.push({ records: [{ data: test_buffer_data}] }); await writer.push({ records: [{ data: test_buffer_data}] });
assertNDEFMessagesEqual(test_buffer_data, mockNFC.pushedMessage()); assertNDEFMessagesEqual(test_buffer_data, mockNFC.pushedMessage());
}, "Test that recordType should be set to 'opaque' if NDEFRecordInit.record's \ }, "Test that recordType should be set to 'mime' if NDEFRecordInit.record's \
recordType is undefined and NDEFRecordInit.record's data is ArrayBuffer."); recordType is undefined and NDEFRecordInit.record's data is not DOMString.");
nfc_test(async (t, mockNFC) => {
const writer = new NDEFWriter();
await writer.push({ records: [{ data: test_json_data }] });
const message = createMessage([createJsonRecord(test_json_data)]);
assertNDEFMessagesEqual(message, mockNFC.pushedMessage());
}, "Test that recordType should be set to 'json' if NDEFRecordInit.record's \
recordType is undefined and NDEFRecordInit.record's data is not DOMString or \
ArrayBuffer.");
nfc_test(async (t, mockNFC) => { nfc_test(async (t, mockNFC) => {
const writer = new NDEFWriter(); const writer = new NDEFWriter();
...@@ -448,19 +421,10 @@ recordType is 'text' and NDEFRecordInit.record's mediaType is undefined."); ...@@ -448,19 +421,10 @@ recordType is 'text' and NDEFRecordInit.record's mediaType is undefined.");
nfc_test(async (t, mockNFC) => { nfc_test(async (t, mockNFC) => {
const writer = new NDEFWriter(); const writer = new NDEFWriter();
await writer.push({ records: [{ recordType: "opaque", data: test_buffer_data }] }); await writer.push({ records: [{ recordType: "mime", data: test_buffer_data }] });
assertNDEFMessagesEqual(test_buffer_data, mockNFC.pushedMessage()); assertNDEFMessagesEqual(test_buffer_data, mockNFC.pushedMessage());
}, "Test that mediaType should be set to 'application/octet-stream' if \ }, "Test that mediaType should be set to 'application/octet-stream' if \
NDEFRecordInit.record's recordType is 'opaque' and NDEFRecordInit.record's \ NDEFRecordInit.record's recordType is 'mime' and NDEFRecordInit.record's \
mediaType is undefined.");
nfc_test(async (t, mockNFC) => {
const writer = new NDEFWriter();
await writer.push({ records: [{ recordType: "json", data: test_json_data }] });
const message = createMessage([createJsonRecord(test_json_data)]);
assertNDEFMessagesEqual(message, mockNFC.pushedMessage());
}, "Test that mediaType should be set to 'application/json' if \
NDEFRecordInit.record's recordType is 'json' and NDEFRecordInit.record's \
mediaType is undefined."); mediaType is undefined.");
nfc_test(async (t, mockNFC) => { nfc_test(async (t, mockNFC) => {
......
...@@ -103,12 +103,14 @@ function createTextRecord(data, encoding, lang) { ...@@ -103,12 +103,14 @@ function createTextRecord(data, encoding, lang) {
return createRecord('text', 'text/plain', data, encoding, lang); return createRecord('text', 'text/plain', data, encoding, lang);
} }
function createJsonRecord(json) { function createMimeRecordFromJson(json) {
return createRecord('json', 'application/json', json); return createRecord(
'mime', 'application/json',
new TextEncoder('utf-8').encode(JSON.stringify(json)));
} }
function createOpaqueRecord(buffer) { function createMimeRecord(buffer) {
return createRecord('opaque', 'application/octet-stream', buffer); return createRecord('mime', 'application/octet-stream', buffer);
} }
function createUnknownRecord(buffer) { function createUnknownRecord(buffer) {
...@@ -136,7 +138,7 @@ function assertNDEFMessagesEqual(providedMessage, receivedMessage) { ...@@ -136,7 +138,7 @@ 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([createOpaqueRecord(providedMessage)]); provided = createMessage([createMimeRecord(providedMessage)]);
else if (typeof providedMessage === 'string') else if (typeof providedMessage === 'string')
provided = createMessage([createTextRecord(providedMessage)]); provided = createMessage([createTextRecord(providedMessage)]);
......
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