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
3 // found in the LICENSE file.
5 #include "ios/chrome/test/ios_chrome_unit_test_suite.h"
7 #include "ios/chrome/browser/browser_state/browser_state_keyed_service_factories.h"
8 #include "ios/chrome/browser/chrome_paths.h"
9 #include "ios/chrome/test/testing_application_context.h"
10 #include "ios/public/test/test_chrome_browser_provider.h"
11 #include "ios/public/test/test_chrome_provider_initializer.h"
12 #include "ios/web/public/web_client.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/base/ui_base_paths.h"
16 #include "url/url_util.h"
20 class IOSChromeUnitTestSuiteInitializer
21 : public testing::EmptyTestEventListener
{
23 IOSChromeUnitTestSuiteInitializer() {}
24 ~IOSChromeUnitTestSuiteInitializer() override
{}
26 void OnTestStart(const testing::TestInfo
& test_info
) override
{
27 web_client_
.reset(new web::WebClient());
28 web::SetWebClient(web_client_
.get());
29 test_ios_chrome_provider_initializer_
.reset(
30 new ios::TestChromeProviderInitializer());
31 application_context_
.reset(new TestingApplicationContext
);
34 void OnTestEnd(const testing::TestInfo
& test_info
) override
{
36 web::SetWebClient(nullptr);
37 test_ios_chrome_provider_initializer_
.reset();
38 application_context_
.reset();
42 scoped_ptr
<web::WebClient
> web_client_
;
43 scoped_ptr
<ios::TestChromeProviderInitializer
>
44 test_ios_chrome_provider_initializer_
;
45 scoped_ptr
<ApplicationContext
> application_context_
;
46 DISALLOW_COPY_AND_ASSIGN(IOSChromeUnitTestSuiteInitializer
);
51 IOSChromeUnitTestSuite::IOSChromeUnitTestSuite(int argc
, char** argv
)
52 : base::TestSuite(argc
, argv
) {
55 IOSChromeUnitTestSuite::~IOSChromeUnitTestSuite() {
58 void IOSChromeUnitTestSuite::Initialize() {
59 // Add an additional listener to do the extra initialization for unit tests.
60 // It will be started before the base class listeners and ended after the
61 // base class listeners.
62 testing::TestEventListeners
& listeners
=
63 testing::UnitTest::GetInstance()->listeners();
64 listeners
.Append(new IOSChromeUnitTestSuiteInitializer
);
66 ui::ResourceBundle::InitSharedInstanceWithLocale(
67 "en-US", nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES
);
69 // Ensure that all BrowserStateKeyedServiceFactories are built before any
70 // test is run so that the dependencies are correctly resolved.
71 EnsureBrowserStateKeyedServiceFactoriesBuilt();
73 ios::RegisterPathProvider();
74 ui::RegisterPathProvider();
77 ios::TestChromeBrowserProvider provider
;
78 url::AddStandardScheme(provider
.GetChromeUIScheme());
81 base::TestSuite::Initialize();