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_ASH) |
| 19 #include "ash/shell.h" |
| 20 #endif |
18 #if defined(USE_AURA) | 21 #if defined(USE_AURA) |
19 #include "ash/shell.h" | |
20 #include "ui/aura/client/event_client.h" | 22 #include "ui/aura/client/event_client.h" |
21 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
22 #include "ui/aura/root_window.h" | 24 #include "ui/aura/root_window.h" |
23 #endif | 25 #endif |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 // View subclass that allows you to specify the preferred size. | 29 // View subclass that allows you to specify the preferred size. |
28 class TestView : public views::View { | 30 class TestView : public views::View { |
29 public: | 31 public: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 76 |
75 // If we're in a nested message loop, as is the case with menus, we | 77 // If we're in a nested message loop, as is the case with menus, we |
76 // need to quit twice. The second quit does that for us. Finish all | 78 // need to quit twice. The second quit does that for us. Finish all |
77 // pending UI events before posting closure because events it may be | 79 // pending UI events before posting closure because events it may be |
78 // executed before UI events are executed. | 80 // executed before UI events are executed. |
79 ui_controls::RunClosureAfterAllPendingUIEvents(MessageLoop::QuitClosure()); | 81 ui_controls::RunClosureAfterAllPendingUIEvents(MessageLoop::QuitClosure()); |
80 } | 82 } |
81 | 83 |
82 void ViewEventTestBase::SetUp() { | 84 void ViewEventTestBase::SetUp() { |
83 ui::CompositorTestSupport::Initialize(); | 85 ui::CompositorTestSupport::Initialize(); |
84 #if defined(USE_AURA) | 86 #if defined(USE_ASH) |
85 ash::Shell::CreateInstance(NULL); | 87 ash::Shell::CreateInstance(NULL); |
86 // The shell runs with a locked screen in tests, so we must clear the event | 88 // The shell runs with a locked screen in tests, so we must clear the event |
87 // client so it doesn't interfere with event propagation. | 89 // client so it doesn't interfere with event propagation. |
88 aura::client::SetEventClient(ash::Shell::GetInstance()->GetRootWindow(), | 90 aura::client::SetEventClient(ash::Shell::GetInstance()->GetRootWindow(), |
89 NULL); | 91 NULL); |
90 #endif | 92 #endif |
91 window_ = views::Widget::CreateWindow(this); | 93 window_ = views::Widget::CreateWindow(this); |
92 } | 94 } |
93 | 95 |
94 void ViewEventTestBase::TearDown() { | 96 void ViewEventTestBase::TearDown() { |
95 if (window_) { | 97 if (window_) { |
96 #if defined(OS_WIN) && !defined(USE_AURA) | 98 #if defined(OS_WIN) && !defined(USE_AURA) |
97 DestroyWindow(window_->GetNativeWindow()); | 99 DestroyWindow(window_->GetNativeWindow()); |
98 #else | 100 #else |
99 window_->Close(); | 101 window_->Close(); |
100 ui_test_utils::RunAllPendingInMessageLoop(); | 102 ui_test_utils::RunAllPendingInMessageLoop(); |
101 #endif | 103 #endif |
102 window_ = NULL; | 104 window_ = NULL; |
103 } | 105 } |
| 106 #if defined(USE_ASH) |
| 107 ash::Shell::DeleteInstance(); |
| 108 #endif |
104 #if defined(USE_AURA) | 109 #if defined(USE_AURA) |
105 ash::Shell::DeleteInstance(); | |
106 aura::Env::DeleteInstance(); | 110 aura::Env::DeleteInstance(); |
107 #endif | 111 #endif |
108 ui::CompositorTestSupport::Terminate(); | 112 ui::CompositorTestSupport::Terminate(); |
109 } | 113 } |
110 | 114 |
111 bool ViewEventTestBase::CanResize() const { | 115 bool ViewEventTestBase::CanResize() const { |
112 return true; | 116 return true; |
113 } | 117 } |
114 | 118 |
115 views::View* ViewEventTestBase::GetContentsView() { | 119 views::View* ViewEventTestBase::GetContentsView() { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 dnd_thread_.reset(NULL); | 178 dnd_thread_.reset(NULL); |
175 } | 179 } |
176 | 180 |
177 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { | 181 void ViewEventTestBase::RunTestMethod(const base::Closure& task) { |
178 StopBackgroundThread(); | 182 StopBackgroundThread(); |
179 | 183 |
180 task.Run(); | 184 task.Run(); |
181 if (HasFatalFailure()) | 185 if (HasFatalFailure()) |
182 Done(); | 186 Done(); |
183 } | 187 } |
OLD | NEW |