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

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

Issue 63173016: DevTools: place DevTools WebContents underneath inspected WebContents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Gtk Created 7 years 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
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_layout.h" 5 #include "chrome/browser/ui/views/frame/browser_view_layout.h"
6 6
7 #include "chrome/browser/ui/views/frame/browser_view.h" 7 #include "chrome/browser/ui/views/frame/browser_view.h"
8 #include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h" 8 #include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h"
9 #include "chrome/browser/ui/views/frame/contents_container.h" 9 #include "chrome/browser/ui/views/frame/contents_container.h"
10 #include "chrome/browser/ui/views/frame/devtools_container.h"
10 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 11 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
11 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" 12 #include "chrome/browser/ui/views/infobars/infobar_container_view.h"
12 #include "chrome/browser/ui/views/tabs/tab_strip.h" 13 #include "chrome/browser/ui/views/tabs/tab_strip.h"
13 #include "chrome/test/base/browser_with_test_window_test.h" 14 #include "chrome/test/base/browser_with_test_window_test.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 class MockBrowserViewLayoutDelegate : public BrowserViewLayoutDelegate { 17 class MockBrowserViewLayoutDelegate : public BrowserViewLayoutDelegate {
17 public: 18 public:
18 MockBrowserViewLayoutDelegate() 19 MockBrowserViewLayoutDelegate()
19 : tab_strip_visible_(true), 20 : tab_strip_visible_(true),
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 /////////////////////////////////////////////////////////////////////////////// 129 ///////////////////////////////////////////////////////////////////////////////
129 // Tests of BrowserViewLayout. Runs tests without constructing a BrowserView. 130 // Tests of BrowserViewLayout. Runs tests without constructing a BrowserView.
130 class BrowserViewLayoutTest : public BrowserWithTestWindowTest { 131 class BrowserViewLayoutTest : public BrowserWithTestWindowTest {
131 public: 132 public:
132 BrowserViewLayoutTest() 133 BrowserViewLayoutTest()
133 : delegate_(NULL), 134 : delegate_(NULL),
134 top_container_(NULL), 135 top_container_(NULL),
135 tab_strip_(NULL), 136 tab_strip_(NULL),
136 toolbar_(NULL), 137 toolbar_(NULL),
137 infobar_container_(NULL), 138 infobar_container_(NULL),
138 contents_split_(NULL),
139 contents_container_(NULL), 139 contents_container_(NULL),
140 devtools_container_(NULL),
140 active_web_view_(NULL) {} 141 active_web_view_(NULL) {}
141 virtual ~BrowserViewLayoutTest() {} 142 virtual ~BrowserViewLayoutTest() {}
142 143
143 BrowserViewLayout* layout() { return layout_.get(); } 144 BrowserViewLayout* layout() { return layout_.get(); }
144 MockBrowserViewLayoutDelegate* delegate() { return delegate_; } 145 MockBrowserViewLayoutDelegate* delegate() { return delegate_; }
145 MockView* root_view() { return root_view_.get(); } 146 MockView* root_view() { return root_view_.get(); }
146 MockView* top_container() { return top_container_; } 147 MockView* top_container() { return top_container_; }
147 TabStrip* tab_strip() { return tab_strip_; } 148 TabStrip* tab_strip() { return tab_strip_; }
148 MockView* toolbar() { return toolbar_; } 149 MockView* toolbar() { return toolbar_; }
149 InfoBarContainerView* infobar_container() { return infobar_container_; } 150 InfoBarContainerView* infobar_container() { return infobar_container_; }
150 MockView* contents_split() { return contents_split_; }
151 ContentsContainer* contents_container() { return contents_container_; } 151 ContentsContainer* contents_container() { return contents_container_; }
152 DevToolsContainer* devtools_container() { return devtools_container_; }
152 153
153 // BrowserWithTestWindowTest overrides: 154 // BrowserWithTestWindowTest overrides:
154 virtual void SetUp() OVERRIDE { 155 virtual void SetUp() OVERRIDE {
155 BrowserWithTestWindowTest::SetUp(); 156 BrowserWithTestWindowTest::SetUp();
156 157
157 root_view_.reset(new MockView(gfx::Size(800, 600))); 158 root_view_.reset(new MockView(gfx::Size(800, 600)));
158 159
159 immersive_mode_controller_.reset(new MockImmersiveModeController); 160 immersive_mode_controller_.reset(new MockImmersiveModeController);
160 161
161 top_container_ = new MockView(gfx::Size(800, 60)); 162 top_container_ = new MockView(gfx::Size(800, 60));
162 tab_strip_ = new TabStrip(NULL); 163 tab_strip_ = new TabStrip(NULL);
163 top_container_->AddChildView(tab_strip_); 164 top_container_->AddChildView(tab_strip_);
164 toolbar_ = new MockView(gfx::Size(800, 30)); 165 toolbar_ = new MockView(gfx::Size(800, 30));
165 top_container_->AddChildView(toolbar_); 166 top_container_->AddChildView(toolbar_);
166 root_view_->AddChildView(top_container_); 167 root_view_->AddChildView(top_container_);
167 168
168 infobar_container_ = new InfoBarContainerView(NULL); 169 infobar_container_ = new InfoBarContainerView(NULL);
169 root_view_->AddChildView(infobar_container_); 170 root_view_->AddChildView(infobar_container_);
170 171
171 contents_split_ = new MockView(gfx::Size(800, 600));
172 active_web_view_ = new MockView(gfx::Size(800, 600)); 172 active_web_view_ = new MockView(gfx::Size(800, 600));
173 contents_container_ = new ContentsContainer(active_web_view_); 173 devtools_view_ = new MockView(gfx::Size(800, 600));
174 contents_split_->AddChildView(contents_container_); 174 devtools_view_->SetVisible(false);
175 root_view_->AddChildView(contents_split_); 175 devtools_container_ =
176 new DevToolsContainer(active_web_view_, devtools_view_);
177 contents_container_ = new ContentsContainer(devtools_container_);
178 root_view_->AddChildView(contents_container_);
176 179
177 // TODO(jamescook): Attach |layout_| to |root_view_|? 180 // TODO(jamescook): Attach |layout_| to |root_view_|?
178 layout_.reset(new BrowserViewLayout); 181 layout_.reset(new BrowserViewLayout);
179 delegate_ = new MockBrowserViewLayoutDelegate; 182 delegate_ = new MockBrowserViewLayoutDelegate;
180 layout_->Init(delegate_, 183 layout_->Init(delegate_,
181 browser(), 184 browser(),
182 NULL, // BrowserView. 185 NULL, // BrowserView.
183 top_container_, 186 top_container_,
184 tab_strip_, 187 tab_strip_,
185 toolbar_, 188 toolbar_,
186 infobar_container_, 189 infobar_container_,
187 contents_split_,
188 contents_container_, 190 contents_container_,
189 immersive_mode_controller_.get()); 191 immersive_mode_controller_.get());
190 } 192 }
191 193
192 private: 194 private:
193 scoped_ptr<BrowserViewLayout> layout_; 195 scoped_ptr<BrowserViewLayout> layout_;
194 MockBrowserViewLayoutDelegate* delegate_; // Owned by |layout_|. 196 MockBrowserViewLayoutDelegate* delegate_; // Owned by |layout_|.
195 scoped_ptr<MockView> root_view_; 197 scoped_ptr<MockView> root_view_;
196 198
197 // Views owned by |root_view_|. 199 // Views owned by |root_view_|.
198 MockView* top_container_; 200 MockView* top_container_;
199 TabStrip* tab_strip_; 201 TabStrip* tab_strip_;
200 MockView* toolbar_; 202 MockView* toolbar_;
201 InfoBarContainerView* infobar_container_; 203 InfoBarContainerView* infobar_container_;
202 MockView* contents_split_;
203 ContentsContainer* contents_container_; 204 ContentsContainer* contents_container_;
205 DevToolsContainer* devtools_container_;
204 MockView* active_web_view_; 206 MockView* active_web_view_;
207 MockView* devtools_view_;
205 208
206 scoped_ptr<MockImmersiveModeController> immersive_mode_controller_; 209 scoped_ptr<MockImmersiveModeController> immersive_mode_controller_;
207 210
208 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayoutTest); 211 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayoutTest);
209 }; 212 };
210 213
211 // Test basic construction and initialization. 214 // Test basic construction and initialization.
212 TEST_F(BrowserViewLayoutTest, BrowserViewLayout) { 215 TEST_F(BrowserViewLayoutTest, BrowserViewLayout) {
213 EXPECT_TRUE(layout()->browser()); 216 EXPECT_TRUE(layout()->browser());
214 EXPECT_TRUE(layout()->GetWebContentsModalDialogHost()); 217 EXPECT_TRUE(layout()->GetWebContentsModalDialogHost());
215 EXPECT_FALSE(layout()->InfobarVisible()); 218 EXPECT_FALSE(layout()->InfobarVisible());
216 } 219 }
217 220
218 // Test the core layout functions. 221 // Test the core layout functions.
219 TEST_F(BrowserViewLayoutTest, Layout) { 222 TEST_F(BrowserViewLayoutTest, Layout) {
220 // Simulate a window with no interesting UI. 223 // Simulate a window with no interesting UI.
221 delegate()->set_tab_strip_visible(false); 224 delegate()->set_tab_strip_visible(false);
222 delegate()->set_toolbar_visible(false); 225 delegate()->set_toolbar_visible(false);
223 delegate()->set_bookmark_bar_visible(false); 226 delegate()->set_bookmark_bar_visible(false);
224 layout()->Layout(root_view()); 227 layout()->Layout(root_view());
225 228
226 // Top views are zero-height. 229 // Top views are zero-height.
227 EXPECT_EQ("0,0 0x0", tab_strip()->bounds().ToString()); 230 EXPECT_EQ("0,0 0x0", tab_strip()->bounds().ToString());
228 EXPECT_EQ("0,0 800x0", toolbar()->bounds().ToString()); 231 EXPECT_EQ("0,0 800x0", toolbar()->bounds().ToString());
229 EXPECT_EQ("0,0 800x0", infobar_container()->bounds().ToString()); 232 EXPECT_EQ("0,0 800x0", infobar_container()->bounds().ToString());
230 // Contents split fills the window. 233 // Contents split fills the window.
231 EXPECT_EQ("0,0 800x600", contents_split()->bounds().ToString()); 234 EXPECT_EQ("0,0 800x600", contents_container()->bounds().ToString());
232 235
233 // Turn on the toolbar, like in a pop-up window. 236 // Turn on the toolbar, like in a pop-up window.
234 delegate()->set_toolbar_visible(true); 237 delegate()->set_toolbar_visible(true);
235 layout()->Layout(root_view()); 238 layout()->Layout(root_view());
236 239
237 // Now the toolbar has bounds and other views shift down. 240 // Now the toolbar has bounds and other views shift down.
238 EXPECT_EQ("0,0 0x0", tab_strip()->bounds().ToString()); 241 EXPECT_EQ("0,0 0x0", tab_strip()->bounds().ToString());
239 EXPECT_EQ("0,0 800x30", toolbar()->bounds().ToString()); 242 EXPECT_EQ("0,0 800x30", toolbar()->bounds().ToString());
240 EXPECT_EQ("0,30 800x0", infobar_container()->bounds().ToString()); 243 EXPECT_EQ("0,30 800x0", infobar_container()->bounds().ToString());
241 EXPECT_EQ("0,30 800x570", contents_split()->bounds().ToString()); 244 EXPECT_EQ("0,30 800x570", contents_container()->bounds().ToString());
242 245
243 // TODO(jamescook): Tab strip and bookmark bar. 246 // TODO(jamescook): Tab strip and bookmark bar.
244 } 247 }
245 248
246 TEST_F(BrowserViewLayoutTest, LayoutDownloadShelf) { 249 TEST_F(BrowserViewLayoutTest, LayoutDownloadShelf) {
247 scoped_ptr<MockView> download_shelf(new MockView(gfx::Size(800, 50))); 250 scoped_ptr<MockView> download_shelf(new MockView(gfx::Size(800, 50)));
248 layout()->set_download_shelf(download_shelf.get()); 251 layout()->set_download_shelf(download_shelf.get());
249 252
250 // If download shelf doesn't need layout, it doesn't move the bottom edge. 253 // If download shelf doesn't need layout, it doesn't move the bottom edge.
251 delegate()->set_download_shelf_needs_layout(false); 254 delegate()->set_download_shelf_needs_layout(false);
252 const int kBottom = 500; 255 const int kBottom = 500;
253 EXPECT_EQ(kBottom, layout()->LayoutDownloadShelf(kBottom)); 256 EXPECT_EQ(kBottom, layout()->LayoutDownloadShelf(kBottom));
254 257
255 // Download shelf layout moves up the bottom edge and sets visibility. 258 // Download shelf layout moves up the bottom edge and sets visibility.
256 delegate()->set_download_shelf_needs_layout(true); 259 delegate()->set_download_shelf_needs_layout(true);
257 download_shelf->SetVisible(false); 260 download_shelf->SetVisible(false);
258 EXPECT_EQ(450, layout()->LayoutDownloadShelf(kBottom)); 261 EXPECT_EQ(450, layout()->LayoutDownloadShelf(kBottom));
259 EXPECT_TRUE(download_shelf->visible()); 262 EXPECT_TRUE(download_shelf->visible());
260 EXPECT_EQ("0,450 0x50", download_shelf->bounds().ToString()); 263 EXPECT_EQ("0,450 0x50", download_shelf->bounds().ToString());
261 } 264 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698