Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / test / content_test_suite.cc
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.
4
5 #include "content/test/content_test_suite.h"
6
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"
16
17 #if defined(OS_MACOSX)
18 #include "base/mac/scoped_nsautorelease_pool.h"
19 #endif
20
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
27
28 namespace {
29
30 class TestInitializationListener : public testing::EmptyTestEventListener {
31  public:
32   TestInitializationListener() : test_content_client_initializer_(NULL) {
33   }
34
35   virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE {
36     test_content_client_initializer_ =
37         new content::TestContentClientInitializer();
38   }
39
40   virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
41     delete test_content_client_initializer_;
42   }
43
44  private:
45   content::TestContentClientInitializer* test_content_client_initializer_;
46
47   DISALLOW_COPY_AND_ASSIGN(TestInitializationListener);
48 };
49
50 }  // namespace
51
52 namespace content {
53
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
62 }
63
64 ContentTestSuite::~ContentTestSuite() {
65 #if defined(USE_AURA)
66   ui::ResourceBundle::CleanupSharedInstance();
67 #endif
68 }
69
70 void ContentTestSuite::Initialize() {
71 #if defined(OS_MACOSX)
72   base::mac::ScopedNSAutoreleasePool autorelease_pool;
73 #endif
74
75   ContentTestSuiteBase::Initialize();
76   {
77     ContentClient client;
78     ContentTestSuiteBase::RegisterContentSchemes(&client);
79   }
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());
89   }
90 #endif
91   testing::TestEventListeners& listeners =
92       testing::UnitTest::GetInstance()->listeners();
93   listeners.Append(new TestInitializationListener);
94 }
95
96 }  // namespace content