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

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

Issue 1708543002: [webnfc] Implement push() method in blink nfc module. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@onionsoup_webnfc
Patch Set: Move dependency from content_browsertests to layouttest_support_content Created 4 years, 6 months 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 const invalid_messages =
11 [
12 // NFCMessage.data: should have at least 1 valid record.
13 // https://w3c.github.io/web-nfc/#the-push-method - Step 8.
14 createMessage([{}]),
15
16 // https://w3c.github.io/web-nfc/#dfn-map-text-to-ndef
17 // NFCRecord must have data.
18 createMessage([createTextRecord()]),
19
20 // NFCRecord.mediaType for 'text' record must be text/* .
21 createMessage([createRecord('text', 'application/json',
22 test_number_data)]),
23
24 // NFCRecord.data for 'text' record must be number or string.
25 createMessage([createTextRecord(test_buffer_data)]),
26 createMessage([createTextRecord(test_json_data)]),
27
28 // https://w3c.github.io/web-nfc/#dfn-map-a-json-object-to-ndef
29 // NFCRecord must have data.
30 createMessage([createJsonRecord()]),
31
32 // NFCRecord.data for 'json' record must be object.
33 createMessage([createJsonRecord(test_buffer_data)]),
34 createMessage([createJsonRecord(test_number_data)]),
35 createMessage([createJsonRecord(test_text_data)]),
36
37 // NFCRecord.mediaType for 'json' record must be 'application/json'.
38 createMessage([createRecord('json', 'image/png', test_json_data)]),
39
40 // https://w3c.github.io/web-nfc/#dfn-map-a-url-to-ndef
41 // NFCRecord must have data.
42 createMessage([createUrlRecord()]),
43
44 // NFCRecord.data for 'url' record must be string.
45 createMessage([createUrlRecord(test_buffer_data)]),
46 createMessage([createUrlRecord(test_number_data)]),
47 createMessage([createUrlRecord(test_json_data)]),
48
49 // https://w3c.github.io/web-nfc/#dfn-map-binary-data-to-ndef
50 // NFCRecord must have data.
51 createMessage([createOpaqueRecord()]),
52 // NFCRecord.data for 'opaque' record must be ArrayBuffer.
53 createMessage([createOpaqueRecord(test_text_data)]),
54 createMessage([createOpaqueRecord(test_number_data)]),
55 createMessage([createOpaqueRecord(test_json_data)])
56 ];
57
58 nfc_test(nfc => {
59 return promise_test(test => {
60 promise_rejects(test, 'TypeMismatchError', navigator.nfc.push(undefined));
61 }, 'Reject promise with TypeMismatchError if invalid type is provided.');
62 }, 'Test that passing undefined to nfc.push would raise TypeMismatchError.');
63
64 nfc_test(nfc => {
65 let promises = [];
66 invalid_messages.forEach(message => {
67 promises.push(promise_test(test => {
68 promise_rejects(test, 'SyntaxError', navigator.nfc.push(message));
69 }, 'Promise rejected with SyntaxError.'));
70 });
71 return Promise.all(promises)
72 }, 'Test that promise is rejected with SyntaxError if NFCMessage is invalid.');
73
74
75 nfc_test(nfc => {
76 nfc.mockNFC.setHWStatus(NFCHWStatus.DISABLED);
77 return promise_test(test => {
78 promise_rejects(test, 'NotSupportedError', navigator.nfc.push(test_text_data ));
79 }, 'Promise rejected with NotSupportedError.');
80 }, 'nfc.push should fail when NFC HW is disabled.')
81
82 nfc_test(nfc => {
83 nfc.mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED);
84 return promise_test(test => {
85 promise_rejects(test, 'NotSupportedError', navigator.nfc.push(test_text_data ));
86 }, 'Promise rejected with NotSupportedError.');
87 }, 'nfc.push should fail when NFC HW is not supported.')
88
89 nfc_test(nfc => {
90 return navigator.nfc.push(test_text_data, { timeout: 1 });
91 }, 'nfc.push should succeed when NFC HW is enabled');
92
93 nfc_test(nfc => {
94 nfc.mockNFC.setPendingPushCompleted(false);
95 return promise_test(test => {
96 promise_rejects(test, 'TimeoutError',
97 navigator.nfc.push(test_text_data,{ timeout: 1 }));
98 }, 'Promise rejected with TimeoutError.');
99 }, 'nfc.push should fail with TimeoutError when push operation is not' +
100 ' completed before specified timeout value.')
101
102 nfc_test(nfc => {
103 let message = createMessage([createTextRecord(test_text_data),
104 createJsonRecord(test_json_data),
105 createOpaqueRecord(test_buffer_data),
106 createTextRecord(test_number_data),
107 createUrlRecord(test_url_data)],
108 test_message_origin);
109 return navigator.nfc.push(message).then(() => {
110 nfc.assertNFCMessagesEqual(message, nfc.mockNFC.pushedMessage());
111 });
112 }, 'nfc.push NFCMessage containing text, json, opaque and url records with defau lt '
113 + 'NFCPushOptions.');
114
115 nfc_test(nfc => {
116 return navigator.nfc.push(test_text_data).then(() => {
117 nfc.assertNFCMessagesEqual(test_text_data, nfc.mockNFC.pushedMessage());
118 });
119 }, 'nfc.push String with default NFCPushOptions.');
120
121 nfc_test(nfc => {
122 return navigator.nfc.push(test_buffer_data).then(() => {
123 nfc.assertNFCMessagesEqual(test_buffer_data, nfc.mockNFC.pushedMessage());
124 });
125 }, 'nfc.push ArrayBuffer with default NFCPushOptions.');
126
127 nfc_test(nfc => {
128 return navigator.nfc.push(test_text_data).then(() => {
129 nfc.assertNFCPushOptionsEqual(createNFCPushOptions('any', Infinity, true),
130 nfc.mockNFC.pushOptions());
131 });
132 }, 'Check that default NFCPushOptions values are correctly set.');
133
134 nfc_test(nfc => {
135 let nfcPushOptions = createNFCPushOptions('tag', 1, false);
136 return navigator.nfc.push(test_text_data, nfcPushOptions).then(() => {
137 nfc.assertNFCPushOptionsEqual(nfcPushOptions, nfc.mockNFC.pushOptions());
138 });
139 }, 'Check that provided NFCPushOptions values are correctly converted.');
140
141 nfc_test(nfc => {
142 return navigator.nfc.push(test_buffer_data).then(() => {
143 nfc.assertNFCMessagesEqual(test_buffer_data, nfc.mockNFC.pushedMessage());
144 });
145 }, 'Push ArrayBuffer with default NFCPushOptions.');
146
147 nfc_test(nfc => {
148 return navigator.nfc.push(test_text_data)
149 .then(() => { navigator.nfc.cancelPush });
150 }, 'nfc.cancelPush should succeed if there is pending push operation.');
151
152 nfc_test(nfc => {
153 nfc.mockNFC.setPendingPushCompleted(false);
154 return promise_test(test => {
155 promise_rejects(test, 'TimeoutError',
156 navigator.nfc.push(test_text_data,{ timeout: 1 }));
157 }, 'Promise rejected with TimeoutError.');
158 }, 'nfc.push should fail with TimeoutError when push operation is not' +
159 ' completed before specified timeout value.')
160
161 nfc_test(nfc => {
162 nfc.mockNFC.setPendingPushCompleted(false);
163 let promise = navigator.nfc.push(test_text_data, { timeout: 100 });
164 navigator.nfc.cancelPush();
165 return promise_test(test => {
166 promise_rejects(test, 'AbortError', promise);
167 }, 'Promise rejected with AbortError.');
168 }, 'nfc.cancelPush should reject pending promise with AbortError.')
169
170 </script>
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/nfc/mock-nfc.html ('k') | third_party/WebKit/LayoutTests/nfc/resources/nfc-helpers.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698