OLD | NEW |
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 #include "base/location.h" | 9 #include "base/location.h" |
10 #import "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 int paint_count() { return paint_count_; } | 377 int paint_count() { return paint_count_; } |
378 | 378 |
379 private: | 379 private: |
380 int paint_count_ = 0; | 380 int paint_count_ = 0; |
381 int target_paint_count_ = 0; | 381 int target_paint_count_ = 0; |
382 base::RunLoop* run_loop_ = nullptr; | 382 base::RunLoop* run_loop_ = nullptr; |
383 | 383 |
384 DISALLOW_COPY_AND_ASSIGN(PaintCountView); | 384 DISALLOW_COPY_AND_ASSIGN(PaintCountView); |
385 }; | 385 }; |
386 | 386 |
| 387 // Test for correct child window restore when parent window is minimized |
| 388 // and restored using -makeKeyAndOrderFront:. |
| 389 // Parent-child window relationships in AppKit are not supported when window |
| 390 // visibility changes. |
| 391 // Disabled because it relies on cocoa occlusion APIs |
| 392 // and state changes that are unavoidably flaky. |
| 393 TEST_F(NativeWidgetMacTest, DISABLED_OrderFrontAfterMiniaturize) { |
| 394 Widget* widget = CreateTopLevelPlatformWidget(); |
| 395 NSWindow* ns_window = widget->GetNativeWindow(); |
| 396 |
| 397 Widget* child_widget = CreateChildPlatformWidget(widget->GetNativeView()); |
| 398 NSWindow* child_ns_window = child_widget->GetNativeWindow(); |
| 399 |
| 400 // Set parent bounds that overlap child. |
| 401 widget->SetBounds(gfx::Rect(100, 100, 300, 300)); |
| 402 child_widget->SetBounds(gfx::Rect(110, 110, 100, 100)); |
| 403 |
| 404 widget->Show(); |
| 405 base::RunLoop().RunUntilIdle(); |
| 406 |
| 407 EXPECT_FALSE(widget->IsMinimized()); |
| 408 |
| 409 // Minimize parent. |
| 410 [ns_window performMiniaturize:nil]; |
| 411 base::RunLoop().RunUntilIdle(); |
| 412 |
| 413 EXPECT_TRUE(widget->IsMinimized()); |
| 414 EXPECT_FALSE(widget->IsVisible()); |
| 415 EXPECT_FALSE(child_widget->IsVisible()); |
| 416 |
| 417 // Restore parent window as AppController does. |
| 418 [ns_window makeKeyAndOrderFront:nil]; |
| 419 |
| 420 // Wait and check that child is really visible. |
| 421 // TODO(kirr): remove the fixed delay. |
| 422 base::MessageLoop::current()->PostDelayedTask( |
| 423 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 424 base::TimeDelta::FromSeconds(2)); |
| 425 base::MessageLoop::current()->Run(); |
| 426 |
| 427 EXPECT_FALSE(widget->IsMinimized()); |
| 428 EXPECT_TRUE(widget->IsVisible()); |
| 429 EXPECT_TRUE(child_widget->IsVisible()); |
| 430 // Check that child window is visible. |
| 431 EXPECT_TRUE([child_ns_window occlusionState] & NSWindowOcclusionStateVisible); |
| 432 EXPECT_TRUE(IsWindowStackedAbove(child_widget, widget)); |
| 433 widget->Close(); |
| 434 } |
| 435 |
387 // Test minimized states triggered externally, implied visibility and restored | 436 // Test minimized states triggered externally, implied visibility and restored |
388 // bounds whilst minimized. | 437 // bounds whilst minimized. |
389 TEST_F(NativeWidgetMacTest, MiniaturizeExternally) { | 438 TEST_F(NativeWidgetMacTest, MiniaturizeExternally) { |
390 Widget* widget = new Widget; | 439 Widget* widget = new Widget; |
391 Widget::InitParams init_params(Widget::InitParams::TYPE_WINDOW); | 440 Widget::InitParams init_params(Widget::InitParams::TYPE_WINDOW); |
392 widget->Init(init_params); | 441 widget->Init(init_params); |
393 | 442 |
394 PaintCountView* view = new PaintCountView(); | 443 PaintCountView* view = new PaintCountView(); |
395 widget->GetContentsView()->AddChildView(view); | 444 widget->GetContentsView()->AddChildView(view); |
396 NSWindow* ns_window = widget->GetNativeWindow(); | 445 NSWindow* ns_window = widget->GetNativeWindow(); |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 // -[NSWindow orderOut:] call that is triggered from -[ViewsNSWindowDelegate | 1014 // -[NSWindow orderOut:] call that is triggered from -[ViewsNSWindowDelegate |
966 // sheetDidEnd:]. |sheet_widget| will be destroyed next, so it's still safe to | 1015 // sheetDidEnd:]. |sheet_widget| will be destroyed next, so it's still safe to |
967 // use in the block. However, since the orderOut just happened, it's not very | 1016 // use in the block. However, since the orderOut just happened, it's not very |
968 // interesting. | 1017 // interesting. |
969 observer = [[NSNotificationCenter defaultCenter] | 1018 observer = [[NSNotificationCenter defaultCenter] |
970 addObserverForName:NSWindowDidEndSheetNotification | 1019 addObserverForName:NSWindowDidEndSheetNotification |
971 object:native_parent | 1020 object:native_parent |
972 queue:nil | 1021 queue:nil |
973 usingBlock:^(NSNotification* note) { | 1022 usingBlock:^(NSNotification* note) { |
974 EXPECT_TRUE([sheet_window delegate]); | 1023 EXPECT_TRUE([sheet_window delegate]); |
975 EXPECT_FALSE(sheet_widget->IsVisible()); | |
976 EXPECT_FALSE(sheet_widget->GetLayer()->IsDrawn()); | |
977 *did_observe_ptr = true; | 1024 *did_observe_ptr = true; |
978 }]; | 1025 }]; |
979 | 1026 |
980 // Pump in order to trigger -[NSWindow endSheet:..], which will block while | 1027 // Pump in order to trigger -[NSWindow endSheet:..], which will block while |
981 // the animation runs, then delete |sheet_widget|. | 1028 // the animation runs, then delete |sheet_widget|. |
982 TestWidgetObserver widget_observer(sheet_widget); | 1029 TestWidgetObserver widget_observer(sheet_widget); |
983 EXPECT_TRUE([sheet_window delegate]); | 1030 EXPECT_TRUE([sheet_window delegate]); |
984 base::RunLoop().RunUntilIdle(); | 1031 base::RunLoop().RunUntilIdle(); |
985 EXPECT_FALSE([sheet_window delegate]); | 1032 EXPECT_FALSE([sheet_window delegate]); |
986 | 1033 |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 | 1699 |
1653 - (void)dealloc { | 1700 - (void)dealloc { |
1654 if (deallocFlag_) { | 1701 if (deallocFlag_) { |
1655 DCHECK(!*deallocFlag_); | 1702 DCHECK(!*deallocFlag_); |
1656 *deallocFlag_ = true; | 1703 *deallocFlag_ = true; |
1657 } | 1704 } |
1658 [super dealloc]; | 1705 [super dealloc]; |
1659 } | 1706 } |
1660 | 1707 |
1661 @end | 1708 @end |
OLD | NEW |