| 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/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "chrome/test/base/chrome_unit_test_suite.h" | 11 #include "chrome/test/base/chrome_unit_test_suite.h" |
| 12 #include "chrome/test/base/interactive_test_utils.h" | 12 #include "chrome/test/base/interactive_test_utils.h" |
| 13 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
| 14 #include "chrome/test/base/view_event_test_platform_part.h" | 14 #include "chrome/test/base/view_event_test_platform_part.h" |
| 15 #include "ui/base/ime/input_method_initializer.h" | 15 #include "ui/base/ime/input_method_initializer.h" |
| 16 #include "ui/base/test/ui_controls.h" | 16 #include "ui/base/test/ui_controls.h" |
| 17 #include "ui/compositor/test/context_factories_for_test.h" | 17 #include "ui/compositor/test/context_factories_for_test.h" |
| 18 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // View subclass that allows you to specify the preferred size. | 23 // View subclass that allows you to specify the preferred size. |
| 24 class TestView : public views::View { | 24 class TestView : public views::View { |
| 25 public: | 25 public: |
| 26 TestView() {} | 26 explicit TestView(ViewEventTestBase* harness) : harness_(harness) {} |
| 27 | |
| 28 void SetPreferredSize(const gfx::Size& size) { | |
| 29 preferred_size_ = size; | |
| 30 PreferredSizeChanged(); | |
| 31 } | |
| 32 | 27 |
| 33 gfx::Size GetPreferredSize() const override { | 28 gfx::Size GetPreferredSize() const override { |
| 34 if (!preferred_size_.IsEmpty()) | 29 return harness_->GetPreferredSize(); |
| 35 return preferred_size_; | |
| 36 return View::GetPreferredSize(); | |
| 37 } | 30 } |
| 38 | 31 |
| 39 void Layout() override { | 32 void Layout() override { |
| 40 View* child_view = child_at(0); | 33 View* child_view = child_at(0); |
| 41 child_view->SetBounds(0, 0, width(), height()); | 34 child_view->SetBounds(0, 0, width(), height()); |
| 42 } | 35 } |
| 43 | 36 |
| 44 private: | 37 private: |
| 45 gfx::Size preferred_size_; | 38 ViewEventTestBase* harness_; |
| 46 | 39 |
| 47 DISALLOW_COPY_AND_ASSIGN(TestView); | 40 DISALLOW_COPY_AND_ASSIGN(TestView); |
| 48 }; | 41 }; |
| 49 | 42 |
| 50 // Delay in background thread before posting mouse move. | 43 // Delay in background thread before posting mouse move. |
| 51 const int kMouseMoveDelayMS = 200; | 44 const int kMouseMoveDelayMS = 200; |
| 52 | 45 |
| 53 } // namespace | 46 } // namespace |
| 54 | 47 |
| 55 ViewEventTestBase::ViewEventTestBase() | 48 ViewEventTestBase::ViewEventTestBase() |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 86 } |
| 94 | 87 |
| 95 ui::Clipboard::DestroyClipboardForCurrentThread(); | 88 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 96 platform_part_.reset(); | 89 platform_part_.reset(); |
| 97 | 90 |
| 98 ui::TerminateContextFactoryForTests(); | 91 ui::TerminateContextFactoryForTests(); |
| 99 | 92 |
| 100 ui::ShutdownInputMethodForTesting(); | 93 ui::ShutdownInputMethodForTesting(); |
| 101 } | 94 } |
| 102 | 95 |
| 96 gfx::Size ViewEventTestBase::GetPreferredSize() const { |
| 97 return gfx::Size(); |
| 98 } |
| 99 |
| 103 bool ViewEventTestBase::CanResize() const { | 100 bool ViewEventTestBase::CanResize() const { |
| 104 return true; | 101 return true; |
| 105 } | 102 } |
| 106 | 103 |
| 107 views::View* ViewEventTestBase::GetContentsView() { | 104 views::View* ViewEventTestBase::GetContentsView() { |
| 108 if (!content_view_) { | 105 if (!content_view_) { |
| 109 // Wrap the real view (as returned by CreateContentsView) in a View so | 106 // Wrap the real view (as returned by CreateContentsView) in a View so |
| 110 // that we can customize the preferred size. | 107 // that we can customize the preferred size. |
| 111 TestView* test_view = new TestView(); | 108 TestView* test_view = new TestView(this); |
| 112 test_view->SetPreferredSize(GetPreferredSize()); | |
| 113 test_view->AddChildView(CreateContentsView()); | 109 test_view->AddChildView(CreateContentsView()); |
| 114 content_view_ = test_view; | 110 content_view_ = test_view; |
| 115 } | 111 } |
| 116 return content_view_; | 112 return content_view_; |
| 117 } | 113 } |
| 118 | 114 |
| 119 const views::Widget* ViewEventTestBase::GetWidget() const { | 115 const views::Widget* ViewEventTestBase::GetWidget() const { |
| 120 return content_view_->GetWidget(); | 116 return content_view_->GetWidget(); |
| 121 } | 117 } |
| 122 | 118 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 136 content::RunAllPendingInMessageLoop(); | 132 content::RunAllPendingInMessageLoop(); |
| 137 | 133 |
| 138 // Schedule a task that starts the test. Need to do this as we're going to | 134 // Schedule a task that starts the test. Need to do this as we're going to |
| 139 // run the message loop. | 135 // run the message loop. |
| 140 base::ThreadTaskRunnerHandle::Get()->PostTask( | 136 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 141 FROM_HERE, base::Bind(&ViewEventTestBase::DoTestOnMessageLoop, this)); | 137 FROM_HERE, base::Bind(&ViewEventTestBase::DoTestOnMessageLoop, this)); |
| 142 | 138 |
| 143 content::RunThisRunLoop(&run_loop_); | 139 content::RunThisRunLoop(&run_loop_); |
| 144 } | 140 } |
| 145 | 141 |
| 146 gfx::Size ViewEventTestBase::GetPreferredSize() const { | |
| 147 return gfx::Size(); | |
| 148 } | |
| 149 | |
| 150 void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) { | 142 void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) { |
| 151 if (!dnd_thread_.get()) { | 143 if (!dnd_thread_.get()) { |
| 152 dnd_thread_.reset(new base::Thread("mouse-move-thread")); | 144 dnd_thread_.reset(new base::Thread("mouse-move-thread")); |
| 153 dnd_thread_->Start(); | 145 dnd_thread_->Start(); |
| 154 } | 146 } |
| 155 dnd_thread_->task_runner()->PostDelayedTask( | 147 dnd_thread_->task_runner()->PostDelayedTask( |
| 156 FROM_HERE, | 148 FROM_HERE, |
| 157 base::Bind(base::IgnoreResult(&ui_controls::SendMouseMove), x, y), | 149 base::Bind(base::IgnoreResult(&ui_controls::SendMouseMove), x, y), |
| 158 base::TimeDelta::FromMilliseconds(kMouseMoveDelayMS)); | 150 base::TimeDelta::FromMilliseconds(kMouseMoveDelayMS)); |
| 159 } | 151 } |
| 160 | 152 |
| 161 void ViewEventTestBase::StopBackgroundThread() { | 153 void ViewEventTestBase::StopBackgroundThread() { |
| 162 dnd_thread_.reset(NULL); | 154 dnd_thread_.reset(NULL); |
| 163 } | 155 } |
| 164 | 156 |
| 165 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 157 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
| 166 StopBackgroundThread(); | 158 StopBackgroundThread(); |
| 167 | 159 |
| 168 task.Run(); | 160 task.Run(); |
| 169 if (HasFatalFailure()) | 161 if (HasFatalFailure()) |
| 170 Done(); | 162 Done(); |
| 171 } | 163 } |
| OLD | NEW |