Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / ios / chrome / test / ios_chrome_unit_test_suite.cc
blobbb28a4252fabc4d90cfd3ef8376926f0325d0f43
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/public/test/test_chrome_browser_provider.h"
10 #include "ios/public/test/test_chrome_provider_initializer.h"
11 #include "ios/web/public/web_client.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/base/ui_base_paths.h"
14 #include "url/url_util.h"
16 namespace {
18 class IOSChromeUnitTestSuiteInitializer
19 : public testing::EmptyTestEventListener {
20 public:
21 IOSChromeUnitTestSuiteInitializer() {}
22 ~IOSChromeUnitTestSuiteInitializer() override {}
24 void OnTestStart(const testing::TestInfo& test_info) override {
25 web_client_.reset(new web::WebClient());
26 web::SetWebClient(web_client_.get());
27 test_ios_chrome_provider_initializer_.reset(
28 new ios::TestChromeProviderInitializer());
31 void OnTestEnd(const testing::TestInfo& test_info) override {
32 web_client_.reset();
33 web::SetWebClient(nullptr);
34 test_ios_chrome_provider_initializer_.reset();
37 private:
38 scoped_ptr<web::WebClient> web_client_;
39 scoped_ptr<ios::TestChromeProviderInitializer>
40 test_ios_chrome_provider_initializer_;
41 DISALLOW_COPY_AND_ASSIGN(IOSChromeUnitTestSuiteInitializer);
44 } // namespace
46 IOSChromeUnitTestSuite::IOSChromeUnitTestSuite(int argc, char** argv)
47 : base::TestSuite(argc, argv) {
50 IOSChromeUnitTestSuite::~IOSChromeUnitTestSuite() {
53 void IOSChromeUnitTestSuite::Initialize() {
54 // Add an additional listener to do the extra initialization for unit tests.
55 // It will be started before the base class listeners and ended after the
56 // base class listeners.
57 testing::TestEventListeners& listeners =
58 testing::UnitTest::GetInstance()->listeners();
59 listeners.Append(new IOSChromeUnitTestSuiteInitializer);
61 // Ensure that all BrowserStateKeyedServiceFactories are built before any
62 // test is run so that the dependencies are correctly resolved.
63 EnsureBrowserStateKeyedServiceFactoriesBuilt();
65 ios::RegisterPathProvider();
66 ui::RegisterPathProvider();
69 ios::TestChromeBrowserProvider provider;
70 url::AddStandardScheme(provider.GetChromeUIScheme());
73 base::TestSuite::Initialize();