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

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

Issue 13071002: Turn on component updater on chromeos, only for the pnacl component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: debug Created 7 years, 8 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 <list> 7 #include <list>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 228 }
229 229
230 TestNotificationTracker& notification_tracker() { 230 TestNotificationTracker& notification_tracker() {
231 return notification_tracker_; 231 return notification_tracker_;
232 } 232 }
233 233
234 TestConfigurator* test_configurator() { 234 TestConfigurator* test_configurator() {
235 return test_config_; 235 return test_config_;
236 } 236 }
237 237
238 void RegisterComponent(CrxComponent* com, 238 ComponentUpdateService::Status RegisterComponent(CrxComponent* com,
239 TestComponents component, 239 TestComponents component,
240 const Version& version) { 240 const Version& version) {
241 if (component == kTestComponent_abag) { 241 if (component == kTestComponent_abag) {
242 com->name = "test_abag"; 242 com->name = "test_abag";
243 com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash)); 243 com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash));
244 } else { 244 } else {
245 com->name = "test_jebg"; 245 com->name = "test_jebg";
246 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); 246 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
247 } 247 }
248 com->version = version; 248 com->version = version;
249 TestInstaller* installer = new TestInstaller; 249 TestInstaller* installer = new TestInstaller;
250 com->installer = installer; 250 com->installer = installer;
251 test_installers_.push_back(installer); 251 test_installers_.push_back(installer);
252 component_updater_->RegisterComponent(*com); 252 return component_updater_->RegisterComponent(*com);
253 } 253 }
254 254
255 private: 255 private:
256 scoped_ptr<ComponentUpdateService> component_updater_; 256 scoped_ptr<ComponentUpdateService> component_updater_;
257 base::FilePath test_data_dir_; 257 base::FilePath test_data_dir_;
258 TestNotificationTracker notification_tracker_; 258 TestNotificationTracker notification_tracker_;
259 TestConfigurator* test_config_; 259 TestConfigurator* test_config_;
260 // ComponentInstaller objects to delete after each test. 260 // ComponentInstaller objects to delete after each test.
261 ScopedVector<TestInstaller> test_installers_; 261 ScopedVector<TestInstaller> test_installers_;
262 }; 262 };
(...skipping 27 matching lines...) Expand all
290 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 290 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
291 content::TestBrowserThread file_thread(BrowserThread::FILE); 291 content::TestBrowserThread file_thread(BrowserThread::FILE);
292 content::TestBrowserThread io_thread(BrowserThread::IO); 292 content::TestBrowserThread io_thread(BrowserThread::IO);
293 293
294 io_thread.StartIOThread(); 294 io_thread.StartIOThread();
295 file_thread.Start(); 295 file_thread.Start();
296 296
297 content::URLRequestPrepackagedInterceptor interceptor; 297 content::URLRequestPrepackagedInterceptor interceptor;
298 298
299 CrxComponent com; 299 CrxComponent com;
300 RegisterComponent(&com, kTestComponent_abag, Version("1.1")); 300 EXPECT_EQ(ComponentUpdateService::kOk,
301 RegisterComponent(&com, kTestComponent_abag, Version("1.1")));
301 302
302 const GURL expected_update_url( 303 const GURL expected_update_url(
303 "http://localhost/upd?extra=foo&x=id%3D" 304 "http://localhost/upd?extra=foo&x=id%3D"
304 "abagagagagagagagagagagagagagagag%26v%3D1.1%26uc"); 305 "abagagagagagagagagagagagagagagag%26v%3D1.1%26uc");
305 306
306 interceptor.SetResponse(expected_update_url, 307 interceptor.SetResponse(expected_update_url,
307 test_file("updatecheck_reply_1.xml")); 308 test_file("updatecheck_reply_1.xml"));
308 309
309 // We loop twice, but there are no updates so we expect two sleep messages. 310 // We loop twice, but there are no updates so we expect two sleep messages.
310 test_configurator()->SetLoopCount(2); 311 test_configurator()->SetLoopCount(2);
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 647
647 message_loop.Run(); 648 message_loop.Run();
648 649
649 ASSERT_EQ(2ul, notification_tracker().size()); 650 ASSERT_EQ(2ul, notification_tracker().size());
650 ev0 = notification_tracker().at(0); 651 ev0 = notification_tracker().at(0);
651 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); 652 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
652 ev1 = notification_tracker().at(1); 653 ev1 = notification_tracker().at(1);
653 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); 654 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
654 component_updater()->Stop(); 655 component_updater()->Stop();
655 } 656 }
657
658 // Verify that a previously registered component can get re-registered
659 // with a different version.
660 TEST_F(ComponentUpdaterTest, CheckReRegistration) {
661 MessageLoop message_loop;
662 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
663 content::TestBrowserThread file_thread(BrowserThread::FILE);
664 content::TestBrowserThread io_thread(BrowserThread::IO);
665
666 io_thread.StartIOThread();
667 file_thread.Start();
668
669 content::URLRequestPrepackagedInterceptor interceptor;
670
671 CrxComponent com1;
672 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"));
673 CrxComponent com2;
674 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"));
675
676 // Start with 0.9, and update to 1.0
677 const GURL expected_update_url_1(
678 "http://localhost/upd?extra=foo&x=id%3D"
679 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D"
680 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc");
681
682 const GURL expected_update_url_2(
683 "http://localhost/upd?extra=foo&x=id%3D"
684 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D"
685 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc");
686
687 interceptor.SetResponse(expected_update_url_1,
688 test_file("updatecheck_reply_1.xml"));
689 interceptor.SetResponse(expected_update_url_2,
690 test_file("updatecheck_reply_1.xml"));
691 interceptor.SetResponse(GURL(expected_crx_url),
692 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx"));
693
694 // Loop twice to issue two checks: (1) with original 0.9 version
695 // and (2) with the updated 1.0 version.
696 test_configurator()->SetLoopCount(2);
697
698 component_updater()->Start();
699 message_loop.Run();
700
701 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
702 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count());
703 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
704 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
705
706 EXPECT_EQ(3, interceptor.GetHitCount());
707
708 ASSERT_EQ(5ul, notification_tracker().size());
709
710 TestNotificationTracker::Event ev0 = notification_tracker().at(0);
711 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
712
713 TestNotificationTracker::Event ev1 = notification_tracker().at(1);
714 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type);
715
716 TestNotificationTracker::Event ev2 = notification_tracker().at(2);
717 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type);
718
719 TestNotificationTracker::Event ev3 = notification_tracker().at(3);
720 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type);
721
722 TestNotificationTracker::Event ev4 = notification_tracker().at(4);
723 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
724
725 // Now re-register, pretending to be an even newer version (2.2)
726 component_updater()->Stop();
727 EXPECT_EQ(ComponentUpdateService::kReplaced,
728 RegisterComponent(&com1, kTestComponent_jebg, Version("2.2")));
729
730 // Check that we send out 2.2 as our version.
731 // Interceptor's hit count should go up by 1.
732 const GURL expected_update_url_3(
733 "http://localhost/upd?extra=foo&x=id%3D"
734 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D2.2%26uc&x=id%3D"
735 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc");
736
737 interceptor.SetResponse(expected_update_url_3,
738 test_file("updatecheck_reply_1.xml"));
739
740 notification_tracker().Reset();
741
742 // Loop once just to notice the check happening with the re-register version.
743 test_configurator()->SetLoopCount(1);
744 component_updater()->Start();
745 message_loop.Run();
746
747 ASSERT_EQ(2ul, notification_tracker().size());
748
749 ev0 = notification_tracker().at(0);
750 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type);
751
752 ev1 = notification_tracker().at(1);
753 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type);
754
755 EXPECT_EQ(4, interceptor.GetHitCount());
756
757 // The test harness's Register() function creates a new installer,
758 // so the counts go back to 0.
759 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
760 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
761 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
762 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count());
763
764 component_updater()->Stop();
765 }
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/pnacl/pnacl_profile_observer.cc ('k') | chrome/browser/profiles/profile_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698