OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/base/view_event_test_base.h" | 5 #include "chrome/test/base/view_event_test_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "ash/shell.h" | 24 #include "ash/shell.h" |
25 #include "ash/test/test_session_state_delegate.h" | 25 #include "ash/test/test_session_state_delegate.h" |
26 #include "ash/test/test_shell_delegate.h" | 26 #include "ash/test/test_shell_delegate.h" |
27 #endif | 27 #endif |
28 | 28 |
29 #if defined(USE_AURA) | 29 #if defined(USE_AURA) |
30 #include "ui/aura/client/event_client.h" | 30 #include "ui/aura/client/event_client.h" |
31 #include "ui/aura/env.h" | 31 #include "ui/aura/env.h" |
32 #include "ui/aura/root_window.h" | 32 #include "ui/aura/root_window.h" |
33 #include "ui/aura/test/aura_test_helper.h" | 33 #include "ui/aura/test/aura_test_helper.h" |
| 34 #include "ui/compositor/test/context_factories_for_test.h" |
34 #include "ui/views/corewm/wm_state.h" | 35 #include "ui/views/corewm/wm_state.h" |
35 #endif | 36 #endif |
36 | 37 |
37 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
38 #include "chromeos/audio/cras_audio_handler.h" | 39 #include "chromeos/audio/cras_audio_handler.h" |
39 #include "chromeos/dbus/dbus_thread_manager.h" | 40 #include "chromeos/dbus/dbus_thread_manager.h" |
40 #include "chromeos/network/network_handler.h" | 41 #include "chromeos/network/network_handler.h" |
41 #endif | 42 #endif |
42 | 43 |
43 namespace { | 44 namespace { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 96 |
96 void ViewEventTestBase::SetUp() { | 97 void ViewEventTestBase::SetUp() { |
97 #if defined(USE_AURA) | 98 #if defined(USE_AURA) |
98 wm_state_.reset(new views::corewm::WMState); | 99 wm_state_.reset(new views::corewm::WMState); |
99 #endif | 100 #endif |
100 | 101 |
101 views::ViewsDelegate::views_delegate = &views_delegate_; | 102 views::ViewsDelegate::views_delegate = &views_delegate_; |
102 ui::InitializeInputMethodForTesting(); | 103 ui::InitializeInputMethodForTesting(); |
103 gfx::NativeView context = NULL; | 104 gfx::NativeView context = NULL; |
104 | 105 |
| 106 #if defined(USE_AURA) |
| 107 // The ContextFactory must exist before any Compositors are created. |
| 108 bool enable_pixel_output = false; |
| 109 ui::InitializeContextFactoryForTests(enable_pixel_output); |
| 110 #endif |
| 111 |
105 #if defined(USE_ASH) | 112 #if defined(USE_ASH) |
106 // The ContextFactory must exist before any Compositors are created. | |
107 bool allow_test_contexts = true; | |
108 ui::InitializeContextFactoryForTests(allow_test_contexts); | |
109 #if defined(OS_WIN) | 113 #if defined(OS_WIN) |
110 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when | 114 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when |
111 // interactive_ui_tests is brought up on that platform. | 115 // interactive_ui_tests is brought up on that platform. |
112 gfx::Screen::SetScreenInstance( | 116 gfx::Screen::SetScreenInstance( |
113 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); | 117 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); |
114 | 118 |
115 #else // !OS_WIN | 119 #else // !OS_WIN |
116 // Ash Shell can't just live on its own without a browser process, we need to | 120 // Ash Shell can't just live on its own without a browser process, we need to |
117 // also create the message center. | 121 // also create the message center. |
118 message_center::MessageCenter::Initialize(); | 122 message_center::MessageCenter::Initialize(); |
119 #if defined(OS_CHROMEOS) | 123 #if defined(OS_CHROMEOS) |
120 chromeos::DBusThreadManager::InitializeWithStub(); | 124 chromeos::DBusThreadManager::InitializeWithStub(); |
121 chromeos::CrasAudioHandler::InitializeForTesting(); | 125 chromeos::CrasAudioHandler::InitializeForTesting(); |
122 chromeos::NetworkHandler::Initialize(); | 126 chromeos::NetworkHandler::Initialize(); |
123 #endif // OS_CHROMEOS | 127 #endif // OS_CHROMEOS |
124 ash::test::TestShellDelegate* shell_delegate = | 128 ash::test::TestShellDelegate* shell_delegate = |
125 new ash::test::TestShellDelegate(); | 129 new ash::test::TestShellDelegate(); |
126 ash::Shell::CreateInstance(shell_delegate); | 130 ash::Shell::CreateInstance(shell_delegate); |
127 shell_delegate->test_session_state_delegate() | 131 shell_delegate->test_session_state_delegate() |
128 ->SetActiveUserSessionStarted(true); | 132 ->SetActiveUserSessionStarted(true); |
129 context = ash::Shell::GetPrimaryRootWindow(); | 133 context = ash::Shell::GetPrimaryRootWindow(); |
130 #endif // !OS_WIN | 134 #endif // !OS_WIN |
131 aura::Env::CreateInstance(); | 135 aura::Env::CreateInstance(); |
132 #elif defined(USE_AURA) | 136 #elif defined(USE_AURA) |
133 // Instead of using the ash shell, use an AuraTestHelper to create and manage | 137 // Instead of using the ash shell, use an AuraTestHelper to create and manage |
134 // the test screen. | 138 // the test screen. |
135 aura_test_helper_.reset( | 139 aura_test_helper_.reset( |
136 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); | 140 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
137 bool allow_test_contexts = true; | 141 aura_test_helper_->SetUp(); |
138 aura_test_helper_->SetUp(allow_test_contexts); | |
139 context = aura_test_helper_->root_window(); | 142 context = aura_test_helper_->root_window(); |
140 #endif // !USE_ASH && USE_AURA | 143 #endif // !USE_ASH && USE_AURA |
141 | 144 |
142 window_ = views::Widget::CreateWindowWithContext(this, context); | 145 window_ = views::Widget::CreateWindowWithContext(this, context); |
143 } | 146 } |
144 | 147 |
145 void ViewEventTestBase::TearDown() { | 148 void ViewEventTestBase::TearDown() { |
146 if (window_) { | 149 if (window_) { |
147 window_->Close(); | 150 window_->Close(); |
148 content::RunAllPendingInMessageLoop(); | 151 content::RunAllPendingInMessageLoop(); |
149 window_ = NULL; | 152 window_ = NULL; |
150 } | 153 } |
151 | 154 |
152 #if defined(USE_ASH) | 155 #if defined(USE_ASH) |
153 #if !defined(OS_WIN) | 156 #if !defined(OS_WIN) |
154 ash::Shell::DeleteInstance(); | 157 ash::Shell::DeleteInstance(); |
155 #if defined(OS_CHROMEOS) | 158 #if defined(OS_CHROMEOS) |
156 chromeos::NetworkHandler::Shutdown(); | 159 chromeos::NetworkHandler::Shutdown(); |
157 chromeos::CrasAudioHandler::Shutdown(); | 160 chromeos::CrasAudioHandler::Shutdown(); |
158 chromeos::DBusThreadManager::Shutdown(); | 161 chromeos::DBusThreadManager::Shutdown(); |
159 #endif | 162 #endif |
160 // Ash Shell can't just live on its own without a browser process, we need to | 163 // Ash Shell can't just live on its own without a browser process, we need to |
161 // also shut down the message center. | 164 // also shut down the message center. |
162 message_center::MessageCenter::Shutdown(); | 165 message_center::MessageCenter::Shutdown(); |
163 #endif // !OS_WIN | 166 #endif // !OS_WIN |
164 aura::Env::DeleteInstance(); | 167 aura::Env::DeleteInstance(); |
165 ui::TerminateContextFactoryForTests(); | |
166 #elif defined(USE_AURA) | 168 #elif defined(USE_AURA) |
167 aura_test_helper_->TearDown(); | 169 aura_test_helper_->TearDown(); |
168 #endif // !USE_ASH && USE_AURA | 170 #endif // !USE_ASH && USE_AURA |
169 | 171 |
| 172 #if defined(USE_AURA) |
| 173 ui::TerminateContextFactoryForTests(); |
| 174 #endif |
| 175 |
170 ui::ShutdownInputMethodForTesting(); | 176 ui::ShutdownInputMethodForTesting(); |
171 views::ViewsDelegate::views_delegate = NULL; | 177 views::ViewsDelegate::views_delegate = NULL; |
172 | 178 |
173 #if defined(USE_AURA) | 179 #if defined(USE_AURA) |
174 wm_state_.reset(); | 180 wm_state_.reset(); |
175 #endif | 181 #endif |
176 } | 182 } |
177 | 183 |
178 bool ViewEventTestBase::CanResize() const { | 184 bool ViewEventTestBase::CanResize() const { |
179 return true; | 185 return true; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 dnd_thread_.reset(NULL); | 243 dnd_thread_.reset(NULL); |
238 } | 244 } |
239 | 245 |
240 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 246 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
241 StopBackgroundThread(); | 247 StopBackgroundThread(); |
242 | 248 |
243 task.Run(); | 249 task.Run(); |
244 if (HasFatalFailure()) | 250 if (HasFatalFailure()) |
245 Done(); | 251 Done(); |
246 } | 252 } |
OLD | NEW |