#include "components/commerce/core/webui/shopping_service_handler.h"
#include <memory>
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/uuid.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/test/test_bookmark_client.h"
#include "components/commerce/core/commerce_constants.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/commerce_utils.h"
#include "components/commerce/core/mock_account_checker.h"
#include "components/commerce/core/mock_shopping_service.h"
#include "components/commerce/core/pref_names.h"
#include "components/commerce/core/price_tracking_utils.h"
#include "components/commerce/core/product_specifications/mock_product_specifications_service.h"
#include "components/commerce/core/product_specifications/product_specifications_service.h"
#include "components/commerce/core/product_specifications/product_specifications_set.h"
#include "components/commerce/core/subscriptions/commerce_subscription.h"
#include "components/commerce/core/test_utils.h"
#include "components/feature_engagement/test/mock_tracker.h"
#include "components/optimization_guide/core/model_quality/feature_type_map.h"
#include "components/optimization_guide/core/model_quality/test_model_quality_logs_uploader_service.h"
#include "components/optimization_guide/core/optimization_guide_prefs.h"
#include "components/optimization_guide/proto/features/product_specifications.pb.h"
#include "components/power_bookmarks/core/power_bookmark_utils.h"
#include "components/power_bookmarks/core/proto/power_bookmark_meta.pb.h"
#include "components/power_bookmarks/core/proto/shopping_specifics.pb.h"
#include "components/prefs/testing_pref_service.h"
#include "components/sync/test/mock_data_type_local_change_processor.h"
#include "components/ukm/test_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/webui/resources/cr_components/commerce/shopping_service.mojom.h"
#include "url/gurl.h"
namespace commerce {
namespace {
const std::string kTestUrl1 = …;
const std::string kTestUrl2 = …;
const std::string kTestHistoryResultTitle = …;
class MockPage : public shopping_service::mojom::Page { … };
class MockDelegate : public ShoppingServiceHandler::Delegate { … };
void GetEvaluationProductInfos(
base::OnceClosure closure,
std::vector<shopping_service::mojom::BookmarkProductInfoPtr> expected,
std::vector<shopping_service::mojom::BookmarkProductInfoPtr> found) { … }
MATCHER_P(MojoBookmarkInfoWithId, expected_id, "") { … }
MATCHER_P(MojoBookmarkInfoWithClusterId, expected_id, "") { … }
class ShoppingServiceHandlerTest : public testing::Test { … };
TEST_F(ShoppingServiceHandlerTest, ConvertToMojoTypes) { … }
TEST_F(ShoppingServiceHandlerTest, ConvertToMojoTypes_PriceIncrease) { … }
TEST_F(ShoppingServiceHandlerTest, TestTrackProductSuccess) { … }
TEST_F(ShoppingServiceHandlerTest, TestUntrackProductSuccess) { … }
TEST_F(ShoppingServiceHandlerTest, TestTrackProductFailure) { … }
TEST_F(ShoppingServiceHandlerTest, TestUntrackProductFailure) { … }
TEST_F(ShoppingServiceHandlerTest, PageUpdateForPriceTrackChange) { … }
TEST_F(ShoppingServiceHandlerTest, TestUnsubscribeCausedByBookmarkDeletion) { … }
TEST_F(ShoppingServiceHandlerTest, TestGetProductInfo_FeatureEnabled) { … }
TEST_F(ShoppingServiceHandlerTest, TestGetAllShoppingInfo_FeatureEnabled) { … }
TEST_F(ShoppingServiceHandlerTest,
TestGetProductInfoForCurrentUrl_FeatureEligible) { … }
TEST_F(ShoppingServiceHandlerTest, TestGetProductInfoForUrl) { … }
TEST_F(ShoppingServiceHandlerTest, TestGetPageTitleFromHistory) { … }
TEST_F(ShoppingServiceHandlerTest,
TestGetProductInfoForCurrentUrl_FeatureIneligible) { … }
TEST_F(ShoppingServiceHandlerTest, TestGetPriceInsightsInfoForCurrentUrl) { … }
TEST_F(ShoppingServiceHandlerTest, TestGetPriceInsightsInfoForUrl) { … }
TEST_F(ShoppingServiceHandlerTest,
TestGetPriceInsightsInfoForUrlWhenNotPriceInsightsEligible) { … }
TEST_F(ShoppingServiceHandlerTest, TestGetUrlInfosForProductTabs) { … }
TEST_F(ShoppingServiceHandlerTest, TestGetUrlInfosForRecentlyViewedTabs) { … }
TEST_F(ShoppingServiceHandlerTest, TestShowInsightsSidePanelUI) { … }
TEST_F(ShoppingServiceHandlerTest, TestOpenUrlInNewTab) { … }
TEST_F(ShoppingServiceHandlerTest, TestSwitchToOrOpenTab) { … }
TEST_F(ShoppingServiceHandlerTest, TestShowFeedbackForPriceInsights) { … }
TEST_F(ShoppingServiceHandlerTest,
SetProductSpecificationsUserFeedback_NonNegative) { … }
TEST_F(ShoppingServiceHandlerTest,
SetProductSpecificationsUserFeedback_Negative) { … }
TEST_F(ShoppingServiceHandlerTest, TestIsShoppingListEligible) { … }
TEST_F(ShoppingServiceHandlerTest,
TestGetPriceTrackingStatusForCurrentUrl_WithBookmark) { … }
TEST_F(ShoppingServiceHandlerTest,
TestGetPriceTrackingStatusForCurrentUrl_WithoutBookmark) { … }
TEST_F(ShoppingServiceHandlerTest, TestTrackPriceForCurrentUrl) { … }
TEST_F(ShoppingServiceHandlerTest, TestUntrackPriceForCurrentUrl) { … }
TEST_F(ShoppingServiceHandlerTest,
TestGetParentBookmarkFolderNameForCurrentUrl_NoBookmark) { … }
TEST_F(ShoppingServiceHandlerTest, TestShowBookmarkEditorForCurrentUrl) { … }
TEST_F(ShoppingServiceHandlerTest, TestShowProductSpecificationsSetForUuid) { … }
TEST_F(ShoppingServiceHandlerTest, TestGetProductSpecifications) { … }
TEST_F(ShoppingServiceHandlerTest,
TestGetProductSpecifications_RecordLogEntry) { … }
TEST_F(ShoppingServiceHandlerTest,
TestLogEntryReplacesForGetProductSpecifications) { … }
TEST_F(ShoppingServiceHandlerTest, TestSetDisclosureVersion) { … }
TEST_F(ShoppingServiceHandlerTest, TestSetDisclosureVersion_DefaultValue) { … }
TEST_F(ShoppingServiceHandlerTest, TestBookmarkNodeMoved) { … }
TEST_F(ShoppingServiceHandlerTest, TestGetAllProductSpecificationsSets) { … }
TEST_F(ShoppingServiceHandlerTest, TestGetProductSpecificationsSetByUuid) { … }
TEST_F(ShoppingServiceHandlerTest, TestAddProductSpecificationsSet) { … }
TEST_F(ShoppingServiceHandlerTest, TestDeleteProductSpecificationsSet) { … }
TEST_F(ShoppingServiceHandlerTest, TestSetNameForProductSpecificationsSet) { … }
TEST_F(ShoppingServiceHandlerTest, TestShowSyncSetupFlow) { … }
TEST_F(ShoppingServiceHandlerTest, TestSetUrlsForProductSpecificationsSet) { … }
TEST_F(ShoppingServiceHandlerTest,
TestMaybeShowProductSpecificationDisclosure_NotShow) { … }
TEST_F(ShoppingServiceHandlerTest,
TestMaybeShowProductSpecificationDisclosure_Show) { … }
TEST_F(ShoppingServiceHandlerTest, TestDeclineProductSpecificationDisclosure) { … }
TEST_F(ShoppingServiceHandlerTest,
TestGetProductSpecificationsFeatureState_Allowed) { … }
TEST_F(ShoppingServiceHandlerTest,
TestGetProductSpecificationsFeatureState_NotAllowed) { … }
class ShoppingServiceHandlerFeatureDisableTest : public testing::Test { … };
TEST_F(ShoppingServiceHandlerFeatureDisableTest,
TestGetProductInfo_FeatureDisabled) { … }
class ShoppingServiceHandlerLoggingDisableTest
: public ShoppingServiceHandlerTest { … };
TEST_F(ShoppingServiceHandlerLoggingDisableTest,
TestGetProductSpecifications_NoLoggingEntry) { … }
TEST_F(ShoppingServiceHandlerLoggingDisableTest,
SetProductSpecificationsUserFeedback_NoFeedback) { … }
}
}