1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// found in the LICENSE file. 4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/ui/views/frame/browser_view_layout.h" 6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/ui/views/frame/browser_view.h" 890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h" 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/ui/views/frame/contents_container.h" 1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/ui/views/infobars/infobar_container_view.h" 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/ui/views/tabs/tab_strip.h" 13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/test/base/browser_with_test_window_test.h" 14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class MockBrowserViewLayoutDelegate : public BrowserViewLayoutDelegate { 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockBrowserViewLayoutDelegate() 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : tab_strip_visible_(true), 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) toolbar_visible_(true), 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bookmark_bar_visible_(true), 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) download_shelf_needs_layout_(false) { 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~MockBrowserViewLayoutDelegate() {} 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void set_download_shelf_needs_layout(bool layout) { 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) download_shelf_needs_layout_ = layout; 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void set_tab_strip_visible(bool visible) { 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) tab_strip_visible_ = visible; 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void set_toolbar_visible(bool visible) { 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) toolbar_visible_ = visible; 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void set_bookmark_bar_visible(bool visible) { 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bookmark_bar_visible_ = visible; 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // BrowserViewLayout::Delegate overrides: 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual views::View* GetWindowSwitcherButton() const OVERRIDE { 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // TODO(jamescook): Add a test for Windows that exercises the layout for 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // this button. 4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return NULL; 4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool IsTabStripVisible() const OVERRIDE { 4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return tab_strip_visible_; 4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual gfx::Rect GetBoundsForTabStripInBrowserView() const OVERRIDE { 4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return gfx::Rect(); 5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual int GetTopInsetInBrowserView() const OVERRIDE { 52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return 0; 53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual int GetThemeBackgroundXInset() const OVERRIDE { 55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return 0; 56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool IsToolbarVisible() const OVERRIDE { 5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return toolbar_visible_; 5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool IsBookmarkBarVisible() const OVERRIDE { 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return bookmark_bar_visible_; 6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool DownloadShelfNeedsLayout() const OVERRIDE { 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return download_shelf_needs_layout_; 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual FullscreenExitBubbleViews* GetFullscreenExitBubble() const OVERRIDE { 687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return NULL; 697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool tab_strip_visible_; 7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool toolbar_visible_; 7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool bookmark_bar_visible_; 7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool download_shelf_needs_layout_; 7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MockBrowserViewLayoutDelegate); 7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)/////////////////////////////////////////////////////////////////////////////// 8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// A simple view that prefers an initial size. 8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class MockView : public views::View { 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) explicit MockView(gfx::Size initial_size) 8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : size_(initial_size) { 8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SetBoundsRect(gfx::Rect(gfx::Point(), size_)); 8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~MockView() {} 9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // views::View overrides: 9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual gfx::Size GetPreferredSize() OVERRIDE { 9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return size_; 9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Size size_; 9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MockView); 10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)/////////////////////////////////////////////////////////////////////////////// 10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class MockImmersiveModeController : public ImmersiveModeController { 10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockImmersiveModeController() {} 10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~MockImmersiveModeController() {} 10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // ImmersiveModeController overrides: 110f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void Init(BrowserView* browser_view) OVERRIDE {} 11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual void SetEnabled(bool enabled) OVERRIDE {} 11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool IsEnabled() const OVERRIDE { return false; } 11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool ShouldHideTabIndicators() const OVERRIDE { return false; } 11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool ShouldHideTopViews() const OVERRIDE { return false; } 11590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool IsRevealed() const OVERRIDE { return false; } 116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual int GetTopContainerVerticalOffset( 117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const gfx::Size& top_container_size) const OVERRIDE { return 0; } 11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ImmersiveRevealedLock* GetRevealedLock( 11990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AnimateReveal animate_reveal) OVERRIDE WARN_UNUSED_RESULT { return NULL; } 1207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void OnFindBarVisibleBoundsChanged( 1217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const gfx::Rect& new_visible_bounds) OVERRIDE {} 1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void SetupForTest() OVERRIDE {} 12390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 12490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 12590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MockImmersiveModeController); 12690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 12790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 12890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)/////////////////////////////////////////////////////////////////////////////// 129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Tests of BrowserViewLayout. Runs tests without constructing a BrowserView. 130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class BrowserViewLayoutTest : public BrowserWithTestWindowTest { 131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 13290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) BrowserViewLayoutTest() 13390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : delegate_(NULL), 13490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) top_container_(NULL), 13590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) tab_strip_(NULL), 13690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) toolbar_(NULL), 13790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) infobar_container_(NULL), 13890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) contents_split_(NULL), 13990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) contents_container_(NULL), 14090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) active_web_view_(NULL) {} 141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ~BrowserViewLayoutTest() {} 142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 14390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) BrowserViewLayout* layout() { return layout_.get(); } 14490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockBrowserViewLayoutDelegate* delegate() { return delegate_; } 14590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockView* root_view() { return root_view_.get(); } 14690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockView* top_container() { return top_container_; } 14790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) TabStrip* tab_strip() { return tab_strip_; } 14890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockView* toolbar() { return toolbar_; } 14990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) InfoBarContainerView* infobar_container() { return infobar_container_; } 15090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockView* contents_split() { return contents_split_; } 15190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ContentsContainer* contents_container() { return contents_container_; } 15290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 15390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // BrowserWithTestWindowTest overrides: 154c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetUp() OVERRIDE { 155c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) BrowserWithTestWindowTest::SetUp(); 156c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 15790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) root_view_.reset(new MockView(gfx::Size(800, 600))); 15890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 15990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) immersive_mode_controller_.reset(new MockImmersiveModeController); 16090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 16190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) top_container_ = new MockView(gfx::Size(800, 60)); 16290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) tab_strip_ = new TabStrip(NULL); 16390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) top_container_->AddChildView(tab_strip_); 16490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) toolbar_ = new MockView(gfx::Size(800, 30)); 16590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) top_container_->AddChildView(toolbar_); 16690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) root_view_->AddChildView(top_container_); 16790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1687dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch infobar_container_ = new InfoBarContainerView(NULL); 16990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) root_view_->AddChildView(infobar_container_); 17090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 17190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) contents_split_ = new MockView(gfx::Size(800, 600)); 17290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) active_web_view_ = new MockView(gfx::Size(800, 600)); 17390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) contents_container_ = new ContentsContainer(active_web_view_); 17490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) contents_split_->AddChildView(contents_container_); 17590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) root_view_->AddChildView(contents_split_); 17690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 17790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // TODO(jamescook): Attach |layout_| to |root_view_|? 178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) layout_.reset(new BrowserViewLayout); 17990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate_ = new MockBrowserViewLayoutDelegate; 18090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) layout_->Init(delegate_, 18190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) browser(), 18290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) NULL, // BrowserView. 18390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) top_container_, 18490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) tab_strip_, 18590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) toolbar_, 18690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) infobar_container_, 18790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) contents_split_, 18890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) contents_container_, 18990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) immersive_mode_controller_.get()); 190c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 192c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 193c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<BrowserViewLayout> layout_; 19490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockBrowserViewLayoutDelegate* delegate_; // Owned by |layout_|. 19590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<MockView> root_view_; 19690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 19790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Views owned by |root_view_|. 19890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockView* top_container_; 19990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) TabStrip* tab_strip_; 20090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockView* toolbar_; 20190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) InfoBarContainerView* infobar_container_; 20290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockView* contents_split_; 20390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ContentsContainer* contents_container_; 20490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MockView* active_web_view_; 20590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 20690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<MockImmersiveModeController> immersive_mode_controller_; 207c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 208c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(BrowserViewLayoutTest); 209c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 210c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 211c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Test basic construction and initialization. 212c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(BrowserViewLayoutTest, BrowserViewLayout) { 213c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(layout()->browser()); 214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(layout()->GetWebContentsModalDialogHost()); 215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(layout()->InfobarVisible()); 216c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 218c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Test the core layout functions. 219c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TEST_F(BrowserViewLayoutTest, Layout) { 22090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Simulate a window with no interesting UI. 22190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate()->set_tab_strip_visible(false); 22290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate()->set_toolbar_visible(false); 22390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate()->set_bookmark_bar_visible(false); 22490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) layout()->Layout(root_view()); 22590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 22690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Top views are zero-height. 22790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ("0,0 0x0", tab_strip()->bounds().ToString()); 22890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ("0,0 800x0", toolbar()->bounds().ToString()); 22990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ("0,0 800x0", infobar_container()->bounds().ToString()); 23090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Contents split fills the window. 23190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ("0,0 800x600", contents_split()->bounds().ToString()); 23290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 23390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Turn on the toolbar, like in a pop-up window. 23490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate()->set_toolbar_visible(true); 23590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) layout()->Layout(root_view()); 23690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 23790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Now the toolbar has bounds and other views shift down. 23890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ("0,0 0x0", tab_strip()->bounds().ToString()); 23990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ("0,0 800x30", toolbar()->bounds().ToString()); 24090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ("0,30 800x0", infobar_container()->bounds().ToString()); 24190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ("0,30 800x570", contents_split()->bounds().ToString()); 24290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 24390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // TODO(jamescook): Tab strip and bookmark bar. 24490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 24590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 24690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST_F(BrowserViewLayoutTest, LayoutDownloadShelf) { 24790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<MockView> download_shelf(new MockView(gfx::Size(800, 50))); 24890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) layout()->set_download_shelf(download_shelf.get()); 24990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 25090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // If download shelf doesn't need layout, it doesn't move the bottom edge. 25190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate()->set_download_shelf_needs_layout(false); 25290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) const int kBottom = 500; 25390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(kBottom, layout()->LayoutDownloadShelf(kBottom)); 25490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 25590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Download shelf layout moves up the bottom edge and sets visibility. 25690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) delegate()->set_download_shelf_needs_layout(true); 25790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) download_shelf->SetVisible(false); 25890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(450, layout()->LayoutDownloadShelf(kBottom)); 25990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_TRUE(download_shelf->visible()); 26090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ("0,450 0x50", download_shelf->bounds().ToString()); 261c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 262