| 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/component_updater_service.h" | 5 #include "chrome/browser/component_updater/component_updater_service.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // are generated. | 238 // are generated. |
| 239 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { | 239 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { |
| 240 MessageLoop message_loop; | 240 MessageLoop message_loop; |
| 241 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 241 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 242 content::TestBrowserThread file_thread(BrowserThread::FILE); | 242 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 243 content::TestBrowserThread io_thread(BrowserThread::IO); | 243 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 244 | 244 |
| 245 io_thread.StartIOThread(); | 245 io_thread.StartIOThread(); |
| 246 file_thread.Start(); | 246 file_thread.Start(); |
| 247 | 247 |
| 248 scoped_refptr<ComponentUpdateInterceptor> | 248 ComponentUpdateInterceptor interceptor; |
| 249 interceptor(new ComponentUpdateInterceptor()); | |
| 250 | 249 |
| 251 CrxComponent com; | 250 CrxComponent com; |
| 252 RegisterComponent(&com, kTestComponent_abag, Version("1.1")); | 251 RegisterComponent(&com, kTestComponent_abag, Version("1.1")); |
| 253 | 252 |
| 254 const char expected_update_url[] = | 253 const char expected_update_url[] = |
| 255 "http://localhost/upd?extra=foo&x=id%3D" | 254 "http://localhost/upd?extra=foo&x=id%3D" |
| 256 "abagagagagagagagagagagagagagagag%26v%3D1.1%26uc"; | 255 "abagagagagagagagagagagagagagagag%26v%3D1.1%26uc"; |
| 257 | 256 |
| 258 interceptor->SetResponse(expected_update_url, | 257 interceptor.SetResponse(expected_update_url, |
| 259 header_ok_reply, | 258 header_ok_reply, |
| 260 test_file("updatecheck_reply_1.xml")); | 259 test_file("updatecheck_reply_1.xml")); |
| 261 | 260 |
| 262 // We loop twice, but there are no updates so we expect two sleep messages. | 261 // We loop twice, but there are no updates so we expect two sleep messages. |
| 263 test_configurator()->SetLoopCount(2); | 262 test_configurator()->SetLoopCount(2); |
| 264 component_updater()->Start(); | 263 component_updater()->Start(); |
| 265 | 264 |
| 266 ASSERT_EQ(1ul, notification_tracker().size()); | 265 ASSERT_EQ(1ul, notification_tracker().size()); |
| 267 TestNotificationTracker::Event ev1 = notification_tracker().at(0); | 266 TestNotificationTracker::Event ev1 = notification_tracker().at(0); |
| 268 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); | 267 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); |
| 269 | 268 |
| 270 message_loop.Run(); | 269 message_loop.Run(); |
| 271 | 270 |
| 272 ASSERT_EQ(3ul, notification_tracker().size()); | 271 ASSERT_EQ(3ul, notification_tracker().size()); |
| 273 TestNotificationTracker::Event ev2 = notification_tracker().at(1); | 272 TestNotificationTracker::Event ev2 = notification_tracker().at(1); |
| 274 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 273 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
| 275 TestNotificationTracker::Event ev3 = notification_tracker().at(2); | 274 TestNotificationTracker::Event ev3 = notification_tracker().at(2); |
| 276 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 275 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
| 277 EXPECT_EQ(2, interceptor->hit_count()); | 276 EXPECT_EQ(2, interceptor.GetHitCount()); |
| 278 | 277 |
| 279 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 278 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 280 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 279 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 281 | 280 |
| 282 component_updater()->Stop(); | 281 component_updater()->Stop(); |
| 283 | 282 |
| 284 // Loop twice again but this case we simulate a server error by returning | 283 // Loop twice again but this case we simulate a server error by returning |
| 285 // an empty file. | 284 // an empty file. |
| 286 | 285 |
| 287 interceptor->SetResponse(expected_update_url, | 286 interceptor.SetResponse(expected_update_url, |
| 288 header_ok_reply, | 287 header_ok_reply, |
| 289 test_file("updatecheck_reply_empty")); | 288 test_file("updatecheck_reply_empty")); |
| 290 | 289 |
| 291 notification_tracker().Reset(); | 290 notification_tracker().Reset(); |
| 292 test_configurator()->SetLoopCount(2); | 291 test_configurator()->SetLoopCount(2); |
| 293 component_updater()->Start(); | 292 component_updater()->Start(); |
| 294 | 293 |
| 295 message_loop.Run(); | 294 message_loop.Run(); |
| 296 | 295 |
| 297 ASSERT_EQ(3ul, notification_tracker().size()); | 296 ASSERT_EQ(3ul, notification_tracker().size()); |
| 298 ev1 = notification_tracker().at(0); | 297 ev1 = notification_tracker().at(0); |
| 299 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); | 298 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); |
| 300 ev2 = notification_tracker().at(1); | 299 ev2 = notification_tracker().at(1); |
| 301 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 300 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
| 302 ev3 = notification_tracker().at(2); | 301 ev3 = notification_tracker().at(2); |
| 303 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 302 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
| 304 EXPECT_EQ(4, interceptor->hit_count()); | 303 EXPECT_EQ(4, interceptor.GetHitCount()); |
| 305 | 304 |
| 306 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 305 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 307 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 306 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 308 | 307 |
| 309 component_updater()->Stop(); | 308 component_updater()->Stop(); |
| 310 } | 309 } |
| 311 | 310 |
| 312 // Verify that we can check for updates and install one component. Besides | 311 // Verify that we can check for updates and install one component. Besides |
| 313 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and | 312 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and |
| 314 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops | 313 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops |
| 315 // so the second time around there should be nothing left to do. | 314 // so the second time around there should be nothing left to do. |
| 316 // We also check that only 3 network requests are issued: | 315 // We also check that only 3 network requests are issued: |
| 317 // 1- manifest check | 316 // 1- manifest check |
| 318 // 2- download crx | 317 // 2- download crx |
| 319 // 3- second manifest check. | 318 // 3- second manifest check. |
| 320 TEST_F(ComponentUpdaterTest, InstallCrx) { | 319 TEST_F(ComponentUpdaterTest, InstallCrx) { |
| 321 MessageLoop message_loop; | 320 MessageLoop message_loop; |
| 322 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 321 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 323 content::TestBrowserThread file_thread(BrowserThread::FILE); | 322 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 324 content::TestBrowserThread io_thread(BrowserThread::IO); | 323 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 325 | 324 |
| 326 io_thread.StartIOThread(); | 325 io_thread.StartIOThread(); |
| 327 file_thread.Start(); | 326 file_thread.Start(); |
| 328 | 327 |
| 329 scoped_refptr<ComponentUpdateInterceptor> | 328 ComponentUpdateInterceptor interceptor; |
| 330 interceptor(new ComponentUpdateInterceptor()); | |
| 331 | 329 |
| 332 CrxComponent com1; | 330 CrxComponent com1; |
| 333 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9")); | 331 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9")); |
| 334 CrxComponent com2; | 332 CrxComponent com2; |
| 335 RegisterComponent(&com2, kTestComponent_abag, Version("2.2")); | 333 RegisterComponent(&com2, kTestComponent_abag, Version("2.2")); |
| 336 | 334 |
| 337 const char expected_update_url_1[] = | 335 const char expected_update_url_1[] = |
| 338 "http://localhost/upd?extra=foo&x=id%3D" | 336 "http://localhost/upd?extra=foo&x=id%3D" |
| 339 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D" | 337 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D" |
| 340 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"; | 338 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"; |
| 341 | 339 |
| 342 const char expected_update_url_2[] = | 340 const char expected_update_url_2[] = |
| 343 "http://localhost/upd?extra=foo&x=id%3D" | 341 "http://localhost/upd?extra=foo&x=id%3D" |
| 344 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D" | 342 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D" |
| 345 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc"; | 343 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc"; |
| 346 | 344 |
| 347 interceptor->SetResponse(expected_update_url_1, header_ok_reply, | 345 interceptor.SetResponse(expected_update_url_1, header_ok_reply, |
| 348 test_file("updatecheck_reply_1.xml")); | 346 test_file("updatecheck_reply_1.xml")); |
| 349 interceptor->SetResponse(expected_update_url_2, header_ok_reply, | 347 interceptor.SetResponse(expected_update_url_2, header_ok_reply, |
| 350 test_file("updatecheck_reply_1.xml")); | 348 test_file("updatecheck_reply_1.xml")); |
| 351 interceptor->SetResponse(expected_crx_url, header_ok_reply, | 349 interceptor.SetResponse(expected_crx_url, header_ok_reply, |
| 352 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 350 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 353 | 351 |
| 354 test_configurator()->SetLoopCount(2); | 352 test_configurator()->SetLoopCount(2); |
| 355 | 353 |
| 356 component_updater()->Start(); | 354 component_updater()->Start(); |
| 357 message_loop.Run(); | 355 message_loop.Run(); |
| 358 | 356 |
| 359 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 357 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 360 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 358 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 361 EXPECT_EQ(3, interceptor->hit_count()); | 359 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 362 | 360 |
| 363 ASSERT_EQ(5ul, notification_tracker().size()); | 361 ASSERT_EQ(5ul, notification_tracker().size()); |
| 364 | 362 |
| 365 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 363 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
| 366 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 364 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
| 367 | 365 |
| 368 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 366 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
| 369 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 367 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
| 370 | 368 |
| 371 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 369 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 382 // version is much higher than of chrome. | 380 // version is much higher than of chrome. |
| 383 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { | 381 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
| 384 MessageLoop message_loop; | 382 MessageLoop message_loop; |
| 385 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 383 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 386 content::TestBrowserThread file_thread(BrowserThread::FILE); | 384 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 387 content::TestBrowserThread io_thread(BrowserThread::IO); | 385 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 388 | 386 |
| 389 io_thread.StartIOThread(); | 387 io_thread.StartIOThread(); |
| 390 file_thread.Start(); | 388 file_thread.Start(); |
| 391 | 389 |
| 392 scoped_refptr<ComponentUpdateInterceptor> | 390 ComponentUpdateInterceptor interceptor; |
| 393 interceptor(new ComponentUpdateInterceptor()); | |
| 394 | 391 |
| 395 CrxComponent com; | 392 CrxComponent com; |
| 396 RegisterComponent(&com, kTestComponent_jebg, Version("0.9")); | 393 RegisterComponent(&com, kTestComponent_jebg, Version("0.9")); |
| 397 | 394 |
| 398 const char expected_update_url[] = | 395 const char expected_update_url[] = |
| 399 "http://localhost/upd?extra=foo&x=id%3D" | 396 "http://localhost/upd?extra=foo&x=id%3D" |
| 400 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc"; | 397 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc"; |
| 401 | 398 |
| 402 interceptor->SetResponse(expected_update_url, | 399 interceptor.SetResponse(expected_update_url, |
| 403 header_ok_reply, | 400 header_ok_reply, |
| 404 test_file("updatecheck_reply_2.xml")); | 401 test_file("updatecheck_reply_2.xml")); |
| 405 interceptor->SetResponse(expected_crx_url, header_ok_reply, | 402 interceptor.SetResponse(expected_crx_url, header_ok_reply, |
| 406 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 403 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 407 | 404 |
| 408 test_configurator()->SetLoopCount(1); | 405 test_configurator()->SetLoopCount(1); |
| 409 component_updater()->Start(); | 406 component_updater()->Start(); |
| 410 message_loop.Run(); | 407 message_loop.Run(); |
| 411 | 408 |
| 412 EXPECT_EQ(1, interceptor->hit_count()); | 409 EXPECT_EQ(1, interceptor.GetHitCount()); |
| 413 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 410 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 414 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 411 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 415 | 412 |
| 416 component_updater()->Stop(); | 413 component_updater()->Stop(); |
| 417 } | 414 } |
| OLD | NEW |