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/cocoa/bridged_native_widget.h" | 5 #import "ui/views/cocoa/bridged_native_widget.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 #import "base/mac/mac_util.h" |
10 #import "base/mac/sdk_forward_declarations.h" | 11 #import "base/mac/sdk_forward_declarations.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
14 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #import "testing/gtest_mac.h" | 17 #import "testing/gtest_mac.h" |
17 #import "ui/gfx/test/ui_cocoa_test_helper.h" | 18 #import "ui/gfx/test/ui_cocoa_test_helper.h" |
18 #import "ui/views/cocoa/bridged_content_view.h" | 19 #import "ui/views/cocoa/bridged_content_view.h" |
19 #include "ui/views/controls/textfield/textfield.h" | 20 #include "ui/views/controls/textfield/textfield.h" |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 [ns_view_ doCommandBySelector:@selector(moveLeft:)]; | 528 [ns_view_ doCommandBySelector:@selector(moveLeft:)]; |
528 [ns_view_ doCommandBySelector:@selector(deleteForward:)]; | 529 [ns_view_ doCommandBySelector:@selector(deleteForward:)]; |
529 EXPECT_EQ("", GetText()); | 530 EXPECT_EQ("", GetText()); |
530 EXPECT_EQ_RANGE(NSMakeRange(0, 0), [ns_view_ selectedRange]); | 531 EXPECT_EQ_RANGE(NSMakeRange(0, 0), [ns_view_ selectedRange]); |
531 } | 532 } |
532 | 533 |
533 // Tests for correct fullscreen tracking, regardless of whether it is initiated | 534 // Tests for correct fullscreen tracking, regardless of whether it is initiated |
534 // by the Widget code or elsewhere (e.g. by the user). | 535 // by the Widget code or elsewhere (e.g. by the user). |
535 TEST_F(BridgedNativeWidgetTest, FullscreenSynchronousState) { | 536 TEST_F(BridgedNativeWidgetTest, FullscreenSynchronousState) { |
536 EXPECT_FALSE(widget_->IsFullscreen()); | 537 EXPECT_FALSE(widget_->IsFullscreen()); |
| 538 if (base::mac::IsOSSnowLeopard()) |
| 539 return; |
| 540 |
537 // Allow user-initiated fullscreen changes on the Window. | 541 // Allow user-initiated fullscreen changes on the Window. |
538 [test_window() | 542 [test_window() |
539 setCollectionBehavior:[test_window() collectionBehavior] | | 543 setCollectionBehavior:[test_window() collectionBehavior] | |
540 NSWindowCollectionBehaviorFullScreenPrimary]; | 544 NSWindowCollectionBehaviorFullScreenPrimary]; |
541 | 545 |
542 base::scoped_nsobject<NativeWidgetMacNotificationWaiter> waiter( | 546 base::scoped_nsobject<NativeWidgetMacNotificationWaiter> waiter( |
543 [[NativeWidgetMacNotificationWaiter alloc] initWithWindow:test_window()]); | 547 [[NativeWidgetMacNotificationWaiter alloc] initWithWindow:test_window()]); |
544 const gfx::Rect restored_bounds = widget_->GetRestoredBounds(); | 548 const gfx::Rect restored_bounds = widget_->GetRestoredBounds(); |
545 | 549 |
546 // Simulate a user-initiated fullscreen. Note trying to to this again before | 550 // Simulate a user-initiated fullscreen. Note trying to to this again before |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 base::scoped_nsobject<NativeWidgetMacNotificationWaiter> waiter( | 591 base::scoped_nsobject<NativeWidgetMacNotificationWaiter> waiter( |
588 [[NativeWidgetMacNotificationWaiter alloc] initWithWindow:test_window()]); | 592 [[NativeWidgetMacNotificationWaiter alloc] initWithWindow:test_window()]); |
589 | 593 |
590 EXPECT_FALSE(widget_->IsFullscreen()); | 594 EXPECT_FALSE(widget_->IsFullscreen()); |
591 const gfx::Rect restored_bounds = widget_->GetRestoredBounds(); | 595 const gfx::Rect restored_bounds = widget_->GetRestoredBounds(); |
592 EXPECT_FALSE(restored_bounds.IsEmpty()); | 596 EXPECT_FALSE(restored_bounds.IsEmpty()); |
593 | 597 |
594 // Ensure this works without having to change collection behavior as for the | 598 // Ensure this works without having to change collection behavior as for the |
595 // test above. | 599 // test above. |
596 widget_->SetFullscreen(true); | 600 widget_->SetFullscreen(true); |
| 601 if (base::mac::IsOSSnowLeopard()) { |
| 602 // On Snow Leopard, SetFullscreen() isn't implemented. But shouldn't crash. |
| 603 EXPECT_FALSE(widget_->IsFullscreen()); |
| 604 return; |
| 605 } |
| 606 |
597 EXPECT_TRUE(widget_->IsFullscreen()); | 607 EXPECT_TRUE(widget_->IsFullscreen()); |
598 EXPECT_EQ(restored_bounds, widget_->GetRestoredBounds()); | 608 EXPECT_EQ(restored_bounds, widget_->GetRestoredBounds()); |
599 | 609 |
600 // Should be zero until the runloop spins. | 610 // Should be zero until the runloop spins. |
601 EXPECT_EQ(0, [waiter enterCount]); | 611 EXPECT_EQ(0, [waiter enterCount]); |
602 [waiter waitForEnterCount:1 exitCount:0]; | 612 [waiter waitForEnterCount:1 exitCount:0]; |
603 | 613 |
604 // Verify it hasn't exceeded. | 614 // Verify it hasn't exceeded. |
605 EXPECT_EQ(1, [waiter enterCount]); | 615 EXPECT_EQ(1, [waiter enterCount]); |
606 EXPECT_EQ(0, [waiter exitCount]); | 616 EXPECT_EQ(0, [waiter exitCount]); |
(...skipping 11 matching lines...) Expand all Loading... |
618 } | 628 } |
619 | 629 |
620 typedef BridgedNativeWidgetTestBase BridgedNativeWidgetSimulateFullscreenTest; | 630 typedef BridgedNativeWidgetTestBase BridgedNativeWidgetSimulateFullscreenTest; |
621 | 631 |
622 // Simulate the notifications that AppKit would send out if a fullscreen | 632 // Simulate the notifications that AppKit would send out if a fullscreen |
623 // operation begins, and then fails and must abort. This notification sequence | 633 // operation begins, and then fails and must abort. This notification sequence |
624 // was determined by posting delayed tasks to toggle fullscreen state and then | 634 // was determined by posting delayed tasks to toggle fullscreen state and then |
625 // mashing Ctrl+Left/Right to keep OSX in a transition between Spaces to cause | 635 // mashing Ctrl+Left/Right to keep OSX in a transition between Spaces to cause |
626 // the fullscreen transition to fail. | 636 // the fullscreen transition to fail. |
627 TEST_F(BridgedNativeWidgetSimulateFullscreenTest, FailToEnterAndExit) { | 637 TEST_F(BridgedNativeWidgetSimulateFullscreenTest, FailToEnterAndExit) { |
| 638 if (base::mac::IsOSSnowLeopard()) |
| 639 return; |
| 640 |
628 base::scoped_nsobject<NSWindow> owned_window( | 641 base::scoped_nsobject<NSWindow> owned_window( |
629 [[BridgedNativeWidgetTestFullScreenWindow alloc] | 642 [[BridgedNativeWidgetTestFullScreenWindow alloc] |
630 initWithContentRect:NSMakeRect(50, 50, 400, 300) | 643 initWithContentRect:NSMakeRect(50, 50, 400, 300) |
631 styleMask:NSBorderlessWindowMask | 644 styleMask:NSBorderlessWindowMask |
632 backing:NSBackingStoreBuffered | 645 backing:NSBackingStoreBuffered |
633 defer:YES]); | 646 defer:YES]); |
634 [owned_window setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. | 647 [owned_window setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. |
635 bridge()->Init(owned_window, Widget::InitParams()); // Transfers ownership. | 648 bridge()->Init(owned_window, Widget::InitParams()); // Transfers ownership. |
636 | 649 |
637 BridgedNativeWidgetTestFullScreenWindow* window = | 650 BridgedNativeWidgetTestFullScreenWindow* window = |
(...skipping 12 matching lines...) Expand all Loading... |
650 // On a failure, Cocoa starts by sending an unexpected *exit* fullscreen, and | 663 // On a failure, Cocoa starts by sending an unexpected *exit* fullscreen, and |
651 // BridgedNativeWidget will think it's just a delayed transition and try to go | 664 // BridgedNativeWidget will think it's just a delayed transition and try to go |
652 // back into fullscreen but get ignored by Cocoa. | 665 // back into fullscreen but get ignored by Cocoa. |
653 EXPECT_EQ(0, [window ignoredToggleFullScreenCount]); | 666 EXPECT_EQ(0, [window ignoredToggleFullScreenCount]); |
654 EXPECT_TRUE(bridge()->target_fullscreen_state()); | 667 EXPECT_TRUE(bridge()->target_fullscreen_state()); |
655 [center postNotificationName:NSWindowDidExitFullScreenNotification | 668 [center postNotificationName:NSWindowDidExitFullScreenNotification |
656 object:window]; | 669 object:window]; |
657 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); | 670 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); |
658 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 671 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
659 | 672 |
660 // Cocoa follows up with a failure notification. | 673 // Cocoa follows up with a failure message sent to the NSWindowDelegate (there |
661 [center postNotificationName:NSWindowDidFailToEnterFullScreenNotification | 674 // is no equivalent notification for failure). Called via id so that this |
662 object:window]; | 675 // compiles on 10.6. |
| 676 id window_delegate = [window delegate]; |
| 677 [window_delegate windowDidFailToEnterFullScreen:window]; |
663 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 678 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
664 | 679 |
665 // Now perform a successful fullscreen operation. | 680 // Now perform a successful fullscreen operation. |
666 [center postNotificationName:NSWindowWillEnterFullScreenNotification | 681 [center postNotificationName:NSWindowWillEnterFullScreenNotification |
667 object:window]; | 682 object:window]; |
668 EXPECT_TRUE(bridge()->target_fullscreen_state()); | 683 EXPECT_TRUE(bridge()->target_fullscreen_state()); |
669 [center postNotificationName:NSWindowDidEnterFullScreenNotification | 684 [center postNotificationName:NSWindowDidEnterFullScreenNotification |
670 object:window]; | 685 object:window]; |
671 EXPECT_TRUE(bridge()->target_fullscreen_state()); | 686 EXPECT_TRUE(bridge()->target_fullscreen_state()); |
672 | 687 |
673 // And try to get out. | 688 // And try to get out. |
674 [center postNotificationName:NSWindowWillExitFullScreenNotification | 689 [center postNotificationName:NSWindowWillExitFullScreenNotification |
675 object:window]; | 690 object:window]; |
676 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 691 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
677 | 692 |
678 // On a failure, Cocoa sends a failure notification, but then just dumps the | 693 // On a failure, Cocoa sends a failure message, but then just dumps the window |
679 // Window out of fullscreen anyway (in that order). | 694 // out of fullscreen anyway (in that order). |
680 [center postNotificationName:NSWindowDidFailToExitFullScreenNotification | 695 [window_delegate windowDidFailToExitFullScreen:window]; |
681 object:window]; | |
682 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 696 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
683 [center postNotificationName:NSWindowDidExitFullScreenNotification | 697 [center postNotificationName:NSWindowDidExitFullScreenNotification |
684 object:window]; | 698 object:window]; |
685 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 699 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
686 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 700 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
687 | 701 |
688 widget_->CloseNow(); | 702 widget_->CloseNow(); |
689 } | 703 } |
690 | 704 |
691 } // namespace test | 705 } // namespace test |
692 } // namespace views | 706 } // namespace views |
OLD | NEW |