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/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ui/aura/client/cursor_client.h" |
8 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
9 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
10 #include "ui/views/widget/widget.h" | 11 #include "ui/views/widget/widget.h" |
11 #include "ui/views/widget/widget_delegate.h" | 12 #include "ui/views/widget/widget_delegate.h" |
12 | 13 |
13 namespace views { | 14 namespace views { |
14 | 15 |
15 class DesktopWindowTreeHostMusTest : public ViewsTestBase { | 16 class DesktopWindowTreeHostMusTest : public ViewsTestBase { |
16 public: | 17 public: |
17 DesktopWindowTreeHostMusTest() {} | 18 DesktopWindowTreeHostMusTest() {} |
18 ~DesktopWindowTreeHostMusTest() override {} | 19 ~DesktopWindowTreeHostMusTest() override {} |
19 | 20 |
20 // Creates a test widget. Takes ownership of |delegate|. | 21 // Creates a test widget. Takes ownership of |delegate|. |
21 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { | 22 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { |
22 std::unique_ptr<Widget> widget = base::MakeUnique<Widget>(); | 23 std::unique_ptr<Widget> widget = base::MakeUnique<Widget>(); |
23 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 24 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
24 params.delegate = delegate; | 25 params.delegate = delegate; |
25 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 26 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
26 params.bounds = gfx::Rect(0, 1, 111, 123); | 27 params.bounds = gfx::Rect(0, 1, 111, 123); |
27 widget->Init(params); | 28 widget->Init(params); |
28 return widget; | 29 return widget; |
29 } | 30 } |
30 | 31 |
31 private: | 32 private: |
32 DISALLOW_COPY_AND_ASSIGN(DesktopWindowTreeHostMusTest); | 33 DISALLOW_COPY_AND_ASSIGN(DesktopWindowTreeHostMusTest); |
33 }; | 34 }; |
34 | 35 |
| 36 class ExpectsNullCursorClientDuringTearDown : public aura::WindowObserver { |
| 37 public: |
| 38 explicit ExpectsNullCursorClientDuringTearDown(aura::Window* window) |
| 39 : window_(window) { |
| 40 window_->AddObserver(this); |
| 41 } |
| 42 |
| 43 ~ExpectsNullCursorClientDuringTearDown() override { |
| 44 EXPECT_FALSE(window_); |
| 45 } |
| 46 |
| 47 private: |
| 48 // aura::WindowObserver: |
| 49 void OnWindowRemovingFromRootWindow(aura::Window* window, |
| 50 aura::Window* new_root) override { |
| 51 aura::client::CursorClient* cursor_client = |
| 52 aura::client::GetCursorClient(window->GetRootWindow()); |
| 53 EXPECT_FALSE(cursor_client); |
| 54 window_->RemoveObserver(this); |
| 55 window_ = nullptr; |
| 56 } |
| 57 |
| 58 aura::Window* window_; |
| 59 DISALLOW_COPY_AND_ASSIGN(ExpectsNullCursorClientDuringTearDown); |
| 60 }; |
| 61 |
35 TEST_F(DesktopWindowTreeHostMusTest, Visibility) { | 62 TEST_F(DesktopWindowTreeHostMusTest, Visibility) { |
36 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); | 63 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
37 EXPECT_FALSE(widget->IsVisible()); | 64 EXPECT_FALSE(widget->IsVisible()); |
38 EXPECT_FALSE(widget->GetNativeView()->IsVisible()); | 65 EXPECT_FALSE(widget->GetNativeView()->IsVisible()); |
39 // It's important the parent is also hidden as this value is sent to the | 66 // It's important the parent is also hidden as this value is sent to the |
40 // server. | 67 // server. |
41 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible()); | 68 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible()); |
42 widget->Show(); | 69 widget->Show(); |
43 EXPECT_TRUE(widget->IsVisible()); | 70 EXPECT_TRUE(widget->IsVisible()); |
44 EXPECT_TRUE(widget->GetNativeView()->IsVisible()); | 71 EXPECT_TRUE(widget->GetNativeView()->IsVisible()); |
45 EXPECT_TRUE(widget->GetNativeView()->parent()->IsVisible()); | 72 EXPECT_TRUE(widget->GetNativeView()->parent()->IsVisible()); |
46 widget->Hide(); | 73 widget->Hide(); |
47 EXPECT_FALSE(widget->IsVisible()); | 74 EXPECT_FALSE(widget->IsVisible()); |
48 EXPECT_FALSE(widget->GetNativeView()->IsVisible()); | 75 EXPECT_FALSE(widget->GetNativeView()->IsVisible()); |
49 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible()); | 76 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible()); |
50 } | 77 } |
51 | 78 |
| 79 TEST_F(DesktopWindowTreeHostMusTest, CursorClientDuringTearDown) { |
| 80 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
| 81 widget->Show(); |
| 82 |
| 83 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); |
| 84 window->Init(ui::LAYER_SOLID_COLOR); |
| 85 ExpectsNullCursorClientDuringTearDown observer(window.get()); |
| 86 |
| 87 widget->GetNativeWindow()->AddChild(window.release()); |
| 88 widget.reset(); |
| 89 } |
| 90 |
52 } // namespace views | 91 } // namespace views |
OLD | NEW |