[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/web-nfc/NDEFReader_options.https.html b/web-nfc/NDEFReader_scan_filter.https.html
similarity index 78%
rename from web-nfc/NDEFReader_options.https.html
rename to web-nfc/NDEFReader_scan_filter.https.html
index 6901e5c..4c1e7de 100644
--- a/web-nfc/NDEFReader_options.https.html
+++ b/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/web-nfc/resources/nfc-helpers.js b/web-nfc/resources/nfc-helpers.js
index eb30061..0fe6fe8 100644
--- a/web-nfc/resources/nfc-helpers.js
+++ b/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();