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

Unified Diff: chrome/browser/ui/cocoa/browser_window_controller_unittest.mm

Issue 2679273002: [Mac] Retain location bar focus on switching to fullscreen and back. (Closed)
Patch Set: Undo previous change, add comment. Created 3 years, 7 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: chrome/browser/ui/cocoa/browser_window_controller_unittest.mm
diff --git a/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm b/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm
index d89b54124ee5b6e6a898024a51a9a9225ff706b9..dc6174224dd1a150eeec7e6551a03dee83529533 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm
@@ -8,12 +8,13 @@
#include "base/mac/mac_util.h"
#import "base/mac/scoped_nsobject.h"
+#import "base/mac/scoped_objc_class_swizzler.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
-#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#import "chrome/browser/ui/cocoa/fast_resize_view.h"
+#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
#include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h"
#include "chrome/browser/ui/cocoa/test/run_loop_testing.h"
@@ -43,6 +44,7 @@ using ::testing::Return;
- (NSView*)toolbarView;
- (NSView*)bookmarkView;
- (BOOL)bookmarkBarVisible;
+- (void)dontFocusLocationBar:(BOOL)selectAll;
@end
@implementation BrowserWindowController (ExposedForTesting)
@@ -65,6 +67,9 @@ using ::testing::Return;
- (BOOL)bookmarkBarVisible {
return [bookmarkBarController_ isVisible];
}
+
+- (void)dontFocusLocationBar:(BOOL)selectAll {
+}
@end
class BrowserWindowControllerTest : public CocoaProfileTest {
@@ -808,6 +813,20 @@ TEST_F(BrowserWindowFullScreenControllerTest, TestFullscreen) {
[controller_ showWindow:nil];
EXPECT_FALSE([controller_ isInAnyFullscreenMode]);
+ // The fix for http://crbug.com/447740 , where the omnibox would lose focus
+ // when switching between normal and fullscreen modes, makes some changes to
+ // -[BrowserWindowController setContentViewSubviews:]. Those changes appear
+ // to have extended the lifetime of the browser window during this test -
+ // specifically, the browser window is no longer visible, but it has not been
+ // fully freed (possibly being kept around by a reference from the
+ // autocompleteTextView). As a result the window still appears in
+ // -[NSApplication windows] and causes the test to fail. To get around this
+ // problem, I disable -[BrowserWindowController focusLocationBar:] and later
+ // force the window to clear its first responder.
+ base::mac::ScopedObjCClassSwizzler tmpSwizzler(
+ [BrowserWindowController class], @selector(focusLocationBar:),
+ @selector(dontFocusLocationBar:));
+
[controller_ enterBrowserFullscreen];
WaitForFullScreenTransition();
EXPECT_TRUE([controller_ isInAnyFullscreenMode]);
@@ -815,6 +834,8 @@ TEST_F(BrowserWindowFullScreenControllerTest, TestFullscreen) {
[controller_ exitAnyFullscreen];
WaitForFullScreenTransition();
EXPECT_FALSE([controller_ isInAnyFullscreenMode]);
+
+ [[controller_ window] makeFirstResponder:nil];
}
// If this test fails, it is usually a sign that the bots have some sort of
@@ -832,6 +853,12 @@ TEST_F(BrowserWindowFullScreenControllerTest, TestActivate) {
chrome::testing::NSRunLoopRunAllPending();
EXPECT_TRUE(IsFrontWindow([controller_ window]));
+ // See the comment in TestFullscreen for an explanation of this
+ // swizzling and the makeFirstResponder:nil call below.
+ base::mac::ScopedObjCClassSwizzler tmpSwizzler(
+ [BrowserWindowController class], @selector(focusLocationBar:),
+ @selector(dontFocusLocationBar:));
+
[controller_ enterBrowserFullscreen];
WaitForFullScreenTransition();
[controller_ activate];
@@ -840,6 +867,8 @@ TEST_F(BrowserWindowFullScreenControllerTest, TestActivate) {
// We have to cleanup after ourselves by unfullscreening.
[controller_ exitAnyFullscreen];
WaitForFullScreenTransition();
+
+ [[controller_ window] makeFirstResponder:nil];
}
@implementation BrowserWindowControllerFakeFullscreen
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller_private.mm ('k') | chrome/browser/ui/cocoa/toolbar/toolbar_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698