| OLD | NEW |
| 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" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 185 |
| 186 } // namespace | 186 } // namespace |
| 187 | 187 |
| 188 // Mock FullscreenToolbarController used to test if the toolbar reveal animation | 188 // Mock FullscreenToolbarController used to test if the toolbar reveal animation |
| 189 // is called correctly. | 189 // is called correctly. |
| 190 @interface MockFullscreenToolbarController : FullscreenToolbarController | 190 @interface MockFullscreenToolbarController : FullscreenToolbarController |
| 191 | 191 |
| 192 // True if revealToolbarForTabStripChanges was called. | 192 // True if revealToolbarForTabStripChanges was called. |
| 193 @property(nonatomic, assign) BOOL isRevealingToolbarForTabstrip; | 193 @property(nonatomic, assign) BOOL isRevealingToolbarForTabstrip; |
| 194 | 194 |
| 195 // Initializer. | |
| 196 - (id)initWithBrowserController:(BrowserWindowController*)controller; | |
| 197 | |
| 198 // Sets isRevealingToolbarForTabstrip back to false. | 195 // Sets isRevealingToolbarForTabstrip back to false. |
| 199 - (void)resetToolbarFlag; | 196 - (void)resetToolbarFlag; |
| 200 | 197 |
| 201 // Overridden to set isRevealingToolbarForTabstrip to true when it's called. | 198 // Overridden to set isRevealingToolbarForTabstrip to true when it's called. |
| 202 - (void)revealToolbarForTabStripChanges; | 199 - (void)revealToolbarForTabStripChanges; |
| 203 | 200 |
| 204 // Overridden so that we don't have to deal with the DCHECKs when the | |
| 205 // BWC exits fullscreen. | |
| 206 - (void)exitFullscreenMode; | |
| 207 | |
| 208 @end | 201 @end |
| 209 | 202 |
| 210 @implementation MockFullscreenToolbarController | 203 @implementation MockFullscreenToolbarController |
| 211 | 204 |
| 212 @synthesize isRevealingToolbarForTabstrip = isRevealingToolbarForTabstrip_; | 205 @synthesize isRevealingToolbarForTabstrip = isRevealingToolbarForTabstrip_; |
| 213 | 206 |
| 214 - (id)initWithBrowserController:(BrowserWindowController*)controller { | |
| 215 if ((self = [super initWithBrowserController:controller | |
| 216 style:FullscreenSlidingStyle:: | |
| 217 OMNIBOX_TABS_HIDDEN])) { | |
| 218 } | |
| 219 | |
| 220 return self; | |
| 221 } | |
| 222 | |
| 223 - (void)resetToolbarFlag { | 207 - (void)resetToolbarFlag { |
| 224 isRevealingToolbarForTabstrip_ = NO; | 208 isRevealingToolbarForTabstrip_ = NO; |
| 225 } | 209 } |
| 226 | 210 |
| 227 - (void)revealToolbarForTabStripChanges { | 211 - (void)revealToolbarForTabStripChanges { |
| 228 isRevealingToolbarForTabstrip_ = YES; | 212 isRevealingToolbarForTabstrip_ = YES; |
| 229 } | 213 } |
| 230 | 214 |
| 231 - (void)exitFullscreenMode { | |
| 232 } | |
| 233 | |
| 234 @end | 215 @end |
| 235 | 216 |
| 236 @interface InfoBarContainerController(TestingAPI) | 217 @interface InfoBarContainerController(TestingAPI) |
| 237 - (BOOL)isTopInfoBarAnimationRunning; | 218 - (BOOL)isTopInfoBarAnimationRunning; |
| 238 @end | 219 @end |
| 239 | 220 |
| 240 @implementation InfoBarContainerController(TestingAPI) | 221 @implementation InfoBarContainerController(TestingAPI) |
| 241 - (BOOL)isTopInfoBarAnimationRunning { | 222 - (BOOL)isTopInfoBarAnimationRunning { |
| 242 InfoBarController* infoBarController = [infobarControllers_ objectAtIndex:0]; | 223 InfoBarController* infoBarController = [infobarControllers_ objectAtIndex:0]; |
| 243 if (infoBarController) { | 224 if (infoBarController) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 base::Timer timer(false, true); | 345 base::Timer timer(false, true); |
| 365 timer.Start( | 346 timer.Start( |
| 366 FROM_HERE, | 347 FROM_HERE, |
| 367 base::TimeDelta::FromMilliseconds(15), | 348 base::TimeDelta::FromMilliseconds(15), |
| 368 base::Bind(&CheckBookmarkBarAnimation, | 349 base::Bind(&CheckBookmarkBarAnimation, |
| 369 [controller() bookmarkBarController], | 350 [controller() bookmarkBarController], |
| 370 runner->QuitClosure())); | 351 runner->QuitClosure())); |
| 371 runner->Run(); | 352 runner->Run(); |
| 372 } | 353 } |
| 373 | 354 |
| 374 void VerifyFullscreenToolbarVisibility(FullscreenSlidingStyle style) { | 355 void VerifyFullscreenToolbarVisibility(FullscreenToolbarStyle style) { |
| 375 EXPECT_EQ([[controller() fullscreenToolbarController] slidingStyle], style); | 356 EXPECT_EQ([[controller() fullscreenToolbarController] toolbarStyle], style); |
| 376 | 357 |
| 377 NSRect toolbarFrame = [[[controller() toolbarController] view] frame]; | 358 NSRect toolbarFrame = [[[controller() toolbarController] view] frame]; |
| 378 NSRect screenFrame = [[[controller() window] screen] frame]; | 359 NSRect screenFrame = [[[controller() window] screen] frame]; |
| 379 if (style == FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT) | 360 if (style == FullscreenToolbarStyle::TOOLBAR_PRESENT) |
| 380 EXPECT_LE(NSMaxY(toolbarFrame), NSMaxY(screenFrame)); | 361 EXPECT_LE(NSMaxY(toolbarFrame), NSMaxY(screenFrame)); |
| 381 else | 362 else |
| 382 EXPECT_GE(NSMinY(toolbarFrame), NSMaxY(screenFrame)); | 363 EXPECT_GE(NSMinY(toolbarFrame), NSMaxY(screenFrame)); |
| 383 } | 364 } |
| 384 | 365 |
| 385 NSInteger GetExpectedTopInfoBarTipHeight() { | 366 NSInteger GetExpectedTopInfoBarTipHeight() { |
| 386 InfoBarContainerController* info_bar_container_controller = | 367 InfoBarContainerController* info_bar_container_controller = |
| 387 [controller() infoBarContainerController]; | 368 [controller() infoBarContainerController]; |
| 388 CGFloat overlapping_tip_height = | 369 CGFloat overlapping_tip_height = |
| 389 [info_bar_container_controller overlappingTipHeight]; | 370 [info_bar_container_controller overlappingTipHeight]; |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 // preferences are updated correctly. | 731 // preferences are updated correctly. |
| 751 // Flakily times out. http://crbug.com/599119 | 732 // Flakily times out. http://crbug.com/599119 |
| 752 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, | 733 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| 753 DISABLED_FullscreenToolbarIsVisibleAccordingToPrefs) { | 734 DISABLED_FullscreenToolbarIsVisibleAccordingToPrefs) { |
| 754 // Tests that the preference is set to true by default. | 735 // Tests that the preference is set to true by default. |
| 755 PrefService* prefs = browser()->profile()->GetPrefs(); | 736 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 756 EXPECT_TRUE(prefs->GetBoolean(prefs::kShowFullscreenToolbar)); | 737 EXPECT_TRUE(prefs->GetBoolean(prefs::kShowFullscreenToolbar)); |
| 757 | 738 |
| 758 // Toggle fullscreen and check if the toolbar is shown. | 739 // Toggle fullscreen and check if the toolbar is shown. |
| 759 ToggleFullscreenAndWaitForNotification(); | 740 ToggleFullscreenAndWaitForNotification(); |
| 760 VerifyFullscreenToolbarVisibility( | 741 VerifyFullscreenToolbarVisibility(FullscreenToolbarStyle::TOOLBAR_PRESENT); |
| 761 FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT); | |
| 762 | 742 |
| 763 // Toggle the visibility of the fullscreen toolbar. Verify that the toolbar | 743 // Toggle the visibility of the fullscreen toolbar. Verify that the toolbar |
| 764 // is hidden and the preference is correctly updated. | 744 // is hidden and the preference is correctly updated. |
| 765 [[controller() fullscreenToolbarController] setMenuBarRevealProgress:0.0]; | 745 [[controller() fullscreenToolbarController] setMenuBarRevealProgress:0.0]; |
| 766 chrome::ExecuteCommand(browser(), IDC_TOGGLE_FULLSCREEN_TOOLBAR); | 746 chrome::ExecuteCommand(browser(), IDC_TOGGLE_FULLSCREEN_TOOLBAR); |
| 767 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowFullscreenToolbar)); | 747 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowFullscreenToolbar)); |
| 768 VerifyFullscreenToolbarVisibility( | 748 VerifyFullscreenToolbarVisibility(FullscreenToolbarStyle::TOOLBAR_HIDDEN); |
| 769 FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN); | |
| 770 | 749 |
| 771 // Toggle out and back into fullscreen and verify that the toolbar is still | 750 // Toggle out and back into fullscreen and verify that the toolbar is still |
| 772 // hidden. | 751 // hidden. |
| 773 ToggleFullscreenAndWaitForNotification(); | 752 ToggleFullscreenAndWaitForNotification(); |
| 774 ToggleFullscreenAndWaitForNotification(); | 753 ToggleFullscreenAndWaitForNotification(); |
| 775 [[controller() fullscreenToolbarController] setMenuBarRevealProgress:0.0]; | 754 [[controller() fullscreenToolbarController] setMenuBarRevealProgress:0.0]; |
| 776 VerifyFullscreenToolbarVisibility( | 755 VerifyFullscreenToolbarVisibility(FullscreenToolbarStyle::TOOLBAR_HIDDEN); |
| 777 FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN); | |
| 778 | 756 |
| 779 chrome::ExecuteCommand(browser(), IDC_TOGGLE_FULLSCREEN_TOOLBAR); | 757 chrome::ExecuteCommand(browser(), IDC_TOGGLE_FULLSCREEN_TOOLBAR); |
| 780 EXPECT_TRUE(prefs->GetBoolean(prefs::kShowFullscreenToolbar)); | 758 EXPECT_TRUE(prefs->GetBoolean(prefs::kShowFullscreenToolbar)); |
| 781 } | 759 } |
| 782 | 760 |
| 783 // Tests that the toolbar (tabstrip and omnibox) reveal animation is correctly | 761 // Tests that the toolbar (tabstrip and omnibox) reveal animation is correctly |
| 784 // triggered by the changes in the tabstrip. The animation should not trigger | 762 // triggered by the changes in the tabstrip. The animation should not trigger |
| 785 // if the current tab is a NTP, since the location bar would be focused. | 763 // if the current tab is a NTP, since the location bar would be focused. |
| 786 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, | 764 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| 787 FullscreenToolbarExposedForTabstripChanges) { | 765 FullscreenToolbarExposedForTabstripChanges) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 817 EXPECT_FALSE([fullscreenToolbarController isRevealingToolbarForTabstrip]); | 795 EXPECT_FALSE([fullscreenToolbarController isRevealingToolbarForTabstrip]); |
| 818 [fullscreenToolbarController resetToolbarFlag]; | 796 [fullscreenToolbarController resetToolbarFlag]; |
| 819 | 797 |
| 820 // Switch to a non-NTP tab. | 798 // Switch to a non-NTP tab. |
| 821 TabStripModel* model = browser()->tab_strip_model(); | 799 TabStripModel* model = browser()->tab_strip_model(); |
| 822 model->ActivateTabAt(1, true); | 800 model->ActivateTabAt(1, true); |
| 823 ASSERT_FALSE([[controller() toolbarController] isLocationBarFocused]); | 801 ASSERT_FALSE([[controller() toolbarController] isLocationBarFocused]); |
| 824 EXPECT_TRUE([fullscreenToolbarController isRevealingToolbarForTabstrip]); | 802 EXPECT_TRUE([fullscreenToolbarController isRevealingToolbarForTabstrip]); |
| 825 [fullscreenToolbarController resetToolbarFlag]; | 803 [fullscreenToolbarController resetToolbarFlag]; |
| 826 } | 804 } |
| OLD | NEW |