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

Unified 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: Rebased to master. Added back finalization to NFC class. Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
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..40ef9b349437b3d6e7c53066c1c3e5d755629cb5
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/nfc/push.html
@@ -0,0 +1,157 @@
+<!DOCTYPE html>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharness-helpers.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';
+
+var invalid_messages =
kenneth.christiansen 2016/04/14 14:29:27 Guess we could use const/let here
shalamov 2016/04/15 07:56:39 Done.
+ [
+ // 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)])
+ ];
+
+promise_test(() => {
+ return assert_promise_rejects(
+ navigator.nfc.push(undefined),
+ 'TypeMismatchError');
+}, 'Reject promise with TypeMismatchError if invalid type is provided.');
+
+invalid_messages.forEach((message) => {
kenneth.christiansen 2016/04/14 14:29:27 no need to put () around message
shalamov 2016/04/15 07:56:39 Done.
+ promise_test(() => {
+ return assert_promise_rejects(
+ navigator.nfc.push(message),
+ 'SyntaxError');
+ }, 'Reject promise with SyntaxError if NFCMessage is invalid.');
+});
+
+nfc_test(nfc => {
+ nfc.mockNFC.setHWStatus(NFCHWStatus.DISABLED);
+ return assert_promise_rejects(
+ navigator.nfc.push(test_text_data),
+ 'NotSupportedError');
+}, 'nfc.push should fail when NFC HW is disabled.')
+
+nfc_test(nfc => {
+ nfc.mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED);
+ return assert_promise_rejects(
+ navigator.nfc.push(test_text_data),
+ '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 assert_promise_rejects(
+ 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.')
+
+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', 10, 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);
+ let promise = navigator.nfc.push(test_text_data, { timeout: 10000 });
+ navigator.nfc.cancelPush();
+ return assert_promise_rejects(
+ promise,
+ 'AbortError');
+}, 'nfc.cancelPush should reject pending promise with AbortError.')
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698