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