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 |
index 00bc82c1a317f809effb25068a9521dfb3950359..c55d9f60f5d0256364fb00cde2a86762d771c44c 100644 |
--- a/third_party/WebKit/LayoutTests/nfc/push.html |
+++ b/third_party/WebKit/LayoutTests/nfc/push.html |
@@ -7,7 +7,7 @@ |
'use strict'; |
-const invalid_messages = |
+const invalid_type_messages = |
[ |
// Invalid NFCPushMessage type |
undefined, |
@@ -20,10 +20,6 @@ const invalid_messages = |
// 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)]), |
@@ -37,9 +33,6 @@ const invalid_messages = |
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()]), |
@@ -58,9 +51,25 @@ const invalid_messages = |
createMessage([createOpaqueRecord(test_json_data)]) |
]; |
+const invalid_syntax_messages = |
+ [ |
+ // NFCRecord.mediaType for 'text' record must be 'text/*'. |
+ createMessage([createRecord('text', 'application/json', |
+ test_number_data)]), |
+ |
+ // Data for 'url' record, must be a valid URL. |
+ createMessage([createUrlRecord('Invalid URL:// Data')]), |
+ |
+ // NFCRecord.mediaType for 'json' record must be 'application/json' or |
+ // starts with 'application/' and ends with '+json'. |
+ createMessage([createRecord('json', 'image/png', test_json_data)]), |
+ createMessage([createRecord('json', 'application/x+y', test_json_data)]), |
+ createMessage([createRecord('json', 'custom/app+json', test_json_data)]), |
+ ]; |
+ |
nfc_test(nfc => { |
let promises = []; |
- invalid_messages.forEach(message => { |
+ invalid_type_messages.forEach(message => { |
promises.push( |
assertRejectsWithError(navigator.nfc.push(message), 'TypeError')); |
}); |
@@ -68,16 +77,26 @@ nfc_test(nfc => { |
}, 'Test that promise is rejected with TypeError if NFCMessage is invalid.'); |
nfc_test(nfc => { |
+ let promises = []; |
+ invalid_syntax_messages.forEach(message => { |
+ promises.push( |
+ assertRejectsWithError(navigator.nfc.push(message), 'SyntaxError')); |
+ }); |
+ return Promise.all(promises) |
+}, 'Test that promise is rejected with SyntaxError if NFCMessage contains' + |
+ ' invalid records.'); |
+ |
+nfc_test(nfc => { |
nfc.mockNFC.setHWStatus(NFCHWStatus.DISABLED); |
return assertRejectsWithError(navigator.nfc.push(test_text_data), |
'NotSupportedError'); |
-}, 'nfc.push should fail when NFC HW is disabled.') |
+}, 'nfc.push should fail when NFC HW is disabled.'); |
nfc_test(nfc => { |
nfc.mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED); |
return assertRejectsWithError(navigator.nfc.push(test_text_data), |
'NotSupportedError'); |
-}, 'nfc.push should fail when NFC HW is not supported.') |
+}, 'nfc.push should fail when NFC HW is not supported.'); |
nfc_test(nfc => { |
return navigator.nfc.push(test_text_data, { timeout: 1 }); |
@@ -99,7 +118,7 @@ nfc_test(nfc => { |
navigator.nfc.push(test_text_data,{ timeout: 1 }), |
'TimeoutError'); |
}, 'nfc.push should fail with TimeoutError when push operation is not' + |
- ' completed before specified timeout value.') |
+ ' completed before specified timeout value.'); |
nfc_test(nfc => { |
let message = createMessage([createTextRecord(test_text_data), |
@@ -127,6 +146,10 @@ nfc_test(nfc => { |
}, 'nfc.push ArrayBuffer with default NFCPushOptions.'); |
nfc_test(nfc => { |
+ return navigator.nfc.push(createMessage([createRecord('empty')])); |
+}, 'nfc.push with "empty" record should succeed.'); |
+ |
+nfc_test(nfc => { |
return navigator.nfc.push(test_text_data).then(() => { |
nfc.assertNFCPushOptionsEqual(createNFCPushOptions('any', Infinity, true), |
nfc.mockNFC.pushOptions()); |
@@ -150,7 +173,7 @@ nfc_test(nfc => { |
let promise = navigator.nfc.push(test_text_data, { timeout: 100 }); |
navigator.nfc.cancelPush(); |
return assertRejectsWithError(promise, 'AbortError'); |
-}, 'nfc.cancelPush should reject pending promise with AbortError.') |
+}, 'nfc.cancelPush should reject pending promise with AbortError.'); |
nfc_test(nfc => { |
return assertRejectsWithError( |
@@ -158,4 +181,21 @@ nfc_test(nfc => { |
'NotSupportedError'); |
}, 'Reject promise with NotSupportedError if NFC message size exceeds 32KB.'); |
+nfc_test(nfc => { |
+ let message = createMessage([createTextRecord(test_text_data)]); |
+ message.url = '%00/invalid/ path'; |
+ return assertRejectsWithError( |
+ navigator.nfc.push(message), |
+ 'SyntaxError'); |
+}, 'Reject promise with SyntaxError if WebNFC Id cannot be created from' + |
+ ' provided URL.'); |
+ |
+nfc_test(nfc => { |
+ let message = createMessage([createRecord('json','application/json', |
+ { get x(){ return this; } })]); |
+ return assertRejectsWithError( |
+ navigator.nfc.push(message), |
+ 'SyntaxError'); |
+}, 'Reject promise with SyntaxError if "json" record cannot be serialized.'); |
+ |
</script> |