Commit 8a7f390a authored by Francois Beaufort's avatar Francois Beaufort Committed by Chromium LUCI CQ

[WebNFC] Remove unused CancelAllWatches

This CL removes the unused method CancelAllWatches() that used to cancel
all watch NFC operations. It also removes one duplicated web platform
test that was referencing obsolete NDEFScanOptions id.

Change-Id: I1a702cae22b7525a9229da818bec91255a273f4b
Bug: 520391
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2554575Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarRijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/master@{#832300}
parent 3c0b2d00
...@@ -266,25 +266,6 @@ public class NfcImpl implements Nfc { ...@@ -266,25 +266,6 @@ public class NfcImpl implements Nfc {
} }
} }
/**
* Cancels all NFC watch operations.
*
* @param callback that is used to notify caller when cancelAllWatches() is completed.
*/
@Override
public void cancelAllWatches(CancelAllWatchesResponse callback) {
if (!checkIfReady(callback)) return;
if (mWatchIds.size() == 0) {
callback.call(
createError(NdefErrorType.NOT_FOUND, "No pending scan operation to cancel."));
} else {
mWatchIds.clear();
callback.call(null);
disableReaderModeIfNeeded();
}
}
@Override @Override
public void close() { public void close() {
mDelegate.stopTrackingActivityForHost(mHostId); mDelegate.stopTrackingActivityForHost(mHostId);
...@@ -382,8 +363,8 @@ public class NfcImpl implements Nfc { ...@@ -382,8 +363,8 @@ public class NfcImpl implements Nfc {
/** /**
* Uses checkIfReady() method and if NFC cannot be used, calls mojo callback with NdefError. * Uses checkIfReady() method and if NFC cannot be used, calls mojo callback with NdefError.
* *
* @param callback Generic callback that is provided to push(), cancelPush(), * @param callback Generic callback that is provided to push(), cancelPush(), and
* cancelWatch() and cancelAllWatches() methods. * cancelWatch() methods.
* @return boolean true if NFC functionality can be used, false otherwise. * @return boolean true if NFC functionality can be used, false otherwise.
*/ */
private boolean checkIfReady(Callbacks.Callback1<NdefError> callback) { private boolean checkIfReady(Callbacks.Callback1<NdefError> callback) {
......
...@@ -50,7 +50,6 @@ import org.chromium.device.mojom.NdefMessage; ...@@ -50,7 +50,6 @@ import org.chromium.device.mojom.NdefMessage;
import org.chromium.device.mojom.NdefRecord; import org.chromium.device.mojom.NdefRecord;
import org.chromium.device.mojom.NdefRecordTypeCategory; import org.chromium.device.mojom.NdefRecordTypeCategory;
import org.chromium.device.mojom.NdefWriteOptions; import org.chromium.device.mojom.NdefWriteOptions;
import org.chromium.device.mojom.Nfc.CancelAllWatchesResponse;
import org.chromium.device.mojom.Nfc.CancelPushResponse; import org.chromium.device.mojom.Nfc.CancelPushResponse;
import org.chromium.device.mojom.Nfc.CancelWatchResponse; import org.chromium.device.mojom.Nfc.CancelWatchResponse;
import org.chromium.device.mojom.Nfc.PushResponse; import org.chromium.device.mojom.Nfc.PushResponse;
...@@ -176,8 +175,8 @@ public class NFCTest { ...@@ -176,8 +175,8 @@ public class NFCTest {
doReturn(null).when(mNfcManager).getDefaultAdapter(); doReturn(null).when(mNfcManager).getDefaultAdapter();
TestNfcImpl nfc = new TestNfcImpl(mContext, mDelegate); TestNfcImpl nfc = new TestNfcImpl(mContext, mDelegate);
mDelegate.invokeCallback(); mDelegate.invokeCallback();
CancelAllWatchesResponse mockCallback = mock(CancelAllWatchesResponse.class); WatchResponse mockCallback = mock(WatchResponse.class);
nfc.cancelAllWatches(mockCallback); nfc.watch(mNextWatchId, mockCallback);
verify(mockCallback).call(mErrorCaptor.capture()); verify(mockCallback).call(mErrorCaptor.capture());
assertEquals(NdefErrorType.NOT_SUPPORTED, mErrorCaptor.getValue().errorType); assertEquals(NdefErrorType.NOT_SUPPORTED, mErrorCaptor.getValue().errorType);
} }
...@@ -192,8 +191,8 @@ public class NFCTest { ...@@ -192,8 +191,8 @@ public class NFCTest {
.when(mContext) .when(mContext)
.checkPermission(anyString(), anyInt(), anyInt()); .checkPermission(anyString(), anyInt(), anyInt());
TestNfcImpl nfc = new TestNfcImpl(mContext, mDelegate); TestNfcImpl nfc = new TestNfcImpl(mContext, mDelegate);
CancelAllWatchesResponse mockCallback = mock(CancelAllWatchesResponse.class); WatchResponse mockCallback = mock(WatchResponse.class);
nfc.cancelAllWatches(mockCallback); nfc.watch(mNextWatchId, mockCallback);
verify(mockCallback).call(mErrorCaptor.capture()); verify(mockCallback).call(mErrorCaptor.capture());
assertEquals(NdefErrorType.NOT_ALLOWED, mErrorCaptor.getValue().errorType); assertEquals(NdefErrorType.NOT_ALLOWED, mErrorCaptor.getValue().errorType);
} }
...@@ -1248,32 +1247,6 @@ public class NFCTest { ...@@ -1248,32 +1247,6 @@ public class NFCTest {
.onWatch(any(int[].class), nullable(String.class), any(NdefMessage.class)); .onWatch(any(int[].class), nullable(String.class), any(NdefMessage.class));
} }
/**
* Test that Nfc.cancelAllWatches() cancels all pending watch operations.
*/
@Test
@Feature({"NFCTest"})
public void testCancelAllWatches() {
TestNfcImpl nfc = new TestNfcImpl(mContext, mDelegate);
mDelegate.invokeCallback();
WatchResponse mockWatchCallback1 = mock(WatchResponse.class);
WatchResponse mockWatchCallback2 = mock(WatchResponse.class);
nfc.watch(mNextWatchId++, mockWatchCallback1);
verify(mockWatchCallback1).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
nfc.watch(mNextWatchId++, mockWatchCallback2);
verify(mockWatchCallback2).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
CancelAllWatchesResponse mockCallback = mock(CancelAllWatchesResponse.class);
nfc.cancelAllWatches(mockCallback);
// Check that cancel request was successfuly completed.
verify(mockCallback).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
}
/** /**
* Test that Nfc.cancelWatch() with invalid id is failing with NOT_FOUND error. * Test that Nfc.cancelWatch() with invalid id is failing with NOT_FOUND error.
*/ */
...@@ -1295,22 +1268,6 @@ public class NFCTest { ...@@ -1295,22 +1268,6 @@ public class NFCTest {
assertEquals(NdefErrorType.NOT_FOUND, mErrorCaptor.getValue().errorType); assertEquals(NdefErrorType.NOT_FOUND, mErrorCaptor.getValue().errorType);
} }
/**
* Test that Nfc.cancelAllWatches() is failing with NOT_FOUND error if there are no active
* watch opeartions.
*/
@Test
@Feature({"NFCTest"})
public void testCancelAllWatchesWithNoWathcers() {
TestNfcImpl nfc = new TestNfcImpl(mContext, mDelegate);
mDelegate.invokeCallback();
CancelAllWatchesResponse mockCallback = mock(CancelAllWatchesResponse.class);
nfc.cancelAllWatches(mockCallback);
verify(mockCallback).call(mErrorCaptor.capture());
assertEquals(NdefErrorType.NOT_FOUND, mErrorCaptor.getValue().errorType);
}
/** /**
* Test that when the tag in proximity is found to be not NDEF compatible, an error event will * Test that when the tag in proximity is found to be not NDEF compatible, an error event will
* be dispatched to the client and the pending push operation will also be ended with an error. * be dispatched to the client and the pending push operation will also be ended with an error.
...@@ -1574,11 +1531,11 @@ public class NFCTest { ...@@ -1574,11 +1531,11 @@ public class NFCTest {
verify(mNfcAdapter, times(0)).disableReaderMode(mActivity); verify(mNfcAdapter, times(0)).disableReaderMode(mActivity);
CancelAllWatchesResponse mockCancelCallback = mock(CancelAllWatchesResponse.class); CancelWatchResponse mockCancelWatchCallback = mock(CancelWatchResponse.class);
nfc.cancelAllWatches(mockCancelCallback); nfc.cancelWatch(mNextWatchId, mockCancelWatchCallback);
// Check that cancel request was successfuly completed. // Check that cancel request was successfuly completed.
verify(mockCancelCallback).call(mErrorCaptor.capture()); verify(mockCancelWatchCallback).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue()); assertNull(mErrorCaptor.getValue());
// Reader mode is disabled when there are no pending push / watch operations. // Reader mode is disabled when there are no pending push / watch operations.
......
...@@ -103,9 +103,11 @@ struct NDEFWriteOptions { ...@@ -103,9 +103,11 @@ struct NDEFWriteOptions {
bool overwrite; bool overwrite;
}; };
// Interface used by Web NFC to push data to NFC devices and get notified of
// nearby NFC devices.
interface NFC { interface NFC {
// NFCClient interface is used to notify |client| when NDEFMessage matches one // NFCClient interface is used to notify |client| when watching for nearby
// or more pending watch operations. // NFC devices.
SetClient(pending_remote<NFCClient> client); SetClient(pending_remote<NFCClient> client);
// Pushes data to NFC device. // Pushes data to NFC device.
...@@ -121,11 +123,10 @@ interface NFC { ...@@ -121,11 +123,10 @@ interface NFC {
// Cancels watch operation with provided id. // Cancels watch operation with provided id.
CancelWatch (uint32 id) => (NDEFError? error); CancelWatch (uint32 id) => (NDEFError? error);
// Cancels all watch operations.
CancelAllWatches () => (NDEFError? error);
}; };
// Interface that client of the NFC interface must implement to get notified of
// nearby NFC devices.
interface NFCClient { interface NFCClient {
// Sends |message| to those readers that have registered |watch_ids| via // Sends |message| to those readers that have registered |watch_ids| via
// NFC.Watch(), i.e. |message| matches their filtering criteria. // NFC.Watch(), i.e. |message| matches their filtering criteria.
......
...@@ -127,10 +127,6 @@ class FakeNfcService : public device::mojom::blink::NFC { ...@@ -127,10 +127,6 @@ class FakeNfcService : public device::mojom::blink::NFC {
std::move(callback).Run(nullptr); std::move(callback).Run(nullptr);
} }
} }
void CancelAllWatches(CancelAllWatchesCallback callback) override {
watchIDs_.clear();
std::move(callback).Run(nullptr);
}
device::mojom::blink::NDEFErrorPtr watch_error_; device::mojom::blink::NDEFErrorPtr watch_error_;
device::mojom::blink::NDEFMessagePtr tag_message_; device::mojom::blink::NDEFMessagePtr tag_message_;
......
...@@ -224,15 +224,6 @@ var WebNFCTest = (() => { ...@@ -224,15 +224,6 @@ var WebNFCTest = (() => {
return createNDEFError(null); return createNDEFError(null);
} }
async cancelAllWatches() {
if (this.watchers_.length === 0) {
return createNDEFError(device.mojom.NDEFErrorType.NOT_FOUND);
}
this.watchers_.splice(0, this.watchers_.length);
return createNDEFError(null);
}
getHWError() { getHWError() {
if (this.hw_status_ === NFCHWStatus.DISABLED) if (this.hw_status_ === NFCHWStatus.DISABLED)
return createNDEFError(device.mojom.NDEFErrorType.NOT_READABLE); return createNDEFError(device.mojom.NDEFErrorType.NOT_READABLE);
......
...@@ -107,20 +107,6 @@ nfc_test(async (t, mockNFC) => { ...@@ -107,20 +107,6 @@ nfc_test(async (t, mockNFC) => {
await promise; await promise;
}, "Test that nfc watch success if NFC HW is enabled."); }, "Test that nfc watch success if NFC HW is enabled.");
nfc_test(async (t, mockNFC) => {
const ndef = new NDEFReader();
const controller = new AbortController();
const ndefWatcher = new EventWatcher(t, ndef, ["reading", "readingerror"]);
const promise = ndefWatcher.wait_for("reading").then(event => {
assert_true(event instanceof NDEFReadingEvent);
controller.abort();
});
await ndef.scan({signal : controller.signal});
mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
await promise;
}, "Test that NDEFReader.scan matches any ids if NDEFScanOptions.id is undefined.");
nfc_test(async (t, mockNFC) => { nfc_test(async (t, mockNFC) => {
const ndef = new NDEFReader(); const ndef = new NDEFReader();
const controller = new AbortController(); const controller = new AbortController();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment