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

Side by Side Diff: chrome/browser/component_updater/test/component_updater_service_unittest.cc

Issue 11859044: Add a way to specify different source urls for the component updater (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 14 matching lines...) Expand all
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 using content::BrowserThread; 27 using content::BrowserThread;
28 using content::TestNotificationTracker; 28 using content::TestNotificationTracker;
29 29
30 namespace { 30 namespace {
31 // Overrides some of the component updater behaviors so it is easier to test 31 // Overrides some of the component updater behaviors so it is easier to test
32 // and loops faster. In actual usage it takes hours do to a full cycle. 32 // and loops faster. In actual usage it takes hours do to a full cycle.
33 class TestConfigurator : public ComponentUpdateService::Configurator { 33 class TestConfigurator : public ComponentUpdateService::Configurator {
34 public: 34 public:
35 TestConfigurator() : times_(1) { 35 TestConfigurator() : times_(1), recheck_time_(0) {
36 } 36 }
37 37
38 virtual int InitialDelay() OVERRIDE { return 0; } 38 virtual int InitialDelay() OVERRIDE { return 0; }
39 39
40 virtual int NextCheckDelay() OVERRIDE { 40 virtual int NextCheckDelay() OVERRIDE {
41 // This is called when a new full cycle of checking for updates is going 41 // This is called when a new full cycle of checking for updates is going
42 // to happen. In test we normally only test one cycle so it is a good 42 // to happen. In test we normally only test one cycle so it is a good
43 // time to break from the test messageloop Run() method so the test can 43 // time to break from the test messageloop Run() method so the test can
44 // finish. 44 // finish.
45 if (--times_ > 0) 45 if (--times_ > 0)
46 return 1; 46 return 1;
47 47
48 MessageLoop::current()->Quit(); 48 MessageLoop::current()->Quit();
49 return 0; 49 return 0;
50 } 50 }
51 51
52 virtual int StepDelay() OVERRIDE { 52 virtual int StepDelay() OVERRIDE {
53 return 0; 53 return 0;
54 } 54 }
55 55
56 virtual int MinimumReCheckWait() OVERRIDE { 56 virtual int MinimumReCheckWait() OVERRIDE {
57 return 0; 57 return recheck_time_;
58 } 58 }
59 59
60 virtual GURL UpdateUrl() OVERRIDE { return GURL("http://localhost/upd"); } 60 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE {
61 switch (source) {
62 case CrxComponent::BANDAID:
63 return GURL("http://localhost/upd");
64 case CrxComponent::CWS_PUBLIC:
65 return GURL("http://localhost/cws");
66 default:
67 return GURL("http://wronghost/bad");
68 };
69 }
61 70
62 virtual const char* ExtraRequestParams() OVERRIDE { return "extra=foo"; } 71 virtual const char* ExtraRequestParams() OVERRIDE { return "extra=foo"; }
63 72
64 virtual size_t UrlSizeLimit() OVERRIDE { return 256; } 73 virtual size_t UrlSizeLimit() OVERRIDE { return 256; }
65 74
66 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE { 75 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE {
67 return new net::TestURLRequestContextGetter( 76 return new net::TestURLRequestContextGetter(
68 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); 77 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
69 } 78 }
70 79
71 // Don't use the utility process to decode files. 80 // Don't use the utility process to decode files.
72 virtual bool InProcess() OVERRIDE { return true; } 81 virtual bool InProcess() OVERRIDE { return true; }
73 82
74 virtual void OnEvent(Events event, int extra) OVERRIDE { } 83 virtual void OnEvent(Events event, int extra) OVERRIDE { }
75 84
76 // Set how many update checks are called, the default value is just once. 85 // Set how many update checks are called, the default value is just once.
77 void SetLoopCount(int times) { times_ = times; } 86 void SetLoopCount(int times) { times_ = times; }
78 87
88 void SetRecheckTime(int seconds) {
89 recheck_time_ = seconds;
90 }
91
79 private: 92 private:
80 int times_; 93 int times_;
94 int recheck_time_;
81 }; 95 };
82 96
83 class TestInstaller : public ComponentInstaller { 97 class TestInstaller : public ComponentInstaller {
84 public : 98 public :
85 explicit TestInstaller() 99 explicit TestInstaller()
86 : error_(0), install_count_(0) { 100 : error_(0), install_count_(0) {
87 } 101 }
88 102
89 virtual void OnUpdateError(int error) OVERRIDE { 103 virtual void OnUpdateError(int error) OVERRIDE {
90 EXPECT_NE(0, error); 104 EXPECT_NE(0, error);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 interceptor.SetResponse(GURL(expected_crx_url), 356 interceptor.SetResponse(GURL(expected_crx_url),
343 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); 357 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
344 358
345 test_configurator()->SetLoopCount(2); 359 test_configurator()->SetLoopCount(2);
346 360
347 component_updater()->Start(); 361 component_updater()->Start();
348 message_loop.Run(); 362 message_loop.Run();
349 363
350 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); 364 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
351 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); 365 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
366 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
367 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
368
352 EXPECT_EQ(3, interceptor.GetHitCount()); 369 EXPECT_EQ(3, interceptor.GetHitCount());
353 370
354 ASSERT_EQ(5ul, notification_tracker().size()); 371 ASSERT_EQ(5ul, notification_tracker().size());
355 372
356 TestNotificationTracker::Event ev1 = notification_tracker().at(1); 373 TestNotificationTracker::Event ev1 = notification_tracker().at(1);
357 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); 374 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type);
358 375
359 TestNotificationTracker::Event ev2 = notification_tracker().at(2); 376 TestNotificationTracker::Event ev2 = notification_tracker().at(2);
360 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); 377 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type);
361 378
362 TestNotificationTracker::Event ev3 = notification_tracker().at(3); 379 TestNotificationTracker::Event ev3 = notification_tracker().at(3);
363 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); 380 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
364 381
365 TestNotificationTracker::Event ev4 = notification_tracker().at(4); 382 TestNotificationTracker::Event ev4 = notification_tracker().at(4);
366 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); 383 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
367 384
368 component_updater()->Stop(); 385 component_updater()->Stop();
369 } 386 }
370 387
388 // This test is like the above InstallCrx but the second component
389 // has a different source. In this case there would be two manifest
390 // checks to different urls, each only containing one component.
391 TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) {
392 MessageLoop message_loop;
393 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
394 content::TestBrowserThread file_thread(BrowserThread::FILE);
395 content::TestBrowserThread io_thread(BrowserThread::IO);
396
397 io_thread.StartIOThread();
398 file_thread.Start();
399
400 content::URLRequestPrepackagedInterceptor interceptor;
401
402 CrxComponent com1;
403 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"));
404 CrxComponent com2;
405 com2.source = CrxComponent::CWS_PUBLIC;
406 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"));
407
408 const GURL expected_update_url_1(
409 "http://localhost/upd?extra=foo&x=id%3D"
410 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc");
411
412 const GURL expected_update_url_2(
413 "http://localhost/cws?extra=foo&x=id%3D"
414 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc");
415
416 interceptor.SetResponse(expected_update_url_1,
417 test_file("updatecheck_reply_3.xml"));
418 interceptor.SetResponse(expected_update_url_2,
419 test_file("updatecheck_reply_1.xml"));
420 interceptor.SetResponse(GURL(expected_crx_url),
421 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
422
423 test_configurator()->SetLoopCount(3);
424
425 // We have to set SetRecheckTime to something bigger than 0 or else the
426 // component updater will keep re-checking the 'abag' component because
427 // the default source pre-empts the other sources.
428 test_configurator()->SetRecheckTime(60*60);
429
430 component_updater()->Start();
431 message_loop.Run();
432
433 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
434 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
435 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
436 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count());
437
438 EXPECT_EQ(3, interceptor.GetHitCount());
439
440 ASSERT_EQ(6ul, notification_tracker().size());
441
442 TestNotificationTracker::Event ev0 = notification_tracker().at(1);
443 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev0.type);
444
445 TestNotificationTracker::Event ev1 = notification_tracker().at(2);
446 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type);
447
448 TestNotificationTracker::Event ev2 = notification_tracker().at(3);
449 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type);
450
451 TestNotificationTracker::Event ev3 = notification_tracker().at(4);
452 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
453
454 TestNotificationTracker::Event ev4 = notification_tracker().at(5);
455 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
456
457 component_updater()->Stop();
458 }
459
371 // This test checks that the "prodversionmin" value is handled correctly. In 460 // This test checks that the "prodversionmin" value is handled correctly. In
372 // particular there should not be an install because the minimum product 461 // particular there should not be an install because the minimum product
373 // version is much higher than of chrome. 462 // version is much higher than of chrome.
374 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { 463 TEST_F(ComponentUpdaterTest, ProdVersionCheck) {
375 MessageLoop message_loop; 464 MessageLoop message_loop;
376 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 465 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
377 content::TestBrowserThread file_thread(BrowserThread::FILE); 466 content::TestBrowserThread file_thread(BrowserThread::FILE);
378 content::TestBrowserThread io_thread(BrowserThread::IO); 467 content::TestBrowserThread io_thread(BrowserThread::IO);
379 468
380 io_thread.StartIOThread(); 469 io_thread.StartIOThread();
(...skipping 16 matching lines...) Expand all
397 test_configurator()->SetLoopCount(1); 486 test_configurator()->SetLoopCount(1);
398 component_updater()->Start(); 487 component_updater()->Start();
399 message_loop.Run(); 488 message_loop.Run();
400 489
401 EXPECT_EQ(1, interceptor.GetHitCount()); 490 EXPECT_EQ(1, interceptor.GetHitCount());
402 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); 491 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
403 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); 492 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count());
404 493
405 component_updater()->Stop(); 494 component_updater()->Stop();
406 } 495 }
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/component_updater_service.cc ('k') | chrome/test/data/components/updatecheck_reply_3.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698