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 "chrome/test/base/chrome_test_suite.h"
7 #if defined(OS_CHROMEOS)
12 #include "base/command_line.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/path_service.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/common/chrome_constants.h"
18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/url_constants.h"
20 #include "components/content_settings/core/common/content_settings_pattern.h"
21 #include "content/public/test/test_launcher.h"
22 #include "extensions/common/constants.h"
23 #include "testing/gtest/include/gtest/gtest.h"
25 #if defined(OS_ANDROID)
26 #include "base/android/jni_android.h"
27 #include "chrome/browser/android/chrome_jni_registrar.h"
28 #include "net/android/net_jni_registrar.h"
29 #include "ui/base/android/ui_base_jni_registrar.h"
30 #include "ui/gfx/android/gfx_jni_registrar.h"
31 #include "ui/gl/android/gl_jni_registrar.h"
34 #if defined(OS_CHROMEOS)
35 #include "base/process/process_metrics.h"
36 #include "chromeos/chromeos_paths.h"
39 #if defined(OS_MACOSX)
40 #include "base/mac/bundle_locations.h"
41 #include "base/mac/scoped_nsautorelease_pool.h"
43 #include "chrome/browser/chrome_browser_application_mac.h"
44 #endif // !defined(OS_IOS)
48 #include "media/base/media.h"
53 bool IsCrosPythonProcess() {
54 #if defined(OS_CHROMEOS)
56 int num_read
= readlink(base::kProcSelfExe
, buf
, sizeof(buf
) - 1);
60 const char kPythonPrefix
[] = "/python";
61 return !strncmp(strrchr(buf
, '/'), kPythonPrefix
, sizeof(kPythonPrefix
) - 1);
64 #endif // defined(OS_CHROMEOS)
69 ChromeTestSuite::ChromeTestSuite(int argc
, char** argv
)
70 : content::ContentTestSuiteBase(argc
, argv
) {
73 ChromeTestSuite::~ChromeTestSuite() {
76 void ChromeTestSuite::Initialize() {
77 #if defined(OS_MACOSX)
78 base::mac::ScopedNSAutoreleasePool autorelease_pool
;
80 chrome_browser_application_mac::RegisterBrowserCrApp();
81 #endif // !defined(OS_IOS)
84 #if defined(OS_ANDROID)
85 // Register JNI bindings for android.
86 gfx::android::RegisterJni(base::android::AttachCurrentThread());
87 net::android::RegisterJni(base::android::AttachCurrentThread());
88 ui::android::RegisterJni(base::android::AttachCurrentThread());
89 ui::gl::android::RegisterJni(base::android::AttachCurrentThread());
90 chrome::android::RegisterJni(base::android::AttachCurrentThread());
93 if (!browser_dir_
.empty()) {
94 PathService::Override(base::DIR_EXE
, browser_dir_
);
95 PathService::Override(base::DIR_MODULE
, browser_dir_
);
99 // Disable external libraries load if we are under python process in
100 // ChromeOS. That means we are autotest and, if ASAN is used,
101 // external libraries load crashes.
102 if (!IsCrosPythonProcess())
103 media::InitializeMediaLibraryForTesting();
106 // Initialize after overriding paths as some content paths depend on correct
107 // values for DIR_EXE and DIR_MODULE.
108 content::ContentTestSuiteBase::Initialize();
110 ContentSettingsPattern::SetNonWildcardDomainNonPortScheme(
111 extensions::kExtensionScheme
);
113 #if defined(OS_MACOSX) && !defined(OS_IOS)
114 // Look in the framework bundle for resources.
116 PathService::Get(base::DIR_EXE
, &path
);
117 path
= path
.Append(chrome::kFrameworkName
);
118 base::mac::SetOverrideFrameworkBundlePath(path
);
122 void ChromeTestSuite::Shutdown() {
123 #if defined(OS_MACOSX) && !defined(OS_IOS)
124 base::mac::SetOverrideFrameworkBundle(NULL
);
127 content::ContentTestSuiteBase::Shutdown();