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

Side by Side Diff: chrome/browser/ui/views/frame/browser_view_unittest.cc

Issue 14598011: Convert a BrowserView.BrowserViewLayout interactive_uitest to unit_test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view_interactive_uitest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome/browser/ui/views/frame/browser_view.h" 5 #include "chrome/browser/ui/views/frame/browser_view.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 8
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/search_engines/template_url_service.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
15 #include "chrome/browser/ui/views/frame/browser_view_layout.h"
16 #include "chrome/browser/ui/views/frame/top_container_view.h"
17 #include "chrome/browser/ui/views/infobars/infobar_container_view.h"
18 #include "chrome/browser/ui/views/tabs/tab_strip.h"
19 #include "chrome/browser/ui/views/toolbar_view.h"
20 #include "chrome/common/url_constants.h"
9 #include "chrome/test/base/browser_with_test_window_test.h" 21 #include "chrome/test/base/browser_with_test_window_test.h"
10 #include "chrome/test/base/scoped_testing_local_state.h" 22 #include "chrome/test/base/scoped_testing_local_state.h"
11 #include "chrome/test/base/testing_browser_process.h" 23 #include "chrome/test/base/testing_browser_process.h"
12 #include "grit/theme_resources.h" 24 #include "grit/theme_resources.h"
13 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/views/controls/single_split_view.h"
27 #include "ui/views/controls/webview/webview.h"
14 28
15 #if defined(OS_CHROMEOS) 29 #if defined(OS_CHROMEOS)
16 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" 30 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
17 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" 31 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
18 #endif 32 #endif
19 33
34 namespace {
35
36 // Tab strip bounds depend on the window frame sizes.
37 gfx::Point ExpectedTabStripOrigin(BrowserView* browser_view) {
38 gfx::Rect tabstrip_bounds(
39 browser_view->frame()->GetBoundsForTabStrip(browser_view->tabstrip()));
40 gfx::Point tabstrip_origin(tabstrip_bounds.origin());
41 views::View::ConvertPointToTarget(browser_view->parent(),
42 browser_view,
43 &tabstrip_origin);
44 return tabstrip_origin;
45 }
46
47 // Caller owns the returned service.
48 ProfileKeyedService* CreateTemplateURLService(
49 content::BrowserContext* profile) {
50 return new TemplateURLService(static_cast<Profile*>(profile));
51 }
52
53 } // namespace
54
20 class BrowserViewTest : public BrowserWithTestWindowTest { 55 class BrowserViewTest : public BrowserWithTestWindowTest {
21 public: 56 public:
22 BrowserViewTest(); 57 BrowserViewTest();
23 virtual ~BrowserViewTest() {} 58 virtual ~BrowserViewTest() {}
24 59
25 // BrowserWithTestWindowTest overrides: 60 // BrowserWithTestWindowTest overrides:
26 virtual void SetUp() OVERRIDE; 61 virtual void SetUp() OVERRIDE;
27 virtual void TearDown() OVERRIDE; 62 virtual void TearDown() OVERRIDE;
63 virtual TestingProfile* CreateProfile() OVERRIDE;
28 virtual BrowserWindow* CreateBrowserWindow() OVERRIDE; 64 virtual BrowserWindow* CreateBrowserWindow() OVERRIDE;
29 65
30 BrowserView* browser_view() { return browser_view_; } 66 BrowserView* browser_view() { return browser_view_; }
31 67
32 private: 68 private:
33 BrowserView* browser_view_; // Not owned. 69 BrowserView* browser_view_; // Not owned.
34 scoped_ptr<ScopedTestingLocalState> local_state_; 70 scoped_ptr<ScopedTestingLocalState> local_state_;
35 DISALLOW_COPY_AND_ASSIGN(BrowserViewTest); 71 DISALLOW_COPY_AND_ASSIGN(BrowserViewTest);
36 }; 72 };
37 73
38 BrowserViewTest::BrowserViewTest() 74 BrowserViewTest::BrowserViewTest()
39 : browser_view_(NULL) { 75 : browser_view_(NULL) {
40 } 76 }
41 77
42 void BrowserViewTest::SetUp() { 78 void BrowserViewTest::SetUp() {
43 local_state_.reset( 79 local_state_.reset(
44 new ScopedTestingLocalState(TestingBrowserProcess::GetGlobal())); 80 new ScopedTestingLocalState(TestingBrowserProcess::GetGlobal()));
45 #if defined(OS_CHROMEOS) 81 #if defined(OS_CHROMEOS)
46 chromeos::input_method::InitializeForTesting( 82 chromeos::input_method::InitializeForTesting(
47 new chromeos::input_method::MockInputMethodManager); 83 new chromeos::input_method::MockInputMethodManager);
48 #endif 84 #endif
49 BrowserWithTestWindowTest::SetUp(); 85 BrowserWithTestWindowTest::SetUp();
50 browser_view_ = static_cast<BrowserView*>(browser()->window()); 86 browser_view_ = static_cast<BrowserView*>(browser()->window());
51 // Memory ownership is tricky here. BrowserView has taken ownership of 87 // Memory ownership is tricky here. BrowserView has taken ownership of
52 // |browser|, so BrowserWithTestWindowTest cannot continue to own it. 88 // |browser|, so BrowserWithTestWindowTest cannot continue to own it.
53 ASSERT_TRUE(release_browser()); 89 ASSERT_TRUE(release_browser());
54 } 90 }
55 91
56 void BrowserViewTest::TearDown() { 92 void BrowserViewTest::TearDown() {
93 // Clean up any tabs we opened, otherwise Browser crashes in destruction.
94 browser_view_->browser()->tab_strip_model()->CloseAllTabs();
57 // Ensure the Browser is reset before BrowserWithTestWindowTest cleans up 95 // Ensure the Browser is reset before BrowserWithTestWindowTest cleans up
58 // the Profile. 96 // the Profile.
59 browser_view_->GetWidget()->CloseNow(); 97 browser_view_->GetWidget()->CloseNow();
60 browser_view_ = NULL; 98 browser_view_ = NULL;
61 BrowserWithTestWindowTest::TearDown(); 99 BrowserWithTestWindowTest::TearDown();
62 #if defined(OS_CHROMEOS) 100 #if defined(OS_CHROMEOS)
63 chromeos::input_method::Shutdown(); 101 chromeos::input_method::Shutdown();
64 #endif 102 #endif
65 local_state_.reset(NULL); 103 local_state_.reset(NULL);
66 } 104 }
67 105
106 TestingProfile* BrowserViewTest::CreateProfile() {
107 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile();
108 // TemplateURLService is normally NULL during testing. Instant extended
109 // needs this service so set a custom factory function.
110 TemplateURLServiceFactory::GetInstance()->SetTestingFactory(
111 profile, &CreateTemplateURLService);
112 return profile;
113 }
114
68 BrowserWindow* BrowserViewTest::CreateBrowserWindow() { 115 BrowserWindow* BrowserViewTest::CreateBrowserWindow() {
69 // Allow BrowserWithTestWindowTest to use Browser to create the default 116 // Allow BrowserWithTestWindowTest to use Browser to create the default
70 // BrowserView and BrowserFrame. 117 // BrowserView and BrowserFrame.
71 return NULL; 118 return NULL;
72 } 119 }
73 120
74 // Test basic construction and initialization. 121 // Test basic construction and initialization.
75 TEST_F(BrowserViewTest, BrowserView) { 122 TEST_F(BrowserViewTest, BrowserView) {
76 // The window is owned by the native widget, not the test class. 123 // The window is owned by the native widget, not the test class.
77 EXPECT_FALSE(window()); 124 EXPECT_FALSE(window());
78 // |browser_view_| owns the Browser, not the test class. 125 // |browser_view_| owns the Browser, not the test class.
79 EXPECT_FALSE(browser()); 126 EXPECT_FALSE(browser());
80 EXPECT_TRUE(browser_view()->browser()); 127 EXPECT_TRUE(browser_view()->browser());
81 128
82 // Test initial state. 129 // Test initial state.
83 EXPECT_TRUE(browser_view()->IsTabStripVisible()); 130 EXPECT_TRUE(browser_view()->IsTabStripVisible());
84 EXPECT_FALSE(browser_view()->IsOffTheRecord()); 131 EXPECT_FALSE(browser_view()->IsOffTheRecord());
85 EXPECT_EQ(IDR_OTR_ICON, browser_view()->GetOTRIconResourceID()); 132 EXPECT_EQ(IDR_OTR_ICON, browser_view()->GetOTRIconResourceID());
86 EXPECT_FALSE(browser_view()->IsGuestSession()); 133 EXPECT_FALSE(browser_view()->IsGuestSession());
87 EXPECT_FALSE(browser_view()->ShouldShowAvatar()); 134 EXPECT_FALSE(browser_view()->ShouldShowAvatar());
88 EXPECT_TRUE(browser_view()->IsBrowserTypeNormal()); 135 EXPECT_TRUE(browser_view()->IsBrowserTypeNormal());
89 EXPECT_FALSE(browser_view()->IsFullscreen()); 136 EXPECT_FALSE(browser_view()->IsFullscreen());
90 EXPECT_FALSE(browser_view()->IsBookmarkBarVisible()); 137 EXPECT_FALSE(browser_view()->IsBookmarkBarVisible());
91 EXPECT_FALSE(browser_view()->IsBookmarkBarAnimating()); 138 EXPECT_FALSE(browser_view()->IsBookmarkBarAnimating());
139 }
92 140
93 // Ensure we've initialized enough to run Layout(). 141 // Test layout of the top-of-window UI.
94 browser_view()->Layout(); 142 TEST_F(BrowserViewTest, BrowserViewLayout) {
95 // TDOO(jamescook): Layout assertions. 143 BookmarkBarView::DisableAnimationsForTesting(true);
144
145 // |browser_view_| owns the Browser, not the test class.
146 Browser* browser = browser_view()->browser();
147 TopContainerView* top_container = browser_view()->top_container();
148 TabStrip* tabstrip = browser_view()->tabstrip();
149 ToolbarView* toolbar = browser_view()->toolbar();
150 views::SingleSplitView* contents_split =
151 browser_view()->GetContentsSplitForTest();
152 views::WebView* contents_web_view =
153 browser_view()->GetContentsWebViewForTest();
154
155 // Start with a single tab open to a normal page.
156 AddTab(browser, GURL("about:blank"));
157
158 // Verify the view hierarchy.
159 EXPECT_EQ(top_container, browser_view()->tabstrip()->parent());
160 EXPECT_EQ(top_container, browser_view()->toolbar()->parent());
161 EXPECT_EQ(top_container, browser_view()->GetBookmarkBarView()->parent());
162 EXPECT_EQ(browser_view(), browser_view()->infobar_container()->parent());
163
164 // Top container is at the front of the view hierarchy.
165 EXPECT_EQ(browser_view()->child_count() - 1,
166 browser_view()->GetIndexOf(top_container));
167
168 // Verify basic layout.
169 EXPECT_EQ(0, top_container->x());
170 EXPECT_EQ(0, top_container->y());
171 EXPECT_EQ(browser_view()->width(), top_container->width());
172 // Tabstrip layout varies based on window frame sizes.
173 gfx::Point expected_tabstrip_origin = ExpectedTabStripOrigin(browser_view());
174 EXPECT_EQ(expected_tabstrip_origin.x(), tabstrip->x());
175 EXPECT_EQ(expected_tabstrip_origin.y(), tabstrip->y());
176 EXPECT_EQ(0, toolbar->x());
177 EXPECT_EQ(
178 tabstrip->bounds().bottom() -
179 BrowserViewLayout::kToolbarTabStripVerticalOverlap,
180 toolbar->y());
181 EXPECT_EQ(0, contents_split->x());
182 EXPECT_EQ(toolbar->bounds().bottom(), contents_split->y());
183 EXPECT_EQ(0, contents_web_view->x());
184 EXPECT_EQ(0, contents_web_view->y());
185
186 // Verify bookmark bar visibility.
187 BookmarkBarView* bookmark_bar = browser_view()->GetBookmarkBarView();
188 EXPECT_FALSE(bookmark_bar->visible());
189 EXPECT_FALSE(bookmark_bar->IsDetached());
190 chrome::ExecuteCommand(browser, IDC_SHOW_BOOKMARK_BAR);
191 EXPECT_TRUE(bookmark_bar->visible());
192 EXPECT_FALSE(bookmark_bar->IsDetached());
193 chrome::ExecuteCommand(browser, IDC_SHOW_BOOKMARK_BAR);
194 EXPECT_FALSE(bookmark_bar->visible());
195 EXPECT_FALSE(bookmark_bar->IsDetached());
196
197 // Bookmark bar is reparented to BrowserView on NTP.
198 NavigateAndCommitActiveTabWithTitle(browser,
199 GURL(chrome::kChromeUINewTabURL),
200 string16());
201 EXPECT_TRUE(bookmark_bar->visible());
202 EXPECT_TRUE(bookmark_bar->IsDetached());
203 EXPECT_EQ(browser_view(), bookmark_bar->parent());
204 // Top container is still in front.
205 EXPECT_EQ(browser_view()->child_count() - 1,
206 browser_view()->GetIndexOf(top_container));
207
208 // Bookmark bar layout on NTP.
209 EXPECT_EQ(0, bookmark_bar->x());
210 EXPECT_EQ(
211 tabstrip->bounds().bottom() +
212 toolbar->height() -
213 BrowserViewLayout::kToolbarTabStripVerticalOverlap -
214 views::NonClientFrameView::kClientEdgeThickness,
215 bookmark_bar->y());
216 EXPECT_EQ(toolbar->bounds().bottom(), contents_split->y());
217 // Contents view has a "top margin" pushing it below the bookmark bar.
218 EXPECT_EQ(bookmark_bar->height() -
219 views::NonClientFrameView::kClientEdgeThickness,
220 contents_web_view->y());
221
222 // Bookmark bar is parented back to top container on normal page.
223 NavigateAndCommitActiveTabWithTitle(browser,
224 GURL("about:blank"),
225 string16());
226 EXPECT_FALSE(bookmark_bar->visible());
227 EXPECT_FALSE(bookmark_bar->IsDetached());
228 EXPECT_EQ(top_container, bookmark_bar->parent());
229 // Top container is still in front.
230 EXPECT_EQ(browser_view()->child_count() - 1,
231 browser_view()->GetIndexOf(top_container));
232
233 BookmarkBarView::DisableAnimationsForTesting(false);
96 } 234 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view_interactive_uitest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698