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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 void TestConfigurator::AddComponentToCheck(CrxComponent* com, | 122 void TestConfigurator::AddComponentToCheck(CrxComponent* com, |
123 int at_loop_iter) { | 123 int at_loop_iter) { |
124 components_to_check_.push_back(std::make_pair(com, at_loop_iter)); | 124 components_to_check_.push_back(std::make_pair(com, at_loop_iter)); |
125 } | 125 } |
126 | 126 |
127 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { | 127 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { |
128 cus_ = cus; | 128 cus_ = cus; |
129 } | 129 } |
130 | 130 |
| 131 TestUpdateNotificationTracker::TestUpdateNotificationTracker() {} |
| 132 |
| 133 TestUpdateNotificationTracker::~TestUpdateNotificationTracker() {} |
| 134 |
| 135 std::string TestUpdateNotificationTracker::SourceAt(size_t num) { |
| 136 return sources_[num]; |
| 137 } |
| 138 |
| 139 void TestUpdateNotificationTracker::Observe( |
| 140 int type, |
| 141 const content::NotificationSource& source, |
| 142 const content::NotificationDetails& details) { |
| 143 if (type == chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND |
| 144 || type == chrome::NOTIFICATION_COMPONENT_UPDATE_READY) { |
| 145 sources_.push_back(std::string( |
| 146 *content::Source<std::string>(source).ptr())); |
| 147 } else |
| 148 sources_.push_back(std::string()); |
| 149 TestNotificationTracker::Observe(type, source, details); |
| 150 } |
| 151 |
| 152 void TestUpdateNotificationTracker::Reset() { |
| 153 sources_.clear(); |
| 154 TestNotificationTracker::Reset(); |
| 155 } |
| 156 |
131 ComponentUpdaterTest::ComponentUpdaterTest() : test_config_(NULL) { | 157 ComponentUpdaterTest::ComponentUpdaterTest() : test_config_(NULL) { |
132 // The component updater instance under test. | 158 // The component updater instance under test. |
133 test_config_ = new TestConfigurator; | 159 test_config_ = new TestConfigurator; |
134 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); | 160 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); |
135 test_config_->SetComponentUpdateService(component_updater_.get()); | 161 test_config_->SetComponentUpdateService(component_updater_.get()); |
136 // The test directory is chrome/test/data/components. | 162 // The test directory is chrome/test/data/components. |
137 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 163 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
138 test_data_dir_ = test_data_dir_.AppendASCII("components"); | 164 test_data_dir_ = test_data_dir_.AppendASCII("components"); |
139 | 165 |
140 // Subscribe to all component updater notifications. | 166 // Subscribe to all component updater notifications. |
(...skipping 21 matching lines...) Expand all Loading... |
162 | 188 |
163 ComponentUpdateService* ComponentUpdaterTest::component_updater() { | 189 ComponentUpdateService* ComponentUpdaterTest::component_updater() { |
164 return component_updater_.get(); | 190 return component_updater_.get(); |
165 } | 191 } |
166 | 192 |
167 // Makes the full path to a component updater test file. | 193 // Makes the full path to a component updater test file. |
168 const base::FilePath ComponentUpdaterTest::test_file(const char* file) { | 194 const base::FilePath ComponentUpdaterTest::test_file(const char* file) { |
169 return test_data_dir_.AppendASCII(file); | 195 return test_data_dir_.AppendASCII(file); |
170 } | 196 } |
171 | 197 |
172 TestNotificationTracker& ComponentUpdaterTest::notification_tracker() { | 198 TestUpdateNotificationTracker& ComponentUpdaterTest::notification_tracker() { |
173 return notification_tracker_; | 199 return notification_tracker_; |
174 } | 200 } |
175 | 201 |
176 TestConfigurator* ComponentUpdaterTest::test_configurator() { | 202 TestConfigurator* ComponentUpdaterTest::test_configurator() { |
177 return test_config_; | 203 return test_config_; |
178 } | 204 } |
179 | 205 |
180 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent( | 206 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent( |
181 CrxComponent* com, | 207 CrxComponent* com, |
182 TestComponents component, | 208 TestComponents component, |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 373 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
348 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 374 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
349 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 375 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
350 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 376 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
351 | 377 |
352 EXPECT_EQ(3, interceptor.GetHitCount()); | 378 EXPECT_EQ(3, interceptor.GetHitCount()); |
353 | 379 |
354 ASSERT_EQ(5ul, notification_tracker().size()); | 380 ASSERT_EQ(5ul, notification_tracker().size()); |
355 | 381 |
356 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 382 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
| 383 std::string source1 = notification_tracker().SourceAt(1); |
357 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 384 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
| 385 // Check that the UPDATE_FOUND is for com1. |
| 386 EXPECT_FALSE(ComponentUpdateService::IsUpdateNotificationForComponent( |
| 387 content::Source<std::string>(&source1), com2)); |
| 388 EXPECT_TRUE(ComponentUpdateService::IsUpdateNotificationForComponent( |
| 389 content::Source<std::string>(&source1), com1)); |
358 | 390 |
359 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 391 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
| 392 std::string source2 = notification_tracker().SourceAt(2); |
360 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 393 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
| 394 // Check that the UPDATE_READY is for com1. |
| 395 EXPECT_FALSE(ComponentUpdateService::IsUpdateNotificationForComponent( |
| 396 content::Source<std::string>(&source2), com2)); |
| 397 EXPECT_TRUE(ComponentUpdateService::IsUpdateNotificationForComponent( |
| 398 content::Source<std::string>(&source2), com1)); |
361 | 399 |
362 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 400 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
363 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 401 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
364 | 402 |
365 TestNotificationTracker::Event ev4 = notification_tracker().at(4); | 403 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
366 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); | 404 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
367 | 405 |
368 component_updater()->Stop(); | 406 component_updater()->Stop(); |
369 } | 407 } |
370 | 408 |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 component_updater()->Start(); | 797 component_updater()->Start(); |
760 message_loop.Run(); | 798 message_loop.Run(); |
761 | 799 |
762 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 800 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
763 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); | 801 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
764 | 802 |
765 EXPECT_EQ(6, interceptor.GetHitCount()); | 803 EXPECT_EQ(6, interceptor.GetHitCount()); |
766 | 804 |
767 component_updater()->Stop(); | 805 component_updater()->Stop(); |
768 } | 806 } |
OLD | NEW |