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" | |
9 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_number_conversions.h" | |
11 #include "chrome/test/base/chrome_unit_test_suite.h" | 9 #include "chrome/test/base/chrome_unit_test_suite.h" |
12 #include "chrome/test/base/interactive_test_utils.h" | 10 #include "chrome/test/base/interactive_test_utils.h" |
13 #include "chrome/test/base/testing_browser_process.h" | 11 #include "chrome/test/base/testing_browser_process.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/view_event_test_platform_part.h" |
15 #include "ui/aura/client/event_client.h" | |
16 #include "ui/aura/env.h" | |
17 #include "ui/aura/test/aura_test_helper.h" | |
18 #include "ui/aura/window_event_dispatcher.h" | |
19 #include "ui/aura/window_tree_host.h" | |
20 #include "ui/base/ime/input_method_initializer.h" | 13 #include "ui/base/ime/input_method_initializer.h" |
21 #include "ui/base/test/ui_controls.h" | 14 #include "ui/base/test/ui_controls.h" |
22 #include "ui/compositor/test/context_factories_for_test.h" | 15 #include "ui/compositor/test/context_factories_for_test.h" |
23 #include "ui/compositor/test/context_factories_for_test.h" | |
24 #include "ui/message_center/message_center.h" | |
25 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
26 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
27 #include "ui/wm/core/default_activation_client.h" | |
28 #include "ui/wm/core/wm_state.h" | |
29 | |
30 #if defined(USE_ASH) | |
31 #include "ash/shell.h" | |
32 #include "ash/shell_init_params.h" | |
33 #include "ash/test/test_session_state_delegate.h" | |
34 #include "ash/test/test_shell_delegate.h" | |
35 #endif | |
36 | |
37 #if defined(OS_CHROMEOS) | |
38 #include "chromeos/audio/cras_audio_handler.h" | |
39 #include "chromeos/dbus/dbus_thread_manager.h" | |
40 #include "chromeos/network/network_handler.h" | |
41 #else // !defined(OS_CHROMEOS) | |
42 #include "ui/views/widget/desktop_aura/desktop_screen.h" | |
43 #endif | |
44 | 18 |
45 namespace { | 19 namespace { |
46 | 20 |
47 // View subclass that allows you to specify the preferred size. | 21 // View subclass that allows you to specify the preferred size. |
48 class TestView : public views::View { | 22 class TestView : public views::View { |
49 public: | 23 public: |
50 TestView() {} | 24 TestView() {} |
51 | 25 |
52 void SetPreferredSize(const gfx::Size& size) { | 26 void SetPreferredSize(const gfx::Size& size) { |
53 preferred_size_ = size; | 27 preferred_size_ = size; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 ui_controls::RunClosureAfterAllPendingUIEvents( | 68 ui_controls::RunClosureAfterAllPendingUIEvents( |
95 base::MessageLoop::QuitClosure()); | 69 base::MessageLoop::QuitClosure()); |
96 } | 70 } |
97 | 71 |
98 void ViewEventTestBase::SetUpTestCase() { | 72 void ViewEventTestBase::SetUpTestCase() { |
99 ChromeUnitTestSuite::InitializeProviders(); | 73 ChromeUnitTestSuite::InitializeProviders(); |
100 ChromeUnitTestSuite::InitializeResourceBundle(); | 74 ChromeUnitTestSuite::InitializeResourceBundle(); |
101 } | 75 } |
102 | 76 |
103 void ViewEventTestBase::SetUp() { | 77 void ViewEventTestBase::SetUp() { |
104 wm_state_.reset(new wm::WMState); | |
105 | |
106 views::ViewsDelegate::views_delegate = &views_delegate_; | 78 views::ViewsDelegate::views_delegate = &views_delegate_; |
107 ui::InitializeInputMethodForTesting(); | 79 ui::InitializeInputMethodForTesting(); |
108 gfx::NativeView context = NULL; | |
109 | 80 |
110 // The ContextFactory must exist before any Compositors are created. | 81 // The ContextFactory must exist before any Compositors are created. |
111 bool enable_pixel_output = false; | 82 bool enable_pixel_output = false; |
112 ui::ContextFactory* context_factory = | 83 ui::ContextFactory* context_factory = |
113 ui::InitializeContextFactoryForTests(enable_pixel_output); | 84 ui::InitializeContextFactoryForTests(enable_pixel_output); |
114 | 85 |
115 #if defined(OS_CHROMEOS) | 86 platform_part_.reset(ViewEventTestPlatformPart::Create(context_factory)); |
116 // Ash Shell can't just live on its own without a browser process, we need to | 87 gfx::NativeWindow context = platform_part_->GetContext(); |
117 // also create the message center. | |
118 message_center::MessageCenter::Initialize(); | |
119 chromeos::DBusThreadManager::InitializeWithStub(); | |
120 chromeos::CrasAudioHandler::InitializeForTesting(); | |
121 chromeos::NetworkHandler::Initialize(); | |
122 ash::test::TestShellDelegate* shell_delegate = | |
123 new ash::test::TestShellDelegate(); | |
124 ash::ShellInitParams init_params; | |
125 init_params.delegate = shell_delegate; | |
126 init_params.context_factory = context_factory; | |
127 ash::Shell::CreateInstance(init_params); | |
128 shell_delegate->test_session_state_delegate() | |
129 ->SetActiveUserSessionStarted(true); | |
130 context = ash::Shell::GetPrimaryRootWindow(); | |
131 context->GetHost()->Show(); | |
132 #elif defined(USE_ASH) | |
133 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when | |
134 // interactive_ui_tests is brought up on that platform. | |
135 gfx::Screen::SetScreenInstance( | |
136 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); | |
137 aura::Env::CreateInstance(true); | |
138 aura::Env::GetInstance()->set_context_factory(context_factory); | |
139 #elif defined(USE_AURA) | |
140 // Instead of using the ash shell, use an AuraTestHelper to create and manage | |
141 // the test screen. | |
142 aura_test_helper_.reset( | |
143 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); | |
144 aura_test_helper_->SetUp(context_factory); | |
145 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | |
146 context = aura_test_helper_->root_window(); | |
147 #endif | |
148 | |
149 window_ = views::Widget::CreateWindowWithContext(this, context); | 88 window_ = views::Widget::CreateWindowWithContext(this, context); |
150 } | 89 } |
151 | 90 |
152 void ViewEventTestBase::TearDown() { | 91 void ViewEventTestBase::TearDown() { |
153 if (window_) { | 92 if (window_) { |
154 window_->Close(); | 93 window_->Close(); |
155 content::RunAllPendingInMessageLoop(); | 94 content::RunAllPendingInMessageLoop(); |
156 window_ = NULL; | 95 window_ = NULL; |
157 } | 96 } |
158 | 97 |
159 ui::Clipboard::DestroyClipboardForCurrentThread(); | 98 ui::Clipboard::DestroyClipboardForCurrentThread(); |
160 | 99 platform_part_.reset(); |
161 #if defined(USE_ASH) | |
162 #if defined(OS_CHROMEOS) | |
163 ash::Shell::DeleteInstance(); | |
164 chromeos::NetworkHandler::Shutdown(); | |
165 chromeos::CrasAudioHandler::Shutdown(); | |
166 chromeos::DBusThreadManager::Shutdown(); | |
167 // Ash Shell can't just live on its own without a browser process, we need to | |
168 // also shut down the message center. | |
169 message_center::MessageCenter::Shutdown(); | |
170 #endif | |
171 aura::Env::DeleteInstance(); | |
172 #elif defined(USE_AURA) | |
173 aura_test_helper_->TearDown(); | |
174 #endif // !USE_ASH && USE_AURA | |
175 | 100 |
176 ui::TerminateContextFactoryForTests(); | 101 ui::TerminateContextFactoryForTests(); |
177 | 102 |
178 ui::ShutdownInputMethodForTesting(); | 103 ui::ShutdownInputMethodForTesting(); |
179 views::ViewsDelegate::views_delegate = NULL; | 104 views::ViewsDelegate::views_delegate = NULL; |
180 | |
181 wm_state_.reset(); | |
182 } | 105 } |
183 | 106 |
184 bool ViewEventTestBase::CanResize() const { | 107 bool ViewEventTestBase::CanResize() const { |
185 return true; | 108 return true; |
186 } | 109 } |
187 | 110 |
188 views::View* ViewEventTestBase::GetContentsView() { | 111 views::View* ViewEventTestBase::GetContentsView() { |
189 if (!content_view_) { | 112 if (!content_view_) { |
190 // Wrap the real view (as returned by CreateContentsView) in a View so | 113 // Wrap the real view (as returned by CreateContentsView) in a View so |
191 // that we can customize the preferred size. | 114 // that we can customize the preferred size. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 dnd_thread_.reset(NULL); | 166 dnd_thread_.reset(NULL); |
244 } | 167 } |
245 | 168 |
246 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 169 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
247 StopBackgroundThread(); | 170 StopBackgroundThread(); |
248 | 171 |
249 task.Run(); | 172 task.Run(); |
250 if (HasFatalFailure()) | 173 if (HasFatalFailure()) |
251 Done(); | 174 Done(); |
252 } | 175 } |
OLD | NEW |