| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" | 7 #include "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/component_updater/component_updater_resource_throttle.h
" |
| 15 #include "chrome/browser/component_updater/component_updater_utils.h" | 16 #include "chrome/browser/component_updater/component_updater_utils.h" |
| 16 #include "chrome/browser/component_updater/test/test_configurator.h" | 17 #include "chrome/browser/component_updater/test/test_configurator.h" |
| 17 #include "chrome/browser/component_updater/test/test_installer.h" | 18 #include "chrome/browser/component_updater/test/test_installer.h" |
| 18 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/resource_controller.h" | 21 #include "content/public/browser/resource_controller.h" |
| 21 #include "content/public/browser/resource_request_info.h" | 22 #include "content/public/browser/resource_request_info.h" |
| 22 #include "content/public/browser/resource_throttle.h" | 23 #include "content/public/browser/resource_throttle.h" |
| 23 #include "libxml/globals.h" | 24 #include "libxml/globals.h" |
| 24 #include "net/base/upload_bytes_element_reader.h" | 25 #include "net/base/upload_bytes_element_reader.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 RunThreadsUntilIdle(); | 135 RunThreadsUntilIdle(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void ComponentUpdaterTest::RunThreadsUntilIdle() { | 138 void ComponentUpdaterTest::RunThreadsUntilIdle() { |
| 138 base::RunLoop().RunUntilIdle(); | 139 base::RunLoop().RunUntilIdle(); |
| 139 } | 140 } |
| 140 | 141 |
| 141 ComponentUpdateService::Status OnDemandTester::OnDemand( | 142 ComponentUpdateService::Status OnDemandTester::OnDemand( |
| 142 ComponentUpdateService* cus, | 143 ComponentUpdateService* cus, |
| 143 const std::string& component_id) { | 144 const std::string& component_id) { |
| 144 return cus->GetOnDemandUpdater().OnDemandUpdate(component_id); | 145 return cus->OnDemandUpdate(component_id); |
| 145 } | 146 } |
| 146 | 147 |
| 147 // Verify that our test fixture work and the component updater can | 148 // Verify that our test fixture work and the component updater can |
| 148 // be created and destroyed with no side effects. | 149 // be created and destroyed with no side effects. |
| 149 TEST_F(ComponentUpdaterTest, VerifyFixture) { | 150 TEST_F(ComponentUpdaterTest, VerifyFixture) { |
| 150 EXPECT_TRUE(component_updater() != NULL); | 151 EXPECT_TRUE(component_updater() != NULL); |
| 151 } | 152 } |
| 152 | 153 |
| 153 // Verify that the component updater can be caught in a quick | 154 // Verify that the component updater can be caught in a quick |
| 154 // start-shutdown situation. Failure of this test will be a crash. | 155 // start-shutdown situation. Failure of this test will be a crash. |
| (...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 content::ResourceThrottle* RequestTestResourceThrottle( | 1184 content::ResourceThrottle* RequestTestResourceThrottle( |
| 1184 ComponentUpdateService* cus, | 1185 ComponentUpdateService* cus, |
| 1185 TestResourceController* controller, | 1186 TestResourceController* controller, |
| 1186 const char* crx_id) { | 1187 const char* crx_id) { |
| 1187 net::TestURLRequestContext context; | 1188 net::TestURLRequestContext context; |
| 1188 net::TestURLRequest url_request(GURL("http://foo.example.com/thing.bin"), | 1189 net::TestURLRequest url_request(GURL("http://foo.example.com/thing.bin"), |
| 1189 net::DEFAULT_PRIORITY, | 1190 net::DEFAULT_PRIORITY, |
| 1190 NULL, | 1191 NULL, |
| 1191 &context); | 1192 &context); |
| 1192 | 1193 |
| 1193 content::ResourceThrottle* rt = | 1194 content::ResourceThrottle* rt = GetOnDemandResourceThrottle(cus, crx_id); |
| 1194 cus->GetOnDemandUpdater().GetOnDemandResourceThrottle(&url_request, | |
| 1195 crx_id); | |
| 1196 rt->set_controller_for_testing(controller); | 1195 rt->set_controller_for_testing(controller); |
| 1197 controller->SetThrottle(rt); | 1196 controller->SetThrottle(rt); |
| 1198 return rt; | 1197 return rt; |
| 1199 } | 1198 } |
| 1200 | 1199 |
| 1201 void RequestAndDeleteResourceThrottle(ComponentUpdateService* cus, | 1200 void RequestAndDeleteResourceThrottle(ComponentUpdateService* cus, |
| 1202 const char* crx_id) { | 1201 const char* crx_id) { |
| 1203 // By requesting a throttle and deleting it immediately we ensure that we | 1202 // By requesting a throttle and deleting it immediately we ensure that we |
| 1204 // hit the case where the component updater tries to use the weak | 1203 // hit the case where the component updater tries to use the weak |
| 1205 // pointer to a dead Resource throttle. | 1204 // pointer to a dead Resource throttle. |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 component_updater()->RemoveObserver(&observer2); | 1489 component_updater()->RemoveObserver(&observer2); |
| 1491 | 1490 |
| 1492 test_configurator()->SetLoopCount(1); | 1491 test_configurator()->SetLoopCount(1); |
| 1493 component_updater()->Start(); | 1492 component_updater()->Start(); |
| 1494 RunThreads(); | 1493 RunThreads(); |
| 1495 | 1494 |
| 1496 component_updater()->Stop(); | 1495 component_updater()->Stop(); |
| 1497 } | 1496 } |
| 1498 | 1497 |
| 1499 } // namespace component_updater | 1498 } // namespace component_updater |
| OLD | NEW |