Update wpt NFC tests to use mojo mocks for unavailable impl
This change updates the wpt tests in web-nfc/ to use the mockNFC object
in the tests that simulate a 'no implementation available' case.
MockNFC now has a new method simulateClosedPipe() which results in the
pipe being closed on a connection request.
This unblocks https://crrev.com/c/2062696, which adds code to crash the
renderer if no binder was found for a requested interface.
Bug: 1047680
Change-Id: Ib8f16f73a78982b2c17bf518d37d05e59ea384ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2072923
Commit-Queue: Oksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744760}
diff --git a/resources/chromium/nfc-mock.js b/resources/chromium/nfc-mock.js
index ce1ad8e..7832a82 100644
--- a/resources/chromium/nfc-mock.js
+++ b/resources/chromium/nfc-mock.js
@@ -144,8 +144,13 @@
this.bindingSet_ = new mojo.BindingSet(device.mojom.NFC);
this.interceptor_ = new MojoInterfaceInterceptor(device.mojom.NFC.name);
- this.interceptor_.oninterfacerequest =
- e => this.bindingSet_.addBinding(this, e.handle);
+ this.interceptor_.oninterfacerequest = e => {
+ if (this.should_close_pipe_on_request_)
+ e.handle.close();
+ else
+ this.bindingSet_.addBinding(this, e.handle);
+ }
+
this.interceptor_.start();
this.hw_status_ = NFCHWStatus.ENABLED;
@@ -159,6 +164,7 @@
this.operations_suspended_ = false;
this.is_formatted_tag_ = false;
this.data_transfer_failed_ = false;
+ this.should_close_pipe_on_request_ = false;
}
// NFC delegate functions.
@@ -278,6 +284,7 @@
this.cancelPendingPushOperation();
this.is_formatted_tag_ = false;
this.data_transfer_failed_ = false;
+ this.should_close_pipe_on_request_ = false;
}
cancelPendingPushOperation() {
@@ -360,6 +367,10 @@
simulateDataTransferFails() {
this.data_transfer_failed_ = true;
}
+
+ simulateClosedPipe() {
+ this.should_close_pipe_on_request_ = true;
+ }
}
let testInternal = {
diff --git a/web-nfc/NDEFReader-document-hidden-manual.https.html b/web-nfc/NDEFReader-document-hidden-manual.https.html
index 9cf42e8..10ce53e 100644
--- a/web-nfc/NDEFReader-document-hidden-manual.https.html
+++ b/web-nfc/NDEFReader-document-hidden-manual.https.html
@@ -5,9 +5,11 @@
<link rel="help" href="https://w3c.github.io/web-nfc/#visible-document">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
+<script src="resources/nfc-helpers.js"></script>
<script>
-promise_test(async t => {
+nfc_test(async (t, mockNFC) => {
+ mockNFC.simulateClosedPipe();
const reader = new NDEFReader();
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
const promise = readerWatcher.wait_for("reading").then(event => {
diff --git a/web-nfc/NDEFReader_scan.https.html b/web-nfc/NDEFReader_scan.https.html
index 6e66b7d..581412e 100644
--- a/web-nfc/NDEFReader_scan.https.html
+++ b/web-nfc/NDEFReader_scan.https.html
@@ -47,7 +47,8 @@
// We do not provide NFC mock here to simulate that there has no available
// implementation for NFC Mojo interface.
-promise_test(async t => {
+nfc_test(async (t, mockNFC) => {
+ mockNFC.simulateClosedPipe();
if (window.testRunner) {
window.testRunner.setPermission('nfc', 'granted',
location.origin, location.origin);
diff --git a/web-nfc/NDEFWriter_write.https.html b/web-nfc/NDEFWriter_write.https.html
index 1cca68c..4ca7faa 100644
--- a/web-nfc/NDEFWriter_write.https.html
+++ b/web-nfc/NDEFWriter_write.https.html
@@ -156,7 +156,8 @@
// We do not provide NFC mock here to simulate that there has no available
// implementation for NFC Mojo interface.
-promise_test(async t => {
+nfc_test(async (t, mockNFC) => {
+ mockNFC.simulateClosedPipe();
if (window.testRunner) {
// Deny nfc permissions for Chromium testrunner.
window.testRunner.setPermission('nfc', 'granted',