chromium/components/commerce/core/shopping_service_unittest.cc

// Copyright 2022 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 "components/commerce/core/shopping_service.h"

#include <string>

#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/values.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/bookmarks/test/test_bookmark_client.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/feature_utils.h"
#include "components/commerce/core/mock_account_checker.h"
#include "components/commerce/core/mock_discounts_storage.h"
#include "components/commerce/core/pref_names.h"
#include "components/commerce/core/proto/shopping_page_types.pb.h"
#include "components/commerce/core/shopping_service_test_base.h"
#include "components/commerce/core/test_utils.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/browser/url_row.h"
#include "components/optimization_guide/core/optimization_guide_decider.h"
#include "components/optimization_guide/core/optimization_guide_decision.h"
#include "components/optimization_guide/core/optimization_metadata.h"
#include "components/optimization_guide/proto/hints.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/search/ntp_features.h"
#include "components/signin/public/base/consent_level.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/sync/base/features.h"
#include "components/sync/base/user_selectable_type.h"
#include "components/sync/test/test_sync_service.h"
#include "components/unified_consent/pref_names.h"
#include "net/base/url_util.h"
#include "testing/gtest/include/gtest/gtest.h"

OptimizationGuideDecision;
OptimizationGuideDecisionCallback;
OptimizationMetadata;
Any;
OptimizationType;

_;

