| 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/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_menu_button.h" | 10 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 // Disable the New Avatar Menu. | 204 // Disable the New Avatar Menu. |
| 205 switches::DisableNewAvatarMenuForTesting( | 205 switches::DisableNewAvatarMenuForTesting( |
| 206 base::CommandLine::ForCurrentProcess()); | 206 base::CommandLine::ForCurrentProcess()); |
| 207 | 207 |
| 208 menu_button_ = new AvatarMenuButton(nullptr, false); | 208 menu_button_ = new AvatarMenuButton(nullptr, false); |
| 209 menu_button_->set_id(VIEW_ID_AVATAR_BUTTON); | 209 menu_button_->set_id(VIEW_ID_AVATAR_BUTTON); |
| 210 delegate_->SetShouldShowAvatar(true); | 210 delegate_->SetShouldShowAvatar(true); |
| 211 root_view_->AddChildView(menu_button_); | 211 root_view_->AddChildView(menu_button_); |
| 212 } | 212 } |
| 213 | 213 |
| 214 #if defined(ENABLE_SUPERVISED_USERS) | |
| 215 void AddSupervisedUserAvatarLabel() { | |
| 216 supervised_user_avatar_label_ = new SupervisedUserAvatarLabel(nullptr); | |
| 217 supervised_user_avatar_label_->set_id(VIEW_ID_SUPERVISED_USER_AVATAR_LABEL); | |
| 218 root_view_->AddChildView(supervised_user_avatar_label_); | |
| 219 | |
| 220 // The avatar label should only be used together with the avatar button. | |
| 221 AddAvatarButton(); | |
| 222 } | |
| 223 #endif | |
| 224 | |
| 225 void AddNewAvatarButton() { | 214 void AddNewAvatarButton() { |
| 226 // Enable the New Avatar Menu. | 215 // Enable the New Avatar Menu. |
| 227 switches::EnableNewAvatarMenuForTesting( | 216 switches::EnableNewAvatarMenuForTesting( |
| 228 base::CommandLine::ForCurrentProcess()); | 217 base::CommandLine::ForCurrentProcess()); |
| 229 | 218 |
| 230 new_avatar_button_ = | 219 new_avatar_button_ = |
| 231 new views::MenuButton(nullptr, base::string16(), nullptr, false); | 220 new views::MenuButton(nullptr, base::string16(), nullptr, false); |
| 232 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); | 221 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); |
| 233 root_view_->AddChildView(new_avatar_button_); | 222 root_view_->AddChildView(new_avatar_button_); |
| 234 } | 223 } |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 root_view_->Layout(); | 396 root_view_->Layout(); |
| 408 | 397 |
| 409 // We should have the right hand side should match the BasicWindow case. | 398 // We should have the right hand side should match the BasicWindow case. |
| 410 ExpectBasicWindowBounds(); | 399 ExpectBasicWindowBounds(); |
| 411 | 400 |
| 412 // Check the location of the tab icon and window title. | 401 // Check the location of the tab icon and window title. |
| 413 EXPECT_EQ("6,3 17x17", tab_icon_view_->bounds().ToString()); | 402 EXPECT_EQ("6,3 17x17", tab_icon_view_->bounds().ToString()); |
| 414 EXPECT_EQ("27,3 370x17", window_title_->bounds().ToString()); | 403 EXPECT_EQ("27,3 370x17", window_title_->bounds().ToString()); |
| 415 } | 404 } |
| 416 | 405 |
| 417 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatar) { | |
| 418 // Tests a normal tabstrip window with an avatar icon. | |
| 419 AddAvatarButton(); | |
| 420 root_view_->Layout(); | |
| 421 | |
| 422 ExpectBasicWindowBounds(); | |
| 423 | |
| 424 // Check the location of the avatar | |
| 425 EXPECT_EQ("7,11 40x29", menu_button_->bounds().ToString()); | |
| 426 EXPECT_EQ("45,13 352x29", | |
| 427 layout_manager_->GetBoundsForTabStrip( | |
| 428 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | |
| 429 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | |
| 430 } | |
| 431 | |
| 432 TEST_F(OpaqueBrowserFrameViewLayoutTest, | |
| 433 WindowWithAvatarWithoutCaptionButtonsOnLeft) { | |
| 434 // Tests the layout of a chrome window with an avatar icon and no caption | |
| 435 // buttons. However, the caption buttons *would* be on the left if they | |
| 436 // weren't hidden, and therefore, the avatar icon should be on the right. | |
| 437 // The lack of caption buttons should force the tab strip to be condensed. | |
| 438 AddAvatarButton(); | |
| 439 std::vector<views::FrameButton> leading_buttons; | |
| 440 std::vector<views::FrameButton> trailing_buttons; | |
| 441 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE); | |
| 442 leading_buttons.push_back(views::FRAME_BUTTON_MINIMIZE); | |
| 443 leading_buttons.push_back(views::FRAME_BUTTON_MAXIMIZE); | |
| 444 layout_manager_->SetButtonOrdering(leading_buttons, trailing_buttons); | |
| 445 delegate_->SetShouldShowCaptionButtons(false); | |
| 446 root_view_->Layout(); | |
| 447 | |
| 448 EXPECT_EQ("0,0 0x0", maximize_button_->bounds().ToString()); | |
| 449 EXPECT_EQ("0,0 0x0", minimize_button_->bounds().ToString()); | |
| 450 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); | |
| 451 EXPECT_EQ("0,0 0x0", close_button_->bounds().ToString()); | |
| 452 | |
| 453 // Check the location of the avatar | |
| 454 EXPECT_EQ("458,0 40x24", menu_button_->bounds().ToString()); | |
| 455 EXPECT_EQ("-5,-3 458x29", | |
| 456 layout_manager_->GetBoundsForTabStrip( | |
| 457 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | |
| 458 EXPECT_EQ("251x61", layout_manager_->GetMinimumSize(kWidth).ToString()); | |
| 459 | |
| 460 // A normal window with no window icon still produces icon bounds for | |
| 461 // Windows, which has a hidden icon that a user can double click on to close | |
| 462 // the window. | |
| 463 EXPECT_EQ("2,0 17x17", layout_manager_->IconBounds().ToString()); | |
| 464 } | |
| 465 | |
| 466 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithNewAvatar) { | 406 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithNewAvatar) { |
| 467 // Tests a normal tabstrip window with the new style avatar icon. | 407 // Tests a normal tabstrip window with the new style avatar icon. |
| 468 AddNewAvatarButton(); | 408 AddNewAvatarButton(); |
| 469 root_view_->Layout(); | 409 root_view_->Layout(); |
| 470 | 410 |
| 471 ExpectBasicWindowBounds(); | 411 ExpectBasicWindowBounds(); |
| 472 | 412 |
| 473 // Check the location of the avatar button. | 413 // Check the location of the avatar button. |
| 474 EXPECT_EQ("385,1 12x18", new_avatar_button_->bounds().ToString()); | 414 EXPECT_EQ("385,1 12x18", new_avatar_button_->bounds().ToString()); |
| 475 // The new tab button is 39px wide and slides completely under the new | 415 // The new tab button is 39px wide and slides completely under the new |
| 476 // avatar button, thus increasing the tabstrip by that amount. | 416 // avatar button, thus increasing the tabstrip by that amount. |
| 477 EXPECT_EQ("-1,13 420x29", | 417 EXPECT_EQ("-1,13 420x29", |
| 478 layout_manager_->GetBoundsForTabStrip( | 418 layout_manager_->GetBoundsForTabStrip( |
| 479 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 419 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); |
| 480 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | 420 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); |
| 481 } | 421 } |
| 482 | |
| 483 #if defined(ENABLE_SUPERVISED_USERS) | |
| 484 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarWithButtonsOnLeft) { | |
| 485 // Tests the layout of a chrome window with an avatar icon and caption buttons | |
| 486 // on the left. The avatar icon should therefore be on the right. | |
| 487 // AddAvatarLabel() also adds the avatar button. | |
| 488 AddSupervisedUserAvatarLabel(); | |
| 489 std::vector<views::FrameButton> leading_buttons; | |
| 490 std::vector<views::FrameButton> trailing_buttons; | |
| 491 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE); | |
| 492 leading_buttons.push_back(views::FRAME_BUTTON_MINIMIZE); | |
| 493 leading_buttons.push_back(views::FRAME_BUTTON_MAXIMIZE); | |
| 494 layout_manager_->SetButtonOrdering(leading_buttons, trailing_buttons); | |
| 495 root_view_->Layout(); | |
| 496 | |
| 497 EXPECT_EQ("73,1 25x18", maximize_button_->bounds().ToString()); | |
| 498 EXPECT_EQ("47,1 26x18", minimize_button_->bounds().ToString()); | |
| 499 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); | |
| 500 EXPECT_EQ("4,1 43x18", close_button_->bounds().ToString()); | |
| 501 | |
| 502 // Check the location of the avatar | |
| 503 EXPECT_EQ("454,11 40x29", menu_button_->bounds().ToString()); | |
| 504 | |
| 505 // Check the tab strip bounds. | |
| 506 gfx::Rect tab_strip_bounds = layout_manager_->GetBoundsForTabStrip( | |
| 507 delegate_->GetTabstripPreferredSize(), kWidth); | |
| 508 EXPECT_GT(tab_strip_bounds.x(), maximize_button_->bounds().x()); | |
| 509 EXPECT_GT(maximize_button_->bounds().right(), tab_strip_bounds.x()); | |
| 510 EXPECT_EQ(13, tab_strip_bounds.y()); | |
| 511 EXPECT_EQ(29, tab_strip_bounds.height()); | |
| 512 EXPECT_GT(supervised_user_avatar_label_->bounds().x(), | |
| 513 tab_strip_bounds.right()); | |
| 514 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | |
| 515 | |
| 516 // Check the relative location of the avatar label to the avatar. The right | |
| 517 // end of the avatar label should be slightly to the right of the right end of | |
| 518 // the avatar icon. | |
| 519 EXPECT_GT(supervised_user_avatar_label_->bounds().right(), | |
| 520 menu_button_->bounds().right()); | |
| 521 EXPECT_GT(menu_button_->bounds().x(), | |
| 522 supervised_user_avatar_label_->bounds().x()); | |
| 523 EXPECT_GT(menu_button_->bounds().bottom(), | |
| 524 supervised_user_avatar_label_->bounds().bottom()); | |
| 525 EXPECT_GT(supervised_user_avatar_label_->bounds().y(), | |
| 526 menu_button_->bounds().y()); | |
| 527 | |
| 528 // This means that the menu will pop out facing the left (if it were to face | |
| 529 // the right, it would go outside the window frame and be clipped). | |
| 530 EXPECT_TRUE(menu_button_->button_on_right()); | |
| 531 | |
| 532 // If the buttons are on the left, there should be no hidden icon for the user | |
| 533 // to double click. | |
| 534 EXPECT_EQ("0,0 0x0", layout_manager_->IconBounds().ToString()); | |
| 535 } | |
| 536 | |
| 537 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarLabelAndButtonOnLeft) { | |
| 538 AddSupervisedUserAvatarLabel(); | |
| 539 root_view_->Layout(); | |
| 540 | |
| 541 ExpectBasicWindowBounds(); | |
| 542 | |
| 543 // Check the location of the avatar label relative to the avatar button if | |
| 544 // both are displayed on the left side. | |
| 545 // 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. | |
| 547 EXPECT_EQ(menu_button_->bounds().x() - 2, | |
| 548 supervised_user_avatar_label_->bounds().x()); | |
| 549 EXPECT_EQ(menu_button_->bounds().bottom() - 3 - | |
| 550 supervised_user_avatar_label_->bounds().height(), | |
| 551 supervised_user_avatar_label_->bounds().y()); | |
| 552 } | |
| 553 #endif | |
| OLD | NEW |