Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 7124815

Browse files
Honrychromium-wpt-export-bot
authored andcommitted
[WebNFC] Add test for focused iframe
Following Web NFC spec change at w3c/web-nfc#383, this CL adds a test to check NFC scanning from top-level document will not be stopped when an iframe is focused Bug: 996250, 520391 Change-Id: If89079d7bf9d7dc58587abcd0c9a9a797420aa50 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1862475 Reviewed-by: François Beaufort <[email protected]> Commit-Queue: Wanming Lin <[email protected]> Cr-Commit-Position: refs/heads/master@{#706321}
1 parent ca9c141 commit 7124815

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<meta charset=utf-8>
3+
<title>NFCWriter.scan with an focused iframe</title>
4+
<link rel="help" href="https://w3c.github.io/web-nfc/"/>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="resources/nfc-helpers.js"></script>
8+
<body>
9+
<script>
10+
11+
nfc_test(async (t, mockNFC) => {
12+
const reader = new NFCReader();
13+
const controller = new AbortController();
14+
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
15+
16+
const promise = readerWatcher.wait_for("reading").then(event => {
17+
assert_true(event instanceof NFCReadingEvent);
18+
controller.abort();
19+
});
20+
reader.scan({ signal: controller.signal });
21+
22+
const iframe = document.createElement('iframe');
23+
iframe.src = 'resources/support-iframe.html';
24+
25+
const iframeLoadWatcher = new EventWatcher(t, iframe, 'load');
26+
document.body.appendChild(iframe);
27+
await iframeLoadWatcher.wait_for('load');
28+
// Focus on iframe
29+
iframe.contentWindow.document.getElementById('foo').focus();
30+
assert_true(iframe.contentDocument.hasFocus(), 'iframe gains the focus');
31+
32+
mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
33+
await promise;
34+
35+
// Remove iframe from main document.
36+
iframe.parentNode.removeChild(iframe);
37+
}, 'Test that NFCWriter.scan is not suspended if iframe gains focus.');
38+
39+
</script>
40+
</body>

web-nfc/resources/support-iframe.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!DOCTYPE HTML>
2+
<meta charset="utf-8">
3+
<input type="text" id="foo" value="click me!"></input>

0 commit comments

Comments
 (0)