| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
| 4 <script src="../resources/mojo-helpers.js"></script> | 4 <script src="../resources/mojo-helpers.js"></script> |
| 5 <script src="resources/nfc-helpers.js"></script> | 5 <script src="resources/nfc-helpers.js"></script> |
| 6 <script> | 6 <script> |
| 7 | 7 |
| 8 'use strict'; | 8 'use strict'; |
| 9 | 9 |
| 10 const invalid_messages = | 10 const invalid_messages = |
| 11 [ | 11 [ |
| 12 // Invalid NFCPushMessage type |
| 13 undefined, |
| 14 |
| 12 // NFCMessage.data: should have at least 1 valid record. | 15 // NFCMessage.data: should have at least 1 valid record. |
| 13 // https://w3c.github.io/web-nfc/#the-push-method - Step 8. | 16 // https://w3c.github.io/web-nfc/#the-push-method - Step 8. |
| 14 createMessage([{}]), | 17 createMessage([{}]), |
| 15 | 18 |
| 16 // https://w3c.github.io/web-nfc/#dfn-map-text-to-ndef | 19 // https://w3c.github.io/web-nfc/#dfn-map-text-to-ndef |
| 17 // NFCRecord must have data. | 20 // NFCRecord must have data. |
| 18 createMessage([createTextRecord()]), | 21 createMessage([createTextRecord()]), |
| 19 | 22 |
| 20 // NFCRecord.mediaType for 'text' record must be 'text/*'. | 23 // NFCRecord.mediaType for 'text' record must be 'text/*'. |
| 21 createMessage([createRecord('text', 'application/json', | 24 createMessage([createRecord('text', 'application/json', |
| (...skipping 27 matching lines...) Expand all Loading... |
| 49 // https://w3c.github.io/web-nfc/#dfn-map-binary-data-to-ndef | 52 // https://w3c.github.io/web-nfc/#dfn-map-binary-data-to-ndef |
| 50 // NFCRecord must have data. | 53 // NFCRecord must have data. |
| 51 createMessage([createOpaqueRecord()]), | 54 createMessage([createOpaqueRecord()]), |
| 52 // NFCRecord.data for 'opaque' record must be ArrayBuffer. | 55 // NFCRecord.data for 'opaque' record must be ArrayBuffer. |
| 53 createMessage([createOpaqueRecord(test_text_data)]), | 56 createMessage([createOpaqueRecord(test_text_data)]), |
| 54 createMessage([createOpaqueRecord(test_number_data)]), | 57 createMessage([createOpaqueRecord(test_number_data)]), |
| 55 createMessage([createOpaqueRecord(test_json_data)]) | 58 createMessage([createOpaqueRecord(test_json_data)]) |
| 56 ]; | 59 ]; |
| 57 | 60 |
| 58 nfc_test(nfc => { | 61 nfc_test(nfc => { |
| 59 return assertRejectsWithError(navigator.nfc.push(undefined), | |
| 60 'TypeMismatchError'); | |
| 61 }, 'Test that passing undefined to nfc.push would raise TypeMismatchError.'); | |
| 62 | |
| 63 nfc_test(nfc => { | |
| 64 let promises = []; | 62 let promises = []; |
| 65 invalid_messages.forEach(message => { | 63 invalid_messages.forEach(message => { |
| 66 promises.push( | 64 promises.push( |
| 67 assertRejectsWithError(navigator.nfc.push(message), 'SyntaxError')); | 65 assertRejectsWithError(navigator.nfc.push(message), 'TypeError')); |
| 68 }); | 66 }); |
| 69 return Promise.all(promises) | 67 return Promise.all(promises) |
| 70 }, 'Test that promise is rejected with SyntaxError if NFCMessage is invalid.'); | 68 }, 'Test that promise is rejected with TypeError if NFCMessage is invalid.'); |
| 71 | 69 |
| 72 nfc_test(nfc => { | 70 nfc_test(nfc => { |
| 73 nfc.mockNFC.setHWStatus(NFCHWStatus.DISABLED); | 71 nfc.mockNFC.setHWStatus(NFCHWStatus.DISABLED); |
| 74 return assertRejectsWithError(navigator.nfc.push(test_text_data), | 72 return assertRejectsWithError(navigator.nfc.push(test_text_data), |
| 75 'NotSupportedError'); | 73 'NotSupportedError'); |
| 76 }, 'nfc.push should fail when NFC HW is disabled.') | 74 }, 'nfc.push should fail when NFC HW is disabled.') |
| 77 | 75 |
| 78 nfc_test(nfc => { | 76 nfc_test(nfc => { |
| 79 nfc.mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED); | 77 nfc.mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED); |
| 80 return assertRejectsWithError(navigator.nfc.push(test_text_data), | 78 return assertRejectsWithError(navigator.nfc.push(test_text_data), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 return assertRejectsWithError(promise, 'AbortError'); | 142 return assertRejectsWithError(promise, 'AbortError'); |
| 145 }, 'nfc.cancelPush should reject pending promise with AbortError.') | 143 }, 'nfc.cancelPush should reject pending promise with AbortError.') |
| 146 | 144 |
| 147 nfc_test(nfc => { | 145 nfc_test(nfc => { |
| 148 return assertRejectsWithError( | 146 return assertRejectsWithError( |
| 149 navigator.nfc.push(new ArrayBuffer(32 * 1024 + 1)), | 147 navigator.nfc.push(new ArrayBuffer(32 * 1024 + 1)), |
| 150 'NotSupportedError'); | 148 'NotSupportedError'); |
| 151 }, 'Reject promise with NotSupportedError if NFC message size exceeds 32KB.'); | 149 }, 'Reject promise with NotSupportedError if NFC message size exceeds 32KB.'); |
| 152 | 150 |
| 153 </script> | 151 </script> |
| OLD | NEW |