| 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_container.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 #include "ui/views/controls/webview/webview.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), |
| 20 toolbar_visible_(true), | 21 toolbar_visible_(true), |
| 21 bookmark_bar_visible_(true), | 22 bookmark_bar_visible_(true), |
| 22 download_shelf_needs_layout_(false) { | 23 download_shelf_needs_layout_(false) { |
| 23 } | 24 } |
| 24 virtual ~MockBrowserViewLayoutDelegate() {} | 25 virtual ~MockBrowserViewLayoutDelegate() {} |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 virtual gfx::Size GetPreferredSize() OVERRIDE { | 88 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 88 return size_; | 89 return size_; |
| 89 } | 90 } |
| 90 | 91 |
| 91 private: | 92 private: |
| 92 gfx::Size size_; | 93 gfx::Size size_; |
| 93 | 94 |
| 94 DISALLOW_COPY_AND_ASSIGN(MockView); | 95 DISALLOW_COPY_AND_ASSIGN(MockView); |
| 95 }; | 96 }; |
| 96 | 97 |
| 98 // A simple web view that prefers an initial size. |
| 99 class MockWebView : public views::WebView { |
| 100 public: |
| 101 explicit MockWebView(gfx::Size initial_size) |
| 102 : views::WebView(NULL), |
| 103 size_(initial_size) { |
| 104 SetBoundsRect(gfx::Rect(gfx::Point(), size_)); |
| 105 } |
| 106 virtual ~MockWebView() {} |
| 107 |
| 108 // views::View overrides: |
| 109 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 110 return size_; |
| 111 } |
| 112 |
| 113 private: |
| 114 gfx::Size size_; |
| 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(MockWebView); |
| 117 }; |
| 118 |
| 119 |
| 97 /////////////////////////////////////////////////////////////////////////////// | 120 /////////////////////////////////////////////////////////////////////////////// |
| 98 | 121 |
| 99 class MockImmersiveModeController : public ImmersiveModeController { | 122 class MockImmersiveModeController : public ImmersiveModeController { |
| 100 public: | 123 public: |
| 101 MockImmersiveModeController() {} | 124 MockImmersiveModeController() {} |
| 102 virtual ~MockImmersiveModeController() {} | 125 virtual ~MockImmersiveModeController() {} |
| 103 | 126 |
| 104 // ImmersiveModeController overrides: | 127 // ImmersiveModeController overrides: |
| 105 virtual void Init(Delegate* delegate, | 128 virtual void Init(Delegate* delegate, |
| 106 views::Widget* widget, | 129 views::Widget* widget, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 tab_strip_ = new TabStrip(NULL); | 181 tab_strip_ = new TabStrip(NULL); |
| 159 top_container_->AddChildView(tab_strip_); | 182 top_container_->AddChildView(tab_strip_); |
| 160 toolbar_ = new MockView(gfx::Size(800, 30)); | 183 toolbar_ = new MockView(gfx::Size(800, 30)); |
| 161 top_container_->AddChildView(toolbar_); | 184 top_container_->AddChildView(toolbar_); |
| 162 root_view_->AddChildView(top_container_); | 185 root_view_->AddChildView(top_container_); |
| 163 | 186 |
| 164 infobar_container_ = new InfoBarContainerView(NULL); | 187 infobar_container_ = new InfoBarContainerView(NULL); |
| 165 root_view_->AddChildView(infobar_container_); | 188 root_view_->AddChildView(infobar_container_); |
| 166 | 189 |
| 167 contents_split_ = new MockView(gfx::Size(800, 600)); | 190 contents_split_ = new MockView(gfx::Size(800, 600)); |
| 168 active_web_view_ = new MockView(gfx::Size(800, 600)); | 191 active_web_view_ = new MockWebView(gfx::Size(800, 600)); |
| 169 contents_container_ = new ContentsContainer(active_web_view_); | 192 contents_container_ = new ContentsContainer(active_web_view_); |
| 170 contents_split_->AddChildView(contents_container_); | 193 contents_split_->AddChildView(contents_container_); |
| 171 root_view_->AddChildView(contents_split_); | 194 root_view_->AddChildView(contents_split_); |
| 172 | 195 |
| 173 // TODO(jamescook): Attach |layout_| to |root_view_|? | 196 // TODO(jamescook): Attach |layout_| to |root_view_|? |
| 174 layout_.reset(new BrowserViewLayout); | 197 layout_.reset(new BrowserViewLayout); |
| 175 delegate_ = new MockBrowserViewLayoutDelegate; | 198 delegate_ = new MockBrowserViewLayoutDelegate; |
| 176 layout_->Init(delegate_, | 199 layout_->Init(delegate_, |
| 177 browser(), | 200 browser(), |
| 178 NULL, // BrowserView. | 201 NULL, // BrowserView. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 190 MockBrowserViewLayoutDelegate* delegate_; // Owned by |layout_|. | 213 MockBrowserViewLayoutDelegate* delegate_; // Owned by |layout_|. |
| 191 scoped_ptr<MockView> root_view_; | 214 scoped_ptr<MockView> root_view_; |
| 192 | 215 |
| 193 // Views owned by |root_view_|. | 216 // Views owned by |root_view_|. |
| 194 MockView* top_container_; | 217 MockView* top_container_; |
| 195 TabStrip* tab_strip_; | 218 TabStrip* tab_strip_; |
| 196 MockView* toolbar_; | 219 MockView* toolbar_; |
| 197 InfoBarContainerView* infobar_container_; | 220 InfoBarContainerView* infobar_container_; |
| 198 MockView* contents_split_; | 221 MockView* contents_split_; |
| 199 ContentsContainer* contents_container_; | 222 ContentsContainer* contents_container_; |
| 200 MockView* active_web_view_; | 223 MockWebView* active_web_view_; |
| 201 | 224 |
| 202 scoped_ptr<MockImmersiveModeController> immersive_mode_controller_; | 225 scoped_ptr<MockImmersiveModeController> immersive_mode_controller_; |
| 203 | 226 |
| 204 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayoutTest); | 227 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayoutTest); |
| 205 }; | 228 }; |
| 206 | 229 |
| 207 // Test basic construction and initialization. | 230 // Test basic construction and initialization. |
| 208 TEST_F(BrowserViewLayoutTest, BrowserViewLayout) { | 231 TEST_F(BrowserViewLayoutTest, BrowserViewLayout) { |
| 209 EXPECT_TRUE(layout()->browser()); | 232 EXPECT_TRUE(layout()->browser()); |
| 210 EXPECT_TRUE(layout()->GetWebContentsModalDialogHost()); | 233 EXPECT_TRUE(layout()->GetWebContentsModalDialogHost()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 const int kBottom = 500; | 271 const int kBottom = 500; |
| 249 EXPECT_EQ(kBottom, layout()->LayoutDownloadShelf(kBottom)); | 272 EXPECT_EQ(kBottom, layout()->LayoutDownloadShelf(kBottom)); |
| 250 | 273 |
| 251 // Download shelf layout moves up the bottom edge and sets visibility. | 274 // Download shelf layout moves up the bottom edge and sets visibility. |
| 252 delegate()->set_download_shelf_needs_layout(true); | 275 delegate()->set_download_shelf_needs_layout(true); |
| 253 download_shelf->SetVisible(false); | 276 download_shelf->SetVisible(false); |
| 254 EXPECT_EQ(450, layout()->LayoutDownloadShelf(kBottom)); | 277 EXPECT_EQ(450, layout()->LayoutDownloadShelf(kBottom)); |
| 255 EXPECT_TRUE(download_shelf->visible()); | 278 EXPECT_TRUE(download_shelf->visible()); |
| 256 EXPECT_EQ("0,450 0x50", download_shelf->bounds().ToString()); | 279 EXPECT_EQ("0,450 0x50", download_shelf->bounds().ToString()); |
| 257 } | 280 } |
| OLD | NEW |