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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm

Issue 2086273003: [Mac] Reveal Fullscreen Toolbar for Tab Strip Changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scoped_nsobject Created 4 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <stddef.h> 7 #include <stddef.h>
8 #import "base/mac/mac_util.h" 8 #import "base/mac/mac_util.h"
9 9
10 #include "base/mac/sdk_forward_declarations.h" 10 #include "base/mac/sdk_forward_declarations.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/devtools/devtools_window_testing.h" 17 #include "chrome/browser/devtools/devtools_window_testing.h"
18 #include "chrome/browser/infobars/infobar_service.h" 18 #include "chrome/browser/infobars/infobar_service.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" 21 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
22 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_commands.h" 23 #include "chrome/browser/ui/browser_commands.h"
24 #include "chrome/browser/ui/browser_list.h" 24 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/browser/ui/browser_navigator.h"
26 #include "chrome/browser/ui/browser_navigator_params.h"
25 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
26 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" 28 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
27 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" 29 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
28 #import "chrome/browser/ui/cocoa/fast_resize_view.h" 30 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
29 #import "chrome/browser/ui/cocoa/history_overlay_controller.h" 31 #import "chrome/browser/ui/cocoa/history_overlay_controller.h"
30 #import "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" 32 #import "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h"
31 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 33 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
32 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" 34 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h"
33 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 35 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
34 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" 36 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h"
35 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" 37 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h"
36 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" 38 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h"
37 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 39 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
40 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
38 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" 41 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
39 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" 42 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h"
40 #include "chrome/browser/ui/extensions/application_launch.h" 43 #include "chrome/browser/ui/extensions/application_launch.h"
41 #include "chrome/browser/ui/find_bar/find_bar.h" 44 #include "chrome/browser/ui/find_bar/find_bar.h"
42 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 45 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
43 #include "chrome/browser/ui/infobar_container_delegate.h" 46 #include "chrome/browser/ui/infobar_container_delegate.h"
44 #include "chrome/browser/ui/tabs/tab_strip_model.h" 47 #include "chrome/browser/ui/tabs/tab_strip_model.h"
45 #include "chrome/common/pref_names.h" 48 #include "chrome/common/pref_names.h"
46 #include "chrome/test/base/in_process_browser_test.h" 49 #include "chrome/test/base/in_process_browser_test.h"
47 #include "chrome/test/base/testing_profile.h" 50 #include "chrome/test/base/testing_profile.h"
48 #include "components/infobars/core/infobar_delegate.h" 51 #include "components/infobars/core/infobar_delegate.h"
49 #include "components/infobars/core/simple_alert_infobar_delegate.h" 52 #include "components/infobars/core/simple_alert_infobar_delegate.h"
50 #include "content/public/browser/web_contents.h" 53 #include "content/public/browser/web_contents.h"
54 #include "content/public/test/browser_test_utils.h"
51 #include "content/public/test/test_utils.h" 55 #include "content/public/test/test_utils.h"
52 #import "testing/gtest_mac.h" 56 #import "testing/gtest_mac.h"
53 #import "third_party/ocmock/OCMock/OCMock.h" 57 #import "third_party/ocmock/OCMock/OCMock.h"
54 #import "ui/base/cocoa/nsview_additions.h" 58 #import "ui/base/cocoa/nsview_additions.h"
55 #include "ui/gfx/animation/slide_animation.h" 59 #include "ui/gfx/animation/slide_animation.h"
56 #include "ui/gfx/vector_icons_public.h" 60 #include "ui/gfx/vector_icons_public.h"
57 61
58 namespace { 62 namespace {
59 63
60 // Creates a mock of an NSWindow that has the given |frame|. 64 // Creates a mock of an NSWindow that has the given |frame|.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 178
175 // Exceptions are allowed to overlap |exposed_view_|. Exceptions must still 179 // Exceptions are allowed to overlap |exposed_view_|. Exceptions must still
176 // be Z-order behind |exposed_view_|. 180 // be Z-order behind |exposed_view_|.
177 base::scoped_nsobject<NSArray> exceptions_; 181 base::scoped_nsobject<NSArray> exceptions_;
178 182
179 DISALLOW_COPY_AND_ASSIGN(ViewExposedChecker); 183 DISALLOW_COPY_AND_ASSIGN(ViewExposedChecker);
180 }; 184 };
181 185
182 } // namespace 186 } // namespace
183 187
188 // Mock PresentationModeController used to test if the toolbar reveal animation
189 // is called correctly.
190 @interface MockPresentationModeController : PresentationModeController
191
192 // True if revealToolbarForTabStripChanges was called.
193 @property(nonatomic, assign) BOOL isRevealingToolbarForTabstrip;
194
195 // Initializer.
196 - (id)initWithBrowserController:(BrowserWindowController*)controller;
197
198 // Sets isRevealingToolbarForTabstrip back to false.
199 - (void)resetToolbarFlag;
200
201 // Overridden to set isRevealingToolbarForTabstrip to true when it's called.
202 - (void)revealToolbarForTabStripChanges;
203
204 // Overridden so that we don't have to deal with the DCHECKs when the
205 // BWC exits fullscreen.
206 - (void)exitPresentationMode;
207
208 @end
209
210 @implementation MockPresentationModeController
211
212 @synthesize isRevealingToolbarForTabstrip = isRevealingToolbarForTabstrip_;
213
214 - (id)initWithBrowserController:(BrowserWindowController*)controller {
215 if ((self = [super
216 initWithBrowserController:controller
217 style:fullscreen_mac::OMNIBOX_TABS_HIDDEN])) {
218 }
219
220 return self;
221 }
222
223 - (void)resetToolbarFlag {
224 isRevealingToolbarForTabstrip_ = NO;
225 }
226
227 - (void)revealToolbarForTabStripChanges {
228 isRevealingToolbarForTabstrip_ = YES;
229 }
230
231 - (void)exitPresentationMode {
232 }
233
234 @end
235
184 @interface InfoBarContainerController(TestingAPI) 236 @interface InfoBarContainerController(TestingAPI)
185 - (BOOL)isTopInfoBarAnimationRunning; 237 - (BOOL)isTopInfoBarAnimationRunning;
186 @end 238 @end
187 239
188 @implementation InfoBarContainerController(TestingAPI) 240 @implementation InfoBarContainerController(TestingAPI)
189 - (BOOL)isTopInfoBarAnimationRunning { 241 - (BOOL)isTopInfoBarAnimationRunning {
190 InfoBarController* infoBarController = [infobarControllers_ objectAtIndex:0]; 242 InfoBarController* infoBarController = [infobarControllers_ objectAtIndex:0];
191 if (infoBarController) { 243 if (infoBarController) {
192 const gfx::SlideAnimation& infobarAnimation = 244 const gfx::SlideAnimation& infobarAnimation =
193 static_cast<const InfoBarCocoa*>( 245 static_cast<const InfoBarCocoa*>(
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 waiter->Wait(); 435 waiter->Wait();
384 } 436 }
385 437
386 // Verifies that the flags |blockLayoutSubviews_| and |blockFullscreenResize| 438 // Verifies that the flags |blockLayoutSubviews_| and |blockFullscreenResize|
387 // are false. 439 // are false.
388 void VerifyFullscreenResizeFlagsAfterTransition() { 440 void VerifyFullscreenResizeFlagsAfterTransition() {
389 ASSERT_FALSE([controller() isLayoutSubviewsBlocked]); 441 ASSERT_FALSE([controller() isLayoutSubviewsBlocked]);
390 ASSERT_FALSE([controller() isActiveTabContentsControllerResizeBlocked]); 442 ASSERT_FALSE([controller() isActiveTabContentsControllerResizeBlocked]);
391 } 443 }
392 444
445 // Inserts a new tab into the tabstrip at the background.
446 void AddTabAtBackground(int index, GURL url) {
447 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK);
448 params.tabstrip_index = index;
449 params.disposition = NEW_BACKGROUND_TAB;
450 chrome::Navigate(&params);
451 content::WaitForLoadStopWithoutSuccessCheck(params.target_contents);
452 }
453
393 private: 454 private:
394 DISALLOW_COPY_AND_ASSIGN(BrowserWindowControllerTest); 455 DISALLOW_COPY_AND_ASSIGN(BrowserWindowControllerTest);
395 }; 456 };
396 457
397 // Tests that adding the first profile moves the Lion fullscreen button over 458 // Tests that adding the first profile moves the Lion fullscreen button over
398 // correctly. 459 // correctly.
399 // DISABLED_ because it regularly times out: http://crbug.com/159002. 460 // DISABLED_ because it regularly times out: http://crbug.com/159002.
400 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, 461 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
401 DISABLED_ProfileAvatarFullscreenButton) { 462 DISABLED_ProfileAvatarFullscreenButton) {
402 // Initialize the locals. 463 // Initialize the locals.
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 // Toggle out and back into fullscreen and verify that the toolbar is still 770 // Toggle out and back into fullscreen and verify that the toolbar is still
710 // hidden. 771 // hidden.
711 ToggleFullscreenAndWaitForNotification(); 772 ToggleFullscreenAndWaitForNotification();
712 ToggleFullscreenAndWaitForNotification(); 773 ToggleFullscreenAndWaitForNotification();
713 [[controller() presentationModeController] setMenuBarRevealProgress:0.0]; 774 [[controller() presentationModeController] setMenuBarRevealProgress:0.0];
714 VerifyFullscreenToolbarVisibility(fullscreen_mac::OMNIBOX_TABS_HIDDEN); 775 VerifyFullscreenToolbarVisibility(fullscreen_mac::OMNIBOX_TABS_HIDDEN);
715 776
716 chrome::ExecuteCommand(browser(), IDC_TOGGLE_FULLSCREEN_TOOLBAR); 777 chrome::ExecuteCommand(browser(), IDC_TOGGLE_FULLSCREEN_TOOLBAR);
717 EXPECT_TRUE(prefs->GetBoolean(prefs::kShowFullscreenToolbar)); 778 EXPECT_TRUE(prefs->GetBoolean(prefs::kShowFullscreenToolbar));
718 } 779 }
780
781 // Tests that the toolbar (tabstrip and omnibox) reveal animation is correctly
782 // triggered by the changes in the tabstrip. The animation should not trigger
783 // if the current tab is a NTP, since the location bar would be focused.
784 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
785 FullscreenToolbarExposedForTabstripChanges) {
786 base::scoped_nsobject<MockPresentationModeController>
787 presentationModeController([[MockPresentationModeController alloc]
788 initWithBrowserController:controller()]);
789 [controller() setPresentationModeController:presentationModeController.get()];
790
791 ToggleFullscreenAndWaitForNotification();
792
793 // Insert a non-NTP new tab in the foreground.
794 AddTabAtIndex(0, GURL("http://google.com"), ui::PAGE_TRANSITION_LINK);
795 ASSERT_FALSE([[controller() toolbarController] isLocationBarFocused]);
796 EXPECT_TRUE([presentationModeController isRevealingToolbarForTabstrip]);
797 [presentationModeController resetToolbarFlag];
798
799 // Insert a new tab in the background.
800 AddTabAtBackground(0, GURL("about:blank"));
801 EXPECT_TRUE([presentationModeController isRevealingToolbarForTabstrip]);
802 [presentationModeController resetToolbarFlag];
803
804 // Insert a NTP new tab in the foreground.
805 AddTabAtIndex(0, GURL("about:blank"), ui::PAGE_TRANSITION_LINK);
806 ASSERT_TRUE([[controller() toolbarController] isLocationBarFocused]);
807 EXPECT_FALSE([presentationModeController isRevealingToolbarForTabstrip]);
808 [presentationModeController resetToolbarFlag];
809
810 // Insert a new tab in the background. The animation should not be triggered
811 // since the location bar should still be focused.
812 AddTabAtBackground(1, GURL("http://google.com"));
813 ASSERT_TRUE([[controller() toolbarController] isLocationBarFocused]);
814 EXPECT_FALSE([presentationModeController isRevealingToolbarForTabstrip]);
815 [presentationModeController resetToolbarFlag];
816
817 // Switch to a non-NTP tab.
818 TabStripModel* model = browser()->tab_strip_model();
819 model->ActivateTabAt(1, true);
820 ASSERT_FALSE([[controller() toolbarController] isLocationBarFocused]);
821 EXPECT_TRUE([presentationModeController isRevealingToolbarForTabstrip]);
822 [presentationModeController resetToolbarFlag];
823 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.mm ('k') | chrome/browser/ui/cocoa/presentation_mode_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698