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

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

Issue 2484813002: Add child for parent_mus when params.parent_mus is not initialized. (Closed)
Patch Set: Fix typo Created 4 years, 1 month 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') | 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/native_widget_mus.h"
mfomitchev 2016/11/09 17:44:20 The unit test is for NativeWidgetMus, so this incl
6 5
7 #include "base/callback.h" 6 #include "base/callback.h"
8 #include "base/macros.h" 7 #include "base/macros.h"
9 #include "services/ui/public/cpp/property_type_converters.h" 8 #include "services/ui/public/cpp/property_type_converters.h"
10 #include "services/ui/public/cpp/tests/window_tree_client_private.h" 9 #include "services/ui/public/cpp/tests/window_tree_client_private.h"
11 #include "services/ui/public/cpp/window.h" 10 #include "services/ui/public/cpp/window.h"
12 #include "services/ui/public/cpp/window_observer.h" 11 #include "services/ui/public/cpp/window_observer.h"
13 #include "services/ui/public/cpp/window_property.h" 12 #include "services/ui/public/cpp/window_property.h"
14 #include "services/ui/public/cpp/window_tree_client.h" 13 #include "services/ui/public/cpp/window_tree_client.h"
15 #include "services/ui/public/interfaces/window_manager.mojom.h" 14 #include "services/ui/public/interfaces/window_manager.mojom.h"
16 #include "services/ui/public/interfaces/window_tree.mojom.h" 15 #include "services/ui/public/interfaces/window_tree.mojom.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
19 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
19 #include "ui/aura/client/aura_constants.h"
mfomitchev 2016/11/09 17:44:20 Is this used?
thanhph 2016/11/09 19:11:37 I removed this include with the function CreateTes
20 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
21 #include "ui/events/event.h" 21 #include "ui/events/event.h"
22 #include "ui/events/test/test_event_handler.h" 22 #include "ui/events/test/test_event_handler.h"
23 #include "ui/gfx/geometry/rect.h" 23 #include "ui/gfx/geometry/rect.h"
24 #include "ui/gfx/image/image_skia.h" 24 #include "ui/gfx/image/image_skia.h"
25 #include "ui/gfx/path.h" 25 #include "ui/gfx/path.h"
26 #include "ui/gfx/skia_util.h" 26 #include "ui/gfx/skia_util.h"
27 #include "ui/views/controls/native/native_view_host.h" 27 #include "ui/views/controls/native/native_view_host.h"
28 #include "ui/views/mus/native_widget_mus.h"
28 #include "ui/views/mus/window_manager_connection.h" 29 #include "ui/views/mus/window_manager_connection.h"
29 #include "ui/views/test/focus_manager_test.h" 30 #include "ui/views/test/focus_manager_test.h"
30 #include "ui/views/test/views_test_base.h" 31 #include "ui/views/test/views_test_base.h"
31 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
32 #include "ui/views/widget/widget_delegate.h" 33 #include "ui/views/widget/widget_delegate.h"
33 #include "ui/views/widget/widget_observer.h" 34 #include "ui/views/widget/widget_observer.h"
34 #include "ui/wm/public/activation_client.h" 35 #include "ui/wm/public/activation_client.h"
35 36
36 using ui::mojom::EventResult; 37 using ui::mojom::EventResult;
37 38
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { 155 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) {
155 std::unique_ptr<Widget> widget(new Widget()); 156 std::unique_ptr<Widget> widget(new Widget());
156 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 157 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
157 params.delegate = delegate; 158 params.delegate = delegate;
158 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 159 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
159 params.bounds = initial_bounds(); 160 params.bounds = initial_bounds();
160 widget->Init(params); 161 widget->Init(params);
161 return widget; 162 return widget;
162 } 163 }
163 164
165 aura::Window* CreateTestWindow() {
mfomitchev 2016/11/09 17:44:20 This isn't actually used it seems.
thanhph 2016/11/09 19:11:37 Acknowledged.
166 aura::Window* window = new aura::Window(nullptr);
167 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
168 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
169 window->Init(ui::LAYER_TEXTURED);
170 return window;
171 }
172
164 int ack_callback_count() { return ack_callback_count_; } 173 int ack_callback_count() { return ack_callback_count_; }
165 174
166 void AckCallback(ui::mojom::EventResult result) { 175 void AckCallback(ui::mojom::EventResult result) {
167 ack_callback_count_++; 176 ack_callback_count_++;
168 EXPECT_EQ(ui::mojom::EventResult::HANDLED, result); 177 EXPECT_EQ(ui::mojom::EventResult::HANDLED, result);
169 } 178 }
170 179
171 // Returns a mouse pressed event inside the widget. Tests that place views 180 // Returns a mouse pressed event inside the widget. Tests that place views
172 // within the widget that respond to the event must be constructed within the 181 // within the widget that respond to the event must be constructed within the
173 // widget coordinate space such that they respond correctly. 182 // widget coordinate space such that they respond correctly.
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 params.bounds = initial_bounds(); 611 params.bounds = initial_bounds();
603 params.native_widget = new NativeWidgetMus( 612 params.native_widget = new NativeWidgetMus(
604 widget.get(), window, ui::mojom::CompositorFrameSinkType::DEFAULT); 613 widget.get(), window, ui::mojom::CompositorFrameSinkType::DEFAULT);
605 widget->Init(params); 614 widget->Init(params);
606 window->SetSharedProperty<int32_t>( 615 window->SetSharedProperty<int32_t>(
607 ui::mojom::WindowManager::kShowState_Property, 616 ui::mojom::WindowManager::kShowState_Property,
608 static_cast<uint32_t>(ui::mojom::ShowState::MAXIMIZED)); 617 static_cast<uint32_t>(ui::mojom::ShowState::MAXIMIZED));
609 EXPECT_TRUE(widget->IsMaximized()); 618 EXPECT_TRUE(widget->IsMaximized());
610 } 619 }
611 620
621 // This test is to ensure corresponding parentship relation between widget and
mfomitchev 2016/11/09 17:44:20 This isn't quite accurate. Strictly speaking, widg
thanhph 2016/11/09 19:11:37 Acknowledged. Thanks for the clarification!
622 // window. If widget A is child of Widget B, then window that contains widget A
623 // is also a child of window that contains widget B.
624 TEST_F(NativeWidgetMusTest, WindowOfChildWidgetIsChildOfParentWindowWidget) {
mfomitchev 2016/11/09 17:44:20 Maybe just call the test something like InitNative
thanhph 2016/11/09 19:11:37 Acknowledged.
625 ASSERT_TRUE(WindowManagerConnection::Exists());
626
627 ui::Window* parent_window = WindowManagerConnection::Get()->NewTopLevelWindow(
628 std::map<std::string, std::vector<uint8_t>>());
629 std::unique_ptr<Widget> parent_widget(new Widget());
630 Widget::InitParams parent_params =
631 CreateParams(Widget::InitParams::TYPE_WINDOW);
632 parent_params.name = "Parent Widget";
633 parent_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
634 parent_params.shadow_type = Widget::InitParams::SHADOW_TYPE_NONE;
635 parent_params.opacity = Widget::InitParams::OPAQUE_WINDOW;
636 parent_params.parent = nullptr;
637 parent_params.bounds = initial_bounds();
638 parent_params.native_widget =
639 new NativeWidgetMus(parent_widget.get(), parent_window,
640 ui::mojom::CompositorFrameSinkType::DEFAULT);
641 parent_widget->Init(parent_params);
642
643 std::unique_ptr<Widget> child_widget(new Widget());
644 ui::Window* child_window = parent_window->window_tree()->NewWindow();
645 Widget::InitParams child_params = CreateParams(Widget::InitParams::TYPE_MENU);
646 child_params.parent = parent_widget->GetNativeView();
647 child_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
648 child_params.name = "Child Widget";
649 child_params.native_widget =
650 new NativeWidgetMus(child_widget.get(), child_window,
651 ui::mojom::CompositorFrameSinkType::DEFAULT);
652 child_widget->Init(child_params);
653
654 EXPECT_EQ(child_window->parent(), parent_window);
655
656 std::unique_ptr<Widget> not_child_widget(new Widget());
657 ui::Window* not_child_window = parent_window->window_tree()->NewWindow();
658 Widget::InitParams not_child_params =
659 CreateParams(Widget::InitParams::TYPE_MENU);
660 not_child_params.ownership =
661 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
662 not_child_params.name = "Not Child Widget";
663 not_child_params.native_widget =
664 new NativeWidgetMus(not_child_widget.get(), not_child_window,
665 ui::mojom::CompositorFrameSinkType::DEFAULT);
666 not_child_widget->Init(not_child_params);
667
668 EXPECT_NE(not_child_window->parent(), parent_window);
669 }
670
612 } // namespace views 671 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/native_widget_mus.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698