Commit 1905d7a9 authored by Rijubrata Bhaumik's avatar Rijubrata Bhaumik Committed by Commit Bot

[webnfc] Prefix NDEF related objects with NDEF instead of NFC.

Rename NFCMessage to NDEFMessage.

nfc_message.idl -> ndef_message.idl

git grep -l 'NFCMessage' | xargs sed -i 's/NFCMessage/NDEFMessage/g'

git grep -l 'NfcMessage' | xargs sed -i 's/NfcMessage/NdefMessage/g'

Java does not allow to import same className from different packages,
which in this case is NdefMessage
So not importing android.nfc.NdefMessage and using fully qualified name
to avoid ambiguity.

Repeat the same for NFCRecord -> NDEFRecord.

Spec changes for this corresponding CL:
https://github.com/w3c/web-nfc/commit/5b74305be004a8e758d4931f8409bd354bc4039e

Bug: 520391
Change-Id: Ib88e0db5c9cd7fa973170f93c5f5352dcda6630e
Reviewed-on: https://chromium-review.googlesource.com/c/1481296Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Rijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Cr-Commit-Position: refs/heads/master@{#635927}
parent 764db2c5
...@@ -11,10 +11,10 @@ android_library("java") { ...@@ -11,10 +11,10 @@ android_library("java") {
"//services/device:*", "//services/device:*",
] ]
java_files = [ java_files = [
"java/src/org/chromium/device/nfc/InvalidNfcMessageException.java", "java/src/org/chromium/device/nfc/InvalidNdefMessageException.java",
"java/src/org/chromium/device/nfc/NfcProviderImpl.java", "java/src/org/chromium/device/nfc/NfcProviderImpl.java",
"java/src/org/chromium/device/nfc/NfcImpl.java", "java/src/org/chromium/device/nfc/NfcImpl.java",
"java/src/org/chromium/device/nfc/NfcMessageValidator.java", "java/src/org/chromium/device/nfc/NdefMessageValidator.java",
"java/src/org/chromium/device/nfc/NfcTagHandler.java", "java/src/org/chromium/device/nfc/NfcTagHandler.java",
"java/src/org/chromium/device/nfc/NfcTypeConverter.java", "java/src/org/chromium/device/nfc/NfcTypeConverter.java",
] ]
......
...@@ -5,6 +5,6 @@ ...@@ -5,6 +5,6 @@
package org.chromium.device.nfc; package org.chromium.device.nfc;
/** /**
* Exception that raised when NfcMessage is found to be invalid during conversion to NdefMessage. * Exception that raised when NdefMessage is found to be invalid during conversion to NdefMessage.
*/ */
public final class InvalidNfcMessageException extends Exception {} public final class InvalidNdefMessageException extends Exception {}
\ No newline at end of file \ No newline at end of file
...@@ -4,21 +4,21 @@ ...@@ -4,21 +4,21 @@
package org.chromium.device.nfc; package org.chromium.device.nfc;
import org.chromium.device.mojom.NfcMessage; import org.chromium.device.mojom.NdefMessage;
import org.chromium.device.mojom.NfcRecord; import org.chromium.device.mojom.NdefRecord;
import org.chromium.device.mojom.NfcRecordType; import org.chromium.device.mojom.NdefRecordType;
/** /**
* Utility class that provides validation of NfcMessage. * Utility class that provides validation of NdefMessage.
*/ */
public final class NfcMessageValidator { public final class NdefMessageValidator {
/** /**
* Validates NfcMessage. * Validates NdefMessage.
* *
* @param message to be validated. * @param message to be validated.
* @return true if message is valid, false otherwise. * @return true if message is valid, false otherwise.
*/ */
public static boolean isValid(NfcMessage message) { public static boolean isValid(NdefMessage message) {
if (message == null || message.data == null || message.data.length == 0) { if (message == null || message.data == null || message.data.length == 0) {
return false; return false;
} }
...@@ -30,12 +30,12 @@ public final class NfcMessageValidator { ...@@ -30,12 +30,12 @@ public final class NfcMessageValidator {
} }
/** /**
* Checks that NfcRecord#data and NfcRecord#mediaType fields are valid. NfcRecord#data and * Checks that NdefRecord#data and NdefRecord#mediaType fields are valid. NdefRecord#data and
* NfcRecord#mediaType fields are omitted for the record with EMPTY type. * NdefRecord#mediaType fields are omitted for the record with EMPTY type.
*/ */
private static boolean isValid(NfcRecord record) { private static boolean isValid(NdefRecord record) {
if (record == null) return false; if (record == null) return false;
if (record.recordType == NfcRecordType.EMPTY) return true; if (record.recordType == NdefRecordType.EMPTY) return true;
return record.data != null && record.mediaType != null && !record.mediaType.isEmpty(); return record.data != null && record.mediaType != null && !record.mediaType.isEmpty();
} }
} }
...@@ -10,7 +10,6 @@ import android.app.Activity; ...@@ -10,7 +10,6 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.nfc.FormatException; import android.nfc.FormatException;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter; import android.nfc.NfcAdapter;
import android.nfc.NfcAdapter.ReaderCallback; import android.nfc.NfcAdapter.ReaderCallback;
import android.nfc.NfcManager; import android.nfc.NfcManager;
...@@ -24,11 +23,11 @@ import android.util.SparseArray; ...@@ -24,11 +23,11 @@ import android.util.SparseArray;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.device.mojom.NdefMessage;
import org.chromium.device.mojom.Nfc; import org.chromium.device.mojom.Nfc;
import org.chromium.device.mojom.NfcClient; import org.chromium.device.mojom.NfcClient;
import org.chromium.device.mojom.NfcError; import org.chromium.device.mojom.NfcError;
import org.chromium.device.mojom.NfcErrorType; import org.chromium.device.mojom.NfcErrorType;
import org.chromium.device.mojom.NfcMessage;
import org.chromium.device.mojom.NfcPushOptions; import org.chromium.device.mojom.NfcPushOptions;
import org.chromium.device.mojom.NfcPushTarget; import org.chromium.device.mojom.NfcPushTarget;
import org.chromium.device.mojom.NfcWatchMode; import org.chromium.device.mojom.NfcWatchMode;
...@@ -81,7 +80,7 @@ public class NfcImpl implements Nfc { ...@@ -81,7 +80,7 @@ public class NfcImpl implements Nfc {
/** /**
* Object that contains data that was passed to method * Object that contains data that was passed to method
* #push(NfcMessage message, NfcPushOptions options, PushResponse callback) * #push(NdefMessage message, NfcPushOptions options, PushResponse callback)
* @see PendingPushOperation * @see PendingPushOperation
*/ */
private PendingPushOperation mPendingPushOperation; private PendingPushOperation mPendingPushOperation;
...@@ -93,7 +92,7 @@ public class NfcImpl implements Nfc { ...@@ -93,7 +92,7 @@ public class NfcImpl implements Nfc {
private NfcTagHandler mTagHandler; private NfcTagHandler mTagHandler;
/** /**
* Client interface used to deliver NFCMessages for registered watch operations. * Client interface used to deliver NdefMessages for registered watch operations.
* @see #watch * @see #watch
*/ */
private NfcClient mClient; private NfcClient mClient;
...@@ -107,7 +106,7 @@ public class NfcImpl implements Nfc { ...@@ -107,7 +106,7 @@ public class NfcImpl implements Nfc {
* Map of watchId <-> NfcWatchOptions. All NfcWatchOptions are matched against tag that is in * Map of watchId <-> NfcWatchOptions. All NfcWatchOptions are matched against tag that is in
* proximity, when match algorithm (@see #matchesWatchOptions) returns true, watcher with * proximity, when match algorithm (@see #matchesWatchOptions) returns true, watcher with
* corresponding ID would be notified using NfcClient interface. * corresponding ID would be notified using NfcClient interface.
* @see NfcClient#onWatch(int[] id, NfcMessage message) * @see NfcClient#onWatch(int[] id, NdefMessage message)
*/ */
private final SparseArray<NfcWatchOptions> mWatchers = new SparseArray<>(); private final SparseArray<NfcWatchOptions> mWatchers = new SparseArray<>();
...@@ -164,7 +163,7 @@ public class NfcImpl implements Nfc { ...@@ -164,7 +163,7 @@ public class NfcImpl implements Nfc {
/** /**
* Sets NfcClient. NfcClient interface is used to notify mojo NFC service client when NFC * Sets NfcClient. NfcClient interface is used to notify mojo NFC service client when NFC
* device is in proximity and has NfcMessage that matches NfcWatchOptions criteria. * device is in proximity and has NdefMessage that matches NfcWatchOptions criteria.
* @see Nfc#watch(NfcWatchOptions options, WatchResponse callback) * @see Nfc#watch(NfcWatchOptions options, WatchResponse callback)
* *
* @param client @see NfcClient * @param client @see NfcClient
...@@ -175,7 +174,7 @@ public class NfcImpl implements Nfc { ...@@ -175,7 +174,7 @@ public class NfcImpl implements Nfc {
} }
/** /**
* Pushes NfcMessage to Tag or Peer, whenever NFC device is in proximity. At the moment, only * Pushes NdefMessage to Tag or Peer, whenever NFC device is in proximity. At the moment, only
* passive NFC devices are supported (NfcPushTarget.TAG). * passive NFC devices are supported (NfcPushTarget.TAG).
* *
* @param message that should be pushed to NFC device. * @param message that should be pushed to NFC device.
...@@ -183,10 +182,10 @@ public class NfcImpl implements Nfc { ...@@ -183,10 +182,10 @@ public class NfcImpl implements Nfc {
* @param callback that is used to notify when push operation is completed. * @param callback that is used to notify when push operation is completed.
*/ */
@Override @Override
public void push(NfcMessage message, NfcPushOptions options, PushResponse callback) { public void push(NdefMessage message, NfcPushOptions options, PushResponse callback) {
if (!checkIfReady(callback)) return; if (!checkIfReady(callback)) return;
if (!NfcMessageValidator.isValid(message)) { if (!NdefMessageValidator.isValid(message)) {
callback.call(createError(NfcErrorType.INVALID_MESSAGE)); callback.call(createError(NfcErrorType.INVALID_MESSAGE));
return; return;
} }
...@@ -237,13 +236,13 @@ public class NfcImpl implements Nfc { ...@@ -237,13 +236,13 @@ public class NfcImpl implements Nfc {
} }
/** /**
* Watch method allows to set filtering criteria for NfcMessages that are found when NFC device * Watch method allows to set filtering criteria for NdefMessages that are found when NFC device
* is within proximity. On success, watch ID is returned to caller through WatchResponse * is within proximity. On success, watch ID is returned to caller through WatchResponse
* callback. When NfcMessage that matches NfcWatchOptions is found, it is passed to NfcClient * callback. When NdefMessage that matches NfcWatchOptions is found, it is passed to NfcClient
* interface together with corresponding watch ID. * interface together with corresponding watch ID.
* @see NfcClient#onWatch(int[] id, NfcMessage message) * @see NfcClient#onWatch(int[] id, NdefMessage message)
* *
* @param options used to filter NfcMessages, @see NfcWatchOptions. * @param options used to filter NdefMessages, @see NfcWatchOptions.
* @param callback that is used to notify caller when watch() is completed and return watch ID. * @param callback that is used to notify caller when watch() is completed and return watch ID.
*/ */
@Override @Override
...@@ -324,13 +323,13 @@ public class NfcImpl implements Nfc { ...@@ -324,13 +323,13 @@ public class NfcImpl implements Nfc {
* Holds information about pending push operation. * Holds information about pending push operation.
*/ */
private static class PendingPushOperation { private static class PendingPushOperation {
public final NfcMessage nfcMessage; public final NdefMessage ndefMessage;
public final NfcPushOptions nfcPushOptions; public final NfcPushOptions nfcPushOptions;
private final PushResponse mPushResponseCallback; private final PushResponse mPushResponseCallback;
public PendingPushOperation( public PendingPushOperation(
NfcMessage message, NfcPushOptions options, PushResponse callback) { NdefMessage message, NfcPushOptions options, PushResponse callback) {
nfcMessage = message; ndefMessage = message;
nfcPushOptions = options; nfcPushOptions = options;
mPushResponseCallback = callback; mPushResponseCallback = callback;
} }
...@@ -500,10 +499,10 @@ public class NfcImpl implements Nfc { ...@@ -500,10 +499,10 @@ public class NfcImpl implements Nfc {
try { try {
mTagHandler.connect(); mTagHandler.connect();
mTagHandler.write(NfcTypeConverter.toNdefMessage(mPendingPushOperation.nfcMessage)); mTagHandler.write(NfcTypeConverter.toNdefMessage(mPendingPushOperation.ndefMessage));
pendingPushOperationCompleted(null); pendingPushOperationCompleted(null);
} catch (InvalidNfcMessageException e) { } catch (InvalidNdefMessageException e) {
Log.w(TAG, "Cannot write data to NFC tag. Invalid NfcMessage."); Log.w(TAG, "Cannot write data to NFC tag. Invalid NdefMessage.");
pendingPushOperationCompleted(createError(NfcErrorType.INVALID_MESSAGE)); pendingPushOperationCompleted(createError(NfcErrorType.INVALID_MESSAGE));
} catch (TagLostException e) { } catch (TagLostException e) {
Log.w(TAG, "Cannot write data to NFC tag. Tag is lost."); Log.w(TAG, "Cannot write data to NFC tag. Tag is lost.");
...@@ -515,7 +514,7 @@ public class NfcImpl implements Nfc { ...@@ -515,7 +514,7 @@ public class NfcImpl implements Nfc {
} }
/** /**
* Reads NfcMessage from a tag and forwards message to matching method. * Reads NdefMessage from a tag and forwards message to matching method.
*/ */
private void processPendingWatchOperations() { private void processPendingWatchOperations() {
if (mTagHandler == null || mClient == null || mWatchers.size() == 0) return; if (mTagHandler == null || mClient == null || mWatchers.size() == 0) return;
...@@ -530,13 +529,13 @@ public class NfcImpl implements Nfc { ...@@ -530,13 +529,13 @@ public class NfcImpl implements Nfc {
return; return;
} }
NdefMessage message = null; android.nfc.NdefMessage message = null;
try { try {
mTagHandler.connect(); mTagHandler.connect();
message = mTagHandler.read(); message = mTagHandler.read();
if (message.getByteArrayLength() > NfcMessage.MAX_SIZE) { if (message.getByteArrayLength() > NdefMessage.MAX_SIZE) {
Log.w(TAG, "Cannot read data from NFC tag. NfcMessage exceeds allowed size."); Log.w(TAG, "Cannot read data from NFC tag. NdefMessage exceeds allowed size.");
return; return;
} }
} catch (TagLostException e) { } catch (TagLostException e) {
...@@ -550,15 +549,15 @@ public class NfcImpl implements Nfc { ...@@ -550,15 +549,15 @@ public class NfcImpl implements Nfc {
/** /**
* Iterates through active watchers and if any of those match NfcWatchOptions criteria, * Iterates through active watchers and if any of those match NfcWatchOptions criteria,
* delivers NfcMessage to the client. * delivers NdefMessage to the client.
*/ */
private void notifyMatchingWatchers(NdefMessage message) { private void notifyMatchingWatchers(android.nfc.NdefMessage message) {
try { try {
NfcMessage nfcMessage = NfcTypeConverter.toNfcMessage(message); NdefMessage ndefMessage = NfcTypeConverter.toNdefMessage(message);
List<Integer> watchIds = new ArrayList<Integer>(); List<Integer> watchIds = new ArrayList<Integer>();
for (int i = 0; i < mWatchers.size(); i++) { for (int i = 0; i < mWatchers.size(); i++) {
NfcWatchOptions options = mWatchers.valueAt(i); NfcWatchOptions options = mWatchers.valueAt(i);
if (matchesWatchOptions(nfcMessage, options)) watchIds.add(mWatchers.keyAt(i)); if (matchesWatchOptions(ndefMessage, options)) watchIds.add(mWatchers.keyAt(i));
} }
if (watchIds.size() != 0) { if (watchIds.size() != 0) {
...@@ -566,17 +565,17 @@ public class NfcImpl implements Nfc { ...@@ -566,17 +565,17 @@ public class NfcImpl implements Nfc {
for (int i = 0; i < watchIds.size(); ++i) { for (int i = 0; i < watchIds.size(); ++i) {
ids[i] = watchIds.get(i).intValue(); ids[i] = watchIds.get(i).intValue();
} }
mClient.onWatch(ids, nfcMessage); mClient.onWatch(ids, ndefMessage);
} }
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
Log.w(TAG, "Cannot convert NdefMessage to NfcMessage."); Log.w(TAG, "Cannot convert NdefMessage to NdefMessage.");
} }
} }
/** /**
* Implements matching algorithm. * Implements matching algorithm.
*/ */
private boolean matchesWatchOptions(NfcMessage message, NfcWatchOptions options) { private boolean matchesWatchOptions(NdefMessage message, NfcWatchOptions options) {
// Valid WebNFC message must have non-empty url. // Valid WebNFC message must have non-empty url.
if (options.mode == NfcWatchMode.WEBNFC_ONLY if (options.mode == NfcWatchMode.WEBNFC_ONLY
&& (message.url == null || message.url.isEmpty())) { && (message.url == null || message.url.isEmpty())) {
......
...@@ -16,7 +16,7 @@ enum NFCErrorType { ...@@ -16,7 +16,7 @@ enum NFCErrorType {
IO_ERROR IO_ERROR
}; };
enum NFCRecordType { enum NDEFRecordType {
EMPTY, EMPTY,
TEXT, TEXT,
URL, URL,
...@@ -46,20 +46,20 @@ struct NFCError { ...@@ -46,20 +46,20 @@ struct NFCError {
NFCErrorType error_type; NFCErrorType error_type;
}; };
struct NFCRecord { struct NDEFRecord {
// The type of NFCRecord. // The type of NDEFRecord.
NFCRecordType record_type; NDEFRecordType record_type;
// Represents the IANA media type of the NFCRecord data field. // Represents the IANA media type of the NDEFRecord data field.
string? media_type; string? media_type;
// Payload of the NFCRecord. // Payload of the NDEFRecord.
array<uint8> data; array<uint8> data;
}; };
struct NFCMessage { struct NDEFMessage {
// The body of the NFCMessage is a collection of NFCRecord objects. // The body of the NDEFMessage is a collection of NDEFRecord objects.
array<NFCRecord> data; array<NDEFRecord> data;
// The |url| field is an ASCII serialized origin, optionally followed by a URL // The |url| field is an ASCII serialized origin, optionally followed by a URL
// path. It represents Web NFC id, that can be used for matching Web NFC // path. It represents Web NFC id, that can be used for matching Web NFC
...@@ -82,8 +82,8 @@ struct NFCPushOptions { ...@@ -82,8 +82,8 @@ struct NFCPushOptions {
bool ignore_read; bool ignore_read;
}; };
struct NFCRecordTypeFilter { struct NDEFRecordTypeFilter {
NFCRecordType record_type; NDEFRecordType record_type;
}; };
struct NFCWatchOptions { struct NFCWatchOptions {
...@@ -91,7 +91,7 @@ struct NFCWatchOptions { ...@@ -91,7 +91,7 @@ struct NFCWatchOptions {
string? url; string? url;
// Defines filtering constraint for NFC records with specified record type. // Defines filtering constraint for NFC records with specified record type.
NFCRecordTypeFilter? record_filter; NDEFRecordTypeFilter? record_filter;
// Defines media type filtering constraint. // Defines media type filtering constraint.
string? media_type; string? media_type;
...@@ -101,7 +101,7 @@ struct NFCWatchOptions { ...@@ -101,7 +101,7 @@ struct NFCWatchOptions {
}; };
interface NFC { interface NFC {
// NFCClient interface is used to notify |client| when NFCMessage matches one // NFCClient interface is used to notify |client| when NDEFMessage matches one
// or more pending watch operations. // or more pending watch operations.
SetClient(NFCClient client); SetClient(NFCClient client);
...@@ -109,7 +109,7 @@ interface NFC { ...@@ -109,7 +109,7 @@ interface NFC {
// NFCPushOptions specify timeout and type of device where data should be // NFCPushOptions specify timeout and type of device where data should be
// pushed. If timeout is defined and data is not pushed before timeout is // pushed. If timeout is defined and data is not pushed before timeout is
// expired, callback with corresponding error is called. // expired, callback with corresponding error is called.
Push(NFCMessage message, NFCPushOptions? options) => (NFCError? error); Push(NDEFMessage message, NFCPushOptions? options) => (NFCError? error);
// Cancels pending push request. // Cancels pending push request.
CancelPush(NFCPushTarget target) => (NFCError? error); CancelPush(NFCPushTarget target) => (NFCError? error);
...@@ -133,5 +133,5 @@ interface NFC { ...@@ -133,5 +133,5 @@ interface NFC {
}; };
interface NFCClient { interface NFCClient {
OnWatch(array<uint32> watch_ids, NFCMessage message); OnWatch(array<uint32> watch_ids, NDEFMessage message);
}; };
...@@ -68,8 +68,8 @@ bindings_modules_generated_union_type_files = [ ...@@ -68,8 +68,8 @@ bindings_modules_generated_union_type_files = [
"$bindings_modules_v8_output_dir/rendering_context.h", "$bindings_modules_v8_output_dir/rendering_context.h",
"$bindings_modules_v8_output_dir/request_or_usv_string_or_request_or_usv_string_sequence.cc", "$bindings_modules_v8_output_dir/request_or_usv_string_or_request_or_usv_string_sequence.cc",
"$bindings_modules_v8_output_dir/request_or_usv_string_or_request_or_usv_string_sequence.h", "$bindings_modules_v8_output_dir/request_or_usv_string_or_request_or_usv_string_sequence.h",
"$bindings_modules_v8_output_dir/string_or_array_buffer_or_nfc_message.cc", "$bindings_modules_v8_output_dir/string_or_array_buffer_or_ndef_message.cc",
"$bindings_modules_v8_output_dir/string_or_array_buffer_or_nfc_message.h", "$bindings_modules_v8_output_dir/string_or_array_buffer_or_ndef_message.h",
"$bindings_modules_v8_output_dir/string_or_canvas_gradient_or_canvas_pattern.cc", "$bindings_modules_v8_output_dir/string_or_canvas_gradient_or_canvas_pattern.cc",
"$bindings_modules_v8_output_dir/string_or_canvas_gradient_or_canvas_pattern.h", "$bindings_modules_v8_output_dir/string_or_canvas_gradient_or_canvas_pattern.h",
"$bindings_modules_v8_output_dir/string_or_string_sequence_or_constrain_dom_string_parameters.cc", "$bindings_modules_v8_output_dir/string_or_string_sequence_or_constrain_dom_string_parameters.cc",
......
...@@ -602,9 +602,9 @@ modules_dictionary_idl_files = ...@@ -602,9 +602,9 @@ modules_dictionary_idl_files =
"mediastream/media_track_constraints.idl", "mediastream/media_track_constraints.idl",
"mediastream/media_track_settings.idl", "mediastream/media_track_settings.idl",
"mediastream/media_track_supported_constraints.idl", "mediastream/media_track_supported_constraints.idl",
"nfc/nfc_message.idl", "nfc/ndef_message.idl",
"nfc/nfc_push_options.idl", "nfc/nfc_push_options.idl",
"nfc/nfc_record.idl", "nfc/ndef_record.idl",
"nfc/nfc_watch_options.idl", "nfc/nfc_watch_options.idl",
"notifications/get_notification_options.idl", "notifications/get_notification_options.idl",
"notifications/notification_action.idl", "notifications/notification_action.idl",
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// https://w3c.github.io/web-nfc/#the-nfcmessage-dictionary // https://w3c.github.io/web-nfc/#dom-ndefmessage
dictionary NFCMessage { dictionary NDEFMessage {
sequence<NFCRecord> records; sequence<NDEFRecord> records;
USVString url; USVString url;
}; };
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
// https://w3c.github.io/web-nfc/#the-nfcrecord-dictionary // https://w3c.github.io/web-nfc/#the-nfcrecord-dictionary
enum NFCRecordType { "empty", "text", "url", "json", "opaque" }; enum NDEFRecordType { "empty", "text", "url", "json", "opaque" };
// TODO(shalamov): This is blocked by https://crbug.com/524424 // TODO(riju): Fix http://crbug.com/935912
// typedef (DOMString or unrestricted double or ArrayBuffer or Dictionary) NFCRecordData; // typedef (DOMString or unrestricted double or ArrayBuffer or Dictionary) NDEFRecordData;
typedef any NFCRecordData; typedef any NDEFRecordData;
dictionary NFCRecord { dictionary NDEFRecord {
NFCRecordType recordType; NDEFRecordType recordType;
USVString mediaType; USVString mediaType;
NFCRecordData data; NDEFRecordData data;
}; };
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "services/device/public/mojom/nfc.mojom-blink.h" #include "services/device/public/mojom/nfc.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/modules/v8/string_or_array_buffer_or_nfc_message.h" #include "third_party/blink/renderer/bindings/modules/v8/string_or_array_buffer_or_ndef_message.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_message_callback.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_message_callback.h"
#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h" #include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/page/page_visibility_observer.h" #include "third_party/blink/renderer/core/page/page_visibility_observer.h"
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
namespace blink { namespace blink {
class NFCPushOptions; class NFCPushOptions;
using NFCPushMessage = StringOrArrayBufferOrNFCMessage; using NFCPushMessage = StringOrArrayBufferOrNDEFMessage;
class NFCWatchOptions; class NFCWatchOptions;
class ScriptPromiseResolver; class ScriptPromiseResolver;
...@@ -83,7 +83,7 @@ class NFC final : public ScriptWrappable, ...@@ -83,7 +83,7 @@ class NFC final : public ScriptWrappable,
// device::mojom::blink::NFCClient implementation. // device::mojom::blink::NFCClient implementation.
void OnWatch(const Vector<uint32_t>& ids, void OnWatch(const Vector<uint32_t>& ids,
device::mojom::blink::NFCMessagePtr) override; device::mojom::blink::NDEFMessagePtr) override;
private: private:
device::mojom::blink::NFCPtr nfc_; device::mojom::blink::NFCPtr nfc_;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// https://w3c.github.io/web-nfc/#the-nfc-interface // https://w3c.github.io/web-nfc/#the-nfc-interface
typedef (DOMString or ArrayBuffer or NFCMessage) NFCPushMessage; typedef (DOMString or ArrayBuffer or NDEFMessage) NFCPushMessage;
[ [
RuntimeEnabled=WebNFC, RuntimeEnabled=WebNFC,
...@@ -17,4 +17,4 @@ typedef (DOMString or ArrayBuffer or NFCMessage) NFCPushMessage; ...@@ -17,4 +17,4 @@ typedef (DOMString or ArrayBuffer or NFCMessage) NFCPushMessage;
}; };
// https://w3c.github.io/web-nfc/#dom-messagecallback // https://w3c.github.io/web-nfc/#dom-messagecallback
callback MessageCallback = void (NFCMessage message); callback MessageCallback = void (NDEFMessage message);
...@@ -8,7 +8,7 @@ enum NFCWatchMode { "web-nfc-only", "any" }; ...@@ -8,7 +8,7 @@ enum NFCWatchMode { "web-nfc-only", "any" };
dictionary NFCWatchOptions { dictionary NFCWatchOptions {
USVString url = ""; USVString url = "";
NFCRecordType? recordType; NDEFRecordType? recordType;
USVString mediaType = ""; USVString mediaType = "";
NFCWatchMode mode = "web-nfc-only"; NFCWatchMode mode = "web-nfc-only";
}; };
This is a testharness.js-based test. This is a testharness.js-based test.
Harness Error. harness_status.status = 1 , harness_status.message = WebNFC is not supported. Harness Error. harness_status.status = 1 , harness_status.message = WebNFC is not supported.
PASS Test that promise is rejected with TypeError if NFCMessage is invalid. PASS Test that promise is rejected with TypeError if NDEFMessage is invalid.
PASS 'Test that promise is rejected with SyntaxError if NFCMessage contains invalid records. PASS 'Test that promise is rejected with SyntaxError if NDEFMessage contains invalid records.
PASS nfc.push should fail with TypeError when invalid timeout is provided. PASS nfc.push should fail with TypeError when invalid timeout is provided.
PASS nfc.push should fail with TypeError when invalid negative timeout value is provided. PASS nfc.push should fail with TypeError when invalid negative timeout value is provided.
FAIL nfc.push should fail with TimeoutError when timer expires. assert_throws: function "function() { throw e }" threw object "NotSupportedError: NFC operation not supported." that is not a DOMException TimeoutError: property "code" is equal to 9, expected 23 FAIL nfc.push should fail with TimeoutError when timer expires. assert_throws: function "function() { throw e }" threw object "NotSupportedError: NFC operation not supported." that is not a DOMException TimeoutError: property "code" is equal to 9, expected 23
......
...@@ -18,41 +18,41 @@ const invalid_type_messages = ...@@ -18,41 +18,41 @@ const invalid_type_messages =
// Invalid NFCPushMessage type // Invalid NFCPushMessage type
undefined, undefined,
// NFCMessage.records: should have at least 1 valid record. // NDEFMessage.records: should have at least 1 valid record.
// https://w3c.github.io/web-nfc/#the-push-method - Step 8. // https://w3c.github.io/web-nfc/#the-push-method - Step 8.
createMessage([{}]), createMessage([{}]),
// https://w3c.github.io/web-nfc/#dfn-map-text-to-ndef // https://w3c.github.io/web-nfc/#dfn-map-text-to-ndef
// NFCRecord must have data. // NDEFRecord must have data.
createMessage([createTextRecord()]), createMessage([createTextRecord()]),
// NFCRecord.data for 'text' record must be number or string. // NDEFRecord.data for 'text' record must be number or string.
createMessage([createTextRecord(test_buffer_data)]), createMessage([createTextRecord(test_buffer_data)]),
createMessage([createTextRecord(test_json_data)]), createMessage([createTextRecord(test_json_data)]),
// https://w3c.github.io/web-nfc/#dfn-map-a-json-object-to-ndef // https://w3c.github.io/web-nfc/#dfn-map-a-json-object-to-ndef
// NFCRecord must have data. // NDEFRecord must have data.
createMessage([createJsonRecord()]), createMessage([createJsonRecord()]),
// NFCRecord.data for 'json' record must be object. // NDEFRecord.data for 'json' record must be object.
createMessage([createJsonRecord(test_buffer_data)]), createMessage([createJsonRecord(test_buffer_data)]),
createMessage([createJsonRecord(test_number_data)]), createMessage([createJsonRecord(test_number_data)]),
createMessage([createJsonRecord(test_text_data)]), createMessage([createJsonRecord(test_text_data)]),
// https://w3c.github.io/web-nfc/#dfn-map-a-url-to-ndef // https://w3c.github.io/web-nfc/#dfn-map-a-url-to-ndef
// NFCRecord must have data. // NDEFRecord must have data.
createMessage([createUrlRecord()]), createMessage([createUrlRecord()]),
// NFCRecord.data for 'url' record must be string. // NDEFRecord.data for 'url' record must be string.
createMessage([createUrlRecord(test_buffer_data)]), createMessage([createUrlRecord(test_buffer_data)]),
createMessage([createUrlRecord(test_number_data)]), createMessage([createUrlRecord(test_number_data)]),
createMessage([createUrlRecord(test_json_data)]), createMessage([createUrlRecord(test_json_data)]),
// https://w3c.github.io/web-nfc/#dfn-map-binary-data-to-ndef // https://w3c.github.io/web-nfc/#dfn-map-binary-data-to-ndef
// NFCRecord must have data. // NDEFRecord must have data.
createMessage([createOpaqueRecord()]), createMessage([createOpaqueRecord()]),
// NFCRecord.data for 'opaque' record must be ArrayBuffer. // NDEFRecord.data for 'opaque' record must be ArrayBuffer.
createMessage([createOpaqueRecord(test_text_data)]), createMessage([createOpaqueRecord(test_text_data)]),
createMessage([createOpaqueRecord(test_number_data)]), createMessage([createOpaqueRecord(test_number_data)]),
createMessage([createOpaqueRecord(test_json_data)]) createMessage([createOpaqueRecord(test_json_data)])
...@@ -60,14 +60,14 @@ const invalid_type_messages = ...@@ -60,14 +60,14 @@ const invalid_type_messages =
const invalid_syntax_messages = const invalid_syntax_messages =
[ [
// NFCRecord.mediaType for 'text' record must be 'text/*'. // NDEFRecord.mediaType for 'text' record must be 'text/*'.
createMessage([createRecord('text', 'application/json', createMessage([createRecord('text', 'application/json',
test_number_data)]), test_number_data)]),
// Data for 'url' record, must be a valid URL. // Data for 'url' record, must be a valid URL.
createMessage([createUrlRecord('Invalid URL:// Data')]), createMessage([createUrlRecord('Invalid URL:// Data')]),
// NFCRecord.mediaType for 'json' record must be 'application/json' or // NDEFRecord.mediaType for 'json' record must be 'application/json' or
// starts with 'application/' and ends with '+json'. // starts with 'application/' and ends with '+json'.
createMessage([createRecord('json', 'image/png', test_json_data)]), createMessage([createRecord('json', 'image/png', test_json_data)]),
createMessage([createRecord('json', 'application/x+y', test_json_data)]), createMessage([createRecord('json', 'application/x+y', test_json_data)]),
...@@ -81,7 +81,7 @@ promise_test(t => { ...@@ -81,7 +81,7 @@ promise_test(t => {
promise_rejects(t, new TypeError(), navigator.nfc.push(message))); promise_rejects(t, new TypeError(), navigator.nfc.push(message)));
}); });
return Promise.all(promises); return Promise.all(promises);
}, "Test that promise is rejected with TypeError if NFCMessage is invalid."); }, "Test that promise is rejected with TypeError if NDEFMessage is invalid.");
promise_test(t => { promise_test(t => {
let promises = []; let promises = [];
...@@ -90,7 +90,7 @@ promise_test(t => { ...@@ -90,7 +90,7 @@ promise_test(t => {
promise_rejects(t, 'SyntaxError', navigator.nfc.push(message))); promise_rejects(t, 'SyntaxError', navigator.nfc.push(message)));
}); });
return Promise.all(promises); return Promise.all(promises);
}, "'Test that promise is rejected with SyntaxError if NFCMessage contains invalid records."); }, "'Test that promise is rejected with SyntaxError if NDEFMessage contains invalid records.");
promise_test(t => { promise_test(t => {
return promise_rejects(t, new TypeError(), navigator.nfc.push(test_text_data, { timeout: "invalid"})); return promise_rejects(t, new TypeError(), navigator.nfc.push(test_text_data, { timeout: "invalid"}));
......
...@@ -29,6 +29,6 @@ let watchOptions = { ...@@ -29,6 +29,6 @@ let watchOptions = {
} }
let message = createMessage([createRecord('empty', '')]); let message = createMessage([createRecord('empty', '')]);
testNFCMessage(message, watchOptions, desc); testNDEFMessage(message, watchOptions, desc);
</script> </script>
...@@ -29,6 +29,6 @@ let watchOptions = { ...@@ -29,6 +29,6 @@ let watchOptions = {
} }
let message = createMessage([createJsonRecord(test_json_data)]); let message = createMessage([createJsonRecord(test_json_data)]);
testNFCMessage(message, watchOptions, desc); testNDEFMessage(message, watchOptions, desc);
</script> </script>
...@@ -29,6 +29,6 @@ let watchOptions = { ...@@ -29,6 +29,6 @@ let watchOptions = {
} }
let message = createMessage([createOpaqueRecord(test_buffer_data)]); let message = createMessage([createOpaqueRecord(test_buffer_data)]);
testNFCMessage(message, watchOptions, desc); testNDEFMessage(message, watchOptions, desc);
</script> </script>
...@@ -29,6 +29,6 @@ let watchOptions = { ...@@ -29,6 +29,6 @@ let watchOptions = {
} }
let message = createMessage([createTextRecord(test_text_data)]); let message = createMessage([createTextRecord(test_text_data)]);
testNFCMessage(message, watchOptions, desc); testNDEFMessage(message, watchOptions, desc);
</script> </script>
...@@ -30,6 +30,6 @@ let watchOptions = { ...@@ -30,6 +30,6 @@ let watchOptions = {
} }
let message = createMessage([createUrlRecord(test_url_data)]); let message = createMessage([createUrlRecord(test_url_data)]);
testNFCMessage(message, watchOptions, desc); testNDEFMessage(message, watchOptions, desc);
</script> </script>
...@@ -47,7 +47,7 @@ function createUrlRecord(url) { ...@@ -47,7 +47,7 @@ function createUrlRecord(url) {
return createRecord('url', 'text/plain', url); return createRecord('url', 'text/plain', url);
} }
function assertWebNFCMessagesEqual(a, b) { function assertWebNDEFMessagesEqual(a, b) {
assert_equals(a.records.length, b.records.length); assert_equals(a.records.length, b.records.length);
for(let i in a.records) { for(let i in a.records) {
let recordA = a.records[i]; let recordA = a.records[i];
...@@ -67,14 +67,14 @@ function assertWebNFCMessagesEqual(a, b) { ...@@ -67,14 +67,14 @@ function assertWebNFCMessagesEqual(a, b) {
} }
} }
function testNFCMessage(pushedMessage, watchOptions, desc) { function testNDEFMessage(pushedMessage, watchOptions, desc) {
promise_test(t => { promise_test(t => {
return navigator.nfc.push(pushedMessage) return navigator.nfc.push(pushedMessage)
.then(() => { .then(() => {
return new Promise(resolve => { return new Promise(resolve => {
navigator.nfc.watch((message) => resolve(message), watchOptions); navigator.nfc.watch((message) => resolve(message), watchOptions);
}).then((message) => { }).then((message) => {
assertWebNFCMessagesEqual(message, pushedMessage); assertWebNDEFMessagesEqual(message, pushedMessage);
}); });
}); });
}, desc); }, desc);
......
...@@ -13,40 +13,40 @@ const invalid_type_messages = ...@@ -13,40 +13,40 @@ const invalid_type_messages =
// Invalid NFCPushMessage type // Invalid NFCPushMessage type
undefined, undefined,
// NFCMessage.records: should have at least 1 valid record. // NDEFMessage.records: should have at least 1 valid record.
// https://w3c.github.io/web-nfc/#the-push-method - Step 8. // https://w3c.github.io/web-nfc/#the-push-method - Step 8.
createMessage([{}]), createMessage([{}]),
// https://w3c.github.io/web-nfc/#dfn-map-text-to-ndef // https://w3c.github.io/web-nfc/#dfn-map-text-to-ndef
// NFCRecord must have data. // NDEFRecord must have data.
createMessage([createTextRecord()]), createMessage([createTextRecord()]),
// NFCRecord.data for 'text' record must be number or string. // NDEFRecord.data for 'text' record must be number or string.
createMessage([createTextRecord(test_buffer_data)]), createMessage([createTextRecord(test_buffer_data)]),
createMessage([createTextRecord(test_json_data)]), createMessage([createTextRecord(test_json_data)]),
// https://w3c.github.io/web-nfc/#dfn-map-a-json-object-to-ndef // https://w3c.github.io/web-nfc/#dfn-map-a-json-object-to-ndef
// NFCRecord must have data. // NDEFRecord must have data.
createMessage([createJsonRecord()]), createMessage([createJsonRecord()]),
// NFCRecord.data for 'json' record must be object. // NDEFRecord.data for 'json' record must be object.
createMessage([createJsonRecord(test_buffer_data)]), createMessage([createJsonRecord(test_buffer_data)]),
createMessage([createJsonRecord(test_number_data)]), createMessage([createJsonRecord(test_number_data)]),
createMessage([createJsonRecord(test_text_data)]), createMessage([createJsonRecord(test_text_data)]),
// https://w3c.github.io/web-nfc/#dfn-map-a-url-to-ndef // https://w3c.github.io/web-nfc/#dfn-map-a-url-to-ndef
// NFCRecord must have data. // NDEFRecord must have data.
createMessage([createUrlRecord()]), createMessage([createUrlRecord()]),
// NFCRecord.data for 'url' record must be string. // NDEFRecord.data for 'url' record must be string.
createMessage([createUrlRecord(test_buffer_data)]), createMessage([createUrlRecord(test_buffer_data)]),
createMessage([createUrlRecord(test_number_data)]), createMessage([createUrlRecord(test_number_data)]),
createMessage([createUrlRecord(test_json_data)]), createMessage([createUrlRecord(test_json_data)]),
// https://w3c.github.io/web-nfc/#dfn-map-binary-data-to-ndef // https://w3c.github.io/web-nfc/#dfn-map-binary-data-to-ndef
// NFCRecord must have data. // NDEFRecord must have data.
createMessage([createOpaqueRecord()]), createMessage([createOpaqueRecord()]),
// NFCRecord.data for 'opaque' record must be ArrayBuffer. // NDEFRecord.data for 'opaque' record must be ArrayBuffer.
createMessage([createOpaqueRecord(test_text_data)]), createMessage([createOpaqueRecord(test_text_data)]),
createMessage([createOpaqueRecord(test_number_data)]), createMessage([createOpaqueRecord(test_number_data)]),
createMessage([createOpaqueRecord(test_json_data)]) createMessage([createOpaqueRecord(test_json_data)])
...@@ -54,14 +54,14 @@ const invalid_type_messages = ...@@ -54,14 +54,14 @@ const invalid_type_messages =
const invalid_syntax_messages = const invalid_syntax_messages =
[ [
// NFCRecord.mediaType for 'text' record must be 'text/*'. // NDEFRecord.mediaType for 'text' record must be 'text/*'.
createMessage([createRecord('text', 'application/json', createMessage([createRecord('text', 'application/json',
test_number_data)]), test_number_data)]),
// Data for 'url' record, must be a valid URL. // Data for 'url' record, must be a valid URL.
createMessage([createUrlRecord('Invalid URL:// Data')]), createMessage([createUrlRecord('Invalid URL:// Data')]),
// NFCRecord.mediaType for 'json' record must be 'application/json' or // NDEFRecord.mediaType for 'json' record must be 'application/json' or
// starts with 'application/' and ends with '+json'. // starts with 'application/' and ends with '+json'.
createMessage([createRecord('json', 'image/png', test_json_data)]), createMessage([createRecord('json', 'image/png', test_json_data)]),
createMessage([createRecord('json', 'application/x+y', test_json_data)]), createMessage([createRecord('json', 'application/x+y', test_json_data)]),
...@@ -75,7 +75,7 @@ nfc_test(() => { ...@@ -75,7 +75,7 @@ nfc_test(() => {
assertRejectsWithError(navigator.nfc.push(message), 'TypeError')); assertRejectsWithError(navigator.nfc.push(message), 'TypeError'));
}); });
return Promise.all(promises); return Promise.all(promises);
}, 'Test that promise is rejected with TypeError if NFCMessage is invalid.'); }, 'Test that promise is rejected with TypeError if NDEFMessage is invalid.');
nfc_test(() => { nfc_test(() => {
let promises = []; let promises = [];
...@@ -84,7 +84,7 @@ nfc_test(() => { ...@@ -84,7 +84,7 @@ nfc_test(() => {
assertRejectsWithError(navigator.nfc.push(message), 'SyntaxError')); assertRejectsWithError(navigator.nfc.push(message), 'SyntaxError'));
}); });
return Promise.all(promises); return Promise.all(promises);
}, 'Test that promise is rejected with SyntaxError if NFCMessage contains' + }, 'Test that promise is rejected with SyntaxError if NDEFMessage contains' +
' invalid records.'); ' invalid records.');
nfc_test(() => { nfc_test(() => {
...@@ -129,18 +129,18 @@ nfc_test(async () => { ...@@ -129,18 +129,18 @@ nfc_test(async () => {
createUrlRecord(test_url_data)], createUrlRecord(test_url_data)],
test_message_origin); test_message_origin);
await navigator.nfc.push(message); await navigator.nfc.push(message);
assertNFCMessagesEqual(message, mockNFC.pushedMessage()); assertNDEFMessagesEqual(message, mockNFC.pushedMessage());
}, 'nfc.push NFCMessage containing text, json, opaque and url records with' }, 'nfc.push NDEFMessage containing text, json, opaque and url records with'
+ ' default NFCPushOptions.'); + ' default NFCPushOptions.');
nfc_test(async () => { nfc_test(async () => {
await navigator.nfc.push(test_text_data); await navigator.nfc.push(test_text_data);
assertNFCMessagesEqual(test_text_data, mockNFC.pushedMessage()); assertNDEFMessagesEqual(test_text_data, mockNFC.pushedMessage());
}, 'nfc.push String with default NFCPushOptions.'); }, 'nfc.push String with default NFCPushOptions.');
nfc_test(async () => { nfc_test(async () => {
await navigator.nfc.push(test_buffer_data); await navigator.nfc.push(test_buffer_data);
assertNFCMessagesEqual(test_buffer_data, mockNFC.pushedMessage()); assertNDEFMessagesEqual(test_buffer_data, mockNFC.pushedMessage());
}, 'nfc.push ArrayBuffer with default NFCPushOptions.'); }, 'nfc.push ArrayBuffer with default NFCPushOptions.');
nfc_test(() => { nfc_test(() => {
......
...@@ -67,19 +67,19 @@ function createUrlRecord(url) { ...@@ -67,19 +67,19 @@ function createUrlRecord(url) {
return createRecord('url', 'text/plain', url); return createRecord('url', 'text/plain', url);
} }
function toMojoNFCRecordType(type) { function toMojoNDEFRecordType(type) {
switch (type) { switch (type) {
case 'text': case 'text':
return device.mojom.NFCRecordType.TEXT; return device.mojom.NDEFRecordType.TEXT;
case 'url': case 'url':
return device.mojom.NFCRecordType.URL; return device.mojom.NDEFRecordType.URL;
case 'json': case 'json':
return device.mojom.NFCRecordType.JSON; return device.mojom.NDEFRecordType.JSON;
case 'opaque': case 'opaque':
return device.mojom.NFCRecordType.OPAQUE_RECORD; return device.mojom.NDEFRecordType.OPAQUE_RECORD;
} }
return device.mojom.NFCRecordType.EMPTY; return device.mojom.NDEFRecordType.EMPTY;
} }
function toMojoNFCPushTarget(target) { function toMojoNFCPushTarget(target) {
...@@ -101,20 +101,20 @@ function toMojoNFCWatchMode(mode) { ...@@ -101,20 +101,20 @@ function toMojoNFCWatchMode(mode) {
return device.mojom.NFCWatchMode.ANY; return device.mojom.NFCWatchMode.ANY;
} }
// Converts between NFCMessage https://w3c.github.io/web-nfc/#dom-nfcmessage // Converts between NDEFMessage https://w3c.github.io/web-nfc/#dom-ndefmessage
// and mojo::NFCMessage structure, so that nfc.watch function can be tested. // and mojom.NDEFMessage structure, so that nfc.watch function can be tested.
function toMojoNFCMessage(message) { function toMojoNDEFMessage(message) {
let nfcMessage = new device.mojom.NFCMessage(); let ndefMessage = new device.mojom.NDEFMessage();
nfcMessage.url = message.url; ndefMessage.url = message.url;
nfcMessage.data = []; ndefMessage.data = [];
for (let record of message.records) for (let record of message.records)
nfcMessage.data.push(toMojoNFCRecord(record)); ndefMessage.data.push(toMojoNDEFRecord(record));
return nfcMessage; return ndefMessage;
} }
function toMojoNFCRecord(record) { function toMojoNDEFRecord(record) {
let nfcRecord = new device.mojom.NFCRecord(); let nfcRecord = new device.mojom.NDEFRecord();
nfcRecord.recordType = toMojoNFCRecordType(record.recordType); nfcRecord.recordType = toMojoNDEFRecordType(record.recordType);
nfcRecord.mediaType = record.mediaType; nfcRecord.mediaType = record.mediaType;
nfcRecord.data = toByteArray(record.data); nfcRecord.data = toByteArray(record.data);
return nfcRecord; return nfcRecord;
...@@ -136,12 +136,12 @@ function toByteArray(data) { ...@@ -136,12 +136,12 @@ function toByteArray(data) {
return byteArray; return byteArray;
} }
// Compares NFCMessage that was provided to the API // Compares NDEFMessage that was provided to the API
// (e.g. navigator.nfc.push), and NFCMessage that was received by the // (e.g. navigator.nfc.push), and NDEFMessage that was received by the
// mock NFC service. // mock NFC service.
function assertNFCMessagesEqual(providedMessage, receivedMessage) { function assertNDEFMessagesEqual(providedMessage, receivedMessage) {
// If simple data type is passed, e.g. String or ArrayBuffer, convert it // If simple data type is passed, e.g. String or ArrayBuffer, convert it
// to NFCMessage before comparing. // to NDEFMessage before comparing.
// https://w3c.github.io/web-nfc/#idl-def-nfcpushmessage // https://w3c.github.io/web-nfc/#idl-def-nfcpushmessage
let provided = providedMessage; let provided = providedMessage;
if (providedMessage instanceof ArrayBuffer) if (providedMessage instanceof ArrayBuffer)
...@@ -150,17 +150,17 @@ function assertNFCMessagesEqual(providedMessage, receivedMessage) { ...@@ -150,17 +150,17 @@ function assertNFCMessagesEqual(providedMessage, receivedMessage) {
provided = createMessage([createTextRecord(providedMessage)]); provided = createMessage([createTextRecord(providedMessage)]);
assert_equals(provided.records.length, receivedMessage.data.length, assert_equals(provided.records.length, receivedMessage.data.length,
'NFCMessages must have same number of NFCRecords'); 'NDEFMessages must have same number of NDEFRecords');
// Compare contents of each individual NFCRecord // Compare contents of each individual NDEFRecord
for (let i = 0; i < provided.records.length; ++i) for (let i = 0; i < provided.records.length; ++i)
compareNFCRecords(provided.records[i], receivedMessage.data[i]); compareNDEFRecords(provided.records[i], receivedMessage.data[i]);
} }
// Used to compare two WebNFC messages, one that is provided to mock NFC // Used to compare two WebNFC messages, one that is provided to mock NFC
// service through triggerWatchCallback and another that is received by // service through triggerWatchCallback and another that is received by
// callback that is provided to navigator.nfc.watch function. // callback that is provided to navigator.nfc.watch function.
function assertWebNFCMessagesEqual(a, b) { function assertWebNDEFMessagesEqual(a, b) {
assert_equals(a.url, b.url); assert_equals(a.url, b.url);
assert_equals(a.records.length, b.records.length); assert_equals(a.records.length, b.records.length);
for(let i in a.records) { for(let i in a.records) {
...@@ -183,9 +183,9 @@ function assertWebNFCMessagesEqual(a, b) { ...@@ -183,9 +183,9 @@ function assertWebNFCMessagesEqual(a, b) {
} }
} }
// Compares NFCRecords that were provided / received by the mock service. // Compares NDEFRecords that were provided / received by the mock service.
function compareNFCRecords(providedRecord, receivedRecord) { function compareNDEFRecords(providedRecord, receivedRecord) {
assert_equals(toMojoNFCRecordType(providedRecord.recordType), assert_equals(toMojoNDEFRecordType(providedRecord.recordType),
receivedRecord.recordType); receivedRecord.recordType);
// Compare media types without charset. // Compare media types without charset.
...@@ -194,8 +194,8 @@ function compareNFCRecords(providedRecord, receivedRecord) { ...@@ -194,8 +194,8 @@ function compareNFCRecords(providedRecord, receivedRecord) {
assert_equals(providedRecord.mediaType, assert_equals(providedRecord.mediaType,
receivedRecord.mediaType.substring(0, providedRecord.mediaType.length)); receivedRecord.mediaType.substring(0, providedRecord.mediaType.length));
assert_false(toMojoNFCRecordType(providedRecord.recordType) == assert_false(toMojoNDEFRecordType(providedRecord.recordType) ==
device.mojom.NFCRecordType.EMPTY); device.mojom.NDEFRecordType.EMPTY);
assert_array_equals(toByteArray(providedRecord.data), assert_array_equals(toByteArray(providedRecord.data),
new Uint8Array(receivedRecord.data)); new Uint8Array(receivedRecord.data));
...@@ -240,7 +240,7 @@ function assertNFCWatchOptionsEqual(provided, received) { ...@@ -240,7 +240,7 @@ function assertNFCWatchOptionsEqual(provided, received) {
if (provided.recordType !== undefined) { if (provided.recordType !== undefined) {
assert_equals(!+received.record_filter, true); assert_equals(!+received.record_filter, true);
assert_equals(toMojoNFCRecordType(provided.recordType), assert_equals(toMojoNDEFRecordType(provided.recordType),
received.recordFilter.recordType); received.recordFilter.recordType);
} }
} }
...@@ -424,7 +424,7 @@ class MockNFC { ...@@ -424,7 +424,7 @@ class MockNFC {
triggerWatchCallback(id, message) { triggerWatchCallback(id, message) {
assert_true(this.client_ !== null); assert_true(this.client_ !== null);
if (this.watchers_.length > 0) { if (this.watchers_.length > 0) {
this.client_.onWatch([id], toMojoNFCMessage(message)); this.client_.onWatch([id], toMojoNDEFMessage(message));
} }
} }
} }
......
...@@ -62,7 +62,7 @@ nfc_test(async () => { ...@@ -62,7 +62,7 @@ nfc_test(async () => {
let messageCallback; let messageCallback;
let promise = new Promise(resolve => { let promise = new Promise(resolve => {
messageCallback = receivedMessage => { messageCallback = receivedMessage => {
assertWebNFCMessagesEqual(message, receivedMessage); assertWebNDEFMessagesEqual(message, receivedMessage);
resolve(); resolve();
} }
}); });
...@@ -70,7 +70,7 @@ nfc_test(async () => { ...@@ -70,7 +70,7 @@ nfc_test(async () => {
let id = await navigator.nfc.watch(messageCallback); let id = await navigator.nfc.watch(messageCallback);
mockNFC.triggerWatchCallback(id, message); mockNFC.triggerWatchCallback(id, message);
return promise; return promise;
}, 'Test that watch callback is triggered with valid NFCMessage.'); }, 'Test that watch callback is triggered with valid NDEFMessage.');
nfc_test(() => { nfc_test(() => {
return assertRejectsWithError(navigator.nfc.watch(noop, {url:"www.a.com"}), return assertRejectsWithError(navigator.nfc.watch(noop, {url:"www.a.com"}),
......
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