Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: ui/views/mus/desktop_window_tree_host_mus_unittest.cc

Issue 2649103009: chromeos: wires transients using the WindowTreeHost window (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/mus/desktop_window_tree_host_mus.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/transient_window_client.h"
11 #include "ui/aura/mus/in_flight_change.h" 12 #include "ui/aura/mus/in_flight_change.h"
12 #include "ui/aura/test/mus/change_completion_waiter.h" 13 #include "ui/aura/test/mus/change_completion_waiter.h"
13 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
14 #include "ui/views/mus/mus_client.h" 15 #include "ui/views/mus/mus_client.h"
15 #include "ui/views/test/views_test_base.h" 16 #include "ui/views/test/views_test_base.h"
16 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_delegate.h" 18 #include "ui/views/widget/widget_delegate.h"
18 #include "ui/views/widget/widget_observer.h" 19 #include "ui/views/widget/widget_observer.h"
19 20
20 namespace views { 21 namespace views {
21 22
22 class DesktopWindowTreeHostMusTest : public ViewsTestBase, 23 class DesktopWindowTreeHostMusTest : public ViewsTestBase,
23 public WidgetObserver { 24 public WidgetObserver {
24 public: 25 public:
25 DesktopWindowTreeHostMusTest() 26 DesktopWindowTreeHostMusTest()
26 : widget_activated_(nullptr), 27 : widget_activated_(nullptr),
27 widget_deactivated_(nullptr), 28 widget_deactivated_(nullptr),
28 waiting_for_deactivate_(nullptr) {} 29 waiting_for_deactivate_(nullptr) {}
29 ~DesktopWindowTreeHostMusTest() override {} 30 ~DesktopWindowTreeHostMusTest() override {}
30 31
31 // Creates a test widget. Takes ownership of |delegate|. 32 // Creates a test widget. Takes ownership of |delegate|.
32 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { 33 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate = nullptr,
34 aura::Window* parent = nullptr) {
33 std::unique_ptr<Widget> widget = base::MakeUnique<Widget>(); 35 std::unique_ptr<Widget> widget = base::MakeUnique<Widget>();
34 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 36 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
35 params.delegate = delegate; 37 params.delegate = delegate;
36 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 38 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
37 params.bounds = gfx::Rect(0, 1, 111, 123); 39 params.bounds = gfx::Rect(0, 1, 111, 123);
40 params.parent = parent;
38 widget->Init(params); 41 widget->Init(params);
39 widget->AddObserver(this); 42 widget->AddObserver(this);
40 return widget; 43 return widget;
41 } 44 }
42 45
43 const Widget* widget_activated() const { return widget_activated_; } 46 const Widget* widget_activated() const { return widget_activated_; }
44 const Widget* widget_deactivated() const { return widget_deactivated_; } 47 const Widget* widget_deactivated() const { return widget_deactivated_; }
45 48
46 void DeactivateAndWait(Widget* to_deactivate) { 49 void DeactivateAndWait(Widget* to_deactivate) {
47 waiting_for_deactivate_ = to_deactivate; 50 waiting_for_deactivate_ = to_deactivate;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 EXPECT_FALSE(cursor_client); 101 EXPECT_FALSE(cursor_client);
99 window_->RemoveObserver(this); 102 window_->RemoveObserver(this);
100 window_ = nullptr; 103 window_ = nullptr;
101 } 104 }
102 105
103 aura::Window* window_; 106 aura::Window* window_;
104 DISALLOW_COPY_AND_ASSIGN(ExpectsNullCursorClientDuringTearDown); 107 DISALLOW_COPY_AND_ASSIGN(ExpectsNullCursorClientDuringTearDown);
105 }; 108 };
106 109
107 TEST_F(DesktopWindowTreeHostMusTest, Visibility) { 110 TEST_F(DesktopWindowTreeHostMusTest, Visibility) {
108 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); 111 std::unique_ptr<Widget> widget(CreateWidget());
109 EXPECT_FALSE(widget->IsVisible()); 112 EXPECT_FALSE(widget->IsVisible());
110 EXPECT_FALSE(widget->GetNativeView()->IsVisible()); 113 EXPECT_FALSE(widget->GetNativeView()->IsVisible());
111 // It's important the parent is also hidden as this value is sent to the 114 // It's important the parent is also hidden as this value is sent to the
112 // server. 115 // server.
113 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible()); 116 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible());
114 widget->Show(); 117 widget->Show();
115 EXPECT_TRUE(widget->IsVisible()); 118 EXPECT_TRUE(widget->IsVisible());
116 EXPECT_TRUE(widget->GetNativeView()->IsVisible()); 119 EXPECT_TRUE(widget->GetNativeView()->IsVisible());
117 EXPECT_TRUE(widget->GetNativeView()->parent()->IsVisible()); 120 EXPECT_TRUE(widget->GetNativeView()->parent()->IsVisible());
118 widget->Hide(); 121 widget->Hide();
119 EXPECT_FALSE(widget->IsVisible()); 122 EXPECT_FALSE(widget->IsVisible());
120 EXPECT_FALSE(widget->GetNativeView()->IsVisible()); 123 EXPECT_FALSE(widget->GetNativeView()->IsVisible());
121 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible()); 124 EXPECT_FALSE(widget->GetNativeView()->parent()->IsVisible());
122 } 125 }
123 126
124 TEST_F(DesktopWindowTreeHostMusTest, Deactivate) { 127 TEST_F(DesktopWindowTreeHostMusTest, Deactivate) {
125 std::unique_ptr<Widget> widget1(CreateWidget(nullptr)); 128 std::unique_ptr<Widget> widget1(CreateWidget());
126 widget1->Show(); 129 widget1->Show();
127 130
128 std::unique_ptr<Widget> widget2(CreateWidget(nullptr)); 131 std::unique_ptr<Widget> widget2(CreateWidget());
129 widget2->Show(); 132 widget2->Show();
130 133
131 widget1->Activate(); 134 widget1->Activate();
132 RunPendingMessages(); 135 RunPendingMessages();
133 EXPECT_TRUE(widget1->IsActive()); 136 EXPECT_TRUE(widget1->IsActive());
134 EXPECT_EQ(widget_activated(), widget1.get()); 137 EXPECT_EQ(widget_activated(), widget1.get());
135 138
136 DeactivateAndWait(widget1.get()); 139 DeactivateAndWait(widget1.get());
137 EXPECT_FALSE(widget1->IsActive()); 140 EXPECT_FALSE(widget1->IsActive());
138 } 141 }
139 142
140 TEST_F(DesktopWindowTreeHostMusTest, CursorClientDuringTearDown) { 143 TEST_F(DesktopWindowTreeHostMusTest, CursorClientDuringTearDown) {
141 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); 144 std::unique_ptr<Widget> widget(CreateWidget());
142 widget->Show(); 145 widget->Show();
143 146
144 std::unique_ptr<aura::Window> window(new aura::Window(nullptr)); 147 std::unique_ptr<aura::Window> window(new aura::Window(nullptr));
145 window->Init(ui::LAYER_SOLID_COLOR); 148 window->Init(ui::LAYER_SOLID_COLOR);
146 ExpectsNullCursorClientDuringTearDown observer(window.get()); 149 ExpectsNullCursorClientDuringTearDown observer(window.get());
147 150
148 widget->GetNativeWindow()->AddChild(window.release()); 151 widget->GetNativeWindow()->AddChild(window.release());
149 widget.reset(); 152 widget.reset();
150 } 153 }
151 154
152 TEST_F(DesktopWindowTreeHostMusTest, StackAtTop) { 155 TEST_F(DesktopWindowTreeHostMusTest, StackAtTop) {
153 std::unique_ptr<Widget> widget1(CreateWidget(nullptr)); 156 std::unique_ptr<Widget> widget1(CreateWidget());
154 widget1->Show(); 157 widget1->Show();
155 158
156 std::unique_ptr<Widget> widget2(CreateWidget(nullptr)); 159 std::unique_ptr<Widget> widget2(CreateWidget());
157 widget2->Show(); 160 widget2->Show();
158 161
159 aura::test::ChangeCompletionWaiter waiter( 162 aura::test::ChangeCompletionWaiter waiter(
160 MusClient::Get()->window_tree_client(), 163 MusClient::Get()->window_tree_client(),
161 aura::ChangeType::REORDER, true); 164 aura::ChangeType::REORDER, true);
162 widget1->StackAtTop(); 165 widget1->StackAtTop();
163 waiter.Wait(); 166 waiter.Wait();
164 167
165 // Other than the signal that our StackAtTop() succeeded, we don't have any 168 // Other than the signal that our StackAtTop() succeeded, we don't have any
166 // pieces of public data that we can check. If we actually stopped waiting, 169 // pieces of public data that we can check. If we actually stopped waiting,
167 // count that as success. 170 // count that as success.
168 } 171 }
169 172
170 TEST_F(DesktopWindowTreeHostMusTest, StackAtTopAlreadyOnTop) { 173 TEST_F(DesktopWindowTreeHostMusTest, StackAtTopAlreadyOnTop) {
171 std::unique_ptr<Widget> widget1(CreateWidget(nullptr)); 174 std::unique_ptr<Widget> widget1(CreateWidget());
172 widget1->Show(); 175 widget1->Show();
173 176
174 std::unique_ptr<Widget> widget2(CreateWidget(nullptr)); 177 std::unique_ptr<Widget> widget2(CreateWidget());
175 widget2->Show(); 178 widget2->Show();
176 179
177 aura::test::ChangeCompletionWaiter waiter( 180 aura::test::ChangeCompletionWaiter waiter(
178 MusClient::Get()->window_tree_client(), 181 MusClient::Get()->window_tree_client(),
179 aura::ChangeType::REORDER, true); 182 aura::ChangeType::REORDER, true);
180 widget2->StackAtTop(); 183 widget2->StackAtTop();
181 waiter.Wait(); 184 waiter.Wait();
182 } 185 }
183 186
187 TEST_F(DesktopWindowTreeHostMusTest, TransientParentWiredToHostWindow) {
188 std::unique_ptr<Widget> widget1(CreateWidget());
189 widget1->Show();
190
191 std::unique_ptr<Widget> widget2(
192 CreateWidget(nullptr, widget1->GetNativeView()));
193 widget2->Show();
194
195 aura::client::TransientWindowClient* transient_window_client =
196 aura::client::GetTransientWindowClient();
197 // Even though the widget1->GetNativeView() was specified as the parent we
198 // expect the transient parents to be marked at the host level.
199 EXPECT_EQ(widget1->GetNativeView()->GetHost()->window(),
200 transient_window_client->GetTransientParent(
201 widget2->GetNativeView()->GetHost()->window()));
202 }
203
184 } // namespace views 204 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/desktop_window_tree_host_mus.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698