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

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

Issue 355233002: Fix build when ENABLE_MANAGED_USERS is not defined (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits, minor refactoring Created 6 years, 5 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/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/views/profiles/avatar_label.h"
11 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" 10 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
12 #include "chrome/browser/ui/views/tab_icon_view.h" 11 #include "chrome/browser/ui/views/tab_icon_view.h"
13 #include "chrome/browser/ui/views/tabs/tab.h" 12 #include "chrome/browser/ui/views/tabs/tab.h"
14 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
15 #include "components/signin/core/common/profile_management_switches.h" 14 #include "components/signin/core/common/profile_management_switches.h"
16 #include "ui/gfx/image/image_skia.h" 15 #include "ui/gfx/image/image_skia.h"
17 #include "ui/gfx/image/image_skia_rep.h" 16 #include "ui/gfx/image/image_skia_rep.h"
18 #include "ui/gfx/text_constants.h" 17 #include "ui/gfx/text_constants.h"
19 #include "ui/views/controls/button/image_button.h" 18 #include "ui/views/controls/button/image_button.h"
20 #include "ui/views/controls/button/menu_button.h" 19 #include "ui/views/controls/button/menu_button.h"
21 #include "ui/views/controls/label.h" 20 #include "ui/views/controls/label.h"
22 #include "ui/views/test/views_test_base.h" 21 #include "ui/views/test/views_test_base.h"
23 22
23 #if defined(ENABLE_MANAGED_USERS)
24 #include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h"
25 #endif
26
24 using views::Widget; 27 using views::Widget;
25 28
26 namespace { 29 namespace {
27 30
28 const int kWidth = 500; 31 const int kWidth = 500;
29 32
30 class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate { 33 class TestLayoutDelegate : public OpaqueBrowserFrameViewLayoutDelegate {
31 public: 34 public:
32 enum WindowState { 35 enum WindowState {
33 STATE_NORMAL, 36 STATE_NORMAL,
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 root_view_->AddChildView(window_title_); 216 root_view_->AddChildView(window_title_);
214 } 217 }
215 218
216 void AddAvatarButton() { 219 void AddAvatarButton() {
217 menu_button_ = new AvatarMenuButton(NULL, false); 220 menu_button_ = new AvatarMenuButton(NULL, false);
218 menu_button_->set_id(VIEW_ID_AVATAR_BUTTON); 221 menu_button_->set_id(VIEW_ID_AVATAR_BUTTON);
219 delegate_->SetShouldShowAvatar(true); 222 delegate_->SetShouldShowAvatar(true);
220 root_view_->AddChildView(menu_button_); 223 root_view_->AddChildView(menu_button_);
221 } 224 }
222 225
223 void AddAvatarLabel() { 226 #if defined(ENABLE_MANAGED_USERS)
224 avatar_label_ = new AvatarLabel(NULL); 227 void AddSupervisedUserAvatarLabel() {
225 avatar_label_->set_id(VIEW_ID_AVATAR_LABEL); 228 supervised_user_avatar_label_ = new SupervisedUserAvatarLabel(NULL);
226 root_view_->AddChildView(avatar_label_); 229 supervised_user_avatar_label_->set_id(VIEW_ID_SUPERVISED_USER_AVATAR_LABEL);
230 root_view_->AddChildView(supervised_user_avatar_label_);
227 231
228 // The avatar label should only be used together with the avatar button. 232 // The avatar label should only be used together with the avatar button.
229 AddAvatarButton(); 233 AddAvatarButton();
230 } 234 }
235 #endif
231 236
232 void AddNewAvatarButton() { 237 void AddNewAvatarButton() {
233 new_avatar_button_ = 238 new_avatar_button_ =
234 new views::MenuButton(NULL, base::string16(), NULL, false); 239 new views::MenuButton(NULL, base::string16(), NULL, false);
235 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); 240 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON);
236 root_view_->AddChildView(new_avatar_button_); 241 root_view_->AddChildView(new_avatar_button_);
237 } 242 }
238 243
239 void ExpectBasicWindowBounds() { 244 void ExpectBasicWindowBounds() {
240 EXPECT_EQ("428,1 25x18", maximize_button_->bounds().ToString()); 245 EXPECT_EQ("428,1 25x18", maximize_button_->bounds().ToString());
241 EXPECT_EQ("402,1 26x18", minimize_button_->bounds().ToString()); 246 EXPECT_EQ("402,1 26x18", minimize_button_->bounds().ToString());
242 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); 247 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString());
243 EXPECT_EQ("453,1 43x18", close_button_->bounds().ToString()); 248 EXPECT_EQ("453,1 43x18", close_button_->bounds().ToString());
244 } 249 }
245 250
246 Widget* widget_; 251 Widget* widget_;
247 views::View* root_view_; 252 views::View* root_view_;
248 OpaqueBrowserFrameViewLayout* layout_manager_; 253 OpaqueBrowserFrameViewLayout* layout_manager_;
249 scoped_ptr<TestLayoutDelegate> delegate_; 254 scoped_ptr<TestLayoutDelegate> delegate_;
250 255
251 // Widgets: 256 // Widgets:
252 views::ImageButton* minimize_button_; 257 views::ImageButton* minimize_button_;
253 views::ImageButton* maximize_button_; 258 views::ImageButton* maximize_button_;
254 views::ImageButton* restore_button_; 259 views::ImageButton* restore_button_;
255 views::ImageButton* close_button_; 260 views::ImageButton* close_button_;
256 261
257 TabIconView* tab_icon_view_; 262 TabIconView* tab_icon_view_;
258 views::Label* window_title_; 263 views::Label* window_title_;
259 264
260 AvatarLabel* avatar_label_; 265 #if defined(ENABLE_MANAGED_USERS)
266 SupervisedUserAvatarLabel* supervised_user_avatar_label_;
267 #endif
261 AvatarMenuButton* menu_button_; 268 AvatarMenuButton* menu_button_;
262 views::MenuButton* new_avatar_button_; 269 views::MenuButton* new_avatar_button_;
263 270
264 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest); 271 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest);
265 }; 272 };
266 273
267 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) { 274 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) {
268 // Tests the layout of a default chrome window with no avatars, no window 275 // Tests the layout of a default chrome window with no avatars, no window
269 // titles, and a tabstrip. 276 // titles, and a tabstrip.
270 root_view_->Layout(); 277 root_view_->Layout();
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 ExpectBasicWindowBounds(); 430 ExpectBasicWindowBounds();
424 431
425 // Check the location of the avatar 432 // Check the location of the avatar
426 EXPECT_EQ("7,11 40x29", menu_button_->bounds().ToString()); 433 EXPECT_EQ("7,11 40x29", menu_button_->bounds().ToString());
427 EXPECT_EQ("45,13 352x29", 434 EXPECT_EQ("45,13 352x29",
428 layout_manager_->GetBoundsForTabStrip( 435 layout_manager_->GetBoundsForTabStrip(
429 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); 436 delegate_->GetTabstripPreferredSize(), kWidth).ToString());
430 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); 437 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString());
431 } 438 }
432 439
433 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarWithButtonsOnLeft) {
434 // Tests the layout of a chrome window with an avatar icon and caption buttons
435 // on the left. The avatar icon should therefore be on the right.
436 // AddAvatarLabel() also adds the avatar button.
437 AddAvatarLabel();
438 std::vector<views::FrameButton> leading_buttons;
439 std::vector<views::FrameButton> trailing_buttons;
440 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE);
441 leading_buttons.push_back(views::FRAME_BUTTON_MINIMIZE);
442 leading_buttons.push_back(views::FRAME_BUTTON_MAXIMIZE);
443 layout_manager_->SetButtonOrdering(leading_buttons, trailing_buttons);
444 root_view_->Layout();
445
446 EXPECT_EQ("73,1 25x18", maximize_button_->bounds().ToString());
447 EXPECT_EQ("47,1 26x18", minimize_button_->bounds().ToString());
448 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString());
449 EXPECT_EQ("4,1 43x18", close_button_->bounds().ToString());
450
451 // Check the location of the avatar
452 EXPECT_EQ("454,11 40x29", menu_button_->bounds().ToString());
453
454 // Check the tab strip bounds.
455 gfx::Rect tab_strip_bounds = layout_manager_->GetBoundsForTabStrip(
456 delegate_->GetTabstripPreferredSize(), kWidth);
457 EXPECT_GT(tab_strip_bounds.x(), maximize_button_->bounds().x());
458 EXPECT_GT(maximize_button_->bounds().right(), tab_strip_bounds.x());
459 EXPECT_EQ(13, tab_strip_bounds.y());
460 EXPECT_EQ(29, tab_strip_bounds.height());
461 EXPECT_GT(avatar_label_->bounds().x(), tab_strip_bounds.right());
462 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString());
463
464 // Check the relative location of the avatar label to the avatar. The right
465 // end of the avatar label should be slightly to the right of the right end of
466 // the avatar icon.
467 EXPECT_GT(avatar_label_->bounds().right(), menu_button_->bounds().right());
468 EXPECT_GT(menu_button_->bounds().x(), avatar_label_->bounds().x());
469 EXPECT_GT(menu_button_->bounds().bottom(),
470 avatar_label_->bounds().bottom());
471 EXPECT_GT(avatar_label_->bounds().y(), menu_button_->bounds().y());
472
473 // This means that the menu will pop out facing the left (if it were to face
474 // the right, it would go outside the window frame and be clipped).
475 EXPECT_TRUE(menu_button_->button_on_right());
476
477 // If the buttons are on the left, there should be no hidden icon for the user
478 // to double click.
479 EXPECT_EQ("0,0 0x0", layout_manager_->IconBounds().ToString());
480 }
481
482 TEST_F(OpaqueBrowserFrameViewLayoutTest, 440 TEST_F(OpaqueBrowserFrameViewLayoutTest,
483 WindowWithAvatarWithoutCaptionButtonsOnLeft) { 441 WindowWithAvatarWithoutCaptionButtonsOnLeft) {
484 // Tests the layout of a chrome window with an avatar icon and no caption 442 // Tests the layout of a chrome window with an avatar icon and no caption
485 // buttons. However, the caption buttons *would* be on the left if they 443 // buttons. However, the caption buttons *would* be on the left if they
486 // weren't hidden, and therefore, the avatar icon should be on the right. 444 // weren't hidden, and therefore, the avatar icon should be on the right.
487 // The lack of caption buttons should force the tab strip to be condensed. 445 // The lack of caption buttons should force the tab strip to be condensed.
488 AddAvatarButton(); 446 AddAvatarButton();
489 std::vector<views::FrameButton> leading_buttons; 447 std::vector<views::FrameButton> leading_buttons;
490 std::vector<views::FrameButton> trailing_buttons; 448 std::vector<views::FrameButton> trailing_buttons;
491 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE); 449 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 EXPECT_EQ("385,1 12x20", new_avatar_button_->bounds().ToString()); 485 EXPECT_EQ("385,1 12x20", new_avatar_button_->bounds().ToString());
528 // The basic window bounds are (-1, 13 398x29). There should not be an icon 486 // The basic window bounds are (-1, 13 398x29). There should not be an icon
529 // avatar in the left, and the new avatar button has an offset of 5 to its 487 // avatar in the left, and the new avatar button has an offset of 5 to its
530 // next control. 488 // next control.
531 EXPECT_EQ("-1,13 381x29", 489 EXPECT_EQ("-1,13 381x29",
532 layout_manager_->GetBoundsForTabStrip( 490 layout_manager_->GetBoundsForTabStrip(
533 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); 491 delegate_->GetTabstripPreferredSize(), kWidth).ToString());
534 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); 492 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString());
535 } 493 }
536 494
495 #if defined(ENABLE_MANAGED_USERS)
496 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarWithButtonsOnLeft) {
497 // Tests the layout of a chrome window with an avatar icon and caption buttons
498 // on the left. The avatar icon should therefore be on the right.
499 // AddAvatarLabel() also adds the avatar button.
500 AddSupervisedUserAvatarLabel();
501 std::vector<views::FrameButton> leading_buttons;
502 std::vector<views::FrameButton> trailing_buttons;
503 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE);
504 leading_buttons.push_back(views::FRAME_BUTTON_MINIMIZE);
505 leading_buttons.push_back(views::FRAME_BUTTON_MAXIMIZE);
506 layout_manager_->SetButtonOrdering(leading_buttons, trailing_buttons);
507 root_view_->Layout();
508
509 EXPECT_EQ("73,1 25x18", maximize_button_->bounds().ToString());
510 EXPECT_EQ("47,1 26x18", minimize_button_->bounds().ToString());
511 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString());
512 EXPECT_EQ("4,1 43x18", close_button_->bounds().ToString());
513
514 // Check the location of the avatar
515 EXPECT_EQ("454,11 40x29", menu_button_->bounds().ToString());
516
517 // Check the tab strip bounds.
518 gfx::Rect tab_strip_bounds = layout_manager_->GetBoundsForTabStrip(
519 delegate_->GetTabstripPreferredSize(), kWidth);
520 EXPECT_GT(tab_strip_bounds.x(), maximize_button_->bounds().x());
521 EXPECT_GT(maximize_button_->bounds().right(), tab_strip_bounds.x());
522 EXPECT_EQ(13, tab_strip_bounds.y());
523 EXPECT_EQ(29, tab_strip_bounds.height());
524 EXPECT_GT(supervised_user_avatar_label_->bounds().x(),
525 tab_strip_bounds.right());
526 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString());
527
528 // Check the relative location of the avatar label to the avatar. The right
529 // end of the avatar label should be slightly to the right of the right end of
530 // the avatar icon.
531 EXPECT_GT(supervised_user_avatar_label_->bounds().right(),
532 menu_button_->bounds().right());
533 EXPECT_GT(menu_button_->bounds().x(),
534 supervised_user_avatar_label_->bounds().x());
535 EXPECT_GT(menu_button_->bounds().bottom(),
536 supervised_user_avatar_label_->bounds().bottom());
537 EXPECT_GT(supervised_user_avatar_label_->bounds().y(),
538 menu_button_->bounds().y());
539
540 // This means that the menu will pop out facing the left (if it were to face
541 // the right, it would go outside the window frame and be clipped).
542 EXPECT_TRUE(menu_button_->button_on_right());
543
544 // If the buttons are on the left, there should be no hidden icon for the user
545 // to double click.
546 EXPECT_EQ("0,0 0x0", layout_manager_->IconBounds().ToString());
547 }
548
537 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarLabelAndButtonOnLeft) { 549 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarLabelAndButtonOnLeft) {
538 AddAvatarLabel(); 550 AddSupervisedUserAvatarLabel();
539 root_view_->Layout(); 551 root_view_->Layout();
540 552
541 ExpectBasicWindowBounds(); 553 ExpectBasicWindowBounds();
542 554
543 // Check the location of the avatar label relative to the avatar button if 555 // Check the location of the avatar label relative to the avatar button if
544 // both are displayed on the left side. 556 // both are displayed on the left side.
545 // The label height and width depends on the font size and the text displayed. 557 // The label height and width depends on the font size and the text displayed.
546 // This may possibly change, so we don't test it here. 558 // This may possibly change, so we don't test it here.
547 EXPECT_EQ(menu_button_->bounds().x() - 2, avatar_label_->bounds().x()); 559 EXPECT_EQ(menu_button_->bounds().x() - 2,
548 EXPECT_EQ( 560 supervised_user_avatar_label_->bounds().x());
549 menu_button_->bounds().bottom() - 3 - avatar_label_->bounds().height(), 561 EXPECT_EQ(menu_button_->bounds().bottom() - 3 -
550 avatar_label_->bounds().y()); 562 supervised_user_avatar_label_->bounds().height(),
563 supervised_user_avatar_label_->bounds().y());
551 } 564 }
565 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698