| 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 "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" | 5 #include "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/component_updater/component_updater_resource_throttle.h
" | 16 #include "chrome/browser/component_updater/component_updater_resource_throttle.h
" |
| 17 #include "chrome/browser/component_updater/test/test_configurator.h" | |
| 18 #include "chrome/browser/component_updater/test/test_installer.h" | |
| 19 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 20 #include "components/component_updater/component_updater_utils.h" | 18 #include "components/component_updater/component_updater_utils.h" |
| 19 #include "components/component_updater/test/test_configurator.h" |
| 20 #include "components/component_updater/test/test_installer.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/resource_controller.h" | 22 #include "content/public/browser/resource_controller.h" |
| 23 #include "content/public/browser/resource_request_info.h" | 23 #include "content/public/browser/resource_request_info.h" |
| 24 #include "content/public/browser/resource_throttle.h" | 24 #include "content/public/browser/resource_throttle.h" |
| 25 #include "libxml/globals.h" | 25 #include "libxml/globals.h" |
| 26 #include "net/base/upload_bytes_element_reader.h" | 26 #include "net/base/upload_bytes_element_reader.h" |
| 27 #include "net/url_request/url_fetcher.h" | 27 #include "net/url_request/url_fetcher.h" |
| 28 #include "net/url_request/url_request_test_util.h" | 28 #include "net/url_request/url_request_test_util.h" |
| 29 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 30 | 30 |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 | 32 |
| 33 using ::testing::_; | 33 using ::testing::_; |
| 34 using ::testing::AnyNumber; | 34 using ::testing::AnyNumber; |
| 35 using ::testing::InSequence; | 35 using ::testing::InSequence; |
| 36 using ::testing::Mock; | 36 using ::testing::Mock; |
| 37 | 37 |
| 38 namespace component_updater { | 38 namespace component_updater { |
| 39 | 39 |
| 40 MockServiceObserver::MockServiceObserver() { | 40 MockServiceObserver::MockServiceObserver() { |
| 41 } | 41 } |
| 42 | 42 |
| 43 MockServiceObserver::~MockServiceObserver() { | 43 MockServiceObserver::~MockServiceObserver() { |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool PartialMatch::Match(const std::string& actual) const { | |
| 47 return actual.find(expected_) != std::string::npos; | |
| 48 } | |
| 49 | |
| 50 InterceptorFactory::InterceptorFactory() | |
| 51 : URLRequestPostInterceptorFactory(POST_INTERCEPT_SCHEME, | |
| 52 POST_INTERCEPT_HOSTNAME) { | |
| 53 } | |
| 54 | |
| 55 InterceptorFactory::~InterceptorFactory() { | |
| 56 } | |
| 57 | |
| 58 URLRequestPostInterceptor* InterceptorFactory::CreateInterceptor() { | |
| 59 return URLRequestPostInterceptorFactory::CreateInterceptor( | |
| 60 base::FilePath::FromUTF8Unsafe(POST_INTERCEPT_PATH)); | |
| 61 } | |
| 62 | |
| 63 ComponentUpdaterTest::ComponentUpdaterTest() | 46 ComponentUpdaterTest::ComponentUpdaterTest() |
| 64 : test_config_(NULL), | 47 : test_config_(NULL), |
| 65 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 48 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 66 // The component updater instance under test. | 49 // The component updater instance under test. |
| 67 test_config_ = new TestConfigurator; | 50 test_config_ = new TestConfigurator; |
| 68 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); | 51 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); |
| 69 | 52 |
| 70 // The test directory is chrome/test/data/components. | |
| 71 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | |
| 72 test_data_dir_ = test_data_dir_.AppendASCII("components"); | |
| 73 | |
| 74 net::URLFetcher::SetEnableInterceptionForTests(true); | 53 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 75 } | 54 } |
| 76 | 55 |
| 77 ComponentUpdaterTest::~ComponentUpdaterTest() { | 56 ComponentUpdaterTest::~ComponentUpdaterTest() { |
| 78 net::URLFetcher::SetEnableInterceptionForTests(false); | 57 net::URLFetcher::SetEnableInterceptionForTests(false); |
| 79 } | 58 } |
| 80 | 59 |
| 81 void ComponentUpdaterTest::SetUp() { | 60 void ComponentUpdaterTest::SetUp() { |
| 82 get_interceptor_.reset(new GetInterceptor); | 61 get_interceptor_.reset(new GetInterceptor); |
| 83 interceptor_factory_.reset(new InterceptorFactory); | 62 interceptor_factory_.reset(new InterceptorFactory); |
| 84 post_interceptor_ = interceptor_factory_->CreateInterceptor(); | 63 post_interceptor_ = interceptor_factory_->CreateInterceptor(); |
| 85 EXPECT_TRUE(post_interceptor_); | 64 EXPECT_TRUE(post_interceptor_); |
| 86 } | 65 } |
| 87 | 66 |
| 88 void ComponentUpdaterTest::TearDown() { | 67 void ComponentUpdaterTest::TearDown() { |
| 89 interceptor_factory_.reset(); | 68 interceptor_factory_.reset(); |
| 90 get_interceptor_.reset(); | 69 get_interceptor_.reset(); |
| 91 xmlCleanupGlobals(); | 70 xmlCleanupGlobals(); |
| 92 } | 71 } |
| 93 | 72 |
| 94 ComponentUpdateService* ComponentUpdaterTest::component_updater() { | 73 ComponentUpdateService* ComponentUpdaterTest::component_updater() { |
| 95 return component_updater_.get(); | 74 return component_updater_.get(); |
| 96 } | 75 } |
| 97 | 76 |
| 98 // Makes the full path to a component updater test file. | 77 // Makes the full path to a component updater test file. |
| 99 const base::FilePath ComponentUpdaterTest::test_file(const char* file) { | 78 const base::FilePath ComponentUpdaterTest::test_file(const char* file) { |
| 100 return test_data_dir_.AppendASCII(file); | 79 base::FilePath path; |
| 80 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 81 return path.AppendASCII("components").AppendASCII("test").AppendASCII("data") |
| 82 .AppendASCII("component_updater").AppendASCII(file); |
| 101 } | 83 } |
| 102 | 84 |
| 103 TestConfigurator* ComponentUpdaterTest::test_configurator() { | 85 TestConfigurator* ComponentUpdaterTest::test_configurator() { |
| 104 return test_config_; | 86 return test_config_; |
| 105 } | 87 } |
| 106 | 88 |
| 107 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent( | 89 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent( |
| 108 CrxComponent* com, | 90 CrxComponent* com, |
| 109 TestComponents component, | 91 TestComponents component, |
| 110 const Version& version, | 92 const Version& version, |
| (...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 component_updater()->RemoveObserver(&observer2); | 1478 component_updater()->RemoveObserver(&observer2); |
| 1497 | 1479 |
| 1498 test_configurator()->SetLoopCount(1); | 1480 test_configurator()->SetLoopCount(1); |
| 1499 component_updater()->Start(); | 1481 component_updater()->Start(); |
| 1500 RunThreads(); | 1482 RunThreads(); |
| 1501 | 1483 |
| 1502 component_updater()->Stop(); | 1484 component_updater()->Stop(); |
| 1503 } | 1485 } |
| 1504 | 1486 |
| 1505 } // namespace component_updater | 1487 } // namespace component_updater |
| OLD | NEW |