From c7646854131fe696fa38ae8b5e3e611dc6f52d19 Mon Sep 17 00:00:00 2001 From: Evan Stade Date: Wed, 14 Apr 2021 18:42:49 -0700 Subject: [PATCH] Background Fetch: use permission context directly when initiating fetch. 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 Reviewed-by: Nasko Oskov Reviewed-by: Mugdha Lakhani Cr-Commit-Position: refs/heads/master@{#872641} --- background-fetch/resources/utils.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/background-fetch/resources/utils.js b/background-fetch/resources/utils.js index dbe041941d093e..10895c3ccfc012 100644 --- a/background-fetch/resources/utils.js +++ b/background-fetch/resources/utils.js @@ -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 => { @@ -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);