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

Unified Diff: third_party/WebKit/LayoutTests/nfc/watch.html

Issue 1759373003: [webnfc] Implement nfc.watch in blink nfc module. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@implement_nfc_push_in_android
Patch Set: Rebased. 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/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>

Powered by Google App Engine
This is Rietveld 408576698