Commit 7c2e0040 authored by Wanming Lin's avatar Wanming Lin Committed by Commit Bot

[WebNFC] Add test for focused iframe

Following Web NFC spec change at https://github.com/w3c/web-nfc/pull/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/+/1862475Reviewed-by: default avatarFrançois Beaufort <beaufort.francois@gmail.com>
Commit-Queue: Wanming Lin <wanming.lin@intel.com>
Cr-Commit-Position: refs/heads/master@{#706321}
parent 99fb7f7d
<!DOCTYPE html>
<meta charset=utf-8>
<title>NFCWriter.scan with an focused iframe</title>
<link rel="help" href="https://w3c.github.io/web-nfc/"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/nfc-helpers.js"></script>
<body>
<script>
nfc_test(async (t, mockNFC) => {
const reader = new NFCReader();
const controller = new AbortController();
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
const promise = readerWatcher.wait_for("reading").then(event => {
assert_true(event instanceof NFCReadingEvent);
controller.abort();
});
reader.scan({ signal: controller.signal });
const iframe = document.createElement('iframe');
iframe.src = 'resources/support-iframe.html';
const iframeLoadWatcher = new EventWatcher(t, iframe, 'load');
document.body.appendChild(iframe);
await iframeLoadWatcher.wait_for('load');
// Focus on iframe
iframe.contentWindow.document.getElementById('foo').focus();
assert_true(iframe.contentDocument.hasFocus(), 'iframe gains the focus');
mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
await promise;
// Remove iframe from main document.
iframe.parentNode.removeChild(iframe);
}, 'Test that NFCWriter.scan is not suspended if iframe gains focus.');
</script>
</body>
\ No newline at end of file
<!DOCTYPE HTML>
<meta charset="utf-8">
<input type="text" id="foo" value="click me!"></input>
\ No newline at end of file
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