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

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

Issue 1307093004: Remove references to IsNewAvatarMenu since the flag was removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review feedback Created 5 years, 2 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_menu_button.h" 10 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 193
194 window_title_ = new views::Label(delegate_->GetWindowTitle()); 194 window_title_ = new views::Label(delegate_->GetWindowTitle());
195 window_title_->SetVisible(delegate_->ShouldShowWindowTitle()); 195 window_title_->SetVisible(delegate_->ShouldShowWindowTitle());
196 window_title_->SetEnabledColor(SK_ColorWHITE); 196 window_title_->SetEnabledColor(SK_ColorWHITE);
197 window_title_->SetSubpixelRenderingEnabled(false); 197 window_title_->SetSubpixelRenderingEnabled(false);
198 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 198 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
199 window_title_->set_id(VIEW_ID_WINDOW_TITLE); 199 window_title_->set_id(VIEW_ID_WINDOW_TITLE);
200 root_view_->AddChildView(window_title_); 200 root_view_->AddChildView(window_title_);
201 } 201 }
202 202
203 void AddAvatarButton() {
204 // Disable the New Avatar Menu.
205 switches::DisableNewAvatarMenuForTesting(
206 base::CommandLine::ForCurrentProcess());
207
208 menu_button_ = new AvatarMenuButton(nullptr, false);
209 menu_button_->set_id(VIEW_ID_AVATAR_BUTTON);
210 delegate_->SetShouldShowAvatar(true);
211 root_view_->AddChildView(menu_button_);
212 }
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() { 203 void AddNewAvatarButton() {
226 // Enable the New Avatar Menu.
227 switches::EnableNewAvatarMenuForTesting(
228 base::CommandLine::ForCurrentProcess());
229
230 new_avatar_button_ = 204 new_avatar_button_ =
231 new views::MenuButton(nullptr, base::string16(), nullptr, false); 205 new views::MenuButton(nullptr, base::string16(), nullptr, false);
232 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); 206 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON);
233 root_view_->AddChildView(new_avatar_button_); 207 root_view_->AddChildView(new_avatar_button_);
234 } 208 }
235 209
236 void ExpectBasicWindowBounds() { 210 void ExpectBasicWindowBounds() {
237 EXPECT_EQ("428,1 25x18", maximize_button_->bounds().ToString()); 211 EXPECT_EQ("428,1 25x18", maximize_button_->bounds().ToString());
238 EXPECT_EQ("402,1 26x18", minimize_button_->bounds().ToString()); 212 EXPECT_EQ("402,1 26x18", minimize_button_->bounds().ToString());
239 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); 213 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString());
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 root_view_->Layout(); 381 root_view_->Layout();
408 382
409 // We should have the right hand side should match the BasicWindow case. 383 // We should have the right hand side should match the BasicWindow case.
410 ExpectBasicWindowBounds(); 384 ExpectBasicWindowBounds();
411 385
412 // Check the location of the tab icon and window title. 386 // Check the location of the tab icon and window title.
413 EXPECT_EQ("6,3 17x17", tab_icon_view_->bounds().ToString()); 387 EXPECT_EQ("6,3 17x17", tab_icon_view_->bounds().ToString());
414 EXPECT_EQ("27,3 370x17", window_title_->bounds().ToString()); 388 EXPECT_EQ("27,3 370x17", window_title_->bounds().ToString());
415 } 389 }
416 390
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) { 391 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithNewAvatar) {
467 // Tests a normal tabstrip window with the new style avatar icon. 392 // Tests a normal tabstrip window with the new style avatar icon.
468 AddNewAvatarButton(); 393 AddNewAvatarButton();
469 root_view_->Layout(); 394 root_view_->Layout();
470 395
471 ExpectBasicWindowBounds(); 396 ExpectBasicWindowBounds();
472 397
473 // Check the location of the avatar button. 398 // Check the location of the avatar button.
474 EXPECT_EQ("385,1 12x18", new_avatar_button_->bounds().ToString()); 399 EXPECT_EQ("385,1 12x18", new_avatar_button_->bounds().ToString());
475 // The new tab button is 39px wide and slides completely under the new 400 // The new tab button is 39px wide and slides completely under the new
476 // avatar button, thus increasing the tabstrip by that amount. 401 // avatar button, thus increasing the tabstrip by that amount.
477 EXPECT_EQ("-1,13 420x29", 402 EXPECT_EQ("-1,13 420x29",
478 layout_manager_->GetBoundsForTabStrip( 403 layout_manager_->GetBoundsForTabStrip(
479 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); 404 delegate_->GetTabstripPreferredSize(), kWidth).ToString());
480 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); 405 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString());
481 } 406 }
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698