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_layout_manager.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 explicit MockBrowserViewLayoutDelegate(views::View* contents_web_view) | 18 explicit MockBrowserViewLayoutDelegate(views::View* contents_web_view) |
19 : contents_web_view_(contents_web_view), | 19 : contents_web_view_(contents_web_view), |
20 tab_strip_visible_(true), | 20 tab_strip_visible_(true), |
21 toolbar_visible_(true), | 21 toolbar_visible_(true), |
22 bookmark_bar_visible_(true), | 22 bookmark_bar_visible_(true), |
23 download_shelf_needs_layout_(false) { | 23 download_shelf_needs_layout_(false) { |
24 } | 24 } |
25 virtual ~MockBrowserViewLayoutDelegate() {} | 25 ~MockBrowserViewLayoutDelegate() override {} |
26 | 26 |
27 void set_download_shelf_needs_layout(bool layout) { | 27 void set_download_shelf_needs_layout(bool layout) { |
28 download_shelf_needs_layout_ = layout; | 28 download_shelf_needs_layout_ = layout; |
29 } | 29 } |
30 void set_tab_strip_visible(bool visible) { | 30 void set_tab_strip_visible(bool visible) { |
31 tab_strip_visible_ = visible; | 31 tab_strip_visible_ = visible; |
32 } | 32 } |
33 void set_toolbar_visible(bool visible) { | 33 void set_toolbar_visible(bool visible) { |
34 toolbar_visible_ = visible; | 34 toolbar_visible_ = visible; |
35 } | 35 } |
36 void set_bookmark_bar_visible(bool visible) { | 36 void set_bookmark_bar_visible(bool visible) { |
37 bookmark_bar_visible_ = visible; | 37 bookmark_bar_visible_ = visible; |
38 } | 38 } |
39 | 39 |
40 // BrowserViewLayout::Delegate overrides: | 40 // BrowserViewLayout::Delegate overrides: |
41 virtual views::View* GetContentsWebView() const override { | 41 views::View* GetContentsWebView() const override { |
42 return contents_web_view_; | 42 return contents_web_view_; |
43 } | 43 } |
44 virtual bool IsTabStripVisible() const override { | 44 bool IsTabStripVisible() const override { return tab_strip_visible_; } |
45 return tab_strip_visible_; | 45 gfx::Rect GetBoundsForTabStripInBrowserView() const override { |
46 } | |
47 virtual gfx::Rect GetBoundsForTabStripInBrowserView() const override { | |
48 return gfx::Rect(); | 46 return gfx::Rect(); |
49 } | 47 } |
50 virtual int GetTopInsetInBrowserView() const override { | 48 int GetTopInsetInBrowserView() const override { return 0; } |
51 return 0; | 49 int GetThemeBackgroundXInset() const override { return 0; } |
52 } | 50 bool IsToolbarVisible() const override { return toolbar_visible_; } |
53 virtual int GetThemeBackgroundXInset() const override { | 51 bool IsBookmarkBarVisible() const override { return bookmark_bar_visible_; } |
54 return 0; | 52 bool DownloadShelfNeedsLayout() const override { |
55 } | |
56 virtual bool IsToolbarVisible() const override { | |
57 return toolbar_visible_; | |
58 } | |
59 virtual bool IsBookmarkBarVisible() const override { | |
60 return bookmark_bar_visible_; | |
61 } | |
62 virtual bool DownloadShelfNeedsLayout() const override { | |
63 return download_shelf_needs_layout_; | 53 return download_shelf_needs_layout_; |
64 } | 54 } |
65 | 55 |
66 virtual FullscreenExitBubbleViews* GetFullscreenExitBubble() const override { | 56 FullscreenExitBubbleViews* GetFullscreenExitBubble() const override { |
67 return NULL; | 57 return NULL; |
68 } | 58 } |
69 | 59 |
70 private: | 60 private: |
71 views::View* contents_web_view_; | 61 views::View* contents_web_view_; |
72 bool tab_strip_visible_; | 62 bool tab_strip_visible_; |
73 bool toolbar_visible_; | 63 bool toolbar_visible_; |
74 bool bookmark_bar_visible_; | 64 bool bookmark_bar_visible_; |
75 bool download_shelf_needs_layout_; | 65 bool download_shelf_needs_layout_; |
76 | 66 |
77 DISALLOW_COPY_AND_ASSIGN(MockBrowserViewLayoutDelegate); | 67 DISALLOW_COPY_AND_ASSIGN(MockBrowserViewLayoutDelegate); |
78 }; | 68 }; |
79 | 69 |
80 /////////////////////////////////////////////////////////////////////////////// | 70 /////////////////////////////////////////////////////////////////////////////// |
81 | 71 |
82 // A simple view that prefers an initial size. | 72 // A simple view that prefers an initial size. |
83 class MockView : public views::View { | 73 class MockView : public views::View { |
84 public: | 74 public: |
85 explicit MockView(gfx::Size initial_size) | 75 explicit MockView(gfx::Size initial_size) |
86 : size_(initial_size) { | 76 : size_(initial_size) { |
87 SetBoundsRect(gfx::Rect(gfx::Point(), size_)); | 77 SetBoundsRect(gfx::Rect(gfx::Point(), size_)); |
88 } | 78 } |
89 virtual ~MockView() {} | 79 ~MockView() override {} |
90 | 80 |
91 // views::View overrides: | 81 // views::View overrides: |
92 virtual gfx::Size GetPreferredSize() const override { | 82 gfx::Size GetPreferredSize() const override { return size_; } |
93 return size_; | |
94 } | |
95 | 83 |
96 private: | 84 private: |
97 gfx::Size size_; | 85 gfx::Size size_; |
98 | 86 |
99 DISALLOW_COPY_AND_ASSIGN(MockView); | 87 DISALLOW_COPY_AND_ASSIGN(MockView); |
100 }; | 88 }; |
101 | 89 |
102 /////////////////////////////////////////////////////////////////////////////// | 90 /////////////////////////////////////////////////////////////////////////////// |
103 | 91 |
104 class MockImmersiveModeController : public ImmersiveModeController { | 92 class MockImmersiveModeController : public ImmersiveModeController { |
105 public: | 93 public: |
106 MockImmersiveModeController() {} | 94 MockImmersiveModeController() {} |
107 virtual ~MockImmersiveModeController() {} | 95 ~MockImmersiveModeController() override {} |
108 | 96 |
109 // ImmersiveModeController overrides: | 97 // ImmersiveModeController overrides: |
110 virtual void Init(BrowserView* browser_view) override {} | 98 void Init(BrowserView* browser_view) override {} |
111 virtual void SetEnabled(bool enabled) override {} | 99 void SetEnabled(bool enabled) override {} |
112 virtual bool IsEnabled() const override { return false; } | 100 bool IsEnabled() const override { return false; } |
113 virtual bool ShouldHideTabIndicators() const override { return false; } | 101 bool ShouldHideTabIndicators() const override { return false; } |
114 virtual bool ShouldHideTopViews() const override { return false; } | 102 bool ShouldHideTopViews() const override { return false; } |
115 virtual bool IsRevealed() const override { return false; } | 103 bool IsRevealed() const override { return false; } |
116 virtual int GetTopContainerVerticalOffset( | 104 int GetTopContainerVerticalOffset( |
117 const gfx::Size& top_container_size) const override { return 0; } | 105 const gfx::Size& top_container_size) const override { |
118 virtual ImmersiveRevealedLock* GetRevealedLock( | 106 return 0; |
119 AnimateReveal animate_reveal) override WARN_UNUSED_RESULT { return NULL; } | 107 } |
120 virtual void OnFindBarVisibleBoundsChanged( | 108 ImmersiveRevealedLock* GetRevealedLock(AnimateReveal animate_reveal) override |
| 109 WARN_UNUSED_RESULT { |
| 110 return NULL; |
| 111 } |
| 112 void OnFindBarVisibleBoundsChanged( |
121 const gfx::Rect& new_visible_bounds) override {} | 113 const gfx::Rect& new_visible_bounds) override {} |
122 virtual void SetupForTest() override {} | 114 void SetupForTest() override {} |
123 | 115 |
124 private: | 116 private: |
125 DISALLOW_COPY_AND_ASSIGN(MockImmersiveModeController); | 117 DISALLOW_COPY_AND_ASSIGN(MockImmersiveModeController); |
126 }; | 118 }; |
127 | 119 |
128 /////////////////////////////////////////////////////////////////////////////// | 120 /////////////////////////////////////////////////////////////////////////////// |
129 // Tests of BrowserViewLayout. Runs tests without constructing a BrowserView. | 121 // Tests of BrowserViewLayout. Runs tests without constructing a BrowserView. |
130 class BrowserViewLayoutTest : public BrowserWithTestWindowTest { | 122 class BrowserViewLayoutTest : public BrowserWithTestWindowTest { |
131 public: | 123 public: |
132 BrowserViewLayoutTest() | 124 BrowserViewLayoutTest() |
133 : delegate_(NULL), | 125 : delegate_(NULL), |
134 top_container_(NULL), | 126 top_container_(NULL), |
135 tab_strip_(NULL), | 127 tab_strip_(NULL), |
136 toolbar_(NULL), | 128 toolbar_(NULL), |
137 infobar_container_(NULL), | 129 infobar_container_(NULL), |
138 contents_container_(NULL), | 130 contents_container_(NULL), |
139 contents_web_view_(NULL), | 131 contents_web_view_(NULL), |
140 devtools_web_view_(NULL) {} | 132 devtools_web_view_(NULL) {} |
141 virtual ~BrowserViewLayoutTest() {} | 133 ~BrowserViewLayoutTest() override {} |
142 | 134 |
143 BrowserViewLayout* layout() { return layout_.get(); } | 135 BrowserViewLayout* layout() { return layout_.get(); } |
144 MockBrowserViewLayoutDelegate* delegate() { return delegate_; } | 136 MockBrowserViewLayoutDelegate* delegate() { return delegate_; } |
145 MockView* root_view() { return root_view_.get(); } | 137 MockView* root_view() { return root_view_.get(); } |
146 MockView* top_container() { return top_container_; } | 138 MockView* top_container() { return top_container_; } |
147 TabStrip* tab_strip() { return tab_strip_; } | 139 TabStrip* tab_strip() { return tab_strip_; } |
148 MockView* toolbar() { return toolbar_; } | 140 MockView* toolbar() { return toolbar_; } |
149 InfoBarContainerView* infobar_container() { return infobar_container_; } | 141 InfoBarContainerView* infobar_container() { return infobar_container_; } |
150 MockView* contents_container() { return contents_container_; } | 142 MockView* contents_container() { return contents_container_; } |
151 | 143 |
152 // BrowserWithTestWindowTest overrides: | 144 // BrowserWithTestWindowTest overrides: |
153 virtual void SetUp() override { | 145 void SetUp() override { |
154 BrowserWithTestWindowTest::SetUp(); | 146 BrowserWithTestWindowTest::SetUp(); |
155 | 147 |
156 root_view_.reset(new MockView(gfx::Size(800, 600))); | 148 root_view_.reset(new MockView(gfx::Size(800, 600))); |
157 | 149 |
158 immersive_mode_controller_.reset(new MockImmersiveModeController); | 150 immersive_mode_controller_.reset(new MockImmersiveModeController); |
159 | 151 |
160 top_container_ = new MockView(gfx::Size(800, 60)); | 152 top_container_ = new MockView(gfx::Size(800, 60)); |
161 tab_strip_ = new TabStrip(NULL); | 153 tab_strip_ = new TabStrip(NULL); |
162 top_container_->AddChildView(tab_strip_); | 154 top_container_->AddChildView(tab_strip_); |
163 toolbar_ = new MockView(gfx::Size(800, 30)); | 155 toolbar_ = new MockView(gfx::Size(800, 30)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 const int kBottom = 500; | 250 const int kBottom = 500; |
259 EXPECT_EQ(kBottom, layout()->LayoutDownloadShelf(kBottom)); | 251 EXPECT_EQ(kBottom, layout()->LayoutDownloadShelf(kBottom)); |
260 | 252 |
261 // Download shelf layout moves up the bottom edge and sets visibility. | 253 // Download shelf layout moves up the bottom edge and sets visibility. |
262 delegate()->set_download_shelf_needs_layout(true); | 254 delegate()->set_download_shelf_needs_layout(true); |
263 download_shelf->SetVisible(false); | 255 download_shelf->SetVisible(false); |
264 EXPECT_EQ(450, layout()->LayoutDownloadShelf(kBottom)); | 256 EXPECT_EQ(450, layout()->LayoutDownloadShelf(kBottom)); |
265 EXPECT_TRUE(download_shelf->visible()); | 257 EXPECT_TRUE(download_shelf->visible()); |
266 EXPECT_EQ("0,450 0x50", download_shelf->bounds().ToString()); | 258 EXPECT_EQ("0,450 0x50", download_shelf->bounds().ToString()); |
267 } | 259 } |
OLD | NEW |