Skip to content

Commit

Permalink
[WebNFC] Add permission prompt for NDEFReader.scan
Browse files Browse the repository at this point in the history
This CL makes sure NDEFReader.scan shows a permission request if user
didn't previously allow Web NFC.

Screenshots: https://photos.app.goo.gl/k7wz55v9ELVTS19i8

Bug:520391
Change-Id: I10125c8db9a4b1cdd3476939bdf650583c7f19b3
  • Loading branch information
beaufortfrancois authored and chromium-wpt-export-bot committed Nov 22, 2019
1 parent 50fa7d6 commit ddd9131
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
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

0 comments on commit ddd9131

Please sign in to comment.