| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 : window_(NULL), | 78 : window_(NULL), |
| 79 content_view_(NULL) { | 79 content_view_(NULL) { |
| 80 // The TestingBrowserProcess must be created in the constructor because there | 80 // The TestingBrowserProcess must be created in the constructor because there |
| 81 // are tests that require it before SetUp() is called. | 81 // are tests that require it before SetUp() is called. |
| 82 TestingBrowserProcess::CreateInstance(); | 82 TestingBrowserProcess::CreateInstance(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void ViewEventTestBase::Done() { | 85 void ViewEventTestBase::Done() { |
| 86 base::MessageLoop::current()->Quit(); | 86 base::MessageLoop::current()->Quit(); |
| 87 | 87 |
| 88 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 89 // We need to post a message to tickle the Dispatcher getting called and | |
| 90 // exiting out of the nested loop. Without this the quit never runs. | |
| 91 if (window_) | |
| 92 PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0); | |
| 93 #endif | |
| 94 | |
| 95 // If we're in a nested message loop, as is the case with menus, we | 88 // If we're in a nested message loop, as is the case with menus, we |
| 96 // need to quit twice. The second quit does that for us. Finish all | 89 // need to quit twice. The second quit does that for us. Finish all |
| 97 // pending UI events before posting closure because events it may be | 90 // pending UI events before posting closure because events it may be |
| 98 // executed before UI events are executed. | 91 // executed before UI events are executed. |
| 99 ui_controls::RunClosureAfterAllPendingUIEvents( | 92 ui_controls::RunClosureAfterAllPendingUIEvents( |
| 100 base::MessageLoop::QuitClosure()); | 93 base::MessageLoop::QuitClosure()); |
| 101 } | 94 } |
| 102 | 95 |
| 103 void ViewEventTestBase::SetUp() { | 96 void ViewEventTestBase::SetUp() { |
| 104 #if defined(USE_AURA) | 97 #if defined(USE_AURA) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 bool allow_test_contexts = true; | 137 bool allow_test_contexts = true; |
| 145 aura_test_helper_->SetUp(allow_test_contexts); | 138 aura_test_helper_->SetUp(allow_test_contexts); |
| 146 context = aura_test_helper_->root_window(); | 139 context = aura_test_helper_->root_window(); |
| 147 #endif // !USE_ASH && USE_AURA | 140 #endif // !USE_ASH && USE_AURA |
| 148 | 141 |
| 149 window_ = views::Widget::CreateWindowWithContext(this, context); | 142 window_ = views::Widget::CreateWindowWithContext(this, context); |
| 150 } | 143 } |
| 151 | 144 |
| 152 void ViewEventTestBase::TearDown() { | 145 void ViewEventTestBase::TearDown() { |
| 153 if (window_) { | 146 if (window_) { |
| 154 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 155 DestroyWindow(window_->GetNativeWindow()); | |
| 156 #else | |
| 157 window_->Close(); | 147 window_->Close(); |
| 158 content::RunAllPendingInMessageLoop(); | 148 content::RunAllPendingInMessageLoop(); |
| 159 #endif | |
| 160 window_ = NULL; | 149 window_ = NULL; |
| 161 } | 150 } |
| 162 | 151 |
| 163 #if defined(USE_ASH) | 152 #if defined(USE_ASH) |
| 164 #if !defined(OS_WIN) | 153 #if !defined(OS_WIN) |
| 165 ash::Shell::DeleteInstance(); | 154 ash::Shell::DeleteInstance(); |
| 166 #if defined(OS_CHROMEOS) | 155 #if defined(OS_CHROMEOS) |
| 167 chromeos::NetworkHandler::Shutdown(); | 156 chromeos::NetworkHandler::Shutdown(); |
| 168 chromeos::CrasAudioHandler::Shutdown(); | 157 chromeos::CrasAudioHandler::Shutdown(); |
| 169 chromeos::DBusThreadManager::Shutdown(); | 158 chromeos::DBusThreadManager::Shutdown(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 dnd_thread_.reset(NULL); | 237 dnd_thread_.reset(NULL); |
| 249 } | 238 } |
| 250 | 239 |
| 251 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 240 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
| 252 StopBackgroundThread(); | 241 StopBackgroundThread(); |
| 253 | 242 |
| 254 task.Run(); | 243 task.Run(); |
| 255 if (HasFatalFailure()) | 244 if (HasFatalFailure()) |
| 256 Done(); | 245 Done(); |
| 257 } | 246 } |
| OLD | NEW |