This source file includes following definitions.
- ExpectedTabStripOrigin
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
#include "chrome/browser/ui/views/frame/browser_view_layout.h"
#include "chrome/browser/ui/views/frame/test_with_browser_view.h"
#include "chrome/browser/ui/views/frame/top_container_view.h"
#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/common/url_constants.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/single_split_view.h"
#include "ui/views/controls/webview/webview.h"
namespace {
gfx::Point ExpectedTabStripOrigin(BrowserView* browser_view) {
gfx::Rect tabstrip_bounds(
browser_view->frame()->GetBoundsForTabStrip(browser_view->tabstrip()));
gfx::Point tabstrip_origin(tabstrip_bounds.origin());
views::View::ConvertPointToTarget(browser_view->parent(),
browser_view,
&tabstrip_origin);
return tabstrip_origin;
}
}
typedef TestWithBrowserView BrowserViewTest;
TEST_F(BrowserViewTest, BrowserView) {
EXPECT_FALSE(window());
EXPECT_TRUE(browser_view()->browser());
EXPECT_TRUE(browser_view()->IsTabStripVisible());
EXPECT_FALSE(browser_view()->IsOffTheRecord());
EXPECT_EQ(IDR_OTR_ICON, browser_view()->GetOTRIconResourceID());
EXPECT_FALSE(browser_view()->IsGuestSession());
EXPECT_FALSE(browser_view()->ShouldShowAvatar());
EXPECT_TRUE(browser_view()->IsBrowserTypeNormal());
EXPECT_FALSE(browser_view()->IsFullscreen());
EXPECT_FALSE(browser_view()->IsBookmarkBarVisible());
EXPECT_FALSE(browser_view()->IsBookmarkBarAnimating());
}
TEST_F(BrowserViewTest, BrowserViewLayout) {
BookmarkBarView::DisableAnimationsForTesting(true);
Browser* browser = browser_view()->browser();
TopContainerView* top_container = browser_view()->top_container();
TabStrip* tabstrip = browser_view()->tabstrip();
ToolbarView* toolbar = browser_view()->toolbar();
views::View* contents_container =
browser_view()->GetContentsContainerForTest();
views::WebView* contents_web_view =
browser_view()->GetContentsWebViewForTest();
views::WebView* devtools_web_view =
browser_view()->GetDevToolsWebViewForTest();
AddTab(browser, GURL("about:blank"));
EXPECT_EQ(top_container, browser_view()->tabstrip()->parent());
EXPECT_EQ(top_container, browser_view()->toolbar()->parent());
EXPECT_EQ(top_container, browser_view()->GetBookmarkBarView()->parent());
EXPECT_EQ(browser_view(), browser_view()->infobar_container()->parent());
EXPECT_EQ(browser_view()->child_count() - 1,
browser_view()->GetIndexOf(browser_view()->find_bar_host_view()));
EXPECT_EQ(browser_view()->child_count() - 2,
browser_view()->GetIndexOf(top_container));
EXPECT_EQ(0, top_container->x());
EXPECT_EQ(0, top_container->y());
EXPECT_EQ(browser_view()->width(), top_container->width());
gfx::Point expected_tabstrip_origin = ExpectedTabStripOrigin(browser_view());
EXPECT_EQ(expected_tabstrip_origin.x(), tabstrip->x());
EXPECT_EQ(expected_tabstrip_origin.y(), tabstrip->y());
EXPECT_EQ(0, toolbar->x());
EXPECT_EQ(
tabstrip->bounds().bottom() -
BrowserViewLayout::kToolbarTabStripVerticalOverlap,
toolbar->y());
EXPECT_EQ(0, contents_container->x());
EXPECT_EQ(toolbar->bounds().bottom(), contents_container->y());
EXPECT_EQ(top_container->bounds().bottom(), contents_container->y());
EXPECT_EQ(0, devtools_web_view->x());
EXPECT_EQ(0, devtools_web_view->y());
EXPECT_EQ(0, contents_web_view->x());
EXPECT_EQ(0, contents_web_view->y());
BookmarkBarView* bookmark_bar = browser_view()->GetBookmarkBarView();
EXPECT_FALSE(bookmark_bar->visible());
EXPECT_FALSE(bookmark_bar->IsDetached());
chrome::ExecuteCommand(browser, IDC_SHOW_BOOKMARK_BAR);
EXPECT_TRUE(bookmark_bar->visible());
EXPECT_FALSE(bookmark_bar->IsDetached());
chrome::ExecuteCommand(browser, IDC_SHOW_BOOKMARK_BAR);
EXPECT_FALSE(bookmark_bar->visible());
EXPECT_FALSE(bookmark_bar->IsDetached());
NavigateAndCommitActiveTabWithTitle(browser,
GURL(chrome::kChromeUINewTabURL),
base::string16());
EXPECT_TRUE(bookmark_bar->visible());
EXPECT_TRUE(bookmark_bar->IsDetached());
EXPECT_EQ(browser_view(), bookmark_bar->parent());
EXPECT_EQ(browser_view()->child_count() - 1,
browser_view()->GetIndexOf(browser_view()->find_bar_host_view()));
EXPECT_EQ(browser_view()->child_count() - 2,
browser_view()->GetIndexOf(top_container));
EXPECT_EQ(0, bookmark_bar->x());
EXPECT_EQ(
tabstrip->bounds().bottom() +
toolbar->height() -
BrowserViewLayout::kToolbarTabStripVerticalOverlap -
views::NonClientFrameView::kClientEdgeThickness,
bookmark_bar->y());
EXPECT_EQ(toolbar->bounds().bottom(), contents_container->y());
EXPECT_EQ(bookmark_bar->height() -
views::NonClientFrameView::kClientEdgeThickness,
devtools_web_view->y());
EXPECT_EQ(bookmark_bar->height() -
views::NonClientFrameView::kClientEdgeThickness,
contents_web_view->y());
NavigateAndCommitActiveTabWithTitle(browser,
GURL("about:blank"),
base::string16());
EXPECT_FALSE(bookmark_bar->visible());
EXPECT_FALSE(bookmark_bar->IsDetached());
EXPECT_EQ(top_container, bookmark_bar->parent());
EXPECT_EQ(browser_view()->child_count() - 2,
browser_view()->GetIndexOf(top_container));
BookmarkBarView::DisableAnimationsForTesting(false);
}
class BrowserViewHostedAppTest : public TestWithBrowserView {
public:
BrowserViewHostedAppTest()
: TestWithBrowserView(Browser::TYPE_POPUP,
chrome::HOST_DESKTOP_TYPE_NATIVE,
true) {
}
virtual ~BrowserViewHostedAppTest() {
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserViewHostedAppTest);
};
TEST_F(BrowserViewHostedAppTest, Layout) {
AddTab(browser(), GURL("about:blank"));
views::View* contents_container =
browser_view()->GetContentsContainerForTest();
EXPECT_FALSE(browser_view()->tabstrip()->visible());
EXPECT_FALSE(browser_view()->toolbar()->visible());
EXPECT_FALSE(browser_view()->IsBookmarkBarVisible());
gfx::Point header_offset;
views::View::ConvertPointToTarget(
browser_view(),
browser_view()->frame()->non_client_view()->frame_view(),
&header_offset);
int bottom_of_header = browser_view()->frame()->GetTopInset() -
header_offset.y();
EXPECT_EQ(bottom_of_header, contents_container->y());
EXPECT_EQ(browser_view()->frame()->GetTopInset() - 1,
browser_view()->GetFindBarBoundingBox().y());
}