File: mock_shopping_service.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 (177 lines) | stat: -rw-r--r-- 6,846 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// 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_MOCK_SHOPPING_SERVICE_H_
#define COMPONENTS_COMMERCE_CORE_MOCK_SHOPPING_SERVICE_H_

#include <map>
#include <memory>
#include <vector>

#include "components/commerce/core/compare/product_group.h"
#include "components/commerce/core/shopping_service.h"
#include "components/commerce/core/subscriptions/commerce_subscription.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace bookmarks {
class BookmarkNode;
}  // namespace bookmarks

namespace commerce {

class AccountChecker;
class MockClusterManager;
class MockProductSpecificationsService;

// A mock ShoppingService that allows us to decide the response.
class MockShoppingService : public commerce::ShoppingService {
 public:
  // Produces a testing::NiceMock of the MockShoppingService.
  static std::unique_ptr<KeyedService> Build();

  MockShoppingService();
  ~MockShoppingService() override;

  // commerce::ShoppingService overrides.
  MOCK_METHOD(AccountChecker*, GetAccountChecker, (), (override));
  MOCK_METHOD(void,
              GetProductInfoForUrl,
              (const GURL& url, commerce::ProductInfoCallback callback),
              (override));
  MOCK_METHOD(void,
              GetProductInfoForUrls,
              (const std::vector<GURL>& url, ProductInfoBatchCallback callback),
              (override));
  MOCK_METHOD(void,
              GetPriceInsightsInfoForUrl,
              (const GURL& url, commerce::PriceInsightsInfoCallback callback),
              (override));
  MOCK_METHOD(const std::vector<commerce::UrlInfo>,
              GetUrlInfosForActiveWebWrappers,
              (),
              (override));
  MOCK_METHOD(
      void,
      GetUrlInfosForWebWrappersWithProducts,
      (base::OnceCallback<void(const std::vector<commerce::UrlInfo>)> callback),
      (override));
  MOCK_METHOD(const std::vector<commerce::UrlInfo>,
              GetUrlInfosForRecentlyViewedWebWrappers,
              (),
              (override));
  MOCK_METHOD(void,
              GetUpdatedProductInfoForBookmarks,
              (const std::vector<int64_t>& bookmark_ids,
               BookmarkProductInfoUpdatedCallback info_updated_callback),
              (override));
  MOCK_METHOD(size_t, GetMaxProductBookmarkUpdatesPerBatch, (), (override));
  MOCK_METHOD(void,
              GetMerchantInfoForUrl,
              (const GURL& url, MerchantInfoCallback callback),
              (override));
  MOCK_METHOD(void,
              IsShoppingPage,
              (const GURL& url, IsShoppingPageCallback callback),
              (override));
  MOCK_METHOD(std::optional<ProductInfo>,
              GetAvailableProductInfoForUrl,
              (const GURL& url),
              (override));
  MOCK_METHOD(void,
              Subscribe,
              (std::unique_ptr<std::vector<CommerceSubscription>> subscriptions,
               base::OnceCallback<void(bool)> callback),
              (override));
  MOCK_METHOD(void,
              Unsubscribe,
              (std::unique_ptr<std::vector<CommerceSubscription>> subscriptions,
               base::OnceCallback<void(bool)> callback),
              (override));
  MOCK_METHOD(
      void,
      GetAllSubscriptions,
      (SubscriptionType type,
       base::OnceCallback<void(std::vector<CommerceSubscription>)> callback),
      (override));
  MOCK_METHOD(void,
              IsSubscribed,
              (CommerceSubscription subscription,
               base::OnceCallback<void(bool)> callback),
              (override));
  MOCK_METHOD(bool,
              IsSubscribedFromCache,
              (const CommerceSubscription& subscription),
              (override));
  MOCK_METHOD(void,
              GetAllPriceTrackedBookmarks,
              (base::OnceCallback<
                  void(std::vector<const bookmarks::BookmarkNode*>)> callback),
              (override));
  MOCK_METHOD(std::vector<const bookmarks::BookmarkNode*>,
              GetAllShoppingBookmarks,
              (),
              (override));
  MOCK_METHOD(void, ScheduleSavedProductUpdate, (), (override));
  MOCK_METHOD(bool, IsShoppingListEligible, (), (override));
  MOCK_METHOD(void,
              WaitForReady,
              (base::OnceCallback<void(ShoppingService*)>),
              (override));
  MOCK_METHOD(void,
              GetDiscountInfoForUrl,
              (const GURL& url, DiscountInfoCallback callback),
              (override));
  MOCK_METHOD(void,
              GetProductSpecificationsForUrls,
              (const std::vector<GURL>& urls,
               ProductSpecificationsCallback callback),
              (override));
  MOCK_METHOD(ProductSpecificationsService*,
              GetProductSpecificationsService,
              (),
              (override));
  MOCK_METHOD(ClusterManager*, GetClusterManager, (), (override));

  // Make this mock permissive for all features but default to providing empty
  // data for all accessors of shopping data.
  void SetupPermissiveMock();

  void SetAccountChecker(AccountChecker* account_checker);
  void SetResponseForGetProductInfoForUrl(
      std::optional<commerce::ProductInfo> product_info);
  void SetResponseForGetPriceInsightsInfoForUrl(
      std::optional<commerce::PriceInsightsInfo> price_insights_info);
  void SetResponseForGetUrlInfosForActiveWebWrappers(
      std::vector<commerce::UrlInfo> url_infos);
  void SetResponsesForGetUpdatedProductInfoForBookmarks(
      std::map<int64_t, ProductInfo> bookmark_updates);
  void SetResponseForGetMerchantInfoForUrl(
      std::optional<commerce::MerchantInfo> merchant_info);
  void SetResponseForIsShoppingPage(std::optional<bool> is_shopping_page);
  void SetSubscribeCallbackValue(bool subscribe_should_succeed);
  void SetUnsubscribeCallbackValue(bool unsubscribe_should_succeed);
  void SetIsSubscribedCallbackValue(bool is_subscribed);
  void SetGetAllSubscriptionsCallbackValue(
      std::vector<CommerceSubscription> subscriptions);
  void SetIsShoppingListEligible(bool enabled);
  void SetIsReady(bool ready);
  void SetGetAllPriceTrackedBookmarksCallbackValue(
      std::vector<const bookmarks::BookmarkNode*> bookmarks);
  void SetGetAllShoppingBookmarksValue(
      std::vector<const bookmarks::BookmarkNode*> bookmarks);
  void SetResponseForGetDiscountInfoForUrl(
      const std::vector<DiscountInfo>& infos);
  void SetResponseForGetProductSpecificationsForUrls(
      ProductSpecifications specs);

 private:
  std::unique_ptr<MockProductSpecificationsService>
      product_specifications_service_;
  std::unique_ptr<MockClusterManager> cluster_manager_;
};

}  // namespace commerce

#endif  // COMPONENTS_COMMERCE_CORE_MOCK_SHOPPING_SERVICE_H_