|
21 | 21 | ];
|
22 | 22 |
|
23 | 23 | function waitSyntaxErrorPromise(t, scan_options) {
|
24 |
| - const reader = new NDEFReader(); |
25 |
| - return promise_rejects_dom(t, 'SyntaxError', reader.scan(scan_options)); |
| 24 | + const ndef = new NDEFReader(); |
| 25 | + return promise_rejects_dom(t, 'SyntaxError', ndef.scan(scan_options)); |
26 | 26 | }
|
27 | 27 |
|
28 | 28 | nfc_test(async t => {
|
29 |
| - const reader = new NDEFReader(); |
| 29 | + const ndef = new NDEFReader(); |
30 | 30 | const promises = [];
|
31 | 31 | invalid_signals.forEach(invalid_signal => {
|
32 | 32 | promises.push(promise_rejects_js(t, TypeError,
|
33 |
| - reader.scan({ signal: invalid_signal }))); |
| 33 | + ndef.scan({ signal: invalid_signal }))); |
34 | 34 | });
|
35 | 35 | await Promise.all(promises);
|
36 | 36 | }, "Test that NDEFReader.scan rejects if signal is not an AbortSignal.");
|
37 | 37 |
|
38 | 38 | nfc_test(async t => {
|
39 | 39 | await test_driver.set_permission({ name: 'nfc' }, 'denied', false);
|
40 |
| - const reader = new NDEFReader(); |
41 |
| - await promise_rejects_dom(t, 'NotAllowedError', reader.scan()); |
| 40 | + const ndef = new NDEFReader(); |
| 41 | + await promise_rejects_dom(t, 'NotAllowedError', ndef.scan()); |
42 | 42 | }, "NDEFReader.scan should fail if user permission is not granted.");
|
43 | 43 |
|
44 | 44 | // We do not provide NFC mock here to simulate that there has no available
|
45 | 45 | // implementation for NFC Mojo interface.
|
46 | 46 | nfc_test(async (t, mockNFC) => {
|
47 | 47 | mockNFC.simulateClosedPipe();
|
48 |
| - const reader = new NDEFReader(); |
49 |
| - await promise_rejects_dom(t, 'NotSupportedError', reader.scan()); |
50 |
| -}, "NDEFReader.scan should faild if no implementation for NFC Mojo interface."); |
| 48 | + const ndef = new NDEFReader(); |
| 49 | + await promise_rejects_dom(t, 'NotSupportedError', ndef.scan()); |
| 50 | +}, "NDEFReader.scan should fail if no implementation for NFC Mojo interface."); |
51 | 51 |
|
52 | 52 | nfc_test(async (t, mockNFC) => {
|
53 | 53 | mockNFC.setHWStatus(NFCHWStatus.DISABLED);
|
54 |
| - const reader = new NDEFReader(); |
55 |
| - await promise_rejects_dom(t, 'NotReadableError', reader.scan()); |
| 54 | + const ndef = new NDEFReader(); |
| 55 | + await promise_rejects_dom(t, 'NotReadableError', ndef.scan()); |
56 | 56 | }, "NDEFReader.scan should fail if NFC HW is disabled.");
|
57 | 57 |
|
58 | 58 | nfc_test(async (t, mockNFC) => {
|
59 | 59 | mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED);
|
60 |
| - const reader = new NDEFReader(); |
61 |
| - await promise_rejects_dom(t, 'NotSupportedError', reader.scan()); |
| 60 | + const ndef = new NDEFReader(); |
| 61 | + await promise_rejects_dom(t, 'NotSupportedError', ndef.scan()); |
62 | 62 | }, "NDEFReader.scan should fail if NFC HW is not supported.");
|
63 | 63 |
|
64 | 64 | nfc_test(async (t, mockNFC) => {
|
65 |
| - const reader = new NDEFReader(); |
| 65 | + const ndef = new NDEFReader(); |
66 | 66 | const controller = new AbortController();
|
67 |
| - const readerWatcher = new EventWatcher(t, reader, ["reading", "readingerror"]); |
68 |
| - const promise = readerWatcher.wait_for("reading").then(event => { |
| 67 | + const ndefWatcher = new EventWatcher(t, ndef, ["reading", "readingerror"]); |
| 68 | + const promise = ndefWatcher.wait_for("reading").then(event => { |
69 | 69 | assert_true(event instanceof NDEFReadingEvent);
|
70 | 70 | controller.abort();
|
71 | 71 | });
|
72 |
| - await reader.scan({signal : controller.signal}); |
| 72 | + await ndef.scan({signal : controller.signal}); |
73 | 73 |
|
74 | 74 | mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
|
75 | 75 | await promise;
|
76 | 76 | }, "Test that nfc watch success if NFC HW is enabled.");
|
77 | 77 |
|
78 | 78 | nfc_test(async (t, mockNFC) => {
|
79 |
| - const reader = new NDEFReader(); |
| 79 | + const ndef = new NDEFReader(); |
80 | 80 | const controller = new AbortController();
|
81 |
| - const readerWatcher = new EventWatcher(t, reader, ["reading", "readingerror"]); |
82 |
| - const promise = readerWatcher.wait_for("reading").then(event => { |
| 81 | + const ndefWatcher = new EventWatcher(t, ndef, ["reading", "readingerror"]); |
| 82 | + const promise = ndefWatcher.wait_for("reading").then(event => { |
83 | 83 | assert_true(event instanceof NDEFReadingEvent);
|
84 | 84 | controller.abort();
|
85 | 85 | });
|
86 |
| - await reader.scan({signal : controller.signal}); |
| 86 | + await ndef.scan({signal : controller.signal}); |
87 | 87 |
|
88 | 88 | mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
|
89 | 89 | await promise;
|
90 | 90 | }, "Test that NDEFReader.scan matches any ids if NDEFScanOptions.id is undefined.");
|
91 | 91 |
|
92 | 92 | nfc_test(async (t, mockNFC) => {
|
93 |
| - const reader = new NDEFReader(); |
| 93 | + const ndef = new NDEFReader(); |
94 | 94 | const controller = new AbortController();
|
95 | 95 | controller.abort();
|
96 |
| - await promise_rejects_dom(t, 'AbortError', reader.scan({signal: controller.signal})); |
| 96 | + await promise_rejects_dom(t, 'AbortError', ndef.scan({signal: controller.signal})); |
97 | 97 | }, "Test that NDEFReader.scan rejects if NDEFScanOptions.signal is already aborted.");
|
98 | 98 |
|
99 | 99 | nfc_test(async (t, mockNFC) => {
|
100 |
| - const reader = new NDEFReader(); |
| 100 | + const ndef = new NDEFReader(); |
101 | 101 | const controller = new AbortController();
|
102 |
| - const promise = reader.scan({signal: controller.signal}); |
| 102 | + const promise = ndef.scan({signal: controller.signal}); |
103 | 103 | controller.abort();
|
104 | 104 | await promise_rejects_dom(t, 'AbortError', promise);
|
105 | 105 | }, "Test that NDEFReader.scan rejects if NDEFScanOptions.signal aborts right after \
|
106 | 106 | the scan invocation.");
|
107 | 107 |
|
108 | 108 | nfc_test(async (t, mockNFC) => {
|
109 |
| - const reader = new NDEFReader(); |
| 109 | + const ndef = new NDEFReader(); |
110 | 110 | const controller = new AbortController();
|
111 |
| - const readerWatcher = new EventWatcher(t, reader, ["reading", "readingerror"]); |
| 111 | + const ndefWatcher = new EventWatcher(t, ndef, ["reading", "readingerror"]); |
112 | 112 | const message = createMessage([createTextRecord(test_text_data)]);
|
113 |
| - const promise = readerWatcher.wait_for("reading").then(event => { |
| 113 | + const promise = ndefWatcher.wait_for("reading").then(event => { |
114 | 114 | assert_true(event instanceof NDEFReadingEvent);
|
115 | 115 | });
|
116 |
| - await reader.scan({signal : controller.signal}); |
| 116 | + await ndef.scan({signal : controller.signal}); |
117 | 117 |
|
118 | 118 | mockNFC.setReadingMessage(message);
|
119 | 119 | await promise;
|
120 | 120 |
|
121 |
| - reader.onreading = t.unreached_func("reading event should not be fired."); |
| 121 | + ndef.onreading = t.unreached_func("reading event should not be fired."); |
122 | 122 | mockNFC.setReadingMessage(message);
|
123 | 123 | controller.abort();
|
124 | 124 | await new Promise((resolve, reject) => {
|
|
127 | 127 | }, "Test that NDEFReader can not get any reading events once the signal aborts.");
|
128 | 128 |
|
129 | 129 | nfc_test(async (t, mockNFC) => {
|
130 |
| - const reader = new NDEFReader(); |
| 130 | + const ndef = new NDEFReader(); |
131 | 131 | const controller = new AbortController();
|
132 |
| - const readerWatcher = new EventWatcher(t, reader, ["reading", "readingerror"]); |
133 |
| - const promise = readerWatcher.wait_for("reading").then(event => { |
| 132 | + const ndefWatcher = new EventWatcher(t, ndef, ["reading", "readingerror"]); |
| 133 | + const promise = ndefWatcher.wait_for("reading").then(event => { |
134 | 134 | controller.abort();
|
135 | 135 | assert_true(event instanceof NDEFReadingEvent);
|
136 | 136 |
|
|
151 | 151 | assert_equals(decoder.decode(event.message.records[0].toRecords()[0].toRecords()[0].data),
|
152 | 152 | test_text_data, 'data has the same content with the original dictionary');
|
153 | 153 | });
|
154 |
| - await reader.scan({signal : controller.signal}); |
| 154 | + await ndef.scan({signal : controller.signal}); |
155 | 155 |
|
156 | 156 | // An external type record --contains-> a local type record --contains-> a text record.
|
157 | 157 | const messageContainText = createMessage([createTextRecord(test_text_data)]);
|
|
164 | 164 | }, "NDEFRecord.toRecords returns its embedded records correctly.");
|
165 | 165 |
|
166 | 166 | nfc_test(async (t, mockNFC) => {
|
167 |
| - const reader = new NDEFReader(); |
| 167 | + const ndef = new NDEFReader(); |
168 | 168 | const controller = new AbortController();
|
169 |
| - const readerWatcher = new EventWatcher(t, reader, ["reading", "readingerror"]); |
170 |
| - const promise = readerWatcher.wait_for("reading").then(event => { |
| 169 | + const ndefWatcher = new EventWatcher(t, ndef, ["reading", "readingerror"]); |
| 170 | + const promise = ndefWatcher.wait_for("reading").then(event => { |
171 | 171 | controller.abort();
|
172 | 172 | assert_true(event instanceof NDEFReadingEvent);
|
173 | 173 |
|
|
203 | 203 | assert_array_equals(embedded_record_types.sort(), ['text', 'url'],
|
204 | 204 | 'smart-poster record\'s contained record types');
|
205 | 205 | });
|
206 |
| - await reader.scan({signal : controller.signal}); |
| 206 | + await ndef.scan({signal : controller.signal}); |
207 | 207 |
|
208 | 208 | // A smart-poster record contains a uri record, text record.
|
209 | 209 | const uri_record = createUrlRecord(test_url_data);
|
|
218 | 218 | nfc_test(async (t, mockNFC) => {
|
219 | 219 | const promises = [];
|
220 | 220 |
|
221 |
| - const reader1 = new NDEFReader(); |
222 |
| - const readerWatcher1 = new EventWatcher(t, reader1, ["reading", "readingerror"]); |
223 |
| - const promise1 = readerWatcher1.wait_for("readingerror"); |
| 221 | + const ndef1 = new NDEFReader(); |
| 222 | + const ndefWatcher1 = new EventWatcher(t, ndef1, ["reading", "readingerror"]); |
| 223 | + const promise1 = ndefWatcher1.wait_for("readingerror"); |
224 | 224 | promises.push(promise1);
|
225 |
| - await reader1.scan(); |
| 225 | + await ndef1.scan(); |
226 | 226 |
|
227 |
| - const reader2 = new NDEFReader(); |
228 |
| - const readerWatcher2 = new EventWatcher(t, reader2, ["reading", "readingerror"]); |
229 |
| - const promise2 = readerWatcher2.wait_for("readingerror"); |
| 227 | + const ndef2 = new NDEFReader(); |
| 228 | + const ndefWatcher2 = new EventWatcher(t, ndef2, ["reading", "readingerror"]); |
| 229 | + const promise2 = ndefWatcher2.wait_for("readingerror"); |
230 | 230 | promises.push(promise2);
|
231 |
| - await reader2.scan(); |
| 231 | + await ndef2.scan(); |
232 | 232 |
|
233 | 233 | mockNFC.simulateNonNDEFTagDiscovered();
|
234 | 234 | await Promise.all(promises);
|
235 | 235 | }, "Test that NDEFReader.onreadingerror should be fired if the NFC tag does not \
|
236 | 236 | expose NDEF technology.");
|
237 | 237 |
|
238 | 238 | nfc_test(async (t, mockNFC) => {
|
239 |
| - const reader = new NDEFReader(); |
| 239 | + const ndef = new NDEFReader(); |
240 | 240 | const controller = new AbortController();
|
241 |
| - const readerWatcher = new EventWatcher(t, reader, ["reading", "readingerror"]); |
242 |
| - const promise = readerWatcher.wait_for("reading").then(event => { |
| 241 | + const ndefWatcher = new EventWatcher(t, ndef, ["reading", "readingerror"]); |
| 242 | + const promise = ndefWatcher.wait_for("reading").then(event => { |
243 | 243 | assert_equals(event.serialNumber, fake_tag_serial_number);
|
244 | 244 | assert_equals(event.message.records.length, 0);
|
245 | 245 | controller.abort();
|
246 | 246 | });
|
247 |
| - await reader.scan({signal : controller.signal}); |
| 247 | + await ndef.scan({signal : controller.signal}); |
248 | 248 |
|
249 | 249 | mockNFC.setReadingMessage({ records: [] });
|
250 | 250 | await promise;
|
251 | 251 | }, "Test that NDEFReader.onreading should be fired on an unformatted NFC tag \
|
252 | 252 | with empty records array for NDEFMessage.");
|
253 | 253 |
|
254 | 254 | nfc_test(async (t, mockNFC) => {
|
255 |
| - const reader = new NDEFReader(); |
| 255 | + const ndef = new NDEFReader(); |
256 | 256 | const controller = new AbortController();
|
257 | 257 | const message = createMessage([createTextRecord(test_text_data),
|
258 | 258 | createMimeRecordFromJson(test_json_data),
|
|
262 | 262 | createUrlRecord(test_url_data, true),
|
263 | 263 | createRecord('w3.org:xyz', test_buffer_data)],
|
264 | 264 | test_message_origin);
|
265 |
| - const readerWatcher = new EventWatcher(t, reader, ["reading", "readingerror"]); |
266 |
| - const promise = readerWatcher.wait_for("reading").then(event => { |
| 265 | + const ndefWatcher = new EventWatcher(t, ndef, ["reading", "readingerror"]); |
| 266 | + const promise = ndefWatcher.wait_for("reading").then(event => { |
267 | 267 | assert_equals(event.serialNumber, fake_tag_serial_number);
|
268 | 268 | assertWebNDEFMessagesEqual(event.message, new NDEFMessage(message));
|
269 | 269 | controller.abort();
|
270 | 270 | });
|
271 |
| - await reader.scan({signal : controller.signal}); |
| 271 | + await ndef.scan({signal : controller.signal}); |
272 | 272 |
|
273 | 273 | mockNFC.setReadingMessage(message);
|
274 | 274 | await promise;
|
275 | 275 | }, "Test that reading message with multiple records should succeed.");
|
276 | 276 |
|
277 | 277 | nfc_test(async (t, mockNFC) => {
|
278 |
| - const reader = new NDEFReader(); |
279 |
| - const promise1 = reader.scan(); |
280 |
| - const promise2 = promise_rejects_dom(t, 'InvalidStateError', reader.scan()); |
| 278 | + const ndef = new NDEFReader(); |
| 279 | + const promise1 = ndef.scan(); |
| 280 | + const promise2 = promise_rejects_dom(t, 'InvalidStateError', ndef.scan()); |
281 | 281 | await promise1;
|
282 | 282 | await promise2;
|
283 | 283 | }, "Test that NDEFReader.scan rejects if there is already an ongoing scan.");
|
284 | 284 |
|
285 | 285 | nfc_test(async (t, mockNFC) => {
|
286 |
| - const reader = new NDEFReader(); |
| 286 | + const ndef = new NDEFReader(); |
287 | 287 | const controller = new AbortController();
|
288 |
| - await reader.scan({signal : controller.signal}); |
| 288 | + await ndef.scan({signal : controller.signal}); |
289 | 289 | controller.abort();
|
290 |
| - await reader.scan(); |
| 290 | + await ndef.scan(); |
291 | 291 | }, "Test that NDEFReader.scan can be started after the previous scan is aborted.");
|
292 | 292 | </script>
|
0 commit comments