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/public/test/test_chrome_browser_provider.h"
8 #include "ios/public/test/test_chrome_provider_initializer.h"
9 #include "ios/web/public/web_client.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/base/ui_base_paths.h"
12 #include "url/url_util.h"
16 class IOSChromeUnitTestSuiteInitializer
17 : public testing::EmptyTestEventListener
{
19 IOSChromeUnitTestSuiteInitializer() {}
20 ~IOSChromeUnitTestSuiteInitializer() override
{}
22 void OnTestStart(const testing::TestInfo
& test_info
) override
{
23 web_client_
.reset(new web::WebClient());
24 web::SetWebClient(web_client_
.get());
25 test_ios_chrome_provider_initializer_
.reset(
26 new ios::TestChromeProviderInitializer());
29 void OnTestEnd(const testing::TestInfo
& test_info
) override
{
31 web::SetWebClient(NULL
);
32 test_ios_chrome_provider_initializer_
.reset();
36 scoped_ptr
<web::WebClient
> web_client_
;
37 scoped_ptr
<ios::TestChromeProviderInitializer
>
38 test_ios_chrome_provider_initializer_
;
39 DISALLOW_COPY_AND_ASSIGN(IOSChromeUnitTestSuiteInitializer
);
44 IOSChromeUnitTestSuite::IOSChromeUnitTestSuite(int argc
, char** argv
)
45 : base::TestSuite(argc
, argv
) {
48 IOSChromeUnitTestSuite::~IOSChromeUnitTestSuite() {
51 void IOSChromeUnitTestSuite::Initialize() {
52 // Add an additional listener to do the extra initialization for unit tests.
53 // It will be started before the base class listeners and ended after the
54 // base class listeners.
55 testing::TestEventListeners
& listeners
=
56 testing::UnitTest::GetInstance()->listeners();
57 listeners
.Append(new IOSChromeUnitTestSuiteInitializer
);
59 ui::RegisterPathProvider();
62 ios::TestChromeBrowserProvider provider
;
63 url::AddStandardScheme(provider
.GetChromeUIScheme());
66 base::TestSuite::Initialize();