Chromium Code Reviews| 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..8a66f971492b763d0ced98cb98fc9e017910805b 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.'); |
|
Reilly Grant (use Gerrit)
2017/05/16 15:21:03
Can an empty record with data succeed?
Alexander Shalamov
2017/05/16 17:49:10
https://w3c.github.io/web-nfc/#mapping-empty-recor
|
| + |
| +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( |