| 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/chrome_unit_test_suite.h" | 11 #include "chrome/test/base/chrome_unit_test_suite.h" |
| 12 #include "chrome/test/base/interactive_test_utils.h" | 12 #include "chrome/test/base/interactive_test_utils.h" |
| 13 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.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" |
| 15 #include "ui/base/ime/input_method_initializer.h" | 20 #include "ui/base/ime/input_method_initializer.h" |
| 16 #include "ui/base/test/ui_controls.h" | 21 #include "ui/base/test/ui_controls.h" |
| 17 #include "ui/compositor/test/context_factories_for_test.h" | 22 #include "ui/compositor/test/context_factories_for_test.h" |
| 23 #include "ui/events/platform/platform_event_source.h" |
| 18 #include "ui/message_center/message_center.h" | 24 #include "ui/message_center/message_center.h" |
| 19 #include "ui/views/view.h" | 25 #include "ui/views/view.h" |
| 20 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 27 #include "ui/wm/core/wm_state.h" |
| 21 | 28 |
| 22 #if defined(USE_ASH) | 29 #if defined(USE_ASH) |
| 23 #include "ash/shell.h" | 30 #include "ash/shell.h" |
| 24 #include "ash/test/test_session_state_delegate.h" | 31 #include "ash/test/test_session_state_delegate.h" |
| 25 #include "ash/test/test_shell_delegate.h" | 32 #include "ash/test/test_shell_delegate.h" |
| 26 #endif | 33 #endif |
| 27 | 34 |
| 28 #if defined(USE_AURA) | |
| 29 #include "ui/aura/client/event_client.h" | |
| 30 #include "ui/aura/env.h" | |
| 31 #include "ui/aura/test/aura_test_helper.h" | |
| 32 #include "ui/aura/window_event_dispatcher.h" | |
| 33 #include "ui/aura/window_tree_host.h" | |
| 34 #include "ui/compositor/test/context_factories_for_test.h" | |
| 35 #include "ui/wm/core/wm_state.h" | |
| 36 #endif | |
| 37 | |
| 38 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 39 #include "chromeos/audio/cras_audio_handler.h" | 36 #include "chromeos/audio/cras_audio_handler.h" |
| 40 #include "chromeos/dbus/dbus_thread_manager.h" | 37 #include "chromeos/dbus/dbus_thread_manager.h" |
| 41 #include "chromeos/network/network_handler.h" | 38 #include "chromeos/network/network_handler.h" |
| 42 #else // !defined(OS_CHROMEOS) | 39 #else // !defined(OS_CHROMEOS) |
| 43 #include "ui/views/widget/desktop_aura/desktop_screen.h" | 40 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
| 44 #endif | 41 #endif |
| 45 | 42 |
| 46 namespace { | 43 namespace { |
| 47 | 44 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 ui_controls::RunClosureAfterAllPendingUIEvents( | 92 ui_controls::RunClosureAfterAllPendingUIEvents( |
| 96 base::MessageLoop::QuitClosure()); | 93 base::MessageLoop::QuitClosure()); |
| 97 } | 94 } |
| 98 | 95 |
| 99 void ViewEventTestBase::SetUpTestCase() { | 96 void ViewEventTestBase::SetUpTestCase() { |
| 100 ChromeUnitTestSuite::InitializeProviders(); | 97 ChromeUnitTestSuite::InitializeProviders(); |
| 101 ChromeUnitTestSuite::InitializeResourceBundle(); | 98 ChromeUnitTestSuite::InitializeResourceBundle(); |
| 102 } | 99 } |
| 103 | 100 |
| 104 void ViewEventTestBase::SetUp() { | 101 void ViewEventTestBase::SetUp() { |
| 105 #if defined(USE_AURA) | 102 event_source_ = ui::PlatformEventSource::CreateDefault(); |
| 103 |
| 106 wm_state_.reset(new wm::WMState); | 104 wm_state_.reset(new wm::WMState); |
| 107 #endif | |
| 108 | 105 |
| 109 views::ViewsDelegate::views_delegate = &views_delegate_; | 106 views::ViewsDelegate::views_delegate = &views_delegate_; |
| 110 ui::InitializeInputMethodForTesting(); | 107 ui::InitializeInputMethodForTesting(); |
| 111 gfx::NativeView context = NULL; | 108 gfx::NativeView context = NULL; |
| 112 | 109 |
| 113 #if defined(USE_AURA) | |
| 114 // The ContextFactory must exist before any Compositors are created. | 110 // The ContextFactory must exist before any Compositors are created. |
| 115 bool enable_pixel_output = false; | 111 bool enable_pixel_output = false; |
| 116 ui::InitializeContextFactoryForTests(enable_pixel_output); | 112 ui::InitializeContextFactoryForTests(enable_pixel_output); |
| 117 #endif | |
| 118 | 113 |
| 119 #if defined(USE_ASH) | 114 #if defined(USE_ASH) |
| 120 #if defined(OS_WIN) | 115 #if defined(OS_WIN) |
| 121 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when | 116 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when |
| 122 // interactive_ui_tests is brought up on that platform. | 117 // interactive_ui_tests is brought up on that platform. |
| 123 gfx::Screen::SetScreenInstance( | 118 gfx::Screen::SetScreenInstance( |
| 124 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); | 119 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); |
| 125 | 120 |
| 126 #else // !OS_WIN | 121 #else // !OS_WIN |
| 127 // Ash Shell can't just live on its own without a browser process, we need to | 122 // Ash Shell can't just live on its own without a browser process, we need to |
| 128 // also create the message center. | 123 // also create the message center. |
| 129 message_center::MessageCenter::Initialize(); | 124 message_center::MessageCenter::Initialize(); |
| 130 #if defined(OS_CHROMEOS) | 125 #if defined(OS_CHROMEOS) |
| 131 chromeos::DBusThreadManager::InitializeWithStub(); | 126 chromeos::DBusThreadManager::InitializeWithStub(); |
| 132 chromeos::CrasAudioHandler::InitializeForTesting(); | 127 chromeos::CrasAudioHandler::InitializeForTesting(); |
| 133 chromeos::NetworkHandler::Initialize(); | 128 chromeos::NetworkHandler::Initialize(); |
| 134 #endif // OS_CHROMEOS | 129 #endif // OS_CHROMEOS |
| 135 ash::test::TestShellDelegate* shell_delegate = | 130 ash::test::TestShellDelegate* shell_delegate = |
| 136 new ash::test::TestShellDelegate(); | 131 new ash::test::TestShellDelegate(); |
| 137 ash::Shell::CreateInstance(shell_delegate); | 132 ash::Shell::CreateInstance(shell_delegate); |
| 138 shell_delegate->test_session_state_delegate() | 133 shell_delegate->test_session_state_delegate() |
| 139 ->SetActiveUserSessionStarted(true); | 134 ->SetActiveUserSessionStarted(true); |
| 140 context = ash::Shell::GetPrimaryRootWindow(); | 135 context = ash::Shell::GetPrimaryRootWindow(); |
| 141 context->GetHost()->Show(); | 136 context->GetHost()->Show(); |
| 142 #endif // !OS_WIN | 137 #endif // !OS_WIN |
| 143 aura::Env::CreateInstance(); | 138 aura::Env::CreateInstance(); |
| 144 #elif defined(USE_AURA) | 139 #else |
| 145 // Instead of using the ash shell, use an AuraTestHelper to create and manage | 140 // Instead of using the ash shell, use an AuraTestHelper to create and manage |
| 146 // the test screen. | 141 // the test screen. |
| 147 aura_test_helper_.reset( | 142 aura_test_helper_.reset( |
| 148 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); | 143 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
| 149 aura_test_helper_->SetUp(); | 144 aura_test_helper_->SetUp(); |
| 150 context = aura_test_helper_->root_window(); | 145 context = aura_test_helper_->root_window(); |
| 151 #endif // !USE_ASH && USE_AURA | 146 #endif // !USE_ASH && USE_AURA |
| 152 | 147 |
| 153 window_ = views::Widget::CreateWindowWithContext(this, context); | 148 window_ = views::Widget::CreateWindowWithContext(this, context); |
| 154 } | 149 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 168 #if defined(OS_CHROMEOS) | 163 #if defined(OS_CHROMEOS) |
| 169 chromeos::NetworkHandler::Shutdown(); | 164 chromeos::NetworkHandler::Shutdown(); |
| 170 chromeos::CrasAudioHandler::Shutdown(); | 165 chromeos::CrasAudioHandler::Shutdown(); |
| 171 chromeos::DBusThreadManager::Shutdown(); | 166 chromeos::DBusThreadManager::Shutdown(); |
| 172 #endif | 167 #endif |
| 173 // Ash Shell can't just live on its own without a browser process, we need to | 168 // Ash Shell can't just live on its own without a browser process, we need to |
| 174 // also shut down the message center. | 169 // also shut down the message center. |
| 175 message_center::MessageCenter::Shutdown(); | 170 message_center::MessageCenter::Shutdown(); |
| 176 #endif // !OS_WIN | 171 #endif // !OS_WIN |
| 177 aura::Env::DeleteInstance(); | 172 aura::Env::DeleteInstance(); |
| 178 #elif defined(USE_AURA) | 173 #else |
| 179 aura_test_helper_->TearDown(); | 174 aura_test_helper_->TearDown(); |
| 180 #endif // !USE_ASH && USE_AURA | 175 #endif // !USE_ASH && USE_AURA |
| 181 | 176 |
| 182 #if defined(USE_AURA) | |
| 183 ui::TerminateContextFactoryForTests(); | 177 ui::TerminateContextFactoryForTests(); |
| 184 #endif | |
| 185 | 178 |
| 186 ui::ShutdownInputMethodForTesting(); | 179 ui::ShutdownInputMethodForTesting(); |
| 187 views::ViewsDelegate::views_delegate = NULL; | 180 views::ViewsDelegate::views_delegate = NULL; |
| 188 | 181 |
| 189 #if defined(USE_AURA) | |
| 190 wm_state_.reset(); | 182 wm_state_.reset(); |
| 191 #endif | |
| 192 } | 183 } |
| 193 | 184 |
| 194 bool ViewEventTestBase::CanResize() const { | 185 bool ViewEventTestBase::CanResize() const { |
| 195 return true; | 186 return true; |
| 196 } | 187 } |
| 197 | 188 |
| 198 views::View* ViewEventTestBase::GetContentsView() { | 189 views::View* ViewEventTestBase::GetContentsView() { |
| 199 if (!content_view_) { | 190 if (!content_view_) { |
| 200 // Wrap the real view (as returned by CreateContentsView) in a View so | 191 // Wrap the real view (as returned by CreateContentsView) in a View so |
| 201 // that we can customize the preferred size. | 192 // that we can customize the preferred size. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 dnd_thread_.reset(NULL); | 244 dnd_thread_.reset(NULL); |
| 254 } | 245 } |
| 255 | 246 |
| 256 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 247 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
| 257 StopBackgroundThread(); | 248 StopBackgroundThread(); |
| 258 | 249 |
| 259 task.Run(); | 250 task.Run(); |
| 260 if (HasFatalFailure()) | 251 if (HasFatalFailure()) |
| 261 Done(); | 252 Done(); |
| 262 } | 253 } |
| OLD | NEW |