Index: third_party/WebKit/LayoutTests/nfc/push.html |
diff --git a/third_party/WebKit/LayoutTests/nfc/push.html b/third_party/WebKit/LayoutTests/nfc/push.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ae44e25c31a063caa4fc6fbfce1e26765eab96c2 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/nfc/push.html |
@@ -0,0 +1,170 @@ |
+<!DOCTYPE html> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script src="../resources/mojo-helpers.js"></script> |
+<script src="resources/nfc-helpers.js"></script> |
+<script> |
+ |
+'use strict'; |
+ |
+const invalid_messages = |
+ [ |
+ // NFCMessage.data: should have at least 1 valid record. |
+ // https://w3c.github.io/web-nfc/#the-push-method - Step 8. |
+ createMessage([{}]), |
+ |
+ // https://w3c.github.io/web-nfc/#dfn-map-text-to-ndef |
+ // NFCRecord must have data. |
+ createMessage([createTextRecord()]), |
+ |
+ // NFCRecord.mediaType for 'text' record must be text/* . |
+ createMessage([createRecord('text', 'application/json', |
+ test_number_data)]), |
+ |
+ // NFCRecord.data for 'text' record must be number or string. |
+ createMessage([createTextRecord(test_buffer_data)]), |
+ createMessage([createTextRecord(test_json_data)]), |
+ |
+ // https://w3c.github.io/web-nfc/#dfn-map-a-json-object-to-ndef |
+ // NFCRecord must have data. |
+ createMessage([createJsonRecord()]), |
+ |
+ // NFCRecord.data for 'json' record must be object. |
+ createMessage([createJsonRecord(test_buffer_data)]), |
+ createMessage([createJsonRecord(test_number_data)]), |
+ createMessage([createJsonRecord(test_text_data)]), |
+ |
+ // NFCRecord.mediaType for 'json' record must be 'application/json'. |
+ createMessage([createRecord('json', 'image/png', test_json_data)]), |
+ |
+ // https://w3c.github.io/web-nfc/#dfn-map-a-url-to-ndef |
+ // NFCRecord must have data. |
+ createMessage([createUrlRecord()]), |
+ |
+ // NFCRecord.data for 'url' record must be string. |
+ createMessage([createUrlRecord(test_buffer_data)]), |
+ createMessage([createUrlRecord(test_number_data)]), |
+ createMessage([createUrlRecord(test_json_data)]), |
+ |
+ // https://w3c.github.io/web-nfc/#dfn-map-binary-data-to-ndef |
+ // NFCRecord must have data. |
+ createMessage([createOpaqueRecord()]), |
+ // NFCRecord.data for 'opaque' record must be ArrayBuffer. |
+ createMessage([createOpaqueRecord(test_text_data)]), |
+ createMessage([createOpaqueRecord(test_number_data)]), |
+ createMessage([createOpaqueRecord(test_json_data)]) |
+ ]; |
+ |
+nfc_test(nfc => { |
+ return promise_test(test => { |
+ promise_rejects(test, 'TypeMismatchError', navigator.nfc.push(undefined)); |
+ }, 'Reject promise with TypeMismatchError if invalid type is provided.'); |
+}, 'Test that passing undefined to nfc.push would raise TypeMismatchError.'); |
+ |
+nfc_test(nfc => { |
+ let promises = []; |
+ invalid_messages.forEach(message => { |
+ promises.push(promise_test(test => { |
+ promise_rejects(test, 'SyntaxError', navigator.nfc.push(message)); |
+ }, 'Promise rejected with SyntaxError.')); |
+ }); |
+ return Promise.all(promises) |
+}, 'Test that promise is rejected with SyntaxError if NFCMessage is invalid.'); |
+ |
+ |
+nfc_test(nfc => { |
+ nfc.mockNFC.setHWStatus(NFCHWStatus.DISABLED); |
+ return promise_test(test => { |
+ promise_rejects(test, 'NotSupportedError', navigator.nfc.push(test_text_data)); |
+ }, 'Promise rejected with NotSupportedError.'); |
+}, 'nfc.push should fail when NFC HW is disabled.') |
+ |
+nfc_test(nfc => { |
+ nfc.mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED); |
+ return promise_test(test => { |
+ promise_rejects(test, 'NotSupportedError', navigator.nfc.push(test_text_data)); |
+ }, 'Promise rejected with NotSupportedError.'); |
+}, 'nfc.push should fail when NFC HW is not supported.') |
+ |
+nfc_test(nfc => { |
+ return navigator.nfc.push(test_text_data, { timeout: 1 }); |
+}, 'nfc.push should succeed when NFC HW is enabled'); |
+ |
+nfc_test(nfc => { |
+ nfc.mockNFC.setPendingPushCompleted(false); |
+ return promise_test(test => { |
+ promise_rejects(test, 'TimeoutError', |
+ navigator.nfc.push(test_text_data,{ timeout: 1 })); |
+ }, 'Promise rejected with TimeoutError.'); |
+}, 'nfc.push should fail with TimeoutError when push operation is not' + |
+ ' completed before specified timeout value.') |
+ |
+nfc_test(nfc => { |
+ let message = createMessage([createTextRecord(test_text_data), |
+ createJsonRecord(test_json_data), |
+ createOpaqueRecord(test_buffer_data), |
+ createTextRecord(test_number_data), |
+ createUrlRecord(test_url_data)], |
+ test_message_origin); |
+ return navigator.nfc.push(message).then(() => { |
+ nfc.assertNFCMessagesEqual(message, nfc.mockNFC.pushedMessage()); |
+ }); |
+}, 'nfc.push NFCMessage containing text, json, opaque and url records with default ' |
+ + 'NFCPushOptions.'); |
+ |
+nfc_test(nfc => { |
+ return navigator.nfc.push(test_text_data).then(() => { |
+ nfc.assertNFCMessagesEqual(test_text_data, nfc.mockNFC.pushedMessage()); |
+ }); |
+}, 'nfc.push String with default NFCPushOptions.'); |
+ |
+nfc_test(nfc => { |
+ return navigator.nfc.push(test_buffer_data).then(() => { |
+ nfc.assertNFCMessagesEqual(test_buffer_data, nfc.mockNFC.pushedMessage()); |
+ }); |
+}, 'nfc.push ArrayBuffer with default NFCPushOptions.'); |
+ |
+nfc_test(nfc => { |
+ return navigator.nfc.push(test_text_data).then(() => { |
+ nfc.assertNFCPushOptionsEqual(createNFCPushOptions('any', Infinity, true), |
+ nfc.mockNFC.pushOptions()); |
+ }); |
+}, 'Check that default NFCPushOptions values are correctly set.'); |
+ |
+nfc_test(nfc => { |
+ let nfcPushOptions = createNFCPushOptions('tag', 1, false); |
+ return navigator.nfc.push(test_text_data, nfcPushOptions).then(() => { |
+ nfc.assertNFCPushOptionsEqual(nfcPushOptions, nfc.mockNFC.pushOptions()); |
+ }); |
+}, 'Check that provided NFCPushOptions values are correctly converted.'); |
+ |
+nfc_test(nfc => { |
+ return navigator.nfc.push(test_buffer_data).then(() => { |
+ nfc.assertNFCMessagesEqual(test_buffer_data, nfc.mockNFC.pushedMessage()); |
+ }); |
+}, 'Push ArrayBuffer with default NFCPushOptions.'); |
+ |
+nfc_test(nfc => { |
+ return navigator.nfc.push(test_text_data) |
+ .then(() => { navigator.nfc.cancelPush }); |
+}, 'nfc.cancelPush should succeed if there is pending push operation.'); |
+ |
+nfc_test(nfc => { |
+ nfc.mockNFC.setPendingPushCompleted(false); |
+ return promise_test(test => { |
+ promise_rejects(test, 'TimeoutError', |
+ navigator.nfc.push(test_text_data,{ timeout: 1 })); |
+ }, 'Promise rejected with TimeoutError.'); |
+}, 'nfc.push should fail with TimeoutError when push operation is not' + |
+ ' completed before specified timeout value.') |
+ |
+nfc_test(nfc => { |
+ nfc.mockNFC.setPendingPushCompleted(false); |
+ let promise = navigator.nfc.push(test_text_data, { timeout: 100 }); |
+ navigator.nfc.cancelPush(); |
+ return promise_test(test => { |
+ promise_rejects(test, 'AbortError', promise); |
+ }, 'Promise rejected with AbortError.'); |
+}, 'nfc.cancelPush should reject pending promise with AbortError.') |
+ |
+</script> |