Chromium Code Reviews| Index: ui/views/widget/native_widget_mac_unittest.mm |
| diff --git a/ui/views/widget/native_widget_mac_unittest.mm b/ui/views/widget/native_widget_mac_unittest.mm |
| index ccc1e4c48c56de2886e7939469c70ea04e32ed59..7e873b9bae13c4390b06b489d3ff2e8d75040155 100644 |
| --- a/ui/views/widget/native_widget_mac_unittest.mm |
| +++ b/ui/views/widget/native_widget_mac_unittest.mm |
| @@ -7,13 +7,16 @@ |
| #import <Cocoa/Cocoa.h> |
| #include "base/run_loop.h" |
| +#import "base/mac/scoped_nsobject.h" |
|
Andre
2015/05/07 17:32:38
Sorts before base/run_loop.h.
tapted
2015/05/07 23:43:51
Whoops - forgot header sort checks don't check .mm
|
| #include "base/strings/utf_string_conversions.h" |
| #import "testing/gtest_mac.h" |
| #import "ui/events/test/cocoa_test_event_utils.h" |
| #include "ui/events/test/event_generator.h" |
| #import "ui/gfx/mac/coordinate_conversion.h" |
| +#import "ui/views/cocoa/bridged_native_widget.h" |
| #include "ui/views/controls/label.h" |
| #include "ui/views/native_cursor.h" |
| +#include "ui/views/widget/native_widget_private.h" |
|
Andre
2015/05/07 17:32:37
Sorts after ui/views/test/...
tapted
2015/05/07 23:43:51
Done.
|
| #include "ui/views/test/test_widget_observer.h" |
| #include "ui/views/test/widget_test.h" |
| @@ -364,5 +367,64 @@ TEST_F(NativeWidgetMacTest, AccessibilityIntegration) { |
| EXPECT_NSEQ(title, @"Green"); |
| } |
| +// Tests creating a views::Widget parented off a native NSWindow. |
| +TEST_F(NativeWidgetMacTest, NonWidgetParent) { |
| + NSRect parent_nsrect = NSMakeRect(100, 100, 300, 200); |
| + base::scoped_nsobject<NSWindow> native_parent( |
| + [[NSWindow alloc] initWithContentRect:parent_nsrect |
| + styleMask:NSBorderlessWindowMask |
| + backing:NSBackingStoreBuffered |
| + defer:NO]); |
| + [native_parent setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. |
| + [native_parent makeKeyAndOrderFront:nil]; |
| + |
| + // Note: Don't use WidgetTest::CreateChildPlatformWidget because that makes |
| + // windows of TYPE_CONTROL which are automatically made visible. But still |
| + // mark it as a child to test window positioning. |
| + Widget* child = new Widget; |
| + Widget::InitParams init_params; |
| + init_params.parent = [native_parent contentView]; |
| + init_params.child = true; |
| + child->Init(init_params); |
| + |
| + TestWidgetObserver child_observer(child); |
| + |
| + // GetTopLevelNativeWidget() only goes as far as there exists a Widget (i.e. |
| + // must stop at |child|. |
| + internal::NativeWidgetPrivate* top_level_widget = |
| + internal::NativeWidgetPrivate::GetTopLevelNativeWidget( |
| + child->GetNativeView()); |
| + EXPECT_EQ(child, top_level_widget->GetWidget()); |
| + |
| + // To verify the parent, we need to use NativeWidgetMac APIs. |
| + BridgedNativeWidget* bridged_native_widget = |
| + NativeWidgetMac::GetBridgeForNativeWindow(child->GetNativeWindow()); |
| + EXPECT_EQ(native_parent, bridged_native_widget->parent()->GetNSWindow()); |
| + |
| + child->SetBounds(gfx::Rect(50, 50, 200, 100)); |
| + EXPECT_FALSE(child->IsVisible()); |
| + EXPECT_EQ(0u, [[native_parent childWindows] count]); |
| + |
| + child->Show(); |
| + EXPECT_TRUE(child->IsVisible()); |
| + EXPECT_EQ(1u, [[native_parent childWindows] count]); |
| + EXPECT_EQ(child->GetNativeWindow(), |
| + [[native_parent childWindows] objectAtIndex:0]); |
| + EXPECT_EQ(native_parent, [child->GetNativeWindow() parentWindow]); |
| + |
| + // Child should be positioned on screen relative to the parent, but note we |
| + // positioned the parent in Cooca coordinates, so we need to convert. |
| + gfx::Point parent_origin = gfx::ScreenRectFromNSRect(parent_nsrect).origin(); |
| + EXPECT_EQ(gfx::Rect(150, parent_origin.y() + 50, 200, 100), |
| + child->GetWindowBoundsInScreen()); |
| + |
| + // Closing the parent should close and destroy the child. |
| + EXPECT_FALSE(child_observer.widget_closed()); |
| + [native_parent close]; |
| + EXPECT_TRUE(child_observer.widget_closed()); |
| + |
| + EXPECT_EQ(0u, [[native_parent childWindows] count]); |
| +} |
| + |
| } // namespace test |
| } // namespace views |