Commit 3c526c9d authored by Yue Zhang's avatar Yue Zhang Committed by Chromium LUCI CQ

[ChromeCart] Update dismiss/restore functionalities in CartService

Instead of using one boolean value in profile pref to record
dismiss/restore state of cart module, this CL introduces two boolean
values to record whether the module is temporarily hidden or
permanently removed.

Bug: 1157892
Change-Id: I01d95a62fca6466ab893c7be8afbc20b5065ddf6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2625816Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844179}
parent 72a1f14c
......@@ -48,9 +48,9 @@ void CartHandler::GetMerchantCarts(GetMerchantCartsCallback callback) {
}
void CartHandler::DismissCartModule() {
CartServiceFactory::GetForProfile(profile_)->Dismiss();
CartServiceFactory::GetForProfile(profile_)->Hide();
}
void CartHandler::RestoreCartModule() {
CartServiceFactory::GetForProfile(profile_)->Restore();
CartServiceFactory::GetForProfile(profile_)->RestoreHidden();
}
......@@ -12,17 +12,30 @@ CartService::CartService(Profile* profile)
CartService::~CartService() = default;
void CartService::RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(prefs::kCartModuleDismissed, false);
registry->RegisterBooleanPref(prefs::kCartModuleHidden, false);
registry->RegisterBooleanPref(prefs::kCartModuleRemoved, false);
}
void CartService::Dismiss() {
profile_->GetPrefs()->SetBoolean(prefs::kCartModuleDismissed, true);
void CartService::Hide() {
profile_->GetPrefs()->SetBoolean(prefs::kCartModuleHidden, true);
}
void CartService::Restore() {
profile_->GetPrefs()->SetBoolean(prefs::kCartModuleDismissed, false);
void CartService::RestoreHidden() {
profile_->GetPrefs()->SetBoolean(prefs::kCartModuleHidden, false);
}
bool CartService::IsDismissed() {
return profile_->GetPrefs()->GetBoolean(prefs::kCartModuleDismissed);
bool CartService::IsHidden() {
return profile_->GetPrefs()->GetBoolean(prefs::kCartModuleHidden);
}
void CartService::Remove() {
profile_->GetPrefs()->SetBoolean(prefs::kCartModuleRemoved, true);
}
void CartService::RestoreRemoved() {
profile_->GetPrefs()->SetBoolean(prefs::kCartModuleRemoved, false);
}
bool CartService::IsRemoved() {
return profile_->GetPrefs()->GetBoolean(prefs::kCartModuleRemoved);
}
......@@ -21,12 +21,18 @@ class CartService : public KeyedService {
~CartService() override;
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
// Gets called when cart module is dismissed.
void Dismiss();
// Gets called when the dismiss of cart module is restored.
void Restore();
// Returns the current dismiss status of cart module.
bool IsDismissed();
// Gets called when cart module is temporarily hidden.
void Hide();
// Gets called when restoring the temporarily hidden cart module.
void RestoreHidden();
// Returns whether cart module has been temporarily hidden.
bool IsHidden();
// Gets called when cart module is permanently removed.
void Remove();
// Gets called when restoring the permanently removed cart module.
void RestoreRemoved();
// Returns whether cart module has been permanently removed.
bool IsRemoved();
private:
friend class CartServiceFactory;
......
......@@ -28,13 +28,24 @@ class CartServiceTest : public testing::Test {
CartService* service_;
};
// Verifies the dismiss status is flipped by dismiss and restore.
TEST_F(CartServiceTest, TestDismissStatusChange) {
ASSERT_FALSE(service_->IsDismissed());
// Verifies the hide status is flipped by hiding and restoring.
TEST_F(CartServiceTest, TestHideStatusChange) {
ASSERT_FALSE(service_->IsHidden());
service_->Dismiss();
ASSERT_TRUE(service_->IsDismissed());
service_->Hide();
ASSERT_TRUE(service_->IsHidden());
service_->Restore();
ASSERT_FALSE(service_->IsDismissed());
service_->RestoreHidden();
ASSERT_FALSE(service_->IsHidden());
}
// Verifies the remove status is flipped by removing and restoring.
TEST_F(CartServiceTest, TestRemoveStatusChange) {
ASSERT_FALSE(service_->IsRemoved());
service_->Remove();
ASSERT_TRUE(service_->IsRemoved());
service_->RestoreRemoved();
ASSERT_FALSE(service_->IsRemoved());
}
......@@ -3150,7 +3150,9 @@ const char kSecurityTokenSessionNotificationScheduledDomain[] =
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
#if !defined(OS_ANDROID)
// Boolean pref indicating whether user has dismissed the cart module on NTP.
const char kCartModuleDismissed[] = "cart_module_dismissed";
// Boolean pref indicating whether user has hidden the cart module on NTP.
const char kCartModuleHidden[] = "cart_module_hidden";
// Boolean pref indicating whether user has removed the cart module on NTP.
const char kCartModuleRemoved[] = "cart_module_removed";
#endif
} // namespace prefs
......@@ -1103,7 +1103,8 @@ extern const char kSecurityTokenSessionNotificationScheduledDomain[];
#endif
#if !defined(OS_ANDROID)
extern const char kCartModuleDismissed[];
extern const char kCartModuleHidden[];
extern const char kCartModuleRemoved[];
#endif
} // namespace prefs
......
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