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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <ole2.h> | 8 #include <ole2.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 ViewEventTestBase::ViewEventTestBase() | 62 ViewEventTestBase::ViewEventTestBase() |
63 : window_(NULL), | 63 : window_(NULL), |
64 content_view_(NULL), | 64 content_view_(NULL), |
65 ui_thread_(content::BrowserThread::UI, &message_loop_) { | 65 ui_thread_(content::BrowserThread::UI, &message_loop_) { |
66 } | 66 } |
67 | 67 |
68 void ViewEventTestBase::Done() { | 68 void ViewEventTestBase::Done() { |
69 MessageLoop::current()->Quit(); | 69 MessageLoop::current()->Quit(); |
70 | 70 |
71 #if defined(OS_WIN) | 71 #if defined(OS_WIN) && !defined(USE_AURA) |
72 // We need to post a message to tickle the Dispatcher getting called and | 72 // We need to post a message to tickle the Dispatcher getting called and |
73 // exiting out of the nested loop. Without this the quit never runs. | 73 // exiting out of the nested loop. Without this the quit never runs. |
74 PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0); | 74 PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0); |
75 #endif | 75 #endif |
76 | 76 |
77 // If we're in a nested message loop, as is the case with menus, we | 77 // If we're in a nested message loop, as is the case with menus, we |
78 // need to quit twice. The second quit does that for us. Finish all | 78 // need to quit twice. The second quit does that for us. Finish all |
79 // pending UI events before posting closure because events it may be | 79 // pending UI events before posting closure because events it may be |
80 // executed before UI events are executed. | 80 // executed before UI events are executed. |
81 ui_controls::RunClosureAfterAllPendingUIEvents(MessageLoop::QuitClosure()); | 81 ui_controls::RunClosureAfterAllPendingUIEvents(MessageLoop::QuitClosure()); |
82 } | 82 } |
83 | 83 |
84 void ViewEventTestBase::SetUp() { | 84 void ViewEventTestBase::SetUp() { |
85 #if defined(OS_WIN) | 85 #if defined(OS_WIN) |
86 OleInitialize(NULL); | 86 OleInitialize(NULL); |
87 #endif | 87 #endif |
88 ui::CompositorTestSupport::Initialize(); | 88 ui::CompositorTestSupport::Initialize(); |
89 #if defined(USE_AURA) | 89 #if defined(USE_AURA) |
90 ash::Shell::GetRootWindow(); | |
91 ash::Shell::CreateInstance(NULL); | 90 ash::Shell::CreateInstance(NULL); |
92 #endif | 91 #endif |
93 window_ = views::Widget::CreateWindow(this); | 92 window_ = views::Widget::CreateWindow(this); |
94 } | 93 } |
95 | 94 |
96 void ViewEventTestBase::TearDown() { | 95 void ViewEventTestBase::TearDown() { |
97 if (window_) { | 96 if (window_) { |
98 #if defined(OS_WIN) | 97 #if defined(OS_WIN) && !defined(USE_AURA) |
99 DestroyWindow(window_->GetNativeWindow()); | 98 DestroyWindow(window_->GetNativeWindow()); |
100 #else | 99 #else |
101 window_->Close(); | 100 window_->Close(); |
102 ui_test_utils::RunAllPendingInMessageLoop(); | 101 ui_test_utils::RunAllPendingInMessageLoop(); |
103 #endif | 102 #endif |
104 window_ = NULL; | 103 window_ = NULL; |
105 } | 104 } |
106 #if defined(USE_AURA) | 105 #if defined(USE_AURA) |
107 ash::Shell::DeleteInstance(); | 106 ash::Shell::DeleteInstance(); |
108 aura::RootWindow::DeleteInstance(); | |
109 aura::Env::DeleteInstance(); | 107 aura::Env::DeleteInstance(); |
110 #endif | 108 #endif |
111 ui::CompositorTestSupport::Terminate(); | 109 ui::CompositorTestSupport::Terminate(); |
112 #if defined(OS_WIN) | 110 #if defined(OS_WIN) |
113 OleUninitialize(); | 111 OleUninitialize(); |
114 #endif | 112 #endif |
115 } | 113 } |
116 | 114 |
117 bool ViewEventTestBase::CanResize() const { | 115 bool ViewEventTestBase::CanResize() const { |
118 return true; | 116 return true; |
(...skipping 19 matching lines...) Expand all Loading... |
138 return content_view_->GetWidget(); | 136 return content_view_->GetWidget(); |
139 } | 137 } |
140 | 138 |
141 ViewEventTestBase::~ViewEventTestBase() { | 139 ViewEventTestBase::~ViewEventTestBase() { |
142 } | 140 } |
143 | 141 |
144 void ViewEventTestBase::StartMessageLoopAndRunTest() { | 142 void ViewEventTestBase::StartMessageLoopAndRunTest() { |
145 window_->Show(); | 143 window_->Show(); |
146 // Make sure the window is the foreground window, otherwise none of the | 144 // Make sure the window is the foreground window, otherwise none of the |
147 // mouse events are going to be targeted correctly. | 145 // mouse events are going to be targeted correctly. |
148 #if defined(OS_WIN) | 146 #if defined(OS_WIN) && !defined(USE_AURA) |
149 SetForegroundWindow(window_->GetNativeWindow()); | 147 SetForegroundWindow(window_->GetNativeWindow()); |
150 #endif | 148 #endif |
151 | 149 |
152 // Flush any pending events to make sure we start with a clean slate. | 150 // Flush any pending events to make sure we start with a clean slate. |
153 ui_test_utils::RunAllPendingInMessageLoop(); | 151 ui_test_utils::RunAllPendingInMessageLoop(); |
154 | 152 |
155 // Schedule a task that starts the test. Need to do this as we're going to | 153 // Schedule a task that starts the test. Need to do this as we're going to |
156 // run the message loop. | 154 // run the message loop. |
157 MessageLoop::current()->PostTask( | 155 MessageLoop::current()->PostTask( |
158 FROM_HERE, | 156 FROM_HERE, |
(...skipping 21 matching lines...) Expand all Loading... |
180 dnd_thread_.reset(NULL); | 178 dnd_thread_.reset(NULL); |
181 } | 179 } |
182 | 180 |
183 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 181 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
184 StopBackgroundThread(); | 182 StopBackgroundThread(); |
185 | 183 |
186 task.Run(); | 184 task.Run(); |
187 if (HasFatalFailure()) | 185 if (HasFatalFailure()) |
188 Done(); | 186 Done(); |
189 } | 187 } |
OLD | NEW |