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

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

Issue 1169063002: MacViews: Retain non-Widget parent NSWindows, as well as the anchor NSView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/cocoa/widget_owner_nswindow_adapter.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/scoped_nsobject.h" 9 #import "base/mac/scoped_nsobject.h"
10 #import "base/mac/scoped_objc_class_swizzler.h" 10 #import "base/mac/scoped_objc_class_swizzler.h"
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 402
403 id hit = [widget->GetNativeWindow() accessibilityHitTest:midpoint]; 403 id hit = [widget->GetNativeWindow() accessibilityHitTest:midpoint];
404 id title = [hit accessibilityAttributeValue:NSAccessibilityTitleAttribute]; 404 id title = [hit accessibilityAttributeValue:NSAccessibilityTitleAttribute];
405 EXPECT_NSEQ(title, @"Green"); 405 EXPECT_NSEQ(title, @"Green");
406 } 406 }
407 407
408 // Tests creating a views::Widget parented off a native NSWindow. 408 // Tests creating a views::Widget parented off a native NSWindow.
409 TEST_F(NativeWidgetMacTest, NonWidgetParent) { 409 TEST_F(NativeWidgetMacTest, NonWidgetParent) {
410 NSWindow* native_parent = MakeNativeParent(); 410 NSWindow* native_parent = MakeNativeParent();
411 411
412 base::scoped_nsobject<NSView> anchor_view(
413 [[NSView alloc] initWithFrame:[[native_parent contentView] bounds]]);
414 [[native_parent contentView] addSubview:anchor_view];
415
412 // Note: Don't use WidgetTest::CreateChildPlatformWidget because that makes 416 // Note: Don't use WidgetTest::CreateChildPlatformWidget because that makes
413 // windows of TYPE_CONTROL which are automatically made visible. But still 417 // windows of TYPE_CONTROL which are automatically made visible. But still
414 // mark it as a child to test window positioning. 418 // mark it as a child to test window positioning.
415 Widget* child = new Widget; 419 Widget* child = new Widget;
416 Widget::InitParams init_params; 420 Widget::InitParams init_params;
417 init_params.parent = [native_parent contentView]; 421 init_params.parent = anchor_view;
418 init_params.child = true; 422 init_params.child = true;
419 child->Init(init_params); 423 child->Init(init_params);
420 424
421 TestWidgetObserver child_observer(child); 425 TestWidgetObserver child_observer(child);
422 426
423 // GetTopLevelNativeWidget() only goes as far as there exists a Widget (i.e. 427 // GetTopLevelNativeWidget() only goes as far as there exists a Widget (i.e.
424 // must stop at |child|. 428 // must stop at |child|.
425 internal::NativeWidgetPrivate* top_level_widget = 429 internal::NativeWidgetPrivate* top_level_widget =
426 internal::NativeWidgetPrivate::GetTopLevelNativeWidget( 430 internal::NativeWidgetPrivate::GetTopLevelNativeWidget(
427 child->GetNativeView()); 431 child->GetNativeView());
428 EXPECT_EQ(child, top_level_widget->GetWidget()); 432 EXPECT_EQ(child, top_level_widget->GetWidget());
429 433
430 // To verify the parent, we need to use NativeWidgetMac APIs. 434 // To verify the parent, we need to use NativeWidgetMac APIs.
431 BridgedNativeWidget* bridged_native_widget = 435 BridgedNativeWidget* bridged_native_widget =
432 NativeWidgetMac::GetBridgeForNativeWindow(child->GetNativeWindow()); 436 NativeWidgetMac::GetBridgeForNativeWindow(child->GetNativeWindow());
433 EXPECT_EQ(native_parent, bridged_native_widget->parent()->GetNSWindow()); 437 EXPECT_EQ(native_parent, bridged_native_widget->parent()->GetNSWindow());
434 438
435 child->SetBounds(gfx::Rect(50, 50, 200, 100)); 439 child->SetBounds(gfx::Rect(50, 50, 200, 100));
436 EXPECT_FALSE(child->IsVisible()); 440 EXPECT_FALSE(child->IsVisible());
437 EXPECT_EQ(0u, [[native_parent childWindows] count]); 441 EXPECT_EQ(0u, [[native_parent childWindows] count]);
438 442
439 child->Show(); 443 child->Show();
440 EXPECT_TRUE(child->IsVisible()); 444 EXPECT_TRUE(child->IsVisible());
441 EXPECT_EQ(1u, [[native_parent childWindows] count]); 445 EXPECT_EQ(1u, [[native_parent childWindows] count]);
442 EXPECT_EQ(child->GetNativeWindow(), 446 EXPECT_EQ(child->GetNativeWindow(),
443 [[native_parent childWindows] objectAtIndex:0]); 447 [[native_parent childWindows] objectAtIndex:0]);
444 EXPECT_EQ(native_parent, [child->GetNativeWindow() parentWindow]); 448 EXPECT_EQ(native_parent, [child->GetNativeWindow() parentWindow]);
445 449
446 // Child should be positioned on screen relative to the parent, but note we 450 // Child should be positioned on screen relative to the parent, but note we
447 // positioned the parent in Cooca coordinates, so we need to convert. 451 // positioned the parent in Cocoa coordinates, so we need to convert.
448 gfx::Point parent_origin = gfx::ScreenRectFromNSRect(ParentRect()).origin(); 452 gfx::Point parent_origin = gfx::ScreenRectFromNSRect(ParentRect()).origin();
449 EXPECT_EQ(gfx::Rect(150, parent_origin.y() + 50, 200, 100), 453 EXPECT_EQ(gfx::Rect(150, parent_origin.y() + 50, 200, 100),
450 child->GetWindowBoundsInScreen()); 454 child->GetWindowBoundsInScreen());
451 455
456 // Removing the anchor_view from its view hierarchy is permitted. This should
457 // not break the relationship between the two windows.
458 [anchor_view removeFromSuperview];
459 anchor_view.reset();
460 EXPECT_EQ(native_parent, bridged_native_widget->parent()->GetNSWindow());
461
452 // Closing the parent should close and destroy the child. 462 // Closing the parent should close and destroy the child.
453 EXPECT_FALSE(child_observer.widget_closed()); 463 EXPECT_FALSE(child_observer.widget_closed());
454 [native_parent close]; 464 [native_parent close];
455 EXPECT_TRUE(child_observer.widget_closed()); 465 EXPECT_TRUE(child_observer.widget_closed());
456 466
457 EXPECT_EQ(0u, [[native_parent childWindows] count]); 467 EXPECT_EQ(0u, [[native_parent childWindows] count]);
458 } 468 }
459 469
460 // Use Native APIs to query the tooltip text that would be shown once the 470 // Use Native APIs to query the tooltip text that would be shown once the
461 // tooltip delay had elapsed. 471 // tooltip delay had elapsed.
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 } 703 }
694 704
695 } // namespace test 705 } // namespace test
696 } // namespace views 706 } // namespace views
697 707
698 @implementation TestStopAnimationWaiter 708 @implementation TestStopAnimationWaiter
699 - (void)setWindowStateForEnd { 709 - (void)setWindowStateForEnd {
700 views::test::ScopedSwizzleWaiter::GetMethodAndMarkCalled()(self, _cmd); 710 views::test::ScopedSwizzleWaiter::GetMethodAndMarkCalled()(self, _cmd);
701 } 711 }
702 @end 712 @end
OLDNEW
« no previous file with comments | « ui/views/cocoa/widget_owner_nswindow_adapter.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698