Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / chrome / test / base / chrome_test_suite.cc
blob30708f108db0e4e9c08defc495ab63807d2010c5
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 #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
34 #if defined(OS_CHROMEOS)
35 #include "base/process/process_metrics.h"
36 #include "chromeos/chromeos_paths.h"
37 #endif
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 "chrome/browser/chrome_browser_application_mac.h"
44 #endif // !defined(OS_IOS)
45 #endif
47 #if !defined(OS_IOS)
48 #include "media/base/media.h"
49 #endif
51 namespace {
53 bool IsCrosPythonProcess() {
54 #if defined(OS_CHROMEOS)
55 char buf[80];
56 int num_read = readlink(base::kProcSelfExe, buf, sizeof(buf) - 1);
57 if (num_read == -1)
58 return false;
59 buf[num_read] = 0;
60 const char kPythonPrefix[] = "/python";
61 return !strncmp(strrchr(buf, '/'), kPythonPrefix, sizeof(kPythonPrefix) - 1);
62 #else
63 return false;
64 #endif // defined(OS_CHROMEOS)
67 } // namespace
69 ChromeTestSuite::ChromeTestSuite(int argc, char** argv)
70 : content::ContentTestSuiteBase(argc, argv) {
73 ChromeTestSuite::~ChromeTestSuite() {
76 void ChromeTestSuite::Initialize() {
77 #if defined(OS_MACOSX)
78 base::mac::ScopedNSAutoreleasePool autorelease_pool;
79 #if !defined(OS_IOS)
80 chrome_browser_application_mac::RegisterBrowserCrApp();
81 #endif // !defined(OS_IOS)
82 #endif
84 #if defined(OS_ANDROID)
85 // Register JNI bindings for android.
86 gfx::android::RegisterJni(base::android::AttachCurrentThread());
87 net::android::RegisterJni(base::android::AttachCurrentThread());
88 ui::android::RegisterJni(base::android::AttachCurrentThread());
89 ui::gl::android::RegisterJni(base::android::AttachCurrentThread());
90 chrome::android::RegisterJni(base::android::AttachCurrentThread());
91 #endif
93 if (!browser_dir_.empty()) {
94 PathService::Override(base::DIR_EXE, browser_dir_);
95 PathService::Override(base::DIR_MODULE, browser_dir_);
98 #if !defined(OS_IOS)
99 // Disable external libraries load if we are under python process in
100 // ChromeOS. That means we are autotest and, if ASAN is used,
101 // external libraries load crashes.
102 if (!IsCrosPythonProcess())
103 media::InitializeMediaLibraryForTesting();
104 #endif
106 // Initialize after overriding paths as some content paths depend on correct
107 // values for DIR_EXE and DIR_MODULE.
108 content::ContentTestSuiteBase::Initialize();
110 ContentSettingsPattern::SetNonWildcardDomainNonPortScheme(
111 extensions::kExtensionScheme);
113 #if defined(OS_MACOSX) && !defined(OS_IOS)
114 // Look in the framework bundle for resources.
115 base::FilePath path;
116 PathService::Get(base::DIR_EXE, &path);
117 path = path.Append(chrome::kFrameworkName);
118 base::mac::SetOverrideFrameworkBundlePath(path);
119 #endif
122 void ChromeTestSuite::Shutdown() {
123 #if defined(OS_MACOSX) && !defined(OS_IOS)
124 base::mac::SetOverrideFrameworkBundle(NULL);
125 #endif
127 content::ContentTestSuiteBase::Shutdown();