Android Credit Card unmasking UI - replace text with progress bar
[chromium-blink-merge.git] / content / test / content_test_suite.cc
blob18a116f3e0a42765c0c6a45baf09074e30cea38e
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 "content/test/content_test_suite.h"
7 #if defined(OS_ANDROID)
8 #include <android/native_window.h>
9 #include <android/native_window_jni.h>
10 #include <map>
11 #endif
13 #include "base/base_paths.h"
14 #include "base/logging.h"
15 #include "content/public/common/content_client.h"
16 #include "content/public/common/content_paths.h"
17 #include "content/public/test/test_content_client_initializer.h"
18 #include "gpu/config/gpu_util.h"
19 #include "testing/gtest/include/gtest/gtest.h"
21 #if defined(OS_WIN)
22 #include "ui/gfx/win/dpi.h"
23 #endif
25 #if defined(OS_MACOSX)
26 #include "base/mac/scoped_nsautorelease_pool.h"
27 #if !defined(OS_IOS)
28 #include "base/test/mock_chrome_application_mac.h"
29 #endif
30 #endif
32 #if !defined(OS_IOS)
33 #include "base/base_switches.h"
34 #include "base/command_line.h"
35 #include "media/base/media.h"
36 #include "ui/gl/gl_surface.h"
37 #endif
39 #if defined(OS_ANDROID)
40 #include "base/android/jni_android.h"
41 #include "base/memory/linked_ptr.h"
42 #include "content/common/android/surface_texture_manager.h"
43 #include "ui/gl/android/scoped_java_surface.h"
44 #include "ui/gl/android/surface_texture.h"
45 #endif
47 namespace content {
48 namespace {
50 class TestInitializationListener : public testing::EmptyTestEventListener {
51 public:
52 TestInitializationListener() : test_content_client_initializer_(NULL) {
55 virtual void OnTestStart(const testing::TestInfo& test_info) override {
56 test_content_client_initializer_ =
57 new content::TestContentClientInitializer();
60 virtual void OnTestEnd(const testing::TestInfo& test_info) override {
61 delete test_content_client_initializer_;
64 private:
65 content::TestContentClientInitializer* test_content_client_initializer_;
67 DISALLOW_COPY_AND_ASSIGN(TestInitializationListener);
70 #if defined(OS_ANDROID)
71 class SurfaceTextureManagerImpl : public SurfaceTextureManager {
72 public:
73 // Overridden from SurfaceTextureManager:
74 void RegisterSurfaceTexture(int surface_texture_id,
75 int client_id,
76 gfx::SurfaceTexture* surface_texture) override {
77 surfaces_[surface_texture_id] =
78 make_linked_ptr(new gfx::ScopedJavaSurface(surface_texture));
80 void UnregisterSurfaceTexture(int surface_texture_id,
81 int client_id) override {
82 surfaces_.erase(surface_texture_id);
84 gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture(
85 int surface_texture_id) override {
86 JNIEnv* env = base::android::AttachCurrentThread();
87 return ANativeWindow_fromSurface(
88 env, surfaces_[surface_texture_id]->j_surface().obj());
91 private:
92 typedef std::map<int, linked_ptr<gfx::ScopedJavaSurface>> SurfaceMap;
93 SurfaceMap surfaces_;
95 #endif
97 } // namespace
99 ContentTestSuite::ContentTestSuite(int argc, char** argv)
100 : ContentTestSuiteBase(argc, argv) {
103 ContentTestSuite::~ContentTestSuite() {
106 void ContentTestSuite::Initialize() {
107 #if defined(OS_MACOSX)
108 base::mac::ScopedNSAutoreleasePool autorelease_pool;
109 #if !defined(OS_IOS)
110 mock_cr_app::RegisterMockCrApp();
111 #endif
112 #endif
114 #if defined(OS_WIN)
115 gfx::InitDeviceScaleFactor(1.0f);
116 #endif
118 ContentTestSuiteBase::Initialize();
120 ContentClient client;
121 ContentTestSuiteBase::RegisterContentSchemes(&client);
123 RegisterPathProvider();
124 #if !defined(OS_IOS)
125 media::InitializeMediaLibraryForTesting();
126 // When running in a child process for Mac sandbox tests, the sandbox exists
127 // to initialize GL, so don't do it here.
128 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
129 switches::kTestChildProcess)) {
130 gfx::GLSurface::InitializeOneOffForTests();
131 gpu::ApplyGpuDriverBugWorkarounds(base::CommandLine::ForCurrentProcess());
133 #endif
134 testing::TestEventListeners& listeners =
135 testing::UnitTest::GetInstance()->listeners();
136 listeners.Append(new TestInitializationListener);
137 #if defined(OS_ANDROID)
138 SurfaceTextureManager::InitInstance(new SurfaceTextureManagerImpl);
139 #endif
142 } // namespace content