Index: third_party/WebKit/LayoutTests/nfc/watch.html |
diff --git a/third_party/WebKit/LayoutTests/nfc/watch.html b/third_party/WebKit/LayoutTests/nfc/watch.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6c2d3c5c610951cc5ca6da4fb3be97d6b523ef36 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/nfc/watch.html |
@@ -0,0 +1,89 @@ |
+<!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'; |
+ |
+nfc_test(nfc => { |
+ return navigator.nfc.watch(message => {}); |
+}, 'nfc.watch should succeed if NFC HW is enabled.') |
kenneth.christiansen
2016/04/25 08:31:47
hardware
shalamov
2016/04/25 11:31:04
Done.
|
+ |
+nfc_test(nfc => { |
+ nfc.mockNFC.setHWStatus(NFCHWStatus.DISABLED); |
+ return assert_promise_rejects( |
+ navigator.nfc.watch(message => {}), |
kenneth.christiansen
2016/04/25 08:31:47
why not define
function noop() {} and use noop ev
shalamov
2016/04/25 11:31:04
Done.
|
+ 'NotSupportedError'); |
+}, 'nfc.watch should fail if NFC HW is disabled.') |
+ |
+nfc_test(nfc => { |
+ nfc.mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED); |
+ return assert_promise_rejects( |
+ navigator.nfc.watch(message => {}), |
+ 'NotSupportedError'); |
+}, 'nfc.watch should fail if NFC functionality is not supported.') |
+ |
+nfc_test(nfc => { |
+ return navigator.nfc.watch(message => {}). |
+ then(() => { |
+ nfc.assertNFCWatchOptionsEqual(createNFCWatchOptions(), nfc.mockNFC.watchOptions()); |
+ }); |
+}, 'nfc.watch test that default NFCWatchOptions values are set correctly.') |
+ |
+nfc_test(nfc => { |
+ let watchOptions = createNFCWatchOptions(test_message_origin, 'json', |
+ 'application/json', 'any'); |
+ return navigator.nfc.watch(message => {}, watchOptions). |
+ then(() => { |
+ nfc.assertNFCWatchOptionsEqual(watchOptions, nfc.mockNFC.watchOptions()); |
+ }); |
+}, 'nfc.watch test that default NFCWatchOptions values are set correctly.') |
+ |
+nfc_test(nfc => { |
+ return assert_promise_rejects( |
+ navigator.nfc.cancelWatch(1), |
+ 'NotFoundError'); |
+}, 'nfc.cancelWatch should fail if invalid watch ID is provided.') |
+ |
+nfc_test(nfc => { |
+ return assert_promise_rejects( |
+ navigator.nfc.cancelWatch(), |
+ 'NotFoundError'); |
+}, 'nfc.cancelWatch should fail if there are no active watchers.') |
+ |
+nfc_test(nfc => { |
+ return navigator.nfc.watch(message => {}). |
+ then(id => { navigator.nfc.cancelWatch(id); }); |
+}, 'nfc.cancelWatch should succeed if there are active watchers.') |
+ |
+nfc_test(nfc => { |
+ return navigator.nfc.watch(message => {}). |
+ then(() => { navigator.nfc.cancelWatch(); }); |
+}, 'nfc.cancelWatch should succeed and cancel all active watchers.') |
+ |
+nfc_test(nfc => { |
+ return navigator.nfc.watch(message => {}). |
+ then(() => { navigator.nfc.cancelWatch(); }); |
+}, 'nfc.cancelWatch should succeed and cancel all active watchers.') |
+ |
+ |
+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 new Promise((resolve, reject) => { |
kenneth.christiansen
2016/04/25 08:31:47
why do you need a new promise if it already return
shalamov
2016/04/25 11:31:04
New promise is a wrapper for successful callback i
|
+ navigator.nfc.watch((receivedMessage) => { |
+ nfc.assertWebNFCMessagesEqual(message, receivedMessage); |
+ resolve(); |
+ }).then(id => { nfc.mockNFC.triggerWatchCallback(id, message);}, reject); |
+ }); |
+}, 'nfc.watch should trigger callback with valid NFCMessage.') |
+ |
+</script> |