Make audio thread hang checker less chatty.
[chromium-blink-merge.git] / chrome / test / base / chrome_test_suite.cc
blob933d6a00d76025e0ff7d68489007e2db1044f4bb
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)
8 #include <stdio.h>
9 #include <unistd.h>
10 #endif
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"
28 #endif
30 #if defined(OS_MACOSX)
31 #include "base/mac/bundle_locations.h"
32 #include "base/mac/scoped_nsautorelease_pool.h"
33 #if !defined(OS_IOS)
34 #include "chrome/browser/chrome_browser_application_mac.h"
35 #endif // !defined(OS_IOS)
36 #endif
38 #if !defined(OS_IOS)
39 #include "media/base/media.h"
40 #endif
42 namespace {
44 bool IsCrosPythonProcess() {
45 #if defined(OS_CHROMEOS)
46 char buf[80];
47 int num_read = readlink(base::kProcSelfExe, buf, sizeof(buf) - 1);
48 if (num_read == -1)
49 return false;
50 buf[num_read] = 0;
51 const char kPythonPrefix[] = "/python";
52 return !strncmp(strrchr(buf, '/'), kPythonPrefix, sizeof(kPythonPrefix) - 1);
53 #else
54 return false;
55 #endif // defined(OS_CHROMEOS)
58 } // namespace
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;
70 #if !defined(OS_IOS)
71 chrome_browser_application_mac::RegisterBrowserCrApp();
72 #endif // !defined(OS_IOS)
73 #endif
75 if (!browser_dir_.empty()) {
76 PathService::Override(base::DIR_EXE, browser_dir_);
77 PathService::Override(base::DIR_MODULE, browser_dir_);
80 #if !defined(OS_IOS)
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();
86 #endif
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.
97 base::FilePath path;
98 PathService::Get(base::DIR_EXE, &path);
99 path = path.Append(chrome::kFrameworkName);
100 base::mac::SetOverrideFrameworkBundlePath(path);
101 #endif
104 void ChromeTestSuite::Shutdown() {
105 #if defined(OS_MACOSX) && !defined(OS_IOS)
106 base::mac::SetOverrideFrameworkBundle(NULL);
107 #endif
109 content::ContentTestSuiteBase::Shutdown();