[Merchant Trust]: Let validation logic handle kNoResult status
We were preemptively returning when no data was fetched from the optimization service. We're now letting the validation logic take care of it; in this way the histogram is logged correctly and the total count represents the number of optimization requests. Bug: 400379039 Change-Id: I84015bd29edadeaeab3fe016097ca462b1351ccf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6317305 Reviewed-by: Olesia Marukhno <olesiamarukhno@google.com> Auto-Submit: Nicola Tommasi <tommasin@chromium.org> Commit-Queue: Nicola Tommasi <tommasin@chromium.org> Commit-Queue: Olesia Marukhno <olesiamarukhno@google.com> Cr-Commit-Position: refs/heads/main@{#1427065}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
f4ef014be0
commit
b51cc938a0
components/page_info/core
@@ -142,11 +142,9 @@ void MerchantTrustService::OnCanApplyOptimizationComplete(
|
|||||||
if (decision != optimization_guide::OptimizationGuideDecision::kUnknown) {
|
if (decision != optimization_guide::OptimizationGuideDecision::kUnknown) {
|
||||||
std::optional<commerce::MerchantTrustSignalsV2> merchant_trust_metadata =
|
std::optional<commerce::MerchantTrustSignalsV2> merchant_trust_metadata =
|
||||||
metadata.ParsedMetadata<commerce::MerchantTrustSignalsV2>();
|
metadata.ParsedMetadata<commerce::MerchantTrustSignalsV2>();
|
||||||
if (merchant_trust_metadata.has_value()) {
|
std::move(callback).Run(url,
|
||||||
std::move(callback).Run(
|
GetMerchantDataFromProto(merchant_trust_metadata));
|
||||||
url, GetMerchantDataFromProto(merchant_trust_metadata));
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kMerchantTrustEnabledWithSampleData.Get()) {
|
if (kMerchantTrustEnabledWithSampleData.Get()) {
|
||||||
|
@@ -229,6 +229,29 @@ TEST_F(MerchantTrustServiceTest, SampleData) {
|
|||||||
run_loop.Run();
|
run_loop.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests that if the proto is empty, no data is returned.
|
||||||
|
TEST_F(MerchantTrustServiceTest, NoResult) {
|
||||||
|
base::HistogramTester t;
|
||||||
|
OptimizationMetadata metadata;
|
||||||
|
metadata.set_any_metadata({});
|
||||||
|
SetResponse(GURL("https://foo.com"), OptimizationGuideDecision::kTrue,
|
||||||
|
metadata);
|
||||||
|
|
||||||
|
base::RunLoop run_loop;
|
||||||
|
service()->GetMerchantTrustInfo(
|
||||||
|
GURL("https://foo.com"),
|
||||||
|
base::BindOnce(
|
||||||
|
[](base::RunLoop* run_loop, const GURL& url,
|
||||||
|
std::optional<page_info::MerchantData> info) {
|
||||||
|
ASSERT_FALSE(info.has_value());
|
||||||
|
run_loop->Quit();
|
||||||
|
},
|
||||||
|
&run_loop));
|
||||||
|
run_loop.Run();
|
||||||
|
t.ExpectUniqueSample("Security.PageInfo.MerchantTrustStatus",
|
||||||
|
MerchantTrustStatus::kNoResult, 1);
|
||||||
|
}
|
||||||
|
|
||||||
// Tests that status is recorded as not valid when a proto is missing a field
|
// Tests that status is recorded as not valid when a proto is missing a field
|
||||||
// and no data is returned.
|
// and no data is returned.
|
||||||
TEST_F(MerchantTrustServiceTest, InvalidProto) {
|
TEST_F(MerchantTrustServiceTest, InvalidProto) {
|
||||||
|
@@ -19,6 +19,10 @@ commerce::MerchantTrustSignalsV2 GetSampleProto() {
|
|||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(MerchantTrustValidation, NoResult) {
|
||||||
|
EXPECT_EQ(ValidateProto(std::nullopt), MerchantTrustStatus::kNoResult);
|
||||||
|
}
|
||||||
|
|
||||||
// Tests that correct proto messages are accepted.
|
// Tests that correct proto messages are accepted.
|
||||||
TEST(MerchantTrustValidation, ValidProto) {
|
TEST(MerchantTrustValidation, ValidProto) {
|
||||||
auto proto = GetSampleProto();
|
auto proto = GetSampleProto();
|
||||||
|
Reference in New Issue
Block a user