Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: third_party/WebKit/LayoutTests/nfc/watch.html

Issue 1759373003: [webnfc] Implement nfc.watch in blink nfc module. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@implement_nfc_push_in_android
Patch Set: Rebased to master Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698