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

Unified Diff: chrome/browser/ui/views/frame/browser_view_layout_unittest.cc

Issue 14589016: Unit test for BrowserViewLayout that does not depend on BrowserView (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: BrowserViewLayout owns its delegate Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/frame/browser_view_layout_unittest.cc
diff --git a/chrome/browser/ui/views/frame/browser_view_layout_unittest.cc b/chrome/browser/ui/views/frame/browser_view_layout_unittest.cc
index e083596d6bd6f810ac2d594628598a7520ddf04d..26875bdcd081ec2fa9156329caca0a00a3a8b38f 100644
--- a/chrome/browser/ui/views/frame/browser_view_layout_unittest.cc
+++ b/chrome/browser/ui/views/frame/browser_view_layout_unittest.cc
@@ -5,36 +5,198 @@
#include "chrome/browser/ui/views/frame/browser_view_layout.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h"
+#include "chrome/browser/ui/views/frame/contents_container.h"
+#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
+#include "chrome/browser/ui/views/frame/overlay_container.h"
#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
+#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "testing/gtest/include/gtest/gtest.h"
+class MockBrowserViewLayoutDelegate : public BrowserViewLayoutDelegate {
+ public:
+ MockBrowserViewLayoutDelegate()
+ : tab_strip_visible_(true),
+ toolbar_visible_(true),
+ bookmark_bar_visible_(true),
+ download_shelf_needs_layout_(false) {
+ }
+ virtual ~MockBrowserViewLayoutDelegate() {}
+
+ void set_download_shelf_needs_layout(bool layout) {
+ download_shelf_needs_layout_ = layout;
+ }
+ void set_tab_strip_visible(bool visible) {
+ tab_strip_visible_ = visible;
+ }
+ void set_toolbar_visible(bool visible) {
+ toolbar_visible_ = visible;
+ }
+ void set_bookmark_bar_visible(bool visible) {
+ bookmark_bar_visible_ = visible;
+ }
+
+ // BrowserViewLayout::Delegate overrides:
+ virtual bool IsTabStripVisible() const OVERRIDE {
+ return tab_strip_visible_;
+ }
+ virtual gfx::Rect GetBoundsForTabStrip(views::View* tab_strip) const
+ OVERRIDE {
+ return gfx::Rect();
+ }
+ virtual bool IsToolbarVisible() const OVERRIDE {
+ return toolbar_visible_;
+ }
+ virtual bool IsBookmarkBarVisible() const OVERRIDE {
+ return bookmark_bar_visible_;
+ }
+ virtual bool DownloadShelfNeedsLayout() const OVERRIDE {
+ return download_shelf_needs_layout_;
+ }
+
+ private:
+ bool tab_strip_visible_;
+ bool toolbar_visible_;
+ bool bookmark_bar_visible_;
+ bool download_shelf_needs_layout_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockBrowserViewLayoutDelegate);
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+// A simple view that prefers an initial size.
+class MockView : public views::View {
+ public:
+ explicit MockView(gfx::Size initial_size)
+ : size_(initial_size) {
+ SetBoundsRect(gfx::Rect(gfx::Point(), size_));
+ }
+ virtual ~MockView() {}
+
+ // views::View overrides:
+ virtual gfx::Size GetPreferredSize() OVERRIDE {
+ return size_;
+ }
+
+ private:
+ gfx::Size size_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockView);
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+class MockImmersiveModeController : public ImmersiveModeController {
+ public:
+ MockImmersiveModeController() {}
+ virtual ~MockImmersiveModeController() {}
+
+ // ImmersiveModeController overrides:
+ virtual void Init(BrowserView* browser_view) OVERRIDE {}
+ virtual void SetEnabled(bool enabled) OVERRIDE {}
+ virtual bool IsEnabled() const OVERRIDE { return false; }
+ virtual bool ShouldHideTabIndicators() const OVERRIDE { return false; }
+ virtual bool ShouldHideTopViews() const OVERRIDE { return false; }
+ virtual bool IsRevealed() const OVERRIDE { return false; }
+ virtual void MaybeStackViewAtTop() OVERRIDE {}
+ virtual ImmersiveRevealedLock* GetRevealedLock(
+ AnimateReveal animate_reveal) OVERRIDE WARN_UNUSED_RESULT { return NULL; }
+ virtual void AnchorWidgetToTopContainer(views::Widget* widget,
+ int y_offset) OVERRIDE {}
+ virtual void UnanchorWidgetFromTopContainer(views::Widget* widget) OVERRIDE {}
+ virtual void OnTopContainerBoundsChanged() OVERRIDE {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockImmersiveModeController);
+};
+
+///////////////////////////////////////////////////////////////////////////////
// Tests of BrowserViewLayout. Runs tests without constructing a BrowserView.
class BrowserViewLayoutTest : public BrowserWithTestWindowTest {
public:
- BrowserViewLayoutTest() {}
+ BrowserViewLayoutTest()
+ : delegate_(NULL),
+ top_container_(NULL),
+ tab_strip_(NULL),
+ toolbar_(NULL),
+ infobar_container_(NULL),
+ contents_split_(NULL),
+ contents_container_(NULL),
+ overlay_container_(NULL),
+ active_web_view_(NULL) {}
virtual ~BrowserViewLayoutTest() {}
+ BrowserViewLayout* layout() { return layout_.get(); }
+ MockBrowserViewLayoutDelegate* delegate() { return delegate_; }
+ MockView* root_view() { return root_view_.get(); }
+ MockView* top_container() { return top_container_; }
+ TabStrip* tab_strip() { return tab_strip_; }
+ MockView* toolbar() { return toolbar_; }
+ InfoBarContainerView* infobar_container() { return infobar_container_; }
+ MockView* contents_split() { return contents_split_; }
+ ContentsContainer* contents_container() { return contents_container_; }
+
+ // BrowserWithTestWindowTest overrides:
virtual void SetUp() OVERRIDE {
BrowserWithTestWindowTest::SetUp();
- // Because we have a TestBrowserWindow, not a BrowserView, |layout_| is
- // not attached to a host view.
+ root_view_.reset(new MockView(gfx::Size(800, 600)));
+
+ top_container_ = new MockView(gfx::Size(800, 60));
+ tab_strip_ = new TabStrip(NULL);
+ top_container_->AddChildView(tab_strip_);
+ toolbar_ = new MockView(gfx::Size(800, 30));
+ top_container_->AddChildView(toolbar_);
+ root_view_->AddChildView(top_container_);
+
+ overlay_container_ = new OverlayContainer(NULL);
+ root_view_->AddChildView(overlay_container_);
+
+ infobar_container_ = new InfoBarContainerView(NULL, NULL);
+ root_view_->AddChildView(infobar_container_);
+
+ contents_split_ = new MockView(gfx::Size(800, 600));
+ active_web_view_ = new MockView(gfx::Size(800, 600));
+ contents_container_ = new ContentsContainer(active_web_view_);
+ contents_split_->AddChildView(contents_container_);
+ root_view_->AddChildView(contents_split_);
+
+ immersive_mode_controller_.reset(new MockImmersiveModeController);
+
+ // TODO(jamescook): Attach |layout_| to |root_view_|?
layout_.reset(new BrowserViewLayout);
- infobar_container_.reset(new InfoBarContainerView(NULL, NULL));
- layout_->Init(browser(),
- NULL,
- infobar_container_.get(),
- NULL,
- NULL,
- NULL);
+ delegate_ = new MockBrowserViewLayoutDelegate;
+ layout_->Init(delegate_,
+ browser(),
+ NULL, // BrowserView.
+ top_container_,
+ tab_strip_,
+ toolbar_,
+ infobar_container_,
+ contents_split_,
+ contents_container_,
+ overlay_container_,
+ immersive_mode_controller_.get());
}
- BrowserViewLayout* layout() { return layout_.get(); }
-
private:
scoped_ptr<BrowserViewLayout> layout_;
- scoped_ptr<InfoBarContainerView> infobar_container_;
+ MockBrowserViewLayoutDelegate* delegate_; // Owned by |layout_|.
+ scoped_ptr<MockView> root_view_;
+
+ // Views owned by |root_view_|.
+ MockView* top_container_;
+ TabStrip* tab_strip_;
+ MockView* toolbar_;
+ InfoBarContainerView* infobar_container_;
+ MockView* contents_split_;
+ ContentsContainer* contents_container_;
+ OverlayContainer* overlay_container_;
+ MockView* active_web_view_;
+
+ scoped_ptr<MockImmersiveModeController> immersive_mode_controller_;
DISALLOW_COPY_AND_ASSIGN(BrowserViewLayoutTest);
};
@@ -45,13 +207,49 @@ TEST_F(BrowserViewLayoutTest, BrowserViewLayout) {
EXPECT_TRUE(layout()->GetWebContentsModalDialogHost());
EXPECT_EQ(BrowserViewLayout::kInstantUINone, layout()->GetInstantUIState());
EXPECT_FALSE(layout()->InfobarVisible());
- // TODO(jamescook): Add more as we break dependencies.
}
// Test the core layout functions.
TEST_F(BrowserViewLayoutTest, Layout) {
- // We don't have a bookmark bar yet, so no contents offset is required.
- EXPECT_EQ(0, layout()->GetContentsOffsetForBookmarkBar());
- EXPECT_EQ(0, layout()->GetTopMarginForActiveContent());
- // TODO(jamescook): Add more as we break dependencies.
+ // Simulate a window with no interesting UI.
+ delegate()->set_tab_strip_visible(false);
+ delegate()->set_toolbar_visible(false);
+ delegate()->set_bookmark_bar_visible(false);
+ layout()->Layout(root_view());
+
+ // Top views are zero-height.
+ EXPECT_EQ("0,0 0x0", tab_strip()->bounds().ToString());
+ EXPECT_EQ("0,0 800x0", toolbar()->bounds().ToString());
+ EXPECT_EQ("0,0 800x0", infobar_container()->bounds().ToString());
+ // Contents split fills the window.
+ EXPECT_EQ("0,0 800x600", contents_split()->bounds().ToString());
+
+ // Turn on the toolbar, like in a pop-up window.
+ delegate()->set_toolbar_visible(true);
+ layout()->Layout(root_view());
+
+ // Now the toolbar has bounds and other views shift down.
+ EXPECT_EQ("0,0 0x0", tab_strip()->bounds().ToString());
+ EXPECT_EQ("0,0 800x30", toolbar()->bounds().ToString());
+ EXPECT_EQ("0,30 800x0", infobar_container()->bounds().ToString());
+ EXPECT_EQ("0,30 800x570", contents_split()->bounds().ToString());
+
+ // TODO(jamescook): Tab strip and bookmark bar.
+}
+
+TEST_F(BrowserViewLayoutTest, LayoutDownloadShelf) {
+ scoped_ptr<MockView> download_shelf(new MockView(gfx::Size(800, 50)));
+ layout()->set_download_shelf(download_shelf.get());
+
+ // If download shelf doesn't need layout, it doesn't move the bottom edge.
+ delegate()->set_download_shelf_needs_layout(false);
+ const int kBottom = 500;
+ EXPECT_EQ(kBottom, layout()->LayoutDownloadShelf(kBottom));
+
+ // Download shelf layout moves up the bottom edge and sets visibility.
+ delegate()->set_download_shelf_needs_layout(true);
+ download_shelf->SetVisible(false);
+ EXPECT_EQ(450, layout()->LayoutDownloadShelf(kBottom));
+ EXPECT_TRUE(download_shelf->visible());
+ EXPECT_EQ("0,450 0x50", download_shelf->bounds().ToString());
}
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view_layout_delegate.h ('k') | chrome/browser/ui/views/frame/contents_container.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698