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

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: Created 4 years, 10 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
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..d0a22ac60d10aec7a061b53b44dc77bc08c64d20 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 FocusedNSView : NSView
tapted 2016/03/04 00:56:19 nit: FocusableTestNSView (name collisions are eas
kirr 2016/03/04 08:31:31 Done.
+@end
+
namespace views {
namespace test {
@@ -1309,6 +1312,30 @@ TEST_F(NativeWidgetMacTest, SchedulePaintInRect_Borderless) {
widget->CloseNow();
}
+TEST_F(NativeWidgetMacTest, ChangeFocusOnChangeFirstResponder) {
+ Widget* widget = CreateTopLevelPlatformWidget();
+ widget->GetRootView()->SetFocusable(true);
+ widget->Show();
+
+ base::scoped_nsobject<NSView> child_view(
+ [[FocusedNSView alloc] initWithFrame:[widget->GetNativeView() bounds]]);
+ [widget->GetNativeView() addSubview:child_view];
+ DCHECK_EQ([child_view acceptsFirstResponder], YES);
tapted 2016/03/04 00:56:19 nit: EXPECT_TRUE
kirr 2016/03/04 08:31:30 Done.
+ DCHECK_EQ(widget->GetRootView()->IsFocusable(), YES);
tapted 2016/03/04 00:56:19 EXPECT_TRUE (somewhat moot here since this won't
kirr 2016/03/04 08:31:30 Done.
+
+ FocusManager* manager = widget->GetFocusManager();
+ manager->SetFocusedView(widget->GetRootView());
+ DCHECK_EQ(manager->GetFocusedView(), widget->GetRootView());
tapted 2016/03/04 00:56:19 EXPECT_EQ
kirr 2016/03/04 08:31:31 Done.
+
+ [widget->GetNativeWindow() makeFirstResponder: child_view];
tapted 2016/03/04 00:56:19 nit: no space before `child_view`
kirr 2016/03/04 08:31:30 Done.
+ DCHECK(!manager->GetFocusedView());
tapted 2016/03/04 00:56:19 EXPECT_FALSE
kirr 2016/03/04 08:31:31 Done.
+
+ [widget->GetNativeWindow() makeFirstResponder: widget->GetNativeView()];
tapted 2016/03/04 00:56:19 nit: no space before `widget`. -- running `git cl
kirr 2016/03/04 08:31:30 Done. "git cl format" - is super helpful. Thanks a
+ DCHECK_EQ(manager->GetFocusedView(), widget->GetRootView());
tapted 2016/03/04 00:56:19 EXPECT_EQ
kirr 2016/03/04 08:31:30 Done.
+
+ widget->CloseNow();
+}
+
} // namespace test
} // namespace views
@@ -1340,3 +1367,10 @@ TEST_F(NativeWidgetMacTest, SchedulePaintInRect_Borderless) {
}
@end
+
+@implementation FocusedNSView
+- (BOOL)acceptsFirstResponder {
+ return YES;
+}
+@end
+
tapted 2016/03/04 00:56:20 nit: remove trailing blank line
kirr 2016/03/04 08:31:30 Done.
« ui/views/cocoa/bridged_content_view.mm ('K') | « 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