| 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 <list> | 5 #include <list> |
| 6 #include <utility> | 6 #include <utility> |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 void TestConfigurator::AddComponentToCheck(CrxComponent* com, | 129 void TestConfigurator::AddComponentToCheck(CrxComponent* com, |
| 130 int at_loop_iter) { | 130 int at_loop_iter) { |
| 131 components_to_check_.push_back(std::make_pair(com, at_loop_iter)); | 131 components_to_check_.push_back(std::make_pair(com, at_loop_iter)); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { | 134 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { |
| 135 cus_ = cus; | 135 cus_ = cus; |
| 136 } | 136 } |
| 137 | 137 |
| 138 TestUpdateNotificationTracker::TestUpdateNotificationTracker() {} |
| 139 |
| 140 TestUpdateNotificationTracker::~TestUpdateNotificationTracker() {} |
| 141 |
| 142 ComponentUpdateService::UpdateSource |
| 143 TestUpdateNotificationTracker::SourceAt(size_t num) { |
| 144 return sources_[num]; |
| 145 } |
| 146 |
| 147 void TestUpdateNotificationTracker::Observe( |
| 148 int type, |
| 149 const content::NotificationSource& source, |
| 150 const content::NotificationDetails& details) { |
| 151 if (type == chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND |
| 152 || type == chrome::NOTIFICATION_COMPONENT_UPDATE_READY) { |
| 153 sources_.push_back(ComponentUpdateService::UpdateSource( |
| 154 *content::Source<ComponentUpdateService::UpdateSource>( |
| 155 source).ptr())); |
| 156 } else |
| 157 sources_.push_back(ComponentUpdateService::UpdateSource()); |
| 158 TestNotificationTracker::Observe(type, source, details); |
| 159 } |
| 160 |
| 161 void TestUpdateNotificationTracker::Reset() { |
| 162 sources_.clear(); |
| 163 TestNotificationTracker::Reset(); |
| 164 } |
| 165 |
| 138 ComponentUpdaterTest::ComponentUpdaterTest() : test_config_(NULL) { | 166 ComponentUpdaterTest::ComponentUpdaterTest() : test_config_(NULL) { |
| 139 // The component updater instance under test. | 167 // The component updater instance under test. |
| 140 test_config_ = new TestConfigurator; | 168 test_config_ = new TestConfigurator; |
| 141 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); | 169 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); |
| 142 test_config_->SetComponentUpdateService(component_updater_.get()); | 170 test_config_->SetComponentUpdateService(component_updater_.get()); |
| 143 // The test directory is chrome/test/data/components. | 171 // The test directory is chrome/test/data/components. |
| 144 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 172 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| 145 test_data_dir_ = test_data_dir_.AppendASCII("components"); | 173 test_data_dir_ = test_data_dir_.AppendASCII("components"); |
| 146 | 174 |
| 147 // Subscribe to all component updater notifications. | 175 // Subscribe to all component updater notifications. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 169 | 197 |
| 170 ComponentUpdateService* ComponentUpdaterTest::component_updater() { | 198 ComponentUpdateService* ComponentUpdaterTest::component_updater() { |
| 171 return component_updater_.get(); | 199 return component_updater_.get(); |
| 172 } | 200 } |
| 173 | 201 |
| 174 // Makes the full path to a component updater test file. | 202 // Makes the full path to a component updater test file. |
| 175 const base::FilePath ComponentUpdaterTest::test_file(const char* file) { | 203 const base::FilePath ComponentUpdaterTest::test_file(const char* file) { |
| 176 return test_data_dir_.AppendASCII(file); | 204 return test_data_dir_.AppendASCII(file); |
| 177 } | 205 } |
| 178 | 206 |
| 179 TestNotificationTracker& ComponentUpdaterTest::notification_tracker() { | 207 TestUpdateNotificationTracker& ComponentUpdaterTest::notification_tracker() { |
| 180 return notification_tracker_; | 208 return notification_tracker_; |
| 181 } | 209 } |
| 182 | 210 |
| 183 TestConfigurator* ComponentUpdaterTest::test_configurator() { | 211 TestConfigurator* ComponentUpdaterTest::test_configurator() { |
| 184 return test_config_; | 212 return test_config_; |
| 185 } | 213 } |
| 186 | 214 |
| 187 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent( | 215 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent( |
| 188 CrxComponent* com, | 216 CrxComponent* com, |
| 189 TestComponents component, | 217 TestComponents component, |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 382 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 355 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 383 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 356 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 384 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 357 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 385 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 358 | 386 |
| 359 EXPECT_EQ(3, interceptor.GetHitCount()); | 387 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 360 | 388 |
| 361 ASSERT_EQ(5ul, notification_tracker().size()); | 389 ASSERT_EQ(5ul, notification_tracker().size()); |
| 362 | 390 |
| 363 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 391 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
| 392 ComponentUpdateService::UpdateSource source1 = |
| 393 notification_tracker().SourceAt(1); |
| 364 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 394 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
| 395 // Check that the UPDATE_FOUND is for com1. |
| 396 EXPECT_FALSE(ComponentUpdateService::IsUpdateNotificationForComponent( |
| 397 content::Source<std::string>(&source1), com2)); |
| 398 EXPECT_TRUE(ComponentUpdateService::IsUpdateNotificationForComponent( |
| 399 content::Source<std::string>(&source1), com1)); |
| 365 | 400 |
| 366 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 401 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
| 402 ComponentUpdateService::UpdateSource source2 = |
| 403 notification_tracker().SourceAt(2); |
| 367 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 404 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
| 405 // Check that the UPDATE_READY is for com1. |
| 406 EXPECT_FALSE(ComponentUpdateService::IsUpdateNotificationForComponent( |
| 407 content::Source<std::string>(&source2), com2)); |
| 408 EXPECT_TRUE(ComponentUpdateService::IsUpdateNotificationForComponent( |
| 409 content::Source<std::string>(&source2), com1)); |
| 368 | 410 |
| 369 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 411 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
| 370 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 412 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
| 371 | 413 |
| 372 TestNotificationTracker::Event ev4 = notification_tracker().at(4); | 414 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
| 373 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); | 415 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
| 374 | 416 |
| 375 component_updater()->Stop(); | 417 component_updater()->Stop(); |
| 376 } | 418 } |
| 377 | 419 |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 component_updater()->Start(); | 882 component_updater()->Start(); |
| 841 message_loop.Run(); | 883 message_loop.Run(); |
| 842 | 884 |
| 843 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 885 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 844 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); | 886 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 845 | 887 |
| 846 EXPECT_EQ(6, interceptor.GetHitCount()); | 888 EXPECT_EQ(6, interceptor.GetHitCount()); |
| 847 | 889 |
| 848 component_updater()->Stop(); | 890 component_updater()->Stop(); |
| 849 } | 891 } |
| OLD | NEW |