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/test/test_content_client_initializer.h" 11 #include "content/test/test_content_client.h" 12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "ui/base/resource/resource_bundle.h" 14 15 #if defined(OS_MACOSX) 16 #include "base/mac/scoped_nsautorelease_pool.h" 17 #endif 18 19 namespace { 20 21 class TestInitializationListener : public testing::EmptyTestEventListener { 22 public: TestInitializationListener()23 TestInitializationListener() : test_content_client_initializer_(NULL) { 24 } 25 OnTestStart(const testing::TestInfo & test_info)26 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { 27 test_content_client_initializer_ = 28 new content::TestContentClientInitializer(); 29 } 30 OnTestEnd(const testing::TestInfo & test_info)31 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { 32 delete test_content_client_initializer_; 33 } 34 35 private: 36 content::TestContentClientInitializer* test_content_client_initializer_; 37 38 DISALLOW_COPY_AND_ASSIGN(TestInitializationListener); 39 }; 40 41 } // namespace 42 43 namespace content { 44 ContentTestSuite(int argc,char ** argv)45ContentTestSuite::ContentTestSuite(int argc, char** argv) 46 : ContentTestSuiteBase(argc, argv) { 47 #if defined(USE_AURA) 48 base::FilePath pak_file; 49 PathService::Get(base::DIR_MODULE, &pak_file); 50 pak_file = pak_file.AppendASCII("ui_test.pak"); 51 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); 52 #endif 53 } 54 ~ContentTestSuite()55ContentTestSuite::~ContentTestSuite() { 56 #if defined(USE_AURA) 57 ui::ResourceBundle::CleanupSharedInstance(); 58 #endif 59 } 60 Initialize()61void ContentTestSuite::Initialize() { 62 #if defined(OS_MACOSX) 63 base::mac::ScopedNSAutoreleasePool autorelease_pool; 64 #endif 65 66 ContentTestSuiteBase::Initialize(); 67 68 testing::TestEventListeners& listeners = 69 testing::UnitTest::GetInstance()->listeners(); 70 listeners.Append(new TestInitializationListener); 71 } 72 CreateClientForInitialization()73ContentClient* ContentTestSuite::CreateClientForInitialization() { 74 return new TestContentClient(); 75 } 76 77 } // namespace content 78