chromium/chrome/browser/cart/cart_handler_unittest.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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 =;
}  // namespace

class CartHandlerTest : public testing::Test {};

// Verifies that the ChromeCart feature status is correctly retrieved.
TEST_F(CartHandlerTest, TestGetCartFeatureEnabled) {}

// Verifies the hide status is flipped by hiding and restoring.
TEST_F(CartHandlerTest, TestHideStatusChange) {}

// Tests hiding a single cart and undoing the hide.
TEST_F(CartHandlerTest, TestHideCart) {}

// Tests removing a single cart and undoing the remove.
TEST_F(CartHandlerTest, TestRemoveCart) {}

// Verifies GetMerchantCarts loads real data without fake data parameter.
// Flaky, see crbug.com/1185497.
TEST_F(CartHandlerTest, DISABLED_TestDisableFakeData) {}

// Tests show welcome surface for first three appearances of cart module.
TEST_F(CartHandlerTest, TestShowWelcomeSurface) {}

// Verifies discount data not showing with RBD disabled.
TEST_F(CartHandlerTest, TestDiscountDataWithoutFeature) {}

// Override CartHandlerTest so that we can initialize feature_list_ in our
// constructor, before CartHandlerTest::SetUp is called.
class CartHandlerNtpModuleFakeDataTest : public CartHandlerTest {};

// Verifies GetMerchantCarts loads fake data with feature parameter.
TEST_F(CartHandlerNtpModuleFakeDataTest, TestEnableFakeData) {}

// Override CartHandlerTest so that we can initialize feature_list_ in our
// constructor, before CartHandlerTest::SetUp is called.
class CartHandlerNtpModuleDiscountTest : public CartHandlerTest {};

// Test discount consent card visibility aligns with CartService.
// Flaky on multiple platforms: crbug.com/1256745
TEST_F(CartHandlerNtpModuleDiscountTest,
       DISABLED_TestGetDiscountConsentCardVisible) {}

// Test OnDiscountConsentAcknowledged can update status in CartService.
// Flaky on multiple platforms: crbug.com/1256745
TEST_F(CartHandlerNtpModuleDiscountTest,
       DISABLED_TestOnDiscountConsentAcknowledged) {}

// Test GetDiscountEnabled returns whether rule-based discount feature is
// enabled.
TEST_F(CartHandlerNtpModuleDiscountTest, TestGetDiscountEnabled) {}

// Test SetDiscountEnabled updates whether rule-based discount is enabled.
TEST_F(CartHandlerNtpModuleDiscountTest, TestSetDiscountEnabled) {}

// Verifies discount data showing with RBD enabled.
TEST_F(CartHandlerNtpModuleDiscountTest, TestDiscountDataWithFeature) {}

// Verifies discount data showing when coupons is available.
TEST_F(CartHandlerNtpModuleDiscountTest, TestDiscountDataShows) {}

// Override CartHandlerTest so that we can initialize feature_list_ in our
// constructor, before CartHandlerTest::SetUp is called.
class CartHandlerCartURLUTMTest : public CartHandlerTest {};

// Verifies UTM tags are correctly appended to partner merchant's cart.
TEST_F(CartHandlerCartURLUTMTest, TestAppendUTMToPartnerMerchant) {}

// Verifies UTM tags are correctly appended to non-partner merchant's cart.
TEST_F(CartHandlerCartURLUTMTest, TestAppendUTMToNonPartnerMerchant) {}

class CartHandlerNtpModuleDiscountConsentV2Test : public CartHandlerTest {};

TEST_F(CartHandlerNtpModuleDiscountConsentV2Test,
       TestOnDiscountConsentDismissed) {}