Commit 4b059f06 authored by Glen Robertson's avatar Glen Robertson Committed by Commit Bot

Fix badge_manager to not include test headers in prod code.

Fixes a `gn check` failure.
Split out from crrev.com/c/2383400

Bug: 898837
Change-Id: I5dcc0ff5d00bfa04c241a07fc62c63c502a1ad74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2384691
Auto-Submit: Glen Robertson <glenrob@chromium.org>
Reviewed-by: default avatarChris Mumford <cmumford@google.com>
Commit-Queue: Glen Robertson <glenrob@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803338}
parent db0ce6aa
......@@ -14,7 +14,6 @@
#include "base/optional.h"
#include "chrome/browser/web_applications/components/web_app_id.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "third_party/blink/public/mojom/badging/badging.mojom.h"
#include "url/gurl.h"
......@@ -26,6 +25,10 @@ class RenderFrameHost;
class RenderProcessHost;
} // namespace content
namespace ukm {
class UkmRecorder;
}
namespace badging {
class BadgeManagerDelegate;
......@@ -72,13 +75,11 @@ class BadgeManager : public KeyedService, public blink::mojom::BadgeService {
// badged.
base::Optional<BadgeValue> GetBadgeValue(const web_app::AppId& app_id);
void SetBadgeForTesting(
const web_app::AppId& app_id,
BadgeValue value,
ukm::UkmRecorder* test_recorder = ukm::TestUkmRecorder::Get());
void ClearBadgeForTesting(
const web_app::AppId& app_id,
ukm::UkmRecorder* test_recorder = ukm::TestUkmRecorder::Get());
void SetBadgeForTesting(const web_app::AppId& app_id,
BadgeValue value,
ukm::UkmRecorder* test_recorder);
void ClearBadgeForTesting(const web_app::AppId& app_id,
ukm::UkmRecorder* test_recorder);
private:
// The BindingContext of a mojo request. Allows mojo calls to be tied back
......
......@@ -106,10 +106,11 @@ TEST_F(BadgeManagerUnittest, SetBadgeForMultipleApps) {
const web_app::AppId kOtherAppId = "2";
constexpr uint64_t kOtherContents = 2;
badge_manager()->SetBadgeForTesting(kAppId,
base::make_optional(kBadgeContents));
badge_manager()->SetBadgeForTesting(
kAppId, base::make_optional(kBadgeContents), ukm::TestUkmRecorder::Get());
badge_manager()->SetBadgeForTesting(kOtherAppId,
base::make_optional(kOtherContents));
base::make_optional(kOtherContents),
ukm::TestUkmRecorder::Get());
EXPECT_EQ(2UL, delegate()->set_badges().size());
......@@ -121,11 +122,11 @@ TEST_F(BadgeManagerUnittest, SetBadgeForMultipleApps) {
}
TEST_F(BadgeManagerUnittest, SetBadgeForAppAfterClear) {
badge_manager()->SetBadgeForTesting(kAppId,
base::make_optional(kBadgeContents));
badge_manager()->ClearBadgeForTesting(kAppId);
badge_manager()->SetBadgeForTesting(kAppId,
base::make_optional(kBadgeContents));
badge_manager()->SetBadgeForTesting(
kAppId, base::make_optional(kBadgeContents), ukm::TestUkmRecorder::Get());
badge_manager()->ClearBadgeForTesting(kAppId, ukm::TestUkmRecorder::Get());
badge_manager()->SetBadgeForTesting(
kAppId, base::make_optional(kBadgeContents), ukm::TestUkmRecorder::Get());
EXPECT_EQ(2UL, delegate()->set_badges().size());
......@@ -139,8 +140,8 @@ TEST_F(BadgeManagerUnittest, SetBadgeForAppAfterClear) {
TEST_F(BadgeManagerUnittest, ClearBadgeForBadgedApp) {
ukm::TestUkmRecorder test_recorder;
badge_manager()->SetBadgeForTesting(kAppId,
base::make_optional(kBadgeContents));
badge_manager()->SetBadgeForTesting(
kAppId, base::make_optional(kBadgeContents), ukm::TestUkmRecorder::Get());
badge_manager()->ClearBadgeForTesting(kAppId, &test_recorder);
auto entries =
test_recorder.GetEntriesByName(ukm::builders::Badging::kEntryName);
......@@ -161,13 +162,16 @@ TEST_F(BadgeManagerUnittest, BadgingMultipleProfiles) {
auto* other_delegate = owned_other_delegate.get();
other_badge_manager->SetDelegate(std::move(owned_other_delegate));
other_badge_manager->SetBadgeForTesting(kAppId, base::nullopt);
other_badge_manager->SetBadgeForTesting(kAppId,
base::make_optional(kBadgeContents));
other_badge_manager->SetBadgeForTesting(kAppId, base::nullopt);
other_badge_manager->ClearBadgeForTesting(kAppId);
other_badge_manager->SetBadgeForTesting(kAppId, base::nullopt,
ukm::TestUkmRecorder::Get());
other_badge_manager->SetBadgeForTesting(
kAppId, base::make_optional(kBadgeContents), ukm::TestUkmRecorder::Get());
other_badge_manager->SetBadgeForTesting(kAppId, base::nullopt,
ukm::TestUkmRecorder::Get());
other_badge_manager->ClearBadgeForTesting(kAppId,
ukm::TestUkmRecorder::Get());
badge_manager()->ClearBadgeForTesting(kAppId);
badge_manager()->ClearBadgeForTesting(kAppId, ukm::TestUkmRecorder::Get());
EXPECT_EQ(3UL, other_delegate->set_badges().size());
EXPECT_EQ(0UL, delegate()->set_badges().size());
......@@ -184,10 +188,11 @@ TEST_F(BadgeManagerUnittest, BadgingMultipleProfiles) {
TEST_F(BadgeManagerUnittest, BadgingWithNoDelegateDoesNotCrash) {
badge_manager()->SetDelegate(nullptr);
badge_manager()->SetBadgeForTesting(kAppId, base::nullopt);
badge_manager()->SetBadgeForTesting(kAppId,
base::make_optional(kBadgeContents));
badge_manager()->ClearBadgeForTesting(kAppId);
badge_manager()->SetBadgeForTesting(kAppId, base::nullopt,
ukm::TestUkmRecorder::Get());
badge_manager()->SetBadgeForTesting(
kAppId, base::make_optional(kBadgeContents), ukm::TestUkmRecorder::Get());
badge_manager()->ClearBadgeForTesting(kAppId, ukm::TestUkmRecorder::Get());
}
} // namespace badging
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