Chromium Code Reviews| 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, bool success) | |
| 111 : type_(type), success_(success), received_(false) { | |
| 112 test::MusClientTestApi::SetChangeTestObserver(this); | |
| 113 } | |
| 114 | |
| 115 ~WaitForChangeCompletor() override { | |
| 116 test::MusClientTestApi::SetChangeTestObserver(nullptr); | |
| 117 } | |
| 118 | |
| 119 void Wait() { | |
| 120 if (!received_) { | |
| 121 quit_closure_ = run_loop_.QuitClosure(); | |
| 122 run_loop_.Run(); | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 private: | |
| 127 // test::MusClientTestObserver: | |
| 128 void OnChangeCompleted(aura::ChangeType type, bool success) override { | |
| 129 if (type == type_ && success == success_) { | |
|
sky
2017/01/20 16:36:10
One potential problem with this pattern is that if
Elliot Glaysher
2017/01/20 22:31:02
Moved this to ui/aura/test/mus/, and made it liste
| |
| 130 received_ = true; | |
| 131 if (quit_closure_) | |
| 132 quit_closure_.Run(); | |
| 133 } | |
| 134 } | |
| 135 | |
| 136 base::RunLoop run_loop_; | |
| 137 aura::ChangeType type_; | |
| 138 bool success_; | |
| 139 bool received_; | |
| 140 base::Closure quit_closure_; | |
| 141 | |
| 142 DISALLOW_COPY_AND_ASSIGN(WaitForChangeCompletor); | |
| 143 }; | |
| 144 | |
| 105 TEST_F(DesktopWindowTreeHostMusTest, Visibility) { | 145 TEST_F(DesktopWindowTreeHostMusTest, Visibility) { |
| 106 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); | 146 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
| 107 EXPECT_FALSE(widget->IsVisible()); | 147 EXPECT_FALSE(widget->IsVisible()); |
| 108 EXPECT_FALSE(widget->GetNativeView()->IsVisible()); | 148 EXPECT_FALSE(widget->GetNativeView()->IsVisible()); |
| 109 // It's important the parent is also hidden as this value is sent to the | 149 // It's important the parent is also hidden as this value is sent to the |
| 110 // server. | 150 // server. |
| 111 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible()); | 151 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible()); |
| 112 widget->Show(); | 152 widget->Show(); |
| 113 EXPECT_TRUE(widget->IsVisible()); | 153 EXPECT_TRUE(widget->IsVisible()); |
| 114 EXPECT_TRUE(widget->GetNativeView()->IsVisible()); | 154 EXPECT_TRUE(widget->GetNativeView()->IsVisible()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 140 widget->Show(); | 180 widget->Show(); |
| 141 | 181 |
| 142 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); | 182 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); |
| 143 window->Init(ui::LAYER_SOLID_COLOR); | 183 window->Init(ui::LAYER_SOLID_COLOR); |
| 144 ExpectsNullCursorClientDuringTearDown observer(window.get()); | 184 ExpectsNullCursorClientDuringTearDown observer(window.get()); |
| 145 | 185 |
| 146 widget->GetNativeWindow()->AddChild(window.release()); | 186 widget->GetNativeWindow()->AddChild(window.release()); |
| 147 widget.reset(); | 187 widget.reset(); |
| 148 } | 188 } |
| 149 | 189 |
| 190 TEST_F(DesktopWindowTreeHostMusTest, StackAtTop) { | |
| 191 std::unique_ptr<Widget> widget1(CreateWidget(nullptr)); | |
| 192 widget1->Show(); | |
| 193 | |
| 194 std::unique_ptr<Widget> widget2(CreateWidget(nullptr)); | |
| 195 widget2->Show(); | |
| 196 | |
| 197 WaitForChangeCompletor waiter(aura::ChangeType::REORDER, true); | |
| 198 widget1->StackAtTop(); | |
| 199 waiter.Wait(); | |
| 200 | |
| 201 // Other than the signal that our StackAtTop() succeeded, we don't have any | |
| 202 // pieces of public data that we can check. If we actually stopped waiting, | |
| 203 // count that as success. | |
| 204 } | |
| 205 | |
| 206 TEST_F(DesktopWindowTreeHostMusTest, StackAtTopAlreadyOnTop) { | |
| 207 std::unique_ptr<Widget> widget1(CreateWidget(nullptr)); | |
| 208 widget1->Show(); | |
| 209 | |
| 210 std::unique_ptr<Widget> widget2(CreateWidget(nullptr)); | |
| 211 widget2->Show(); | |
| 212 | |
| 213 WaitForChangeCompletor waiter(aura::ChangeType::REORDER, true); | |
| 214 widget2->StackAtTop(); | |
| 215 waiter.Wait(); | |
| 216 } | |
| 217 | |
| 150 } // namespace views | 218 } // namespace views |
| OLD | NEW |