[shared storage] Consolidate FLEDGE's shared storage modifier methods
What: - Consolidate the existing modifier methods into a single `SharedStorageUpdate(SharedStorageModifierMethod)` method. - No behavior change. Why: - Enable Batch Updates: This prepares for the upcoming support for the JavaScript API, batchUpdate(sequence<SharedStorageModifierMethod>), allowing websites to perform multiple modifications in a single operation. Explainer: https://github.com/WICG/shared-storage/pull/199 - Improved Maintainability: This simplifies the Mojo interface and reduces future maintenance overhead. Bug: 373899210 Change-Id: I26ad3d9048709dfcda2614d573dcea6d60a971aa Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5953467 Reviewed-by: Dominic Farolino <dom@chromium.org> Reviewed-by: Russ Hamilton <behamilton@google.com> Commit-Queue: Yao Xiao <yaoxia@chromium.org> Cr-Commit-Position: refs/heads/main@{#1373433}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
b618d46a5e
commit
4cf6811ced
content
browser
services
@ -55,56 +55,42 @@ void AuctionSharedStorageHost::BindNewReceiver(
|
||||
.worklet_origin = worklet_origin});
|
||||
}
|
||||
|
||||
void AuctionSharedStorageHost::Set(
|
||||
const std::u16string& key,
|
||||
const std::u16string& value,
|
||||
bool ignore_if_present,
|
||||
void AuctionSharedStorageHost::SharedStorageUpdate(
|
||||
blink::mojom::SharedStorageModifierMethodPtr method,
|
||||
auction_worklet::mojom::AuctionWorkletFunction
|
||||
source_auction_worklet_function) {
|
||||
storage::SharedStorageManager::SetBehavior set_behavior =
|
||||
ignore_if_present
|
||||
? storage::SharedStorageManager::SetBehavior::kIgnoreIfPresent
|
||||
: storage::SharedStorageManager::SetBehavior::kDefault;
|
||||
if (method->is_set_method()) {
|
||||
blink::mojom::SharedStorageSetMethodPtr& set_method =
|
||||
method->get_set_method();
|
||||
|
||||
shared_storage_manager_->Set(receiver_set_.current_context().worklet_origin,
|
||||
key, value, base::DoNothing(), set_behavior);
|
||||
storage::SharedStorageManager::SetBehavior set_behavior =
|
||||
set_method->ignore_if_present
|
||||
? storage::SharedStorageManager::SetBehavior::kIgnoreIfPresent
|
||||
: storage::SharedStorageManager::SetBehavior::kDefault;
|
||||
|
||||
GetContentClient()->browser()->LogWebFeatureForCurrentPage(
|
||||
receiver_set_.current_context().auction_runner_rfh,
|
||||
ToWebFeature(source_auction_worklet_function));
|
||||
}
|
||||
shared_storage_manager_->Set(receiver_set_.current_context().worklet_origin,
|
||||
set_method->key, set_method->value,
|
||||
base::DoNothing(), set_behavior);
|
||||
} else if (method->is_append_method()) {
|
||||
blink::mojom::SharedStorageAppendMethodPtr& append_method =
|
||||
method->get_append_method();
|
||||
|
||||
void AuctionSharedStorageHost::Append(
|
||||
const std::u16string& key,
|
||||
const std::u16string& value,
|
||||
auction_worklet::mojom::AuctionWorkletFunction
|
||||
source_auction_worklet_function) {
|
||||
shared_storage_manager_->Append(
|
||||
receiver_set_.current_context().worklet_origin, key, value,
|
||||
base::DoNothing());
|
||||
shared_storage_manager_->Append(
|
||||
receiver_set_.current_context().worklet_origin, append_method->key,
|
||||
append_method->value, base::DoNothing());
|
||||
} else if (method->is_delete_method()) {
|
||||
blink::mojom::SharedStorageDeleteMethodPtr& delete_method =
|
||||
method->get_delete_method();
|
||||
|
||||
GetContentClient()->browser()->LogWebFeatureForCurrentPage(
|
||||
receiver_set_.current_context().auction_runner_rfh,
|
||||
ToWebFeature(source_auction_worklet_function));
|
||||
}
|
||||
shared_storage_manager_->Delete(
|
||||
receiver_set_.current_context().worklet_origin, delete_method->key,
|
||||
base::DoNothing());
|
||||
} else {
|
||||
CHECK(method->is_clear_method());
|
||||
|
||||
void AuctionSharedStorageHost::Delete(
|
||||
const std::u16string& key,
|
||||
auction_worklet::mojom::AuctionWorkletFunction
|
||||
source_auction_worklet_function) {
|
||||
shared_storage_manager_->Delete(
|
||||
receiver_set_.current_context().worklet_origin, key, base::DoNothing());
|
||||
|
||||
GetContentClient()->browser()->LogWebFeatureForCurrentPage(
|
||||
receiver_set_.current_context().auction_runner_rfh,
|
||||
ToWebFeature(source_auction_worklet_function));
|
||||
}
|
||||
|
||||
void AuctionSharedStorageHost::Clear(
|
||||
auction_worklet::mojom::AuctionWorkletFunction
|
||||
source_auction_worklet_function) {
|
||||
shared_storage_manager_->Clear(receiver_set_.current_context().worklet_origin,
|
||||
base::DoNothing());
|
||||
shared_storage_manager_->Clear(
|
||||
receiver_set_.current_context().worklet_origin, base::DoNothing());
|
||||
}
|
||||
|
||||
GetContentClient()->browser()->LogWebFeatureForCurrentPage(
|
||||
receiver_set_.current_context().auction_runner_rfh,
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "content/services/auction_worklet/public/mojom/auction_shared_storage_host.mojom.h"
|
||||
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
||||
#include "mojo/public/cpp/bindings/receiver_set.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
namespace storage {
|
||||
class SharedStorageManager;
|
||||
@ -40,20 +41,9 @@ class CONTENT_EXPORT AuctionSharedStorageHost
|
||||
receiver);
|
||||
|
||||
// auction_worklet::mojom::AuctionSharedStorageHost:
|
||||
void Set(const std::u16string& key,
|
||||
const std::u16string& value,
|
||||
bool ignore_if_present,
|
||||
auction_worklet::mojom::AuctionWorkletFunction
|
||||
source_auction_worklet_function) override;
|
||||
void Append(const std::u16string& key,
|
||||
const std::u16string& value,
|
||||
auction_worklet::mojom::AuctionWorkletFunction
|
||||
source_auction_worklet_function) override;
|
||||
void Delete(const std::u16string& key,
|
||||
auction_worklet::mojom::AuctionWorkletFunction
|
||||
source_auction_worklet_function) override;
|
||||
void Clear(auction_worklet::mojom::AuctionWorkletFunction
|
||||
source_auction_worklet_function) override;
|
||||
void SharedStorageUpdate(blink::mojom::SharedStorageModifierMethodPtr method,
|
||||
auction_worklet::mojom::AuctionWorkletFunction
|
||||
source_auction_worklet_function) override;
|
||||
|
||||
private:
|
||||
struct ReceiverContext;
|
||||
|
@ -61,6 +61,7 @@
|
||||
#include "third_party/blink/public/common/interest_group/ad_display_size.h"
|
||||
#include "third_party/blink/public/common/interest_group/interest_group.h"
|
||||
#include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h"
|
||||
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom.h"
|
||||
#include "third_party/googletest/src/googlemock/include/gmock/gmock-more-matchers.h"
|
||||
#include "url/gurl.h"
|
||||
#include "url/origin.h"
|
||||
@ -10611,43 +10612,32 @@ TEST_F(BidderWorkletSharedStorageAPIEnabledTest,
|
||||
// dedicated pipe.
|
||||
task_environment_.RunUntilIdle();
|
||||
|
||||
using RequestType =
|
||||
auction_worklet::TestAuctionSharedStorageHost::RequestType;
|
||||
using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
|
||||
|
||||
EXPECT_THAT(
|
||||
test_shared_storage_host.observed_requests(),
|
||||
testing::ElementsAre(
|
||||
Request{.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid},
|
||||
Request{.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = true,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid},
|
||||
Request{.type = RequestType::kAppend,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid},
|
||||
Request{.type = RequestType::kDelete,
|
||||
.key = u"a",
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid},
|
||||
Request{.type = RequestType::kClear,
|
||||
.key = std::u16string(),
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/false)),
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/true)),
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
|
||||
blink::mojom::SharedStorageAppendMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b")),
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid),
|
||||
Request(
|
||||
blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
|
||||
blink::mojom::SharedStorageDeleteMethod::New(/*key=*/u"a")),
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewClearMethod(
|
||||
blink::mojom::SharedStorageClearMethod::New()),
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid)));
|
||||
}
|
||||
|
||||
{
|
||||
@ -10710,43 +10700,32 @@ TEST_F(BidderWorkletSharedStorageAPIEnabledTest,
|
||||
// dedicated pipe.
|
||||
task_environment_.RunUntilIdle();
|
||||
|
||||
using RequestType =
|
||||
auction_worklet::TestAuctionSharedStorageHost::RequestType;
|
||||
using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
|
||||
|
||||
EXPECT_THAT(
|
||||
test_shared_storage_host.observed_requests(),
|
||||
testing::ElementsAre(
|
||||
Request{.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderReportWin},
|
||||
Request{.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = true,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderReportWin},
|
||||
Request{.type = RequestType::kAppend,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderReportWin},
|
||||
Request{.type = RequestType::kDelete,
|
||||
.key = u"a",
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderReportWin},
|
||||
Request{.type = RequestType::kClear,
|
||||
.key = std::u16string(),
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderReportWin}));
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/false)),
|
||||
mojom::AuctionWorkletFunction::kBidderReportWin),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/true)),
|
||||
mojom::AuctionWorkletFunction::kBidderReportWin),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
|
||||
blink::mojom::SharedStorageAppendMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b")),
|
||||
mojom::AuctionWorkletFunction::kBidderReportWin),
|
||||
Request(
|
||||
blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
|
||||
blink::mojom::SharedStorageDeleteMethod::New(/*key=*/u"a")),
|
||||
mojom::AuctionWorkletFunction::kBidderReportWin),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewClearMethod(
|
||||
blink::mojom::SharedStorageClearMethod::New()),
|
||||
mojom::AuctionWorkletFunction::kBidderReportWin)));
|
||||
}
|
||||
|
||||
{
|
||||
@ -10851,18 +10830,16 @@ TEST_F(BidderWorkletTwoThreadsSharedStorageAPIEnabledTest,
|
||||
// handling the GenerateBid has observed the requests.
|
||||
EXPECT_TRUE(test_shared_storage_host1.observed_requests().empty());
|
||||
|
||||
using RequestType =
|
||||
auction_worklet::TestAuctionSharedStorageHost::RequestType;
|
||||
using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
|
||||
|
||||
EXPECT_THAT(test_shared_storage_host0.observed_requests(),
|
||||
testing::ElementsAre(Request{
|
||||
.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
|
||||
testing::ElementsAre(Request(
|
||||
blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/false)),
|
||||
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid)));
|
||||
}
|
||||
|
||||
class BidderWorkletPrivateAggregationEnabledTest : public BidderWorkletTest {
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "third_party/blink/public/common/interest_group/interest_group.h"
|
||||
#include "third_party/blink/public/mojom/aggregation_service/aggregatable_report.mojom.h"
|
||||
#include "third_party/blink/public/mojom/private_aggregation/private_aggregation_host.mojom-forward.h"
|
||||
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom.h"
|
||||
#include "v8/include/v8-context.h"
|
||||
#include "v8/include/v8-primitive.h"
|
||||
|
||||
@ -2134,8 +2135,6 @@ TEST_F(ContextRecyclerTest,
|
||||
}
|
||||
|
||||
TEST_F(ContextRecyclerTest, SharedStorageMethods) {
|
||||
using RequestType =
|
||||
auction_worklet::TestAuctionSharedStorageHost::RequestType;
|
||||
using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
|
||||
|
||||
const std::string kInvalidValue(
|
||||
@ -2192,13 +2191,12 @@ TEST_F(ContextRecyclerTest, SharedStorageMethods) {
|
||||
EXPECT_THAT(error_msgs, ElementsAre());
|
||||
|
||||
EXPECT_THAT(test_shared_storage_host.observed_requests(),
|
||||
ElementsAre(Request{
|
||||
.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
|
||||
ElementsAre(Request(
|
||||
blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/false)),
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid)));
|
||||
|
||||
test_shared_storage_host.ClearObservedRequests();
|
||||
}
|
||||
@ -2221,13 +2219,12 @@ TEST_F(ContextRecyclerTest, SharedStorageMethods) {
|
||||
EXPECT_THAT(error_msgs, ElementsAre());
|
||||
|
||||
EXPECT_THAT(test_shared_storage_host.observed_requests(),
|
||||
ElementsAre(Request{
|
||||
.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = true,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
|
||||
ElementsAre(Request(
|
||||
blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/true)),
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid)));
|
||||
|
||||
test_shared_storage_host.ClearObservedRequests();
|
||||
}
|
||||
@ -2245,13 +2242,11 @@ TEST_F(ContextRecyclerTest, SharedStorageMethods) {
|
||||
EXPECT_THAT(error_msgs, ElementsAre());
|
||||
|
||||
EXPECT_THAT(test_shared_storage_host.observed_requests(),
|
||||
ElementsAre(Request{
|
||||
.type = RequestType::kAppend,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
|
||||
ElementsAre(Request(
|
||||
blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
|
||||
blink::mojom::SharedStorageAppendMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b")),
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid)));
|
||||
|
||||
test_shared_storage_host.ClearObservedRequests();
|
||||
}
|
||||
@ -2268,13 +2263,11 @@ TEST_F(ContextRecyclerTest, SharedStorageMethods) {
|
||||
EXPECT_THAT(error_msgs, ElementsAre());
|
||||
|
||||
EXPECT_THAT(test_shared_storage_host.observed_requests(),
|
||||
ElementsAre(Request{
|
||||
.type = RequestType::kDelete,
|
||||
.key = u"a",
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
|
||||
ElementsAre(Request(
|
||||
blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
|
||||
blink::mojom::SharedStorageDeleteMethod::New(
|
||||
/*key=*/u"a")),
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid)));
|
||||
|
||||
test_shared_storage_host.ClearObservedRequests();
|
||||
}
|
||||
@ -2291,13 +2284,10 @@ TEST_F(ContextRecyclerTest, SharedStorageMethods) {
|
||||
EXPECT_THAT(error_msgs, ElementsAre());
|
||||
|
||||
EXPECT_THAT(test_shared_storage_host.observed_requests(),
|
||||
ElementsAre(Request{
|
||||
.type = RequestType::kClear,
|
||||
.key = std::u16string(),
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
|
||||
ElementsAre(Request(
|
||||
blink::mojom::SharedStorageModifierMethod::NewClearMethod(
|
||||
blink::mojom::SharedStorageClearMethod::New()),
|
||||
mojom::AuctionWorkletFunction::kBidderGenerateBid)));
|
||||
|
||||
test_shared_storage_host.ClearObservedRequests();
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/test/bind.h"
|
||||
#include "base/test/task_environment.h"
|
||||
#include "content/services/auction_worklet/worklet_test_util.h"
|
||||
|
@ -18,24 +18,7 @@ enum AuctionWorkletFunction {
|
||||
// storage API (i.e. the setter methods). We intentionally do not return the
|
||||
// result of these calls to avoid leaking state to the worklet.
|
||||
interface AuctionSharedStorageHost {
|
||||
// Handle sharedStorage.set(): set `key`’s entry to `value`. If
|
||||
// `ignore_if_present` is true, the entry is not updated if `key` already
|
||||
// exists.
|
||||
Set(blink.mojom.SharedStorageKeyArgument key,
|
||||
blink.mojom.SharedStorageValueArgument value,
|
||||
bool ignore_if_present,
|
||||
AuctionWorkletFunction source_auction_worklet_function);
|
||||
|
||||
// Handle sharedStorage.append(): append `value` to the entry for `key`.
|
||||
// Equivalent to "set" if the `key` is not present.
|
||||
Append(blink.mojom.SharedStorageKeyArgument key,
|
||||
blink.mojom.SharedStorageValueArgument value,
|
||||
AuctionWorkletFunction source_auction_worklet_function);
|
||||
|
||||
// Handle sharedStorage.delete(): delete the entry at the given `key`.
|
||||
Delete(blink.mojom.SharedStorageKeyArgument key,
|
||||
AuctionWorkletFunction source_auction_worklet_function);
|
||||
|
||||
// Handle sharedStorage.clear(): delete all entries.
|
||||
Clear(AuctionWorkletFunction source_auction_worklet_function);
|
||||
// Handle the modifier method `method`.
|
||||
SharedStorageUpdate(blink.mojom.SharedStorageModifierMethod method,
|
||||
AuctionWorkletFunction source_auction_worklet_function);
|
||||
};
|
||||
|
@ -57,6 +57,7 @@
|
||||
#include "third_party/blink/public/common/interest_group/ad_display_size.h"
|
||||
#include "third_party/blink/public/common/interest_group/auction_config.h"
|
||||
#include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h"
|
||||
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom.h"
|
||||
#include "url/gurl.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
@ -5976,43 +5977,32 @@ TEST_F(SellerWorkletSharedStorageAPIEnabledTest, SharedStorageWriteInScoreAd) {
|
||||
// dedicated pipe.
|
||||
task_environment_.RunUntilIdle();
|
||||
|
||||
using RequestType =
|
||||
auction_worklet::TestAuctionSharedStorageHost::RequestType;
|
||||
using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
|
||||
|
||||
EXPECT_THAT(
|
||||
test_shared_storage_host.observed_requests(),
|
||||
testing::ElementsAre(
|
||||
Request{.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd},
|
||||
Request{.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = true,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd},
|
||||
Request{.type = RequestType::kAppend,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd},
|
||||
Request{.type = RequestType::kDelete,
|
||||
.key = u"a",
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd},
|
||||
Request{.type = RequestType::kClear,
|
||||
.key = std::u16string(),
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd}));
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/false)),
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/true)),
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
|
||||
blink::mojom::SharedStorageAppendMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b")),
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd),
|
||||
Request(
|
||||
blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
|
||||
blink::mojom::SharedStorageDeleteMethod::New(/*key=*/u"a")),
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewClearMethod(
|
||||
blink::mojom::SharedStorageClearMethod::New()),
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd)));
|
||||
}
|
||||
|
||||
{
|
||||
@ -6073,43 +6063,32 @@ TEST_F(SellerWorkletSharedStorageAPIEnabledTest,
|
||||
// dedicated pipe.
|
||||
task_environment_.RunUntilIdle();
|
||||
|
||||
using RequestType =
|
||||
auction_worklet::TestAuctionSharedStorageHost::RequestType;
|
||||
using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
|
||||
|
||||
EXPECT_THAT(
|
||||
test_shared_storage_host.observed_requests(),
|
||||
testing::ElementsAre(
|
||||
Request{.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kSellerReportResult},
|
||||
Request{.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = true,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kSellerReportResult},
|
||||
Request{.type = RequestType::kAppend,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kSellerReportResult},
|
||||
Request{.type = RequestType::kDelete,
|
||||
.key = u"a",
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kSellerReportResult},
|
||||
Request{.type = RequestType::kClear,
|
||||
.key = std::u16string(),
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kSellerReportResult}));
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/false)),
|
||||
mojom::AuctionWorkletFunction::kSellerReportResult),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/true)),
|
||||
mojom::AuctionWorkletFunction::kSellerReportResult),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
|
||||
blink::mojom::SharedStorageAppendMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b")),
|
||||
mojom::AuctionWorkletFunction::kSellerReportResult),
|
||||
Request(
|
||||
blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
|
||||
blink::mojom::SharedStorageDeleteMethod::New(/*key=*/u"a")),
|
||||
mojom::AuctionWorkletFunction::kSellerReportResult),
|
||||
Request(blink::mojom::SharedStorageModifierMethod::NewClearMethod(
|
||||
blink::mojom::SharedStorageClearMethod::New()),
|
||||
mojom::AuctionWorkletFunction::kSellerReportResult)));
|
||||
}
|
||||
|
||||
{
|
||||
@ -6343,18 +6322,15 @@ TEST_F(SellerWorkletTwoThreadsSharedStorageAPIEnabledTest,
|
||||
// handling the ScoreAd has observed the requests.
|
||||
EXPECT_TRUE(test_shared_storage_host1.observed_requests().empty());
|
||||
|
||||
using RequestType =
|
||||
auction_worklet::TestAuctionSharedStorageHost::RequestType;
|
||||
using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
|
||||
|
||||
EXPECT_THAT(test_shared_storage_host0.observed_requests(),
|
||||
testing::ElementsAre(
|
||||
Request{.type = RequestType::kSet,
|
||||
.key = u"a",
|
||||
.value = u"b",
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function =
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd}));
|
||||
testing::ElementsAre(Request(
|
||||
blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
/*key=*/u"a", /*value=*/u"b",
|
||||
/*ignore_if_present=*/false)),
|
||||
mojom::AuctionWorkletFunction::kSellerScoreAd)));
|
||||
}
|
||||
|
||||
class SellerWorkletRealTimeTest : public SellerWorkletTest {
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "content/services/auction_worklet/webidl_compat.h"
|
||||
#include "gin/converter.h"
|
||||
#include "third_party/blink/public/common/shared_storage/shared_storage_utils.h"
|
||||
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom.h"
|
||||
#include "v8/include/v8-exception.h"
|
||||
#include "v8/include/v8-external.h"
|
||||
#include "v8/include/v8-function-callback.h"
|
||||
@ -142,9 +143,12 @@ void SharedStorageBindings::Set(
|
||||
return;
|
||||
}
|
||||
|
||||
bindings->shared_storage_host_->Set(
|
||||
arg0_key, arg1_value, ignore_if_present.value_or(false),
|
||||
bindings->source_auction_worklet_function_);
|
||||
auto method = blink::mojom::SharedStorageModifierMethod::NewSetMethod(
|
||||
blink::mojom::SharedStorageSetMethod::New(
|
||||
arg0_key, arg1_value, ignore_if_present.value_or(false)));
|
||||
|
||||
bindings->shared_storage_host_->SharedStorageUpdate(
|
||||
std::move(method), bindings->source_auction_worklet_function_);
|
||||
}
|
||||
|
||||
// static
|
||||
@ -187,8 +191,11 @@ void SharedStorageBindings::Append(
|
||||
return;
|
||||
}
|
||||
|
||||
bindings->shared_storage_host_->Append(
|
||||
arg0_key, arg1_value, bindings->source_auction_worklet_function_);
|
||||
auto method = blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
|
||||
blink::mojom::SharedStorageAppendMethod::New(arg0_key, arg1_value));
|
||||
|
||||
bindings->shared_storage_host_->SharedStorageUpdate(
|
||||
std::move(method), bindings->source_auction_worklet_function_);
|
||||
}
|
||||
|
||||
// static
|
||||
@ -223,8 +230,11 @@ void SharedStorageBindings::Delete(
|
||||
return;
|
||||
}
|
||||
|
||||
bindings->shared_storage_host_->Delete(
|
||||
arg0_key, bindings->source_auction_worklet_function_);
|
||||
auto method = blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
|
||||
blink::mojom::SharedStorageDeleteMethod::New(arg0_key));
|
||||
|
||||
bindings->shared_storage_host_->SharedStorageUpdate(
|
||||
std::move(method), bindings->source_auction_worklet_function_);
|
||||
}
|
||||
|
||||
// static
|
||||
@ -241,7 +251,10 @@ void SharedStorageBindings::Clear(
|
||||
return;
|
||||
}
|
||||
|
||||
bindings->shared_storage_host_->Clear(
|
||||
bindings->source_auction_worklet_function_);
|
||||
auto method = blink::mojom::SharedStorageModifierMethod::NewClearMethod(
|
||||
blink::mojom::SharedStorageClearMethod::New());
|
||||
|
||||
bindings->shared_storage_host_->SharedStorageUpdate(
|
||||
std::move(method), bindings->source_auction_worklet_function_);
|
||||
}
|
||||
} // namespace auction_worklet
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "services/network/public/cpp/url_loader_completion_status.h"
|
||||
#include "services/network/public/mojom/url_response_head.mojom.h"
|
||||
#include "services/network/test/test_url_loader_factory.h"
|
||||
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom.h"
|
||||
|
||||
namespace auction_worklet {
|
||||
|
||||
@ -137,10 +138,34 @@ base::WaitableEvent* WedgeV8Thread(AuctionV8Helper* v8_helper) {
|
||||
return event_handle;
|
||||
}
|
||||
|
||||
TestAuctionSharedStorageHost::Request::Request(
|
||||
blink::mojom::SharedStorageModifierMethodPtr method,
|
||||
mojom::AuctionWorkletFunction source_auction_worklet_function)
|
||||
: method(std::move(method)),
|
||||
source_auction_worklet_function(source_auction_worklet_function) {}
|
||||
|
||||
TestAuctionSharedStorageHost::Request::~Request() = default;
|
||||
|
||||
TestAuctionSharedStorageHost::Request::Request(const Request& other)
|
||||
: method(other.method->Clone()),
|
||||
source_auction_worklet_function(other.source_auction_worklet_function) {}
|
||||
|
||||
TestAuctionSharedStorageHost::Request&
|
||||
TestAuctionSharedStorageHost::Request::operator=(const Request& other) {
|
||||
if (this != &other) {
|
||||
method = other.method->Clone();
|
||||
source_auction_worklet_function = other.source_auction_worklet_function;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
TestAuctionSharedStorageHost::Request::Request(Request&& other) = default;
|
||||
TestAuctionSharedStorageHost::Request&
|
||||
TestAuctionSharedStorageHost::Request::operator=(Request&& other) = default;
|
||||
|
||||
bool TestAuctionSharedStorageHost::Request::operator==(
|
||||
const Request& rhs) const {
|
||||
return type == rhs.type && key == rhs.key && value == rhs.value &&
|
||||
ignore_if_present == rhs.ignore_if_present &&
|
||||
return method == rhs.method &&
|
||||
source_auction_worklet_function == rhs.source_auction_worklet_function;
|
||||
}
|
||||
|
||||
@ -148,50 +173,12 @@ TestAuctionSharedStorageHost::TestAuctionSharedStorageHost() = default;
|
||||
|
||||
TestAuctionSharedStorageHost::~TestAuctionSharedStorageHost() = default;
|
||||
|
||||
void TestAuctionSharedStorageHost::Set(
|
||||
const std::u16string& key,
|
||||
const std::u16string& value,
|
||||
bool ignore_if_present,
|
||||
mojom::AuctionWorkletFunction source_auction_worklet_function) {
|
||||
observed_requests_.emplace_back(Request{
|
||||
.type = RequestType::kSet,
|
||||
.key = key,
|
||||
.value = value,
|
||||
.ignore_if_present = ignore_if_present,
|
||||
.source_auction_worklet_function = source_auction_worklet_function});
|
||||
}
|
||||
|
||||
void TestAuctionSharedStorageHost::Append(
|
||||
const std::u16string& key,
|
||||
const std::u16string& value,
|
||||
mojom::AuctionWorkletFunction source_auction_worklet_function) {
|
||||
observed_requests_.emplace_back(Request{
|
||||
.type = RequestType::kAppend,
|
||||
.key = key,
|
||||
.value = value,
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function = source_auction_worklet_function});
|
||||
}
|
||||
|
||||
void TestAuctionSharedStorageHost::Delete(
|
||||
const std::u16string& key,
|
||||
mojom::AuctionWorkletFunction source_auction_worklet_function) {
|
||||
observed_requests_.emplace_back(Request{
|
||||
.type = RequestType::kDelete,
|
||||
.key = key,
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function = source_auction_worklet_function});
|
||||
}
|
||||
|
||||
void TestAuctionSharedStorageHost::Clear(
|
||||
mojom::AuctionWorkletFunction source_auction_worklet_function) {
|
||||
observed_requests_.emplace_back(Request{
|
||||
.type = RequestType::kClear,
|
||||
.key = std::u16string(),
|
||||
.value = std::u16string(),
|
||||
.ignore_if_present = false,
|
||||
.source_auction_worklet_function = source_auction_worklet_function});
|
||||
void TestAuctionSharedStorageHost::SharedStorageUpdate(
|
||||
blink::mojom::SharedStorageModifierMethodPtr method,
|
||||
auction_worklet::mojom::AuctionWorkletFunction
|
||||
source_auction_worklet_function) {
|
||||
observed_requests_.emplace_back(
|
||||
Request(std::move(method), source_auction_worklet_function));
|
||||
}
|
||||
|
||||
void TestAuctionSharedStorageHost::ClearObservedRequests() {
|
||||
|
@ -80,18 +80,17 @@ base::WaitableEvent* WedgeV8Thread(AuctionV8Helper* v8_helper);
|
||||
// Receives shared storage mojom messages.
|
||||
class TestAuctionSharedStorageHost : public mojom::AuctionSharedStorageHost {
|
||||
public:
|
||||
enum RequestType {
|
||||
kSet,
|
||||
kAppend,
|
||||
kDelete,
|
||||
kClear,
|
||||
};
|
||||
|
||||
struct Request {
|
||||
RequestType type;
|
||||
std::u16string key;
|
||||
std::u16string value;
|
||||
bool ignore_if_present;
|
||||
Request(blink::mojom::SharedStorageModifierMethodPtr method,
|
||||
mojom::AuctionWorkletFunction source_auction_worklet_function);
|
||||
~Request();
|
||||
|
||||
Request(const Request& other);
|
||||
Request& operator=(const Request& other);
|
||||
Request(Request&& other);
|
||||
Request& operator=(Request&& other);
|
||||
|
||||
blink::mojom::SharedStorageModifierMethodPtr method;
|
||||
mojom::AuctionWorkletFunction source_auction_worklet_function;
|
||||
|
||||
bool operator==(const Request& rhs) const;
|
||||
@ -102,23 +101,9 @@ class TestAuctionSharedStorageHost : public mojom::AuctionSharedStorageHost {
|
||||
~TestAuctionSharedStorageHost() override;
|
||||
|
||||
// mojom::AuctionSharedStorageHost:
|
||||
void Set(
|
||||
const std::u16string& key,
|
||||
const std::u16string& value,
|
||||
bool ignore_if_present,
|
||||
mojom::AuctionWorkletFunction source_auction_worklet_function) override;
|
||||
|
||||
void Append(
|
||||
const std::u16string& key,
|
||||
const std::u16string& value,
|
||||
mojom::AuctionWorkletFunction source_auction_worklet_function) override;
|
||||
|
||||
void Delete(
|
||||
const std::u16string& key,
|
||||
mojom::AuctionWorkletFunction source_auction_worklet_function) override;
|
||||
|
||||
void Clear(
|
||||
mojom::AuctionWorkletFunction source_auction_worklet_function) override;
|
||||
void SharedStorageUpdate(blink::mojom::SharedStorageModifierMethodPtr method,
|
||||
auction_worklet::mojom::AuctionWorkletFunction
|
||||
source_auction_worklet_function) override;
|
||||
|
||||
const std::vector<Request>& observed_requests() const {
|
||||
return observed_requests_;
|
||||
|
Reference in New Issue
Block a user