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

Side by Side Diff: components/payments/content/android/payment_manifest_downloader_test.cc

Issue 2645813006: Download web payment manifests. (Closed)
Patch Set: At most INT_MAX sections in manifest and fingperints in section Created 3 years, 9 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
Mathieu 2017/03/03 19:42:09 if it's a unittest the file name should end with _
please use gerrit instead 2017/03/09 18:05:33 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/payments/content/android/payment_manifest_downloader.h"
6
7 #include "base/threading/thread_task_runner_handle.h"
8 #include "content/public/test/test_browser_thread_bundle.h"
9 #include "net/http/http_response_headers.h"
10 #include "net/url_request/test_url_fetcher_factory.h"
11 #include "net/url_request/url_request_test_util.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace payments {
16 namespace {
17
18 class PaymentManifestDownloaderTest
19 : public testing::Test,
20 public PaymentManifestDownloader::Delegate {
21 public:
22 PaymentManifestDownloaderTest()
23 : context_(new net::TestURLRequestContextGetter(
24 base::ThreadTaskRunnerHandle::Get())),
25 downloader_(context_, GURL("https://bobpay.com"), this) {
26 downloader_.Download();
27 }
28
29 ~PaymentManifestDownloaderTest() override {}
30
31 // PaymentManifestDownloader::Delegate
32 MOCK_METHOD1(OnManifestDownloadSuccess, void(const std::string& content));
33 MOCK_METHOD0(OnManifestDownloadFailure, void());
34
35 net::TestURLFetcher* fetcher() { return factory_.GetFetcherByID(0); }
36
37 private:
38 content::TestBrowserThreadBundle thread_bundle_;
39 net::TestURLFetcherFactory factory_;
40 scoped_refptr<net::TestURLRequestContextGetter> context_;
41 PaymentManifestDownloader downloader_;
42
43 DISALLOW_COPY_AND_ASSIGN(PaymentManifestDownloaderTest);
44 };
45
46 TEST_F(PaymentManifestDownloaderTest, HttpHeadResponse404IsFailure) {
47 fetcher()->set_response_code(404);
48
49 EXPECT_CALL(*this, OnManifestDownloadFailure());
50
51 fetcher()->delegate()->OnURLFetchComplete(fetcher());
52 }
53
54 TEST_F(PaymentManifestDownloaderTest, NoHttpHeadersIsFailure) {
55 fetcher()->set_response_code(200);
56
57 EXPECT_CALL(*this, OnManifestDownloadFailure());
58
59 fetcher()->delegate()->OnURLFetchComplete(fetcher());
60 }
61
62 TEST_F(PaymentManifestDownloaderTest, EmptyHttpHeaderIsFailure) {
63 scoped_refptr<net::HttpResponseHeaders> headers(
64 new net::HttpResponseHeaders(std::string()));
65 fetcher()->set_response_headers(headers);
66 fetcher()->set_response_code(200);
67
68 EXPECT_CALL(*this, OnManifestDownloadFailure());
69
70 fetcher()->delegate()->OnURLFetchComplete(fetcher());
71 }
72
73 TEST_F(PaymentManifestDownloaderTest, EmptyHttpLinkHeaderIsFailure) {
74 scoped_refptr<net::HttpResponseHeaders> headers(
75 new net::HttpResponseHeaders(std::string()));
76 headers->AddHeader("Link:");
77 fetcher()->set_response_headers(headers);
78 fetcher()->set_response_code(200);
79
80 EXPECT_CALL(*this, OnManifestDownloadFailure());
81
82 fetcher()->delegate()->OnURLFetchComplete(fetcher());
83 }
84
85 TEST_F(PaymentManifestDownloaderTest, NoRelInHttpLinkHeaderIsFailure) {
86 scoped_refptr<net::HttpResponseHeaders> headers(
87 new net::HttpResponseHeaders(std::string()));
88 headers->AddHeader("Link: <manifest.json>");
89 fetcher()->set_response_headers(headers);
90 fetcher()->set_response_code(200);
91
92 EXPECT_CALL(*this, OnManifestDownloadFailure());
93
94 fetcher()->delegate()->OnURLFetchComplete(fetcher());
95 }
96
97 TEST_F(PaymentManifestDownloaderTest, NoUrlInHttpLinkHeaderIsFailure) {
98 scoped_refptr<net::HttpResponseHeaders> headers(
99 new net::HttpResponseHeaders(std::string()));
100 headers->AddHeader("Link: rel=payment-method-manifest");
101 fetcher()->set_response_headers(headers);
102 fetcher()->set_response_code(200);
103
104 EXPECT_CALL(*this, OnManifestDownloadFailure());
105
106 fetcher()->delegate()->OnURLFetchComplete(fetcher());
107 }
108
109 TEST_F(PaymentManifestDownloaderTest, NoManifestRellInHttpLinkHeaderIsFailure) {
110 scoped_refptr<net::HttpResponseHeaders> headers(
111 new net::HttpResponseHeaders(std::string()));
112 headers->AddHeader("Link: <manifest.json>; rel=web-app-manifest");
113 fetcher()->set_response_headers(headers);
114 fetcher()->set_response_code(200);
115
116 EXPECT_CALL(*this, OnManifestDownloadFailure());
117
118 fetcher()->delegate()->OnURLFetchComplete(fetcher());
119 }
120
121 TEST_F(PaymentManifestDownloaderTest, HttpGetResponse404IsFailure) {
122 scoped_refptr<net::HttpResponseHeaders> headers(
123 new net::HttpResponseHeaders(std::string()));
124 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest");
125 fetcher()->set_response_headers(headers);
126 fetcher()->set_response_code(200);
127 fetcher()->delegate()->OnURLFetchComplete(fetcher());
128 fetcher()->set_response_code(404);
129
130 EXPECT_CALL(*this, OnManifestDownloadFailure());
131
132 fetcher()->delegate()->OnURLFetchComplete(fetcher());
133 }
134
135 TEST_F(PaymentManifestDownloaderTest, EmptyHttpGetResponseIsFailure) {
136 scoped_refptr<net::HttpResponseHeaders> headers(
137 new net::HttpResponseHeaders(std::string()));
138 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest");
139 fetcher()->set_response_headers(headers);
140 fetcher()->set_response_code(200);
141 fetcher()->delegate()->OnURLFetchComplete(fetcher());
142 fetcher()->set_response_code(200);
143
144 EXPECT_CALL(*this, OnManifestDownloadFailure());
145
146 fetcher()->delegate()->OnURLFetchComplete(fetcher());
147 }
148
149 TEST_F(PaymentManifestDownloaderTest, NonEmptyHttpGetResponseIsSuccess) {
150 scoped_refptr<net::HttpResponseHeaders> headers(
151 new net::HttpResponseHeaders(std::string()));
152 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest");
153 fetcher()->set_response_headers(headers);
154 fetcher()->set_response_code(200);
155 fetcher()->delegate()->OnURLFetchComplete(fetcher());
156 fetcher()->SetResponseString("manifest content");
157 fetcher()->set_response_code(200);
158
159 EXPECT_CALL(*this, OnManifestDownloadSuccess("manifest content"));
160
161 fetcher()->delegate()->OnURLFetchComplete(fetcher());
162 }
163
164 TEST_F(PaymentManifestDownloaderTest, RelativeHttpHeaderLinkUrl) {
165 scoped_refptr<net::HttpResponseHeaders> headers(
166 new net::HttpResponseHeaders(std::string()));
167 headers->AddHeader("Link: <manifest.json>; rel=payment-method-manifest");
168 fetcher()->set_response_headers(headers);
169 fetcher()->set_response_code(200);
170 fetcher()->delegate()->OnURLFetchComplete(fetcher());
171
172 EXPECT_EQ("https://bobpay.com/manifest.json",
173 fetcher()->GetOriginalURL().spec());
174 }
175
176 TEST_F(PaymentManifestDownloaderTest, AbsoluteHttpsHeaderLinkUrl) {
177 scoped_refptr<net::HttpResponseHeaders> headers(
178 new net::HttpResponseHeaders(std::string()));
179 headers->AddHeader(
180 "Link: <https://alicepay.com/manifest.json>; "
181 "rel=payment-method-manifest");
182 fetcher()->set_response_headers(headers);
183 fetcher()->set_response_code(200);
184 fetcher()->delegate()->OnURLFetchComplete(fetcher());
185
186 EXPECT_EQ("https://alicepay.com/manifest.json",
187 fetcher()->GetOriginalURL().spec());
188 }
189
190 TEST_F(PaymentManifestDownloaderTest, AbsoluteHttpHeaderLinkUrl) {
191 scoped_refptr<net::HttpResponseHeaders> headers(
192 new net::HttpResponseHeaders(std::string()));
193 headers->AddHeader(
194 "Link: <http://alicepay.com/manifest.json>; "
195 "rel=payment-method-manifest");
196 fetcher()->set_response_headers(headers);
197 fetcher()->set_response_code(200);
198
199 EXPECT_CALL(*this, OnManifestDownloadFailure());
200
201 fetcher()->delegate()->OnURLFetchComplete(fetcher());
202 }
203
204 } // namespace
205 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698