Blink roll 174933:174969
[chromium-blink-merge.git] / content / test / content_test_suite.cc
blob9aef7703914d78dc6092180d77a7648f1f92302d
1 // Copyright (c) 2012 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 "content/test/content_test_suite.h"
7 #include "base/base_paths.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "content/public/common/content_client.h"
11 #include "content/public/common/content_paths.h"
12 #include "content/public/test/test_content_client_initializer.h"
13 #include "gpu/config/gpu_util.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/resource/resource_bundle.h"
17 #if defined(OS_MACOSX)
18 #include "base/mac/scoped_nsautorelease_pool.h"
19 #endif
21 #if !defined(OS_IOS)
22 #include "base/base_switches.h"
23 #include "base/command_line.h"
24 #include "media/base/media.h"
25 #include "ui/gl/gl_surface.h"
26 #endif
28 namespace {
30 class TestInitializationListener : public testing::EmptyTestEventListener {
31 public:
32 TestInitializationListener() : test_content_client_initializer_(NULL) {
35 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE {
36 test_content_client_initializer_ =
37 new content::TestContentClientInitializer();
40 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
41 delete test_content_client_initializer_;
44 private:
45 content::TestContentClientInitializer* test_content_client_initializer_;
47 DISALLOW_COPY_AND_ASSIGN(TestInitializationListener);
50 } // namespace
52 namespace content {
54 ContentTestSuite::ContentTestSuite(int argc, char** argv)
55 : ContentTestSuiteBase(argc, argv) {
56 #if defined(USE_AURA)
57 base::FilePath pak_file;
58 PathService::Get(base::DIR_MODULE, &pak_file);
59 pak_file = pak_file.AppendASCII("ui_test.pak");
60 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
61 #endif
64 ContentTestSuite::~ContentTestSuite() {
65 #if defined(USE_AURA)
66 ui::ResourceBundle::CleanupSharedInstance();
67 #endif
70 void ContentTestSuite::Initialize() {
71 #if defined(OS_MACOSX)
72 base::mac::ScopedNSAutoreleasePool autorelease_pool;
73 #endif
75 ContentTestSuiteBase::Initialize();
77 ContentClient client;
78 ContentTestSuiteBase::RegisterContentSchemes(&client);
80 RegisterPathProvider();
81 #if !defined(OS_IOS)
82 media::InitializeMediaLibraryForTesting();
83 // When running in a child process for Mac sandbox tests, the sandbox exists
84 // to initialize GL, so don't do it here.
85 if (!CommandLine::ForCurrentProcess()->HasSwitch(
86 switches::kTestChildProcess)) {
87 gfx::GLSurface::InitializeOneOffForTests();
88 gpu::ApplyGpuDriverBugWorkarounds(CommandLine::ForCurrentProcess());
90 #endif
91 testing::TestEventListeners& listeners =
92 testing::UnitTest::GetInstance()->listeners();
93 listeners.Append(new TestInitializationListener);
96 } // namespace content