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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "chrome/browser/ui/cocoa/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
11 #import "base/mac/scoped_objc_class_swizzler.h"
11 #include "chrome/app/chrome_command_ids.h" 12 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/ui/browser_list.h" 14 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
16 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
15 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 17 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
16 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
17 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 18 #include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
18 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" 19 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h"
19 #include "chrome/browser/ui/cocoa/test/run_loop_testing.h" 20 #include "chrome/browser/ui/cocoa/test/run_loop_testing.h"
20 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 21 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "components/bookmarks/common/bookmark_pref_names.h" 24 #include "components/bookmarks/common/bookmark_pref_names.h"
24 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
25 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
26 #include "content/public/test/test_utils.h" 27 #include "content/public/test/test_utils.h"
27 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
28 #import "testing/gtest_mac.h" 29 #import "testing/gtest_mac.h"
29 #import "third_party/ocmock/OCMock/OCMock.h" 30 #import "third_party/ocmock/OCMock/OCMock.h"
30 #import "ui/base/test/scoped_fake_nswindow_fullscreen.h" 31 #import "ui/base/test/scoped_fake_nswindow_fullscreen.h"
31 32
32 using ::testing::Return; 33 using ::testing::Return;
33 34
34 @interface BrowserWindowController (JustForTesting) 35 @interface BrowserWindowController (JustForTesting)
35 // Already defined in BWC. 36 // Already defined in BWC.
36 - (void)saveWindowPositionIfNeeded; 37 - (void)saveWindowPositionIfNeeded;
37 - (void)layoutSubviews; 38 - (void)layoutSubviews;
38 @end 39 @end
39 40
40 @interface BrowserWindowController (ExposedForTesting) 41 @interface BrowserWindowController (ExposedForTesting)
41 // Implementations are below. 42 // Implementations are below.
42 - (NSView*)infoBarContainerView; 43 - (NSView*)infoBarContainerView;
43 - (NSView*)toolbarView; 44 - (NSView*)toolbarView;
44 - (NSView*)bookmarkView; 45 - (NSView*)bookmarkView;
45 - (BOOL)bookmarkBarVisible; 46 - (BOOL)bookmarkBarVisible;
47 - (void)dontFocusLocationBar:(BOOL)selectAll;
46 @end 48 @end
47 49
48 @implementation BrowserWindowController (ExposedForTesting) 50 @implementation BrowserWindowController (ExposedForTesting)
49 - (NSView*)infoBarContainerView { 51 - (NSView*)infoBarContainerView {
50 return [infoBarContainerController_ view]; 52 return [infoBarContainerController_ view];
51 } 53 }
52 54
53 - (NSView*)toolbarView { 55 - (NSView*)toolbarView {
54 return [toolbarController_ view]; 56 return [toolbarController_ view];
55 } 57 }
56 58
57 - (NSView*)bookmarkView { 59 - (NSView*)bookmarkView {
58 return [bookmarkBarController_ view]; 60 return [bookmarkBarController_ view];
59 } 61 }
60 62
61 - (NSView*)findBarView { 63 - (NSView*)findBarView {
62 return [findBarCocoaController_ view]; 64 return [findBarCocoaController_ view];
63 } 65 }
64 66
65 - (BOOL)bookmarkBarVisible { 67 - (BOOL)bookmarkBarVisible {
66 return [bookmarkBarController_ isVisible]; 68 return [bookmarkBarController_ isVisible];
67 } 69 }
70
71 - (void)dontFocusLocationBar:(BOOL)selectAll {
72 }
68 @end 73 @end
69 74
70 class BrowserWindowControllerTest : public CocoaProfileTest { 75 class BrowserWindowControllerTest : public CocoaProfileTest {
71 public: 76 public:
72 void SetUp() override { 77 void SetUp() override {
73 CocoaProfileTest::SetUp(); 78 CocoaProfileTest::SetUp();
74 ASSERT_TRUE(browser()); 79 ASSERT_TRUE(browser());
75 80
76 controller_ = [[BrowserWindowController alloc] initWithBrowser:browser() 81 controller_ = [[BrowserWindowController alloc] initWithBrowser:browser()
77 takeOwnership:NO]; 82 takeOwnership:NO];
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 content::NotificationService::AllSources()); 806 content::NotificationService::AllSources());
802 observer.Wait(); 807 observer.Wait();
803 } 808 }
804 809
805 // http://crbug.com/53586 810 // http://crbug.com/53586
806 TEST_F(BrowserWindowFullScreenControllerTest, TestFullscreen) { 811 TEST_F(BrowserWindowFullScreenControllerTest, TestFullscreen) {
807 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; 812 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
808 [controller_ showWindow:nil]; 813 [controller_ showWindow:nil];
809 EXPECT_FALSE([controller_ isInAnyFullscreenMode]); 814 EXPECT_FALSE([controller_ isInAnyFullscreenMode]);
810 815
816 // The fix for http://crbug.com/447740 , where the omnibox would lose focus
817 // when switching between normal and fullscreen modes, makes some changes to
818 // -[BrowserWindowController setContentViewSubviews:]. Those changes appear
819 // to have extended the lifetime of the browser window during this test -
820 // specifically, the browser window is no longer visible, but it has not been
821 // fully freed (possibly being kept around by a reference from the
822 // autocompleteTextView). As a result the window still appears in
823 // -[NSApplication windows] and causes the test to fail. To get around this
824 // problem, I disable -[BrowserWindowController focusLocationBar:] and later
825 // force the window to clear its first responder.
826 base::mac::ScopedObjCClassSwizzler tmpSwizzler(
827 [BrowserWindowController class], @selector(focusLocationBar:),
828 @selector(dontFocusLocationBar:));
829
811 [controller_ enterBrowserFullscreen]; 830 [controller_ enterBrowserFullscreen];
812 WaitForFullScreenTransition(); 831 WaitForFullScreenTransition();
813 EXPECT_TRUE([controller_ isInAnyFullscreenMode]); 832 EXPECT_TRUE([controller_ isInAnyFullscreenMode]);
814 833
815 [controller_ exitAnyFullscreen]; 834 [controller_ exitAnyFullscreen];
816 WaitForFullScreenTransition(); 835 WaitForFullScreenTransition();
817 EXPECT_FALSE([controller_ isInAnyFullscreenMode]); 836 EXPECT_FALSE([controller_ isInAnyFullscreenMode]);
837
838 [[controller_ window] makeFirstResponder:nil];
818 } 839 }
819 840
820 // If this test fails, it is usually a sign that the bots have some sort of 841 // If this test fails, it is usually a sign that the bots have some sort of
821 // problem (such as a modal dialog up). This tests is a very useful canary, so 842 // problem (such as a modal dialog up). This tests is a very useful canary, so
822 // please do not mark it as flaky without first verifying that there are no bot 843 // please do not mark it as flaky without first verifying that there are no bot
823 // problems. 844 // problems.
824 // http://crbug.com/53586 845 // http://crbug.com/53586
825 TEST_F(BrowserWindowFullScreenControllerTest, TestActivate) { 846 TEST_F(BrowserWindowFullScreenControllerTest, TestActivate) {
826 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen; 847 ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
827 [controller_ showWindow:nil]; 848 [controller_ showWindow:nil];
828 849
829 EXPECT_FALSE([controller_ isInAnyFullscreenMode]); 850 EXPECT_FALSE([controller_ isInAnyFullscreenMode]);
830 851
831 [controller_ activate]; 852 [controller_ activate];
832 chrome::testing::NSRunLoopRunAllPending(); 853 chrome::testing::NSRunLoopRunAllPending();
833 EXPECT_TRUE(IsFrontWindow([controller_ window])); 854 EXPECT_TRUE(IsFrontWindow([controller_ window]));
834 855
856 // See the comment in TestFullscreen for an explanation of this
857 // swizzling and the makeFirstResponder:nil call below.
858 base::mac::ScopedObjCClassSwizzler tmpSwizzler(
859 [BrowserWindowController class], @selector(focusLocationBar:),
860 @selector(dontFocusLocationBar:));
861
835 [controller_ enterBrowserFullscreen]; 862 [controller_ enterBrowserFullscreen];
836 WaitForFullScreenTransition(); 863 WaitForFullScreenTransition();
837 [controller_ activate]; 864 [controller_ activate];
838 chrome::testing::NSRunLoopRunAllPending(); 865 chrome::testing::NSRunLoopRunAllPending();
839 866
840 // We have to cleanup after ourselves by unfullscreening. 867 // We have to cleanup after ourselves by unfullscreening.
841 [controller_ exitAnyFullscreen]; 868 [controller_ exitAnyFullscreen];
842 WaitForFullScreenTransition(); 869 WaitForFullScreenTransition();
870
871 [[controller_ window] makeFirstResponder:nil];
843 } 872 }
844 873
845 @implementation BrowserWindowControllerFakeFullscreen 874 @implementation BrowserWindowControllerFakeFullscreen
846 // Override |-createFullscreenWindow| to return a dummy window. This isn't 875 // Override |-createFullscreenWindow| to return a dummy window. This isn't
847 // needed to pass the test, but because the dummy window is only 100x100, it 876 // needed to pass the test, but because the dummy window is only 100x100, it
848 // prevents the real fullscreen window from flashing up and taking over the 877 // prevents the real fullscreen window from flashing up and taking over the
849 // whole screen. We have to return an actual window because |-layoutSubviews| 878 // whole screen. We have to return an actual window because |-layoutSubviews|
850 // looks at the window's frame. 879 // looks at the window's frame.
851 - (NSWindow*)createFullscreenWindow { 880 - (NSWindow*)createFullscreenWindow {
852 if (testFullscreenWindow_.get()) 881 if (testFullscreenWindow_.get())
853 return testFullscreenWindow_.get(); 882 return testFullscreenWindow_.get();
854 883
855 testFullscreenWindow_.reset( 884 testFullscreenWindow_.reset(
856 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) 885 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400)
857 styleMask:NSBorderlessWindowMask 886 styleMask:NSBorderlessWindowMask
858 backing:NSBackingStoreBuffered 887 backing:NSBackingStoreBuffered
859 defer:NO]); 888 defer:NO]);
860 [[testFullscreenWindow_ contentView] setWantsLayer:YES]; 889 [[testFullscreenWindow_ contentView] setWantsLayer:YES];
861 return testFullscreenWindow_.get(); 890 return testFullscreenWindow_.get();
862 } 891 }
863 @end 892 @end
864 893
865 /* TODO(???): test other methods of BrowserWindowController */ 894 /* TODO(???): test other methods of BrowserWindowController */
OLDNEW
« 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