#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/cart/cart_handler.h"
#include <optional>
#include "base/memory/raw_ptr.h"
#include "base/test/metrics/histogram_tester.h"
#include "build/build_config.h"
#include "chrome/browser/cart/cart_service.h"
#include "chrome/browser/cart/cart_service_factory.h"
#include "chrome/browser/commerce/shopping_service_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/commerce/core/commerce_constants.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/commerce_heuristics_data.h"
#include "components/commerce/core/mock_shopping_service.h"
#include "components/commerce/core/proto/cart_db_content.pb.h"
#include "components/commerce/core/shopping_service.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/search/ntp_features.h"
#include "components/session_proto_db/session_proto_db.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_web_contents_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
void GetEvaluationMerchantCarts(
base::OnceClosure closure,
std::vector<chrome_cart::mojom::MerchantCartPtr> expected,
std::vector<chrome_cart::mojom::MerchantCartPtr> found) { … }
void GetEvaluationMerchantCartWithUtmSource(
base::OnceClosure closure,
bool expected_has_utm_source,
const std::string& expected_utm_source_tag_and_value,
std::vector<chrome_cart::mojom::MerchantCartPtr> found) { … }
cart_db::ChromeCartContentProto BuildProto(const char* key,
const char* domain,
const char* merchant_url) { … }
const char kFakeMerchantKey[] = …;
const char kFakeMerchant[] = …;
const char kFakeMerchantURL[] = …;
const char kMockMerchantBKey[] = …;
const char kMockMerchantB[] = …;
const char kMockMerchantURLB[] = …;
const cart_db::ChromeCartContentProto kFakeProto = …;
const cart_db::ChromeCartContentProto kMockProtoB = …;
const std::vector<SessionProtoDB<cart_db::ChromeCartContentProto>::KeyAndValue>
kExpectedFake = …;
const std::vector<SessionProtoDB<cart_db::ChromeCartContentProto>::KeyAndValue>
kExpectedAllData = …;
}
class CartHandlerTest : public testing::Test { … };
TEST_F(CartHandlerTest, TestGetCartFeatureEnabled) { … }
TEST_F(CartHandlerTest, TestHideStatusChange) { … }
TEST_F(CartHandlerTest, TestHideCart) { … }
TEST_F(CartHandlerTest, TestRemoveCart) { … }
TEST_F(CartHandlerTest, DISABLED_TestDisableFakeData) { … }
TEST_F(CartHandlerTest, TestShowWelcomeSurface) { … }
TEST_F(CartHandlerTest, TestDiscountDataWithoutFeature) { … }
class CartHandlerNtpModuleFakeDataTest : public CartHandlerTest { … };
TEST_F(CartHandlerNtpModuleFakeDataTest, TestEnableFakeData) { … }
class CartHandlerNtpModuleDiscountTest : public CartHandlerTest { … };
TEST_F(CartHandlerNtpModuleDiscountTest,
DISABLED_TestGetDiscountConsentCardVisible) { … }
TEST_F(CartHandlerNtpModuleDiscountTest,
DISABLED_TestOnDiscountConsentAcknowledged) { … }
TEST_F(CartHandlerNtpModuleDiscountTest, TestGetDiscountEnabled) { … }
TEST_F(CartHandlerNtpModuleDiscountTest, TestSetDiscountEnabled) { … }
TEST_F(CartHandlerNtpModuleDiscountTest, TestDiscountDataWithFeature) { … }
TEST_F(CartHandlerNtpModuleDiscountTest, TestDiscountDataShows) { … }
class CartHandlerCartURLUTMTest : public CartHandlerTest { … };
TEST_F(CartHandlerCartURLUTMTest, TestAppendUTMToPartnerMerchant) { … }
TEST_F(CartHandlerCartURLUTMTest, TestAppendUTMToNonPartnerMerchant) { … }
class CartHandlerNtpModuleDiscountConsentV2Test : public CartHandlerTest { … };
TEST_F(CartHandlerNtpModuleDiscountConsentV2Test,
TestOnDiscountConsentDismissed) { … }