Commit 8907cc01 authored by Oksana Zhuravlova's avatar Oksana Zhuravlova Committed by Commit Bot

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: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744760}
parent dc2407bc
...@@ -144,8 +144,13 @@ var WebNFCTest = (() => { ...@@ -144,8 +144,13 @@ var WebNFCTest = (() => {
this.bindingSet_ = new mojo.BindingSet(device.mojom.NFC); this.bindingSet_ = new mojo.BindingSet(device.mojom.NFC);
this.interceptor_ = new MojoInterfaceInterceptor(device.mojom.NFC.name); this.interceptor_ = new MojoInterfaceInterceptor(device.mojom.NFC.name);
this.interceptor_.oninterfacerequest = this.interceptor_.oninterfacerequest = e => {
e => this.bindingSet_.addBinding(this, e.handle); if (this.should_close_pipe_on_request_)
e.handle.close();
else
this.bindingSet_.addBinding(this, e.handle);
}
this.interceptor_.start(); this.interceptor_.start();
this.hw_status_ = NFCHWStatus.ENABLED; this.hw_status_ = NFCHWStatus.ENABLED;
...@@ -159,6 +164,7 @@ var WebNFCTest = (() => { ...@@ -159,6 +164,7 @@ var WebNFCTest = (() => {
this.operations_suspended_ = false; this.operations_suspended_ = false;
this.is_formatted_tag_ = false; this.is_formatted_tag_ = false;
this.data_transfer_failed_ = false; this.data_transfer_failed_ = false;
this.should_close_pipe_on_request_ = false;
} }
// NFC delegate functions. // NFC delegate functions.
...@@ -278,6 +284,7 @@ var WebNFCTest = (() => { ...@@ -278,6 +284,7 @@ var WebNFCTest = (() => {
this.cancelPendingPushOperation(); this.cancelPendingPushOperation();
this.is_formatted_tag_ = false; this.is_formatted_tag_ = false;
this.data_transfer_failed_ = false; this.data_transfer_failed_ = false;
this.should_close_pipe_on_request_ = false;
} }
cancelPendingPushOperation() { cancelPendingPushOperation() {
...@@ -360,6 +367,10 @@ var WebNFCTest = (() => { ...@@ -360,6 +367,10 @@ var WebNFCTest = (() => {
simulateDataTransferFails() { simulateDataTransferFails() {
this.data_transfer_failed_ = true; this.data_transfer_failed_ = true;
} }
simulateClosedPipe() {
this.should_close_pipe_on_request_ = true;
}
} }
let testInternal = { let testInternal = {
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
<link rel="help" href="https://w3c.github.io/web-nfc/#visible-document"> <link rel="help" href="https://w3c.github.io/web-nfc/#visible-document">
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="resources/nfc-helpers.js"></script>
<script> <script>
promise_test(async t => { nfc_test(async (t, mockNFC) => {
mockNFC.simulateClosedPipe();
const reader = new NDEFReader(); const reader = new NDEFReader();
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]); const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
const promise = readerWatcher.wait_for("reading").then(event => { const promise = readerWatcher.wait_for("reading").then(event => {
......
...@@ -47,7 +47,8 @@ promise_test(async t => { ...@@ -47,7 +47,8 @@ promise_test(async t => {
// We do not provide NFC mock here to simulate that there has no available // We do not provide NFC mock here to simulate that there has no available
// implementation for NFC Mojo interface. // implementation for NFC Mojo interface.
promise_test(async t => { nfc_test(async (t, mockNFC) => {
mockNFC.simulateClosedPipe();
if (window.testRunner) { if (window.testRunner) {
window.testRunner.setPermission('nfc', 'granted', window.testRunner.setPermission('nfc', 'granted',
location.origin, location.origin); location.origin, location.origin);
......
...@@ -156,7 +156,8 @@ promise_test(async t => { ...@@ -156,7 +156,8 @@ promise_test(async t => {
// We do not provide NFC mock here to simulate that there has no available // We do not provide NFC mock here to simulate that there has no available
// implementation for NFC Mojo interface. // implementation for NFC Mojo interface.
promise_test(async t => { nfc_test(async (t, mockNFC) => {
mockNFC.simulateClosedPipe();
if (window.testRunner) { if (window.testRunner) {
// Deny nfc permissions for Chromium testrunner. // Deny nfc permissions for Chromium testrunner.
window.testRunner.setPermission('nfc', 'granted', window.testRunner.setPermission('nfc', 'granted',
......
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