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

Side by Side Diff: ui/views/widget/native_widget_mac_unittest.mm

Issue 2535163002: MacViews: Fix Widget::GetAllChildWidgets(gfx::NativeView) for non-Widgets. (Closed)
Patch Set: respond to comments Created 4 years 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/widget/native_widget_mac.mm ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "ui/views/widget/native_widget_mac.h" 5 #import "ui/views/widget/native_widget_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #import "base/mac/foundation_util.h" 9 #import "base/mac/foundation_util.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 init_params.type = Widget::InitParams::TYPE_POPUP; 685 init_params.type = Widget::InitParams::TYPE_POPUP;
686 child->Init(init_params); 686 child->Init(init_params);
687 return child; 687 return child;
688 } 688 }
689 689
690 } // namespace 690 } // namespace
691 691
692 // Tests creating a views::Widget parented off a native NSWindow. 692 // Tests creating a views::Widget parented off a native NSWindow.
693 TEST_F(NativeWidgetMacTest, NonWidgetParent) { 693 TEST_F(NativeWidgetMacTest, NonWidgetParent) {
694 NSWindow* native_parent = MakeNativeParent(); 694 NSWindow* native_parent = MakeNativeParent();
695
696 Widget::Widgets children;
697 Widget::GetAllChildWidgets([native_parent contentView], &children);
698 EXPECT_TRUE(children.empty());
699
695 Widget* child = AttachPopupToNativeParent(native_parent); 700 Widget* child = AttachPopupToNativeParent(native_parent);
696 TestWidgetObserver child_observer(child); 701 TestWidgetObserver child_observer(child);
697 702
698 // GetTopLevelNativeWidget() only goes as far as there exists a Widget (i.e. 703 // GetTopLevelNativeWidget() only goes as far as there exists a Widget (i.e.
699 // must stop at |child|. 704 // must stop at |child|.
700 internal::NativeWidgetPrivate* top_level_widget = 705 internal::NativeWidgetPrivate* top_level_widget =
701 internal::NativeWidgetPrivate::GetTopLevelNativeWidget( 706 internal::NativeWidgetPrivate::GetTopLevelNativeWidget(
702 child->GetNativeView()); 707 child->GetNativeView());
703 EXPECT_EQ(child, top_level_widget->GetWidget()); 708 EXPECT_EQ(child, top_level_widget->GetWidget());
704 709
705 // To verify the parent, we need to use NativeWidgetMac APIs. 710 // To verify the parent, we need to use NativeWidgetMac APIs.
706 BridgedNativeWidget* bridged_native_widget = 711 BridgedNativeWidget* bridged_native_widget =
707 NativeWidgetMac::GetBridgeForNativeWindow(child->GetNativeWindow()); 712 NativeWidgetMac::GetBridgeForNativeWindow(child->GetNativeWindow());
708 EXPECT_EQ(native_parent, bridged_native_widget->parent()->GetNSWindow()); 713 EXPECT_EQ(native_parent, bridged_native_widget->parent()->GetNSWindow());
709 714
710 const gfx::Rect child_bounds(50, 50, 200, 100); 715 const gfx::Rect child_bounds(50, 50, 200, 100);
711 child->SetBounds(child_bounds); 716 child->SetBounds(child_bounds);
712 EXPECT_FALSE(child->IsVisible()); 717 EXPECT_FALSE(child->IsVisible());
713 EXPECT_EQ(0u, [[native_parent childWindows] count]); 718 EXPECT_EQ(0u, [[native_parent childWindows] count]);
714 719
715 child->Show(); 720 child->Show();
716 EXPECT_TRUE(child->IsVisible()); 721 EXPECT_TRUE(child->IsVisible());
717 EXPECT_EQ(1u, [[native_parent childWindows] count]); 722 EXPECT_EQ(1u, [[native_parent childWindows] count]);
718 EXPECT_EQ(child->GetNativeWindow(), 723 EXPECT_EQ(child->GetNativeWindow(),
719 [[native_parent childWindows] objectAtIndex:0]); 724 [[native_parent childWindows] objectAtIndex:0]);
720 EXPECT_EQ(native_parent, [child->GetNativeWindow() parentWindow]); 725 EXPECT_EQ(native_parent, [child->GetNativeWindow() parentWindow]);
721 726
727 Widget::GetAllChildWidgets([native_parent contentView], &children);
728 ASSERT_EQ(1u, children.size());
729 EXPECT_EQ(child, *children.begin());
730
722 // Only non-toplevel Widgets are positioned relative to the parent, so the 731 // Only non-toplevel Widgets are positioned relative to the parent, so the
723 // bounds set above should be in screen coordinates. 732 // bounds set above should be in screen coordinates.
724 EXPECT_EQ(child_bounds, child->GetWindowBoundsInScreen()); 733 EXPECT_EQ(child_bounds, child->GetWindowBoundsInScreen());
725 734
726 // Removing the anchor view from its view hierarchy is permitted. This should 735 // Removing the anchor view from its view hierarchy is permitted. This should
727 // not break the relationship between the two windows. 736 // not break the relationship between the two windows.
728 NSView* anchor_view = [[native_parent contentView] subviews][0]; 737 NSView* anchor_view = [[native_parent contentView] subviews][0];
729 EXPECT_TRUE(anchor_view); 738 EXPECT_TRUE(anchor_view);
730 [anchor_view removeFromSuperview]; 739 [anchor_view removeFromSuperview];
731 EXPECT_EQ(native_parent, bridged_native_widget->parent()->GetNSWindow()); 740 EXPECT_EQ(native_parent, bridged_native_widget->parent()->GetNSWindow());
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1835 1844
1836 - (void)dealloc { 1845 - (void)dealloc {
1837 if (deallocFlag_) { 1846 if (deallocFlag_) {
1838 DCHECK(!*deallocFlag_); 1847 DCHECK(!*deallocFlag_);
1839 *deallocFlag_ = true; 1848 *deallocFlag_ = true;
1840 } 1849 }
1841 [super dealloc]; 1850 [super dealloc];
1842 } 1851 }
1843 1852
1844 @end 1853 @end
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698