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

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

Issue 1972033002: Simplify some old avatar menu button code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reinstate ash browser test fix Created 4 years, 7 months 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/opaque_browser_frame_view_layout.h" 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/layout_constants.h" 10 #include "chrome/browser/ui/layout_constants.h"
11 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" 11 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h"
12 #include "chrome/browser/ui/views/tab_icon_view.h" 12 #include "chrome/browser/ui/views/tab_icon_view.h"
13 #include "chrome/browser/ui/views/tabs/tab.h" 13 #include "chrome/browser/ui/views/tabs/tab.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "components/signin/core/common/profile_management_switches.h" 15 #include "components/signin/core/common/profile_management_switches.h"
16 #include "ui/gfx/image/image_skia.h" 16 #include "ui/gfx/image/image_skia.h"
17 #include "ui/gfx/image/image_skia_rep.h" 17 #include "ui/gfx/image/image_skia_rep.h"
18 #include "ui/gfx/text_constants.h" 18 #include "ui/gfx/text_constants.h"
19 #include "ui/views/controls/button/image_button.h" 19 #include "ui/views/controls/button/image_button.h"
20 #include "ui/views/controls/button/menu_button.h" 20 #include "ui/views/controls/button/menu_button.h"
21 #include "ui/views/controls/label.h" 21 #include "ui/views/controls/label.h"
(...skipping 10 matching lines...) Expand all
32 const int kMaximizeButtonWidth = 25; 32 const int kMaximizeButtonWidth = 25;
33 const int kCloseButtonWidth = 43; 33 const int kCloseButtonWidth = 43;
34 const int kMaximizedExtraCloseWidth = OBFVL::kFrameBorderThickness - 34 const int kMaximizedExtraCloseWidth = OBFVL::kFrameBorderThickness -
35 views::NonClientFrameView::kFrameShadowThickness; 35 views::NonClientFrameView::kFrameShadowThickness;
36 const int kCaptionButtonsWidth = 36 const int kCaptionButtonsWidth =
37 kMinimizeButtonWidth + kMaximizeButtonWidth + kCloseButtonWidth; 37 kMinimizeButtonWidth + kMaximizeButtonWidth + kCloseButtonWidth;
38 const int kCaptionButtonHeight = 18; 38 const int kCaptionButtonHeight = 18;
39 39
40 class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate { 40 class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate {
41 public: 41 public:
42 TestLayoutDelegate() 42 TestLayoutDelegate() : show_caption_buttons_(true), maximized_(false) {}
43 : show_avatar_(false),
44 show_caption_buttons_(true),
45 maximized_(false) {
46 }
47 ~TestLayoutDelegate() override {} 43 ~TestLayoutDelegate() override {}
48 44
49 void set_window_title(const base::string16& title) { window_title_ = title; } 45 void set_window_title(const base::string16& title) { window_title_ = title; }
50 void set_show_avatar(bool show_avatar) { show_avatar_ = show_avatar; }
51 void set_show_caption_buttons(bool show_caption_buttons) { 46 void set_show_caption_buttons(bool show_caption_buttons) {
52 show_caption_buttons_ = show_caption_buttons; 47 show_caption_buttons_ = show_caption_buttons;
53 } 48 }
54 void set_maximized(bool maximized) { maximized_ = maximized; } 49 void set_maximized(bool maximized) { maximized_ = maximized; }
55 50
56 // OpaqueBrowserFrameViewLayoutDelegate: 51 // OpaqueBrowserFrameViewLayoutDelegate:
57 bool ShouldShowWindowIcon() const override { return !window_title_.empty(); } 52 bool ShouldShowWindowIcon() const override { return !window_title_.empty(); }
58 bool ShouldShowWindowTitle() const override { return !window_title_.empty(); } 53 bool ShouldShowWindowTitle() const override { return !window_title_.empty(); }
59 base::string16 GetWindowTitle() const override { return window_title_; } 54 base::string16 GetWindowTitle() const override { return window_title_; }
60 int GetIconSize() const override { return 17; } 55 int GetIconSize() const override { return 17; }
61 gfx::Size GetBrowserViewMinimumSize() const override { 56 gfx::Size GetBrowserViewMinimumSize() const override {
62 return gfx::Size(168, 64); 57 return gfx::Size(168, 64);
63 } 58 }
64 bool ShouldShowCaptionButtons() const override { 59 bool ShouldShowCaptionButtons() const override {
65 return show_caption_buttons_; 60 return show_caption_buttons_;
66 } 61 }
67 bool ShouldShowAvatar() const override { return show_avatar_; }
68 bool IsRegularOrGuestSession() const override { return true; } 62 bool IsRegularOrGuestSession() const override { return true; }
69 gfx::ImageSkia GetOTRAvatarIcon() const override { 63 gfx::ImageSkia GetOTRAvatarIcon() const override {
70 return gfx::ImageSkia(gfx::ImageSkiaRep(gfx::Size(40, 29), 1.0f)); 64 return gfx::ImageSkia(gfx::ImageSkiaRep(gfx::Size(40, 29), 1.0f));
71 } 65 }
72 bool IsMaximized() const override { return maximized_; } 66 bool IsMaximized() const override { return maximized_; }
73 bool IsMinimized() const override { return false; } 67 bool IsMinimized() const override { return false; }
74 bool IsFullscreen() const override { return false; } 68 bool IsFullscreen() const override { return false; }
75 bool IsTabStripVisible() const override { return window_title_.empty(); } 69 bool IsTabStripVisible() const override { return window_title_.empty(); }
76 int GetTabStripHeight() const override { 70 int GetTabStripHeight() const override {
77 return IsTabStripVisible() ? Tab::GetMinimumInactiveSize().height() : 0; 71 return IsTabStripVisible() ? Tab::GetMinimumInactiveSize().height() : 0;
78 } 72 }
79 bool IsToolbarVisible() const override { return true; } 73 bool IsToolbarVisible() const override { return true; }
80 gfx::Size GetTabstripPreferredSize() const override { 74 gfx::Size GetTabstripPreferredSize() const override {
81 return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size(); 75 return IsTabStripVisible() ? gfx::Size(78, 29) : gfx::Size();
82 } 76 }
83 int GetToolbarLeadingCornerClientWidth() const override { return 0; } 77 int GetToolbarLeadingCornerClientWidth() const override { return 0; }
84 78
85 private: 79 private:
86 base::string16 window_title_; 80 base::string16 window_title_;
87 bool show_avatar_;
88 bool show_caption_buttons_; 81 bool show_caption_buttons_;
89 bool maximized_; 82 bool maximized_;
90 83
91 DISALLOW_COPY_AND_ASSIGN(TestLayoutDelegate); 84 DISALLOW_COPY_AND_ASSIGN(TestLayoutDelegate);
92 }; 85 };
93 86
94 } // namespace 87 } // namespace
95 88
96 class OpaqueBrowserFrameViewLayoutTest : public views::ViewsTestBase { 89 class OpaqueBrowserFrameViewLayoutTest : public views::ViewsTestBase {
97 public: 90 public:
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 window_title_ = new views::Label(delegate_->GetWindowTitle()); 152 window_title_ = new views::Label(delegate_->GetWindowTitle());
160 window_title_->SetVisible(delegate_->ShouldShowWindowTitle()); 153 window_title_->SetVisible(delegate_->ShouldShowWindowTitle());
161 window_title_->SetEnabledColor(SK_ColorWHITE); 154 window_title_->SetEnabledColor(SK_ColorWHITE);
162 window_title_->SetSubpixelRenderingEnabled(false); 155 window_title_->SetSubpixelRenderingEnabled(false);
163 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 156 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
164 window_title_->set_id(VIEW_ID_WINDOW_TITLE); 157 window_title_->set_id(VIEW_ID_WINDOW_TITLE);
165 root_view_->AddChildView(window_title_); 158 root_view_->AddChildView(window_title_);
166 } 159 }
167 160
168 void AddNewAvatarButton() { 161 void AddNewAvatarButton() {
169 new_avatar_button_ = 162 avatar_button_ = new views::MenuButton(base::string16(), nullptr, false);
170 new views::MenuButton(base::string16(), nullptr, false); 163 avatar_button_->set_id(VIEW_ID_AVATAR_BUTTON);
171 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); 164 root_view_->AddChildView(avatar_button_);
172 root_view_->AddChildView(new_avatar_button_);
173 delegate_->set_show_avatar(true);
174 } 165 }
175 166
176 int CaptionY() const { 167 int CaptionY() const {
177 return delegate_->IsMaximized() ? 168 return delegate_->IsMaximized() ?
178 0 : views::NonClientFrameView::kFrameShadowThickness; 169 0 : views::NonClientFrameView::kFrameShadowThickness;
179 } 170 }
180 171
181 int CaptionLeft() const { 172 int CaptionLeft() const {
182 return kWindowWidth - 173 return kWindowWidth -
183 (delegate_->IsMaximized() ? kMaximizedExtraCloseWidth 174 (delegate_->IsMaximized() ? kMaximizedExtraCloseWidth
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 EXPECT_EQ(kMinimizeButtonWidth, minimize_button_->width()); 224 EXPECT_EQ(kMinimizeButtonWidth, minimize_button_->width());
234 EXPECT_EQ(visible_button->height(), minimize_button_->height()); 225 EXPECT_EQ(visible_button->height(), minimize_button_->height());
235 EXPECT_TRUE(minimize_button_->visible()); 226 EXPECT_TRUE(minimize_button_->visible());
236 EXPECT_FALSE(hidden_button->visible()); 227 EXPECT_FALSE(hidden_button->visible());
237 } 228 }
238 229
239 void ExpectTabStripAndMinimumSize(bool caption_buttons_on_left) { 230 void ExpectTabStripAndMinimumSize(bool caption_buttons_on_left) {
240 int caption_buttons_width = kCaptionButtonsWidth; 231 int caption_buttons_width = kCaptionButtonsWidth;
241 bool show_caption_buttons = delegate_->ShouldShowCaptionButtons(); 232 bool show_caption_buttons = delegate_->ShouldShowCaptionButtons();
242 bool maximized = delegate_->IsMaximized() || !show_caption_buttons; 233 bool maximized = delegate_->IsMaximized() || !show_caption_buttons;
243 if (delegate_->ShouldShowAvatar()) { 234 if (avatar_button_) {
244 caption_buttons_width += new_avatar_button_->GetPreferredSize().width() + 235 caption_buttons_width +=
236 avatar_button_->GetPreferredSize().width() +
245 (maximized ? OBFVL::kCaptionSpacing 237 (maximized ? OBFVL::kCaptionSpacing
246 : -GetLayoutSize(NEW_TAB_BUTTON).width()); 238 : -GetLayoutSize(NEW_TAB_BUTTON).width());
247 } 239 }
248 int tabstrip_x = GetLayoutInsets(AVATAR_ICON).right(); 240 int tabstrip_x = GetLayoutInsets(AVATAR_ICON).right();
249 if (show_caption_buttons && caption_buttons_on_left) { 241 if (show_caption_buttons && caption_buttons_on_left) {
250 int right_of_close = 242 int right_of_close =
251 maximized ? kMaximizedExtraCloseWidth : OBFVL::kFrameBorderThickness; 243 maximized ? kMaximizedExtraCloseWidth : OBFVL::kFrameBorderThickness;
252 tabstrip_x += caption_buttons_width + right_of_close; 244 tabstrip_x += caption_buttons_width + right_of_close;
253 } else if (!maximized) { 245 } else if (!maximized) {
254 tabstrip_x += kNonClientBorderThickness; 246 tabstrip_x += kNonClientBorderThickness;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 (delegate_->IsMaximized() ? 0 : OBFVL::kFrameBorderThickness) + 311 (delegate_->IsMaximized() ? 0 : OBFVL::kFrameBorderThickness) +
320 OBFVL::kIconLeftSpacing + icon_size + OBFVL::kIconTitleSpacing; 312 OBFVL::kIconLeftSpacing + icon_size + OBFVL::kIconTitleSpacing;
321 gfx::Rect title_bounds(window_title_->bounds()); 313 gfx::Rect title_bounds(window_title_->bounds());
322 EXPECT_EQ(title_x, title_bounds.x()); 314 EXPECT_EQ(title_x, title_bounds.x());
323 EXPECT_EQ(IconAndTitleY(), title_bounds.y()); 315 EXPECT_EQ(IconAndTitleY(), title_bounds.y());
324 EXPECT_EQ(CaptionLeft() - title_x, title_bounds.width()); 316 EXPECT_EQ(CaptionLeft() - title_x, title_bounds.width());
325 EXPECT_EQ(icon_size, title_bounds.height()); 317 EXPECT_EQ(icon_size, title_bounds.height());
326 } 318 }
327 319
328 void ExpectAvatar() { 320 void ExpectAvatar() {
329 int avatar_width = new_avatar_button_->GetPreferredSize().width(); 321 int avatar_width = avatar_button_->GetPreferredSize().width();
330 gfx::Rect avatar_bounds(new_avatar_button_->bounds()); 322 gfx::Rect avatar_bounds(avatar_button_->bounds());
331 EXPECT_EQ(CaptionLeft() - avatar_width, avatar_bounds.x()); 323 EXPECT_EQ(CaptionLeft() - avatar_width, avatar_bounds.x());
332 EXPECT_EQ(CaptionY(), avatar_bounds.y()); 324 EXPECT_EQ(CaptionY(), avatar_bounds.y());
333 EXPECT_EQ(avatar_width, avatar_bounds.width()); 325 EXPECT_EQ(avatar_width, avatar_bounds.width());
334 EXPECT_EQ(kCaptionButtonHeight, avatar_bounds.height()); 326 EXPECT_EQ(kCaptionButtonHeight, avatar_bounds.height());
335 } 327 }
336 328
337 views::Widget* widget_; 329 views::Widget* widget_ = nullptr;
338 views::View* root_view_; 330 views::View* root_view_ = nullptr;
339 OBFVL* layout_manager_; 331 OBFVL* layout_manager_ = nullptr;
340 std::unique_ptr<TestLayoutDelegate> delegate_; 332 std::unique_ptr<TestLayoutDelegate> delegate_;
341 333
342 // Widgets: 334 // Widgets:
343 views::ImageButton* minimize_button_; 335 views::ImageButton* minimize_button_ = nullptr;
344 views::ImageButton* maximize_button_; 336 views::ImageButton* maximize_button_ = nullptr;
345 views::ImageButton* restore_button_; 337 views::ImageButton* restore_button_ = nullptr;
346 views::ImageButton* close_button_; 338 views::ImageButton* close_button_ = nullptr;
347 339
348 TabIconView* tab_icon_view_; 340 TabIconView* tab_icon_view_ = nullptr;
349 views::Label* window_title_; 341 views::Label* window_title_ = nullptr;
350 342
351 AvatarMenuButton* menu_button_; 343 AvatarMenuButton* menu_button_ = nullptr;
352 views::MenuButton* new_avatar_button_; 344 views::MenuButton* avatar_button_ = nullptr;
353 345
354 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest); 346 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest);
355 }; 347 };
356 348
357 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) { 349 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) {
358 // Tests the layout of a default chrome window with no avatars, no window 350 // Tests the layout of a default chrome window with no avatars, no window
359 // titles, and a tabstrip. 351 // titles, and a tabstrip.
360 352
361 for (int i = 0; i < 2; ++i) { 353 for (int i = 0; i < 2; ++i) {
362 root_view_->Layout(); 354 root_view_->Layout();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 427
436 for (int i = 0; i < 2; ++i) { 428 for (int i = 0; i < 2; ++i) {
437 root_view_->Layout(); 429 root_view_->Layout();
438 SCOPED_TRACE(i == 0 ? "Window is restored" : "Window is maximized"); 430 SCOPED_TRACE(i == 0 ? "Window is restored" : "Window is maximized");
439 ExpectCaptionButtons(false, 0); 431 ExpectCaptionButtons(false, 0);
440 ExpectTabStripAndMinimumSize(false); 432 ExpectTabStripAndMinimumSize(false);
441 ExpectAvatar(); 433 ExpectAvatar();
442 delegate_->set_maximized(true); 434 delegate_->set_maximized(true);
443 } 435 }
444 } 436 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698