[go: nahoru, domu]

blob: fd327a18210f7cb1a39f7b5b6f5ad921d4abedfd [file] [log] [blame]
kaiwang@chromium.org64f5650c2013-01-11 05:35:091// 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.orgd85fe1e2013-09-05 18:20:365#include "base/bind.h"
jam6bb3c8f2015-01-22 00:44:086#include "base/files/file_path.h"
kaiwang@chromium.org62885ab2013-01-23 03:55:167#include "base/memory/scoped_ptr.h"
mathp@chromium.orgbdceb3ba2014-07-25 16:47:488#include "base/metrics/statistics_recorder.h"
blundell@chromium.orgbcb9e872014-03-04 11:22:479#include "base/path_service.h"
phajdan.jr@chromium.orgee881f402013-10-04 21:51:5010#include "base/test/launcher/unit_test_launcher.h"
kaiwang@chromium.org64f5650c2013-01-11 05:35:0911#include "base/test/test_suite.h"
mukai077089f2014-09-11 18:41:5212#include "components/content_settings/core/common/content_settings_pattern.h"
kaiwang@chromium.org62885ab2013-01-23 03:55:1613#include "content/public/test/test_content_client_initializer.h"
14#include "testing/gtest/include/gtest/gtest.h"
tfarina@chromium.orgf84b5332013-12-17 14:50:5015#include "ui/base/resource/resource_bundle.h"
blundell@chromium.orgbcb9e872014-03-04 11:22:4716#include "ui/base/ui_base_paths.h"
mukai077089f2014-09-11 18:41:5217#include "url/url_util.h"
kaiwang@chromium.org62885ab2013-01-23 03:55:1618
danakj@chromium.org55ad9fa12014-02-25 10:12:1619#if !defined(OS_IOS)
sadrulba162cd2015-07-20 22:34:2620#include "ui/gl/test/gl_surface_test_support.h"
danakj@chromium.org55ad9fa12014-02-25 10:12:1621#endif
22
tfarina@chromium.orgf84b5332013-12-17 14:50:5023#if defined(OS_ANDROID)
24#include "base/android/jni_android.h"
knn062cdbb2015-06-26 18:18:4225#include "components/invalidation/impl/android/component_jni_registrar.h"
bauerbb1704d02015-07-13 11:05:4426#include "components/safe_json/android/component_jni_registrar.h"
tfarina@chromium.orgf84b5332013-12-17 14:50:5027#include "ui/base/android/ui_base_jni_registrar.h"
28#include "ui/gfx/android/gfx_jni_registrar.h"
29#endif
30
31namespace {
32
33class ComponentsTestSuite : public base::TestSuite {
34 public:
35 ComponentsTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
36
37 private:
dcheng00ea022b2014-10-21 11:24:5638 void Initialize() override {
tfarina@chromium.orgf84b5332013-12-17 14:50:5039 base::TestSuite::Initialize();
mathp@chromium.orgbdceb3ba2014-07-25 16:47:4840
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.org55ad9fa12014-02-25 10:12:1646#if !defined(OS_IOS)
sadrulba162cd2015-07-20 22:34:2647 gfx::GLSurfaceTestSupport::InitializeOneOff();
danakj@chromium.org55ad9fa12014-02-25 10:12:1648#endif
tfarina@chromium.orgf84b5332013-12-17 14:50:5049#if defined(OS_ANDROID)
50 // Register JNI bindings for android.
51 JNIEnv* env = base::android::AttachCurrentThread();
bauerbb1704d02015-07-13 11:05:4452 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.orgf84b5332013-12-17 14:50:5056#endif
57
blundell@chromium.orgbcb9e872014-03-04 11:22:4758 ui::RegisterPathProvider();
59
tfarinae80cf1c2015-02-16 12:44:1060 base::FilePath pak_path;
jam6bb3c8f2015-01-22 00:44:0861#if defined(OS_ANDROID)
tfarinae80cf1c2015-02-16 12:44:1062 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path);
jam6bb3c8f2015-01-22 00:44:0863#else
tfarinae80cf1c2015-02-16 12:44:1064 PathService::Get(base::DIR_MODULE, &pak_path);
dchengbb135a2e2015-01-07 19:42:1665#endif
sadrul618bc162015-05-13 16:09:5366
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);
mukai077089f2014-09-11 18:41:5274
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.orgf84b5332013-12-17 14:50:5085 }
86
dcheng00ea022b2014-10-21 11:24:5687 void Shutdown() override {
tfarina@chromium.orgf84b5332013-12-17 14:50:5088 ui::ResourceBundle::CleanupSharedInstance();
chrishtra2e3cc72015-01-21 23:10:2389
tfarina@chromium.orgf84b5332013-12-17 14:50:5090 base::TestSuite::Shutdown();
91 }
92
93 DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite);
94};
kaiwang@chromium.org62885ab2013-01-23 03:55:1695
96class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener {
97 public:
98 ComponentsUnitTestEventListener() {}
nick79ff5662015-04-28 17:22:2299 ~ComponentsUnitTestEventListener() override {}
kaiwang@chromium.org62885ab2013-01-23 03:55:16100
nick79ff5662015-04-28 17:22:22101 void OnTestStart(const testing::TestInfo& test_info) override {
kaiwang@chromium.org62885ab2013-01-23 03:55:16102 content_initializer_.reset(new content::TestContentClientInitializer());
103 }
104
nick79ff5662015-04-28 17:22:22105 void OnTestEnd(const testing::TestInfo& test_info) override {
kaiwang@chromium.org62885ab2013-01-23 03:55:16106 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.orgf84b5332013-12-17 14:50:50115} // namespace
kaiwang@chromium.org64f5650c2013-01-11 05:35:09116
117int main(int argc, char** argv) {
tfarina@chromium.orgf84b5332013-12-17 14:50:50118 ComponentsTestSuite test_suite(argc, argv);
nhiroki@chromium.orgdf2622c2013-08-12 03:41:34119
kaiwang@chromium.org62885ab2013-01-23 03:55:16120 // 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.orgf84b5332013-12-17 14:50:50124 listeners.Append(new ComponentsUnitTestEventListener());
kaiwang@chromium.org62885ab2013-01-23 03:55:16125
phajdan.jr@chromium.orgd85fe1e2013-09-05 18:20:36126 return base::LaunchUnitTests(
127 argc, argv, base::Bind(&base::TestSuite::Run,
128 base::Unretained(&test_suite)));
kaiwang@chromium.org64f5650c2013-01-11 05:35:09129}