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) && !defined(USE_AURA) | 71 #if defined(OS_WIN) |
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(); |
90 ash::Shell::CreateInstance(NULL); | 91 ash::Shell::CreateInstance(NULL); |
91 #endif | 92 #endif |
92 window_ = views::Widget::CreateWindow(this); | 93 window_ = views::Widget::CreateWindow(this); |
93 } | 94 } |
94 | 95 |
95 void ViewEventTestBase::TearDown() { | 96 void ViewEventTestBase::TearDown() { |
96 if (window_) { | 97 if (window_) { |
97 #if defined(OS_WIN) && !defined(USE_AURA) | 98 #if defined(OS_WIN) |
98 DestroyWindow(window_->GetNativeWindow()); | 99 DestroyWindow(window_->GetNativeWindow()); |
99 #else | 100 #else |
100 window_->Close(); | 101 window_->Close(); |
101 ui_test_utils::RunAllPendingInMessageLoop(); | 102 ui_test_utils::RunAllPendingInMessageLoop(); |
102 #endif | 103 #endif |
103 window_ = NULL; | 104 window_ = NULL; |
104 } | 105 } |
105 #if defined(USE_AURA) | 106 #if defined(USE_AURA) |
106 ash::Shell::DeleteInstance(); | 107 ash::Shell::DeleteInstance(); |
| 108 aura::RootWindow::DeleteInstance(); |
107 aura::Env::DeleteInstance(); | 109 aura::Env::DeleteInstance(); |
108 #endif | 110 #endif |
109 ui::CompositorTestSupport::Terminate(); | 111 ui::CompositorTestSupport::Terminate(); |
110 #if defined(OS_WIN) | 112 #if defined(OS_WIN) |
111 OleUninitialize(); | 113 OleUninitialize(); |
112 #endif | 114 #endif |
113 } | 115 } |
114 | 116 |
115 bool ViewEventTestBase::CanResize() const { | 117 bool ViewEventTestBase::CanResize() const { |
116 return true; | 118 return true; |
(...skipping 19 matching lines...) Expand all Loading... |
136 return content_view_->GetWidget(); | 138 return content_view_->GetWidget(); |
137 } | 139 } |
138 | 140 |
139 ViewEventTestBase::~ViewEventTestBase() { | 141 ViewEventTestBase::~ViewEventTestBase() { |
140 } | 142 } |
141 | 143 |
142 void ViewEventTestBase::StartMessageLoopAndRunTest() { | 144 void ViewEventTestBase::StartMessageLoopAndRunTest() { |
143 window_->Show(); | 145 window_->Show(); |
144 // Make sure the window is the foreground window, otherwise none of the | 146 // Make sure the window is the foreground window, otherwise none of the |
145 // mouse events are going to be targeted correctly. | 147 // mouse events are going to be targeted correctly. |
146 #if defined(OS_WIN) && !defined(USE_AURA) | 148 #if defined(OS_WIN) |
147 SetForegroundWindow(window_->GetNativeWindow()); | 149 SetForegroundWindow(window_->GetNativeWindow()); |
148 #endif | 150 #endif |
149 | 151 |
150 // Flush any pending events to make sure we start with a clean slate. | 152 // Flush any pending events to make sure we start with a clean slate. |
151 ui_test_utils::RunAllPendingInMessageLoop(); | 153 ui_test_utils::RunAllPendingInMessageLoop(); |
152 | 154 |
153 // Schedule a task that starts the test. Need to do this as we're going to | 155 // Schedule a task that starts the test. Need to do this as we're going to |
154 // run the message loop. | 156 // run the message loop. |
155 MessageLoop::current()->PostTask( | 157 MessageLoop::current()->PostTask( |
156 FROM_HERE, | 158 FROM_HERE, |
(...skipping 21 matching lines...) Expand all Loading... |
178 dnd_thread_.reset(NULL); | 180 dnd_thread_.reset(NULL); |
179 } | 181 } |
180 | 182 |
181 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 183 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
182 StopBackgroundThread(); | 184 StopBackgroundThread(); |
183 | 185 |
184 task.Run(); | 186 task.Run(); |
185 if (HasFatalFailure()) | 187 if (HasFatalFailure()) |
186 Done(); | 188 Done(); |
187 } | 189 } |
OLD | NEW |