Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: components/payments/content/payment_manifest_downloader_unittest.cc

Issue 2802043002: Use web-app manifest format for Android payment apps. (Closed)
Patch Set: Address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/payments/content/payment_manifest_downloader.h" 5 #include "components/payments/content/payment_manifest_downloader.h"
6 6
7 #include "base/threading/thread_task_runner_handle.h" 7 #include "base/threading/thread_task_runner_handle.h"
8 #include "content/public/test/test_browser_thread_bundle.h" 8 #include "content/public/test/test_browser_thread_bundle.h"
9 #include "net/http/http_response_headers.h" 9 #include "net/http/http_response_headers.h"
10 #include "net/url_request/test_url_fetcher_factory.h" 10 #include "net/url_request/test_url_fetcher_factory.h"
11 #include "net/url_request/url_request_test_util.h" 11 #include "net/url_request/url_request_test_util.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace payments { 15 namespace payments {
16 namespace { 16 namespace {
17 17
18 class PaymentManifestDownloaderTest 18 class PaymentMethodManifestDownloaderTest
19 : public testing::Test, 19 : public testing::Test,
20 public PaymentManifestDownloader::Delegate { 20 public PaymentManifestDownloader::Delegate {
21 public: 21 public:
22 PaymentManifestDownloaderTest() 22 PaymentMethodManifestDownloaderTest()
23 : context_(new net::TestURLRequestContextGetter( 23 : context_(new net::TestURLRequestContextGetter(
24 base::ThreadTaskRunnerHandle::Get())), 24 base::ThreadTaskRunnerHandle::Get())),
25 downloader_(context_, GURL("https://bobpay.com"), this) { 25 downloader_(context_, GURL("https://bobpay.com"), this) {
26 downloader_.Download(); 26 downloader_.DownloadPaymentMethodManifest();
27 } 27 }
28 28
29 ~PaymentManifestDownloaderTest() override {} 29 ~PaymentMethodManifestDownloaderTest() override {}
30 30
31 // PaymentManifestDownloader::Delegate 31 // PaymentManifestDownloader::Delegate
32 MOCK_METHOD1(OnManifestDownloadSuccess, void(const std::string& content)); 32 MOCK_METHOD1(OnManifestDownloadSuccess, void(const std::string& content));
33 MOCK_METHOD0(OnManifestDownloadFailure, void()); 33 MOCK_METHOD0(OnManifestDownloadFailure, void());
34 34
35 net::TestURLFetcher* fetcher() { return factory_.GetFetcherByID(0); } 35 net::TestURLFetcher* fetcher() { return factory_.GetFetcherByID(0); }
36 36
37 private: 37 private:
38 content::TestBrowserThreadBundle thread_bundle_; 38 content::TestBrowserThreadBundle thread_bundle_;
39 net::TestURLFetcherFactory factory_; 39 net::TestURLFetcherFactory factory_;
40 scoped_refptr<net::TestURLRequestContextGetter> context_; 40 scoped_refptr<net::TestURLRequestContextGetter> context_;
41 PaymentManifestDownloader downloader_; 41 PaymentManifestDownloader downloader_;
42 42
43 DISALLOW_COPY_AND_ASSIGN(PaymentManifestDownloaderTest); 43 DISALLOW_COPY_AND_ASSIGN(PaymentMethodManifestDownloaderTest);
44 }; 44 };
45 45
46 TEST_F(PaymentManifestDownloaderTest, HttpHeadResponse404IsFailure) { 46 TEST_F(PaymentMethodManifestDownloaderTest, HttpHeadResponse404IsFailure) {
47 fetcher()->set_response_code(404); 47 fetcher()->set_response_code(404);
48 48
49 EXPECT_CALL(*this, OnManifestDownloadFailure()); 49 EXPECT_CALL(*this, OnManifestDownloadFailure());
50 50
51 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 51 fetcher()->delegate()->OnURLFetchComplete(fetcher());
52 } 52 }
53 53
54 TEST_F(PaymentManifestDownloaderTest, NoHttpHeadersIsFailure) { 54 TEST_F(PaymentMethodManifestDownloaderTest, NoHttpHeadersIsFailure) {
55 fetcher()->set_response_code(200); 55 fetcher()->set_response_code(200);
56 56
57 EXPECT_CALL(*this, OnManifestDownloadFailure()); 57 EXPECT_CALL(*this, OnManifestDownloadFailure());
58 58
59 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 59 fetcher()->delegate()->OnURLFetchComplete(fetcher());
60 } 60 }
61 61
62 TEST_F(PaymentManifestDownloaderTest, EmptyHttpHeaderIsFailure) { 62 TEST_F(PaymentMethodManifestDownloaderTest, EmptyHttpHeaderIsFailure) {
63 scoped_refptr<net::HttpResponseHeaders> headers( 63 scoped_refptr<net::HttpResponseHeaders> headers(
64 new net::HttpResponseHeaders(std::string())); 64 new net::HttpResponseHeaders(std::string()));
65 fetcher()->set_response_headers(headers); 65 fetcher()->set_response_headers(headers);
66 fetcher()->set_response_code(200); 66 fetcher()->set_response_code(200);
67 67
68 EXPECT_CALL(*this, OnManifestDownloadFailure()); 68 EXPECT_CALL(*this, OnManifestDownloadFailure());
69 69
70 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 70 fetcher()->delegate()->OnURLFetchComplete(fetcher());
71 } 71 }
72 72
73 TEST_F(PaymentManifestDownloaderTest, EmptyHttpLinkHeaderIsFailure) { 73 TEST_F(PaymentMethodManifestDownloaderTest, EmptyHttpLinkHeaderIsFailure) {
74 scoped_refptr<net::HttpResponseHeaders> headers( 74 scoped_refptr<net::HttpResponseHeaders> headers(
75 new net::HttpResponseHeaders(std::string())); 75 new net::HttpResponseHeaders(std::string()));
76 headers->AddHeader("Link:"); 76 headers->AddHeader("Link:");
77 fetcher()->set_response_headers(headers); 77 fetcher()->set_response_headers(headers);
78 fetcher()->set_response_code(200); 78 fetcher()->set_response_code(200);
79 79
80 EXPECT_CALL(*this, OnManifestDownloadFailure()); 80 EXPECT_CALL(*this, OnManifestDownloadFailure());
81 81
82 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 82 fetcher()->delegate()->OnURLFetchComplete(fetcher());
83 } 83 }
84 84
85 TEST_F(PaymentManifestDownloaderTest, NoRelInHttpLinkHeaderIsFailure) { 85 TEST_F(PaymentMethodManifestDownloaderTest, NoRelInHttpLinkHeaderIsFailure) {
86 scoped_refptr<net::HttpResponseHeaders> headers( 86 scoped_refptr<net::HttpResponseHeaders> headers(
87 new net::HttpResponseHeaders(std::string())); 87 new net::HttpResponseHeaders(std::string()));
88 headers->AddHeader("Link: <manifest.json>"); 88 headers->AddHeader("Link: <manifest.json>");
89 fetcher()->set_response_headers(headers); 89 fetcher()->set_response_headers(headers);
90 fetcher()->set_response_code(200); 90 fetcher()->set_response_code(200);
91 91
92 EXPECT_CALL(*this, OnManifestDownloadFailure()); 92 EXPECT_CALL(*this, OnManifestDownloadFailure());
93 93
94 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 94 fetcher()->delegate()->OnURLFetchComplete(fetcher());
95 } 95 }
96 96
97 TEST_F(PaymentManifestDownloaderTest, NoUrlInHttpLinkHeaderIsFailure) { 97 TEST_F(PaymentMethodManifestDownloaderTest, NoUrlInHttpLinkHeaderIsFailure) {
98 scoped_refptr<net::HttpResponseHeaders> headers( 98 scoped_refptr<net::HttpResponseHeaders> headers(
99 new net::HttpResponseHeaders(std::string())); 99 new net::HttpResponseHeaders(std::string()));
100 headers->AddHeader("Link: rel=payment-method-manifest"); 100 headers->AddHeader("Link: rel=payment-method-manifest");
101 fetcher()->set_response_headers(headers); 101 fetcher()->set_response_headers(headers);
102 fetcher()->set_response_code(200); 102 fetcher()->set_response_code(200);
103 103
104 EXPECT_CALL(*this, OnManifestDownloadFailure()); 104 EXPECT_CALL(*this, OnManifestDownloadFailure());
105 105
106 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 106 fetcher()->delegate()->OnURLFetchComplete(fetcher());
107 } 107 }
108 108
109 TEST_F(PaymentManifestDownloaderTest, NoManifestRellInHttpLinkHeaderIsFailure) { 109 TEST_F(PaymentMethodManifestDownloaderTest,
110 NoManifestRellInHttpLinkHeaderIsFailure) {
110 scoped_refptr<net::HttpResponseHeaders> headers( 111 scoped_refptr<net::HttpResponseHeaders> headers(
111 new net::HttpResponseHeaders(std::string())); 112 new net::HttpResponseHeaders(std::string()));
112 headers->AddHeader("Link: <manifest.json>; rel=web-app-manifest"); 113 headers->AddHeader("Link: <manifest.json>; rel=web-app-manifest");
113 fetcher()->set_response_headers(headers); 114 fetcher()->set_response_headers(headers);
114 fetcher()->set_response_code(200); 115 fetcher()->set_response_code(200);
115 116
116 EXPECT_CALL(*this, OnManifestDownloadFailure()); 117 EXPECT_CALL(*this, OnManifestDownloadFailure());
117 118
118 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 119 fetcher()->delegate()->OnURLFetchComplete(fetcher());
119 } 120 }
120 121
121 TEST_F(PaymentManifestDownloaderTest, HttpGetResponse404IsFailure) { 122 TEST_F(PaymentMethodManifestDownloaderTest, HttpGetResponse404IsFailure) {
122 scoped_refptr<net::HttpResponseHeaders> headers( 123 scoped_refptr<net::HttpResponseHeaders> headers(
123 new net::HttpResponseHeaders(std::string())); 124 new net::HttpResponseHeaders(std::string()));
124 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest"); 125 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest");
125 fetcher()->set_response_headers(headers); 126 fetcher()->set_response_headers(headers);
126 fetcher()->set_response_code(200); 127 fetcher()->set_response_code(200);
127 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 128 fetcher()->delegate()->OnURLFetchComplete(fetcher());
128 fetcher()->set_response_code(404); 129 fetcher()->set_response_code(404);
129 130
130 EXPECT_CALL(*this, OnManifestDownloadFailure()); 131 EXPECT_CALL(*this, OnManifestDownloadFailure());
131 132
132 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 133 fetcher()->delegate()->OnURLFetchComplete(fetcher());
133 } 134 }
134 135
135 TEST_F(PaymentManifestDownloaderTest, EmptyHttpGetResponseIsFailure) { 136 TEST_F(PaymentMethodManifestDownloaderTest, EmptyHttpGetResponseIsFailure) {
136 scoped_refptr<net::HttpResponseHeaders> headers( 137 scoped_refptr<net::HttpResponseHeaders> headers(
137 new net::HttpResponseHeaders(std::string())); 138 new net::HttpResponseHeaders(std::string()));
138 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest"); 139 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest");
139 fetcher()->set_response_headers(headers); 140 fetcher()->set_response_headers(headers);
140 fetcher()->set_response_code(200); 141 fetcher()->set_response_code(200);
141 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 142 fetcher()->delegate()->OnURLFetchComplete(fetcher());
142 fetcher()->set_response_code(200); 143 fetcher()->set_response_code(200);
143 144
144 EXPECT_CALL(*this, OnManifestDownloadFailure()); 145 EXPECT_CALL(*this, OnManifestDownloadFailure());
145 146
146 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 147 fetcher()->delegate()->OnURLFetchComplete(fetcher());
147 } 148 }
148 149
149 TEST_F(PaymentManifestDownloaderTest, NonEmptyHttpGetResponseIsSuccess) { 150 TEST_F(PaymentMethodManifestDownloaderTest, NonEmptyHttpGetResponseIsSuccess) {
150 scoped_refptr<net::HttpResponseHeaders> headers( 151 scoped_refptr<net::HttpResponseHeaders> headers(
151 new net::HttpResponseHeaders(std::string())); 152 new net::HttpResponseHeaders(std::string()));
152 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest"); 153 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest");
153 fetcher()->set_response_headers(headers); 154 fetcher()->set_response_headers(headers);
154 fetcher()->set_response_code(200); 155 fetcher()->set_response_code(200);
155 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 156 fetcher()->delegate()->OnURLFetchComplete(fetcher());
156 fetcher()->SetResponseString("manifest content"); 157 fetcher()->SetResponseString("manifest content");
157 fetcher()->set_response_code(200); 158 fetcher()->set_response_code(200);
158 159
159 EXPECT_CALL(*this, OnManifestDownloadSuccess("manifest content")); 160 EXPECT_CALL(*this, OnManifestDownloadSuccess("manifest content"));
160 161
161 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 162 fetcher()->delegate()->OnURLFetchComplete(fetcher());
162 } 163 }
163 164
164 TEST_F(PaymentManifestDownloaderTest, RelativeHttpHeaderLinkUrl) { 165 TEST_F(PaymentMethodManifestDownloaderTest, RelativeHttpHeaderLinkUrl) {
165 scoped_refptr<net::HttpResponseHeaders> headers( 166 scoped_refptr<net::HttpResponseHeaders> headers(
166 new net::HttpResponseHeaders(std::string())); 167 new net::HttpResponseHeaders(std::string()));
167 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest"); 168 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest");
168 fetcher()->set_response_headers(headers); 169 fetcher()->set_response_headers(headers);
169 fetcher()->set_response_code(200); 170 fetcher()->set_response_code(200);
170 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 171 fetcher()->delegate()->OnURLFetchComplete(fetcher());
171 172
172 EXPECT_EQ("https://bobpay.com/manifest.json", 173 EXPECT_EQ("https://bobpay.com/manifest.json",
173 fetcher()->GetOriginalURL().spec()); 174 fetcher()->GetOriginalURL().spec());
174 } 175 }
175 176
176 TEST_F(PaymentManifestDownloaderTest, AbsoluteHttpsHeaderLinkUrl) { 177 TEST_F(PaymentMethodManifestDownloaderTest, AbsoluteHttpsHeaderLinkUrl) {
177 scoped_refptr<net::HttpResponseHeaders> headers( 178 scoped_refptr<net::HttpResponseHeaders> headers(
178 new net::HttpResponseHeaders(std::string())); 179 new net::HttpResponseHeaders(std::string()));
179 headers->AddHeader( 180 headers->AddHeader(
180 "Link: <https://alicepay.com/manifest.json>; " 181 "Link: <https://alicepay.com/manifest.json>; "
181 "rel=payment-method-manifest"); 182 "rel=payment-method-manifest");
182 fetcher()->set_response_headers(headers); 183 fetcher()->set_response_headers(headers);
183 fetcher()->set_response_code(200); 184 fetcher()->set_response_code(200);
184 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 185 fetcher()->delegate()->OnURLFetchComplete(fetcher());
185 186
186 EXPECT_EQ("https://alicepay.com/manifest.json", 187 EXPECT_EQ("https://alicepay.com/manifest.json",
187 fetcher()->GetOriginalURL().spec()); 188 fetcher()->GetOriginalURL().spec());
188 } 189 }
189 190
190 TEST_F(PaymentManifestDownloaderTest, AbsoluteHttpHeaderLinkUrl) { 191 TEST_F(PaymentMethodManifestDownloaderTest, AbsoluteHttpHeaderLinkUrl) {
191 scoped_refptr<net::HttpResponseHeaders> headers( 192 scoped_refptr<net::HttpResponseHeaders> headers(
192 new net::HttpResponseHeaders(std::string())); 193 new net::HttpResponseHeaders(std::string()));
193 headers->AddHeader( 194 headers->AddHeader(
194 "Link: <http://alicepay.com/manifest.json>; " 195 "Link: <http://alicepay.com/manifest.json>; "
195 "rel=payment-method-manifest"); 196 "rel=payment-method-manifest");
196 fetcher()->set_response_headers(headers); 197 fetcher()->set_response_headers(headers);
197 fetcher()->set_response_code(200); 198 fetcher()->set_response_code(200);
198 199
199 EXPECT_CALL(*this, OnManifestDownloadFailure()); 200 EXPECT_CALL(*this, OnManifestDownloadFailure());
200 201
201 fetcher()->delegate()->OnURLFetchComplete(fetcher()); 202 fetcher()->delegate()->OnURLFetchComplete(fetcher());
202 } 203 }
203 204
205 class WebAppManifestDownloaderTest
206 : public testing::Test,
207 public PaymentManifestDownloader::Delegate {
208 public:
209 WebAppManifestDownloaderTest()
210 : context_(new net::TestURLRequestContextGetter(
211 base::ThreadTaskRunnerHandle::Get())),
212 downloader_(context_, GURL("https://bobpay.com"), this) {
213 downloader_.DownloadWebAppManifest();
214 }
215
216 ~WebAppManifestDownloaderTest() override {}
217
218 // PaymentManifestDownloader::Delegate
219 MOCK_METHOD1(OnManifestDownloadSuccess, void(const std::string& content));
220 MOCK_METHOD0(OnManifestDownloadFailure, void());
221
222 net::TestURLFetcher* fetcher() { return factory_.GetFetcherByID(0); }
223
224 private:
225 content::TestBrowserThreadBundle thread_bundle_;
226 net::TestURLFetcherFactory factory_;
227 scoped_refptr<net::TestURLRequestContextGetter> context_;
228 PaymentManifestDownloader downloader_;
229
230 DISALLOW_COPY_AND_ASSIGN(WebAppManifestDownloaderTest);
231 };
232
233 TEST_F(WebAppManifestDownloaderTest, HttpGetResponse404IsFailure) {
234 fetcher()->set_response_code(404);
235
236 EXPECT_CALL(*this, OnManifestDownloadFailure());
237
238 fetcher()->delegate()->OnURLFetchComplete(fetcher());
239 }
240
241 TEST_F(WebAppManifestDownloaderTest, EmptyHttpGetResponseIsFailure) {
242 fetcher()->set_response_code(200);
243
244 EXPECT_CALL(*this, OnManifestDownloadFailure());
245
246 fetcher()->delegate()->OnURLFetchComplete(fetcher());
247 }
248
249 TEST_F(WebAppManifestDownloaderTest, NonEmptyHttpGetResponseIsSuccess) {
250 fetcher()->SetResponseString("manifest content");
251 fetcher()->set_response_code(200);
252
253 EXPECT_CALL(*this, OnManifestDownloadSuccess("manifest content"));
254
255 fetcher()->delegate()->OnURLFetchComplete(fetcher());
256 }
257
204 } // namespace 258 } // namespace
205 } // namespace payments 259 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698