gecko-dev/testing/web-platform/tests/storage-access-api/helpers.js
Brandon Maslen 22d659d74e Bug 1585279 [wpt PR 19436] - Connect document.requestStorageAccess() to NetworkService, a=testonly
Automatic update from web-platform-tests
Connect document.requestStorageAccess() to NetworkService

This change plumbs successful Document::RequestStorageAccess calls
from blink to the RenderFrameHost and subsequently into the
BrowserContentClient and CookieManager. This call also ensures that the
default StoragePartition in the NetworkService is called to update the
set of storage access grants it has. The original callback in the
Document is gated upon the successful update of the StoragePartition;
this is to ensure no race exists between the renderer process receiving
notice of access being granted and the grant(s) actually being
delivered to the StoragePartition. Currently only the default partition
is signaled to ensure state is not leaked across guest partitions.

Future changes will amend the added methods to ensure that new grants
are conditionally added to the appropriate CONTENT_SETTINGS_* to
persist and that those settings are delivered to the NetworkService
CookieManager properly. This change focuses on the proper plumbing and
conditional callback when access is requested from a renderer's
Document.

New mojo methods have been added to the CookieManager and FrameHost
interfaces to facilitate updating storage grants and request storage
access respectively. As the renderer process may not be trustworthy the
FrameHost method is guarded by a feature control check to ensure the
feature is actually enabled before allowing the call to proceed.

Browser and unit tests have been added to validate newly added surface
area and a WPT test case has been added to validate the end to end
scenario. In order to facilitate the non-blink feature flag
configuration required to run the new test case a virtual test suite
`virtual/storage-access-api` has been added to pass the
--enable-features=StorageAccessAPI flag to the test binaries.

Bug: 989663
Change-Id: Icaf964097f765ae94d4973633a05beb9bdc8c962
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1833481
Commit-Queue: Brandon Maslen <brandm@microsoft.com>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Balazs Engedy <engedy@chromium.org>
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Mike West <mkwst@chromium.org>
Reviewed-by: Theresa  <twellington@chromium.org>
Reviewed-by: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: Ilya Sherman <isherman@chromium.org>
Reviewed-by: Maksim Orlovich <morlovich@chromium.org>
Reviewed-by: Tao Bai <michaelbai@chromium.org>
Reviewed-by: Bret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742422}

--

wpt-commits: 7a0c45dacd346df8cd6dc4e1a040ad8d68526cc7
wpt-pr: 19436
2020-02-21 10:45:05 +00:00

49 lines
1.5 KiB
JavaScript

'use strict';
function RunTestsInIFrame(sourceURL) {
let frame = document.createElement('iframe');
frame.src = sourceURL;
document.body.appendChild(frame);
fetch_tests_from_window(frame.contentWindow);
}
function RunTestsInNestedIFrame(sourceURL) {
let nestedFrame = document.createElement('iframe');
document.body.appendChild(nestedFrame);
let content = `
<script src="/resources/testharness.js"></script>
<script src="helpers.js"></script>
<body>
<script>
RunTestsInIFrame("${sourceURL}");
</sc` + `ript>
`;
nestedFrame.contentDocument.write(content);
nestedFrame.contentDocument.close();
fetch_tests_from_window(nestedFrame.contentWindow);
}
let g_clickID = 0;
function ClickButtonWithGesture(onClickMethod) {
// Append some formatting and information so non WebDriver instances can complete this test too.
let info = document.createElement('p');
info.innerText = "This test case requires user-interaction and TestDriver. If you're running it manually please click the 'Request Access' button below exactly once.";
document.body.appendChild(info);
let button = document.createElement('button');
button.innerText = "Request Access";
g_clickID += 1;
button.id = g_clickID;
button.style = "background-color:#FF0000;"
// Insert the button and use test driver to click the button with a gesture.
document.body.appendChild(button);
button.addEventListener('click', e => {
onClickMethod();
button.style = "background-color:#00FF00;"
}, {once: true});
return test_driver.click(button);
}