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

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: Add DCHECK for bounds change; git cl format 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
« no previous file with comments | « ui/views/mus/native_widget_mus.cc ('k') | ui/views/mus/platform_window_mus.h » ('j') | 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/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() { 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
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
OLDNEW
« no previous file with comments | « ui/views/mus/native_widget_mus.cc ('k') | ui/views/mus/platform_window_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698