Chromium Code Reviews| 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 #import "base/mac/mac_util.h" | 7 #import "base/mac/mac_util.h" |
| 8 #include "base/mac/sdk_forward_declarations.h" | 8 #include "base/mac/sdk_forward_declarations.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/devtools/devtools_window_testing.h" | 13 #include "chrome/browser/devtools/devtools_window_testing.h" |
| 13 #include "chrome/browser/infobars/infobar_service.h" | 14 #include "chrome/browser/infobars/infobar_service.h" |
| 14 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" | 15 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" | 18 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
| 18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
| 20 #include "chrome/browser/ui/browser_list.h" | 21 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 23 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 23 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" | 24 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
| 24 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 25 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
| 25 #import "chrome/browser/ui/cocoa/history_overlay_controller.h" | 26 #import "chrome/browser/ui/cocoa/history_overlay_controller.h" |
| 26 #import "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" | 27 #import "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" |
| 27 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 28 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 29 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" | |
| 30 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | |
| 28 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 31 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
| 29 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" | 32 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" |
| 30 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" | 33 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" |
| 31 #include "chrome/browser/ui/extensions/application_launch.h" | 34 #include "chrome/browser/ui/extensions/application_launch.h" |
| 32 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 35 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 33 #include "chrome/browser/ui/find_bar/find_bar.h" | 36 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 35 #include "chrome/test/base/in_process_browser_test.h" | 38 #include "chrome/test/base/in_process_browser_test.h" |
| 36 #include "chrome/test/base/testing_profile.h" | 39 #include "chrome/test/base/testing_profile.h" |
| 37 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/test/test_utils.h" | |
| 38 #import "testing/gtest_mac.h" | 42 #import "testing/gtest_mac.h" |
| 43 #include "ui/gfx/animation/slide_animation.h" | |
| 39 | 44 |
| 40 namespace { | 45 namespace { |
| 41 | 46 |
| 42 void CreateProfileCallback(const base::Closure& quit_closure, | 47 void CreateProfileCallback(const base::Closure& quit_closure, |
| 43 Profile* profile, | 48 Profile* profile, |
| 44 Profile::CreateStatus status) { | 49 Profile::CreateStatus status) { |
| 45 EXPECT_TRUE(profile); | 50 EXPECT_TRUE(profile); |
| 46 EXPECT_NE(Profile::CREATE_STATUS_LOCAL_FAIL, status); | 51 EXPECT_NE(Profile::CREATE_STATUS_LOCAL_FAIL, status); |
| 47 EXPECT_NE(Profile::CREATE_STATUS_REMOTE_FAIL, status); | 52 EXPECT_NE(Profile::CREATE_STATUS_REMOTE_FAIL, status); |
| 48 // This will be called multiple times. Wait until the profile is initialized | 53 // This will be called multiple times. Wait until the profile is initialized |
| 49 // fully to quit the loop. | 54 // fully to quit the loop. |
| 50 if (status == Profile::CREATE_STATUS_INITIALIZED) | 55 if (status == Profile::CREATE_STATUS_INITIALIZED) |
| 51 quit_closure.Run(); | 56 quit_closure.Run(); |
| 52 } | 57 } |
| 53 | 58 |
| 54 enum ViewID { | 59 enum ViewID { |
| 55 VIEW_ID_TOOLBAR, | 60 VIEW_ID_TOOLBAR, |
| 56 VIEW_ID_BOOKMARK_BAR, | 61 VIEW_ID_BOOKMARK_BAR, |
| 57 VIEW_ID_INFO_BAR, | 62 VIEW_ID_INFO_BAR, |
| 58 VIEW_ID_FIND_BAR, | 63 VIEW_ID_FIND_BAR, |
| 59 VIEW_ID_DOWNLOAD_SHELF, | 64 VIEW_ID_DOWNLOAD_SHELF, |
| 60 VIEW_ID_TAB_CONTENT_AREA, | 65 VIEW_ID_TAB_CONTENT_AREA, |
| 61 VIEW_ID_FULLSCREEN_FLOATING_BAR, | 66 VIEW_ID_FULLSCREEN_FLOATING_BAR, |
| 62 VIEW_ID_COUNT, | 67 VIEW_ID_COUNT, |
| 63 }; | 68 }; |
| 64 | 69 |
| 65 } // namespace | 70 } // namespace |
| 66 | 71 |
| 72 @interface InfoBarContainerController(TestingAPI) | |
| 73 - (BOOL)isTopInfoBarAnimationRunning; | |
| 74 @end | |
| 75 | |
| 76 @implementation InfoBarContainerController(TestingAPI) | |
| 77 - (BOOL)isTopInfoBarAnimationRunning { | |
| 78 InfoBarController* infoBarController = [infobarControllers_ objectAtIndex:0]; | |
| 79 if (infoBarController) { | |
| 80 const gfx::SlideAnimation& infobarAnimation = | |
| 81 const_cast<const InfoBarCocoa*>(infoBarController.infobar)->animation(); | |
|
Robert Sesek
2014/08/26 16:26:18
Why do you need this const cast?
Malcolm
2014/08/27 06:29:21
Class InfoBar has two methods named "animation()",
Peter Kasting
2014/08/27 06:59:51
If you're adding const, use static_cast rather tha
Malcolm
2014/08/27 09:06:36
Oh, should be static_cast here, very careful, than
| |
| 82 return infobarAnimation.is_animating(); | |
| 83 } | |
| 84 return NO; | |
| 85 } | |
| 86 @end | |
| 87 | |
| 67 class BrowserWindowControllerTest : public InProcessBrowserTest { | 88 class BrowserWindowControllerTest : public InProcessBrowserTest { |
| 68 public: | 89 public: |
| 69 BrowserWindowControllerTest() : InProcessBrowserTest() { | 90 BrowserWindowControllerTest() : InProcessBrowserTest() { |
| 70 } | 91 } |
| 71 | 92 |
| 72 virtual void SetUpOnMainThread() OVERRIDE { | 93 virtual void SetUpOnMainThread() OVERRIDE { |
| 73 [[controller() bookmarkBarController] setStateAnimationsEnabled:NO]; | 94 [[controller() bookmarkBarController] setStateAnimationsEnabled:NO]; |
| 74 [[controller() bookmarkBarController] setInnerContentAnimationsEnabled:NO]; | 95 [[controller() bookmarkBarController] setInnerContentAnimationsEnabled:NO]; |
| 75 } | 96 } |
| 76 | 97 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 | 148 |
| 128 CGFloat GetViewHeight(ViewID viewID) const { | 149 CGFloat GetViewHeight(ViewID viewID) const { |
| 129 CGFloat height = NSHeight([GetViewWithID(viewID) frame]); | 150 CGFloat height = NSHeight([GetViewWithID(viewID) frame]); |
| 130 if (viewID == VIEW_ID_INFO_BAR) { | 151 if (viewID == VIEW_ID_INFO_BAR) { |
| 131 height -= [[controller() infoBarContainerController] | 152 height -= [[controller() infoBarContainerController] |
| 132 overlappingTipHeight]; | 153 overlappingTipHeight]; |
| 133 } | 154 } |
| 134 return height; | 155 return height; |
| 135 } | 156 } |
| 136 | 157 |
| 158 static void CheckTopInfoBarAnimation( | |
| 159 InfoBarContainerController* infoBarContainerController, | |
| 160 const base::Closure& quit_task) { | |
| 161 if (![infoBarContainerController isTopInfoBarAnimationRunning]) | |
| 162 quit_task.Run(); | |
| 163 } | |
| 164 | |
| 165 static void CheckBookmarkBarAnimation( | |
| 166 BookmarkBarController* bookmarkBarController, | |
| 167 const base::Closure& quit_task) { | |
| 168 if (![bookmarkBarController isAnimationRunning]) | |
| 169 quit_task.Run(); | |
| 170 } | |
| 171 | |
| 172 void WaitForTopInfoBarAnimationToFinish() { | |
| 173 scoped_refptr<content::MessageLoopRunner> runner = | |
| 174 new content::MessageLoopRunner; | |
| 175 | |
| 176 base::Timer timer(false, true); | |
| 177 timer.Start( | |
| 178 FROM_HERE, | |
| 179 base::TimeDelta::FromMilliseconds(15), | |
| 180 base::Bind(&CheckTopInfoBarAnimation, | |
| 181 [controller() infoBarContainerController], | |
| 182 runner->QuitClosure())); | |
| 183 runner->Run(); | |
| 184 } | |
| 185 | |
| 186 void WaitForBookmarkBarAnimationToFinish() { | |
| 187 scoped_refptr<content::MessageLoopRunner> runner = | |
| 188 new content::MessageLoopRunner; | |
| 189 | |
| 190 base::Timer timer(false, true); | |
| 191 timer.Start( | |
| 192 FROM_HERE, | |
| 193 base::TimeDelta::FromMilliseconds(15), | |
| 194 base::Bind(&CheckBookmarkBarAnimation, | |
| 195 [controller() bookmarkBarController], | |
| 196 runner->QuitClosure())); | |
| 197 runner->Run(); | |
| 198 } | |
| 199 | |
| 200 NSInteger GetExpectedTopInfoBarTipHeight() { | |
| 201 InfoBarContainerController* infoBarContainerController = | |
| 202 [controller() infoBarContainerController]; | |
| 203 CGFloat overlappingTipHeight = | |
|
Robert Sesek
2014/08/26 16:26:18
naming: overlapping_tip_height
| |
| 204 [infoBarContainerController overlappingTipHeight]; | |
| 205 LocationBarViewMac* locationBarView = [controller() locationBarBridge]; | |
|
Robert Sesek
2014/08/26 16:26:18
naming: location_bar_view
| |
| 206 NSPoint iconBottom = locationBarView->GetPageInfoBubblePoint(); | |
|
Robert Sesek
2014/08/26 16:26:18
naming: icon_bottom
| |
| 207 | |
| 208 NSPoint infoBarTop = NSMakePoint(0, | |
|
Robert Sesek
2014/08/26 16:26:18
naming: info_bar_top
| |
| 209 NSHeight([infoBarContainerController view].frame) - | |
| 210 overlappingTipHeight); | |
| 211 infoBarTop = [[infoBarContainerController view] convertPoint:infoBarTop | |
| 212 toView:nil]; | |
| 213 return iconBottom.y - infoBarTop.y; | |
| 214 } | |
| 215 | |
| 137 private: | 216 private: |
| 138 DISALLOW_COPY_AND_ASSIGN(BrowserWindowControllerTest); | 217 DISALLOW_COPY_AND_ASSIGN(BrowserWindowControllerTest); |
| 139 }; | 218 }; |
| 140 | 219 |
| 141 // Tests that adding the first profile moves the Lion fullscreen button over | 220 // Tests that adding the first profile moves the Lion fullscreen button over |
| 142 // correctly. | 221 // correctly. |
| 143 // DISABLED_ because it regularly times out: http://crbug.com/159002. | 222 // DISABLED_ because it regularly times out: http://crbug.com/159002. |
| 144 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, | 223 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| 145 DISABLED_ProfileAvatarFullscreenButton) { | 224 DISABLED_ProfileAvatarFullscreenButton) { |
| 146 if (base::mac::IsOSSnowLeopard()) | 225 if (base::mac::IsOSSnowLeopard()) |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 DevToolsWindow* devtools_window = | 426 DevToolsWindow* devtools_window = |
| 348 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true); | 427 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true); |
| 349 DevToolsWindowTesting::Get(devtools_window)->SetInspectedPageBounds( | 428 DevToolsWindowTesting::Get(devtools_window)->SetInspectedPageBounds( |
| 350 gfx::Rect(10, 10, 100, 100)); | 429 gfx::Rect(10, 10, 100, 100)); |
| 351 | 430 |
| 352 NSPoint originWithDevTools = [controller() statusBubbleBaseFrame].origin; | 431 NSPoint originWithDevTools = [controller() statusBubbleBaseFrame].origin; |
| 353 EXPECT_FALSE(NSEqualPoints(origin, originWithDevTools)); | 432 EXPECT_FALSE(NSEqualPoints(origin, originWithDevTools)); |
| 354 | 433 |
| 355 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); | 434 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); |
| 356 } | 435 } |
| 436 | |
| 437 // Tests that top infobar tip is streched when bookmark bar becomes SHOWN/HIDDEN | |
| 438 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, | |
| 439 InfoBarTipStrechedWhenBookmarkBarStatusChanged) { | |
| 440 EXPECT_FALSE([controller() isBookmarkBarVisible]); | |
| 441 ShowInfoBar(browser()); | |
| 442 // The infobar tip is animated during the infobar is being added, wait until | |
| 443 // it completes. | |
| 444 WaitForTopInfoBarAnimationToFinish(); | |
| 445 | |
| 446 EXPECT_FALSE([[controller() infoBarContainerController] | |
| 447 shouldSuppressTopInfoBarTip]); | |
| 448 | |
| 449 NSInteger maxTipHeight = infobars::InfoBar::kMaximumArrowTargetHeight + | |
|
Robert Sesek
2014/08/26 16:26:18
naming: In C++ functions (which tests are), use un
| |
| 450 infobars::InfoBar::kSeparatorLineHeight; | |
| 451 | |
| 452 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR); | |
| 453 WaitForBookmarkBarAnimationToFinish(); | |
| 454 EXPECT_TRUE([controller() isBookmarkBarVisible]); | |
| 455 EXPECT_EQ(std::min(GetExpectedTopInfoBarTipHeight(), maxTipHeight), | |
| 456 [[controller() infoBarContainerController] overlappingTipHeight]); | |
| 457 | |
| 458 chrome::ExecuteCommand(browser(), IDC_SHOW_BOOKMARK_BAR); | |
| 459 WaitForBookmarkBarAnimationToFinish(); | |
| 460 EXPECT_FALSE([controller() isBookmarkBarVisible]); | |
| 461 EXPECT_EQ(std::min(GetExpectedTopInfoBarTipHeight(), maxTipHeight), | |
| 462 [[controller() infoBarContainerController] overlappingTipHeight]); | |
| 463 } | |
| OLD | NEW |