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"
30 #if defined(OS_CHROMEOS)
31 #include "base/process/process_metrics.h"
32 #include "chromeos/chromeos_paths.h"
35 #if defined(OS_MACOSX)
36 #include "base/mac/bundle_locations.h"
37 #include "base/mac/scoped_nsautorelease_pool.h"
39 #include "chrome/browser/chrome_browser_application_mac.h"
40 #endif // !defined(OS_IOS)
44 #include "media/base/media.h"
49 bool IsCrosPythonProcess() {
50 #if defined(OS_CHROMEOS)
52 int num_read
= readlink(base::kProcSelfExe
, buf
, sizeof(buf
) - 1);
56 const char kPythonPrefix
[] = "/python";
57 return !strncmp(strrchr(buf
, '/'), kPythonPrefix
, sizeof(kPythonPrefix
) - 1);
60 #endif // defined(OS_CHROMEOS)
65 ChromeTestSuite::ChromeTestSuite(int argc
, char** argv
)
66 : content::ContentTestSuiteBase(argc
, argv
) {
69 ChromeTestSuite::~ChromeTestSuite() {
72 void ChromeTestSuite::Initialize() {
73 #if defined(OS_MACOSX)
74 base::mac::ScopedNSAutoreleasePool autorelease_pool
;
76 chrome_browser_application_mac::RegisterBrowserCrApp();
77 #endif // !defined(OS_IOS)
80 if (!browser_dir_
.empty()) {
81 PathService::Override(base::DIR_EXE
, browser_dir_
);
82 PathService::Override(base::DIR_MODULE
, browser_dir_
);
85 #if defined(OS_ANDROID)
86 ASSERT_TRUE(chrome::android::RegisterBrowserJNI(
87 base::android::AttachCurrentThread()));
91 // Disable external libraries load if we are under python process in
92 // ChromeOS. That means we are autotest and, if ASAN is used,
93 // external libraries load crashes.
94 if (!IsCrosPythonProcess())
95 media::InitializeMediaLibrary();
98 // Initialize after overriding paths as some content paths depend on correct
99 // values for DIR_EXE and DIR_MODULE.
100 content::ContentTestSuiteBase::Initialize();
102 ContentSettingsPattern::SetNonWildcardDomainNonPortScheme(
103 extensions::kExtensionScheme
);
105 #if defined(OS_MACOSX) && !defined(OS_IOS)
106 // Look in the framework bundle for resources.
108 PathService::Get(base::DIR_EXE
, &path
);
109 path
= path
.Append(chrome::kFrameworkName
);
110 base::mac::SetOverrideFrameworkBundlePath(path
);
114 void ChromeTestSuite::Shutdown() {
115 #if defined(OS_MACOSX) && !defined(OS_IOS)
116 base::mac::SetOverrideFrameworkBundle(NULL
);
119 content::ContentTestSuiteBase::Shutdown();