chromium/chrome/renderer/cart/commerce_hint_agent_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.

#include "chrome/renderer/cart/commerce_hint_agent.h"

#include <string_view>

#include "base/cfi_buildflags.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "components/commerce/core/commerce_heuristics_data.h"
#include "components/commerce/core/commerce_heuristics_data_metrics_helper.h"
#if BUILDFLAG(IS_ANDROID)
#include "components/commerce/core/commerce_feature_list.h"
#else
#include "components/search/ntp_features.h"
#endif
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace {

constexpr int kTestIterations =;

// clang-format off
const char* kAddToCart[] =;

const char* kAddToCartWithDOMBasedHeuristics[] =;

const char* kNotAddToCart[] =;

const char* kNotAddToCartWithDOMBasedHeuristics[] =;

const char* kVisitCart[] =;

const char* kNotVisitCart[] =;

const char* kVisitCheckout[] =;

const char* kNotVisitCheckout[] =;

const char* kPurchaseURL[] =;

const char* kNotPurchaseURL[] =;

const char* kPurchaseText[] =;

const char* kNotPurchaseText[] =;

const char* kSkipText[] =;

const char* kNotSkipText[] =;
// clang-format on

// Cannot use \b, or non-alphabetical words would fail.
const char kSkipPattern[] =;
std::map<std::string, std::string> kSkipParams =;

std::map<std::string, std::string> kSkipAddToCartRequests =;

std::map<std::string, std::string> kNotSkipAddToCartRequests =;
}  // namespace

CommerceHintAgent;

class CommerceHintAgentUnitTest : public testing::Test {};

TEST_F(CommerceHintAgentUnitTest, IsAddToCart) {}

TEST_F(CommerceHintAgentUnitTest, IsAddToCartForDomBasedHeuristics) {}

TEST_F(CommerceHintAgentUnitTest, IsAddToCart_SkipLengthLimit) {}

TEST_F(CommerceHintAgentUnitTest, IsVisitCart) {}

TEST_F(CommerceHintAgentUnitTest, IsVisitCheckout) {}

TEST_F(CommerceHintAgentUnitTest, IsPurchaseByURL) {}

TEST_F(CommerceHintAgentUnitTest, IsPurchaseByForm) {}

TEST_F(CommerceHintAgentUnitTest, ShouldSkipFromFeatureParam) {}

TEST_F(CommerceHintAgentUnitTest, ShouldSkipFromComponent) {}

TEST_F(CommerceHintAgentUnitTest, ShouldSkip_Priority) {}

TEST_F(CommerceHintAgentUnitTest, ShouldSkipAddToCartFromResource) {}

float BenchmarkIsAddToCart(std::string_view str) {}

float BenchmarkIsVisitCart(const GURL& url) {}

float BenchmarkIsVisitCheckout(const GURL& url) {}

float BenchmarkIsPurchase(const GURL& url, std::string_view str) {}

float BenchmarkShouldSkip(std::string_view str) {}

float BenchmarkShouldSkipAddToCart(const GURL& url) {}

// TSAN builds are 20~50X slower than Release build.
#if defined(THREAD_SANITIZER) || defined(ADDRESS_SANITIZER) ||             \
    defined(MEMORY_SANITIZER) || BUILDFLAG(CFI_CAST_CHECK) ||              \
    BUILDFLAG(CFI_ICALL_CHECK) || BUILDFLAG(CFI_ENFORCEMENT_DIAGNOSTIC) || \
    BUILDFLAG(CFI_ENFORCEMENT_TRAP)
#define MAYBE_RegexBenchmark
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || !defined(NDEBUG)
// TODO(crbug.com/353775530):  Enable once cause of general slowdown is fixed.
#define MAYBE_RegexBenchmark
#else
#define MAYBE_RegexBenchmark
#endif

TEST_F(CommerceHintAgentUnitTest, MAYBE_RegexBenchmark) {}