OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" | 5 #include "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/component_updater/test/test_installer.h" | 12 #include "chrome/browser/component_updater/test/test_installer.h" |
13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #include "content/test/net/url_request_prepackaged_interceptor.h" | |
16 #include "libxml/globals.h" | 15 #include "libxml/globals.h" |
17 #include "net/base/upload_bytes_element_reader.h" | 16 #include "net/base/upload_bytes_element_reader.h" |
18 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
19 #include "url/gurl.h" | 18 #include "url/gurl.h" |
20 | 19 |
21 using content::BrowserThread; | 20 using content::BrowserThread; |
22 | 21 |
23 using ::testing::_; | 22 using ::testing::_; |
24 using ::testing::InSequence; | 23 using ::testing::InSequence; |
25 using ::testing::Mock; | 24 using ::testing::Mock; |
26 | 25 |
27 namespace component_updater { | 26 namespace component_updater { |
28 | 27 |
| 28 #define POST_INTERCEPT_SCHEME "http" |
| 29 #define POST_INTERCEPT_HOSTNAME "localhost2" |
| 30 #define POST_INTERCEPT_PATH "/update2" |
| 31 |
29 MockComponentObserver::MockComponentObserver() { | 32 MockComponentObserver::MockComponentObserver() { |
30 } | 33 } |
31 | 34 |
32 MockComponentObserver::~MockComponentObserver() { | 35 MockComponentObserver::~MockComponentObserver() { |
33 } | 36 } |
34 | 37 |
35 TestConfigurator::TestConfigurator() | 38 TestConfigurator::TestConfigurator() |
36 : times_(1), | 39 : times_(1), |
37 recheck_time_(0), | 40 recheck_time_(0), |
38 ondemand_time_(0), | 41 ondemand_time_(0), |
(...skipping 29 matching lines...) Expand all Loading... |
68 | 71 |
69 int TestConfigurator::MinimumReCheckWait() { | 72 int TestConfigurator::MinimumReCheckWait() { |
70 return recheck_time_; | 73 return recheck_time_; |
71 } | 74 } |
72 | 75 |
73 int TestConfigurator::OnDemandDelay() { | 76 int TestConfigurator::OnDemandDelay() { |
74 return ondemand_time_; | 77 return ondemand_time_; |
75 } | 78 } |
76 | 79 |
77 GURL TestConfigurator::UpdateUrl() { | 80 GURL TestConfigurator::UpdateUrl() { |
78 return GURL("http://localhost/upd"); | 81 return GURL(POST_INTERCEPT_SCHEME "://" |
| 82 POST_INTERCEPT_HOSTNAME POST_INTERCEPT_PATH); |
79 } | 83 } |
80 | 84 |
81 GURL TestConfigurator::PingUrl() { | 85 GURL TestConfigurator::PingUrl() { |
82 return GURL("http://localhost2/update2"); | 86 return UpdateUrl(); |
83 } | 87 } |
84 | 88 |
85 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; } | 89 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; } |
86 | 90 |
87 size_t TestConfigurator::UrlSizeLimit() { return 256; } | 91 size_t TestConfigurator::UrlSizeLimit() { return 256; } |
88 | 92 |
89 net::URLRequestContextGetter* TestConfigurator::RequestContext() { | 93 net::URLRequestContextGetter* TestConfigurator::RequestContext() { |
90 return context_.get(); | 94 return context_.get(); |
91 } | 95 } |
92 | 96 |
(...skipping 22 matching lines...) Expand all Loading... |
115 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { | 119 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { |
116 cus_ = cus; | 120 cus_ = cus; |
117 } | 121 } |
118 | 122 |
119 void TestConfigurator::SetQuitClosure(const base::Closure& quit_closure) { | 123 void TestConfigurator::SetQuitClosure(const base::Closure& quit_closure) { |
120 quit_closure_ = quit_closure; | 124 quit_closure_ = quit_closure; |
121 } | 125 } |
122 | 126 |
123 | 127 |
124 InterceptorFactory::InterceptorFactory() | 128 InterceptorFactory::InterceptorFactory() |
125 : URLRequestPostInterceptorFactory("http", "localhost2") {} | 129 : URLRequestPostInterceptorFactory(POST_INTERCEPT_SCHEME, |
| 130 POST_INTERCEPT_HOSTNAME) {} |
126 | 131 |
127 InterceptorFactory::~InterceptorFactory() {} | 132 InterceptorFactory::~InterceptorFactory() {} |
128 | 133 |
129 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptor() { | 134 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptor() { |
130 return URLRequestPostInterceptorFactory::CreateInterceptor("/update2"); | 135 return URLRequestPostInterceptorFactory::CreateInterceptor( |
| 136 base::FilePath::FromUTF8Unsafe(POST_INTERCEPT_PATH)); |
131 } | 137 } |
132 | 138 |
133 class PartialMatch : public URLRequestPostInterceptor::RequestMatcher { | 139 class PartialMatch : public URLRequestPostInterceptor::RequestMatcher { |
134 public: | 140 public: |
135 explicit PartialMatch(const std::string& expected) : expected_(expected) {} | 141 explicit PartialMatch(const std::string& expected) : expected_(expected) {} |
136 virtual bool Match(const std::string& actual) const OVERRIDE { | 142 virtual bool Match(const std::string& actual) const OVERRIDE { |
137 return actual.find(expected_) != std::string::npos; | 143 return actual.find(expected_) != std::string::npos; |
138 } | 144 } |
139 | 145 |
140 private: | 146 private: |
(...skipping 15 matching lines...) Expand all Loading... |
156 test_data_dir_ = test_data_dir_.AppendASCII("components"); | 162 test_data_dir_ = test_data_dir_.AppendASCII("components"); |
157 | 163 |
158 net::URLFetcher::SetEnableInterceptionForTests(true); | 164 net::URLFetcher::SetEnableInterceptionForTests(true); |
159 } | 165 } |
160 | 166 |
161 ComponentUpdaterTest::~ComponentUpdaterTest() { | 167 ComponentUpdaterTest::~ComponentUpdaterTest() { |
162 net::URLFetcher::SetEnableInterceptionForTests(false); | 168 net::URLFetcher::SetEnableInterceptionForTests(false); |
163 } | 169 } |
164 | 170 |
165 void ComponentUpdaterTest::SetUp() { | 171 void ComponentUpdaterTest::SetUp() { |
| 172 get_interceptor_.reset(new GetInterceptor); |
166 interceptor_factory_.reset(new InterceptorFactory); | 173 interceptor_factory_.reset(new InterceptorFactory); |
| 174 post_interceptor_ = interceptor_factory_->CreateInterceptor(); |
| 175 EXPECT_TRUE(post_interceptor_); |
167 } | 176 } |
168 | 177 |
169 void ComponentUpdaterTest::TearDown() { | 178 void ComponentUpdaterTest::TearDown() { |
170 interceptor_factory_.reset(); | 179 interceptor_factory_.reset(); |
| 180 get_interceptor_.reset(); |
171 xmlCleanupGlobals(); | 181 xmlCleanupGlobals(); |
172 } | 182 } |
173 | 183 |
174 ComponentUpdateService* ComponentUpdaterTest::component_updater() { | 184 ComponentUpdateService* ComponentUpdaterTest::component_updater() { |
175 return component_updater_.get(); | 185 return component_updater_.get(); |
176 } | 186 } |
177 | 187 |
178 // Makes the full path to a component updater test file. | 188 // Makes the full path to a component updater test file. |
179 const base::FilePath ComponentUpdaterTest::test_file(const char* file) { | 189 const base::FilePath ComponentUpdaterTest::test_file(const char* file) { |
180 return test_data_dir_.AppendASCII(file); | 190 return test_data_dir_.AppendASCII(file); |
(...skipping 20 matching lines...) Expand all Loading... |
201 } | 211 } |
202 com->version = version; | 212 com->version = version; |
203 com->installer = installer; | 213 com->installer = installer; |
204 return component_updater_->RegisterComponent(*com); | 214 return component_updater_->RegisterComponent(*com); |
205 } | 215 } |
206 | 216 |
207 void ComponentUpdaterTest::RunThreads() { | 217 void ComponentUpdaterTest::RunThreads() { |
208 base::RunLoop runloop; | 218 base::RunLoop runloop; |
209 test_configurator()->SetQuitClosure(runloop.QuitClosure()); | 219 test_configurator()->SetQuitClosure(runloop.QuitClosure()); |
210 runloop.Run(); | 220 runloop.Run(); |
| 221 |
| 222 // Since some tests need to drain currently enqueued tasks such as network |
| 223 // intercepts on the IO thread, run the threads until they are |
| 224 // idle. The component updater service won't loop again until the loop count |
| 225 // is set and the service is started. |
| 226 RunThreadsUntilIdle(); |
211 } | 227 } |
212 | 228 |
213 void ComponentUpdaterTest::RunThreadsUntilIdle() { | 229 void ComponentUpdaterTest::RunThreadsUntilIdle() { |
214 base::RunLoop().RunUntilIdle(); | 230 base::RunLoop().RunUntilIdle(); |
215 } | 231 } |
216 | 232 |
217 ComponentUpdateService::Status OnDemandTester::OnDemand( | 233 ComponentUpdateService::Status OnDemandTester::OnDemand( |
218 ComponentUpdateService* cus, const std::string& component_id) { | 234 ComponentUpdateService* cus, const std::string& component_id) { |
219 return cus->OnDemandUpdate(component_id); | 235 return cus->OnDemandUpdate(component_id); |
220 } | 236 } |
221 | 237 |
222 // Verify that our test fixture work and the component updater can | 238 // Verify that our test fixture work and the component updater can |
223 // be created and destroyed with no side effects. | 239 // be created and destroyed with no side effects. |
224 TEST_F(ComponentUpdaterTest, VerifyFixture) { | 240 TEST_F(ComponentUpdaterTest, VerifyFixture) { |
225 EXPECT_TRUE(component_updater() != NULL); | 241 EXPECT_TRUE(component_updater() != NULL); |
226 } | 242 } |
227 | 243 |
228 // Verify that the component updater can be caught in a quick | 244 // Verify that the component updater can be caught in a quick |
229 // start-shutdown situation. Failure of this test will be a crash. | 245 // start-shutdown situation. Failure of this test will be a crash. |
230 TEST_F(ComponentUpdaterTest, StartStop) { | 246 TEST_F(ComponentUpdaterTest, StartStop) { |
231 component_updater()->Start(); | 247 component_updater()->Start(); |
232 RunThreadsUntilIdle(); | 248 RunThreadsUntilIdle(); |
233 component_updater()->Stop(); | 249 component_updater()->Stop(); |
234 } | 250 } |
235 | 251 |
236 // Verify that when the server has no updates, we go back to sleep and | 252 // Verify that when the server has no updates, we go back to sleep and |
237 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications | 253 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications |
238 // are generated. No pings are sent. | 254 // are generated. No pings are sent. |
239 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { | 255 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { |
240 URLRequestPostInterceptor* post_interceptor( | 256 MockComponentObserver observer; |
241 interceptor_factory_->CreateInterceptor()); | |
242 EXPECT_TRUE(post_interceptor != NULL); | |
243 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | |
244 "event eventtype"))); | |
245 | 257 |
246 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 258 EXPECT_CALL(observer, |
| 259 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| 260 .Times(1); |
| 261 EXPECT_CALL(observer, |
| 262 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| 263 .Times(2); |
| 264 EXPECT_CALL(observer, |
| 265 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
| 266 .Times(2); |
247 | 267 |
248 MockComponentObserver observer; | 268 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 269 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 270 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 271 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
249 | 272 |
250 TestInstaller installer; | 273 TestInstaller installer; |
251 CrxComponent com; | 274 CrxComponent com; |
252 com.observer = &observer; | 275 com.observer = &observer; |
253 EXPECT_EQ(ComponentUpdateService::kOk, | 276 EXPECT_EQ(ComponentUpdateService::kOk, |
254 RegisterComponent(&com, | 277 RegisterComponent(&com, |
255 kTestComponent_abag, | 278 kTestComponent_abag, |
256 Version("1.1"), | 279 Version("1.1"), |
257 &installer)); | 280 &installer)); |
258 | 281 |
259 const GURL expected_update_url( | |
260 "http://localhost/upd?extra=foo" | |
261 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc"); | |
262 | |
263 interceptor.SetResponse(expected_update_url, | |
264 test_file("updatecheck_reply_1.xml")); | |
265 | |
266 // We loop twice, but there are no updates so we expect two sleep messages. | 282 // We loop twice, but there are no updates so we expect two sleep messages. |
267 test_configurator()->SetLoopCount(2); | 283 test_configurator()->SetLoopCount(2); |
268 | |
269 EXPECT_CALL(observer, | |
270 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | |
271 .Times(1); | |
272 component_updater()->Start(); | 284 component_updater()->Start(); |
273 | |
274 EXPECT_CALL(observer, | |
275 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | |
276 .Times(2); | |
277 | |
278 EXPECT_CALL(observer, | |
279 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | |
280 .Times(2); | |
281 RunThreads(); | 285 RunThreads(); |
282 | 286 |
283 EXPECT_EQ(2, interceptor.GetHitCount()); | |
284 | |
285 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 287 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
286 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 288 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
287 | 289 |
| 290 // Expect to see the two update check requests and no other requests, |
| 291 // including pings. |
| 292 EXPECT_EQ(2, post_interceptor_->GetHitCount()) |
| 293 << post_interceptor_->GetRequestsAsString(); |
| 294 EXPECT_EQ(2, post_interceptor_->GetCount()) |
| 295 << post_interceptor_->GetRequestsAsString(); |
| 296 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 297 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">" |
| 298 "<updatecheck /></app>")) |
| 299 << post_interceptor_->GetRequestsAsString(); |
| 300 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| 301 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">" |
| 302 "<updatecheck /></app>")) |
| 303 << post_interceptor_->GetRequestsAsString(); |
| 304 |
288 component_updater()->Stop(); | 305 component_updater()->Stop(); |
289 | 306 |
290 // Loop twice again but this case we simulate a server error by returning | 307 // Loop twice again but this case we simulate a server error by returning |
291 // an empty file. | 308 // an empty file. Expect the behavior of the service to be the same as before. |
292 | |
293 interceptor.SetResponse(expected_update_url, | |
294 test_file("updatecheck_reply_empty")); | |
295 | |
296 test_configurator()->SetLoopCount(2); | |
297 | |
298 EXPECT_CALL(observer, | 309 EXPECT_CALL(observer, |
299 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 310 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
300 .Times(1); | 311 .Times(1); |
301 component_updater()->Start(); | |
302 | |
303 EXPECT_CALL(observer, | 312 EXPECT_CALL(observer, |
304 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 313 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
305 .Times(2); | 314 .Times(2); |
306 EXPECT_CALL(observer, | 315 EXPECT_CALL(observer, |
307 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 316 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
308 .Times(2); | 317 .Times(2); |
| 318 |
| 319 post_interceptor_->Reset(); |
| 320 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 321 "updatecheck"), test_file("updatecheck_reply_empty"))); |
| 322 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 323 "updatecheck"), test_file("updatecheck_reply_empty"))); |
| 324 |
| 325 test_configurator()->SetLoopCount(2); |
| 326 component_updater()->Start(); |
309 RunThreads(); | 327 RunThreads(); |
310 | 328 |
311 EXPECT_EQ(0, post_interceptor->GetHitCount()) | |
312 << post_interceptor->GetRequestsAsString(); | |
313 EXPECT_EQ(0, post_interceptor->GetMissCount()) | |
314 << post_interceptor->GetRequestsAsString(); | |
315 | |
316 EXPECT_EQ(4, interceptor.GetHitCount()); | |
317 | |
318 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 329 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
319 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 330 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
320 | 331 |
| 332 EXPECT_EQ(2, post_interceptor_->GetHitCount()) |
| 333 << post_interceptor_->GetRequestsAsString(); |
| 334 EXPECT_EQ(2, post_interceptor_->GetCount()) |
| 335 << post_interceptor_->GetRequestsAsString(); |
| 336 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 337 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">" |
| 338 "<updatecheck /></app>")) |
| 339 << post_interceptor_->GetRequestsAsString(); |
| 340 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| 341 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"1.1\">" |
| 342 "<updatecheck /></app>")) |
| 343 << post_interceptor_->GetRequestsAsString(); |
| 344 |
321 component_updater()->Stop(); | 345 component_updater()->Stop(); |
322 } | 346 } |
323 | 347 |
324 // Verify that we can check for updates and install one component. Besides | 348 // Verify that we can check for updates and install one component. Besides |
325 // the notifications above COMPONENT_UPDATE_FOUND and COMPONENT_UPDATE_READY | 349 // the notifications above COMPONENT_UPDATE_FOUND and COMPONENT_UPDATE_READY |
326 // should have been fired. We do two loops so the second time around there | 350 // should have been fired. We do two loops so the second time around there |
327 // should be nothing left to do. | 351 // should be nothing left to do. |
328 // We also check that only 3 non-ping network requests are issued: | 352 // We also check that the following network requests are issued: |
329 // 1- manifest check | 353 // 1- manifest check |
330 // 2- download crx | 354 // 2- download crx |
331 // 3- second manifest check. | 355 // 3- ping |
332 // Only one ping is sent. | 356 // 4- second manifest check. |
333 TEST_F(ComponentUpdaterTest, InstallCrx) { | 357 TEST_F(ComponentUpdaterTest, InstallCrx) { |
334 URLRequestPostInterceptor* post_interceptor( | |
335 interceptor_factory_->CreateInterceptor()); | |
336 EXPECT_TRUE(post_interceptor != NULL); | |
337 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | |
338 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" | |
339 "<o:event eventtype=\"3\" eventresult=\"1\" " | |
340 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>"))); | |
341 | |
342 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | |
343 | |
344 MockComponentObserver observer1; | 358 MockComponentObserver observer1; |
345 { | 359 { |
346 InSequence seq; | 360 InSequence seq; |
347 EXPECT_CALL(observer1, | 361 EXPECT_CALL(observer1, |
348 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 362 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
349 .Times(1); | 363 .Times(1); |
350 EXPECT_CALL(observer1, | 364 EXPECT_CALL(observer1, |
351 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) | 365 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) |
352 .Times(1); | 366 .Times(1); |
353 EXPECT_CALL(observer1, | 367 EXPECT_CALL(observer1, |
(...skipping 26 matching lines...) Expand all Loading... |
380 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 394 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
381 .Times(1); | 395 .Times(1); |
382 EXPECT_CALL(observer2, | 396 EXPECT_CALL(observer2, |
383 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 397 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
384 .Times(1); | 398 .Times(1); |
385 EXPECT_CALL(observer2, | 399 EXPECT_CALL(observer2, |
386 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 400 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
387 .Times(1); | 401 .Times(1); |
388 } | 402 } |
389 | 403 |
| 404 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 405 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 406 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| 407 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 408 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 409 |
| 410 get_interceptor_->SetResponse( |
| 411 GURL(expected_crx_url), |
| 412 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 413 |
390 TestInstaller installer1; | 414 TestInstaller installer1; |
391 CrxComponent com1; | 415 CrxComponent com1; |
392 com1.observer = &observer1; | 416 com1.observer = &observer1; |
393 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); | 417 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
394 TestInstaller installer2; | 418 TestInstaller installer2; |
395 CrxComponent com2; | 419 CrxComponent com2; |
396 com2.observer = &observer2; | 420 com2.observer = &observer2; |
397 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); | 421 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
398 | 422 |
399 const GURL expected_update_url_1( | |
400 "http://localhost/upd?extra=foo" | |
401 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" | |
402 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); | |
403 | |
404 const GURL expected_update_url_2( | |
405 "http://localhost/upd?extra=foo" | |
406 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" | |
407 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"); | |
408 | |
409 interceptor.SetResponse(expected_update_url_1, | |
410 test_file("updatecheck_reply_1.xml")); | |
411 interceptor.SetResponse(expected_update_url_2, | |
412 test_file("updatecheck_reply_1.xml")); | |
413 interceptor.SetResponse(GURL(expected_crx_url), | |
414 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | |
415 | |
416 test_configurator()->SetLoopCount(2); | 423 test_configurator()->SetLoopCount(2); |
417 | |
418 component_updater()->Start(); | 424 component_updater()->Start(); |
419 RunThreads(); | 425 RunThreads(); |
420 | 426 |
421 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 427 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
422 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 428 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
423 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 429 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
424 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 430 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
425 | 431 |
426 EXPECT_EQ(3, interceptor.GetHitCount()); | 432 // Expect three request in total: two update checks and one ping. |
| 433 EXPECT_EQ(3, post_interceptor_->GetHitCount()) |
| 434 << post_interceptor_->GetRequestsAsString(); |
| 435 EXPECT_EQ(3, post_interceptor_->GetCount()) |
| 436 << post_interceptor_->GetRequestsAsString(); |
427 | 437 |
428 EXPECT_EQ(1, post_interceptor->GetHitCount()) | 438 // Expect one component download. |
429 << post_interceptor->GetRequestsAsString(); | 439 EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
430 EXPECT_EQ(0, post_interceptor->GetMissCount()) | 440 |
431 << post_interceptor->GetRequestsAsString(); | 441 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 442 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 443 "<updatecheck /></app>")) |
| 444 << post_interceptor_->GetRequestsAsString(); |
| 445 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 446 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">" |
| 447 "<updatecheck /></app>")) |
| 448 << post_interceptor_->GetRequestsAsString(); |
| 449 |
| 450 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| 451 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| 452 "version=\"0.9\" nextversion=\"1.0\">" |
| 453 "<event eventtype=\"3\" eventresult=\"1\"/></app>")) |
| 454 << post_interceptor_->GetRequestsAsString(); |
| 455 |
| 456 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| 457 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
| 458 "<updatecheck /></app>")); |
| 459 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| 460 "<app appid=\"abagagagagagagagagagagagagagagag\" version=\"2.2\">" |
| 461 "<updatecheck /></app>")) |
| 462 << post_interceptor_->GetRequestsAsString(); |
432 | 463 |
433 component_updater()->Stop(); | 464 component_updater()->Stop(); |
434 } | 465 } |
435 | 466 |
436 // This test checks that the "prodversionmin" value is handled correctly. In | 467 // This test checks that the "prodversionmin" value is handled correctly. In |
437 // particular there should not be an install because the minimum product | 468 // particular there should not be an install because the minimum product |
438 // version is much higher than of chrome. | 469 // version is much higher than of chrome. |
439 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { | 470 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
440 URLRequestPostInterceptor* post_interceptor( | 471 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
441 interceptor_factory_->CreateInterceptor()); | 472 "updatecheck"), test_file("updatecheck_reply_2.xml"))); |
442 EXPECT_TRUE(post_interceptor != NULL); | |
443 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | |
444 "event eventtype"))); | |
445 | 473 |
446 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 474 get_interceptor_->SetResponse( |
| 475 GURL(expected_crx_url), |
| 476 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
447 | 477 |
448 TestInstaller installer; | 478 TestInstaller installer; |
449 CrxComponent com; | 479 CrxComponent com; |
450 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); | 480 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); |
451 | 481 |
452 const GURL expected_update_url( | |
453 "http://localhost/upd?extra=foo&x=id%3D" | |
454 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); | |
455 | |
456 interceptor.SetResponse(expected_update_url, | |
457 test_file("updatecheck_reply_2.xml")); | |
458 interceptor.SetResponse(GURL(expected_crx_url), | |
459 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | |
460 | |
461 test_configurator()->SetLoopCount(1); | 482 test_configurator()->SetLoopCount(1); |
462 component_updater()->Start(); | 483 component_updater()->Start(); |
463 RunThreads(); | 484 RunThreads(); |
464 | 485 |
465 EXPECT_EQ(0, post_interceptor->GetHitCount()) | 486 // Expect one update check and no ping. |
466 << post_interceptor->GetRequestsAsString(); | 487 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
467 EXPECT_EQ(1, interceptor.GetHitCount()); | 488 << post_interceptor_->GetRequestsAsString(); |
| 489 EXPECT_EQ(1, post_interceptor_->GetCount()) |
| 490 << post_interceptor_->GetRequestsAsString(); |
| 491 |
| 492 // Expect no download to occur. |
| 493 EXPECT_EQ(0, get_interceptor_->GetHitCount()); |
468 | 494 |
469 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 495 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
470 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 496 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
471 | 497 |
472 component_updater()->Stop(); | 498 component_updater()->Stop(); |
473 } | 499 } |
474 | 500 |
475 // Test that a update check due to an on demand call can cause installs. | 501 // Test that a update check due to an on demand call can cause installs. |
476 // Here is the timeline: | 502 // Here is the timeline: |
477 // - First loop: we return a reply that indicates no update, so | 503 // - First loop: we return a reply that indicates no update, so |
478 // nothing happens. | 504 // nothing happens. |
479 // - We make an on demand call. | 505 // - We make an on demand call. |
480 // - This triggers a second loop, which has a reply that triggers an install. | 506 // - This triggers a second loop, which has a reply that triggers an install. |
481 TEST_F(ComponentUpdaterTest, OnDemandUpdate) { | 507 TEST_F(ComponentUpdaterTest, OnDemandUpdate) { |
482 URLRequestPostInterceptor* post_interceptor( | |
483 interceptor_factory_->CreateInterceptor()); | |
484 EXPECT_TRUE(post_interceptor != NULL); | |
485 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | |
486 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" | |
487 "<o:event eventtype=\"3\" eventresult=\"1\" " | |
488 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>"))); | |
489 | |
490 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | |
491 | |
492 MockComponentObserver observer1; | 508 MockComponentObserver observer1; |
493 { | 509 { |
494 InSequence seq; | 510 InSequence seq; |
495 EXPECT_CALL(observer1, | 511 EXPECT_CALL(observer1, |
496 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 512 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
497 .Times(1); | 513 .Times(1); |
498 EXPECT_CALL(observer1, | 514 EXPECT_CALL(observer1, |
499 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 515 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
500 .Times(1); | 516 .Times(1); |
501 EXPECT_CALL(observer1, | 517 EXPECT_CALL(observer1, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 OnEvent(ComponentObserver::COMPONENT_UPDATE_READY, 0)) | 550 OnEvent(ComponentObserver::COMPONENT_UPDATE_READY, 0)) |
535 .Times(1); | 551 .Times(1); |
536 EXPECT_CALL(observer2, | 552 EXPECT_CALL(observer2, |
537 OnEvent(ComponentObserver::COMPONENT_UPDATED, 0)) | 553 OnEvent(ComponentObserver::COMPONENT_UPDATED, 0)) |
538 .Times(1); | 554 .Times(1); |
539 EXPECT_CALL(observer2, | 555 EXPECT_CALL(observer2, |
540 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 556 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
541 .Times(1); | 557 .Times(1); |
542 } | 558 } |
543 | 559 |
| 560 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 561 "updatecheck"), test_file("updatecheck_reply_empty"))); |
| 562 |
| 563 get_interceptor_->SetResponse( |
| 564 GURL(expected_crx_url), |
| 565 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 566 |
544 TestInstaller installer1; | 567 TestInstaller installer1; |
545 CrxComponent com1; | 568 CrxComponent com1; |
546 com1.observer = &observer1; | 569 com1.observer = &observer1; |
547 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); | 570 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); |
548 TestInstaller installer2; | 571 TestInstaller installer2; |
549 CrxComponent com2; | 572 CrxComponent com2; |
550 com2.observer = &observer2; | 573 com2.observer = &observer2; |
551 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); | 574 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); |
552 | 575 |
553 const GURL expected_update_url_1( | |
554 "http://localhost/upd?extra=foo" | |
555 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" | |
556 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); | |
557 | |
558 const GURL expected_update_url_2( | |
559 "http://localhost/upd?extra=foo" | |
560 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" | |
561 "%26installsource%3Dondemand" | |
562 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); | |
563 | |
564 interceptor.SetResponse(expected_update_url_1, | |
565 test_file("updatecheck_reply_empty")); | |
566 interceptor.SetResponse(expected_update_url_2, | |
567 test_file("updatecheck_reply_1.xml")); | |
568 interceptor.SetResponse(GURL(expected_crx_url), | |
569 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | |
570 // No update normally. | 576 // No update normally. |
571 test_configurator()->SetLoopCount(1); | 577 test_configurator()->SetLoopCount(1); |
572 component_updater()->Start(); | 578 component_updater()->Start(); |
573 RunThreads(); | 579 RunThreads(); |
574 component_updater()->Stop(); | 580 component_updater()->Stop(); |
575 | 581 |
| 582 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| 583 << post_interceptor_->GetRequestsAsString(); |
| 584 EXPECT_EQ(1, post_interceptor_->GetCount()) |
| 585 << post_interceptor_->GetRequestsAsString(); |
| 586 |
| 587 EXPECT_EQ(0, get_interceptor_->GetHitCount()); |
| 588 |
576 // Update after an on-demand check is issued. | 589 // Update after an on-demand check is issued. |
| 590 post_interceptor_->Reset(); |
| 591 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 592 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 593 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| 594 |
577 EXPECT_EQ(ComponentUpdateService::kOk, | 595 EXPECT_EQ(ComponentUpdateService::kOk, |
578 OnDemandTester::OnDemand(component_updater(), | 596 OnDemandTester::OnDemand(component_updater(), |
579 GetCrxComponentID(com2))); | 597 GetCrxComponentID(com2))); |
580 test_configurator()->SetLoopCount(1); | 598 test_configurator()->SetLoopCount(1); |
581 component_updater()->Start(); | 599 component_updater()->Start(); |
582 RunThreads(); | 600 RunThreads(); |
583 | 601 |
584 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 602 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
585 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); | 603 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); |
586 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 604 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
587 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count()); | 605 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count()); |
588 | 606 |
589 EXPECT_EQ(3, interceptor.GetHitCount()); | 607 EXPECT_EQ(2, post_interceptor_->GetHitCount()) |
| 608 << post_interceptor_->GetRequestsAsString(); |
| 609 EXPECT_EQ(2, post_interceptor_->GetCount()) |
| 610 << post_interceptor_->GetRequestsAsString(); |
| 611 |
| 612 EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
| 613 |
| 614 // Expect the update check to contain an "ondemand" request for the |
| 615 // second component (com2) and a normal request for the other component. |
| 616 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 617 "<app appid=\"abagagagagagagagagagagagagagagag\" " |
| 618 "version=\"2.2\"><updatecheck /></app>")) |
| 619 << post_interceptor_->GetRequestsAsString(); |
| 620 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 621 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| 622 "version=\"0.9\" installsource=\"ondemand\"><updatecheck /></app>")) |
| 623 << post_interceptor_->GetRequestsAsString(); |
| 624 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| 625 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| 626 "version=\"0.9\" nextversion=\"1.0\">" |
| 627 "<event eventtype=\"3\" eventresult=\"1\"/></app>")) |
| 628 << post_interceptor_->GetRequestsAsString(); |
590 | 629 |
591 // Also check what happens if previous check too soon. | 630 // Also check what happens if previous check too soon. |
592 test_configurator()->SetOnDemandTime(60 * 60); | 631 test_configurator()->SetOnDemandTime(60 * 60); |
593 EXPECT_EQ(ComponentUpdateService::kError, | 632 EXPECT_EQ(ComponentUpdateService::kError, |
594 OnDemandTester::OnDemand(component_updater(), | 633 OnDemandTester::OnDemand(component_updater(), |
595 GetCrxComponentID(com2))); | 634 GetCrxComponentID(com2))); |
596 // Okay, now reset to 0 for the other tests. | 635 // Okay, now reset to 0 for the other tests. |
597 test_configurator()->SetOnDemandTime(0); | 636 test_configurator()->SetOnDemandTime(0); |
598 component_updater()->Stop(); | 637 component_updater()->Stop(); |
599 | 638 |
(...skipping 19 matching lines...) Expand all Loading... |
619 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 658 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
620 .Times(1); | 659 .Times(1); |
621 EXPECT_CALL(observer2, | 660 EXPECT_CALL(observer2, |
622 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 661 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
623 .Times(1); | 662 .Times(1); |
624 EXPECT_CALL(observer2, | 663 EXPECT_CALL(observer2, |
625 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 664 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
626 .Times(1); | 665 .Times(1); |
627 } | 666 } |
628 | 667 |
629 const GURL expected_update_url_3( | 668 // No update: error from no server response |
630 "http://localhost/upd?extra=foo" | 669 post_interceptor_->Reset(); |
631 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc" | 670 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
632 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); | 671 "updatecheck"), test_file("updatecheck_reply_empty"))); |
633 | 672 |
634 // No update: error from no server response | |
635 interceptor.SetResponse(expected_update_url_3, | |
636 test_file("updatecheck_reply_empty")); | |
637 test_configurator()->SetLoopCount(1); | 673 test_configurator()->SetLoopCount(1); |
638 component_updater()->Start(); | 674 component_updater()->Start(); |
639 EXPECT_EQ(ComponentUpdateService::kOk, | 675 EXPECT_EQ(ComponentUpdateService::kOk, |
640 OnDemandTester::OnDemand(component_updater(), | 676 OnDemandTester::OnDemand(component_updater(), |
641 GetCrxComponentID(com2))); | 677 GetCrxComponentID(com2))); |
| 678 RunThreads(); |
| 679 component_updater()->Stop(); |
642 | 680 |
643 RunThreads(); | 681 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
644 | 682 << post_interceptor_->GetRequestsAsString(); |
645 component_updater()->Stop(); | 683 EXPECT_EQ(1, post_interceptor_->GetCount()) |
| 684 << post_interceptor_->GetRequestsAsString(); |
646 | 685 |
647 // No update: already updated to 1.0 so nothing new | 686 // No update: already updated to 1.0 so nothing new |
648 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); | 687 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); |
649 { | 688 { |
650 InSequence seq; | 689 InSequence seq; |
651 EXPECT_CALL(observer1, | 690 EXPECT_CALL(observer1, |
652 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 691 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
653 .Times(1); | 692 .Times(1); |
654 EXPECT_CALL(observer1, | 693 EXPECT_CALL(observer1, |
655 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 694 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
656 .Times(1); | 695 .Times(1); |
657 EXPECT_CALL(observer1, | 696 EXPECT_CALL(observer1, |
658 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 697 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
659 .Times(1); | 698 .Times(1); |
660 } | 699 } |
661 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); | 700 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer2)); |
662 { | 701 { |
663 InSequence seq; | 702 InSequence seq; |
664 EXPECT_CALL(observer2, | 703 EXPECT_CALL(observer2, |
665 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 704 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
666 .Times(1); | 705 .Times(1); |
667 EXPECT_CALL(observer2, | 706 EXPECT_CALL(observer2, |
668 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 707 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
669 .Times(1); | 708 .Times(1); |
670 EXPECT_CALL(observer2, | 709 EXPECT_CALL(observer2, |
671 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 710 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
672 .Times(1); | 711 .Times(1); |
673 } | 712 } |
674 | 713 |
675 interceptor.SetResponse(expected_update_url_3, | 714 post_interceptor_->Reset(); |
676 test_file("updatecheck_reply_1.xml")); | 715 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 716 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 717 |
677 test_configurator()->SetLoopCount(1); | 718 test_configurator()->SetLoopCount(1); |
678 component_updater()->Start(); | 719 component_updater()->Start(); |
679 EXPECT_EQ(ComponentUpdateService::kOk, | 720 EXPECT_EQ(ComponentUpdateService::kOk, |
680 OnDemandTester::OnDemand(component_updater(), | 721 OnDemandTester::OnDemand(component_updater(), |
681 GetCrxComponentID(com2))); | 722 GetCrxComponentID(com2))); |
682 | |
683 RunThreads(); | 723 RunThreads(); |
684 | 724 |
685 EXPECT_EQ(1, post_interceptor->GetHitCount()) | 725 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
686 << post_interceptor->GetRequestsAsString(); | 726 << post_interceptor_->GetRequestsAsString(); |
687 EXPECT_EQ(0, post_interceptor->GetMissCount()) | 727 EXPECT_EQ(1, post_interceptor_->GetCount()) |
688 << post_interceptor->GetRequestsAsString(); | 728 << post_interceptor_->GetRequestsAsString(); |
689 | 729 |
690 component_updater()->Stop(); | 730 component_updater()->Stop(); |
691 } | 731 } |
692 | 732 |
693 // Verify that a previously registered component can get re-registered | 733 // Verify that a previously registered component can get re-registered |
694 // with a different version. | 734 // with a different version. |
695 TEST_F(ComponentUpdaterTest, CheckReRegistration) { | 735 TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
696 URLRequestPostInterceptor* post_interceptor( | |
697 interceptor_factory_->CreateInterceptor()); | |
698 EXPECT_TRUE(post_interceptor != NULL); | |
699 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | |
700 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" | |
701 "<o:event eventtype=\"3\" eventresult=\"1\" " | |
702 "previousversion=\"0.9\" nextversion=\"1.0\"/></o:app>"))); | |
703 | |
704 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | |
705 | |
706 MockComponentObserver observer1; | 736 MockComponentObserver observer1; |
707 { | 737 { |
708 InSequence seq; | 738 InSequence seq; |
709 EXPECT_CALL(observer1, | 739 EXPECT_CALL(observer1, |
710 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 740 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
711 .Times(1); | 741 .Times(1); |
712 EXPECT_CALL(observer1, | 742 EXPECT_CALL(observer1, |
713 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) | 743 OnEvent(ComponentObserver::COMPONENT_UPDATE_FOUND, 0)) |
714 .Times(1); | 744 .Times(1); |
715 EXPECT_CALL(observer1, | 745 EXPECT_CALL(observer1, |
(...skipping 26 matching lines...) Expand all Loading... |
742 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 772 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
743 .Times(1); | 773 .Times(1); |
744 EXPECT_CALL(observer2, | 774 EXPECT_CALL(observer2, |
745 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 775 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
746 .Times(1); | 776 .Times(1); |
747 EXPECT_CALL(observer2, | 777 EXPECT_CALL(observer2, |
748 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 778 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
749 .Times(1); | 779 .Times(1); |
750 } | 780 } |
751 | 781 |
| 782 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 783 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 784 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| 785 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 786 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 787 |
| 788 get_interceptor_->SetResponse( |
| 789 GURL(expected_crx_url), |
| 790 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 791 |
752 TestInstaller installer1; | 792 TestInstaller installer1; |
753 CrxComponent com1; | 793 CrxComponent com1; |
754 com1.observer = &observer1; | 794 com1.observer = &observer1; |
755 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); | 795 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
756 TestInstaller installer2; | 796 TestInstaller installer2; |
757 CrxComponent com2; | 797 CrxComponent com2; |
758 com2.observer = &observer2; | 798 com2.observer = &observer2; |
759 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); | 799 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
760 | 800 |
761 // Start with 0.9, and update to 1.0 | 801 // Loop twice to issue two checks: (1) with original 0.9 version, update to |
762 const GURL expected_update_url_1( | 802 // 1.0, and do the second check (2) with the updated 1.0 version. |
763 "http://localhost/upd?extra=foo" | |
764 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" | |
765 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); | |
766 | |
767 const GURL expected_update_url_2( | |
768 "http://localhost/upd?extra=foo" | |
769 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" | |
770 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"); | |
771 | |
772 interceptor.SetResponse(expected_update_url_1, | |
773 test_file("updatecheck_reply_1.xml")); | |
774 interceptor.SetResponse(expected_update_url_2, | |
775 test_file("updatecheck_reply_1.xml")); | |
776 interceptor.SetResponse(GURL(expected_crx_url), | |
777 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | |
778 | |
779 // Loop twice to issue two checks: (1) with original 0.9 version | |
780 // and (2) with the updated 1.0 version. | |
781 test_configurator()->SetLoopCount(2); | 803 test_configurator()->SetLoopCount(2); |
782 | |
783 component_updater()->Start(); | 804 component_updater()->Start(); |
784 RunThreads(); | 805 RunThreads(); |
785 | 806 |
786 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 807 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
787 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 808 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
788 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 809 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
789 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 810 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
790 | 811 |
791 EXPECT_EQ(1, post_interceptor->GetHitCount()) | 812 EXPECT_EQ(3, post_interceptor_->GetHitCount()) |
792 << post_interceptor->GetRequestsAsString(); | 813 << post_interceptor_->GetRequestsAsString(); |
793 EXPECT_EQ(0, post_interceptor->GetMissCount()) | 814 EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
794 << post_interceptor->GetRequestsAsString(); | |
795 | 815 |
796 EXPECT_EQ(3, interceptor.GetHitCount()); | 816 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 817 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 818 "<updatecheck /></app>")) |
| 819 << post_interceptor_->GetRequestsAsString(); |
| 820 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| 821 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| 822 "version=\"0.9\" nextversion=\"1.0\">" |
| 823 "<event eventtype=\"3\" eventresult=\"1\"/></app>")) |
| 824 << post_interceptor_->GetRequestsAsString(); |
| 825 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| 826 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"1.0\">" |
| 827 "<updatecheck /></app>")) |
| 828 << post_interceptor_->GetRequestsAsString(); |
797 | 829 |
798 component_updater()->Stop(); | 830 component_updater()->Stop(); |
799 | 831 |
800 // Now re-register, pretending to be an even newer version (2.2) | 832 // Now re-register, pretending to be an even newer version (2.2) |
801 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); | 833 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer1)); |
802 { | 834 { |
803 InSequence seq; | 835 InSequence seq; |
804 EXPECT_CALL(observer1, | 836 EXPECT_CALL(observer1, |
805 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 837 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
806 .Times(1); | 838 .Times(1); |
(...skipping 12 matching lines...) Expand all Loading... |
819 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) | 851 OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
820 .Times(1); | 852 .Times(1); |
821 EXPECT_CALL(observer2, | 853 EXPECT_CALL(observer2, |
822 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) | 854 OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
823 .Times(1); | 855 .Times(1); |
824 EXPECT_CALL(observer2, | 856 EXPECT_CALL(observer2, |
825 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) | 857 OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
826 .Times(1); | 858 .Times(1); |
827 } | 859 } |
828 | 860 |
| 861 post_interceptor_->Reset(); |
| 862 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 863 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 864 |
829 TestInstaller installer3; | 865 TestInstaller installer3; |
830 EXPECT_EQ(ComponentUpdateService::kReplaced, | 866 EXPECT_EQ(ComponentUpdateService::kReplaced, |
831 RegisterComponent(&com1, | 867 RegisterComponent(&com1, |
832 kTestComponent_jebg, | 868 kTestComponent_jebg, |
833 Version("2.2"), | 869 Version("2.2"), |
834 &installer3)); | 870 &installer3)); |
835 | 871 |
836 // Check that we send out 2.2 as our version. | |
837 // Interceptor's hit count should go up by 1. | |
838 const GURL expected_update_url_3( | |
839 "http://localhost/upd?extra=foo" | |
840 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D2.2%26fp%3D%26uc" | |
841 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); | |
842 | |
843 interceptor.SetResponse(expected_update_url_3, | |
844 test_file("updatecheck_reply_1.xml")); | |
845 | |
846 // Loop once just to notice the check happening with the re-register version. | 872 // Loop once just to notice the check happening with the re-register version. |
847 test_configurator()->SetLoopCount(1); | 873 test_configurator()->SetLoopCount(1); |
848 component_updater()->Start(); | 874 component_updater()->Start(); |
849 RunThreads(); | 875 RunThreads(); |
850 | 876 |
851 EXPECT_EQ(4, interceptor.GetHitCount()); | |
852 | |
853 // No additional pings are expected. | |
854 EXPECT_EQ(1, post_interceptor->GetHitCount()) | |
855 << post_interceptor->GetRequestsAsString(); | |
856 EXPECT_EQ(0, post_interceptor->GetMissCount()) | |
857 << post_interceptor->GetRequestsAsString(); | |
858 | |
859 // We created a new installer, so the counts go back to 0. | 877 // We created a new installer, so the counts go back to 0. |
860 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 878 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
861 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); | 879 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); |
862 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 880 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
863 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 881 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
864 | 882 |
| 883 // One update check and no additional pings are expected. |
| 884 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| 885 << post_interceptor_->GetRequestsAsString(); |
| 886 EXPECT_EQ(1, post_interceptor_->GetCount()) |
| 887 << post_interceptor_->GetRequestsAsString(); |
| 888 |
| 889 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 890 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"2.2\">" |
| 891 "<updatecheck /></app>")); |
| 892 |
865 component_updater()->Stop(); | 893 component_updater()->Stop(); |
866 } | 894 } |
867 | 895 |
868 // Verify that we can download and install a component and a differential | 896 // Verify that we can download and install a component and a differential |
869 // update to that component. We do three loops; the final loop should do | 897 // update to that component. We do three loops; the final loop should do |
870 // nothing. | 898 // nothing. |
871 // We also check that exactly 5 non-ping network requests are issued: | 899 // We also check that exactly 5 non-ping network requests are issued: |
872 // 1- update check (response: v1 available) | 900 // 1- update check (response: v1 available) |
873 // 2- download crx (v1) | 901 // 2- download crx (v1) |
874 // 3- update check (response: v2 available) | 902 // 3- update check (response: v2 available) |
875 // 4- download differential crx (v1 to v2) | 903 // 4- download differential crx (v1 to v2) |
876 // 5- update check (response: no further update available) | 904 // 5- update check (response: no further update available) |
877 // There should be two pings, one for each update. The second will bear a | 905 // There should be two pings, one for each update. The second will bear a |
878 // diffresult=1, while the first will not. | 906 // diffresult=1, while the first will not. |
879 TEST_F(ComponentUpdaterTest, DifferentialUpdate) { | 907 TEST_F(ComponentUpdaterTest, DifferentialUpdate) { |
880 URLRequestPostInterceptor* post_interceptor( | 908 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
881 interceptor_factory_->CreateInterceptor()); | 909 "updatecheck"), test_file("updatecheck_diff_reply_1.xml"))); |
882 EXPECT_TRUE(post_interceptor != NULL); | 910 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
883 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | 911 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
884 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" | 912 "updatecheck"), test_file("updatecheck_diff_reply_2.xml"))); |
885 "<o:event eventtype=\"3\" eventresult=\"1\" " | 913 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
886 "previousversion=\"0.0\" nextversion=\"1.0\" nextfp=\"1\"/></o:app>"))); | 914 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
887 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | 915 "updatecheck"), test_file("updatecheck_diff_reply_3.xml"))); |
888 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" | |
889 "<o:event eventtype=\"3\" eventresult=\"1\" " | |
890 "previousversion=\"1.0\" nextversion=\"2.0\" " | |
891 "diffresult=\"1\" previousfp=\"1\" nextfp=\"f22\"/></o:app>"))); | |
892 | 916 |
893 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 917 get_interceptor_->SetResponse( |
| 918 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), |
| 919 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| 920 get_interceptor_->SetResponse( |
| 921 GURL("http://localhost/download/" |
| 922 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), |
| 923 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
894 | 924 |
895 VersionedTestInstaller installer; | 925 VersionedTestInstaller installer; |
896 CrxComponent com; | 926 CrxComponent com; |
897 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); | 927 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); |
898 | 928 |
899 const GURL expected_update_url_0( | |
900 "http://localhost/upd?extra=foo" | |
901 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); | |
902 const GURL expected_update_url_1( | |
903 "http://localhost/upd?extra=foo" | |
904 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc"); | |
905 const GURL expected_update_url_2( | |
906 "http://localhost/upd?extra=foo" | |
907 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc"); | |
908 const GURL expected_crx_url_1( | |
909 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"); | |
910 const GURL expected_crx_url_1_diff_2( | |
911 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"); | |
912 | |
913 interceptor.SetResponse(expected_update_url_0, | |
914 test_file("updatecheck_diff_reply_1.xml")); | |
915 interceptor.SetResponse(expected_update_url_1, | |
916 test_file("updatecheck_diff_reply_2.xml")); | |
917 interceptor.SetResponse(expected_update_url_2, | |
918 test_file("updatecheck_diff_reply_3.xml")); | |
919 interceptor.SetResponse(expected_crx_url_1, | |
920 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); | |
921 interceptor.SetResponse( | |
922 expected_crx_url_1_diff_2, | |
923 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); | |
924 | |
925 test_configurator()->SetLoopCount(3); | 929 test_configurator()->SetLoopCount(3); |
926 | |
927 component_updater()->Start(); | 930 component_updater()->Start(); |
928 RunThreads(); | 931 RunThreads(); |
929 | 932 |
930 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 933 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
931 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); | 934 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
932 | 935 |
933 // One ping has the diffresult=1, the other does not. | 936 EXPECT_EQ(5, post_interceptor_->GetHitCount()) |
934 EXPECT_EQ(2, post_interceptor->GetHitCount()) | 937 << post_interceptor_->GetRequestsAsString(); |
935 << post_interceptor->GetRequestsAsString(); | 938 EXPECT_EQ(5, post_interceptor_->GetCount()) |
936 EXPECT_EQ(0, post_interceptor->GetMissCount()) | 939 << post_interceptor_->GetRequestsAsString(); |
937 << post_interceptor->GetRequestsAsString(); | 940 EXPECT_EQ(2, get_interceptor_->GetHitCount()); |
938 | 941 |
939 EXPECT_EQ(5, interceptor.GetHitCount()); | 942 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
940 | 943 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"0.0\">" |
| 944 "<updatecheck /></app>")) |
| 945 << post_interceptor_->GetRequestsAsString(); |
| 946 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| 947 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
| 948 "version=\"0.0\" nextversion=\"1.0\">" |
| 949 "<event eventtype=\"3\" eventresult=\"1\" nextfp=\"1\"/></app>")) |
| 950 << post_interceptor_->GetRequestsAsString(); |
| 951 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| 952 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
| 953 "<updatecheck /><packages><package fp=\"1\"/></packages></app>")) |
| 954 << post_interceptor_->GetRequestsAsString(); |
| 955 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find( |
| 956 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
| 957 "version=\"1.0\" nextversion=\"2.0\">" |
| 958 "<event eventtype=\"3\" eventresult=\"1\" diffresult=\"1\" " |
| 959 "previousfp=\"1\" nextfp=\"22\"/></app>")) |
| 960 << post_interceptor_->GetRequestsAsString(); |
| 961 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[4].find( |
| 962 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| 963 "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) |
| 964 << post_interceptor_->GetRequestsAsString(); |
941 component_updater()->Stop(); | 965 component_updater()->Stop(); |
942 } | 966 } |
943 | 967 |
944 // Verify that component installation falls back to downloading and installing | 968 // Verify that component installation falls back to downloading and installing |
945 // a full update if the differential update fails (in this case, because the | 969 // a full update if the differential update fails (in this case, because the |
946 // installer does not know about the existing files). We do two loops; the final | 970 // installer does not know about the existing files). We do two loops; the final |
947 // loop should do nothing. | 971 // loop should do nothing. |
948 // We also check that exactly 4 non-ping network requests are issued: | 972 // We also check that exactly 4 non-ping network requests are issued: |
949 // 1- update check (loop 1) | 973 // 1- update check (loop 1) |
950 // 2- download differential crx | 974 // 2- download differential crx |
951 // 3- download full crx | 975 // 3- download full crx |
952 // 4- update check (loop 2 - no update available) | 976 // 4- update check (loop 2 - no update available) |
953 // There should be one ping for the first attempted update. | 977 // There should be one ping for the first attempted update. |
954 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { | 978 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { |
955 URLRequestPostInterceptor* post_interceptor( | 979 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
956 interceptor_factory_->CreateInterceptor()); | 980 "updatecheck"), test_file("updatecheck_diff_reply_2.xml"))); |
957 EXPECT_TRUE(post_interceptor != NULL); | 981 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
958 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | 982 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
959 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" | 983 "updatecheck"), test_file("updatecheck_diff_reply_3.xml"))); |
960 "<o:event eventtype=\"3\" eventresult=\"1\" " | |
961 "previousversion=\"1.0\" nextversion=\"2.0\" " | |
962 "diffresult=\"0\" differrorcat=\"2\" differrorcode=\"16\" " | |
963 "nextfp=\"f22\"/></o:app>"))); | |
964 | 984 |
965 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 985 get_interceptor_->SetResponse( |
| 986 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), |
| 987 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| 988 get_interceptor_->SetResponse( |
| 989 GURL("http://localhost/download/" |
| 990 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), |
| 991 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
| 992 get_interceptor_->SetResponse( |
| 993 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"), |
| 994 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
966 | 995 |
967 TestInstaller installer; | 996 TestInstaller installer; |
968 CrxComponent com; | 997 CrxComponent com; |
969 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); | 998 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); |
970 | 999 |
971 const GURL expected_update_url_1( | |
972 "http://localhost/upd?extra=foo" | |
973 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); | |
974 const GURL expected_update_url_2( | |
975 "http://localhost/upd?extra=foo" | |
976 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc"); | |
977 const GURL expected_crx_url_1( | |
978 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"); | |
979 const GURL expected_crx_url_1_diff_2( | |
980 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"); | |
981 const GURL expected_crx_url_2( | |
982 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"); | |
983 | |
984 interceptor.SetResponse(expected_update_url_1, | |
985 test_file("updatecheck_diff_reply_2.xml")); | |
986 interceptor.SetResponse(expected_update_url_2, | |
987 test_file("updatecheck_diff_reply_3.xml")); | |
988 interceptor.SetResponse(expected_crx_url_1, | |
989 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); | |
990 interceptor.SetResponse( | |
991 expected_crx_url_1_diff_2, | |
992 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); | |
993 interceptor.SetResponse(expected_crx_url_2, | |
994 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); | |
995 | |
996 test_configurator()->SetLoopCount(2); | 1000 test_configurator()->SetLoopCount(2); |
997 | |
998 component_updater()->Start(); | 1001 component_updater()->Start(); |
999 RunThreads(); | 1002 RunThreads(); |
1000 | 1003 |
1001 // A failed differential update does not count as a failed install. | 1004 // A failed differential update does not count as a failed install. |
1002 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 1005 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
1003 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); | 1006 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); |
1004 | 1007 |
1005 EXPECT_EQ(1, post_interceptor->GetHitCount()) | 1008 EXPECT_EQ(3, post_interceptor_->GetHitCount()) |
1006 << post_interceptor->GetRequestsAsString(); | 1009 << post_interceptor_->GetRequestsAsString(); |
1007 EXPECT_EQ(0, post_interceptor->GetMissCount()) | 1010 EXPECT_EQ(3, post_interceptor_->GetCount()) |
1008 << post_interceptor->GetRequestsAsString(); | 1011 << post_interceptor_->GetRequestsAsString(); |
| 1012 EXPECT_EQ(2, get_interceptor_->GetHitCount()); |
1009 | 1013 |
1010 EXPECT_EQ(4, interceptor.GetHitCount()); | 1014 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 1015 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
| 1016 "<updatecheck /></app>")) |
| 1017 << post_interceptor_->GetRequestsAsString(); |
| 1018 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| 1019 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
| 1020 "version=\"1.0\" nextversion=\"2.0\">" |
| 1021 "<event eventtype=\"3\" eventresult=\"1\" diffresult=\"0\" " |
| 1022 "differrorcat=\"2\" differrorcode=\"16\" nextfp=\"22\"/></app>")) |
| 1023 << post_interceptor_->GetRequestsAsString(); |
| 1024 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| 1025 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| 1026 "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) |
| 1027 << post_interceptor_->GetRequestsAsString(); |
1011 | 1028 |
1012 component_updater()->Stop(); | 1029 component_updater()->Stop(); |
1013 } | 1030 } |
1014 | 1031 |
1015 // Verify that a failed installation causes an install failure ping. | 1032 // Verify that a failed installation causes an install failure ping. |
1016 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { | 1033 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { |
1017 URLRequestPostInterceptor* post_interceptor( | |
1018 interceptor_factory_->CreateInterceptor()); | |
1019 EXPECT_TRUE(post_interceptor != NULL); | |
1020 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | |
1021 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" | |
1022 "<o:event eventtype=\"3\" eventresult=\"0\" " | |
1023 "previousversion=\"0.9\" nextversion=\"1.0\" " | |
1024 "errorcat=\"3\" errorcode=\"9\"/></o:app>"))); | |
1025 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | |
1026 "<o:app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" | |
1027 "<o:event eventtype=\"3\" eventresult=\"0\" " | |
1028 "previousversion=\"0.9\" nextversion=\"1.0\" " | |
1029 "errorcat=\"3\" errorcode=\"9\"/></o:app>"))); | |
1030 | |
1031 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | |
1032 | |
1033 // This test installer reports installation failure. | 1034 // This test installer reports installation failure. |
1034 class : public TestInstaller { | 1035 class : public TestInstaller { |
1035 virtual bool Install(const base::DictionaryValue& manifest, | 1036 virtual bool Install(const base::DictionaryValue& manifest, |
1036 const base::FilePath& unpack_path) OVERRIDE { | 1037 const base::FilePath& unpack_path) OVERRIDE { |
1037 ++install_count_; | 1038 ++install_count_; |
1038 base::DeleteFile(unpack_path, true); | 1039 base::DeleteFile(unpack_path, true); |
1039 return false; | 1040 return false; |
1040 } | 1041 } |
1041 } installer; | 1042 } installer; |
1042 | 1043 |
| 1044 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 1045 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 1046 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| 1047 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 1048 "updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 1049 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
| 1050 get_interceptor_->SetResponse( |
| 1051 GURL(expected_crx_url), |
| 1052 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 1053 |
| 1054 // Start with 0.9, and attempt update to 1.0. |
| 1055 // Loop twice to issue two checks: (1) with original 0.9 version |
| 1056 // and (2), which should retry with 0.9. |
1043 CrxComponent com; | 1057 CrxComponent com; |
1044 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); | 1058 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); |
1045 | 1059 |
1046 // Start with 0.9, and attempt update to 1.0 | |
1047 const GURL expected_update_url_1( | |
1048 "http://localhost/upd?extra=foo" | |
1049 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); | |
1050 | |
1051 interceptor.SetResponse(expected_update_url_1, | |
1052 test_file("updatecheck_reply_1.xml")); | |
1053 interceptor.SetResponse(GURL(expected_crx_url), | |
1054 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | |
1055 | |
1056 // Loop twice to issue two checks: (1) with original 0.9 version | |
1057 // and (2), which should retry with 0.9. | |
1058 test_configurator()->SetLoopCount(2); | 1060 test_configurator()->SetLoopCount(2); |
1059 component_updater()->Start(); | 1061 component_updater()->Start(); |
1060 RunThreads(); | 1062 RunThreads(); |
1061 | 1063 |
| 1064 EXPECT_EQ(4, post_interceptor_->GetHitCount()) |
| 1065 << post_interceptor_->GetRequestsAsString(); |
| 1066 EXPECT_EQ(2, get_interceptor_->GetHitCount()); |
| 1067 |
| 1068 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 1069 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 1070 "<updatecheck /></app>")) |
| 1071 << post_interceptor_->GetRequestsAsString(); |
| 1072 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| 1073 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| 1074 "version=\"0.9\" nextversion=\"1.0\">" |
| 1075 "<event eventtype=\"3\" eventresult=\"0\" " |
| 1076 "errorcat=\"3\" errorcode=\"9\"/></app>")) |
| 1077 << post_interceptor_->GetRequestsAsString(); |
| 1078 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| 1079 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 1080 "<updatecheck /></app>")) |
| 1081 << post_interceptor_->GetRequestsAsString(); |
| 1082 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find( |
| 1083 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" " |
| 1084 "version=\"0.9\" nextversion=\"1.0\">" |
| 1085 "<event eventtype=\"3\" eventresult=\"0\" " |
| 1086 "errorcat=\"3\" errorcode=\"9\"/></app>")) |
| 1087 << post_interceptor_->GetRequestsAsString(); |
| 1088 |
1062 // Loop once more, but expect no ping because a noupdate response is issued. | 1089 // Loop once more, but expect no ping because a noupdate response is issued. |
1063 // This is necessary to clear out the fire-and-forget ping from the previous | 1090 // This is necessary to clear out the fire-and-forget ping from the previous |
1064 // iteration. | 1091 // iteration. |
1065 interceptor.SetResponse(expected_update_url_1, | 1092 post_interceptor_->Reset(); |
1066 test_file("updatecheck_reply_noupdate.xml")); | 1093 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
| 1094 "updatecheck"), test_file("updatecheck_reply_noupdate.xml"))); |
| 1095 |
1067 test_configurator()->SetLoopCount(1); | 1096 test_configurator()->SetLoopCount(1); |
1068 component_updater()->Start(); | 1097 component_updater()->Start(); |
1069 RunThreads(); | 1098 RunThreads(); |
1070 | 1099 |
1071 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 1100 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
1072 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); | 1101 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
1073 | 1102 |
1074 EXPECT_EQ(2, post_interceptor->GetHitCount()) | 1103 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
1075 << post_interceptor->GetRequestsAsString(); | 1104 << post_interceptor_->GetRequestsAsString(); |
1076 EXPECT_EQ(0, post_interceptor->GetMissCount()) | 1105 EXPECT_EQ(1, post_interceptor_->GetCount()) |
1077 << post_interceptor->GetRequestsAsString(); | 1106 << post_interceptor_->GetRequestsAsString(); |
1078 | 1107 |
1079 EXPECT_EQ(5, interceptor.GetHitCount()); | 1108 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 1109 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 1110 "<updatecheck /></app>")) |
| 1111 << post_interceptor_->GetRequestsAsString(); |
1080 | 1112 |
1081 component_updater()->Stop(); | 1113 component_updater()->Stop(); |
1082 } | 1114 } |
1083 | 1115 |
1084 // Verify that we successfully propagate a patcher error. | 1116 // Verify that we successfully propagate a patcher error. |
1085 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect | 1117 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect |
1086 // patching instruction that should fail. | 1118 // patching instruction that should fail. |
1087 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { | 1119 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { |
1088 URLRequestPostInterceptor* post_interceptor( | 1120 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
1089 interceptor_factory_->CreateInterceptor()); | 1121 "updatecheck"), test_file("updatecheck_diff_reply_1.xml"))); |
1090 EXPECT_TRUE(post_interceptor != NULL); | 1122 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
1091 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | 1123 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
1092 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" | 1124 "updatecheck"), test_file("updatecheck_diff_reply_2.xml"))); |
1093 "<o:event eventtype=\"3\" eventresult=\"1\" " | 1125 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch("event"))); |
1094 "previousversion=\"0.0\" nextversion=\"1.0\" nextfp=\"1\"/></o:app>"))); | 1126 EXPECT_TRUE(post_interceptor_->ExpectRequest(new PartialMatch( |
1095 EXPECT_TRUE(post_interceptor->ExpectRequest(new PartialMatch( | 1127 "updatecheck"), test_file("updatecheck_diff_reply_3.xml"))); |
1096 "<o:app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" | |
1097 "<o:event eventtype=\"3\" eventresult=\"1\" " | |
1098 "previousversion=\"1.0\" nextversion=\"2.0\" " | |
1099 "diffresult=\"0\" differrorcat=\"2\" " | |
1100 "differrorcode=\"14\" diffextracode1=\"305\" " | |
1101 "previousfp=\"1\" nextfp=\"f22\"/></o:app>"))); | |
1102 | 1128 |
1103 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 1129 get_interceptor_->SetResponse( |
| 1130 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"), |
| 1131 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| 1132 // This intercept returns a different file than what is specified in the |
| 1133 // update check response and requested in the download. The file that is |
| 1134 // actually dowloaded contains a patching error, an therefore, an error |
| 1135 // is injected at the time of patching. |
| 1136 get_interceptor_->SetResponse( |
| 1137 GURL("http://localhost/download/" |
| 1138 "ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"), |
| 1139 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); |
| 1140 get_interceptor_->SetResponse( |
| 1141 GURL("http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"), |
| 1142 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
1104 | 1143 |
1105 VersionedTestInstaller installer; | 1144 VersionedTestInstaller installer; |
1106 CrxComponent com; | 1145 CrxComponent com; |
1107 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); | 1146 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); |
1108 | 1147 |
1109 const GURL expected_update_url_0( | 1148 test_configurator()->SetLoopCount(3); |
1110 "http://localhost/upd?extra=foo" | |
1111 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); | |
1112 const GURL expected_update_url_1( | |
1113 "http://localhost/upd?extra=foo" | |
1114 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc"); | |
1115 const GURL expected_update_url_2( | |
1116 "http://localhost/upd?extra=foo" | |
1117 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc"); | |
1118 const GURL expected_crx_url_1( | |
1119 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"); | |
1120 const GURL expected_crx_url_1_diff_2( | |
1121 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"); | |
1122 const GURL expected_crx_url_2( | |
1123 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"); | |
1124 | |
1125 interceptor.SetResponse(expected_update_url_0, | |
1126 test_file("updatecheck_diff_reply_1.xml")); | |
1127 interceptor.SetResponse(expected_update_url_1, | |
1128 test_file("updatecheck_diff_reply_2.xml")); | |
1129 interceptor.SetResponse(expected_update_url_2, | |
1130 test_file("updatecheck_diff_reply_3.xml")); | |
1131 interceptor.SetResponse(expected_crx_url_1, | |
1132 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); | |
1133 interceptor.SetResponse( | |
1134 expected_crx_url_1_diff_2, | |
1135 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); | |
1136 interceptor.SetResponse(expected_crx_url_2, | |
1137 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); | |
1138 | |
1139 test_configurator()->SetLoopCount(2); | |
1140 | |
1141 component_updater()->Start(); | 1149 component_updater()->Start(); |
1142 RunThreads(); | 1150 RunThreads(); |
1143 component_updater()->Stop(); | 1151 component_updater()->Stop(); |
1144 // There may still be pings in the queue. | |
1145 RunThreadsUntilIdle(); | |
1146 | 1152 |
1147 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 1153 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
1148 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); | 1154 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
1149 | 1155 |
1150 EXPECT_EQ(2, post_interceptor->GetHitCount()) | 1156 EXPECT_EQ(5, post_interceptor_->GetHitCount()) |
1151 << post_interceptor->GetRequestsAsString(); | 1157 << post_interceptor_->GetRequestsAsString(); |
1152 EXPECT_EQ(0, post_interceptor->GetMissCount()) | 1158 EXPECT_EQ(5, post_interceptor_->GetCount()) |
1153 << post_interceptor->GetRequestsAsString(); | 1159 << post_interceptor_->GetRequestsAsString(); |
| 1160 EXPECT_EQ(3, get_interceptor_->GetHitCount()); |
1154 | 1161 |
1155 EXPECT_EQ(5, interceptor.GetHitCount()); | 1162 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 1163 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"0.0\">" |
| 1164 "<updatecheck /></app>")) |
| 1165 << post_interceptor_->GetRequestsAsString(); |
| 1166 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| 1167 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
| 1168 "version=\"0.0\" nextversion=\"1.0\">" |
| 1169 "<event eventtype=\"3\" eventresult=\"1\" nextfp=\"1\"/></app>")) |
| 1170 << post_interceptor_->GetRequestsAsString(); |
| 1171 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( |
| 1172 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"1.0\">" |
| 1173 "<updatecheck /><packages><package fp=\"1\"/></packages></app>")) |
| 1174 << post_interceptor_->GetRequestsAsString(); |
| 1175 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find( |
| 1176 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" " |
| 1177 "version=\"1.0\" nextversion=\"2.0\">" |
| 1178 "<event eventtype=\"3\" eventresult=\"1\" " |
| 1179 "diffresult=\"0\" differrorcat=\"2\" " |
| 1180 "differrorcode=\"14\" diffextracode1=\"305\" " |
| 1181 "previousfp=\"1\" nextfp=\"22\"/></app>")) |
| 1182 << post_interceptor_->GetRequestsAsString(); |
| 1183 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[4].find( |
| 1184 "<app appid=\"ihfokbkgjpifnbbojhneepfflplebdkc\" version=\"2.0\">" |
| 1185 "<updatecheck /><packages><package fp=\"22\"/></packages></app>")) |
| 1186 << post_interceptor_->GetRequestsAsString(); |
1156 } | 1187 } |
1157 | 1188 |
1158 } // namespace component_updater | 1189 } // namespace component_updater |
1159 | 1190 |
OLD | NEW |