| 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/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "ui/aura/client/default_capture_client.h" | 10 #include "ui/aura/client/default_capture_client.h" |
| 11 #include "ui/aura/client/focus_client.h" | 11 #include "ui/aura/client/focus_client.h" |
| 12 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
| 13 #include "ui/aura/input_state_lookup.h" | 13 #include "ui/aura/input_state_lookup.h" |
| 14 #include "ui/aura/mus/capture_synchronizer.h" | 14 #include "ui/aura/mus/capture_synchronizer.h" |
| 15 #include "ui/aura/mus/focus_synchronizer.h" |
| 15 #include "ui/aura/mus/window_port_mus.h" | 16 #include "ui/aura/mus/window_port_mus.h" |
| 16 #include "ui/aura/mus/window_tree_client.h" | 17 #include "ui/aura/mus/window_tree_client.h" |
| 17 #include "ui/aura/test/env_test_helper.h" | 18 #include "ui/aura/test/env_test_helper.h" |
| 18 #include "ui/aura/test/event_generator_delegate_aura.h" | 19 #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.h" |
| 20 #include "ui/aura/test/mus/test_window_tree_client_setup.h" | 21 #include "ui/aura/test/mus/test_window_tree_client_setup.h" |
| 21 #include "ui/aura/test/test_focus_client.h" | 22 #include "ui/aura/test/test_focus_client.h" |
| 22 #include "ui/aura/test/test_screen.h" | 23 #include "ui/aura/test/test_screen.h" |
| 23 #include "ui/aura/test/test_window_parenting_client.h" | 24 #include "ui/aura/test/test_window_parenting_client.h" |
| 24 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (!Env::GetInstanceDontCreate()) | 106 if (!Env::GetInstanceDontCreate()) |
| 106 env_ = Env::CreateInstance(env_mode); | 107 env_ = Env::CreateInstance(env_mode); |
| 107 EnvTestHelper env_helper; | 108 EnvTestHelper env_helper; |
| 108 // Always reset the mode. This really only matters for if Env was created | 109 // Always reset the mode. This really only matters for if Env was created |
| 109 // above. | 110 // above. |
| 110 env_helper.SetMode(env_mode); | 111 env_helper.SetMode(env_mode); |
| 111 env_helper.SetWindowTreeClient(window_tree_client_); | 112 env_helper.SetWindowTreeClient(window_tree_client_); |
| 112 // Tests assume they can set the mouse location on Env() and have it reflected | 113 // Tests assume they can set the mouse location on Env() and have it reflected |
| 113 // in tests. | 114 // in tests. |
| 114 env_helper.SetAlwaysUseLastMouseLocation(true); | 115 env_helper.SetAlwaysUseLastMouseLocation(true); |
| 115 Env::GetInstance()->SetActiveFocusClient(focus_client_.get(), nullptr); | |
| 116 Env::GetInstance()->set_context_factory(context_factory); | 116 Env::GetInstance()->set_context_factory(context_factory); |
| 117 Env::GetInstance()->set_context_factory_private(context_factory_private); | 117 Env::GetInstance()->set_context_factory_private(context_factory_private); |
| 118 // Unit tests generally don't want to query the system, rather use the state | 118 // Unit tests generally don't want to query the system, rather use the state |
| 119 // from RootWindow. | 119 // from RootWindow. |
| 120 env_helper.SetInputStateLookup(nullptr); | 120 env_helper.SetInputStateLookup(nullptr); |
| 121 env_helper.ResetEventState(); | 121 env_helper.ResetEventState(); |
| 122 | 122 |
| 123 ui::InitializeInputMethodForTesting(); | 123 ui::InitializeInputMethodForTesting(); |
| 124 | 124 |
| 125 display::Screen* screen = display::Screen::GetScreen(); | 125 display::Screen* screen = display::Screen::GetScreen(); |
| 126 gfx::Size host_size(screen ? screen->GetPrimaryDisplay().GetSizeInPixel() | 126 gfx::Size host_size(screen ? screen->GetPrimaryDisplay().GetSizeInPixel() |
| 127 : gfx::Size(800, 600)); | 127 : gfx::Size(800, 600)); |
| 128 // TODO(sky): creating the screen and host should not happen for mus. | 128 // TODO(sky): creating the screen and host should not happen for mus. |
| 129 test_screen_.reset(TestScreen::Create(host_size)); | 129 test_screen_.reset(TestScreen::Create(host_size)); |
| 130 if (!screen) | 130 if (!screen) |
| 131 display::Screen::SetScreenInstance(test_screen_.get()); | 131 display::Screen::SetScreenInstance(test_screen_.get()); |
| 132 host_.reset(test_screen_->CreateHostForPrimaryDisplay()); | 132 host_.reset(test_screen_->CreateHostForPrimaryDisplay()); |
| 133 host_->window()->SetEventTargeter( | 133 host_->window()->SetEventTargeter( |
| 134 std::unique_ptr<ui::EventTargeter>(new WindowTargeter())); | 134 std::unique_ptr<ui::EventTargeter>(new WindowTargeter())); |
| 135 | 135 |
| 136 client::SetFocusClient(root_window(), focus_client_.get()); | 136 client::SetFocusClient(root_window(), focus_client_.get()); |
| 137 client::SetCaptureClient(root_window(), capture_client()); | 137 client::SetCaptureClient(root_window(), capture_client()); |
| 138 parenting_client_.reset(new TestWindowParentingClient(root_window())); | 138 parenting_client_.reset(new TestWindowParentingClient(root_window())); |
| 139 | 139 |
| 140 root_window()->Show(); | 140 root_window()->Show(); |
| 141 // Ensure width != height so tests won't confuse them. | 141 // Ensure width != height so tests won't confuse them. |
| 142 host()->SetBoundsInPixels(gfx::Rect(host_size)); | 142 host()->SetBoundsInPixels(gfx::Rect(host_size)); |
| 143 | 143 |
| 144 if (mode_ == Mode::MUS_CREATE_WINDOW_TREE_CLIENT) | 144 if (mode_ == Mode::MUS_CREATE_WINDOW_TREE_CLIENT) { |
| 145 window_tree_client_->focus_synchronizer()->SetActiveFocusClient( |
| 146 focus_client_.get(), root_window()); |
| 145 window_tree()->AckAllChanges(); | 147 window_tree()->AckAllChanges(); |
| 148 } |
| 146 | 149 |
| 147 g_instance = this; | 150 g_instance = this; |
| 148 } | 151 } |
| 149 | 152 |
| 150 void AuraTestHelper::TearDown() { | 153 void AuraTestHelper::TearDown() { |
| 151 g_instance = nullptr; | 154 g_instance = nullptr; |
| 152 teardown_called_ = true; | 155 teardown_called_ = true; |
| 153 parenting_client_.reset(); | 156 parenting_client_.reset(); |
| 154 client::SetFocusClient(root_window(), nullptr); | 157 client::SetFocusClient(root_window(), nullptr); |
| 155 client::SetCaptureClient(root_window(), nullptr); | 158 client::SetCaptureClient(root_window(), nullptr); |
| 156 host_.reset(); | 159 host_.reset(); |
| 157 ui::GestureRecognizer::Reset(); | 160 ui::GestureRecognizer::Reset(); |
| 158 if (display::Screen::GetScreen() == test_screen_.get()) | 161 if (display::Screen::GetScreen() == test_screen_.get()) |
| 159 display::Screen::SetScreenInstance(nullptr); | 162 display::Screen::SetScreenInstance(nullptr); |
| 160 test_screen_.reset(); | 163 test_screen_.reset(); |
| 161 | 164 |
| 162 Env::GetInstance()->SetActiveFocusClient(nullptr, nullptr); | |
| 163 window_tree_client_setup_.reset(); | 165 window_tree_client_setup_.reset(); |
| 164 focus_client_.reset(); | 166 focus_client_.reset(); |
| 165 capture_client_.reset(); | 167 capture_client_.reset(); |
| 166 | 168 |
| 167 ui::ShutdownInputMethodForTesting(); | 169 ui::ShutdownInputMethodForTesting(); |
| 168 | 170 |
| 169 if (env_) | 171 if (env_) |
| 170 env_.reset(); | 172 env_.reset(); |
| 171 else | 173 else |
| 172 EnvTestHelper().SetWindowTreeClient(nullptr); | 174 EnvTestHelper().SetWindowTreeClient(nullptr); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 196 window_tree_client_setup_ = base::MakeUnique<TestWindowTreeClientSetup>(); | 198 window_tree_client_setup_ = base::MakeUnique<TestWindowTreeClientSetup>(); |
| 197 window_tree_client_setup_->InitForWindowManager(window_tree_delegate_, | 199 window_tree_client_setup_->InitForWindowManager(window_tree_delegate_, |
| 198 window_manager_delegate_); | 200 window_manager_delegate_); |
| 199 window_tree_client_ = window_tree_client_setup_->window_tree_client(); | 201 window_tree_client_ = window_tree_client_setup_->window_tree_client(); |
| 200 window_tree_client_->capture_synchronizer()->AttachToCaptureClient( | 202 window_tree_client_->capture_synchronizer()->AttachToCaptureClient( |
| 201 capture_client_.get()); | 203 capture_client_.get()); |
| 202 } | 204 } |
| 203 | 205 |
| 204 } // namespace test | 206 } // namespace test |
| 205 } // namespace aura | 207 } // namespace aura |
| OLD | NEW |