Don't preload rarely seen large images
[chromium-blink-merge.git] / components / test / run_all_unittests.cc
blob0c2dd10de34e554f11169d3d8a4dba27b354d271
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.
5 #include "base/bind.h"
6 #include "base/files/file_path.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/metrics/statistics_recorder.h"
9 #include "base/path_service.h"
10 #include "base/test/launcher/unit_test_launcher.h"
11 #include "base/test/test_suite.h"
12 #include "components/content_settings/core/common/content_settings_pattern.h"
13 #include "content/public/test/test_content_client_initializer.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/base/ui_base_paths.h"
17 #include "url/url_util.h"
19 #if !defined(OS_IOS)
20 #include "ui/gl/gl_surface.h"
21 #endif
23 #if defined(OS_ANDROID)
24 #include "base/android/jni_android.h"
25 #include "components/invalidation/impl/android/component_jni_registrar.h"
26 #include "ui/base/android/ui_base_jni_registrar.h"
27 #include "ui/gfx/android/gfx_jni_registrar.h"
28 #endif
30 namespace {
32 class ComponentsTestSuite : public base::TestSuite {
33 public:
34 ComponentsTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
36 private:
37 void Initialize() override {
38 base::TestSuite::Initialize();
40 // Initialize the histograms subsystem, so that any histograms hit in tests
41 // are correctly registered with the statistics recorder and can be queried
42 // by tests.
43 base::StatisticsRecorder::Initialize();
45 #if !defined(OS_IOS)
46 gfx::GLSurface::InitializeOneOffForTests();
47 #endif
48 #if defined(OS_ANDROID)
49 // Register JNI bindings for android.
50 JNIEnv* env = base::android::AttachCurrentThread();
51 gfx::android::RegisterJni(env);
52 ui::android::RegisterJni(env);
53 invalidation::android::RegisterInvalidationJni(env);
54 #endif
56 ui::RegisterPathProvider();
58 base::FilePath pak_path;
59 #if defined(OS_ANDROID)
60 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path);
61 #else
62 PathService::Get(base::DIR_MODULE, &pak_path);
63 #endif
65 base::FilePath ui_test_pak_path;
66 ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
67 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
69 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
70 pak_path.AppendASCII("components_tests_resources.pak"),
71 ui::SCALE_FACTOR_NONE);
73 // These schemes need to be added globally to pass tests of
74 // autocomplete_input_unittest.cc and content_settings_pattern*
75 url::AddStandardScheme("chrome");
76 url::AddStandardScheme("chrome-extension");
77 url::AddStandardScheme("chrome-devtools");
78 url::AddStandardScheme("chrome-search");
80 // Not using kExtensionScheme to avoid the dependency to extensions.
81 ContentSettingsPattern::SetNonWildcardDomainNonPortScheme(
82 "chrome-extension");
85 void Shutdown() override {
86 ui::ResourceBundle::CleanupSharedInstance();
88 base::TestSuite::Shutdown();
91 DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite);
94 class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener {
95 public:
96 ComponentsUnitTestEventListener() {}
97 ~ComponentsUnitTestEventListener() override {}
99 void OnTestStart(const testing::TestInfo& test_info) override {
100 content_initializer_.reset(new content::TestContentClientInitializer());
103 void OnTestEnd(const testing::TestInfo& test_info) override {
104 content_initializer_.reset();
107 private:
108 scoped_ptr<content::TestContentClientInitializer> content_initializer_;
110 DISALLOW_COPY_AND_ASSIGN(ComponentsUnitTestEventListener);
113 } // namespace
115 int main(int argc, char** argv) {
116 ComponentsTestSuite test_suite(argc, argv);
118 // The listener will set up common test environment for all components unit
119 // tests.
120 testing::TestEventListeners& listeners =
121 testing::UnitTest::GetInstance()->listeners();
122 listeners.Append(new ComponentsUnitTestEventListener());
124 return base::LaunchUnitTests(
125 argc, argv, base::Bind(&base::TestSuite::Run,
126 base::Unretained(&test_suite)));