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

Commit 9f31d49

Browse files
xiuqijixHonry
authored andcommitted
Add tests for NFC API in non-visible document (#19664)
1 parent 74286c9 commit 9f31d49

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<meta name="timeout" content="long">
4+
<title>NFCReader.onreading respect page visibility changes</title>
5+
<link rel="help" href="https://w3c.github.io/web-nfc/#visible-document">
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<script>
9+
10+
promise_test(async t => {
11+
const reader = new NFCReader();
12+
reader.scan();
13+
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
14+
15+
return await new Promise((resolve, reject) => {
16+
readerWatcher.wait_for("reading").then(event => {
17+
if (document.hidden) reject();
18+
resolve();
19+
});
20+
});
21+
}, "Test NFCReader.onreading is not fired when document is hidden");
22+
23+
</script>
24+
25+
<p>Step1: switch the page to the background, then tap a formatted NFC tag.</p>
26+
<p>Step2: switch back to the page, then tap the tag again.</p>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<meta name="timeout" content="long">
4+
<title>NFCWriter.push respect page visibility changes</title>
5+
<link rel="help" href="https://w3c.github.io/web-nfc/#visible-document">
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<script src="resources/nfc-helpers.js"></script>
9+
<script>
10+
11+
promise_test(async t => {
12+
const writer = new NFCWriter();
13+
const p1 = writer.push(test_text_data);
14+
15+
return await new Promise((resolve, reject) => {
16+
p1.then(() => {
17+
assert_false(document.hidden);
18+
resolve();
19+
}).catch(e => {
20+
reject();
21+
});
22+
});
23+
}, "Test NFCWriter.push operation should be suspend when document is not visible");
24+
25+
</script>
26+
27+
<p>Step1: switch the page to the background, then tap an NFC tag.</p>
28+
<p>Step2: switch back to the page, then tap the tag again.</p>

0 commit comments

Comments
 (0)