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

Unified Diff: ui/views/widget/native_widget_mac_unittest.mm

Issue 1759913004: MacViews: Handling changing of first responder inside NativeWidgetMac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added comment for test. Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 0783ac078c3a1a454fdd1ee49c89f9f0e1b1dd5f..635de898aed2db3dda2792532f0ebdaa202bde43 100644
--- a/ui/views/widget/native_widget_mac_unittest.mm
+++ b/ui/views/widget/native_widget_mac_unittest.mm
@@ -71,6 +71,9 @@
@property(assign, nonatomic) NSRect lastDirtyRect;
@end
+@interface FocusableTestNSView : NSView
+@end
+
namespace views {
namespace test {
@@ -1309,6 +1312,31 @@ TEST_F(NativeWidgetMacTest, SchedulePaintInRect_Borderless) {
widget->CloseNow();
}
+// Ensure traversing NSView focus correctly updates the views::FocusManager.
+TEST_F(NativeWidgetMacTest, ChangeFocusOnChangeFirstResponder) {
+ Widget* widget = CreateTopLevelPlatformWidget();
+ widget->GetRootView()->SetFocusable(true);
+ widget->Show();
+
+ base::scoped_nsobject<NSView> child_view([[FocusableTestNSView alloc]
+ initWithFrame:[widget->GetNativeView() bounds]]);
+ [widget->GetNativeView() addSubview:child_view];
+ EXPECT_TRUE([child_view acceptsFirstResponder]);
+ EXPECT_TRUE(widget->GetRootView()->IsFocusable());
+
+ FocusManager* manager = widget->GetFocusManager();
+ manager->SetFocusedView(widget->GetRootView());
+ EXPECT_EQ(manager->GetFocusedView(), widget->GetRootView());
+
+ [widget->GetNativeWindow() makeFirstResponder:child_view];
+ EXPECT_FALSE(manager->GetFocusedView());
+
+ [widget->GetNativeWindow() makeFirstResponder:widget->GetNativeView()];
+ EXPECT_EQ(manager->GetFocusedView(), widget->GetRootView());
+
+ widget->CloseNow();
+}
+
} // namespace test
} // namespace views
@@ -1340,3 +1368,9 @@ TEST_F(NativeWidgetMacTest, SchedulePaintInRect_Borderless) {
}
@end
+
+@implementation FocusableTestNSView
+- (BOOL)acceptsFirstResponder {
+ return YES;
+}
+@end
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698