| 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 "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/memory/scoped_vector.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/component_updater/component_updater_interceptor.h" | 14 #include "chrome/browser/component_updater/component_updater_interceptor.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
| 20 #include "content/public/test/test_notification_tracker.h" | 20 #include "content/public/test/test_notification_tracker.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 #include "libxml/globals.h" | 22 #include "libxml/globals.h" |
| 23 #include "net/url_request/url_fetcher.h" | 23 #include "net/url_request/url_fetcher.h" |
| 24 #include "net/url_request/url_request_test_util.h" | 24 #include "net/url_request/url_request_test_util.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 #if defined(OS_MACOSX) |
| 28 #include "base/power_monitor/power_monitor.h" |
| 29 #endif |
| 30 |
| 27 using content::BrowserThread; | 31 using content::BrowserThread; |
| 28 using content::TestNotificationTracker; | 32 using content::TestNotificationTracker; |
| 29 | 33 |
| 30 namespace { | 34 namespace { |
| 31 // Overrides some of the component updater behaviors so it is easier to test | 35 // Overrides some of the component updater behaviors so it is easier to test |
| 32 // and loops faster. In actual usage it takes hours do to a full cycle. | 36 // and loops faster. In actual usage it takes hours do to a full cycle. |
| 33 class TestConfigurator : public ComponentUpdateService::Configurator { | 37 class TestConfigurator : public ComponentUpdateService::Configurator { |
| 34 public: | 38 public: |
| 35 TestConfigurator() : times_(1) { | 39 TestConfigurator() : times_(1) { |
| 36 } | 40 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 136 |
| 133 // Common fixture for all the component updater tests. | 137 // Common fixture for all the component updater tests. |
| 134 class ComponentUpdaterTest : public testing::Test { | 138 class ComponentUpdaterTest : public testing::Test { |
| 135 public: | 139 public: |
| 136 enum TestComponents { | 140 enum TestComponents { |
| 137 kTestComponent_abag, | 141 kTestComponent_abag, |
| 138 kTestComponent_jebg | 142 kTestComponent_jebg |
| 139 }; | 143 }; |
| 140 | 144 |
| 141 ComponentUpdaterTest() : component_updater_(NULL), test_config_(NULL) { | 145 ComponentUpdaterTest() : component_updater_(NULL), test_config_(NULL) { |
| 146 #if defined(OS_MACOSX) |
| 147 // Must be called before PowerMonitor's ctor. |
| 148 base::PowerMonitor::AllocateSystemIOPorts(); |
| 149 #endif |
| 142 // The component updater instance under test. | 150 // The component updater instance under test. |
| 143 test_config_ = new TestConfigurator; | 151 test_config_ = new TestConfigurator; |
| 144 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); | 152 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); |
| 145 // The test directory is chrome/test/data/components. | 153 // The test directory is chrome/test/data/components. |
| 146 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 154 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| 147 test_data_dir_ = test_data_dir_.AppendASCII("components"); | 155 test_data_dir_ = test_data_dir_.AppendASCII("components"); |
| 148 | 156 |
| 149 // Subscribe to all component updater notifications. | 157 // Subscribe to all component updater notifications. |
| 150 const int notifications[] = { | 158 const int notifications[] = { |
| 151 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, | 159 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 test_configurator()->SetLoopCount(1); | 416 test_configurator()->SetLoopCount(1); |
| 409 component_updater()->Start(); | 417 component_updater()->Start(); |
| 410 message_loop.Run(); | 418 message_loop.Run(); |
| 411 | 419 |
| 412 EXPECT_EQ(1, interceptor->hit_count()); | 420 EXPECT_EQ(1, interceptor->hit_count()); |
| 413 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 421 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 414 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 422 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 415 | 423 |
| 416 component_updater()->Stop(); | 424 component_updater()->Stop(); |
| 417 } | 425 } |
| OLD | NEW |