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

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: Fixes for comments from haraken Created 4 years, 1 month 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..05d94d4b2f17e951a541fa50b733f626221482ac
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/nfc/watch.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<script src="../resources/testharness.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(noop);
+}, 'Test that nfc.watch succeeds if NFC hardware is enabled.');
+
+nfc_test(nfc => {
+ nfc.mockNFC.setHWStatus(NFCHWStatus.DISABLED);
+ return assertRejectsWithError(navigator.nfc.watch(noop), 'NotSupportedError');
+}, 'Test that nfc.watch fails if NFC hardware is disabled.')
+
+nfc_test(nfc => {
+ nfc.mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED);
+ return assertRejectsWithError(navigator.nfc.watch(noop), 'NotSupportedError');
+}, 'Test that nfc.watch fails if NFC hardware is not supported.')
+
+nfc_test(nfc => {
+ return navigator.nfc.watch(noop).
+ then(() => {
+ nfc.assertNFCWatchOptionsEqual(createNFCWatchOptions(), nfc.mockNFC.watchOptions());
+ });
+}, '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(noop, watchOptions).
+ then(() => {
+ nfc.assertNFCWatchOptionsEqual(watchOptions, nfc.mockNFC.watchOptions());
+ });
+}, 'Test that NFCWatchOptions values are correctly converted.')
+
+nfc_test(nfc => {
+ return assertRejectsWithError(navigator.nfc.cancelWatch(1), 'NotFoundError');
+}, 'Test that nfc.cancelWatch fails if invalid watch ID is provided.')
+
+nfc_test(nfc => {
+ return assertRejectsWithError(navigator.nfc.cancelWatch(), 'NotFoundError');
+}, 'Test that nfc.cancelWatch fails if there are no active watchers.')
+
+nfc_test(nfc => {
+ return navigator.nfc.watch(noop).
+ then(id => { navigator.nfc.cancelWatch(id); });
+}, 'Test that nfc.cancelWatch succeeds if correct watch id is provided.')
+
+nfc_test(nfc => {
+ return navigator.nfc.watch(noop).
+ then(() => { navigator.nfc.cancelWatch(); });
+}, 'Test that nfc.cancelWatch succeeds if there are 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) => {
+ navigator.nfc.watch(receivedMessage => {
+ nfc.assertWebNFCMessagesEqual(message, receivedMessage);
+ resolve();
+ }).then(id => { nfc.mockNFC.triggerWatchCallback(id, message); }, reject);
+ });
+}, 'Test that watch callback is triggered with valid NFCMessage.')
+
+</script>
« no previous file with comments | « third_party/WebKit/LayoutTests/nfc/resources/nfc-helpers.js ('k') | third_party/WebKit/Source/modules/nfc/MessageCallback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698