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

Unified Diff: device/nfc/android/junit/src/org/chromium/device/nfc/NFCTest.java

Issue 2845463004: [webnfc] Handle IllegalStateException during read / write operations (Closed)
Patch Set: Created 3 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
« no previous file with comments | « device/nfc/android/java/src/org/chromium/device/nfc/NfcTagHandler.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/nfc/android/junit/src/org/chromium/device/nfc/NFCTest.java
diff --git a/device/nfc/android/junit/src/org/chromium/device/nfc/NFCTest.java b/device/nfc/android/junit/src/org/chromium/device/nfc/NFCTest.java
index 3e0ded2638436cbe749bc95fe36090c94bdb7043..3905d7c0897189ee813905c0318dfc648188a219 100644
--- a/device/nfc/android/junit/src/org/chromium/device/nfc/NFCTest.java
+++ b/device/nfc/android/junit/src/org/chromium/device/nfc/NFCTest.java
@@ -6,6 +6,7 @@ package org.chromium.device.nfc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -13,6 +14,7 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -579,6 +581,50 @@ public class NFCTest {
assertEquals(NfcErrorType.NOT_FOUND, mErrorCaptor.getValue().errorType);
}
+ /**
+ * Test that when tag is disconnected during read operation, IllegalStateException is handled.
+ */
+ @Test
+ @Feature({"NFCTest"})
+ public void testTagDisconnectedDuringRead() throws IOException, FormatException {
+ TestNfcImpl nfc = new TestNfcImpl(mContext);
+ nfc.setActivityForTesting(mActivity);
+ nfc.setClient(mNfcClient);
+ WatchResponse mockWatchCallback = mock(WatchResponse.class);
+ nfc.watch(createNfcWatchOptions(), mockWatchCallback);
+
+ // Force read operation to fail
+ doThrow(IllegalStateException.class).when(mNfcTagHandler).read();
+
+ // Mocks 'NFC tag found' event.
+ nfc.processPendingOperationsForTesting(mNfcTagHandler);
+
+ // Check that client was not notified.
+ verify(mNfcClient, times(0))
+ .onWatch(mOnWatchCallbackCaptor.capture(), any(NfcMessage.class));
+ }
+
+ /**
+ * Test that when tag is disconnected during write operation, IllegalStateException is handled.
+ */
+ @Test
+ @Feature({"NFCTest"})
+ public void testTagDisconnectedDuringWrite() throws IOException, FormatException {
+ TestNfcImpl nfc = new TestNfcImpl(mContext);
+ nfc.setActivityForTesting(mActivity);
+ PushResponse mockCallback = mock(PushResponse.class);
+
+ // Force write operation to fail
+ doThrow(IllegalStateException.class).when(mNfcTagHandler).write(any(NdefMessage.class));
+ nfc.push(createNfcMessage(), createNfcPushOptions(), mockCallback);
+ nfc.processPendingOperationsForTesting(mNfcTagHandler);
+ verify(mockCallback).call(mErrorCaptor.capture());
+
+ // Test that correct error is returned.
+ assertNotNull(mErrorCaptor.getValue());
+ assertEquals(NfcErrorType.IO_ERROR, mErrorCaptor.getValue().errorType);
+ }
+
private NfcPushOptions createNfcPushOptions() {
NfcPushOptions pushOptions = new NfcPushOptions();
pushOptions.target = NfcPushTarget.ANY;
« no previous file with comments | « device/nfc/android/java/src/org/chromium/device/nfc/NfcTagHandler.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698