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/ash_test_helper.h" | |
23 #include "ash/test/test_session_state_delegate.h" | 24 #include "ash/test/test_session_state_delegate.h" |
24 #include "ash/test/test_shell_delegate.h" | 25 #include "ash/test/test_shell_delegate.h" |
25 #endif | 26 #endif |
26 | 27 |
27 #if defined(USE_AURA) | 28 #if defined(USE_AURA) |
28 #include "ui/aura/client/event_client.h" | 29 #include "ui/aura/client/event_client.h" |
29 #include "ui/aura/env.h" | 30 #include "ui/aura/env.h" |
30 #include "ui/aura/root_window.h" | 31 #include "ui/aura/root_window.h" |
31 #include "ui/aura/test/aura_test_helper.h" | 32 #include "ui/aura/test/aura_test_helper.h" |
32 #endif | 33 #endif |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 | 95 |
95 void ViewEventTestBase::SetUp() { | 96 void ViewEventTestBase::SetUp() { |
96 ui::InitializeInputMethodForTesting(); | 97 ui::InitializeInputMethodForTesting(); |
97 gfx::NativeView context = NULL; | 98 gfx::NativeView context = NULL; |
98 #if defined(USE_ASH) | 99 #if defined(USE_ASH) |
99 #if defined(OS_WIN) | 100 #if defined(OS_WIN) |
100 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when | 101 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when |
101 // interactive_ui_tests is brought up on that platform. | 102 // interactive_ui_tests is brought up on that platform. |
102 gfx::Screen::SetScreenInstance( | 103 gfx::Screen::SetScreenInstance( |
103 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); | 104 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); |
104 #else | |
105 // Ash Shell can't just live on its own without a browser process, we need to | |
106 // also create the message center. | |
107 message_center::MessageCenter::Initialize(); | |
108 #if defined(OS_CHROMEOS) | |
109 chromeos::CrasAudioHandler::InitializeForTesting(); | |
110 #endif | 105 #endif |
111 ash::test::TestShellDelegate* shell_delegate = | 106 ash_test_helper_.reset( |
danakj
2013/07/31 20:14:50
Instead of doing all this ash setup here, use the
| |
112 new ash::test::TestShellDelegate(); | 107 new ash::test::AshTestHelper(base::MessageLoopForUI::current())); |
113 ash::Shell::CreateInstance(shell_delegate); | 108 ash_test_helper_->SetUp(); |
114 shell_delegate->test_session_state_delegate() | 109 context = ash_test_helper_->CurrentContext(); |
115 ->SetActiveUserSessionStarted(true); | |
116 context = ash::Shell::GetPrimaryRootWindow(); | |
117 #endif | |
118 #elif defined(USE_AURA) | 110 #elif defined(USE_AURA) |
119 // Instead of using the ash shell, use an AuraTestHelper to create and manage | 111 // Instead of using the AshTestHelper, use an AuraTestHelper to create and |
120 // the test screen. | 112 // manage the test screen. |
121 aura_test_helper_.reset( | 113 aura_test_helper_.reset( |
122 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); | 114 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
123 aura_test_helper_->SetUp(); | 115 aura_test_helper_->SetUp(); |
124 context = aura_test_helper_->root_window(); | 116 context = aura_test_helper_->root_window(); |
125 #endif | 117 #endif |
126 window_ = views::Widget::CreateWindowWithContext(this, context); | 118 window_ = views::Widget::CreateWindowWithContext(this, context); |
127 } | 119 } |
128 | 120 |
129 void ViewEventTestBase::TearDown() { | 121 void ViewEventTestBase::TearDown() { |
130 if (window_) { | 122 if (window_) { |
131 #if defined(OS_WIN) && !defined(USE_AURA) | 123 #if defined(OS_WIN) && !defined(USE_AURA) |
132 DestroyWindow(window_->GetNativeWindow()); | 124 DestroyWindow(window_->GetNativeWindow()); |
133 #else | 125 #else |
134 window_->Close(); | 126 window_->Close(); |
135 content::RunAllPendingInMessageLoop(); | 127 content::RunAllPendingInMessageLoop(); |
136 #endif | 128 #endif |
137 window_ = NULL; | 129 window_ = NULL; |
138 } | 130 } |
131 | |
139 #if defined(USE_ASH) | 132 #if defined(USE_ASH) |
140 #if defined(OS_WIN) | 133 ash_test_helper_->TearDown(); |
141 #else | |
142 ash::Shell::DeleteInstance(); | |
143 #if defined(OS_CHROMEOS) | |
144 chromeos::CrasAudioHandler::Shutdown(); | |
145 #endif | |
146 // Ash Shell can't just live on its own without a browser process, we need to | |
147 // also shut down the message center. | |
148 message_center::MessageCenter::Shutdown(); | |
149 aura::Env::DeleteInstance(); | |
150 #endif | |
151 #elif defined(USE_AURA) | 134 #elif defined(USE_AURA) |
152 aura_test_helper_->TearDown(); | 135 aura_test_helper_->TearDown(); |
153 #endif | 136 #endif |
137 | |
154 ui::ShutdownInputMethodForTesting(); | 138 ui::ShutdownInputMethodForTesting(); |
155 } | 139 } |
156 | 140 |
157 bool ViewEventTestBase::CanResize() const { | 141 bool ViewEventTestBase::CanResize() const { |
158 return true; | 142 return true; |
159 } | 143 } |
160 | 144 |
161 views::View* ViewEventTestBase::GetContentsView() { | 145 views::View* ViewEventTestBase::GetContentsView() { |
162 if (!content_view_) { | 146 if (!content_view_) { |
163 // Wrap the real view (as returned by CreateContentsView) in a View so | 147 // Wrap the real view (as returned by CreateContentsView) in a View so |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 dnd_thread_.reset(NULL); | 199 dnd_thread_.reset(NULL); |
216 } | 200 } |
217 | 201 |
218 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 202 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
219 StopBackgroundThread(); | 203 StopBackgroundThread(); |
220 | 204 |
221 task.Run(); | 205 task.Run(); |
222 if (HasFatalFailure()) | 206 if (HasFatalFailure()) |
223 Done(); | 207 Done(); |
224 } | 208 } |
OLD | NEW |