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