| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/test/ios_chrome_unit_test_suite.h" | 5 #include "ios/chrome/test/ios_chrome_unit_test_suite.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 9 #include "ios/chrome/browser/browser_state/browser_state_keyed_service_factories
.h" | 10 #include "ios/chrome/browser/browser_state/browser_state_keyed_service_factories
.h" |
| 10 #include "ios/chrome/browser/chrome_paths.h" | 11 #include "ios/chrome/browser/chrome_paths.h" |
| 11 #include "ios/chrome/browser/chrome_url_constants.h" | 12 #include "ios/chrome/browser/chrome_url_constants.h" |
| 12 #include "ios/chrome/test/testing_application_context.h" | 13 #include "ios/chrome/test/testing_application_context.h" |
| 13 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 14 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 14 #include "ios/public/provider/chrome/browser/test_chrome_provider_initializer.h" | 15 #include "ios/public/provider/chrome/browser/test_chrome_provider_initializer.h" |
| 15 #include "ios/web/public/web_client.h" | 16 #include "ios/web/public/web_client.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/base/ui_base_paths.h" | 19 #include "ui/base/ui_base_paths.h" |
| 19 #include "url/url_util.h" | 20 #include "url/url_util.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 class IOSChromeUnitTestSuiteInitializer | 24 class IOSChromeUnitTestSuiteInitializer |
| 24 : public testing::EmptyTestEventListener { | 25 : public testing::EmptyTestEventListener { |
| 25 public: | 26 public: |
| 26 IOSChromeUnitTestSuiteInitializer() {} | 27 IOSChromeUnitTestSuiteInitializer() {} |
| 27 ~IOSChromeUnitTestSuiteInitializer() override {} | 28 ~IOSChromeUnitTestSuiteInitializer() override {} |
| 28 | 29 |
| 29 void OnTestStart(const testing::TestInfo& test_info) override { | 30 void OnTestStart(const testing::TestInfo& test_info) override { |
| 30 DCHECK(!web_client_); | |
| 31 web_client_.reset(new web::WebClient); | |
| 32 web::SetWebClient(web_client_.get()); | |
| 33 | |
| 34 DCHECK(!ios::GetChromeBrowserProvider()); | 31 DCHECK(!ios::GetChromeBrowserProvider()); |
| 35 test_ios_chrome_provider_initializer_.reset( | 32 test_ios_chrome_provider_initializer_.reset( |
| 36 new ios::TestChromeProviderInitializer()); | 33 new ios::TestChromeProviderInitializer()); |
| 37 | 34 |
| 38 DCHECK(!GetApplicationContext()); | 35 DCHECK(!GetApplicationContext()); |
| 39 application_context_.reset(new TestingApplicationContext); | 36 application_context_.reset(new TestingApplicationContext); |
| 40 } | 37 } |
| 41 | 38 |
| 42 void OnTestEnd(const testing::TestInfo& test_info) override { | 39 void OnTestEnd(const testing::TestInfo& test_info) override { |
| 43 DCHECK_EQ(GetApplicationContext(), application_context_.get()); | 40 DCHECK_EQ(GetApplicationContext(), application_context_.get()); |
| 44 application_context_.reset(); | 41 application_context_.reset(); |
| 45 | 42 |
| 46 test_ios_chrome_provider_initializer_.reset(); | 43 test_ios_chrome_provider_initializer_.reset(); |
| 47 DCHECK(!ios::GetChromeBrowserProvider()); | 44 DCHECK(!ios::GetChromeBrowserProvider()); |
| 48 | |
| 49 DCHECK_EQ(web::GetWebClient(), web_client_.get()); | |
| 50 web::SetWebClient(nullptr); | |
| 51 web_client_.reset(); | |
| 52 } | 45 } |
| 53 | 46 |
| 54 private: | 47 private: |
| 55 std::unique_ptr<web::WebClient> web_client_; | |
| 56 std::unique_ptr<ios::TestChromeProviderInitializer> | 48 std::unique_ptr<ios::TestChromeProviderInitializer> |
| 57 test_ios_chrome_provider_initializer_; | 49 test_ios_chrome_provider_initializer_; |
| 58 std::unique_ptr<ApplicationContext> application_context_; | 50 std::unique_ptr<ApplicationContext> application_context_; |
| 51 |
| 59 DISALLOW_COPY_AND_ASSIGN(IOSChromeUnitTestSuiteInitializer); | 52 DISALLOW_COPY_AND_ASSIGN(IOSChromeUnitTestSuiteInitializer); |
| 60 }; | 53 }; |
| 61 | 54 |
| 62 } // namespace | 55 } // namespace |
| 63 | 56 |
| 64 IOSChromeUnitTestSuite::IOSChromeUnitTestSuite(int argc, char** argv) | 57 IOSChromeUnitTestSuite::IOSChromeUnitTestSuite(int argc, char** argv) |
| 65 : base::TestSuite(argc, argv) {} | 58 : web::WebTestSuite(argc, argv) {} |
| 66 | 59 |
| 67 IOSChromeUnitTestSuite::~IOSChromeUnitTestSuite() {} | 60 IOSChromeUnitTestSuite::~IOSChromeUnitTestSuite() {} |
| 68 | 61 |
| 69 void IOSChromeUnitTestSuite::Initialize() { | 62 void IOSChromeUnitTestSuite::Initialize() { |
| 70 // Add an additional listener to do the extra initialization for unit tests. | 63 // Add an additional listener to do the extra initialization for unit tests. |
| 71 // It will be started before the base class listeners and ended after the | 64 // It will be started before the base class listeners and ended after the |
| 72 // base class listeners. | 65 // base class listeners. |
| 73 testing::TestEventListeners& listeners = | 66 testing::TestEventListeners& listeners = |
| 74 testing::UnitTest::GetInstance()->listeners(); | 67 testing::UnitTest::GetInstance()->listeners(); |
| 75 listeners.Append(new IOSChromeUnitTestSuiteInitializer); | 68 listeners.Append(new IOSChromeUnitTestSuiteInitializer); |
| 76 | 69 |
| 70 // Call the superclass Initialize() method after adding the listener. |
| 71 web::WebTestSuite::Initialize(); |
| 72 |
| 77 // Ensure that all BrowserStateKeyedServiceFactories are built before any | 73 // Ensure that all BrowserStateKeyedServiceFactories are built before any |
| 78 // test is run so that the dependencies are correctly resolved. | 74 // test is run so that the dependencies are correctly resolved. |
| 79 EnsureBrowserStateKeyedServiceFactoriesBuilt(); | 75 EnsureBrowserStateKeyedServiceFactoriesBuilt(); |
| 80 | 76 |
| 81 ios::RegisterPathProvider(); | 77 ios::RegisterPathProvider(); |
| 82 ui::RegisterPathProvider(); | 78 ui::RegisterPathProvider(); |
| 83 | |
| 84 ui::ResourceBundle::InitSharedInstanceWithLocale( | |
| 85 "en-US", nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES); | |
| 86 base::FilePath resources_pack_path; | |
| 87 PathService::Get(ios::FILE_RESOURCES_PACK, &resources_pack_path); | |
| 88 ResourceBundle::GetSharedInstance().AddDataPackFromPath( | |
| 89 resources_pack_path, ui::SCALE_FACTOR_100P); | |
| 90 | |
| 91 url::AddStandardScheme(kChromeUIScheme, url::SCHEME_WITHOUT_PORT); | 79 url::AddStandardScheme(kChromeUIScheme, url::SCHEME_WITHOUT_PORT); |
| 92 | 80 ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( |
| 93 base::TestSuite::Initialize(); | 81 kDummyExtensionScheme); |
| 94 } | 82 } |
| OLD | NEW |