OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <script src="../resources/testharness.js"></script> | |
3 <script src="../resources/testharness-helpers.js"></script> | |
4 <script src="../resources/testharnessreport.js"></script> | |
5 <script src="../resources/mojo-helpers.js"></script> | |
6 <script src="resources/nfc-helpers.js"></script> | |
7 <script> | |
8 | |
9 'use strict'; | |
10 | |
11 nfc_test(nfc => { | |
12 return navigator.nfc.watch(message => {}); | |
13 }, 'nfc.watch should succeed if NFC HW is enabled.') | |
kenneth.christiansen
2016/04/25 08:31:47
hardware
shalamov
2016/04/25 11:31:04
Done.
| |
14 | |
15 nfc_test(nfc => { | |
16 nfc.mockNFC.setHWStatus(NFCHWStatus.DISABLED); | |
17 return assert_promise_rejects( | |
18 navigator.nfc.watch(message => {}), | |
kenneth.christiansen
2016/04/25 08:31:47
why not define
function noop() {} and use noop ev
shalamov
2016/04/25 11:31:04
Done.
| |
19 'NotSupportedError'); | |
20 }, 'nfc.watch should fail if NFC HW is disabled.') | |
21 | |
22 nfc_test(nfc => { | |
23 nfc.mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED); | |
24 return assert_promise_rejects( | |
25 navigator.nfc.watch(message => {}), | |
26 'NotSupportedError'); | |
27 }, 'nfc.watch should fail if NFC functionality is not supported.') | |
28 | |
29 nfc_test(nfc => { | |
30 return navigator.nfc.watch(message => {}). | |
31 then(() => { | |
32 nfc.assertNFCWatchOptionsEqual(createNFCWatchOptions(), nfc.mockNFC.watc hOptions()); | |
33 }); | |
34 }, 'nfc.watch test that default NFCWatchOptions values are set correctly.') | |
35 | |
36 nfc_test(nfc => { | |
37 let watchOptions = createNFCWatchOptions(test_message_origin, 'json', | |
38 'application/json', 'any'); | |
39 return navigator.nfc.watch(message => {}, watchOptions). | |
40 then(() => { | |
41 nfc.assertNFCWatchOptionsEqual(watchOptions, nfc.mockNFC.watchOptions()) ; | |
42 }); | |
43 }, 'nfc.watch test that default NFCWatchOptions values are set correctly.') | |
44 | |
45 nfc_test(nfc => { | |
46 return assert_promise_rejects( | |
47 navigator.nfc.cancelWatch(1), | |
48 'NotFoundError'); | |
49 }, 'nfc.cancelWatch should fail if invalid watch ID is provided.') | |
50 | |
51 nfc_test(nfc => { | |
52 return assert_promise_rejects( | |
53 navigator.nfc.cancelWatch(), | |
54 'NotFoundError'); | |
55 }, 'nfc.cancelWatch should fail if there are no active watchers.') | |
56 | |
57 nfc_test(nfc => { | |
58 return navigator.nfc.watch(message => {}). | |
59 then(id => { navigator.nfc.cancelWatch(id); }); | |
60 }, 'nfc.cancelWatch should succeed if there are active watchers.') | |
61 | |
62 nfc_test(nfc => { | |
63 return navigator.nfc.watch(message => {}). | |
64 then(() => { navigator.nfc.cancelWatch(); }); | |
65 }, 'nfc.cancelWatch should succeed and cancel all active watchers.') | |
66 | |
67 nfc_test(nfc => { | |
68 return navigator.nfc.watch(message => {}). | |
69 then(() => { navigator.nfc.cancelWatch(); }); | |
70 }, 'nfc.cancelWatch should succeed and cancel all active watchers.') | |
71 | |
72 | |
73 nfc_test(nfc => { | |
74 let message = createMessage([createTextRecord(test_text_data), | |
75 createJsonRecord(test_json_data), | |
76 createOpaqueRecord(test_buffer_data), | |
77 createTextRecord(test_number_data), | |
78 createUrlRecord(test_url_data)], | |
79 test_message_origin); | |
80 | |
81 return new Promise((resolve, reject) => { | |
kenneth.christiansen
2016/04/25 08:31:47
why do you need a new promise if it already return
shalamov
2016/04/25 11:31:04
New promise is a wrapper for successful callback i
| |
82 navigator.nfc.watch((receivedMessage) => { | |
83 nfc.assertWebNFCMessagesEqual(message, receivedMessage); | |
84 resolve(); | |
85 }).then(id => { nfc.mockNFC.triggerWatchCallback(id, message);}, reject); | |
86 }); | |
87 }, 'nfc.watch should trigger callback with valid NFCMessage.') | |
88 | |
89 </script> | |
OLD | NEW |