namespace commerce {

namespace {

const char kProductUrl[] =;
const char kTitle[] =;
const char kGpcTitle[] =;
const char kImageUrl[] =;
const uint64_t kOfferId =;
const uint64_t kClusterId =;
const char kCountryCode[] =;
const char kCurrencyCode[] =;
const int64_t kPrice =;
const int64_t kNewPrice =;

const char kMerchantUrl[] =;
const float kStarRating =;
const uint32_t kCountRating =;
const char kDetailsPageUrl[] =;
const bool kHasReturnPolicy =;
const bool kContainsSensitiveContent =;

const char kEligibleCountry[] =;
const char kEligibleLocale[] =;

const char kPriceInsightsUrl[] =;
const int64_t kLowTypicalPrice =;
const int64_t kHighTypicalPrice =;
const char kAnotherCurrencyCode[] =;
const char kAttributes[] =;
const char kJackpotUrl[] =;

const char kDiscountsUrl1[] =;
const char kDiscountsUrl2[] =;
const char kDiscountLanguageCode[] =;
const char kDiscountDetail[] =;
const char kDiscountTerms[] =;
const char kDiscountValueText[] =;
const double kDiscountExpiryTime =;
const char kDiscountCode[] =;
const uint64_t kDiscountId1 =;
const uint64_t kDiscountOfferId =;

const std::vector<std::vector<std::string>> kProductCategories =;

NiceMockWebWrapper;

}  // namespace

class ShoppingServiceTest : public ShoppingServiceTestBase,
                            public testing::WithParamInterface<bool> {};

// Test that product info is processed correctly.
TEST_P(ShoppingServiceTest, TestProductInfoResponse) {}

// Test that product info is fetched on demand if there is no web page open but
// the cache has an entry for the queried URL.
TEST_P(ShoppingServiceTest, TestProductInfoResponse_FallbackToOnDemand) {}

// Test multiple on demand calls to get product info.
TEST_P(ShoppingServiceTest, TestProductInfoResponse_MultipleOnDemandRequests) {}
// Test that the product info api fails gracefully (callback run with nullopt)
// if it is disabled.
TEST_P(ShoppingServiceTest, TestProductInfoResponse_ApiDisabled) {}

TEST_P(ShoppingServiceTest, TestProductInfoResponse_CurrencyMismatch) {}

// Test that no object is provided for a negative optimization guide response.
TEST_P(ShoppingServiceTest, TestProductInfoResponse_OptGuideFalse) {}

// Test that the product info cache only keeps track of live tabs.
TEST_P(ShoppingServiceTest, TestProductInfoCacheURLCount) {}

// Ensure we keep track of live web wrappers.
TEST_P(ShoppingServiceTest, TestWebWrapperSet) {}

// Ensure we correctly identify open tabs with products.
TEST_P(ShoppingServiceTest, TestWebWrapperSetWithProducts) {}

// Make sure recent URLs doesn't contain duplicates.
TEST_P(ShoppingServiceTest, TestRecentUrls_NoDuplicates) {}

// Make sure recent URLs doesn't go over the max size.
TEST_P(ShoppingServiceTest, TestRecentUrls_MaxCount) {}

TEST_P(ShoppingServiceTest, TestRecentUrls_ClearedOnHistoryDeletion) {}

TEST_P(ShoppingServiceTest, TestRecentUrls_SingleHistoryItemDeletion) {}

TEST_P(ShoppingServiceTest, TestRecentUrls_CacheEntriesRetained) {}

// Ensure the cache maintained by the service is observing changes in the URLs
// stored in each ProductSpecificationsSet.
TEST_P(ShoppingServiceTest, TestProductSpecificationsSetUrlsRetained) {}

TEST_P(ShoppingServiceTest, TestProductSpecificationsUrlCountMetrics) {}

// Test that product info is inserted into the cache without a client
// necessarily querying for it.
TEST_P(ShoppingServiceTest, TestProductInfoCacheFullLifecycle) {}

// Test the full lifecycle of product info assuming the page loads after
// optimization guide has provided a response.
TEST_P(ShoppingServiceTest,
       TestProductInfoCacheFullLifecycleWithFallback_PageNotLoaded) {}

// Test the full lifecycle of product info assuming the page has loaded prior
// to optimization guide providing a response. This will happen for single-page
// webapps.
TEST_P(ShoppingServiceTest,
       TestProductInfoCacheFullLifecycleWithFallback_PageLoaded) {}

// The on-demand api should not be triggered in the case where we have an
// explicit negative signal from the page.
TEST_P(ShoppingServiceTest, TestProductInfoWithFallback_NoOnDemandCalls) {}

// If there's a reference to the url in the cache and opt guide doesn't know
// about the url, we should be allowed to call the on-demand api.
TEST_P(ShoppingServiceTest,
       TestProductInfoWithFallback_CallsOnDemandOnce_RefInCache) {}

// Test that merchant info is processed correctly.
TEST_P(ShoppingServiceTest, TestMerchantInfoResponse) {}

// Test that the merchant info fails gracefully when the api is disabled.
TEST_P(ShoppingServiceTest, TestMerchantInfoResponse_ApiDisabled) {}

TEST_P(ShoppingServiceTest, TestGetUpdatedProductInfoForBookmarks) {}

TEST_P(ShoppingServiceTest, TestDataMergeWithLeadImage) {}

TEST_P(ShoppingServiceTest, TestDataMergeWithNoLeadImage) {}

TEST_P(ShoppingServiceTest, TestDataMergeWithTitle) {}

TEST_P(ShoppingServiceTest, TestDataMergeWithNoTitle) {}

TEST_P(ShoppingServiceTest, TestShoppingListEligible_Policy) {}

TEST_P(ShoppingServiceTest, TestShoppingListEligible_FeatureFlagOff) {}

TEST_P(ShoppingServiceTest, TestShoppingListEligible_MSBB) {}

TEST_P(ShoppingServiceTest, TestShoppingListEligible_SignIn) {}

TEST_P(ShoppingServiceTest, TestShoppingListEligible_ChildAccount) {}

TEST_P(ShoppingServiceTest, TestShoppingListEligible_SyncState) {}

TEST_P(ShoppingServiceTest, TestShoppingListEligible_CountryAndLocale) {}

TEST_P(ShoppingServiceTest,
       TestShoppingListEligible_CountryAndLocale_BothFlags) {}

TEST_P(ShoppingServiceTest, TestShoppingListEligible_CountryAndLocale_NoFlags) {}

TEST_P(ShoppingServiceTest,
       TestShoppingListEligible_CountryAndLocale_RegionLaunched) {}

class ShoppingServiceReadyTest : public ShoppingServiceTest {};

TEST_P(ShoppingServiceReadyTest,
       TestServiceReadyDelaysForSync_TransportStartsInactive) {}

TEST_P(ShoppingServiceReadyTest,
       TestServiceReadyDelaysForSync_TransportStartsActive) {}

INSTANTIATE_TEST_SUITE_P();

TEST_P(ShoppingServiceTest, TestPriceInsightsInfoResponse) {}

TEST_P(ShoppingServiceTest,
       TestPriceInsightsInfoResponse_DifferentCurrencyCode) {}

TEST_P(ShoppingServiceTest, TestPriceInsightsInfoResponse_EmptyClusterId) {}

TEST_P(ShoppingServiceTest, TestPriceInsightsInfoResponse_EmptyRange) {}

TEST_P(ShoppingServiceTest, TestPriceInsightsInfoResponse_WithoutCache) {}

TEST_P(ShoppingServiceTest, TestPriceInsightsInfoResponse_WithCache) {}

TEST_P(ShoppingServiceTest,
       TestPriceInsightsInfoResponse_WithCacheMultipleTabs) {}

TEST_P(ShoppingServiceTest, TestIsShoppingPage) {}

TEST_P(ShoppingServiceTest, TestDiscountInfoResponse) {}

TEST_P(ShoppingServiceTest, TestDiscountInfoResponse_InfoWithoutId) {}

TEST_P(ShoppingServiceTest, TestDiscountInfoResponse_InfoWithoutTerms) {}

TEST_P(ShoppingServiceTest, TestDiscountInfoResponse_InfoWithoutDiscountCode) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace commerce