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

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

Issue 2009853002: Finish eliminating PlatformWindowMus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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
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/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
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
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() {
190 return gfx::Rect(10, 20, 100, 200);
191 }
192
188 private: 193 private:
189 int ack_callback_count_ = 0; 194 int ack_callback_count_ = 0;
190 195
191 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMusTest); 196 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMusTest);
192 }; 197 };
193 198
194 // Tests communication of activation and focus between Widget and 199 // Tests communication of activation and focus between Widget and
195 // NativeWidgetMus. 200 // NativeWidgetMus.
196 TEST_F(NativeWidgetMusTest, OnActivationChanged) { 201 TEST_F(NativeWidgetMusTest, OnActivationChanged) {
197 std::unique_ptr<Widget> widget(CreateWidget(nullptr)); 202 std::unique_ptr<Widget> widget(CreateWidget(nullptr));
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 489
485 widget->SetCapture(content); 490 widget->SetCapture(content);
486 EXPECT_TRUE(widget_private->HasCapture()); 491 EXPECT_TRUE(widget_private->HasCapture());
487 EXPECT_TRUE(mus_window->HasCapture()); 492 EXPECT_TRUE(mus_window->HasCapture());
488 493
489 widget->ReleaseCapture(); 494 widget->ReleaseCapture();
490 EXPECT_FALSE(widget_private->HasCapture()); 495 EXPECT_FALSE(widget_private->HasCapture());
491 EXPECT_FALSE(mus_window->HasCapture()); 496 EXPECT_FALSE(mus_window->HasCapture());
492 } 497 }
493 498
499 // Ensure that manually setting NativeWidgetMus's mus::Window bounds also
500 // updates its WindowTreeHost bounds.
501 TEST_F(NativeWidgetMusTest, SetMusWindowBounds) {
502 std::unique_ptr<Widget> widget(CreateWidget(nullptr));
503 widget->Show();
504 View* content = new View;
505 widget->GetContentsView()->AddChildView(content);
506 NativeWidgetMus* native_widget =
507 static_cast<NativeWidgetMus*>(widget->native_widget_private());
508 mus::Window* mus_window = native_widget->window();
509
510 gfx::Rect start_bounds = initial_bounds();
511 gfx::Rect end_bounds = gfx::Rect(40, 50, 60, 70);
512 EXPECT_NE(start_bounds, end_bounds);
513
514 EXPECT_EQ(start_bounds, mus_window->bounds());
515 EXPECT_EQ(start_bounds, native_widget->window_tree_host()->GetBounds());
516
517 mus_window->SetBounds(end_bounds);
518
519 EXPECT_EQ(end_bounds, mus_window->bounds());
520
521 // Main check for this test: Setting |mus_window| bounds while bypassing
522 // |native_widget| must update window_tree_host bounds.
523 EXPECT_EQ(end_bounds, native_widget->window_tree_host()->GetBounds());
524 }
525
494 } // namespace views 526 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698