OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tabs/tab.h" | 5 #include "chrome/browser/ui/views/tabs/tab.h" |
6 #include "chrome/browser/ui/views/tabs/tab_controller.h" | 6 #include "chrome/browser/ui/views/tabs/tab_controller.h" |
7 | 7 |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/base/models/list_selection_model.h" | 10 #include "ui/base/models/list_selection_model.h" |
11 #include "ui/views/controls/button/image_button.h" | 11 #include "ui/views/controls/button/image_button.h" |
12 #include "ui/views/controls/label.h" | |
13 #include "ui/views/test/views_test_base.h" | 12 #include "ui/views/test/views_test_base.h" |
14 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
15 | 14 |
16 using views::Widget; | 15 using views::Widget; |
17 | 16 |
18 class FakeTabController : public TabController { | 17 class FakeTabController : public TabController { |
19 public: | 18 public: |
20 FakeTabController() : immersive_style_(false), active_tab_(false) { | 19 FakeTabController() : immersive_style_(false), active_tab_(false) { |
21 } | 20 } |
22 virtual ~FakeTabController() {} | 21 virtual ~FakeTabController() {} |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 EXPECT_FALSE(tab.ShouldShowMediaIndicator()); | 143 EXPECT_FALSE(tab.ShouldShowMediaIndicator()); |
145 break; | 144 break; |
146 } | 145 } |
147 } | 146 } |
148 | 147 |
149 // Check positioning of elements with respect to each other, and that they | 148 // Check positioning of elements with respect to each other, and that they |
150 // are fully within the contents bounds. | 149 // are fully within the contents bounds. |
151 const gfx::Rect contents_bounds = tab.GetContentsBounds(); | 150 const gfx::Rect contents_bounds = tab.GetContentsBounds(); |
152 if (tab.ShouldShowIcon()) { | 151 if (tab.ShouldShowIcon()) { |
153 EXPECT_LE(contents_bounds.x(), tab.favicon_bounds_.x()); | 152 EXPECT_LE(contents_bounds.x(), tab.favicon_bounds_.x()); |
154 if (tab.title_->width() > 0) | 153 if (tab.title_bounds_.width() > 0) |
155 EXPECT_LE(tab.favicon_bounds_.right(), tab.title_->x()); | 154 EXPECT_LE(tab.favicon_bounds_.right(), tab.title_bounds_.x()); |
156 EXPECT_LE(contents_bounds.y(), tab.favicon_bounds_.y()); | 155 EXPECT_LE(contents_bounds.y(), tab.favicon_bounds_.y()); |
157 EXPECT_LE(tab.favicon_bounds_.bottom(), contents_bounds.bottom()); | 156 EXPECT_LE(tab.favicon_bounds_.bottom(), contents_bounds.bottom()); |
158 } | 157 } |
159 if (tab.ShouldShowIcon() && tab.ShouldShowMediaIndicator()) | 158 if (tab.ShouldShowIcon() && tab.ShouldShowMediaIndicator()) |
160 EXPECT_LE(tab.favicon_bounds_.right(), tab.media_indicator_bounds_.x()); | 159 EXPECT_LE(tab.favicon_bounds_.right(), tab.media_indicator_bounds_.x()); |
161 if (tab.ShouldShowMediaIndicator()) { | 160 if (tab.ShouldShowMediaIndicator()) { |
162 if (tab.title_->width() > 0) { | 161 if (tab.title_bounds_.width() > 0) |
163 EXPECT_LE(tab.title_->bounds().right(), | 162 EXPECT_LE(tab.title_bounds_.right(), tab.media_indicator_bounds_.x()); |
164 tab.media_indicator_bounds_.x()); | |
165 } | |
166 EXPECT_LE(tab.media_indicator_bounds_.right(), contents_bounds.right()); | 163 EXPECT_LE(tab.media_indicator_bounds_.right(), contents_bounds.right()); |
167 EXPECT_LE(contents_bounds.y(), tab.media_indicator_bounds_.y()); | 164 EXPECT_LE(contents_bounds.y(), tab.media_indicator_bounds_.y()); |
168 EXPECT_LE(tab.media_indicator_bounds_.bottom(), contents_bounds.bottom()); | 165 EXPECT_LE(tab.media_indicator_bounds_.bottom(), contents_bounds.bottom()); |
169 } | 166 } |
170 if (tab.ShouldShowMediaIndicator() && tab.ShouldShowCloseBox()) { | 167 if (tab.ShouldShowMediaIndicator() && tab.ShouldShowCloseBox()) { |
171 // Note: The media indicator can overlap the left-insets of the close box, | 168 // Note: The media indicator can overlap the left-insets of the close box, |
172 // but should otherwise be to the left of the close button. | 169 // but should otherwise be to the left of the close button. |
173 EXPECT_LE(tab.media_indicator_bounds_.right(), | 170 EXPECT_LE(tab.media_indicator_bounds_.right(), |
174 tab.close_button_->bounds().x() + | 171 tab.close_button_->bounds().x() + |
175 tab.close_button_->GetInsets().left()); | 172 tab.close_button_->GetInsets().left()); |
176 } | 173 } |
177 if (tab.ShouldShowCloseBox()) { | 174 if (tab.ShouldShowCloseBox()) { |
178 // Note: The title bounds can overlap the left-insets of the close box, | 175 // Note: The title bounds can overlap the left-insets of the close box, |
179 // but should otherwise be to the left of the close button. | 176 // but should otherwise be to the left of the close button. |
180 if (tab.title_->width() > 0) { | 177 if (tab.title_bounds_.width() > 0) { |
181 EXPECT_LE(tab.title_->bounds().right(), | 178 EXPECT_LE(tab.title_bounds_.right(), |
182 tab.close_button_->bounds().x() + | 179 tab.close_button_->bounds().x() + |
183 tab.close_button_->GetInsets().left()); | 180 tab.close_button_->GetInsets().left()); |
184 } | 181 } |
185 EXPECT_LE(tab.close_button_->bounds().right(), contents_bounds.right()); | 182 EXPECT_LE(tab.close_button_->bounds().right(), contents_bounds.right()); |
186 EXPECT_LE(contents_bounds.y(), tab.close_button_->bounds().y()); | 183 EXPECT_LE(contents_bounds.y(), tab.close_button_->bounds().y()); |
187 EXPECT_LE(tab.close_button_->bounds().bottom(), contents_bounds.bottom()); | 184 EXPECT_LE(tab.close_button_->bounds().bottom(), contents_bounds.bottom()); |
188 } | 185 } |
189 } | 186 } |
190 }; | 187 }; |
191 | 188 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 tab.Layout(); | 287 tab.Layout(); |
291 gfx::Insets close_button_insets_2 = tab.close_button_->GetInsets(); | 288 gfx::Insets close_button_insets_2 = tab.close_button_->GetInsets(); |
292 EXPECT_EQ(close_button_insets.top(), close_button_insets_2.top()); | 289 EXPECT_EQ(close_button_insets.top(), close_button_insets_2.top()); |
293 EXPECT_EQ(close_button_insets.left(), close_button_insets_2.left()); | 290 EXPECT_EQ(close_button_insets.left(), close_button_insets_2.left()); |
294 EXPECT_EQ(close_button_insets.bottom(), close_button_insets_2.bottom()); | 291 EXPECT_EQ(close_button_insets.bottom(), close_button_insets_2.bottom()); |
295 EXPECT_EQ(close_button_insets.right(), close_button_insets_2.right()); | 292 EXPECT_EQ(close_button_insets.right(), close_button_insets_2.right()); |
296 | 293 |
297 // Also make sure the close button is sized as large as the tab. | 294 // Also make sure the close button is sized as large as the tab. |
298 EXPECT_EQ(50, tab.close_button_->bounds().height()); | 295 EXPECT_EQ(50, tab.close_button_->bounds().height()); |
299 } | 296 } |
OLD | NEW |