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 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #import "base/mac/foundation_util.h" | 11 #import "base/mac/foundation_util.h" |
12 #import "base/mac/mac_util.h" | 12 #import "base/mac/mac_util.h" |
13 #import "base/mac/scoped_objc_class_swizzler.h" | |
13 #import "base/mac/sdk_forward_declarations.h" | 14 #import "base/mac/sdk_forward_declarations.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
16 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #import "testing/gtest_mac.h" | 19 #import "testing/gtest_mac.h" |
19 #import "ui/base/cocoa/window_size_constants.h" | 20 #import "ui/base/cocoa/window_size_constants.h" |
20 #include "ui/base/ime/input_method.h" | 21 #include "ui/base/ime/input_method.h" |
22 #import "ui/base/test/scoped_fake_full_keyboard_access.h" | |
23 #import "ui/base/test/scoped_fake_nswindow_focus.h" | |
21 #import "ui/gfx/mac/coordinate_conversion.h" | 24 #import "ui/gfx/mac/coordinate_conversion.h" |
22 #import "ui/gfx/test/ui_cocoa_test_helper.h" | 25 #import "ui/gfx/test/ui_cocoa_test_helper.h" |
23 #import "ui/views/cocoa/bridged_content_view.h" | 26 #import "ui/views/cocoa/bridged_content_view.h" |
24 #import "ui/views/cocoa/native_widget_mac_nswindow.h" | 27 #import "ui/views/cocoa/native_widget_mac_nswindow.h" |
25 #import "ui/views/cocoa/views_nswindow_delegate.h" | 28 #import "ui/views/cocoa/views_nswindow_delegate.h" |
26 #include "ui/views/controls/textfield/textfield.h" | 29 #include "ui/views/controls/textfield/textfield.h" |
27 #include "ui/views/view.h" | 30 #include "ui/views/view.h" |
28 #include "ui/views/widget/native_widget_mac.h" | 31 #include "ui/views/widget/native_widget_mac.h" |
29 #include "ui/views/widget/root_view.h" | 32 #include "ui/views/widget/root_view.h" |
30 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
741 [window_delegate windowDidFailToExitFullScreen:window]; | 744 [window_delegate windowDidFailToExitFullScreen:window]; |
742 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 745 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
743 [center postNotificationName:NSWindowDidExitFullScreenNotification | 746 [center postNotificationName:NSWindowDidExitFullScreenNotification |
744 object:window]; | 747 object:window]; |
745 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. | 748 EXPECT_EQ(1, [window ignoredToggleFullScreenCount]); // No change. |
746 EXPECT_FALSE(bridge()->target_fullscreen_state()); | 749 EXPECT_FALSE(bridge()->target_fullscreen_state()); |
747 | 750 |
748 widget_->CloseNow(); | 751 widget_->CloseNow(); |
749 } | 752 } |
750 | 753 |
754 class BridgedNativeWidgetFullKeyboardAccess | |
tapted
2016/04/20 06:05:57
BridgedNativeWidgetFullKeyboardAccessTest
karandeepb
2016/05/03 02:54:12
Done.
| |
755 : public BridgedNativeWidgetTestBase { | |
756 public: | |
757 BridgedNativeWidgetFullKeyboardAccess(); | |
758 ~BridgedNativeWidgetFullKeyboardAccess() override; | |
759 | |
760 // testing::Test: | |
761 void SetUp() override; | |
762 void TearDown() override; | |
763 | |
764 protected: | |
765 std::unique_ptr<views::View> view_; | |
766 base::scoped_nsobject<NSWindow> window_; | |
767 ui::test::ScopedFakeFullKeyboardAccess fake_full_keyboard_access_; | |
768 | |
769 private: | |
770 ui::test::ScopedFakeNSWindowFocus fake_window_focus_; | |
771 | |
772 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetFullKeyboardAccess); | |
773 }; | |
774 | |
775 BridgedNativeWidgetFullKeyboardAccess::BridgedNativeWidgetFullKeyboardAccess() { | |
776 } | |
777 | |
778 BridgedNativeWidgetFullKeyboardAccess:: | |
779 ~BridgedNativeWidgetFullKeyboardAccess() {} | |
tapted
2016/04/20 06:05:57
these can be defined inline
karandeepb
2016/05/03 02:54:12
Done.
| |
780 | |
781 void BridgedNativeWidgetFullKeyboardAccess::SetUp() { | |
782 BridgedNativeWidgetTestBase::SetUp(); | |
783 | |
784 fake_full_keyboard_access_.SetFullKeyboardAccessState(false); | |
785 | |
786 // Don't use test_window() since it has special handling when key. | |
tapted
2016/04/20 06:05:57
It might be easier to use NativeWidgetMacTest -- B
karandeepb
2016/05/03 02:54:12
Done, though it feels like these tests should belo
| |
787 window_.reset([[NativeWidgetMacNSWindow alloc] | |
788 initWithContentRect:NSMakeRect(50, 50, 400, 300) | |
789 styleMask:NSBorderlessWindowMask | |
790 backing:NSBackingStoreBuffered | |
791 defer:NO]); | |
792 [window_ setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. | |
793 | |
794 bridge()->Init(window_, init_params_); | |
795 | |
796 view_.reset(new views::internal::RootView(widget_.get())); | |
797 bridge()->SetRootView(view_.get()); | |
798 [window_ makeFirstResponder:bridge()->ns_view()]; | |
799 | |
800 widget_->Show(); | |
801 } | |
802 | |
803 void BridgedNativeWidgetFullKeyboardAccess::TearDown() { | |
804 widget_->CloseNow(); | |
805 | |
806 // Release |window_| since ui::CocoaTest::TearDown() checks whether all | |
807 // windows have been released. | |
808 window_.reset(); | |
809 BridgedNativeWidgetTestBase::TearDown(); | |
810 } | |
811 | |
812 // Test that updateFullKeyboardAccess method on BridgedContentView correctly | |
813 // sets the keyboard accessibility mode on the associated focus manager. | |
814 TEST_F(BridgedNativeWidgetFullKeyboardAccess, FullKeyboardToggle) { | |
815 EXPECT_FALSE(widget_->GetFocusManager()->keyboard_accessible()); | |
816 fake_full_keyboard_access_.SetFullKeyboardAccessState(true); | |
817 [bridge()->ns_view() updateFullKeyboardAccess]; | |
tapted
2016/04/20 06:05:57
(unless you run into problems, this should be trig
karandeepb
2016/05/03 02:54:12
Can't catch notifications generated via NSDistribu
| |
818 EXPECT_TRUE(widget_->GetFocusManager()->keyboard_accessible()); | |
819 fake_full_keyboard_access_.SetFullKeyboardAccessState(false); | |
820 [bridge()->ns_view() updateFullKeyboardAccess]; | |
821 EXPECT_FALSE(widget_->GetFocusManager()->keyboard_accessible()); | |
822 } | |
823 | |
824 // Test that on initilization, BridgedContentView correctly sets the full | |
825 // keyboard access mode on the associated FocusManager. | |
826 TEST_F(BridgedNativeWidgetFullKeyboardAccess, Initialization) { | |
827 fake_full_keyboard_access_.SetFullKeyboardAccessState(true); | |
828 view_.reset(new views::internal::RootView(widget_.get())); | |
829 bridge()->SetRootView(view_.get()); | |
830 EXPECT_TRUE(widget_->GetFocusManager()->keyboard_accessible()); | |
831 | |
832 fake_full_keyboard_access_.SetFullKeyboardAccessState(false); | |
833 view_.reset(new views::internal::RootView(widget_.get())); | |
834 bridge()->SetRootView(view_.get()); | |
835 EXPECT_FALSE(widget_->GetFocusManager()->keyboard_accessible()); | |
836 } | |
837 | |
838 // Test that the correct keyboard accessibility mode is set when the window | |
839 // becomes active. | |
840 TEST_F(BridgedNativeWidgetFullKeyboardAccess, Activation) { | |
841 EXPECT_FALSE(widget_->GetFocusManager()->keyboard_accessible()); | |
842 | |
843 widget_->Hide(); | |
844 fake_full_keyboard_access_.SetFullKeyboardAccessState(true); | |
845 // [ns_view updateFullKeyboardAccess] is not explicitly called since we may | |
846 // not receive full keyboard access toggle notifications when our | |
847 // application is inactive. | |
848 | |
849 widget_->Show(); | |
850 EXPECT_TRUE(widget_->GetFocusManager()->keyboard_accessible()); | |
851 | |
852 widget_->Hide(); | |
853 fake_full_keyboard_access_.SetFullKeyboardAccessState(false); | |
854 | |
855 widget_->Show(); | |
856 EXPECT_FALSE(widget_->GetFocusManager()->keyboard_accessible()); | |
857 } | |
858 | |
751 } // namespace test | 859 } // namespace test |
752 } // namespace views | 860 } // namespace views |
OLD | NEW |