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.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "chrome/browser/ui/views/chrome_views_delegate.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
13 #include "ui/base/ime/text_input_test_support.h" | 14 #include "ui/base/ime/text_input_test_support.h" |
14 #include "ui/compositor/test/compositor_test_support.h" | 15 #include "ui/compositor/test/compositor_test_support.h" |
15 #include "ui/ui_controls/ui_controls.h" | 16 #include "ui/ui_controls/ui_controls.h" |
16 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
| 18 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
17 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
18 | 20 |
19 #if defined(USE_ASH) | 21 #if defined(USE_ASH) |
20 #include "ash/shell.h" | 22 #include "ash/shell.h" |
21 #include "ash/test/test_shell_delegate.h" | 23 #include "ash/test/test_shell_delegate.h" |
22 #endif | 24 #endif |
23 | 25 |
24 #if defined(USE_AURA) | 26 #if defined(USE_AURA) |
25 #include "ui/aura/client/event_client.h" | 27 #include "ui/aura/client/event_client.h" |
26 #include "ui/aura/env.h" | 28 #include "ui/aura/env.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // need to quit twice. The second quit does that for us. Finish all | 83 // need to quit twice. The second quit does that for us. Finish all |
82 // pending UI events before posting closure because events it may be | 84 // pending UI events before posting closure because events it may be |
83 // executed before UI events are executed. | 85 // executed before UI events are executed. |
84 ui_controls::RunClosureAfterAllPendingUIEvents(MessageLoop::QuitClosure()); | 86 ui_controls::RunClosureAfterAllPendingUIEvents(MessageLoop::QuitClosure()); |
85 } | 87 } |
86 | 88 |
87 void ViewEventTestBase::SetUp() { | 89 void ViewEventTestBase::SetUp() { |
88 ui::TextInputTestSupport::Initialize(); | 90 ui::TextInputTestSupport::Initialize(); |
89 ui::CompositorTestSupport::Initialize(); | 91 ui::CompositorTestSupport::Initialize(); |
90 #if defined(USE_ASH) | 92 #if defined(USE_ASH) |
| 93 #if defined(OS_WIN) |
| 94 // http://crbug.com/154081 use ash::Shell code path below on win_ash bots when |
| 95 // interactive_ui_tests is brought up on that platform. |
| 96 views::ViewsDelegate::views_delegate = new ChromeViewsDelegate; |
| 97 |
| 98 gfx::Screen::SetScreenInstance( |
| 99 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); |
| 100 #else |
91 ash::Shell::CreateInstance(new ash::test::TestShellDelegate()); | 101 ash::Shell::CreateInstance(new ash::test::TestShellDelegate()); |
92 #endif | 102 #endif |
| 103 #endif |
93 window_ = views::Widget::CreateWindow(this); | 104 window_ = views::Widget::CreateWindow(this); |
94 } | 105 } |
95 | 106 |
96 void ViewEventTestBase::TearDown() { | 107 void ViewEventTestBase::TearDown() { |
97 if (window_) { | 108 if (window_) { |
98 #if defined(OS_WIN) && !defined(USE_AURA) | 109 #if defined(OS_WIN) && !defined(USE_AURA) |
99 DestroyWindow(window_->GetNativeWindow()); | 110 DestroyWindow(window_->GetNativeWindow()); |
100 #else | 111 #else |
101 window_->Close(); | 112 window_->Close(); |
102 content::RunAllPendingInMessageLoop(); | 113 content::RunAllPendingInMessageLoop(); |
103 #endif | 114 #endif |
104 window_ = NULL; | 115 window_ = NULL; |
105 } | 116 } |
106 #if defined(USE_ASH) | 117 #if defined(USE_ASH) |
| 118 #if defined(OS_WIN) |
| 119 delete views::ViewsDelegate::views_delegate; |
| 120 views::ViewsDelegate::views_delegate = NULL; |
| 121 #else |
107 ash::Shell::DeleteInstance(); | 122 ash::Shell::DeleteInstance(); |
108 #endif | 123 #endif |
| 124 #endif |
109 #if defined(USE_AURA) | 125 #if defined(USE_AURA) |
110 aura::Env::DeleteInstance(); | 126 aura::Env::DeleteInstance(); |
111 #endif | 127 #endif |
112 ui::CompositorTestSupport::Terminate(); | 128 ui::CompositorTestSupport::Terminate(); |
113 ui::TextInputTestSupport::Shutdown(); | 129 ui::TextInputTestSupport::Shutdown(); |
114 } | 130 } |
115 | 131 |
116 bool ViewEventTestBase::CanResize() const { | 132 bool ViewEventTestBase::CanResize() const { |
117 return true; | 133 return true; |
118 } | 134 } |
(...skipping 18 matching lines...) Expand all Loading... |
137 return content_view_->GetWidget(); | 153 return content_view_->GetWidget(); |
138 } | 154 } |
139 | 155 |
140 ViewEventTestBase::~ViewEventTestBase() { | 156 ViewEventTestBase::~ViewEventTestBase() { |
141 } | 157 } |
142 | 158 |
143 void ViewEventTestBase::StartMessageLoopAndRunTest() { | 159 void ViewEventTestBase::StartMessageLoopAndRunTest() { |
144 window_->Show(); | 160 window_->Show(); |
145 // Make sure the window is the foreground window, otherwise none of the | 161 // Make sure the window is the foreground window, otherwise none of the |
146 // mouse events are going to be targeted correctly. | 162 // mouse events are going to be targeted correctly. |
147 #if defined(OS_WIN) && !defined(USE_AURA) | 163 #if defined(OS_WIN) |
148 SetForegroundWindow(window_->GetNativeWindow()); | 164 #if defined(USE_AURA) |
| 165 HWND window = |
| 166 window_->GetNativeWindow()->GetRootWindow()->GetAcceleratedWidget(); |
| 167 #else |
| 168 HWND window = window_->GetNativeWindow(); |
| 169 #endif |
| 170 SetForegroundWindow(window); |
149 #endif | 171 #endif |
150 | 172 |
151 // Flush any pending events to make sure we start with a clean slate. | 173 // Flush any pending events to make sure we start with a clean slate. |
152 content::RunAllPendingInMessageLoop(); | 174 content::RunAllPendingInMessageLoop(); |
153 | 175 |
154 // Schedule a task that starts the test. Need to do this as we're going to | 176 // Schedule a task that starts the test. Need to do this as we're going to |
155 // run the message loop. | 177 // run the message loop. |
156 MessageLoop::current()->PostTask( | 178 MessageLoop::current()->PostTask( |
157 FROM_HERE, | 179 FROM_HERE, |
158 base::Bind(&ViewEventTestBase::DoTestOnMessageLoop, this)); | 180 base::Bind(&ViewEventTestBase::DoTestOnMessageLoop, this)); |
(...skipping 20 matching lines...) Expand all Loading... |
179 dnd_thread_.reset(NULL); | 201 dnd_thread_.reset(NULL); |
180 } | 202 } |
181 | 203 |
182 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 204 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
183 StopBackgroundThread(); | 205 StopBackgroundThread(); |
184 | 206 |
185 task.Run(); | 207 task.Run(); |
186 if (HasFatalFailure()) | 208 if (HasFatalFailure()) |
187 Done(); | 209 Done(); |
188 } | 210 } |
OLD | NEW |