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 26 matching lines...) Expand all Loading... |
37 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
38 #include "chromeos/audio/cras_audio_handler.h" | 38 #include "chromeos/audio/cras_audio_handler.h" |
39 #include "chromeos/dbus/dbus_thread_manager.h" | 39 #include "chromeos/dbus/dbus_thread_manager.h" |
40 #include "chromeos/network/network_handler.h" | 40 #include "chromeos/network/network_handler.h" |
41 #else // !defined(OS_CHROMEOS) | 41 #else // !defined(OS_CHROMEOS) |
42 #include "ui/views/widget/desktop_aura/desktop_screen.h" | 42 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
43 #endif | 43 #endif |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
| 47 class ViewEventTestBaseViewsDelegate : public ChromeViewsDelegate { |
| 48 public: |
| 49 ViewEventTestBaseViewsDelegate() : context_factory_(NULL) { |
| 50 views::ViewsDelegate::views_delegate = this; |
| 51 } |
| 52 virtual ~ViewEventTestBaseViewsDelegate() { |
| 53 views::ViewsDelegate::views_delegate = NULL; |
| 54 } |
| 55 |
| 56 void set_context_factory(ui::ContextFactory* context_factory) { |
| 57 context_factory_ = context_factory; |
| 58 } |
| 59 |
| 60 // ChromeViewsDelegate: |
| 61 virtual ui::ContextFactory* GetContextFactory() OVERRIDE { |
| 62 return context_factory_; |
| 63 } |
| 64 |
| 65 private: |
| 66 ui::ContextFactory* context_factory_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(ViewEventTestBaseViewsDelegate); |
| 69 }; |
| 70 |
47 // View subclass that allows you to specify the preferred size. | 71 // View subclass that allows you to specify the preferred size. |
48 class TestView : public views::View { | 72 class TestView : public views::View { |
49 public: | 73 public: |
50 TestView() {} | 74 TestView() {} |
51 | 75 |
52 void SetPreferredSize(const gfx::Size& size) { | 76 void SetPreferredSize(const gfx::Size& size) { |
53 preferred_size_ = size; | 77 preferred_size_ = size; |
54 PreferredSizeChanged(); | 78 PreferredSizeChanged(); |
55 } | 79 } |
56 | 80 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 120 } |
97 | 121 |
98 void ViewEventTestBase::SetUpTestCase() { | 122 void ViewEventTestBase::SetUpTestCase() { |
99 ChromeUnitTestSuite::InitializeProviders(); | 123 ChromeUnitTestSuite::InitializeProviders(); |
100 ChromeUnitTestSuite::InitializeResourceBundle(); | 124 ChromeUnitTestSuite::InitializeResourceBundle(); |
101 } | 125 } |
102 | 126 |
103 void ViewEventTestBase::SetUp() { | 127 void ViewEventTestBase::SetUp() { |
104 wm_state_.reset(new wm::WMState); | 128 wm_state_.reset(new wm::WMState); |
105 | 129 |
106 views::ViewsDelegate::views_delegate = &views_delegate_; | 130 ViewEventTestBaseViewsDelegate* views_delegate = |
| 131 new ViewEventTestBaseViewsDelegate; |
| 132 views_delegate_.reset(views_delegate); |
| 133 |
107 ui::InitializeInputMethodForTesting(); | 134 ui::InitializeInputMethodForTesting(); |
108 gfx::NativeView context = NULL; | 135 gfx::NativeView context = NULL; |
109 | 136 |
110 // The ContextFactory must exist before any Compositors are created. | 137 // The ContextFactory must exist before any Compositors are created. |
111 bool enable_pixel_output = false; | 138 bool enable_pixel_output = false; |
112 ui::InitializeContextFactoryForTests(enable_pixel_output); | 139 ui::ContextFactory* context_factory = |
| 140 ui::InitializeContextFactoryForTests(enable_pixel_output); |
| 141 views_delegate->set_context_factory(context_factory); |
113 | 142 |
114 #if defined(USE_ASH) | 143 #if defined(USE_ASH) |
115 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
116 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when | 145 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when |
117 // interactive_ui_tests is brought up on that platform. | 146 // interactive_ui_tests is brought up on that platform. |
118 gfx::Screen::SetScreenInstance( | 147 gfx::Screen::SetScreenInstance( |
119 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); | 148 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); |
120 | 149 |
121 #else // !OS_WIN | 150 #else // !OS_WIN |
122 // Ash Shell can't just live on its own without a browser process, we need to | 151 // Ash Shell can't just live on its own without a browser process, we need to |
123 // also create the message center. | 152 // also create the message center. |
124 message_center::MessageCenter::Initialize(); | 153 message_center::MessageCenter::Initialize(); |
125 #if defined(OS_CHROMEOS) | 154 #if defined(OS_CHROMEOS) |
126 chromeos::DBusThreadManager::InitializeWithStub(); | 155 chromeos::DBusThreadManager::InitializeWithStub(); |
127 chromeos::CrasAudioHandler::InitializeForTesting(); | 156 chromeos::CrasAudioHandler::InitializeForTesting(); |
128 chromeos::NetworkHandler::Initialize(); | 157 chromeos::NetworkHandler::Initialize(); |
129 #endif // OS_CHROMEOS | 158 #endif // OS_CHROMEOS |
130 ash::test::TestShellDelegate* shell_delegate = | 159 ash::test::TestShellDelegate* shell_delegate = |
131 new ash::test::TestShellDelegate(); | 160 new ash::test::TestShellDelegate(); |
132 ash::ShellInitParams init_params; | 161 ash::ShellInitParams init_params; |
133 init_params.delegate = shell_delegate; | 162 init_params.delegate = shell_delegate; |
| 163 init_params.context_factory = context_factory; |
134 ash::Shell::CreateInstance(init_params); | 164 ash::Shell::CreateInstance(init_params); |
135 shell_delegate->test_session_state_delegate() | 165 shell_delegate->test_session_state_delegate() |
136 ->SetActiveUserSessionStarted(true); | 166 ->SetActiveUserSessionStarted(true); |
137 context = ash::Shell::GetPrimaryRootWindow(); | 167 context = ash::Shell::GetPrimaryRootWindow(); |
138 context->GetHost()->Show(); | 168 context->GetHost()->Show(); |
139 #endif // !OS_WIN | 169 #endif // !OS_WIN |
140 aura::Env::CreateInstance(true); | 170 aura::Env::CreateInstance(true); |
141 #elif defined(USE_AURA) | 171 #elif defined(USE_AURA) |
142 // Instead of using the ash shell, use an AuraTestHelper to create and manage | 172 // Instead of using the ash shell, use an AuraTestHelper to create and manage |
143 // the test screen. | 173 // the test screen. |
144 aura_test_helper_.reset( | 174 aura_test_helper_.reset( |
145 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); | 175 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
146 aura_test_helper_->SetUp(); | 176 aura_test_helper_->SetUp(context_factory); |
147 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 177 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
148 context = aura_test_helper_->root_window(); | 178 context = aura_test_helper_->root_window(); |
149 #endif // !USE_ASH && USE_AURA | 179 #endif // !USE_ASH && USE_AURA |
150 | 180 |
151 window_ = views::Widget::CreateWindowWithContext(this, context); | 181 window_ = views::Widget::CreateWindowWithContext(this, context); |
152 } | 182 } |
153 | 183 |
154 void ViewEventTestBase::TearDown() { | 184 void ViewEventTestBase::TearDown() { |
155 if (window_) { | 185 if (window_) { |
156 window_->Close(); | 186 window_->Close(); |
(...skipping 16 matching lines...) Expand all Loading... |
173 message_center::MessageCenter::Shutdown(); | 203 message_center::MessageCenter::Shutdown(); |
174 #endif // !OS_WIN | 204 #endif // !OS_WIN |
175 aura::Env::DeleteInstance(); | 205 aura::Env::DeleteInstance(); |
176 #elif defined(USE_AURA) | 206 #elif defined(USE_AURA) |
177 aura_test_helper_->TearDown(); | 207 aura_test_helper_->TearDown(); |
178 #endif // !USE_ASH && USE_AURA | 208 #endif // !USE_ASH && USE_AURA |
179 | 209 |
180 ui::TerminateContextFactoryForTests(); | 210 ui::TerminateContextFactoryForTests(); |
181 | 211 |
182 ui::ShutdownInputMethodForTesting(); | 212 ui::ShutdownInputMethodForTesting(); |
183 views::ViewsDelegate::views_delegate = NULL; | 213 |
| 214 views_delegate_.reset(); |
184 | 215 |
185 wm_state_.reset(); | 216 wm_state_.reset(); |
186 } | 217 } |
187 | 218 |
188 bool ViewEventTestBase::CanResize() const { | 219 bool ViewEventTestBase::CanResize() const { |
189 return true; | 220 return true; |
190 } | 221 } |
191 | 222 |
192 views::View* ViewEventTestBase::GetContentsView() { | 223 views::View* ViewEventTestBase::GetContentsView() { |
193 if (!content_view_) { | 224 if (!content_view_) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 dnd_thread_.reset(NULL); | 278 dnd_thread_.reset(NULL); |
248 } | 279 } |
249 | 280 |
250 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 281 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
251 StopBackgroundThread(); | 282 StopBackgroundThread(); |
252 | 283 |
253 task.Run(); | 284 task.Run(); |
254 if (HasFatalFailure()) | 285 if (HasFatalFailure()) |
255 Done(); | 286 Done(); |
256 } | 287 } |
OLD | NEW |