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" |
11 #include "chrome/test/base/interactive_test_utils.h" | 11 #include "chrome/test/base/interactive_test_utils.h" |
12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "ui/base/ime/input_method_initializer.h" | 14 #include "ui/base/ime/input_method_initializer.h" |
15 #include "ui/base/test/ui_controls.h" | 15 #include "ui/base/test/ui_controls.h" |
16 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
17 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
18 #include "ui/views/widget/desktop_aura/desktop_screen.h" | 18 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
20 | 20 |
21 #if defined(USE_ASH) | 21 #if defined(USE_ASH) |
22 #include "ash/shell.h" | 22 #include "ash/shell.h" |
23 #include "ash/test/test_session_state_delegate.h" | 23 #include "ash/test/test_session_state_delegate.h" |
24 #include "ash/test/test_shell_delegate.h" | 24 #include "ash/test/test_shell_delegate.h" |
25 #if defined(OS_WIN) | |
26 #include "ui/compositor/compositor.h" | |
27 #endif | |
28 #endif | 25 #endif |
29 | 26 |
30 #if defined(USE_AURA) | 27 #if defined(USE_AURA) |
31 #include "ui/aura/client/event_client.h" | 28 #include "ui/aura/client/event_client.h" |
32 #include "ui/aura/env.h" | 29 #include "ui/aura/env.h" |
33 #include "ui/aura/root_window.h" | 30 #include "ui/aura/root_window.h" |
34 #include "ui/aura/test/aura_test_helper.h" | 31 #include "ui/aura/test/aura_test_helper.h" |
35 #endif | 32 #endif |
36 | 33 |
37 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 94 |
98 void ViewEventTestBase::SetUp() { | 95 void ViewEventTestBase::SetUp() { |
99 ui::InitializeInputMethodForTesting(); | 96 ui::InitializeInputMethodForTesting(); |
100 gfx::NativeView context = NULL; | 97 gfx::NativeView context = NULL; |
101 #if defined(USE_ASH) | 98 #if defined(USE_ASH) |
102 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
103 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when | 100 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when |
104 // interactive_ui_tests is brought up on that platform. | 101 // interactive_ui_tests is brought up on that platform. |
105 gfx::Screen::SetScreenInstance( | 102 gfx::Screen::SetScreenInstance( |
106 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); | 103 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); |
107 | 104 #else |
108 // The ContextFactory must exist before any Compositors are created. The | |
109 // ash::Shell code path below handles this, but since we skip it we must | |
110 // do this here. | |
111 bool allow_test_contexts = true; | |
112 ui::Compositor::InitializeContextFactoryForTests(allow_test_contexts); | |
113 #else // !OS_WIN | |
114 // Ash Shell can't just live on its own without a browser process, we need to | 105 // Ash Shell can't just live on its own without a browser process, we need to |
115 // also create the message center. | 106 // also create the message center. |
116 message_center::MessageCenter::Initialize(); | 107 message_center::MessageCenter::Initialize(); |
117 #if defined(OS_CHROMEOS) | 108 #if defined(OS_CHROMEOS) |
118 chromeos::CrasAudioHandler::InitializeForTesting(); | 109 chromeos::CrasAudioHandler::InitializeForTesting(); |
119 #endif // OS_CHROMEOS | 110 #endif |
120 ash::test::TestShellDelegate* shell_delegate = | 111 ash::test::TestShellDelegate* shell_delegate = |
121 new ash::test::TestShellDelegate(); | 112 new ash::test::TestShellDelegate(); |
122 ash::Shell::CreateInstance(shell_delegate); | 113 ash::Shell::CreateInstance(shell_delegate); |
123 shell_delegate->test_session_state_delegate() | 114 shell_delegate->test_session_state_delegate() |
124 ->SetActiveUserSessionStarted(true); | 115 ->SetActiveUserSessionStarted(true); |
125 context = ash::Shell::GetPrimaryRootWindow(); | 116 context = ash::Shell::GetPrimaryRootWindow(); |
126 #endif // !OS_WIN | 117 #endif |
127 #elif defined(USE_AURA) | 118 #elif defined(USE_AURA) |
128 // Instead of using the ash shell, use an AuraTestHelper to create and manage | 119 // Instead of using the ash shell, use an AuraTestHelper to create and manage |
129 // the test screen. | 120 // the test screen. |
130 aura_test_helper_.reset( | 121 aura_test_helper_.reset( |
131 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); | 122 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
132 aura_test_helper_->SetUp(); | 123 aura_test_helper_->SetUp(); |
133 context = aura_test_helper_->root_window(); | 124 context = aura_test_helper_->root_window(); |
134 #endif // USE_AURA | 125 #endif |
135 window_ = views::Widget::CreateWindowWithContext(this, context); | 126 window_ = views::Widget::CreateWindowWithContext(this, context); |
136 } | 127 } |
137 | 128 |
138 void ViewEventTestBase::TearDown() { | 129 void ViewEventTestBase::TearDown() { |
139 if (window_) { | 130 if (window_) { |
140 #if defined(OS_WIN) && !defined(USE_AURA) | 131 #if defined(OS_WIN) && !defined(USE_AURA) |
141 DestroyWindow(window_->GetNativeWindow()); | 132 DestroyWindow(window_->GetNativeWindow()); |
142 #else | 133 #else |
143 window_->Close(); | 134 window_->Close(); |
144 content::RunAllPendingInMessageLoop(); | 135 content::RunAllPendingInMessageLoop(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 dnd_thread_.reset(NULL); | 215 dnd_thread_.reset(NULL); |
225 } | 216 } |
226 | 217 |
227 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 218 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
228 StopBackgroundThread(); | 219 StopBackgroundThread(); |
229 | 220 |
230 task.Run(); | 221 task.Run(); |
231 if (HasFatalFailure()) | 222 if (HasFatalFailure()) |
232 Done(); | 223 Done(); |
233 } | 224 } |
OLD | NEW |