Skip to content

Commit

Permalink
Background Fetch: use permission context directly when initiating fetch.
Browse files Browse the repository at this point in the history
This reduces duplicated logic between BackgroundFetchDelegateImpl and
BackgroundFetchPermissionContext. It also forces the logic to align.
Specifically, the permission context returned ALLOW when automatic DLs
were allowed, but the implementation enforced ASK even if auto DLs
are allowed.

This temporarily regresses WebLayer because there's no
Background Fetch permission context there, but that will be addressed
soon.

Bug: 1189247, 1057770
Change-Id: I5441f00835c186826927d2ef38612c8e55eb049f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2800512
Commit-Queue: Evan Stade <[email protected]>
Reviewed-by: Nasko Oskov <[email protected]>
Reviewed-by: Mugdha Lakhani <[email protected]>
Cr-Commit-Position: refs/heads/master@{#872641}
  • Loading branch information
Evan Stade authored and chromium-wpt-export-bot committed Apr 15, 2021
1 parent f4351ba commit c764685
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions background-fetch/resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

let nextBackgroundFetchId = 0;

function loadScript(path) {
let script = document.createElement('script');
let promise = new Promise(resolve => script.onload = resolve);
script.src = path;
script.async = false;
document.head.appendChild(script);
return promise;
}

// Waits for a single message received from a registered Service Worker.
async function getMessageFromServiceWorker() {
return new Promise(resolve => {
Expand Down Expand Up @@ -39,6 +48,13 @@ async function registerAndActivateServiceWorker(test, name) {
// directory to register.
function backgroundFetchTest(func, description, workerName = 'sw.js') {
promise_test(async t => {
if (typeof test_driver === 'undefined') {
await loadScript('/resources/testdriver.js');
await loadScript('/resources/testdriver-vendor.js');
}

await test_driver.set_permission({name: 'background-fetch'}, 'granted');

const serviceWorkerRegistration =
await registerAndActivateServiceWorker(t, workerName);
serviceWorkerRegistration.active.postMessage(null);
Expand Down

0 comments on commit c764685

Please sign in to comment.