Skip to content

Commit

Permalink
Fenced frames: Update Shared Storage browser tests to test
Browse files Browse the repository at this point in the history
`selectURL()` that returns a FencedFrameConfig.

crrev.com/c/4111682 enables `selectURL()` to return a
FencedFrameConfig object by specifying the new boolean dictionary
member in SharedStorageRunOperationMethodOptions as true. This CL
updates the test cases in
1. shared_storage/shared_storage_browsertest.cc
2. storage/shared_storage_browsertest.cc
to test this new behavior.

A test-only observer is added to observe
1. the generated urn::uuid.
2. the populated FencedFrameConfig.

It's needed because we cannot obtained the urn::uuid from the returned
FencedFrameConfig object. It is designed to be opaque to the web platform. For example:

const fenced_frame_config = await sharedStorage.selectURL(...);
const urn = fenced_frame_config.urn; // Cannot do this

Bug: 1347953
Change-Id: Id580664ab029e4337041ca69911353c1b90c2929
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4127118
Reviewed-by: Dominic Farolino <dom@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Xiaochen Zhou <xiaochenzh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1106897}
  • Loading branch information
xiaochen-z authored and Chromium LUCI CQ committed Feb 17, 2023
1 parent a40ae84 commit 9c4ed28
Show file tree
Hide file tree
Showing 14 changed files with 2,104 additions and 655 deletions.
571 changes: 421 additions & 150 deletions chrome/browser/storage/shared_storage_browsertest.cc

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions content/browser/devtools/protocol/storage_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ class StorageHandler::SharedStorageObserver
owner_origin, params);
}

void OnUrnUuidGenerated(const GURL& urn_uuid) override {}

void OnConfigPopulated(
const absl::optional<FencedFrameConfig>& config) override {}

private:
raw_ptr<StorageHandler> const owner_;
base::ScopedObservation<
Expand Down
5 changes: 4 additions & 1 deletion content/browser/fenced_frame/fenced_frame_url_mapping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ void FencedFrameURLMapping::RemoveObserverForURN(
it->second.erase(observer_it);
}

void FencedFrameURLMapping::OnSharedStorageURNMappingResultDetermined(
absl::optional<FencedFrameConfig>
FencedFrameURLMapping::OnSharedStorageURNMappingResultDetermined(
const GURL& urn_uuid,
const SharedStorageURNMappingResult& mapping_result) {
auto pending_it = pending_urn_uuid_to_url_map_.find(urn_uuid);
Expand Down Expand Up @@ -254,6 +255,8 @@ void FencedFrameURLMapping::OnSharedStorageURNMappingResultDetermined(
}

pending_urn_uuid_to_url_map_.erase(pending_it);

return config;
}

SharedStorageBudgetMetadata*
Expand Down
10 changes: 9 additions & 1 deletion content/browser/fenced_frame/fenced_frame_url_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ using SharedStorageReportingMap = base::flat_map<std::string, ::GURL>;
// Keeps a mapping of fenced frames URN:UUID and URL. Also keeps a set of
// pending mapped URN:UUIDs to support asynchronous mapping. See
// https://github.com/WICG/fenced-frame/blob/master/explainer/opaque_src.md
// TODO(crbug.com/1405477): Add methods for:
// 1. generating the pending config.
// 2. finalizing the pending config.
class CONTENT_EXPORT FencedFrameURLMapping {
public:
// The runURLSelectionOperation's url mapping result. It contains the mapped
Expand Down Expand Up @@ -126,7 +129,12 @@ class CONTENT_EXPORT FencedFrameURLMapping {
// will trigger the observers' OnFencedFrameURLMappingComplete() method
// associated with the `urn_uuid`, unregister those observers, and move the
// `urn_uuid` from `pending_urn_uuid_to_url_map_` to `urn_uuid_to_url_map_`.
void OnSharedStorageURNMappingResultDetermined(
// If the resolved URL is fenced-frame-compatible, the return value is the
// populated fenced frame config. It is used to notify the observers in shared
// storage worklet host manager. Tests can then obtain the populated fenced
// frame configs from the observers.
// Otherwise this method returns an absl::nullopt.
absl::optional<FencedFrameConfig> OnSharedStorageURNMappingResultDetermined(
const GURL& urn_uuid,
const SharedStorageURNMappingResult& mapping_result);

Expand Down

0 comments on commit 9c4ed28

Please sign in to comment.