OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "components/component_updater/request_sender.h" | 10 #include "components/update_client/request_sender.h" |
11 #include "components/component_updater/test/test_configurator.h" | 11 #include "components/update_client/test/test_configurator.h" |
12 #include "components/component_updater/test/url_request_post_interceptor.h" | 12 #include "components/update_client/test/url_request_post_interceptor.h" |
13 #include "net/url_request/url_fetcher.h" | 13 #include "net/url_request/url_fetcher.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace component_updater { | 16 namespace update_client { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const char kUrl1[] = "https://localhost2/path1"; | 20 const char kUrl1[] = "https://localhost2/path1"; |
21 const char kUrl2[] = "https://localhost2/path2"; | 21 const char kUrl2[] = "https://localhost2/path2"; |
22 const char kUrlPath1[] = "path1"; | 22 const char kUrlPath1[] = "path1"; |
23 const char kUrlPath2[] = "path2"; | 23 const char kUrlPath2[] = "path2"; |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 // Tests that when a request to the first url succeeds, the subsequent urls are | 122 // Tests that when a request to the first url succeeds, the subsequent urls are |
123 // not tried. | 123 // not tried. |
124 TEST_F(RequestSenderTest, RequestSendSuccess) { | 124 TEST_F(RequestSenderTest, RequestSendSuccess) { |
125 EXPECT_TRUE(post_interceptor_1->ExpectRequest(new PartialMatch("test"))); | 125 EXPECT_TRUE(post_interceptor_1->ExpectRequest(new PartialMatch("test"))); |
126 | 126 |
127 std::vector<GURL> urls; | 127 std::vector<GURL> urls; |
128 urls.push_back(GURL(kUrl1)); | 128 urls.push_back(GURL(kUrl1)); |
129 urls.push_back(GURL(kUrl2)); | 129 urls.push_back(GURL(kUrl2)); |
130 request_sender_.reset(new RequestSender(*config_)); | 130 request_sender_.reset(new RequestSender(*config_)); |
131 request_sender_->Send("test", | 131 request_sender_->Send("test", urls, |
132 urls, | |
133 base::Bind(&RequestSenderTest::RequestSenderComplete, | 132 base::Bind(&RequestSenderTest::RequestSenderComplete, |
134 base::Unretained(this))); | 133 base::Unretained(this))); |
135 RunThreads(); | 134 RunThreads(); |
136 | 135 |
137 EXPECT_EQ(1, post_interceptor_1->GetHitCount()) | 136 EXPECT_EQ(1, post_interceptor_1->GetHitCount()) |
138 << post_interceptor_1->GetRequestsAsString(); | 137 << post_interceptor_1->GetRequestsAsString(); |
139 EXPECT_EQ(1, post_interceptor_1->GetCount()) | 138 EXPECT_EQ(1, post_interceptor_1->GetCount()) |
140 << post_interceptor_1->GetRequestsAsString(); | 139 << post_interceptor_1->GetRequestsAsString(); |
141 | 140 |
142 EXPECT_STREQ("test", post_interceptor_1->GetRequests()[0].c_str()); | 141 EXPECT_STREQ("test", post_interceptor_1->GetRequests()[0].c_str()); |
143 EXPECT_EQ(GURL(kUrl1), url_fetcher_source_->GetOriginalURL()); | 142 EXPECT_EQ(GURL(kUrl1), url_fetcher_source_->GetOriginalURL()); |
144 EXPECT_EQ(200, url_fetcher_source_->GetResponseCode()); | 143 EXPECT_EQ(200, url_fetcher_source_->GetResponseCode()); |
145 } | 144 } |
146 | 145 |
147 // Tests that the request succeeds using the second url after the first url | 146 // Tests that the request succeeds using the second url after the first url |
148 // has failed. | 147 // has failed. |
149 TEST_F(RequestSenderTest, RequestSendSuccessWithFallback) { | 148 TEST_F(RequestSenderTest, RequestSendSuccessWithFallback) { |
150 EXPECT_TRUE(post_interceptor_1->ExpectRequest(new PartialMatch("test"), 403)); | 149 EXPECT_TRUE(post_interceptor_1->ExpectRequest(new PartialMatch("test"), 403)); |
151 EXPECT_TRUE(post_interceptor_2->ExpectRequest(new PartialMatch("test"))); | 150 EXPECT_TRUE(post_interceptor_2->ExpectRequest(new PartialMatch("test"))); |
152 | 151 |
153 std::vector<GURL> urls; | 152 std::vector<GURL> urls; |
154 urls.push_back(GURL(kUrl1)); | 153 urls.push_back(GURL(kUrl1)); |
155 urls.push_back(GURL(kUrl2)); | 154 urls.push_back(GURL(kUrl2)); |
156 request_sender_.reset(new RequestSender(*config_)); | 155 request_sender_.reset(new RequestSender(*config_)); |
157 request_sender_->Send("test", | 156 request_sender_->Send("test", urls, |
158 urls, | |
159 base::Bind(&RequestSenderTest::RequestSenderComplete, | 157 base::Bind(&RequestSenderTest::RequestSenderComplete, |
160 base::Unretained(this))); | 158 base::Unretained(this))); |
161 RunThreads(); | 159 RunThreads(); |
162 | 160 |
163 EXPECT_EQ(1, post_interceptor_1->GetHitCount()) | 161 EXPECT_EQ(1, post_interceptor_1->GetHitCount()) |
164 << post_interceptor_1->GetRequestsAsString(); | 162 << post_interceptor_1->GetRequestsAsString(); |
165 EXPECT_EQ(1, post_interceptor_1->GetCount()) | 163 EXPECT_EQ(1, post_interceptor_1->GetCount()) |
166 << post_interceptor_1->GetRequestsAsString(); | 164 << post_interceptor_1->GetRequestsAsString(); |
167 EXPECT_EQ(1, post_interceptor_2->GetHitCount()) | 165 EXPECT_EQ(1, post_interceptor_2->GetHitCount()) |
168 << post_interceptor_2->GetRequestsAsString(); | 166 << post_interceptor_2->GetRequestsAsString(); |
169 EXPECT_EQ(1, post_interceptor_2->GetCount()) | 167 EXPECT_EQ(1, post_interceptor_2->GetCount()) |
170 << post_interceptor_2->GetRequestsAsString(); | 168 << post_interceptor_2->GetRequestsAsString(); |
171 | 169 |
172 EXPECT_STREQ("test", post_interceptor_1->GetRequests()[0].c_str()); | 170 EXPECT_STREQ("test", post_interceptor_1->GetRequests()[0].c_str()); |
173 EXPECT_STREQ("test", post_interceptor_2->GetRequests()[0].c_str()); | 171 EXPECT_STREQ("test", post_interceptor_2->GetRequests()[0].c_str()); |
174 EXPECT_EQ(GURL(kUrl2), url_fetcher_source_->GetOriginalURL()); | 172 EXPECT_EQ(GURL(kUrl2), url_fetcher_source_->GetOriginalURL()); |
175 EXPECT_EQ(200, url_fetcher_source_->GetResponseCode()); | 173 EXPECT_EQ(200, url_fetcher_source_->GetResponseCode()); |
176 } | 174 } |
177 | 175 |
178 // Tests that the request fails when both urls have failed. | 176 // Tests that the request fails when both urls have failed. |
179 TEST_F(RequestSenderTest, RequestSendFailed) { | 177 TEST_F(RequestSenderTest, RequestSendFailed) { |
180 EXPECT_TRUE(post_interceptor_1->ExpectRequest(new PartialMatch("test"), 403)); | 178 EXPECT_TRUE(post_interceptor_1->ExpectRequest(new PartialMatch("test"), 403)); |
181 EXPECT_TRUE(post_interceptor_2->ExpectRequest(new PartialMatch("test"), 403)); | 179 EXPECT_TRUE(post_interceptor_2->ExpectRequest(new PartialMatch("test"), 403)); |
182 | 180 |
183 std::vector<GURL> urls; | 181 std::vector<GURL> urls; |
184 urls.push_back(GURL(kUrl1)); | 182 urls.push_back(GURL(kUrl1)); |
185 urls.push_back(GURL(kUrl2)); | 183 urls.push_back(GURL(kUrl2)); |
186 request_sender_.reset(new RequestSender(*config_)); | 184 request_sender_.reset(new RequestSender(*config_)); |
187 request_sender_->Send("test", | 185 request_sender_->Send("test", urls, |
188 urls, | |
189 base::Bind(&RequestSenderTest::RequestSenderComplete, | 186 base::Bind(&RequestSenderTest::RequestSenderComplete, |
190 base::Unretained(this))); | 187 base::Unretained(this))); |
191 RunThreads(); | 188 RunThreads(); |
192 | 189 |
193 EXPECT_EQ(1, post_interceptor_1->GetHitCount()) | 190 EXPECT_EQ(1, post_interceptor_1->GetHitCount()) |
194 << post_interceptor_1->GetRequestsAsString(); | 191 << post_interceptor_1->GetRequestsAsString(); |
195 EXPECT_EQ(1, post_interceptor_1->GetCount()) | 192 EXPECT_EQ(1, post_interceptor_1->GetCount()) |
196 << post_interceptor_1->GetRequestsAsString(); | 193 << post_interceptor_1->GetRequestsAsString(); |
197 EXPECT_EQ(1, post_interceptor_2->GetHitCount()) | 194 EXPECT_EQ(1, post_interceptor_2->GetHitCount()) |
198 << post_interceptor_2->GetRequestsAsString(); | 195 << post_interceptor_2->GetRequestsAsString(); |
199 EXPECT_EQ(1, post_interceptor_2->GetCount()) | 196 EXPECT_EQ(1, post_interceptor_2->GetCount()) |
200 << post_interceptor_2->GetRequestsAsString(); | 197 << post_interceptor_2->GetRequestsAsString(); |
201 | 198 |
202 EXPECT_STREQ("test", post_interceptor_1->GetRequests()[0].c_str()); | 199 EXPECT_STREQ("test", post_interceptor_1->GetRequests()[0].c_str()); |
203 EXPECT_STREQ("test", post_interceptor_2->GetRequests()[0].c_str()); | 200 EXPECT_STREQ("test", post_interceptor_2->GetRequests()[0].c_str()); |
204 EXPECT_EQ(GURL(kUrl2), url_fetcher_source_->GetOriginalURL()); | 201 EXPECT_EQ(GURL(kUrl2), url_fetcher_source_->GetOriginalURL()); |
205 EXPECT_EQ(403, url_fetcher_source_->GetResponseCode()); | 202 EXPECT_EQ(403, url_fetcher_source_->GetResponseCode()); |
206 } | 203 } |
207 | 204 |
208 } // namespace component_updater | 205 } // namespace update_client |
OLD | NEW |