Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / test / base / chrome_test_suite.cc
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.
4
5 #include "chrome/test/base/chrome_test_suite.h"
6
7 #if defined(OS_CHROMEOS)
8 #include <stdio.h>
9 #include <unistd.h>
10 #endif
11
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"
24
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"
32 #endif
33
34 #if defined(OS_CHROMEOS)
35 #include "base/process/process_metrics.h"
36 #include "chromeos/chromeos_paths.h"
37 #endif
38
39 #if defined(OS_MACOSX)
40 #include "base/mac/bundle_locations.h"
41 #include "base/mac/scoped_nsautorelease_pool.h"
42 #if !defined(OS_IOS)
43 #include "base/mac/mac_util.h"
44 #include "chrome/browser/chrome_browser_application_mac.h"
45 #endif  // !defined(OS_IOS)
46 #endif
47
48 #if !defined(OS_IOS)
49 #include "media/base/media.h"
50 #endif
51
52 namespace {
53
54 bool IsCrosPythonProcess() {
55 #if defined(OS_CHROMEOS)
56   char buf[80];
57   int num_read = readlink(base::kProcSelfExe, buf, sizeof(buf) - 1);
58   if (num_read == -1)
59     return false;
60   buf[num_read] = 0;
61   const char kPythonPrefix[] = "/python";
62   return !strncmp(strrchr(buf, '/'), kPythonPrefix, sizeof(kPythonPrefix) - 1);
63 #else
64   return false;
65 #endif  // defined(OS_CHROMEOS)
66 }
67
68 }  // namespace
69
70 ChromeTestSuite::ChromeTestSuite(int argc, char** argv)
71     : content::ContentTestSuiteBase(argc, argv) {
72 }
73
74 ChromeTestSuite::~ChromeTestSuite() {
75 }
76
77 void ChromeTestSuite::Initialize() {
78 #if defined(OS_MACOSX)
79   base::mac::ScopedNSAutoreleasePool autorelease_pool;
80 #if !defined(OS_IOS)
81   chrome_browser_application_mac::RegisterBrowserCrApp();
82 #endif  // !defined(OS_IOS)
83 #endif
84
85 #if defined(OS_ANDROID)
86   // Register JNI bindings for android.
87   gfx::android::RegisterJni(base::android::AttachCurrentThread());
88   net::android::RegisterJni(base::android::AttachCurrentThread());
89   ui::android::RegisterJni(base::android::AttachCurrentThread());
90   ui::gl::android::RegisterJni(base::android::AttachCurrentThread());
91   chrome::android::RegisterJni(base::android::AttachCurrentThread());
92 #endif
93
94   if (!browser_dir_.empty()) {
95     PathService::Override(base::DIR_EXE, browser_dir_);
96     PathService::Override(base::DIR_MODULE, browser_dir_);
97   }
98
99 #if !defined(OS_IOS)
100   // Disable external libraries load if we are under python process in
101   // ChromeOS.  That means we are autotest and, if ASAN is used,
102   // external libraries load crashes.
103   if (!IsCrosPythonProcess())
104     media::InitializeMediaLibraryForTesting();
105 #endif
106
107   // Initialize after overriding paths as some content paths depend on correct
108   // values for DIR_EXE and DIR_MODULE.
109   content::ContentTestSuiteBase::Initialize();
110
111   ContentSettingsPattern::SetNonWildcardDomainNonPortScheme(
112       extensions::kExtensionScheme);
113
114 #if defined(OS_MACOSX) && !defined(OS_IOS)
115   // Look in the framework bundle for resources.
116   base::FilePath path;
117   PathService::Get(base::DIR_EXE, &path);
118   path = path.Append(chrome::kFrameworkName);
119   base::mac::SetOverrideFrameworkBundlePath(path);
120 #endif
121 }
122
123 void ChromeTestSuite::Shutdown() {
124 #if defined(OS_MACOSX) && !defined(OS_IOS)
125   base::mac::SetOverrideFrameworkBundle(NULL);
126 #endif
127
128   content::ContentTestSuiteBase::Shutdown();
129 }