File: test_utils.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (124 lines) | stat: -rw-r--r-- 4,510 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// 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.

#ifndef COMPONENTS_COMMERCE_CORE_TEST_UTILS_H_
#define COMPONENTS_COMMERCE_CORE_TEST_UTILS_H_

#include <optional>
#include <string>

#include "base/test/scoped_feature_list.h"
#include "components/commerce/core/commerce_types.h"
#include "components/commerce/core/shopping_service.h"
#include "components/commerce/core/subscriptions/commerce_subscription.h"
#include "testing/gmock/include/gmock/gmock.h"

class GURL;
class TestingPrefServiceSimple;

namespace bookmarks {
class BookmarkModel;
class BookmarkNode;
}  // namespace bookmarks

namespace {
const char kDate[] = "2023-06-01";
const int64_t kTypicalLowPriceMicros = 1;
const int64_t kTypicalHighPriceMicros = 10;
const int64_t kTypicalPriceMicros = 5;
}  // namespace

namespace commerce {

class MockAccountChecker;

// A matcher that checks that a
// std::unique_ptr<std::vector<CommerceSubscription>> contains a subscription
// ID that matches the provided string.
MATCHER_P(VectorHasSubscriptionWithId, expected_id, "") {
  for (CommerceSubscription& sub : *arg.get()) {
    if (sub.id == expected_id) {
      return true;
    }
  }
  return false;
}

// A matcher that checks that a CommerceSubscription contains a subscription ID
// that matches the provided string.
MATCHER_P(SubscriptionWithId, expected_id, "") {
  return arg.id == expected_id;
}

// Create a product bookmark with the specified cluster ID and place it in the
// "other" bookmarks folder.
const bookmarks::BookmarkNode* AddProductBookmark(
    bookmarks::BookmarkModel* bookmark_model,
    const std::u16string& title,
    const GURL& url,
    uint64_t cluster_id,
    bool is_price_tracked = false,
    const int64_t price_micros = 0L,
    const std::string& currency_code = "usd",
    const std::optional<int64_t>& last_subscription_change_time = std::nullopt);

// Add product information to an existing bookmark node.
void AddProductInfoToExistingBookmark(
    bookmarks::BookmarkModel* bookmark_model,
    const bookmarks::BookmarkNode* bookmark_node,
    const std::u16string& title,
    uint64_t cluster_id,
    bool is_price_tracked = false,
    const int64_t price_micros = 0L,
    const std::string& currency_code = "usd",
    const std::optional<int64_t>& last_subscription_change_time = std::nullopt);

// Sets the state of the enterprise policy for the shopping list feature for
// testing.
void SetShoppingListEnterprisePolicyPref(TestingPrefServiceSimple* prefs,
                                         bool enabled);

// Set the tab compare enterprise policy for testing.
void SetTabCompareEnterprisePolicyPref(TestingPrefServiceSimple* prefs,
                                       int enabled_state);

// Set up price insights eligibility for testing.
void SetUpPriceInsightsEligibility(base::test::ScopedFeatureList* feature_list,
                                   MockAccountChecker* account_checker,
                                   bool is_eligible);

// Set up discount eligibility for testing.
void SetUpDiscountEligibility(base::test::ScopedFeatureList* feature_list,
                              MockAccountChecker* account_checker,
                              bool is_eligible);

// Set up `account_checker` to be `eligible` for discount testing. Please note
// that this API does not change feature setup. Tests that want to set up their
// own features should use this API.
void SetUpDiscountEligibilityForAccount(MockAccountChecker* account_checker,
                                        bool is_eligible);

std::optional<PriceInsightsInfo> CreateValidPriceInsightsInfo(
    bool has_price_range_data = false,
    bool has_price_history_data = false,
    PriceBucket price_bucket = PriceBucket::kUnknown);

DiscountInfo CreateValidDiscountInfo(
    const std::string& detail,
    const std::string& terms_and_conditions,
    const std::string& value_in_text,
    const std::string& discount_code,
    int64_t id,
    bool is_merchant_wide,
    std::optional<double> expiry_time_sec,
    DiscountClusterType cluster_type = DiscountClusterType::kOfferLevel);

// Set up `account_checker` and `prefs` so that product specification data
// fetching is enabled.
void EnableProductSpecificationsDataFetch(MockAccountChecker* account_checker,
                                          TestingPrefServiceSimple* prefs);

}  // namespace commerce

#endif  // COMPONENTS_COMMERCE_CORE_TEST_UTILS_H_