| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/views/mus/desktop_window_tree_host_mus.h" | 5 #include "ui/views/mus/desktop_window_tree_host_mus.h" |
| 6 | 6 |
| 7 #include "base/debug/stack_trace.h" | 7 #include "base/debug/stack_trace.h" |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "ui/aura/client/cursor_client.h" | 10 #include "ui/aura/client/cursor_client.h" |
| 11 #include "ui/aura/client/focus_client.h" |
| 11 #include "ui/aura/client/transient_window_client.h" | 12 #include "ui/aura/client/transient_window_client.h" |
| 13 #include "ui/aura/env.h" |
| 12 #include "ui/aura/mus/capture_synchronizer.h" | 14 #include "ui/aura/mus/capture_synchronizer.h" |
| 13 #include "ui/aura/mus/in_flight_change.h" | 15 #include "ui/aura/mus/in_flight_change.h" |
| 14 #include "ui/aura/mus/window_mus.h" | 16 #include "ui/aura/mus/window_mus.h" |
| 15 #include "ui/aura/mus/window_tree_client.h" | 17 #include "ui/aura/mus/window_tree_client.h" |
| 16 #include "ui/aura/test/mus/change_completion_waiter.h" | 18 #include "ui/aura/test/mus/change_completion_waiter.h" |
| 17 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 18 #include "ui/views/mus/mus_client.h" | 20 #include "ui/views/mus/mus_client.h" |
| 19 #include "ui/views/test/views_test_base.h" | 21 #include "ui/views/test/views_test_base.h" |
| 20 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 21 #include "ui/views/widget/widget_delegate.h" | 23 #include "ui/views/widget/widget_delegate.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 174 } |
| 173 | 175 |
| 174 TEST_F(DesktopWindowTreeHostMusTest, Deactivate) { | 176 TEST_F(DesktopWindowTreeHostMusTest, Deactivate) { |
| 175 std::unique_ptr<Widget> widget1(CreateWidget()); | 177 std::unique_ptr<Widget> widget1(CreateWidget()); |
| 176 widget1->Show(); | 178 widget1->Show(); |
| 177 | 179 |
| 178 std::unique_ptr<Widget> widget2(CreateWidget()); | 180 std::unique_ptr<Widget> widget2(CreateWidget()); |
| 179 widget2->Show(); | 181 widget2->Show(); |
| 180 | 182 |
| 181 widget1->Activate(); | 183 widget1->Activate(); |
| 184 EXPECT_TRUE(widget1->GetNativeWindow()->HasFocus()); |
| 185 |
| 182 RunPendingMessages(); | 186 RunPendingMessages(); |
| 183 EXPECT_TRUE(widget1->IsActive()); | 187 EXPECT_TRUE(widget1->IsActive()); |
| 188 EXPECT_TRUE(widget1->GetNativeWindow()->HasFocus()); |
| 184 EXPECT_EQ(widget_activated(), widget1.get()); | 189 EXPECT_EQ(widget_activated(), widget1.get()); |
| 185 | 190 |
| 186 DeactivateAndWait(widget1.get()); | 191 DeactivateAndWait(widget1.get()); |
| 187 EXPECT_FALSE(widget1->IsActive()); | 192 EXPECT_FALSE(widget1->IsActive()); |
| 188 } | 193 } |
| 189 | 194 |
| 195 TEST_F(DesktopWindowTreeHostMusTest, ActivateBeforeShow) { |
| 196 std::unique_ptr<Widget> widget1(CreateWidget()); |
| 197 // Activation can be attempted before visible. |
| 198 widget1->Activate(); |
| 199 widget1->Show(); |
| 200 widget1->Activate(); |
| 201 EXPECT_TRUE(widget1->IsActive()); |
| 202 // The Widget's NativeWindow (|DesktopNativeWidgetAura::content_window_|) |
| 203 // should be active. |
| 204 EXPECT_TRUE(widget1->GetNativeWindow()->HasFocus()); |
| 205 // Env's active FocusClient should match the active window. |
| 206 aura::client::FocusClient* widget_focus_client = |
| 207 aura::client::GetFocusClient(widget1->GetNativeWindow()); |
| 208 ASSERT_TRUE(widget_focus_client); |
| 209 EXPECT_EQ(widget_focus_client, |
| 210 aura::Env::GetInstance()->active_focus_client()); |
| 211 } |
| 212 |
| 190 TEST_F(DesktopWindowTreeHostMusTest, CursorClientDuringTearDown) { | 213 TEST_F(DesktopWindowTreeHostMusTest, CursorClientDuringTearDown) { |
| 191 std::unique_ptr<Widget> widget(CreateWidget()); | 214 std::unique_ptr<Widget> widget(CreateWidget()); |
| 192 widget->Show(); | 215 widget->Show(); |
| 193 | 216 |
| 194 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); | 217 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); |
| 195 window->Init(ui::LAYER_SOLID_COLOR); | 218 window->Init(ui::LAYER_SOLID_COLOR); |
| 196 ExpectsNullCursorClientDuringTearDown observer(window.get()); | 219 ExpectsNullCursorClientDuringTearDown observer(window.get()); |
| 197 | 220 |
| 198 widget->GetNativeWindow()->AddChild(window.release()); | 221 widget->GetNativeWindow()->AddChild(window.release()); |
| 199 widget.reset(); | 222 widget.reset(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 aura::client::TransientWindowClient* transient_window_client = | 279 aura::client::TransientWindowClient* transient_window_client = |
| 257 aura::client::GetTransientWindowClient(); | 280 aura::client::GetTransientWindowClient(); |
| 258 // Even though the widget1->GetNativeView() was specified as the parent we | 281 // Even though the widget1->GetNativeView() was specified as the parent we |
| 259 // expect the transient parents to be marked at the host level. | 282 // expect the transient parents to be marked at the host level. |
| 260 EXPECT_EQ(widget1->GetNativeView()->GetHost()->window(), | 283 EXPECT_EQ(widget1->GetNativeView()->GetHost()->window(), |
| 261 transient_window_client->GetTransientParent( | 284 transient_window_client->GetTransientParent( |
| 262 widget2->GetNativeView()->GetHost()->window())); | 285 widget2->GetNativeView()->GetHost()->window())); |
| 263 } | 286 } |
| 264 | 287 |
| 265 } // namespace views | 288 } // namespace views |
| OLD | NEW |