OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 11 #include "base/message_loop.h" |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "chrome/browser/component_updater/component_updater_interceptor.h" | 14 #include "chrome/browser/component_updater/component_updater_interceptor.h" |
14 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/test/base/test_url_request_context_getter.h" | 17 #include "chrome/test/base/test_url_request_context_getter.h" |
17 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
19 #include "content/test/test_browser_thread.h" | 20 #include "content/test/test_browser_thread.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 notification_tracker_.ListenFor( | 158 notification_tracker_.ListenFor( |
158 notifications[ix], content::NotificationService::AllSources()); | 159 notifications[ix], content::NotificationService::AllSources()); |
159 } | 160 } |
160 content::URLFetcher::SetEnableInterceptionForTests(true); | 161 content::URLFetcher::SetEnableInterceptionForTests(true); |
161 } | 162 } |
162 | 163 |
163 ~ComponentUpdaterTest() { | 164 ~ComponentUpdaterTest() { |
164 content::URLFetcher::SetEnableInterceptionForTests(false); | 165 content::URLFetcher::SetEnableInterceptionForTests(false); |
165 } | 166 } |
166 | 167 |
| 168 void TearDown() { |
| 169 xmlCleanupGlobals(); |
| 170 } |
| 171 |
167 ComponentUpdateService* component_updater() { | 172 ComponentUpdateService* component_updater() { |
168 return component_updater_.get(); | 173 return component_updater_.get(); |
169 } | 174 } |
170 | 175 |
171 // Makes the full path to a component updater test file. | 176 // Makes the full path to a component updater test file. |
172 const FilePath test_file(const char* file) { | 177 const FilePath test_file(const char* file) { |
173 return test_data_dir_.AppendASCII(file); | 178 return test_data_dir_.AppendASCII(file); |
174 } | 179 } |
175 | 180 |
176 TestNotificationTracker& notification_tracker() { | 181 TestNotificationTracker& notification_tracker() { |
177 return notification_tracker_; | 182 return notification_tracker_; |
178 } | 183 } |
179 | 184 |
180 TestConfigurator* test_configurator() { | 185 TestConfigurator* test_configurator() { |
181 return test_config_; | 186 return test_config_; |
182 } | 187 } |
183 | 188 |
184 void RegisterComponent(CrxComponent* com, | 189 void RegisterComponent(CrxComponent* com, |
185 TestComponents component, | 190 TestComponents component, |
186 const Version& version) { | 191 const Version& version) { |
187 if (component == kTestComponent_abag) { | 192 if (component == kTestComponent_abag) { |
188 com->name = "test_abag"; | 193 com->name = "test_abag"; |
189 com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash)); | 194 com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash)); |
190 } else { | 195 } else { |
191 com->name = "test_jebg"; | 196 com->name = "test_jebg"; |
192 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 197 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
193 } | 198 } |
194 com->version = version; | 199 com->version = version; |
195 com->installer = new TestInstaller; | 200 com->installer = new TestInstaller; |
| 201 test_installers_.push_back(com->installer); |
196 component_updater_->RegisterComponent(*com); | 202 component_updater_->RegisterComponent(*com); |
197 } | 203 } |
198 | 204 |
199 private: | 205 private: |
200 scoped_ptr<ComponentUpdateService> component_updater_; | 206 scoped_ptr<ComponentUpdateService> component_updater_; |
201 FilePath test_data_dir_; | 207 FilePath test_data_dir_; |
202 TestNotificationTracker notification_tracker_; | 208 TestNotificationTracker notification_tracker_; |
203 TestConfigurator* test_config_; | 209 TestConfigurator* test_config_; |
| 210 // ComponentInstaller objects to delete after each test. |
| 211 ScopedVector<ComponentInstaller> test_installers_; |
204 }; | 212 }; |
205 | 213 |
206 // Verify that our test fixture work and the component updater can | 214 // Verify that our test fixture work and the component updater can |
207 // be created and destroyed with no side effects. | 215 // be created and destroyed with no side effects. |
208 TEST_F(ComponentUpdaterTest, VerifyFixture) { | 216 TEST_F(ComponentUpdaterTest, VerifyFixture) { |
209 EXPECT_TRUE(component_updater() != NULL); | 217 EXPECT_TRUE(component_updater() != NULL); |
210 EXPECT_EQ(0ul, notification_tracker().size()); | 218 EXPECT_EQ(0ul, notification_tracker().size()); |
211 } | 219 } |
212 | 220 |
213 // Verify that the component updater can be caught in a quick | 221 // Verify that the component updater can be caught in a quick |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 ev2 = notification_tracker().at(1); | 299 ev2 = notification_tracker().at(1); |
292 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 300 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
293 ev3 = notification_tracker().at(2); | 301 ev3 = notification_tracker().at(2); |
294 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 302 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
295 EXPECT_EQ(4, interceptor->hit_count()); | 303 EXPECT_EQ(4, interceptor->hit_count()); |
296 | 304 |
297 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 305 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
298 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 306 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
299 | 307 |
300 component_updater()->Stop(); | 308 component_updater()->Stop(); |
301 | |
302 delete com.installer; | |
303 xmlCleanupGlobals(); | |
304 } | 309 } |
305 | 310 |
306 // Verify that we can check for updates and install one component. Besides | 311 // Verify that we can check for updates and install one component. Besides |
307 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and | 312 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and |
308 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops | 313 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops |
309 // so the second time arround there should be nothing left to do. | 314 // so the second time arround there should be nothing left to do. |
310 // We also check that only 3 network requests are issued: | 315 // We also check that only 3 network requests are issued: |
311 // 1- manifest check | 316 // 1- manifest check |
312 // 2- download crx | 317 // 2- download crx |
313 // 3- second manifest check. | 318 // 3- second manifest check. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 367 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
363 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 368 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
364 | 369 |
365 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 370 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
366 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 371 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
367 | 372 |
368 TestNotificationTracker::Event ev4 = notification_tracker().at(4); | 373 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
369 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 374 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
370 | 375 |
371 component_updater()->Stop(); | 376 component_updater()->Stop(); |
372 delete com1.installer; | |
373 delete com2.installer; | |
374 xmlCleanupGlobals(); | |
375 } | 377 } |
376 | 378 |
377 // This test checks that the "prodversionmin" value is handled correctly. In | 379 // This test checks that the "prodversionmin" value is handled correctly. In |
378 // particular there should not be an install because the minimun product | 380 // particular there should not be an install because the minimun product |
379 // version is much higher than of chrome. | 381 // version is much higher than of chrome. |
380 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { | 382 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
381 MessageLoop message_loop; | 383 MessageLoop message_loop; |
382 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 384 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
383 content::TestBrowserThread file_thread(BrowserThread::FILE); | 385 content::TestBrowserThread file_thread(BrowserThread::FILE); |
384 content::TestBrowserThread io_thread(BrowserThread::IO); | 386 content::TestBrowserThread io_thread(BrowserThread::IO); |
(...skipping 20 matching lines...) Expand all Loading... |
405 test_configurator()->SetLoopCount(1); | 407 test_configurator()->SetLoopCount(1); |
406 component_updater()->Start(); | 408 component_updater()->Start(); |
407 message_loop.Run(); | 409 message_loop.Run(); |
408 | 410 |
409 EXPECT_EQ(1, interceptor->hit_count()); | 411 EXPECT_EQ(1, interceptor->hit_count()); |
410 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 412 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
411 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 413 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
412 | 414 |
413 component_updater()->Stop(); | 415 component_updater()->Stop(); |
414 } | 416 } |
OLD | NEW |