| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" |
| 11 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 12 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 13 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 14 #include "chrome/browser/automation/ui_controls.h" | 16 #include "chrome/browser/automation/ui_controls.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "views/view.h" | 18 #include "views/view.h" |
| 17 #include "views/widget/widget.h" | 19 #include "views/widget/widget.h" |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 MessageLoop::current()->Quit(); | 65 MessageLoop::current()->Quit(); |
| 64 | 66 |
| 65 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
| 66 // We need to post a message to tickle the Dispatcher getting called and | 68 // We need to post a message to tickle the Dispatcher getting called and |
| 67 // exiting out of the nested loop. Without this the quit never runs. | 69 // exiting out of the nested loop. Without this the quit never runs. |
| 68 PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0); | 70 PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0); |
| 69 #endif | 71 #endif |
| 70 | 72 |
| 71 // If we're in a nested message loop, as is the case with menus, we need | 73 // If we're in a nested message loop, as is the case with menus, we need |
| 72 // to quit twice. The second quit does that for us. | 74 // to quit twice. The second quit does that for us. |
| 73 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 75 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void ViewEventTestBase::SetUp() { | 78 void ViewEventTestBase::SetUp() { |
| 77 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
| 78 OleInitialize(NULL); | 80 OleInitialize(NULL); |
| 79 #endif | 81 #endif |
| 80 window_ = views::Widget::CreateWindow(this); | 82 window_ = views::Widget::CreateWindow(this); |
| 81 } | 83 } |
| 82 | 84 |
| 83 void ViewEventTestBase::TearDown() { | 85 void ViewEventTestBase::TearDown() { |
| 84 if (window_) { | 86 if (window_) { |
| 85 #if defined(OS_WIN) | 87 #if defined(OS_WIN) |
| 86 DestroyWindow(window_->GetNativeWindow()); | 88 DestroyWindow(window_->GetNativeWindow()); |
| 87 #else | 89 #else |
| 88 window_->Close(); | 90 window_->Close(); |
| 89 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 91 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 90 ui_test_utils::RunMessageLoop(); | 92 ui_test_utils::RunMessageLoop(); |
| 91 #endif | 93 #endif |
| 92 window_ = NULL; | 94 window_ = NULL; |
| 93 } | 95 } |
| 94 #if defined(OS_WIN) | 96 #if defined(OS_WIN) |
| 95 OleUninitialize(); | 97 OleUninitialize(); |
| 96 #endif | 98 #endif |
| 97 } | 99 } |
| 98 | 100 |
| 99 bool ViewEventTestBase::CanResize() const { | 101 bool ViewEventTestBase::CanResize() const { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 SetForegroundWindow(window_->GetNativeWindow()); | 133 SetForegroundWindow(window_->GetNativeWindow()); |
| 132 #endif | 134 #endif |
| 133 | 135 |
| 134 // Flush any pending events to make sure we start with a clean slate. | 136 // Flush any pending events to make sure we start with a clean slate. |
| 135 MessageLoop::current()->RunAllPending(); | 137 MessageLoop::current()->RunAllPending(); |
| 136 | 138 |
| 137 // Schedule a task that starts the test. Need to do this as we're going to | 139 // Schedule a task that starts the test. Need to do this as we're going to |
| 138 // run the message loop. | 140 // run the message loop. |
| 139 MessageLoop::current()->PostTask( | 141 MessageLoop::current()->PostTask( |
| 140 FROM_HERE, | 142 FROM_HERE, |
| 141 NewRunnableMethod(this, &ViewEventTestBase::DoTestOnMessageLoop)); | 143 base::Bind(&ViewEventTestBase::DoTestOnMessageLoop, this)); |
| 142 | 144 |
| 143 MessageLoop::current()->Run(); | 145 MessageLoop::current()->Run(); |
| 144 } | 146 } |
| 145 | 147 |
| 146 gfx::Size ViewEventTestBase::GetPreferredSize() { | 148 gfx::Size ViewEventTestBase::GetPreferredSize() { |
| 147 return gfx::Size(); | 149 return gfx::Size(); |
| 148 } | 150 } |
| 149 | 151 |
| 150 void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) { | 152 void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) { |
| 151 if (!dnd_thread_.get()) { | 153 if (!dnd_thread_.get()) { |
| 152 dnd_thread_.reset(new base::Thread("mouse-move-thread")); | 154 dnd_thread_.reset(new base::Thread("mouse-move-thread")); |
| 153 dnd_thread_->Start(); | 155 dnd_thread_->Start(); |
| 154 } | 156 } |
| 155 dnd_thread_->message_loop()->PostDelayedTask( | 157 dnd_thread_->message_loop()->PostDelayedTask( |
| 156 FROM_HERE, NewRunnableFunction(&ui_controls::SendMouseMove, x, y), | 158 FROM_HERE, |
| 159 base::IgnoreReturn<bool>(base::Bind(&ui_controls::SendMouseMove, x, y)), |
| 157 kMouseMoveDelayMS); | 160 kMouseMoveDelayMS); |
| 158 } | 161 } |
| 159 | 162 |
| 160 void ViewEventTestBase::StopBackgroundThread() { | 163 void ViewEventTestBase::StopBackgroundThread() { |
| 161 dnd_thread_.reset(NULL); | 164 dnd_thread_.reset(NULL); |
| 162 } | 165 } |
| 163 | 166 |
| 164 void ViewEventTestBase::RunTestMethod(Task* task) { | 167 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
| 165 StopBackgroundThread(); | 168 StopBackgroundThread(); |
| 166 | 169 |
| 167 scoped_ptr<Task> task_deleter(task); | 170 task.Run(); |
| 168 task->Run(); | |
| 169 if (HasFatalFailure()) | 171 if (HasFatalFailure()) |
| 170 Done(); | 172 Done(); |
| 171 } | 173 } |
| OLD | NEW |