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 "ui/aura/test/aura_test_helper.h" | 5 #include "ui/aura/test/aura_test_helper.h" |
6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" |
7 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
8 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
9 #include "ui/aura/client/default_capture_client.h" | 11 #include "ui/aura/client/default_capture_client.h" |
10 #include "ui/aura/client/focus_client.h" | 12 #include "ui/aura/client/focus_client.h" |
11 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
12 #include "ui/aura/input_state_lookup.h" | 14 #include "ui/aura/input_state_lookup.h" |
| 15 #include "ui/aura/mus/window_port_mus.h" |
| 16 #include "ui/aura/mus/window_tree_client.h" |
13 #include "ui/aura/test/env_test_helper.h" | 17 #include "ui/aura/test/env_test_helper.h" |
14 #include "ui/aura/test/event_generator_delegate_aura.h" | 18 #include "ui/aura/test/event_generator_delegate_aura.h" |
| 19 #include "ui/aura/test/mus/test_window_tree.h" |
| 20 #include "ui/aura/test/mus/test_window_tree_client_setup.h" |
15 #include "ui/aura/test/test_focus_client.h" | 21 #include "ui/aura/test/test_focus_client.h" |
16 #include "ui/aura/test/test_screen.h" | 22 #include "ui/aura/test/test_screen.h" |
17 #include "ui/aura/test/test_window_parenting_client.h" | 23 #include "ui/aura/test/test_window_parenting_client.h" |
18 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
19 #include "ui/aura/window_event_dispatcher.h" | 25 #include "ui/aura/window_event_dispatcher.h" |
20 #include "ui/base/ime/input_method_factory.h" | 26 #include "ui/base/ime/input_method_factory.h" |
21 #include "ui/base/ime/input_method_initializer.h" | 27 #include "ui/base/ime/input_method_initializer.h" |
22 #include "ui/compositor/compositor.h" | 28 #include "ui/compositor/compositor.h" |
23 #include "ui/compositor/layer_animator.h" | 29 #include "ui/compositor/layer_animator.h" |
24 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 30 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
(...skipping 21 matching lines...) Expand all Loading... |
46 InitializeAuraEventGeneratorDelegate(); | 52 InitializeAuraEventGeneratorDelegate(); |
47 } | 53 } |
48 | 54 |
49 AuraTestHelper::~AuraTestHelper() { | 55 AuraTestHelper::~AuraTestHelper() { |
50 CHECK(setup_called_) | 56 CHECK(setup_called_) |
51 << "AuraTestHelper::SetUp() never called."; | 57 << "AuraTestHelper::SetUp() never called."; |
52 CHECK(teardown_called_) | 58 CHECK(teardown_called_) |
53 << "AuraTestHelper::TearDown() never called."; | 59 << "AuraTestHelper::TearDown() never called."; |
54 } | 60 } |
55 | 61 |
| 62 void AuraTestHelper::EnableMus(WindowTreeClientDelegate* window_tree_delegate, |
| 63 WindowManagerDelegate* window_manager_delegate) { |
| 64 DCHECK(!setup_called_); |
| 65 use_mus_ = true; |
| 66 window_tree_delegate_ = window_tree_delegate; |
| 67 window_manager_delegate_ = window_manager_delegate; |
| 68 } |
| 69 |
56 void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) { | 70 void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) { |
57 setup_called_ = true; | 71 setup_called_ = true; |
58 | 72 |
| 73 // Needs to be before creating WindowTreeClient. |
| 74 focus_client_ = base::MakeUnique<TestFocusClient>(); |
| 75 capture_client_ = base::MakeUnique<client::DefaultCaptureClient>(); |
| 76 Env::WindowPortFactory window_impl_factory; |
| 77 if (use_mus_) |
| 78 window_impl_factory = InitMus(); |
59 if (!Env::GetInstanceDontCreate()) | 79 if (!Env::GetInstanceDontCreate()) |
60 env_ = aura::Env::CreateInstance(); | 80 env_ = aura::Env::CreateInstance(window_impl_factory); |
| 81 else if (use_mus_) |
| 82 EnvTestHelper(Env::GetInstance()).SetWindowPortFactory(window_impl_factory); |
61 Env::GetInstance()->set_context_factory(context_factory); | 83 Env::GetInstance()->set_context_factory(context_factory); |
62 // Unit tests generally don't want to query the system, rather use the state | 84 // Unit tests generally don't want to query the system, rather use the state |
63 // from RootWindow. | 85 // from RootWindow. |
64 EnvTestHelper env_helper(Env::GetInstance()); | 86 EnvTestHelper env_helper(Env::GetInstance()); |
65 env_helper.SetInputStateLookup(nullptr); | 87 env_helper.SetInputStateLookup(nullptr); |
66 env_helper.ResetEventState(); | 88 env_helper.ResetEventState(); |
67 | 89 |
68 ui::InitializeInputMethodForTesting(); | 90 ui::InitializeInputMethodForTesting(); |
69 | 91 |
70 display::Screen* screen = display::Screen::GetScreen(); | 92 display::Screen* screen = display::Screen::GetScreen(); |
71 gfx::Size host_size(screen ? screen->GetPrimaryDisplay().GetSizeInPixel() | 93 gfx::Size host_size(screen ? screen->GetPrimaryDisplay().GetSizeInPixel() |
72 : gfx::Size(800, 600)); | 94 : gfx::Size(800, 600)); |
| 95 // TODO(sky): creating the screen and host should not happen for mus. |
73 test_screen_.reset(TestScreen::Create(host_size)); | 96 test_screen_.reset(TestScreen::Create(host_size)); |
74 if (!screen) | 97 if (!screen) |
75 display::Screen::SetScreenInstance(test_screen_.get()); | 98 display::Screen::SetScreenInstance(test_screen_.get()); |
76 host_.reset(test_screen_->CreateHostForPrimaryDisplay()); | 99 host_.reset(test_screen_->CreateHostForPrimaryDisplay()); |
77 | 100 |
78 focus_client_.reset(new TestFocusClient); | |
79 client::SetFocusClient(root_window(), focus_client_.get()); | 101 client::SetFocusClient(root_window(), focus_client_.get()); |
| 102 client::SetCaptureClient(root_window(), capture_client()); |
80 parenting_client_.reset(new TestWindowParentingClient(root_window())); | 103 parenting_client_.reset(new TestWindowParentingClient(root_window())); |
81 capture_client_.reset(new client::DefaultCaptureClient(root_window())); | |
82 | 104 |
83 root_window()->Show(); | 105 root_window()->Show(); |
84 // Ensure width != height so tests won't confuse them. | 106 // Ensure width != height so tests won't confuse them. |
85 host()->SetBounds(gfx::Rect(host_size)); | 107 host()->SetBounds(gfx::Rect(host_size)); |
| 108 |
| 109 if (use_mus_) |
| 110 window_tree()->AckAllChanges(); |
86 } | 111 } |
87 | 112 |
88 void AuraTestHelper::TearDown() { | 113 void AuraTestHelper::TearDown() { |
89 teardown_called_ = true; | 114 teardown_called_ = true; |
90 parenting_client_.reset(); | 115 parenting_client_.reset(); |
91 capture_client_.reset(); | |
92 focus_client_.reset(); | |
93 client::SetFocusClient(root_window(), nullptr); | 116 client::SetFocusClient(root_window(), nullptr); |
| 117 client::SetCaptureClient(root_window(), nullptr); |
94 host_.reset(); | 118 host_.reset(); |
95 ui::GestureRecognizer::Reset(); | 119 ui::GestureRecognizer::Reset(); |
96 if (display::Screen::GetScreen() == test_screen_.get()) | 120 if (display::Screen::GetScreen() == test_screen_.get()) |
97 display::Screen::SetScreenInstance(nullptr); | 121 display::Screen::SetScreenInstance(nullptr); |
98 test_screen_.reset(); | 122 test_screen_.reset(); |
99 | 123 |
100 #if defined(USE_X11) | 124 #if defined(USE_X11) |
101 ui::test::ResetXCursorCache(); | 125 ui::test::ResetXCursorCache(); |
102 #endif | 126 #endif |
103 | 127 |
| 128 window_tree_client_setup_.reset(); |
| 129 focus_client_.reset(); |
| 130 capture_client_.reset(); |
| 131 |
104 ui::ShutdownInputMethodForTesting(); | 132 ui::ShutdownInputMethodForTesting(); |
105 | 133 |
106 env_.reset(); | 134 if (env_) { |
| 135 env_.reset(); |
| 136 } else if (use_mus_) { |
| 137 EnvTestHelper(Env::GetInstance()) |
| 138 .SetWindowPortFactory(Env::WindowPortFactory()); |
| 139 } |
107 } | 140 } |
108 | 141 |
109 void AuraTestHelper::RunAllPendingInMessageLoop() { | 142 void AuraTestHelper::RunAllPendingInMessageLoop() { |
110 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them | 143 // TODO(jbates) crbug.com/134753 Find quitters of this RunLoop and have them |
111 // use run_loop.QuitClosure(). | 144 // use run_loop.QuitClosure(). |
112 base::RunLoop run_loop; | 145 base::RunLoop run_loop; |
113 run_loop.RunUntilIdle(); | 146 run_loop.RunUntilIdle(); |
114 } | 147 } |
115 | 148 |
| 149 TestWindowTree* AuraTestHelper::window_tree() { |
| 150 return window_tree_client_setup_->window_tree(); |
| 151 } |
| 152 |
| 153 WindowTreeClient* AuraTestHelper::window_tree_client() { |
| 154 return window_tree_client_setup_->window_tree_client(); |
| 155 } |
| 156 |
| 157 client::CaptureClient* AuraTestHelper::capture_client() { |
| 158 return capture_client_.get(); |
| 159 } |
| 160 |
| 161 Env::WindowPortFactory AuraTestHelper::InitMus() { |
| 162 window_tree_client_setup_ = base::MakeUnique<TestWindowTreeClientSetup>(); |
| 163 window_tree_client_setup_->InitForWindowManager(window_tree_delegate_, |
| 164 window_manager_delegate_); |
| 165 return base::Bind(&AuraTestHelper::CreateWindowPortMus, |
| 166 base::Unretained(this)); |
| 167 } |
| 168 |
| 169 std::unique_ptr<WindowPort> AuraTestHelper::CreateWindowPortMus( |
| 170 Window* window) { |
| 171 return base::MakeUnique<WindowPortMus>(window_tree_client()); |
| 172 } |
| 173 |
116 } // namespace test | 174 } // namespace test |
117 } // namespace aura | 175 } // namespace aura |
OLD | NEW |