Chromium Code Reviews| Index: chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm |
| diff --git a/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm |
| index 326665c38ee1264a5481727460eb221c025f1eb2..5aad4d3a284a8149f9f84215008d01bdafff9a7f 100644 |
| --- a/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm |
| +++ b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm |
| @@ -7,14 +7,27 @@ |
| #import "base/mac/mac_util.h" |
| #include "base/run_loop.h" |
| #include "base/utf_string_conversions.h" |
| +#include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
| +#include "chrome/browser/api/infobars/infobar_service.h" |
| #include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/ui/browser_tabstrip.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| +#import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
| #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" |
| +#import "chrome/browser/ui/cocoa/fast_resize_view.h" |
| +#import "chrome/browser/ui/cocoa/nsview_additions.h" |
| +#import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" |
| +#include "chrome/browser/ui/search/search.h" |
| +#include "chrome/browser/ui/search/search_model.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| +#include "content/public/browser/web_contents.h" |
| +#import "testing/gtest_mac.h" |
| + |
| +namespace { |
| #if !defined(MAC_OS_X_VERSION_10_7) || \ |
| MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| @@ -24,8 +37,6 @@ enum { |
| }; |
| #endif // MAC_OS_X_VERSION_10_7 |
| -typedef InProcessBrowserTest BrowserWindowControllerTest; |
| - |
| void CreateProfileCallback(const base::Closure& quit_closure, |
| Profile* profile, |
| Profile::CreateStatus status) { |
| @@ -37,6 +48,133 @@ void CreateProfileCallback(const base::Closure& quit_closure, |
| quit_closure.Run(); |
| } |
| +enum ViewID { |
| + VIEW_ID_TOOLBAR, // 0 |
|
dhollowa
2013/01/18 00:55:11
I'm not a fan of the numbers in the comments. I'd
sail
2013/01/18 01:37:09
Done.
Oops, that was just for debugging. Removed.
|
| + VIEW_ID_BOOKMARK_BAR, // 1 |
| + VIEW_ID_INFO_BAR, // 2 |
| + VIEW_ID_FIND_BAR, // 3 |
| + VIEW_ID_DOWNLOAD_SHELF, // 4 |
| + VIEW_ID_TAB_CONTENT_AREA, // 5 |
| + VIEW_ID_FULLSCREEN_FLOATING_BAR, // 6 |
| + VIEW_ID_COUNT, |
| +}; |
| + |
| +class DummyInfoBar : public ConfirmInfoBarDelegate { |
|
dhollowa
2013/01/18 00:55:11
Small doc please.
sail
2013/01/18 01:37:09
Done.
|
| + public: |
| + DummyInfoBar(InfoBarService* service) : ConfirmInfoBarDelegate(service) { |
|
dhollowa
2013/01/18 00:55:11
explicit
sail
2013/01/18 01:37:09
Done.
|
| + } |
| + |
| + virtual ~DummyInfoBar() { |
| + } |
| + |
| + virtual string16 GetMessageText() const OVERRIDE { |
| + return string16(); |
| + } |
| +}; |
|
dhollowa
2013/01/18 00:55:11
DISALLOW_...
sail
2013/01/18 01:37:09
Done.
|
| + |
| +} // namespace |
| + |
| +class BrowserWindowControllerTest : public InProcessBrowserTest { |
| + public: |
| + BrowserWindowControllerTest() : InProcessBrowserTest() { |
| + } |
| + |
| + virtual void SetUpOnMainThread() OVERRIDE { |
| + [[controller() bookmarkBarController] setStateAnimationsEnabled:NO]; |
| + [[controller() bookmarkBarController] setInnerContentAnimationsEnabled:NO]; |
| + } |
| + |
| + virtual void CleanUpOnMainThread() OVERRIDE { |
| + if (web_contents_) |
| + browser()->search_model()->set_web_contents(NULL); |
| + } |
| + |
| + BrowserWindowController* controller() const { |
| + return [BrowserWindowController browserWindowControllerForWindow: |
| + browser()->window()->GetNativeWindow()]; |
| + } |
| + |
| + void ShowInstantResults() { |
| + chrome::search::EnableInstantExtendedAPIForTesting(); |
| + web_contents_.reset(content::WebContents::Create( |
| + content::WebContents::CreateParams(browser()->profile()))); |
| + browser()->search_model()->set_web_contents(web_contents_.get()); |
| + chrome::search::Mode mode(chrome::search::Mode::MODE_SEARCH_SUGGESTIONS, |
| + chrome::search::Mode::ORIGIN_SEARCH); |
| + browser()->search_model()->SetMode(mode); |
| + EXPECT_TRUE(browser()->search_model()->mode().is_search_suggestions()); |
| + EXPECT_TRUE([controller() isShowingInstantResults]); |
| + } |
| + |
| + void ShowInstantNTP() { |
| + chrome::search::EnableInstantExtendedAPIForTesting(); |
| + web_contents_.reset(content::WebContents::Create( |
| + content::WebContents::CreateParams(browser()->profile()))); |
| + browser()->search_model()->set_web_contents(web_contents_.get()); |
| + chrome::search::Mode mode(chrome::search::Mode::MODE_NTP, |
| + chrome::search::Mode::ORIGIN_NTP); |
| + browser()->search_model()->SetMode(mode); |
| + EXPECT_TRUE(browser()->search_model()->mode().is_ntp()); |
| + EXPECT_FALSE([controller() isShowingInstantResults]); |
| + } |
| + |
| + void ShowInfoBar() { |
| + content::WebContents* web_contents = |
| + chrome::GetActiveWebContents(browser()); |
| + InfoBarService* service = |
| + InfoBarService::FromWebContents(web_contents); |
| + service->AddInfoBar(scoped_ptr<InfoBarDelegate>(new DummyInfoBar(service))); |
| + } |
| + |
| + NSView* GetViewWithID(ViewID view_id) const { |
| + switch (view_id) { |
| + case VIEW_ID_FULLSCREEN_FLOATING_BAR: |
| + return [controller() floatingBarBackingView]; |
| + case VIEW_ID_TOOLBAR: |
| + return [[controller() toolbarController] view]; |
| + case VIEW_ID_BOOKMARK_BAR: |
| + return [[controller() bookmarkBarController] view]; |
| + case VIEW_ID_INFO_BAR: |
| + return [[controller() infoBarContainerController] view]; |
| + case VIEW_ID_FIND_BAR: |
| + return [[controller() findBarCocoaController] view]; |
| + case VIEW_ID_DOWNLOAD_SHELF: |
| + return [[controller() downloadShelf] view]; |
| + case VIEW_ID_TAB_CONTENT_AREA: |
| + return [controller() tabContentArea]; |
| + default: |
| + NOTREACHED(); |
| + return nil; |
| + } |
| + } |
| + |
| + void VerifyZOrder(const std::vector<ViewID>& view_list) const { |
| + for (size_t i = 0; i < view_list.size() - 1; ++i) { |
| + NSView* bottom_view = GetViewWithID(view_list[i]); |
| + NSView* top_view = GetViewWithID(view_list[i + 1]); |
| + EXPECT_NSEQ([bottom_view superview], [top_view superview]); |
| + EXPECT_TRUE([bottom_view cr_isBelowView:top_view]); |
| + } |
| + |
| + // Views not in |view_list| must either be nil or not parented. |
| + for (size_t i = 0; i < VIEW_ID_COUNT; ++i) { |
| + if (std::find(view_list.begin(), view_list.end(), i) == view_list.end()) { |
| + NSView* view = GetViewWithID(static_cast<ViewID>(i)); |
| + EXPECT_TRUE(!view || ![view superview]); |
| + } |
| + } |
| + } |
| + |
| + CGFloat GetViewHeight(ViewID viewID) const { |
| + return NSHeight([GetViewWithID(viewID) frame]); |
| + } |
| + |
| + private: |
| + scoped_ptr<content::WebContents> web_contents_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BrowserWindowControllerTest); |
| +}; |
| + |
| // Tests that adding the first profile moves the Lion fullscreen button over |
| // correctly. |
| // DISABLED_ because it regularly times out: http://crbug.com/159002. |
| @@ -52,9 +190,6 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| NSWindow* window = browser()->window()->GetNativeWindow(); |
| ASSERT_TRUE(window); |
| - BrowserWindowController* controller = |
| - static_cast<BrowserWindowCocoa*>(browser()->window())->cocoa_controller(); |
| - |
| // With only one profile, the fullscreen button should be visible, but the |
| // avatar button should not. |
| EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles()); |
| @@ -65,7 +200,7 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| EXPECT_FALSE([fullscreen_button isHidden]); |
| AvatarButtonController* avatar_controller = |
| - [controller avatarButtonController]; |
| + [controller() avatarButtonController]; |
| NSView* avatar = [avatar_controller view]; |
| EXPECT_TRUE(avatar); |
| EXPECT_TRUE([avatar isHidden]); |
| @@ -100,3 +235,187 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| EXPECT_LT(NSMinX(fullscreen_frame), NSMinX(avatar_frame)); |
| EXPECT_LT(NSMaxX(fullscreen_frame), NSMinX(avatar_frame)); |
| } |
| + |
| +// Verify that in non-instant normal mode that the find bar and download shelf |
| +// are above the content area. Everything else should be below it. |
| +IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormal) { |
| + browser()->GetFindBarController(); // add find bar |
| + |
| + std::vector<ViewID> view_list; |
| + view_list.push_back(VIEW_ID_BOOKMARK_BAR); |
| + view_list.push_back(VIEW_ID_TOOLBAR); |
| + view_list.push_back(VIEW_ID_INFO_BAR); |
| + view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); |
| + view_list.push_back(VIEW_ID_FIND_BAR); |
| + view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); |
| + VerifyZOrder(view_list); |
| +} |
| + |
| +// Verify that in non-instant presentation mode that the info bar is below the |
| +// content are and everything else is above it. |
| +IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderPresentationMode) { |
| + browser()->TogglePresentationMode(); |
| + browser()->GetFindBarController(); // add find bar |
| + |
| + std::vector<ViewID> view_list; |
| + view_list.push_back(VIEW_ID_INFO_BAR); |
| + view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); |
| + view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR); |
| + view_list.push_back(VIEW_ID_BOOKMARK_BAR); |
| + view_list.push_back(VIEW_ID_TOOLBAR); |
| + view_list.push_back(VIEW_ID_FIND_BAR); |
| + view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); |
| + VerifyZOrder(view_list); |
| +} |
| + |
| +// Normal mode with instant results showing. Should be same zorder as normal |
| +// mode except find bar is below content area. |
| +IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormalInstant) { |
| + ShowInstantResults(); |
| + browser()->GetFindBarController(); // add find bar |
| + |
| + std::vector<ViewID> view_list; |
| + view_list.push_back(VIEW_ID_BOOKMARK_BAR); |
| + view_list.push_back(VIEW_ID_TOOLBAR); |
| + view_list.push_back(VIEW_ID_INFO_BAR); |
| + view_list.push_back(VIEW_ID_FIND_BAR); |
| + view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); |
| + view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); |
| + VerifyZOrder(view_list); |
| +} |
| + |
| +// Presentation mode with instant results showing. Should be exact same as |
| +// non-instant presentation mode. |
| +IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| + ZOrderInstantPresentationMode) { |
| + browser()->TogglePresentationMode(); |
| + ShowInstantResults(); |
| + browser()->GetFindBarController(); // add find bar |
| + |
| + std::vector<ViewID> view_list; |
| + view_list.push_back(VIEW_ID_INFO_BAR); |
| + view_list.push_back(VIEW_ID_TAB_CONTENT_AREA); |
| + view_list.push_back(VIEW_ID_FULLSCREEN_FLOATING_BAR); |
| + view_list.push_back(VIEW_ID_BOOKMARK_BAR); |
| + view_list.push_back(VIEW_ID_TOOLBAR); |
| + view_list.push_back(VIEW_ID_FIND_BAR); |
| + view_list.push_back(VIEW_ID_DOWNLOAD_SHELF); |
| + VerifyZOrder(view_list); |
| +} |
| + |
| +// Verify that in non-instant presentation mode the content area is beneath |
| +// the bookmark bar and info bar. |
| +IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffset) { |
| + PreviewableContentsController* preview = |
| + [controller() previewableContentsController]; |
| + |
| + // Just toolbar. |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(0, [preview activeContainerOffset]); |
| + |
| + // Plus bookmark bar. |
| + browser()->window()->ToggleBookmarkBar(); |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR), |
| + [preview activeContainerOffset]); |
| + |
| + // Plus info bar. |
| + ShowInfoBar(); |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) + |
| + GetViewHeight(VIEW_ID_INFO_BAR), |
| + [preview activeContainerOffset]); |
| + |
| + // Minus bookmark bar. |
| + browser()->window()->ToggleBookmarkBar(); |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]); |
| +} |
| + |
| +// Verify that in non-instant presentation mode the content area is beneath |
| +// the info bar. |
| +IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, |
| + ContentOffsetPresentationMode) { |
| + browser()->TogglePresentationMode(); |
| + PreviewableContentsController* preview = |
| + [controller() previewableContentsController]; |
| + |
| + // Just toolbar. |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(0, [preview activeContainerOffset]); |
| + |
| + // Plus bookmark bar. |
| + browser()->window()->ToggleBookmarkBar(); |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(0, [preview activeContainerOffset]); |
| + |
| + // Plus info bar. |
| + ShowInfoBar(); |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]); |
| + |
| + // Minus bookmark bar. |
| + browser()->window()->ToggleBookmarkBar(); |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]); |
| +} |
| + |
| +// Verify that when showing instant results the content area overlaps the |
| +// bookmark bar and info bar. |
| +IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstant) { |
| + ShowInstantResults(); |
| + PreviewableContentsController* preview = |
| + [controller() previewableContentsController]; |
| + |
| + // Just toolbar. |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(0, [preview activeContainerOffset]); |
| + |
| + // Plus bookmark bar. |
| + browser()->window()->ToggleBookmarkBar(); |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(0, [preview activeContainerOffset]); |
| + |
| + // Plus info bar. |
| + ShowInfoBar(); |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(0, [preview activeContainerOffset]); |
| + |
| + // Minus bookmark bar. |
| + browser()->window()->ToggleBookmarkBar(); |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(0, [preview activeContainerOffset]); |
| +} |
| + |
| +// The instant NTP case is same as normal case except that the preview is |
| +// also shifted down. |
| +IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstantNPT) { |
| + ShowInstantNTP(); |
| + PreviewableContentsController* preview = |
| + [controller() previewableContentsController]; |
| + |
| + // Just toolbar. |
| + EXPECT_EQ(0, [preview previewOffset]); |
| + EXPECT_EQ(0, [preview activeContainerOffset]); |
| + |
| + // Plus bookmark bar. |
| + browser()->window()->ToggleBookmarkBar(); |
| + EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR), |
| + [preview previewOffset]); |
| + EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR), |
| + [preview activeContainerOffset]); |
| + |
| + // Plus info bar. |
| + ShowInfoBar(); |
| + EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) + |
| + GetViewHeight(VIEW_ID_INFO_BAR), |
| + [preview previewOffset]); |
| + EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) + |
| + GetViewHeight(VIEW_ID_INFO_BAR), |
| + [preview activeContainerOffset]); |
| + |
| + // Minus bookmark bar. |
| + browser()->window()->ToggleBookmarkBar(); |
| + EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview previewOffset]); |
| + EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]); |
| +} |