| 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/message_loop/message_loop.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" |
| 9 #include "chrome/test/base/chrome_unit_test_suite.h" | 11 #include "chrome/test/base/chrome_unit_test_suite.h" |
| 10 #include "chrome/test/base/interactive_test_utils.h" | 12 #include "chrome/test/base/interactive_test_utils.h" |
| 11 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
| 12 #include "chrome/test/base/view_event_test_platform_part.h" | 14 #include "chrome/test/base/view_event_test_platform_part.h" |
| 13 #include "ui/base/ime/input_method_initializer.h" | 15 #include "ui/base/ime/input_method_initializer.h" |
| 14 #include "ui/base/test/ui_controls.h" | 16 #include "ui/base/test/ui_controls.h" |
| 15 #include "ui/compositor/test/context_factories_for_test.h" | 17 #include "ui/compositor/test/context_factories_for_test.h" |
| 16 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
| 17 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 18 | 20 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 130 |
| 129 void ViewEventTestBase::StartMessageLoopAndRunTest() { | 131 void ViewEventTestBase::StartMessageLoopAndRunTest() { |
| 130 ASSERT_TRUE( | 132 ASSERT_TRUE( |
| 131 ui_test_utils::ShowAndFocusNativeWindow(window_->GetNativeWindow())); | 133 ui_test_utils::ShowAndFocusNativeWindow(window_->GetNativeWindow())); |
| 132 | 134 |
| 133 // Flush any pending events to make sure we start with a clean slate. | 135 // Flush any pending events to make sure we start with a clean slate. |
| 134 content::RunAllPendingInMessageLoop(); | 136 content::RunAllPendingInMessageLoop(); |
| 135 | 137 |
| 136 // Schedule a task that starts the test. Need to do this as we're going to | 138 // Schedule a task that starts the test. Need to do this as we're going to |
| 137 // run the message loop. | 139 // run the message loop. |
| 138 base::MessageLoop::current()->PostTask( | 140 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 139 FROM_HERE, base::Bind(&ViewEventTestBase::DoTestOnMessageLoop, this)); | 141 FROM_HERE, base::Bind(&ViewEventTestBase::DoTestOnMessageLoop, this)); |
| 140 | 142 |
| 141 content::RunThisRunLoop(&run_loop_); | 143 content::RunThisRunLoop(&run_loop_); |
| 142 } | 144 } |
| 143 | 145 |
| 144 gfx::Size ViewEventTestBase::GetPreferredSize() const { | 146 gfx::Size ViewEventTestBase::GetPreferredSize() const { |
| 145 return gfx::Size(); | 147 return gfx::Size(); |
| 146 } | 148 } |
| 147 | 149 |
| 148 void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) { | 150 void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) { |
| 149 if (!dnd_thread_.get()) { | 151 if (!dnd_thread_.get()) { |
| 150 dnd_thread_.reset(new base::Thread("mouse-move-thread")); | 152 dnd_thread_.reset(new base::Thread("mouse-move-thread")); |
| 151 dnd_thread_->Start(); | 153 dnd_thread_->Start(); |
| 152 } | 154 } |
| 153 dnd_thread_->message_loop()->PostDelayedTask( | 155 dnd_thread_->task_runner()->PostDelayedTask( |
| 154 FROM_HERE, | 156 FROM_HERE, |
| 155 base::Bind(base::IgnoreResult(&ui_controls::SendMouseMove), x, y), | 157 base::Bind(base::IgnoreResult(&ui_controls::SendMouseMove), x, y), |
| 156 base::TimeDelta::FromMilliseconds(kMouseMoveDelayMS)); | 158 base::TimeDelta::FromMilliseconds(kMouseMoveDelayMS)); |
| 157 } | 159 } |
| 158 | 160 |
| 159 void ViewEventTestBase::StopBackgroundThread() { | 161 void ViewEventTestBase::StopBackgroundThread() { |
| 160 dnd_thread_.reset(NULL); | 162 dnd_thread_.reset(NULL); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 165 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
| 164 StopBackgroundThread(); | 166 StopBackgroundThread(); |
| 165 | 167 |
| 166 task.Run(); | 168 task.Run(); |
| 167 if (HasFatalFailure()) | 169 if (HasFatalFailure()) |
| 168 Done(); | 170 Done(); |
| 169 } | 171 } |
| OLD | NEW |