kaiwang@chromium.org | 64f5650c | 2013-01-11 05:35:09 | [diff] [blame] | 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 | |
phajdan.jr@chromium.org | d85fe1e | 2013-09-05 18:20:36 | [diff] [blame] | 5 | #include "base/bind.h" |
jam | 6bb3c8f | 2015-01-22 00:44:08 | [diff] [blame] | 6 | #include "base/files/file_path.h" |
kaiwang@chromium.org | 62885ab | 2013-01-23 03:55:16 | [diff] [blame] | 7 | #include "base/memory/scoped_ptr.h" |
mathp@chromium.org | bdceb3ba | 2014-07-25 16:47:48 | [diff] [blame] | 8 | #include "base/metrics/statistics_recorder.h" |
blundell@chromium.org | bcb9e87 | 2014-03-04 11:22:47 | [diff] [blame] | 9 | #include "base/path_service.h" |
phajdan.jr@chromium.org | ee881f40 | 2013-10-04 21:51:50 | [diff] [blame] | 10 | #include "base/test/launcher/unit_test_launcher.h" |
kaiwang@chromium.org | 64f5650c | 2013-01-11 05:35:09 | [diff] [blame] | 11 | #include "base/test/test_suite.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 12 | #include "components/content_settings/core/common/content_settings_pattern.h" |
kaiwang@chromium.org | 62885ab | 2013-01-23 03:55:16 | [diff] [blame] | 13 | #include "content/public/test/test_content_client_initializer.h" |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 15 | #include "ui/base/resource/resource_bundle.h" |
blundell@chromium.org | bcb9e87 | 2014-03-04 11:22:47 | [diff] [blame] | 16 | #include "ui/base/ui_base_paths.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 17 | #include "url/url_util.h" |
kaiwang@chromium.org | 62885ab | 2013-01-23 03:55:16 | [diff] [blame] | 18 | |
danakj@chromium.org | 55ad9fa1 | 2014-02-25 10:12:16 | [diff] [blame] | 19 | #if !defined(OS_IOS) |
sadrul | ba162cd | 2015-07-20 22:34:26 | [diff] [blame^] | 20 | #include "ui/gl/test/gl_surface_test_support.h" |
danakj@chromium.org | 55ad9fa1 | 2014-02-25 10:12:16 | [diff] [blame] | 21 | #endif |
| 22 | |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 23 | #if defined(OS_ANDROID) |
| 24 | #include "base/android/jni_android.h" |
knn | 062cdbb | 2015-06-26 18:18:42 | [diff] [blame] | 25 | #include "components/invalidation/impl/android/component_jni_registrar.h" |
bauerb | b1704d0 | 2015-07-13 11:05:44 | [diff] [blame] | 26 | #include "components/safe_json/android/component_jni_registrar.h" |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 27 | #include "ui/base/android/ui_base_jni_registrar.h" |
| 28 | #include "ui/gfx/android/gfx_jni_registrar.h" |
| 29 | #endif |
| 30 | |
| 31 | namespace { |
| 32 | |
| 33 | class ComponentsTestSuite : public base::TestSuite { |
| 34 | public: |
| 35 | ComponentsTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {} |
| 36 | |
| 37 | private: |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 38 | void Initialize() override { |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 39 | base::TestSuite::Initialize(); |
mathp@chromium.org | bdceb3ba | 2014-07-25 16:47:48 | [diff] [blame] | 40 | |
| 41 | // Initialize the histograms subsystem, so that any histograms hit in tests |
| 42 | // are correctly registered with the statistics recorder and can be queried |
| 43 | // by tests. |
| 44 | base::StatisticsRecorder::Initialize(); |
| 45 | |
danakj@chromium.org | 55ad9fa1 | 2014-02-25 10:12:16 | [diff] [blame] | 46 | #if !defined(OS_IOS) |
sadrul | ba162cd | 2015-07-20 22:34:26 | [diff] [blame^] | 47 | gfx::GLSurfaceTestSupport::InitializeOneOff(); |
danakj@chromium.org | 55ad9fa1 | 2014-02-25 10:12:16 | [diff] [blame] | 48 | #endif |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 49 | #if defined(OS_ANDROID) |
| 50 | // Register JNI bindings for android. |
| 51 | JNIEnv* env = base::android::AttachCurrentThread(); |
bauerb | b1704d0 | 2015-07-13 11:05:44 | [diff] [blame] | 52 | ASSERT_TRUE(gfx::android::RegisterJni(env)); |
| 53 | ASSERT_TRUE(ui::android::RegisterJni(env)); |
| 54 | ASSERT_TRUE(invalidation::android::RegisterInvalidationJni(env)); |
| 55 | ASSERT_TRUE(safe_json::android::RegisterSafeJsonJni(env)); |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 56 | #endif |
| 57 | |
blundell@chromium.org | bcb9e87 | 2014-03-04 11:22:47 | [diff] [blame] | 58 | ui::RegisterPathProvider(); |
| 59 | |
tfarina | e80cf1c | 2015-02-16 12:44:10 | [diff] [blame] | 60 | base::FilePath pak_path; |
jam | 6bb3c8f | 2015-01-22 00:44:08 | [diff] [blame] | 61 | #if defined(OS_ANDROID) |
tfarina | e80cf1c | 2015-02-16 12:44:10 | [diff] [blame] | 62 | PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path); |
jam | 6bb3c8f | 2015-01-22 00:44:08 | [diff] [blame] | 63 | #else |
tfarina | e80cf1c | 2015-02-16 12:44:10 | [diff] [blame] | 64 | PathService::Get(base::DIR_MODULE, &pak_path); |
dcheng | bb135a2e | 2015-01-07 19:42:16 | [diff] [blame] | 65 | #endif |
sadrul | 618bc16 | 2015-05-13 16:09:53 | [diff] [blame] | 66 | |
| 67 | base::FilePath ui_test_pak_path; |
| 68 | ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); |
| 69 | ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); |
| 70 | |
| 71 | ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
| 72 | pak_path.AppendASCII("components_tests_resources.pak"), |
| 73 | ui::SCALE_FACTOR_NONE); |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 74 | |
| 75 | // These schemes need to be added globally to pass tests of |
| 76 | // autocomplete_input_unittest.cc and content_settings_pattern* |
| 77 | url::AddStandardScheme("chrome"); |
| 78 | url::AddStandardScheme("chrome-extension"); |
| 79 | url::AddStandardScheme("chrome-devtools"); |
| 80 | url::AddStandardScheme("chrome-search"); |
| 81 | |
| 82 | // Not using kExtensionScheme to avoid the dependency to extensions. |
| 83 | ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( |
| 84 | "chrome-extension"); |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 85 | } |
| 86 | |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 87 | void Shutdown() override { |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 88 | ui::ResourceBundle::CleanupSharedInstance(); |
chrishtr | a2e3cc7 | 2015-01-21 23:10:23 | [diff] [blame] | 89 | |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 90 | base::TestSuite::Shutdown(); |
| 91 | } |
| 92 | |
| 93 | DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite); |
| 94 | }; |
kaiwang@chromium.org | 62885ab | 2013-01-23 03:55:16 | [diff] [blame] | 95 | |
| 96 | class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener { |
| 97 | public: |
| 98 | ComponentsUnitTestEventListener() {} |
nick | 79ff566 | 2015-04-28 17:22:22 | [diff] [blame] | 99 | ~ComponentsUnitTestEventListener() override {} |
kaiwang@chromium.org | 62885ab | 2013-01-23 03:55:16 | [diff] [blame] | 100 | |
nick | 79ff566 | 2015-04-28 17:22:22 | [diff] [blame] | 101 | void OnTestStart(const testing::TestInfo& test_info) override { |
kaiwang@chromium.org | 62885ab | 2013-01-23 03:55:16 | [diff] [blame] | 102 | content_initializer_.reset(new content::TestContentClientInitializer()); |
| 103 | } |
| 104 | |
nick | 79ff566 | 2015-04-28 17:22:22 | [diff] [blame] | 105 | void OnTestEnd(const testing::TestInfo& test_info) override { |
kaiwang@chromium.org | 62885ab | 2013-01-23 03:55:16 | [diff] [blame] | 106 | content_initializer_.reset(); |
| 107 | } |
| 108 | |
| 109 | private: |
| 110 | scoped_ptr<content::TestContentClientInitializer> content_initializer_; |
| 111 | |
| 112 | DISALLOW_COPY_AND_ASSIGN(ComponentsUnitTestEventListener); |
| 113 | }; |
| 114 | |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 115 | } // namespace |
kaiwang@chromium.org | 64f5650c | 2013-01-11 05:35:09 | [diff] [blame] | 116 | |
| 117 | int main(int argc, char** argv) { |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 118 | ComponentsTestSuite test_suite(argc, argv); |
nhiroki@chromium.org | df2622c | 2013-08-12 03:41:34 | [diff] [blame] | 119 | |
kaiwang@chromium.org | 62885ab | 2013-01-23 03:55:16 | [diff] [blame] | 120 | // The listener will set up common test environment for all components unit |
| 121 | // tests. |
| 122 | testing::TestEventListeners& listeners = |
| 123 | testing::UnitTest::GetInstance()->listeners(); |
tfarina@chromium.org | f84b533 | 2013-12-17 14:50:50 | [diff] [blame] | 124 | listeners.Append(new ComponentsUnitTestEventListener()); |
kaiwang@chromium.org | 62885ab | 2013-01-23 03:55:16 | [diff] [blame] | 125 | |
phajdan.jr@chromium.org | d85fe1e | 2013-09-05 18:20:36 | [diff] [blame] | 126 | return base::LaunchUnitTests( |
| 127 | argc, argv, base::Bind(&base::TestSuite::Run, |
| 128 | base::Unretained(&test_suite))); |
kaiwang@chromium.org | 64f5650c | 2013-01-11 05:35:09 | [diff] [blame] | 129 | } |