| Index: third_party/WebKit/LayoutTests/nfc/watch.html
|
| diff --git a/third_party/WebKit/LayoutTests/nfc/watch.html b/third_party/WebKit/LayoutTests/nfc/watch.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..05d94d4b2f17e951a541fa50b733f626221482ac
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/nfc/watch.html
|
| @@ -0,0 +1,74 @@
|
| +<!DOCTYPE html>
|
| +<script src="../resources/testharness.js"></script>
|
| +<script src="../resources/testharnessreport.js"></script>
|
| +<script src="../resources/mojo-helpers.js"></script>
|
| +<script src="resources/nfc-helpers.js"></script>
|
| +<script>
|
| +
|
| +'use strict';
|
| +
|
| +nfc_test(nfc => {
|
| + return navigator.nfc.watch(noop);
|
| +}, 'Test that nfc.watch succeeds if NFC hardware is enabled.');
|
| +
|
| +nfc_test(nfc => {
|
| + nfc.mockNFC.setHWStatus(NFCHWStatus.DISABLED);
|
| + return assertRejectsWithError(navigator.nfc.watch(noop), 'NotSupportedError');
|
| +}, 'Test that nfc.watch fails if NFC hardware is disabled.')
|
| +
|
| +nfc_test(nfc => {
|
| + nfc.mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED);
|
| + return assertRejectsWithError(navigator.nfc.watch(noop), 'NotSupportedError');
|
| +}, 'Test that nfc.watch fails if NFC hardware is not supported.')
|
| +
|
| +nfc_test(nfc => {
|
| + return navigator.nfc.watch(noop).
|
| + then(() => {
|
| + nfc.assertNFCWatchOptionsEqual(createNFCWatchOptions(), nfc.mockNFC.watchOptions());
|
| + });
|
| +}, 'Test that default NFCWatchOptions values are set correctly.')
|
| +
|
| +nfc_test(nfc => {
|
| + let watchOptions = createNFCWatchOptions(test_message_origin, 'json',
|
| + 'application/json', 'any');
|
| + return navigator.nfc.watch(noop, watchOptions).
|
| + then(() => {
|
| + nfc.assertNFCWatchOptionsEqual(watchOptions, nfc.mockNFC.watchOptions());
|
| + });
|
| +}, 'Test that NFCWatchOptions values are correctly converted.')
|
| +
|
| +nfc_test(nfc => {
|
| + return assertRejectsWithError(navigator.nfc.cancelWatch(1), 'NotFoundError');
|
| +}, 'Test that nfc.cancelWatch fails if invalid watch ID is provided.')
|
| +
|
| +nfc_test(nfc => {
|
| + return assertRejectsWithError(navigator.nfc.cancelWatch(), 'NotFoundError');
|
| +}, 'Test that nfc.cancelWatch fails if there are no active watchers.')
|
| +
|
| +nfc_test(nfc => {
|
| + return navigator.nfc.watch(noop).
|
| + then(id => { navigator.nfc.cancelWatch(id); });
|
| +}, 'Test that nfc.cancelWatch succeeds if correct watch id is provided.')
|
| +
|
| +nfc_test(nfc => {
|
| + return navigator.nfc.watch(noop).
|
| + then(() => { navigator.nfc.cancelWatch(); });
|
| +}, 'Test that nfc.cancelWatch succeeds if there are active watchers.')
|
| +
|
| +nfc_test(nfc => {
|
| + let message = createMessage([createTextRecord(test_text_data),
|
| + createJsonRecord(test_json_data),
|
| + createOpaqueRecord(test_buffer_data),
|
| + createTextRecord(test_number_data),
|
| + createUrlRecord(test_url_data)],
|
| + test_message_origin);
|
| +
|
| + return new Promise((resolve, reject) => {
|
| + navigator.nfc.watch(receivedMessage => {
|
| + nfc.assertWebNFCMessagesEqual(message, receivedMessage);
|
| + resolve();
|
| + }).then(id => { nfc.mockNFC.triggerWatchCallback(id, message); }, reject);
|
| + });
|
| +}, 'Test that watch callback is triggered with valid NFCMessage.')
|
| +
|
| +</script>
|
|
|