Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WebNFC] Add permission prompt for NDEFReader.scan #20402

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lint.whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ LAYOUTTESTS APIS: import-maps/resources/jest-test-helper.js
LAYOUTTESTS APIS: resources/chromium/generic_sensor_mocks.js
LAYOUTTESTS APIS: resources/chromium/nfc-mock.js
LAYOUTTESTS APIS: resources/chromium/webxr-test.js
LAYOUTTESTS APIS: web-nfc/NDEFReader-document-hidden-manual.https.html
LAYOUTTESTS APIS: web-nfc/NDEFReader_scan.https.html
LAYOUTTESTS APIS: web-nfc/NDEFWriter_push.https.html

# Signed Exchange files have hard-coded URLs in the certUrl field
Expand Down
5 changes: 5 additions & 0 deletions web-nfc/NDEFReader-document-hidden-manual.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
if (document.hidden) reject();
resolve();
});
if (window.testRunner) {
// Grant nfc permissions for Chromium testrunner.
window.testRunner.setPermission('nfc', 'granted',
location.origin, location.origin);
}
await reader.scan();
await promise;
}, "Test NDEFReader.onreading is not fired when document is hidden");
Expand Down
10 changes: 10 additions & 0 deletions web-nfc/NDEFReader_scan.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
}, "Test that NDEFReader.scan rejects if NDEFScanOptions.id has wrong \
protocol.");

promise_test(async t => {
if (window.testRunner) {
// Deny nfc permissions for Chromium testrunner.
window.testRunner.setPermission('nfc', 'denied',
location.origin, location.origin);
}
const reader = new NDEFReader();
await promise_rejects(t, 'NotAllowedError', reader.scan());
}, "NDEFReader.scan should fail if user permission is not granted.");

nfc_test(async (t, mockNFC) => {
mockNFC.setHWStatus(NFCHWStatus.DISABLED);
const reader = new NDEFReader();
Expand Down