Durable Storage: Refactor browser test and test the basic "deny" flow.
[chromium-blink-merge.git] / chrome / test / base / chrome_test_suite.cc
blob6581d13d17539c087194a452fba2e140aabd774b
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_ANDROID)
26 #include "base/android/jni_android.h"
27 #include "chrome/browser/android/chrome_jni_registrar.h"
28 #endif
30 #if defined(OS_CHROMEOS)
31 #include "base/process/process_metrics.h"
32 #include "chromeos/chromeos_paths.h"
33 #endif
35 #if defined(OS_MACOSX)
36 #include "base/mac/bundle_locations.h"
37 #include "base/mac/scoped_nsautorelease_pool.h"
38 #if !defined(OS_IOS)
39 #include "chrome/browser/chrome_browser_application_mac.h"
40 #endif // !defined(OS_IOS)
41 #endif
43 #if !defined(OS_IOS)
44 #include "media/base/media.h"
45 #endif
47 namespace {
49 bool IsCrosPythonProcess() {
50 #if defined(OS_CHROMEOS)
51 char buf[80];
52 int num_read = readlink(base::kProcSelfExe, buf, sizeof(buf) - 1);
53 if (num_read == -1)
54 return false;
55 buf[num_read] = 0;
56 const char kPythonPrefix[] = "/python";
57 return !strncmp(strrchr(buf, '/'), kPythonPrefix, sizeof(kPythonPrefix) - 1);
58 #else
59 return false;
60 #endif // defined(OS_CHROMEOS)
63 } // namespace
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;
75 #if !defined(OS_IOS)
76 chrome_browser_application_mac::RegisterBrowserCrApp();
77 #endif // !defined(OS_IOS)
78 #endif
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()));
88 #endif
90 #if !defined(OS_IOS)
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();
96 #endif
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.
107 base::FilePath path;
108 PathService::Get(base::DIR_EXE, &path);
109 path = path.Append(chrome::kFrameworkName);
110 base::mac::SetOverrideFrameworkBundlePath(path);
111 #endif
114 void ChromeTestSuite::Shutdown() {
115 #if defined(OS_MACOSX) && !defined(OS_IOS)
116 base::mac::SetOverrideFrameworkBundle(NULL);
117 #endif
119 content::ContentTestSuiteBase::Shutdown();