| 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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "chrome/test/base/ui_test_utils.h" | 11 #include "chrome/test/base/ui_test_utils.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "ui/gfx/compositor/test/compositor_test_support.h" | 13 #include "ui/gfx/compositor/test/compositor_test_support.h" |
| 14 #include "ui/ui_controls/ui_controls.h" | 14 #include "ui/ui_controls/ui_controls.h" |
| 15 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
| 16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 17 | 17 |
| 18 #if defined(USE_AURA) | 18 #if defined(USE_AURA) |
| 19 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 20 #include "ui/aura/client/event_client.h" |
| 20 #include "ui/aura/env.h" | 21 #include "ui/aura/env.h" |
| 21 #include "ui/aura/root_window.h" | 22 #include "ui/aura/root_window.h" |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // View subclass that allows you to specify the preferred size. | 27 // View subclass that allows you to specify the preferred size. |
| 27 class TestView : public views::View { | 28 class TestView : public views::View { |
| 28 public: | 29 public: |
| 29 TestView() {} | 30 TestView() {} |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // need to quit twice. The second quit does that for us. Finish all | 75 // need to quit twice. The second quit does that for us. Finish all |
| 75 // pending UI events before posting closure because events it may be | 76 // pending UI events before posting closure because events it may be |
| 76 // executed before UI events are executed. | 77 // executed before UI events are executed. |
| 77 ui_controls::RunClosureAfterAllPendingUIEvents(MessageLoop::QuitClosure()); | 78 ui_controls::RunClosureAfterAllPendingUIEvents(MessageLoop::QuitClosure()); |
| 78 } | 79 } |
| 79 | 80 |
| 80 void ViewEventTestBase::SetUp() { | 81 void ViewEventTestBase::SetUp() { |
| 81 ui::CompositorTestSupport::Initialize(); | 82 ui::CompositorTestSupport::Initialize(); |
| 82 #if defined(USE_AURA) | 83 #if defined(USE_AURA) |
| 83 ash::Shell::CreateInstance(NULL); | 84 ash::Shell::CreateInstance(NULL); |
| 85 // The shell runs with a locked screen in tests, so we must clear the event |
| 86 // client so it doesn't interfere with event propagation. |
| 87 aura::client::SetEventClient(ash::Shell::GetInstance()->GetRootWindow(), |
| 88 NULL); |
| 84 #endif | 89 #endif |
| 85 window_ = views::Widget::CreateWindow(this); | 90 window_ = views::Widget::CreateWindow(this); |
| 86 } | 91 } |
| 87 | 92 |
| 88 void ViewEventTestBase::TearDown() { | 93 void ViewEventTestBase::TearDown() { |
| 89 if (window_) { | 94 if (window_) { |
| 90 #if defined(OS_WIN) && !defined(USE_AURA) | 95 #if defined(OS_WIN) && !defined(USE_AURA) |
| 91 DestroyWindow(window_->GetNativeWindow()); | 96 DestroyWindow(window_->GetNativeWindow()); |
| 92 #else | 97 #else |
| 93 window_->Close(); | 98 window_->Close(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 dnd_thread_.reset(NULL); | 173 dnd_thread_.reset(NULL); |
| 169 } | 174 } |
| 170 | 175 |
| 171 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 176 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
| 172 StopBackgroundThread(); | 177 StopBackgroundThread(); |
| 173 | 178 |
| 174 task.Run(); | 179 task.Run(); |
| 175 if (HasFatalFailure()) | 180 if (HasFatalFailure()) |
| 176 Done(); | 181 Done(); |
| 177 } | 182 } |
| OLD | NEW |