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_CHROMEOS)
26 #include "base/process/process_metrics.h"
27 #include "chromeos/chromeos_paths.h"
30 #if defined(OS_MACOSX)
31 #include "base/mac/bundle_locations.h"
32 #include "base/mac/scoped_nsautorelease_pool.h"
34 #include "chrome/browser/chrome_browser_application_mac.h"
35 #endif // !defined(OS_IOS)
39 #include "media/base/media.h"
44 bool IsCrosPythonProcess() {
45 #if defined(OS_CHROMEOS)
47 int num_read
= readlink(base::kProcSelfExe
, buf
, sizeof(buf
) - 1);
51 const char kPythonPrefix
[] = "/python";
52 return !strncmp(strrchr(buf
, '/'), kPythonPrefix
, sizeof(kPythonPrefix
) - 1);
55 #endif // defined(OS_CHROMEOS)
60 ChromeTestSuite::ChromeTestSuite(int argc
, char** argv
)
61 : content::ContentTestSuiteBase(argc
, argv
) {
64 ChromeTestSuite::~ChromeTestSuite() {
67 void ChromeTestSuite::Initialize() {
68 #if defined(OS_MACOSX)
69 base::mac::ScopedNSAutoreleasePool autorelease_pool
;
71 chrome_browser_application_mac::RegisterBrowserCrApp();
72 #endif // !defined(OS_IOS)
75 if (!browser_dir_
.empty()) {
76 PathService::Override(base::DIR_EXE
, browser_dir_
);
77 PathService::Override(base::DIR_MODULE
, browser_dir_
);
81 // Disable external libraries load if we are under python process in
82 // ChromeOS. That means we are autotest and, if ASAN is used,
83 // external libraries load crashes.
84 if (!IsCrosPythonProcess())
85 media::InitializeMediaLibrary();
88 // Initialize after overriding paths as some content paths depend on correct
89 // values for DIR_EXE and DIR_MODULE.
90 content::ContentTestSuiteBase::Initialize();
92 ContentSettingsPattern::SetNonWildcardDomainNonPortScheme(
93 extensions::kExtensionScheme
);
95 #if defined(OS_MACOSX) && !defined(OS_IOS)
96 // Look in the framework bundle for resources.
98 PathService::Get(base::DIR_EXE
, &path
);
99 path
= path
.Append(chrome::kFrameworkName
);
100 base::mac::SetOverrideFrameworkBundlePath(path
);
104 void ChromeTestSuite::Shutdown() {
105 #if defined(OS_MACOSX) && !defined(OS_IOS)
106 base::mac::SetOverrideFrameworkBundle(NULL
);
109 content::ContentTestSuiteBase::Shutdown();