| 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 "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "ui/aura/client/cursor_client.h" | 11 #include "ui/aura/client/cursor_client.h" |
| 12 #include "ui/aura/mus/in_flight_change.h" |
| 12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/views/mus/mus_client_test_observer.h" |
| 15 #include "ui/views/mus/test_utils.h" |
| 13 #include "ui/views/test/views_test_base.h" | 16 #include "ui/views/test/views_test_base.h" |
| 14 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 15 #include "ui/views/widget/widget_delegate.h" | 18 #include "ui/views/widget/widget_delegate.h" |
| 16 #include "ui/views/widget/widget_observer.h" | 19 #include "ui/views/widget/widget_observer.h" |
| 17 | 20 |
| 18 namespace views { | 21 namespace views { |
| 19 | 22 |
| 20 class DesktopWindowTreeHostMusTest : public ViewsTestBase, | 23 class DesktopWindowTreeHostMusTest : public ViewsTestBase, |
| 21 public WidgetObserver { | 24 public WidgetObserver { |
| 22 public: | 25 public: |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 aura::client::GetCursorClient(window->GetRootWindow()); | 98 aura::client::GetCursorClient(window->GetRootWindow()); |
| 96 EXPECT_FALSE(cursor_client); | 99 EXPECT_FALSE(cursor_client); |
| 97 window_->RemoveObserver(this); | 100 window_->RemoveObserver(this); |
| 98 window_ = nullptr; | 101 window_ = nullptr; |
| 99 } | 102 } |
| 100 | 103 |
| 101 aura::Window* window_; | 104 aura::Window* window_; |
| 102 DISALLOW_COPY_AND_ASSIGN(ExpectsNullCursorClientDuringTearDown); | 105 DISALLOW_COPY_AND_ASSIGN(ExpectsNullCursorClientDuringTearDown); |
| 103 }; | 106 }; |
| 104 | 107 |
| 108 class WaitForChangeCompletor : public test::MusClientTestObserver { |
| 109 public: |
| 110 WaitForChangeCompletor(aura::ChangeType type, |
| 111 bool success) |
| 112 : type_(type), |
| 113 success_(success), |
| 114 received_(false) { |
| 115 test::MusClientTestApi::SetChangeTestObserver(this); |
| 116 } |
| 117 |
| 118 ~WaitForChangeCompletor() override { |
| 119 test::MusClientTestApi::SetChangeTestObserver(nullptr); |
| 120 } |
| 121 |
| 122 void Wait() { |
| 123 if (!received_) { |
| 124 quit_closure_ = run_loop_.QuitClosure(); |
| 125 run_loop_.Run(); |
| 126 } |
| 127 } |
| 128 |
| 129 private: |
| 130 // test::MusClientTestObserver: |
| 131 void OnChangeCompleted(aura::ChangeType type, bool success) override { |
| 132 if (type == type_ && success == success_) { |
| 133 received_ = true; |
| 134 if (quit_closure_) |
| 135 quit_closure_.Run(); |
| 136 } |
| 137 } |
| 138 |
| 139 base::RunLoop run_loop_; |
| 140 aura::ChangeType type_; |
| 141 bool success_; |
| 142 bool received_; |
| 143 base::Closure quit_closure_; |
| 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(WaitForChangeCompletor); |
| 146 }; |
| 147 |
| 105 TEST_F(DesktopWindowTreeHostMusTest, Visibility) { | 148 TEST_F(DesktopWindowTreeHostMusTest, Visibility) { |
| 106 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); | 149 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
| 107 EXPECT_FALSE(widget->IsVisible()); | 150 EXPECT_FALSE(widget->IsVisible()); |
| 108 EXPECT_FALSE(widget->GetNativeView()->IsVisible()); | 151 EXPECT_FALSE(widget->GetNativeView()->IsVisible()); |
| 109 // It's important the parent is also hidden as this value is sent to the | 152 // It's important the parent is also hidden as this value is sent to the |
| 110 // server. | 153 // server. |
| 111 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible()); | 154 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible()); |
| 112 widget->Show(); | 155 widget->Show(); |
| 113 EXPECT_TRUE(widget->IsVisible()); | 156 EXPECT_TRUE(widget->IsVisible()); |
| 114 EXPECT_TRUE(widget->GetNativeView()->IsVisible()); | 157 EXPECT_TRUE(widget->GetNativeView()->IsVisible()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 140 widget->Show(); | 183 widget->Show(); |
| 141 | 184 |
| 142 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); | 185 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); |
| 143 window->Init(ui::LAYER_SOLID_COLOR); | 186 window->Init(ui::LAYER_SOLID_COLOR); |
| 144 ExpectsNullCursorClientDuringTearDown observer(window.get()); | 187 ExpectsNullCursorClientDuringTearDown observer(window.get()); |
| 145 | 188 |
| 146 widget->GetNativeWindow()->AddChild(window.release()); | 189 widget->GetNativeWindow()->AddChild(window.release()); |
| 147 widget.reset(); | 190 widget.reset(); |
| 148 } | 191 } |
| 149 | 192 |
| 193 TEST_F(DesktopWindowTreeHostMusTest, StackAtTop) { |
| 194 std::unique_ptr<Widget> widget1(CreateWidget(nullptr)); |
| 195 widget1->Show(); |
| 196 |
| 197 std::unique_ptr<Widget> widget2(CreateWidget(nullptr)); |
| 198 widget2->Show(); |
| 199 |
| 200 WaitForChangeCompletor waiter(aura::ChangeType::REORDER, true); |
| 201 widget1->StackAtTop(); |
| 202 waiter.Wait(); |
| 203 |
| 204 // Other than the signal that our StackAtTop() succeeded, we don't have any |
| 205 // pieces of public data that we can check. If we actually stopped waiting, |
| 206 // count that as success. |
| 207 } |
| 208 |
| 209 TEST_F(DesktopWindowTreeHostMusTest, StackAtTopAlreadyOnTop) { |
| 210 std::unique_ptr<Widget> widget1(CreateWidget(nullptr)); |
| 211 widget1->Show(); |
| 212 |
| 213 std::unique_ptr<Widget> widget2(CreateWidget(nullptr)); |
| 214 widget2->Show(); |
| 215 |
| 216 WaitForChangeCompletor waiter(aura::ChangeType::REORDER, true); |
| 217 widget2->StackAtTop(); |
| 218 waiter.Wait(); |
| 219 } |
| 220 |
| 150 } // namespace views | 221 } // namespace views |
| OLD | NEW |