Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/path_service.h" | |
| 7 #include "base/test/launcher/unit_test_launcher.h" | 8 #include "base/test/launcher/unit_test_launcher.h" |
| 8 #include "base/test/test_suite.h" | 9 #include "base/test/test_suite.h" |
| 9 #include "content/public/test/test_content_client_initializer.h" | 10 #include "content/public/test/test_content_client_initializer.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | |
| 11 | 13 |
| 12 namespace components { | 14 namespace { |
| 13 | 15 |
| 14 class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener { | 16 class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener { |
| 15 public: | 17 public: |
| 16 ComponentsUnitTestEventListener() {} | 18 ComponentsUnitTestEventListener() {} |
| 17 virtual ~ComponentsUnitTestEventListener() {} | 19 virtual ~ComponentsUnitTestEventListener() {} |
| 18 | 20 |
| 19 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { | 21 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { |
| 20 content_initializer_.reset(new content::TestContentClientInitializer()); | 22 content_initializer_.reset(new content::TestContentClientInitializer()); |
| 21 } | 23 } |
| 22 | 24 |
| 23 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | 25 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { |
| 24 content_initializer_.reset(); | 26 content_initializer_.reset(); |
| 25 } | 27 } |
| 26 | 28 |
| 27 private: | 29 private: |
| 28 scoped_ptr<content::TestContentClientInitializer> content_initializer_; | 30 scoped_ptr<content::TestContentClientInitializer> content_initializer_; |
| 29 | 31 |
| 30 DISALLOW_COPY_AND_ASSIGN(ComponentsUnitTestEventListener); | 32 DISALLOW_COPY_AND_ASSIGN(ComponentsUnitTestEventListener); |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 } // namespace components | 35 class ComponentsTestSuite : public base::TestSuite { |
| 36 public: | |
| 37 ComponentsTestSuite(int argc, char** argv); | |
| 38 | |
| 39 private: | |
| 40 virtual void Initialize() OVERRIDE; | |
| 41 virtual void Shutdown() OVERRIDE; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite); | |
| 44 }; | |
| 45 | |
| 46 ComponentsTestSuite::ComponentsTestSuite(int argc, char** argv) | |
| 47 : TestSuite(argc, argv) {} | |
| 48 | |
| 49 void ComponentsTestSuite::Initialize() { | |
| 50 base::TestSuite::Initialize(); | |
| 51 | |
| 52 base::FilePath pak_dir; | |
| 53 PathService::Get(base::DIR_MODULE, &pak_dir); | |
| 54 | |
| 55 base::FilePath pak_file; | |
| 56 pak_file = pak_dir.AppendASCII("components") | |
| 57 .AppendASCII("paks") | |
| 58 .AppendASCII("components_test.pak"); | |
| 59 | |
| 60 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | |
|
Peter Beverloo
2013/11/27 19:00:20
ui::ResourceBundle requires screen information, wh
| |
| 61 } | |
| 62 | |
| 63 void ComponentsTestSuite::Shutdown() { | |
| 64 ui::ResourceBundle::CleanupSharedInstance(); | |
| 65 base::TestSuite::Shutdown(); | |
| 66 } | |
| 67 | |
| 68 } // namespace | |
| 34 | 69 |
| 35 int main(int argc, char** argv) { | 70 int main(int argc, char** argv) { |
| 36 base::TestSuite test_suite(argc, argv); | 71 ComponentsTestSuite test_suite(argc, argv); |
| 37 | 72 |
| 38 // The listener will set up common test environment for all components unit | 73 // The listener will set up common test environment for all components unit |
| 39 // tests. | 74 // tests. |
| 40 testing::TestEventListeners& listeners = | 75 testing::TestEventListeners& listeners = |
| 41 testing::UnitTest::GetInstance()->listeners(); | 76 testing::UnitTest::GetInstance()->listeners(); |
| 42 listeners.Append(new components::ComponentsUnitTestEventListener()); | 77 listeners.Append(new ComponentsUnitTestEventListener()); |
| 43 | 78 |
| 44 return base::LaunchUnitTests( | 79 return base::LaunchUnitTests( |
| 45 argc, argv, base::Bind(&base::TestSuite::Run, | 80 argc, |
| 46 base::Unretained(&test_suite))); | 81 argv, |
| 82 base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite))); | |
| 47 } | 83 } |
| OLD | NEW |