Commit f35e7fa3 authored by cfredric's avatar cfredric Committed by Commit Bot

Use a matcher in privacy_budget_browsertest.

This makes the expectations more declarative, and makes it easier to
express more complicated invariants.

Note that in the previous implementation,
kV8Screen_Height_AttributeGetter was listed twice among the expected
keys, but the test did not verify that the |metrics| map contained two
such keys (not that that is possible). |IsSupersetOf| is built on the
idea of a multiset, so it does support checking for repeated expected
elements.

Change-Id: Ia2d617ed826b023bd67f5352e7094fd1136a6e45
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2480964Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Commit-Queue: Chris Fredrickson <cfredric@google.com>
Cr-Commit-Position: refs/heads/master@{#819125}
parent 26a13c6a
......@@ -13,6 +13,7 @@
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_study_settings.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_surface.h"
......@@ -26,6 +27,15 @@
namespace {
using testing::IsSupersetOf;
using testing::Key;
uint64_t HashFeature(const blink::mojom::WebFeature& feature) {
return blink::IdentifiableSurface::FromTypeAndToken(
blink::IdentifiableSurface::Type::kWebFeature, feature)
.ToUkmMetricHash();
}
// This test runs on Android as well as desktop platforms.
class PrivacyBudgetBrowserTest : public PlatformBrowserTest {
public:
......@@ -91,22 +101,23 @@ IN_PROC_BROWSER_TEST_F(PrivacyBudgetBrowserTest, SamplingScreenAPIs) {
// Shouldn't be more than one source here. If this changes, then we'd need to
// adjust this test to deal.
ASSERT_EQ(1u, merged_entries.size());
const auto& metrics = merged_entries.begin()->second->metrics;
// All of the following features should be included in the list of returned
// metrics here. The exact values depend on the test host.
for (auto feature :
{blink::mojom::WebFeature::kV8Screen_Height_AttributeGetter,
blink::mojom::WebFeature::kV8Screen_Width_AttributeGetter,
blink::mojom::WebFeature::kV8Screen_AvailLeft_AttributeGetter,
blink::mojom::WebFeature::kV8Screen_AvailTop_AttributeGetter,
blink::mojom::WebFeature::kV8Screen_AvailWidth_AttributeGetter,
blink::mojom::WebFeature::kV8Screen_Height_AttributeGetter}) {
EXPECT_TRUE(metrics.contains(
blink::IdentifiableSurface::FromTypeAndToken(
blink::IdentifiableSurface::Type::kWebFeature, feature)
.ToUkmMetricHash()));
}
EXPECT_THAT(
merged_entries.begin()->second->metrics,
IsSupersetOf({
Key(HashFeature(
blink::mojom::WebFeature::kV8Screen_Height_AttributeGetter)),
Key(HashFeature(
blink::mojom::WebFeature::kV8Screen_Width_AttributeGetter)),
Key(HashFeature(
blink::mojom::WebFeature::kV8Screen_AvailLeft_AttributeGetter)),
Key(HashFeature(
blink::mojom::WebFeature::kV8Screen_AvailTop_AttributeGetter)),
Key(HashFeature(
blink::mojom::WebFeature::kV8Screen_AvailWidth_AttributeGetter)),
}));
}
#if BUILDFLAG(FIELDTRIAL_TESTING_ENABLED)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment