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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 return crx_update_item; | 154 return crx_update_item; |
155 } | 155 } |
156 | 156 |
157 TEST_F(UpdateCheckerTest, UpdateCheckSuccess) { | 157 TEST_F(UpdateCheckerTest, UpdateCheckSuccess) { |
158 EXPECT_TRUE(post_interceptor_->ExpectRequest( | 158 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
159 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); | 159 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); |
160 | 160 |
161 update_checker_ = UpdateChecker::Create(config_); | 161 update_checker_ = UpdateChecker::Create(config_); |
162 | 162 |
163 CrxUpdateItem item(BuildCrxUpdateItem()); | 163 CrxUpdateItem item(BuildCrxUpdateItem()); |
| 164 item.component.ap = "some_ap"; |
164 std::vector<CrxUpdateItem*> items_to_check; | 165 std::vector<CrxUpdateItem*> items_to_check; |
165 items_to_check.push_back(&item); | 166 items_to_check.push_back(&item); |
166 | 167 |
167 update_checker_->CheckForUpdates( | 168 update_checker_->CheckForUpdates( |
168 items_to_check, "extra=\"params\"", | 169 items_to_check, "extra=\"params\"", |
169 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, | 170 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
170 base::Unretained(this))); | 171 base::Unretained(this))); |
171 | 172 |
172 RunThreads(); | 173 RunThreads(); |
173 | 174 |
174 EXPECT_EQ(1, post_interceptor_->GetHitCount()) | 175 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
175 << post_interceptor_->GetRequestsAsString(); | 176 << post_interceptor_->GetRequestsAsString(); |
176 ASSERT_EQ(1, post_interceptor_->GetCount()) | 177 ASSERT_EQ(1, post_interceptor_->GetCount()) |
177 << post_interceptor_->GetRequestsAsString(); | 178 << post_interceptor_->GetRequestsAsString(); |
178 | 179 |
179 // Sanity check the request. | 180 // Sanity check the request. |
180 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( | 181 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
181 "request protocol=\"3.0\" extra=\"params\"")); | 182 "request protocol=\"3.0\" extra=\"params\"")); |
182 // The request must not contain any "dlpref" in the default case. | 183 // The request must not contain any "dlpref" in the default case. |
183 EXPECT_EQ(string::npos, | 184 EXPECT_EQ(string::npos, |
184 post_interceptor_->GetRequests()[0].find(" dlpref=\"")); | 185 post_interceptor_->GetRequests()[0].find(" dlpref=\"")); |
185 EXPECT_NE( | 186 EXPECT_NE( |
186 string::npos, | 187 string::npos, |
187 post_interceptor_->GetRequests()[0].find( | 188 post_interceptor_->GetRequests()[0].find( |
188 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " | 189 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " |
189 "brand=\"TEST\"><updatecheck />" | 190 "brand=\"TEST\" ap=\"some_ap\"><updatecheck />" |
190 "<packages><package fp=\"fp1\"/></packages></app>")); | 191 "<packages><package fp=\"fp1\"/></packages></app>")); |
191 | 192 |
192 EXPECT_NE(string::npos, | 193 EXPECT_NE(string::npos, |
193 post_interceptor_->GetRequests()[0].find("<hw physmemory=")); | 194 post_interceptor_->GetRequests()[0].find("<hw physmemory=")); |
194 | 195 |
195 // Sanity check the arguments of the callback after parsing. | 196 // Sanity check the arguments of the callback after parsing. |
196 EXPECT_EQ(0, error_); | 197 EXPECT_EQ(0, error_); |
197 EXPECT_EQ(1ul, results_.list.size()); | 198 EXPECT_EQ(1ul, results_.list.size()); |
198 EXPECT_STREQ("jebgalgnebhfojomionfpkfelancnnkf", | 199 EXPECT_STREQ("jebgalgnebhfojomionfpkfelancnnkf", |
199 results_.list[0].extension_id.c_str()); | 200 results_.list[0].extension_id.c_str()); |
200 EXPECT_STREQ("1.0", results_.list[0].manifest.version.c_str()); | 201 EXPECT_STREQ("1.0", results_.list[0].manifest.version.c_str()); |
201 } | 202 } |
202 | 203 |
| 204 // Tests that an invalid "ap" is not serialized. |
| 205 TEST_F(UpdateCheckerTest, UpdateCheckInvalidAp) { |
| 206 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
| 207 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 208 |
| 209 update_checker_ = UpdateChecker::Create(config_); |
| 210 |
| 211 CrxUpdateItem item(BuildCrxUpdateItem()); |
| 212 item.component.ap = std::string(257, 'a'); // Too long. |
| 213 std::vector<CrxUpdateItem*> items_to_check; |
| 214 items_to_check.push_back(&item); |
| 215 |
| 216 update_checker_->CheckForUpdates( |
| 217 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
| 218 base::Unretained(this))); |
| 219 |
| 220 RunThreads(); |
| 221 |
| 222 EXPECT_NE( |
| 223 string::npos, |
| 224 post_interceptor_->GetRequests()[0].find( |
| 225 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " |
| 226 "brand=\"TEST\"><updatecheck />" |
| 227 "<packages><package fp=\"fp1\"/></packages></app>")); |
| 228 } |
| 229 |
203 TEST_F(UpdateCheckerTest, UpdateCheckSuccessNoBrand) { | 230 TEST_F(UpdateCheckerTest, UpdateCheckSuccessNoBrand) { |
204 EXPECT_TRUE(post_interceptor_->ExpectRequest( | 231 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
205 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); | 232 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); |
206 | 233 |
207 config_->SetBrand("TOOLONG"); // Sets an invalid brand code. | 234 config_->SetBrand("TOOLONG"); // Sets an invalid brand code. |
208 update_checker_ = UpdateChecker::Create(config_); | 235 update_checker_ = UpdateChecker::Create(config_); |
209 | 236 |
210 CrxUpdateItem item(BuildCrxUpdateItem()); | 237 CrxUpdateItem item(BuildCrxUpdateItem()); |
211 std::vector<CrxUpdateItem*> items_to_check; | 238 std::vector<CrxUpdateItem*> items_to_check; |
212 items_to_check.push_back(&item); | 239 items_to_check.push_back(&item); |
213 | 240 |
214 update_checker_->CheckForUpdates( | 241 update_checker_->CheckForUpdates( |
215 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, | 242 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
216 base::Unretained(this))); | 243 base::Unretained(this))); |
217 | 244 |
218 RunThreads(); | 245 RunThreads(); |
219 | 246 |
220 EXPECT_NE( | 247 EXPECT_NE( |
221 string::npos, | 248 string::npos, |
222 post_interceptor_->GetRequests()[0].find( | 249 post_interceptor_->GetRequests()[0].find( |
223 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" | 250 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
224 "<updatecheck /><packages><package fp=\"fp1\"/></packages></app>")); | 251 "<updatecheck /><packages><package fp=\"fp1\"/></packages></app>")); |
225 } | 252 } |
226 | 253 |
227 // Simulates a 403 server response error. | 254 // Simulates a 403 server response error. |
228 TEST_F(UpdateCheckerTest, UpdateCheckError) { | 255 TEST_F(UpdateCheckerTest, UpdateCheckError) { |
229 EXPECT_TRUE( | 256 EXPECT_TRUE( |
230 post_interceptor_->ExpectRequest(new PartialMatch("updatecheck"), 403)); | 257 post_interceptor_->ExpectRequest(new PartialMatch("updatecheck"), 403)); |
231 | 258 |
232 update_checker_ = UpdateChecker::Create(config_); | 259 update_checker_ = UpdateChecker::Create(config_); |
233 | 260 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 322 |
296 EXPECT_EQ(1, post_interceptor_->GetHitCount()) | 323 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
297 << post_interceptor_->GetRequestsAsString(); | 324 << post_interceptor_->GetRequestsAsString(); |
298 ASSERT_EQ(1, post_interceptor_->GetCount()) | 325 ASSERT_EQ(1, post_interceptor_->GetCount()) |
299 << post_interceptor_->GetRequestsAsString(); | 326 << post_interceptor_->GetRequestsAsString(); |
300 | 327 |
301 // Sanity check the request. | 328 // Sanity check the request. |
302 EXPECT_NE( | 329 EXPECT_NE( |
303 string::npos, | 330 string::npos, |
304 post_interceptor_->GetRequests()[0].find( | 331 post_interceptor_->GetRequests()[0].find( |
305 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " | 332 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " |
306 "brand=\"TEST\"><updatecheck />" | 333 "brand=\"TEST\"><updatecheck />" |
307 "<packages><package fp=\"fp1\"/></packages></app>")); | 334 "<packages><package fp=\"fp1\"/></packages></app>")); |
308 | 335 |
309 // Expect an error since the response is not trusted. | 336 // Expect an error since the response is not trusted. |
310 EXPECT_EQ(-10000, error_); | 337 EXPECT_EQ(-10000, error_); |
311 EXPECT_EQ(0ul, results_.list.size()); | 338 EXPECT_EQ(0ul, results_.list.size()); |
312 } | 339 } |
313 | 340 |
314 // Tests that the UpdateCheckers will not make an update check for a | 341 // Tests that the UpdateCheckers will not make an update check for a |
315 // component that requires encryption when the update check URL is unsecure. | 342 // component that requires encryption when the update check URL is unsecure. |
(...skipping 10 matching lines...) Expand all Loading... |
326 update_checker_->CheckForUpdates( | 353 update_checker_->CheckForUpdates( |
327 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, | 354 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
328 base::Unretained(this))); | 355 base::Unretained(this))); |
329 RunThreads(); | 356 RunThreads(); |
330 | 357 |
331 EXPECT_EQ(-1, error_); | 358 EXPECT_EQ(-1, error_); |
332 EXPECT_EQ(0u, results_.list.size()); | 359 EXPECT_EQ(0u, results_.list.size()); |
333 } | 360 } |
334 | 361 |
335 } // namespace update_client | 362 } // namespace update_client |
OLD | NEW |