OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script src="../resources/mojo-helpers.js"></script> |
| 5 <script src="resources/nfc-helpers.js"></script> |
| 6 <script> |
| 7 |
| 8 'use strict'; |
| 9 |
| 10 nfc_test(nfc => { |
| 11 return navigator.nfc.watch(noop); |
| 12 }, 'Test that nfc.watch succeeds if NFC hardware is enabled.'); |
| 13 |
| 14 nfc_test(nfc => { |
| 15 nfc.mockNFC.setHWStatus(NFCHWStatus.DISABLED); |
| 16 return assertRejectsWithError(navigator.nfc.watch(noop), 'NotSupportedError'); |
| 17 }, 'Test that nfc.watch fails if NFC hardware is disabled.') |
| 18 |
| 19 nfc_test(nfc => { |
| 20 nfc.mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED); |
| 21 return assertRejectsWithError(navigator.nfc.watch(noop), 'NotSupportedError'); |
| 22 }, 'Test that nfc.watch fails if NFC hardware is not supported.') |
| 23 |
| 24 nfc_test(nfc => { |
| 25 return navigator.nfc.watch(noop). |
| 26 then(() => { |
| 27 nfc.assertNFCWatchOptionsEqual(createNFCWatchOptions(), nfc.mockNFC.watc
hOptions()); |
| 28 }); |
| 29 }, 'Test that default NFCWatchOptions values are set correctly.') |
| 30 |
| 31 nfc_test(nfc => { |
| 32 let watchOptions = createNFCWatchOptions(test_message_origin, 'json', |
| 33 'application/json', 'any'); |
| 34 return navigator.nfc.watch(noop, watchOptions). |
| 35 then(() => { |
| 36 nfc.assertNFCWatchOptionsEqual(watchOptions, nfc.mockNFC.watchOptions())
; |
| 37 }); |
| 38 }, 'Test that NFCWatchOptions values are correctly converted.') |
| 39 |
| 40 nfc_test(nfc => { |
| 41 return assertRejectsWithError(navigator.nfc.cancelWatch(1), 'NotFoundError'); |
| 42 }, 'Test that nfc.cancelWatch fails if invalid watch ID is provided.') |
| 43 |
| 44 nfc_test(nfc => { |
| 45 return assertRejectsWithError(navigator.nfc.cancelWatch(), 'NotFoundError'); |
| 46 }, 'Test that nfc.cancelWatch fails if there are no active watchers.') |
| 47 |
| 48 nfc_test(nfc => { |
| 49 return navigator.nfc.watch(noop). |
| 50 then(id => { navigator.nfc.cancelWatch(id); }); |
| 51 }, 'Test that nfc.cancelWatch succeeds if correct watch id is provided.') |
| 52 |
| 53 nfc_test(nfc => { |
| 54 return navigator.nfc.watch(noop). |
| 55 then(() => { navigator.nfc.cancelWatch(); }); |
| 56 }, 'Test that nfc.cancelWatch succeeds if there are active watchers.') |
| 57 |
| 58 nfc_test(nfc => { |
| 59 let message = createMessage([createTextRecord(test_text_data), |
| 60 createJsonRecord(test_json_data), |
| 61 createOpaqueRecord(test_buffer_data), |
| 62 createTextRecord(test_number_data), |
| 63 createUrlRecord(test_url_data)], |
| 64 test_message_origin); |
| 65 |
| 66 return new Promise((resolve, reject) => { |
| 67 navigator.nfc.watch(receivedMessage => { |
| 68 nfc.assertWebNFCMessagesEqual(message, receivedMessage); |
| 69 resolve(); |
| 70 }).then(id => { nfc.mockNFC.triggerWatchCallback(id, message); }, reject); |
| 71 }); |
| 72 }, 'Test that watch callback is triggered with valid NFCMessage.') |
| 73 |
| 74 </script> |
OLD | NEW |