[webnfc] Add test for multi scan from the same NDEFReader object

This CL adds a test for testing multiple scan() from the same
NDEFReader object with new options should replace existing filters.

Test fails at present as which has not been implemented yet.

This CL also rename NDEFReader_options.https.html as
NDEFReader_scan_filter.https.html because NDEFReader has no
construct options any more, and this test file is mainly for
scan filter testing.

BUG=520391

Change-Id: I4d19659c990c0ddc8dc19a5984c55be1ece48e9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1939327
Commit-Queue: Wanming Lin <wanming.lin@intel.com>
Reviewed-by: Leon Han <leon.han@intel.com>
Cr-Commit-Position: refs/heads/master@{#720112}
diff --git a/third_party/blink/web_tests/external/wpt/web-nfc/NDEFReader_scan_filter.https-expected.txt b/third_party/blink/web_tests/external/wpt/web-nfc/NDEFReader_scan_filter.https-expected.txt
new file mode 100644
index 0000000..4c4b71a
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/web-nfc/NDEFReader_scan_filter.https-expected.txt
@@ -0,0 +1,22 @@
+This is a testharness.js-based test.
+PASS Test that reading data succeed when NDEFScanOptions' recordType is set to 'empty'.
+PASS Test that reading data succeed when NDEFScanOptions' recordType is set to 'mime'.
+PASS Test that reading data succeed when NDEFScanOptions' recordType is set to 'unknown'.
+PASS Test that reading data succeed when NDEFScanOptions' recordType is set to 'text'.
+PASS Test that reading data succeed when NDEFScanOptions' recordType is set to 'url'.
+PASS Test that reading data succeed when NDEFScanOptions' recordType is set to 'absolute-url'.
+PASS Test that reading data succeed when NDEFScanOptions' recordType is set to a custom type for external type records.
+PASS Test that the url of NDEFScanOptions filters relevant data sources correctly.
+PASS Test that the mediaType of NDEFScanOptions filters relevant data sources correctly.
+PASS Test that filtering 'empty' record from different messages correctly with NDEFScanOptions' recordType is set to 'empty'.
+PASS Test that filtering 'mime' record from different messages correctly with NDEFScanOptions' recordType is set to 'mime'.
+PASS Test that filtering 'unknown' record from different messages correctly with NDEFScanOptions' recordType is set to 'unknown'.
+PASS Test that filtering 'text' record from different messages correctly with NDEFScanOptions' recordType is set to 'text'.
+PASS Test that filtering 'url' record from different messages correctly with NDEFScanOptions' recordType is set to 'url'.
+PASS Test that filtering 'absolute-url' record from different messages correctly with NDEFScanOptions' recordType is set to 'absolute-url'.
+PASS Test that filtering external record from different messages correctly with NDEFScanOptions' recordType is set to the custom type.
+PASS Test that filtering 'text' record from different messages correctly with NDEFScanOptions' url set.
+PASS Test that filtering 'mime' record from different messages correctly with NDEFScanOptions' mediaType set.
+FAIL Multiple scan() from the same NDEFReader object with new options should replace existing filters. promise_test: Unhandled rejection with value: object "InvalidStateError: Failed to execute 'scan' on 'NDEFReader': There is already a scan() operation ongoing."
+Harness: the test ran to completion.
+
diff --git a/third_party/blink/web_tests/external/wpt/web-nfc/NDEFReader_options.https.html b/third_party/blink/web_tests/external/wpt/web-nfc/NDEFReader_scan_filter.https.html
similarity index 78%
rename from third_party/blink/web_tests/external/wpt/web-nfc/NDEFReader_options.https.html
rename to third_party/blink/web_tests/external/wpt/web-nfc/NDEFReader_scan_filter.https.html
index 6901e5c..4c1e7de 100644
--- a/third_party/blink/web_tests/external/wpt/web-nfc/NDEFReader_options.https.html
+++ b/third_party/blink/web_tests/external/wpt/web-nfc/NDEFReader_scan_filter.https.html
@@ -1,6 +1,6 @@
 <!DOCTYPE html>
 <meta charset=utf-8>
-<title>Web NFC: NDEFReader option tests</title>
+<title>Web NFC: NDEFReader.scan() filter tests</title>
 <link rel="author" title="Intel" href="http://www.intel.com"/>
 <link rel="help" href="https://w3c.github.io/web-nfc/"/>
 <script src="/resources/testharness.js"></script>
@@ -10,7 +10,7 @@
 
 'use strict';
 
-const NDEFReaderOptionTests =
+const multiScanOptionsTests =
   [
     {
       desc: "Test that reading data succeed when NDEFScanOptions'" +
@@ -78,7 +78,7 @@
     }
   ];
 
-const ReadMultiMessagesTests =
+const multiMessagesTests =
   [
     {
       desc: "Test that filtering 'empty' record from different messages" +
@@ -147,21 +147,53 @@
     }
   ];
 
-for (let NDEFReaderOptionTest of NDEFReaderOptionTests) {
-  testNDEFScanOptions(
-    NDEFReaderOptionTest.message,
-    NDEFReaderOptionTest.scanOptions,
-    NDEFReaderOptionTest.unmatchedScanOptions,
-    NDEFReaderOptionTest.desc
+for (let multiScanOptionsTest of multiScanOptionsTests) {
+  testMultiScanOptions(
+    multiScanOptionsTest.message,
+    multiScanOptionsTest.scanOptions,
+    multiScanOptionsTest.unmatchedScanOptions,
+    multiScanOptionsTest.desc
   );
 }
 
-for (let readMultiMessagesTest of ReadMultiMessagesTests) {
-  testReadingMultiMessages(
-    readMultiMessagesTest.message,
-    readMultiMessagesTest.scanOptions,
-    readMultiMessagesTest.unmatchedMessage,
-    readMultiMessagesTest.desc
+for (let multiMessagesTest of multiMessagesTests) {
+  testMultiMessages(
+    multiMessagesTest.message,
+    multiMessagesTest.scanOptions,
+    multiMessagesTest.unmatchedMessage,
+    multiMessagesTest.desc
   );
 }
+
+nfc_test(async (t, mockNFC) => {
+  const reader = new NDEFReader();
+  const controller = new AbortController();
+  const signal = controller.signal;
+  const textMsg = createMessage([createTextRecord(test_text_data)]);
+  const urlMsg = createMessage([createUrlRecord(test_url_data)]);
+  const mimeMsg = createMessage([createMimeRecord(test_buffer_data)]);
+
+  const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
+  const promise = readerWatcher.wait_for("reading").then(event => {
+    controller.abort();
+    assertWebNDEFMessagesEqual(event.message, new NDEFMessage(mimeMsg));
+  });
+
+  const scanOptions1 = { recordType: "text", signal: signal };
+  const scanOptions2 = {recordType: "url", signal: signal };
+  const scanOptions3 = {recordType: "mime", signal: signal };
+
+  await reader.scan(scanOptions1);
+  await reader.scan(scanOptions2);
+  // There is maximum one filter for an NDEFReader object,
+  // last filter will replace all previous ones.
+  await reader.scan(scanOptions3);
+
+  mockNFC.setReadingMessage(textMsg);
+  mockNFC.setReadingMessage(urlMsg);
+  mockNFC.setReadingMessage(mimeMsg);
+  await promise;
+}, "Multiple scan() from the same NDEFReader object with new options should \
+replace existing filters.");
+
 </script>
diff --git a/third_party/blink/web_tests/external/wpt/web-nfc/resources/nfc-helpers.js b/third_party/blink/web_tests/external/wpt/web-nfc/resources/nfc-helpers.js
index eb30061..0fe6fe80 100644
--- a/third_party/blink/web_tests/external/wpt/web-nfc/resources/nfc-helpers.js
+++ b/third_party/blink/web_tests/external/wpt/web-nfc/resources/nfc-helpers.js
@@ -168,7 +168,7 @@
   }
 }
 
-function testNDEFScanOptions(message, scanOptions, unmatchedScanOptions, desc) {
+function testMultiScanOptions(message, scanOptions, unmatchedScanOptions, desc) {
   nfc_test(async (t, mockNFC) => {
     const reader1 = new NDEFReader();
     const reader2 = new NDEFReader();
@@ -192,8 +192,7 @@
   }, desc);
 }
 
-function testReadingMultiMessages(
-    message, scanOptions, unmatchedMessage, desc) {
+function testMultiMessages(message, scanOptions, unmatchedMessage, desc) {
   nfc_test(async (t, mockNFC) => {
     const reader = new NDEFReader();
     const controller = new AbortController();