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

Side by Side Diff: components/update_client/update_client_unittest.cc

Issue 1112623002: Eliminate component/update_client dependency on content/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « components/update_client/DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/test/sequenced_worker_pool_owner.h"
15 #include "base/thread_task_runner_handle.h" 16 #include "base/thread_task_runner_handle.h"
17 #include "base/threading/thread.h"
16 #include "base/values.h" 18 #include "base/values.h"
17 #include "base/version.h" 19 #include "base/version.h"
18 #include "components/update_client/crx_update_item.h" 20 #include "components/update_client/crx_update_item.h"
19 #include "components/update_client/ping_manager.h" 21 #include "components/update_client/ping_manager.h"
20 #include "components/update_client/test_configurator.h" 22 #include "components/update_client/test_configurator.h"
21 #include "components/update_client/test_installer.h" 23 #include "components/update_client/test_installer.h"
22 #include "components/update_client/update_checker.h" 24 #include "components/update_client/update_checker.h"
23 #include "components/update_client/update_client_internal.h" 25 #include "components/update_client/update_client_internal.h"
24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/test/test_browser_thread_bundle.h"
26 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "url/gurl.h" 28 #include "url/gurl.h"
29 29
30 namespace update_client { 30 namespace update_client {
31 31
32 namespace { 32 namespace {
33 33
34 using base::FilePath; 34 using base::FilePath;
35 35
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } // namespace 97 } // namespace
98 98
99 using ::testing::_; 99 using ::testing::_;
100 using ::testing::AnyNumber; 100 using ::testing::AnyNumber;
101 using ::testing::DoAll; 101 using ::testing::DoAll;
102 using ::testing::InSequence; 102 using ::testing::InSequence;
103 using ::testing::Invoke; 103 using ::testing::Invoke;
104 using ::testing::Mock; 104 using ::testing::Mock;
105 using ::testing::Return; 105 using ::testing::Return;
106 106
107 using content::BrowserThread;
108
109 using std::string; 107 using std::string;
110 108
111 class UpdateClientTest : public testing::Test { 109 class UpdateClientTest : public testing::Test {
112 public: 110 public:
113 UpdateClientTest(); 111 UpdateClientTest();
114 ~UpdateClientTest() override; 112 ~UpdateClientTest() override;
115 113
116 void SetUp() override;
117 void TearDown() override;
118
119 protected: 114 protected:
120 void RunThreads(); 115 void RunThreads();
121 116
122 // Returns the full path to a test file. 117 // Returns the full path to a test file.
123 static base::FilePath TestFilePath(const char* file); 118 static base::FilePath TestFilePath(const char* file);
124 119
125 content::TestBrowserThreadBundle thread_bundle_; 120 scoped_refptr<update_client::Configurator> config() { return config_; }
126 121
122 base::Closure quit_closure() { return quit_closure_; }
123
124 private:
125 static const int kNumWorkerThreads_ = 2;
126
127 base::MessageLoopForUI message_loop_;
127 base::RunLoop runloop_; 128 base::RunLoop runloop_;
128 base::Closure quit_closure_; 129 base::Closure quit_closure_;
129 130
130 scoped_refptr<update_client::TestConfigurator> config_; 131 scoped_ptr<base::SequencedWorkerPoolOwner> worker_pool_;
132 scoped_ptr<base::Thread> thread_;
131 133
132 private: 134 scoped_refptr<update_client::Configurator> config_;
135
133 DISALLOW_COPY_AND_ASSIGN(UpdateClientTest); 136 DISALLOW_COPY_AND_ASSIGN(UpdateClientTest);
134 }; 137 };
135 138
136 UpdateClientTest::UpdateClientTest() 139 UpdateClientTest::UpdateClientTest()
137 : config_(new TestConfigurator( 140 : worker_pool_(
138 BrowserThread::GetBlockingPool() 141 new base::SequencedWorkerPoolOwner(kNumWorkerThreads_, "test")),
139 ->GetSequencedTaskRunnerWithShutdownBehavior( 142 thread_(new base::Thread("test")) {
140 BrowserThread::GetBlockingPool()->GetSequenceToken(), 143 quit_closure_ = runloop_.QuitClosure();
141 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN), 144
142 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) { 145 thread_->Start();
146
147 auto pool = worker_pool_->pool();
148 config_ = new TestConfigurator(
149 pool->GetSequencedTaskRunner(pool->GetSequenceToken()),
150 thread_->task_runner());
143 } 151 }
144 152
145 UpdateClientTest::~UpdateClientTest() { 153 UpdateClientTest::~UpdateClientTest() {
146 } 154 config_ = nullptr;
147 155 thread_->Stop();
148 void UpdateClientTest::SetUp() { 156 worker_pool_->pool()->Shutdown();
149 quit_closure_ = runloop_.QuitClosure();
150 }
151
152 void UpdateClientTest::TearDown() {
153 } 157 }
154 158
155 void UpdateClientTest::RunThreads() { 159 void UpdateClientTest::RunThreads() {
156 runloop_.Run(); 160 runloop_.Run();
157 } 161 }
158 162
159 base::FilePath UpdateClientTest::TestFilePath(const char* file) { 163 base::FilePath UpdateClientTest::TestFilePath(const char* file) {
160 base::FilePath path; 164 base::FilePath path;
161 PathService::Get(base::DIR_SOURCE_ROOT, &path); 165 PathService::Get(base::DIR_SOURCE_ROOT, &path);
162 return path.AppendASCII("components") 166 return path.AppendASCII("components")
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } 229 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); }
226 }; 230 };
227 231
228 class FakePingManager : public FakePingManagerImpl { 232 class FakePingManager : public FakePingManagerImpl {
229 public: 233 public:
230 explicit FakePingManager(const Configurator& config) 234 explicit FakePingManager(const Configurator& config)
231 : FakePingManagerImpl(config) {} 235 : FakePingManagerImpl(config) {}
232 ~FakePingManager() override { EXPECT_TRUE(items().empty()); } 236 ~FakePingManager() override { EXPECT_TRUE(items().empty()); }
233 }; 237 };
234 238
235 scoped_ptr<PingManager> ping_manager(new FakePingManager(*config_)); 239 scoped_ptr<PingManager> ping_manager(new FakePingManager(*config()));
236 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( 240 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl(
237 config_, ping_manager.Pass(), &FakeUpdateChecker::Create, 241 config(), ping_manager.Pass(), &FakeUpdateChecker::Create,
238 &FakeCrxDownloader::Create)); 242 &FakeCrxDownloader::Create));
239 243
240 MockObserver observer; 244 MockObserver observer;
241 InSequence seq; 245 InSequence seq;
242 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, 246 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES,
243 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); 247 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1);
244 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, 248 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED,
245 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); 249 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1);
246 250
247 update_client->AddObserver(&observer); 251 update_client->AddObserver(&observer);
248 252
249 std::vector<std::string> ids; 253 std::vector<std::string> ids;
250 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); 254 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf"));
251 255
252 update_client->Update( 256 update_client->Update(
253 ids, base::Bind(&DataCallbackFake::Callback), 257 ids, base::Bind(&DataCallbackFake::Callback),
254 base::Bind(&CompletionCallbackFake::Callback, quit_closure_)); 258 base::Bind(&CompletionCallbackFake::Callback, quit_closure()));
255 259
256 RunThreads(); 260 RunThreads();
257 261
258 update_client->RemoveObserver(&observer); 262 update_client->RemoveObserver(&observer);
259 } 263 }
260 264
261 // Tests the scenario where two CRXs are checked for updates. On CRX has 265 // Tests the scenario where two CRXs are checked for updates. On CRX has
262 // an update, the other CRX does not. 266 // an update, the other CRX does not.
263 TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { 267 TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) {
264 class DataCallbackFake { 268 class DataCallbackFake {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 const auto& ping_items = items(); 395 const auto& ping_items = items();
392 EXPECT_EQ(1U, ping_items.size()); 396 EXPECT_EQ(1U, ping_items.size());
393 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id); 397 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id);
394 EXPECT_TRUE(base::Version("0.9").Equals(ping_items[0].previous_version)); 398 EXPECT_TRUE(base::Version("0.9").Equals(ping_items[0].previous_version));
395 EXPECT_TRUE(base::Version("1.0").Equals(ping_items[0].next_version)); 399 EXPECT_TRUE(base::Version("1.0").Equals(ping_items[0].next_version));
396 EXPECT_EQ(0, ping_items[0].error_category); 400 EXPECT_EQ(0, ping_items[0].error_category);
397 EXPECT_EQ(0, ping_items[0].error_code); 401 EXPECT_EQ(0, ping_items[0].error_code);
398 } 402 }
399 }; 403 };
400 404
401 scoped_ptr<PingManager> ping_manager(new FakePingManager(*config_)); 405 scoped_ptr<PingManager> ping_manager(new FakePingManager(*config()));
402 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( 406 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl(
403 config_, ping_manager.Pass(), &FakeUpdateChecker::Create, 407 config(), ping_manager.Pass(), &FakeUpdateChecker::Create,
404 &FakeCrxDownloader::Create)); 408 &FakeCrxDownloader::Create));
405 409
406 MockObserver observer; 410 MockObserver observer;
407 { 411 {
408 InSequence seq; 412 InSequence seq;
409 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, 413 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES,
410 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); 414 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1);
411 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, 415 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND,
412 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); 416 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1);
413 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, 417 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING,
(...skipping 12 matching lines...) Expand all
426 } 430 }
427 431
428 update_client->AddObserver(&observer); 432 update_client->AddObserver(&observer);
429 433
430 std::vector<std::string> ids; 434 std::vector<std::string> ids;
431 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); 435 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf"));
432 ids.push_back(std::string("abagagagagagagagagagagagagagagag")); 436 ids.push_back(std::string("abagagagagagagagagagagagagagagag"));
433 437
434 update_client->Update( 438 update_client->Update(
435 ids, base::Bind(&DataCallbackFake::Callback), 439 ids, base::Bind(&DataCallbackFake::Callback),
436 base::Bind(&CompletionCallbackFake::Callback, quit_closure_)); 440 base::Bind(&CompletionCallbackFake::Callback, quit_closure()));
437 441
438 RunThreads(); 442 RunThreads();
439 443
440 update_client->RemoveObserver(&observer); 444 update_client->RemoveObserver(&observer);
441 } 445 }
442 446
443 // Tests the update check for two CRXs scenario. Both CRXs have updates. 447 // Tests the update check for two CRXs scenario. Both CRXs have updates.
444 TEST_F(UpdateClientTest, TwoCrxUpdate) { 448 TEST_F(UpdateClientTest, TwoCrxUpdate) {
445 class DataCallbackFake { 449 class DataCallbackFake {
446 public: 450 public:
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 EXPECT_EQ(0, ping_items[0].error_category); 624 EXPECT_EQ(0, ping_items[0].error_category);
621 EXPECT_EQ(0, ping_items[0].error_code); 625 EXPECT_EQ(0, ping_items[0].error_code);
622 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[1].id); 626 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[1].id);
623 EXPECT_TRUE(base::Version("0.8").Equals(ping_items[1].previous_version)); 627 EXPECT_TRUE(base::Version("0.8").Equals(ping_items[1].previous_version));
624 EXPECT_TRUE(base::Version("1.0").Equals(ping_items[1].next_version)); 628 EXPECT_TRUE(base::Version("1.0").Equals(ping_items[1].next_version));
625 EXPECT_EQ(0, ping_items[1].error_category); 629 EXPECT_EQ(0, ping_items[1].error_category);
626 EXPECT_EQ(0, ping_items[1].error_code); 630 EXPECT_EQ(0, ping_items[1].error_code);
627 } 631 }
628 }; 632 };
629 633
630 scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config_)); 634 scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config()));
631 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( 635 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl(
632 config_, ping_manager.Pass(), &FakeUpdateChecker::Create, 636 config(), ping_manager.Pass(), &FakeUpdateChecker::Create,
633 &FakeCrxDownloader::Create)); 637 &FakeCrxDownloader::Create));
634 638
635 MockObserver observer; 639 MockObserver observer;
636 { 640 {
637 InSequence seq; 641 InSequence seq;
638 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, 642 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES,
639 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); 643 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1);
640 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, 644 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND,
641 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); 645 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1);
642 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, 646 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING,
(...skipping 20 matching lines...) Expand all
663 } 667 }
664 668
665 update_client->AddObserver(&observer); 669 update_client->AddObserver(&observer);
666 670
667 std::vector<std::string> ids; 671 std::vector<std::string> ids;
668 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); 672 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf"));
669 ids.push_back(std::string("ihfokbkgjpifnbbojhneepfflplebdkc")); 673 ids.push_back(std::string("ihfokbkgjpifnbbojhneepfflplebdkc"));
670 674
671 update_client->Update( 675 update_client->Update(
672 ids, base::Bind(&DataCallbackFake::Callback), 676 ids, base::Bind(&DataCallbackFake::Callback),
673 base::Bind(&CompletionCallbackFake::Callback, quit_closure_)); 677 base::Bind(&CompletionCallbackFake::Callback, quit_closure()));
674 678
675 RunThreads(); 679 RunThreads();
676 680
677 update_client->RemoveObserver(&observer); 681 update_client->RemoveObserver(&observer);
678 } 682 }
679 683
680 // Tests the differential update scenario for one CRX. 684 // Tests the differential update scenario for one CRX.
681 TEST_F(UpdateClientTest, OneCrxDiffUpdate) { 685 TEST_F(UpdateClientTest, OneCrxDiffUpdate) {
682 class DataCallbackFake { 686 class DataCallbackFake {
683 public: 687 public:
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 EXPECT_EQ(0, ping_items[0].error_category); 885 EXPECT_EQ(0, ping_items[0].error_category);
882 EXPECT_EQ(0, ping_items[0].error_code); 886 EXPECT_EQ(0, ping_items[0].error_code);
883 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[1].id); 887 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[1].id);
884 EXPECT_TRUE(base::Version("1.0").Equals(ping_items[1].previous_version)); 888 EXPECT_TRUE(base::Version("1.0").Equals(ping_items[1].previous_version));
885 EXPECT_TRUE(base::Version("2.0").Equals(ping_items[1].next_version)); 889 EXPECT_TRUE(base::Version("2.0").Equals(ping_items[1].next_version));
886 EXPECT_EQ(0, ping_items[1].diff_error_category); 890 EXPECT_EQ(0, ping_items[1].diff_error_category);
887 EXPECT_EQ(0, ping_items[1].diff_error_code); 891 EXPECT_EQ(0, ping_items[1].diff_error_code);
888 } 892 }
889 }; 893 };
890 894
891 scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config_)); 895 scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config()));
892 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( 896 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl(
893 config_, ping_manager.Pass(), &FakeUpdateChecker::Create, 897 config(), ping_manager.Pass(), &FakeUpdateChecker::Create,
894 &FakeCrxDownloader::Create)); 898 &FakeCrxDownloader::Create));
895 899
896 MockObserver observer; 900 MockObserver observer;
897 { 901 {
898 InSequence seq; 902 InSequence seq;
899 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, 903 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES,
900 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); 904 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1);
901 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, 905 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND,
902 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); 906 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1);
903 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, 907 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 const auto& ping_items = items(); 1098 const auto& ping_items = items();
1095 EXPECT_EQ(1U, ping_items.size()); 1099 EXPECT_EQ(1U, ping_items.size());
1096 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id); 1100 EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", ping_items[0].id);
1097 EXPECT_TRUE(base::Version("0.9").Equals(ping_items[0].previous_version)); 1101 EXPECT_TRUE(base::Version("0.9").Equals(ping_items[0].previous_version));
1098 EXPECT_TRUE(base::Version("1.0").Equals(ping_items[0].next_version)); 1102 EXPECT_TRUE(base::Version("1.0").Equals(ping_items[0].next_version));
1099 EXPECT_EQ(3, ping_items[0].error_category); // kInstallError. 1103 EXPECT_EQ(3, ping_items[0].error_category); // kInstallError.
1100 EXPECT_EQ(9, ping_items[0].error_code); // kInstallerError. 1104 EXPECT_EQ(9, ping_items[0].error_code); // kInstallerError.
1101 } 1105 }
1102 }; 1106 };
1103 1107
1104 scoped_ptr<PingManager> ping_manager(new FakePingManager(*config_)); 1108 scoped_ptr<PingManager> ping_manager(new FakePingManager(*config()));
1105 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( 1109 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl(
1106 config_, ping_manager.Pass(), &FakeUpdateChecker::Create, 1110 config(), ping_manager.Pass(), &FakeUpdateChecker::Create,
1107 &FakeCrxDownloader::Create)); 1111 &FakeCrxDownloader::Create));
1108 1112
1109 MockObserver observer; 1113 MockObserver observer;
1110 { 1114 {
1111 InSequence seq; 1115 InSequence seq;
1112 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, 1116 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES,
1113 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); 1117 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1);
1114 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, 1118 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND,
1115 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); 1119 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1);
1116 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, 1120 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING,
1117 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); 1121 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1);
1118 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY, 1122 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_READY,
1119 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); 1123 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1);
1120 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, 1124 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED,
1121 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1); 1125 "jebgalgnebhfojomionfpkfelancnnkf")).Times(1);
1122 } 1126 }
1123 1127
1124 update_client->AddObserver(&observer); 1128 update_client->AddObserver(&observer);
1125 1129
1126 std::vector<std::string> ids; 1130 std::vector<std::string> ids;
1127 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); 1131 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf"));
1128 1132
1129 update_client->Update( 1133 update_client->Update(
1130 ids, base::Bind(&DataCallbackFake::Callback), 1134 ids, base::Bind(&DataCallbackFake::Callback),
1131 base::Bind(&CompletionCallbackFake::Callback, quit_closure_)); 1135 base::Bind(&CompletionCallbackFake::Callback, quit_closure()));
1132 1136
1133 RunThreads(); 1137 RunThreads();
1134 1138
1135 update_client->RemoveObserver(&observer); 1139 update_client->RemoveObserver(&observer);
1136 } 1140 }
1137 1141
1138 // Tests the fallback from differential to full update scenario for one CRX. 1142 // Tests the fallback from differential to full update scenario for one CRX.
1139 TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { 1143 TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) {
1140 class DataCallbackFake { 1144 class DataCallbackFake {
1141 public: 1145 public:
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 EXPECT_EQ(0, ping_items[0].error_code); 1359 EXPECT_EQ(0, ping_items[0].error_code);
1356 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[1].id); 1360 EXPECT_EQ("ihfokbkgjpifnbbojhneepfflplebdkc", ping_items[1].id);
1357 EXPECT_TRUE(base::Version("1.0").Equals(ping_items[1].previous_version)); 1361 EXPECT_TRUE(base::Version("1.0").Equals(ping_items[1].previous_version));
1358 EXPECT_TRUE(base::Version("2.0").Equals(ping_items[1].next_version)); 1362 EXPECT_TRUE(base::Version("2.0").Equals(ping_items[1].next_version));
1359 EXPECT_TRUE(ping_items[1].diff_update_failed); 1363 EXPECT_TRUE(ping_items[1].diff_update_failed);
1360 EXPECT_EQ(1, ping_items[1].diff_error_category); // kNetworkError. 1364 EXPECT_EQ(1, ping_items[1].diff_error_category); // kNetworkError.
1361 EXPECT_EQ(-1, ping_items[1].diff_error_code); 1365 EXPECT_EQ(-1, ping_items[1].diff_error_code);
1362 } 1366 }
1363 }; 1367 };
1364 1368
1365 scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config_)); 1369 scoped_ptr<FakePingManager> ping_manager(new FakePingManager(*config()));
1366 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl( 1370 scoped_ptr<UpdateClient> update_client(new UpdateClientImpl(
1367 config_, ping_manager.Pass(), &FakeUpdateChecker::Create, 1371 config(), ping_manager.Pass(), &FakeUpdateChecker::Create,
1368 &FakeCrxDownloader::Create)); 1372 &FakeCrxDownloader::Create));
1369 1373
1370 MockObserver observer; 1374 MockObserver observer;
1371 { 1375 {
1372 InSequence seq; 1376 InSequence seq;
1373 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, 1377 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES,
1374 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); 1378 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1);
1375 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND, 1379 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_FOUND,
1376 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1); 1380 "ihfokbkgjpifnbbojhneepfflplebdkc")).Times(1);
1377 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING, 1381 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_UPDATE_DOWNLOADING,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 update_client->Update( 1417 update_client->Update(
1414 ids, base::Bind(&DataCallbackFake::Callback), 1418 ids, base::Bind(&DataCallbackFake::Callback),
1415 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); 1419 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure()));
1416 runloop.Run(); 1420 runloop.Run();
1417 } 1421 }
1418 1422
1419 update_client->RemoveObserver(&observer); 1423 update_client->RemoveObserver(&observer);
1420 } 1424 }
1421 1425
1422 } // namespace update_client 1426 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698