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/native_widget_mus.h" | 5 #include "ui/views/mus/native_widget_mus.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "components/mus/public/cpp/property_type_converters.h" | 9 #include "components/mus/public/cpp/property_type_converters.h" |
10 #include "components/mus/public/cpp/tests/window_tree_client_impl_private.h" | 10 #include "components/mus/public/cpp/tests/window_tree_client_impl_private.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 public: | 147 public: |
148 NativeWidgetMusTest() {} | 148 NativeWidgetMusTest() {} |
149 ~NativeWidgetMusTest() override {} | 149 ~NativeWidgetMusTest() override {} |
150 | 150 |
151 // Creates a test widget. Takes ownership of |delegate|. | 151 // Creates a test widget. Takes ownership of |delegate|. |
152 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { | 152 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { |
153 std::unique_ptr<Widget> widget(new Widget()); | 153 std::unique_ptr<Widget> widget(new Widget()); |
154 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 154 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
155 params.delegate = delegate; | 155 params.delegate = delegate; |
156 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 156 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
157 params.bounds = gfx::Rect(10, 20, 100, 200); | 157 params.bounds = initial_bounds(); |
158 widget->Init(params); | 158 widget->Init(params); |
159 return widget; | 159 return widget; |
160 } | 160 } |
161 | 161 |
162 int ack_callback_count() { return ack_callback_count_; } | 162 int ack_callback_count() { return ack_callback_count_; } |
163 | 163 |
164 void AckCallback(mus::mojom::EventResult result) { | 164 void AckCallback(mus::mojom::EventResult result) { |
165 ack_callback_count_++; | 165 ack_callback_count_++; |
166 EXPECT_EQ(mus::mojom::EventResult::HANDLED, result); | 166 EXPECT_EQ(mus::mojom::EventResult::HANDLED, result); |
167 } | 167 } |
(...skipping 10 matching lines...) Expand all Loading... |
178 // Simulates an input event to the NativeWidget. | 178 // Simulates an input event to the NativeWidget. |
179 void OnWindowInputEvent( | 179 void OnWindowInputEvent( |
180 NativeWidgetMus* native_widget, | 180 NativeWidgetMus* native_widget, |
181 const ui::Event& event, | 181 const ui::Event& event, |
182 std::unique_ptr<base::Callback<void(mus::mojom::EventResult)>>* | 182 std::unique_ptr<base::Callback<void(mus::mojom::EventResult)>>* |
183 ack_callback) { | 183 ack_callback) { |
184 native_widget->OnWindowInputEvent(native_widget->window(), event, | 184 native_widget->OnWindowInputEvent(native_widget->window(), event, |
185 ack_callback); | 185 ack_callback); |
186 } | 186 } |
187 | 187 |
| 188 protected: |
| 189 gfx::Rect initial_bounds() { return gfx::Rect(10, 20, 100, 200); } |
| 190 |
188 private: | 191 private: |
189 int ack_callback_count_ = 0; | 192 int ack_callback_count_ = 0; |
190 | 193 |
191 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMusTest); | 194 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMusTest); |
192 }; | 195 }; |
193 | 196 |
194 // Tests communication of activation and focus between Widget and | 197 // Tests communication of activation and focus between Widget and |
195 // NativeWidgetMus. | 198 // NativeWidgetMus. |
196 TEST_F(NativeWidgetMusTest, OnActivationChanged) { | 199 TEST_F(NativeWidgetMusTest, OnActivationChanged) { |
197 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); | 200 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 487 |
485 widget->SetCapture(content); | 488 widget->SetCapture(content); |
486 EXPECT_TRUE(widget_private->HasCapture()); | 489 EXPECT_TRUE(widget_private->HasCapture()); |
487 EXPECT_TRUE(mus_window->HasCapture()); | 490 EXPECT_TRUE(mus_window->HasCapture()); |
488 | 491 |
489 widget->ReleaseCapture(); | 492 widget->ReleaseCapture(); |
490 EXPECT_FALSE(widget_private->HasCapture()); | 493 EXPECT_FALSE(widget_private->HasCapture()); |
491 EXPECT_FALSE(mus_window->HasCapture()); | 494 EXPECT_FALSE(mus_window->HasCapture()); |
492 } | 495 } |
493 | 496 |
| 497 // Ensure that manually setting NativeWidgetMus's mus::Window bounds also |
| 498 // updates its WindowTreeHost bounds. |
| 499 TEST_F(NativeWidgetMusTest, SetMusWindowBounds) { |
| 500 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
| 501 widget->Show(); |
| 502 View* content = new View; |
| 503 widget->GetContentsView()->AddChildView(content); |
| 504 NativeWidgetMus* native_widget = |
| 505 static_cast<NativeWidgetMus*>(widget->native_widget_private()); |
| 506 mus::Window* mus_window = native_widget->window(); |
| 507 |
| 508 gfx::Rect start_bounds = initial_bounds(); |
| 509 gfx::Rect end_bounds = gfx::Rect(40, 50, 60, 70); |
| 510 EXPECT_NE(start_bounds, end_bounds); |
| 511 |
| 512 EXPECT_EQ(start_bounds, mus_window->bounds()); |
| 513 EXPECT_EQ(start_bounds, native_widget->window_tree_host()->GetBounds()); |
| 514 |
| 515 mus_window->SetBounds(end_bounds); |
| 516 |
| 517 EXPECT_EQ(end_bounds, mus_window->bounds()); |
| 518 |
| 519 // Main check for this test: Setting |mus_window| bounds while bypassing |
| 520 // |native_widget| must update window_tree_host bounds. |
| 521 EXPECT_EQ(end_bounds, native_widget->window_tree_host()->GetBounds()); |
| 522 } |
| 523 |
494 } // namespace views | 524 } // namespace views |
OLD | NEW |