Skip to content

Commit

Permalink
[PriceTracking] Use a different dialog string if email is turned off
Browse files Browse the repository at this point in the history
If the email notification is turned off by the user, we show a
different body message in the bookmark star entry dialog to better
describe what will happen when the user initiates price tracking.

Bug: 1374118, 1369746
Change-Id: Ic82842980ba51f5105ee5b09c9a975e094d42865
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3953776
Reviewed-by: Mei Liang <meiliang@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Reviewed-by: Matthew Jones <mdjones@chromium.org>
Commit-Queue: Zhiyuan Cai <zhiyuancai@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1060063}
  • Loading branch information
Zhiyuan Cai authored and Chromium LUCI CQ committed Oct 17, 2022
1 parent 63f5b3a commit 764484f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
7 changes: 5 additions & 2 deletions chrome/browser/ui/views/commerce/price_tracking_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ PriceTrackingView::PriceTrackingView(Profile* profile,
title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
title_label->SetFocusBehavior(View::FocusBehavior::ACCESSIBLE_ONLY);
// Body label
int body_string_id = IDS_BOOKMARK_STAR_DIALOG_TRACK_PRICE_DESCRIPTION;
if (profile_ && commerce::IsEmailDisabledByUser(profile_->GetPrefs())) {
body_string_id = IDS_BOOKMARK_STAR_DIALOG_TRACK_PRICE_DESCRIPTION_EMAIL_OFF;
}
body_label_ = text_container->AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(
IDS_BOOKMARK_STAR_DIALOG_TRACK_PRICE_DESCRIPTION),
l10n_util::GetStringUTF16(body_string_id),
views::style::CONTEXT_DIALOG_BODY_TEXT, views::style::STYLE_SECONDARY));
body_label_->SetProperty(views::kMarginsKey,
gfx::Insets::TLBR(kLableSpacing, 0, 0, 0));
Expand Down
21 changes: 21 additions & 0 deletions chrome/browser/ui/views/commerce/price_tracking_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/commerce/core/mock_shopping_service.h"
#include "components/commerce/core/pref_names.h"
#include "components/commerce/core/test_utils.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
Expand Down Expand Up @@ -221,3 +222,23 @@ TEST_F(PriceTrackingViewTest, ToggleRecordUntracked) {
"Commerce.PriceTracking.BookmarkDialogPriceTrackViewUntrackedPrice"),
1);
}

TEST_F(PriceTrackingViewTest, EmailTurnedOff) {
profile()->GetPrefs()->SetBoolean(commerce::kPriceEmailNotificationsEnabled,
false);
const bool enabled = false;
CreateViewAndShow(enabled);
VerifyToggleState(enabled);
VerifyBodyMessage(l10n_util::GetStringUTF16(
IDS_BOOKMARK_STAR_DIALOG_TRACK_PRICE_DESCRIPTION_EMAIL_OFF));
}

TEST_F(PriceTrackingViewTest, EmailTurnedOn) {
profile()->GetPrefs()->SetBoolean(commerce::kPriceEmailNotificationsEnabled,
true);
const bool enabled = false;
CreateViewAndShow(enabled);
VerifyToggleState(enabled);
VerifyBodyMessage(l10n_util::GetStringUTF16(
IDS_BOOKMARK_STAR_DIALOG_TRACK_PRICE_DESCRIPTION));
}
1 change: 1 addition & 0 deletions chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8742,6 +8742,7 @@ test("unit_tests") {
"//chrome/browser/ui/tabs:tab_enums",
"//chrome/browser/ui/views",
"//components/app_constants",
"//components/commerce/core:pref_names",
"//components/commerce/core:shopping_service_test_support",
"//components/constrained_window",
"//components/global_media_controls",
Expand Down
12 changes: 12 additions & 0 deletions components/commerce/core/price_tracking_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,16 @@ void MaybeEnableEmailNotifications(PrefService* pref_service) {
}
}

bool IsEmailDisabledByUser(PrefService* pref_service) {
if (pref_service) {
const PrefService::Preference* email_pref =
pref_service->FindPreference(kPriceEmailNotificationsEnabled);
if (email_pref && !email_pref->IsDefaultValue() &&
!email_pref->GetValue()->GetBool()) {
return true;
}
}
return false;
}

} // namespace commerce
4 changes: 4 additions & 0 deletions components/commerce/core/price_tracking_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ bool PopulateOrUpdateBookmarkMetaIfNeeded(
// a noop.
void MaybeEnableEmailNotifications(PrefService* pref_service);

// Whether the email notification is explicitly disabled by the user. Return
// false if we are using the default preference value.
bool IsEmailDisabledByUser(PrefService* pref_service);

} // namespace commerce

#endif // COMPONENTS_COMMERCE_CORE_PRICE_TRACKING_UTILS_H_

0 comments on commit 764484f

Please sign in to comment.