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

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: Include missing browsertest .js file in chrome_tests.gypi Created 6 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_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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 void AddAvatarButton() { 219 void AddAvatarButton() {
217 // Disable the New Avatar Menu. 220 // Disable the New Avatar Menu.
218 switches::DisableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); 221 switches::DisableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
219 222
220 menu_button_ = new AvatarMenuButton(NULL, false); 223 menu_button_ = new AvatarMenuButton(NULL, false);
221 menu_button_->set_id(VIEW_ID_AVATAR_BUTTON); 224 menu_button_->set_id(VIEW_ID_AVATAR_BUTTON);
222 delegate_->SetShouldShowAvatar(true); 225 delegate_->SetShouldShowAvatar(true);
223 root_view_->AddChildView(menu_button_); 226 root_view_->AddChildView(menu_button_);
224 } 227 }
225 228
226 void AddAvatarLabel() { 229 #if defined(ENABLE_MANAGED_USERS)
227 avatar_label_ = new AvatarLabel(NULL); 230 void AddSupervisedUserAvatarLabel() {
228 avatar_label_->set_id(VIEW_ID_AVATAR_LABEL); 231 supervised_user_avatar_label_ = new SupervisedUserAvatarLabel(NULL);
229 root_view_->AddChildView(avatar_label_); 232 supervised_user_avatar_label_->set_id(VIEW_ID_SUPERVISED_USER_AVATAR_LABEL);
233 root_view_->AddChildView(supervised_user_avatar_label_);
230 234
231 // The avatar label should only be used together with the avatar button. 235 // The avatar label should only be used together with the avatar button.
232 AddAvatarButton(); 236 AddAvatarButton();
233 } 237 }
238 #endif
234 239
235 void AddNewAvatarButton() { 240 void AddNewAvatarButton() {
236 // Enable the New Avatar Menu. 241 // Enable the New Avatar Menu.
237 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); 242 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
238 243
239 new_avatar_button_ = 244 new_avatar_button_ =
240 new views::MenuButton(NULL, base::string16(), NULL, false); 245 new views::MenuButton(NULL, base::string16(), NULL, false);
241 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); 246 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON);
242 root_view_->AddChildView(new_avatar_button_); 247 root_view_->AddChildView(new_avatar_button_);
243 } 248 }
(...skipping 12 matching lines...) Expand all
256 261
257 // Widgets: 262 // Widgets:
258 views::ImageButton* minimize_button_; 263 views::ImageButton* minimize_button_;
259 views::ImageButton* maximize_button_; 264 views::ImageButton* maximize_button_;
260 views::ImageButton* restore_button_; 265 views::ImageButton* restore_button_;
261 views::ImageButton* close_button_; 266 views::ImageButton* close_button_;
262 267
263 TabIconView* tab_icon_view_; 268 TabIconView* tab_icon_view_;
264 views::Label* window_title_; 269 views::Label* window_title_;
265 270
266 AvatarLabel* avatar_label_; 271 #if defined(ENABLE_MANAGED_USERS)
272 SupervisedUserAvatarLabel* supervised_user_avatar_label_;
273 #endif
267 AvatarMenuButton* menu_button_; 274 AvatarMenuButton* menu_button_;
268 views::MenuButton* new_avatar_button_; 275 views::MenuButton* new_avatar_button_;
269 276
270 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest); 277 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest);
271 }; 278 };
272 279
273 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) { 280 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) {
274 // Tests the layout of a default chrome window with no avatars, no window 281 // Tests the layout of a default chrome window with no avatars, no window
275 // titles, and a tabstrip. 282 // titles, and a tabstrip.
276 root_view_->Layout(); 283 root_view_->Layout();
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 ExpectBasicWindowBounds(); 436 ExpectBasicWindowBounds();
430 437
431 // Check the location of the avatar 438 // Check the location of the avatar
432 EXPECT_EQ("7,11 40x29", menu_button_->bounds().ToString()); 439 EXPECT_EQ("7,11 40x29", menu_button_->bounds().ToString());
433 EXPECT_EQ("45,13 352x29", 440 EXPECT_EQ("45,13 352x29",
434 layout_manager_->GetBoundsForTabStrip( 441 layout_manager_->GetBoundsForTabStrip(
435 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); 442 delegate_->GetTabstripPreferredSize(), kWidth).ToString());
436 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); 443 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString());
437 } 444 }
438 445
439 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarWithButtonsOnLeft) {
440 // Tests the layout of a chrome window with an avatar icon and caption buttons
441 // on the left. The avatar icon should therefore be on the right.
442 // AddAvatarLabel() also adds the avatar button.
443 AddAvatarLabel();
444 std::vector<views::FrameButton> leading_buttons;
445 std::vector<views::FrameButton> trailing_buttons;
446 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE);
447 leading_buttons.push_back(views::FRAME_BUTTON_MINIMIZE);
448 leading_buttons.push_back(views::FRAME_BUTTON_MAXIMIZE);
449 layout_manager_->SetButtonOrdering(leading_buttons, trailing_buttons);
450 root_view_->Layout();
451
452 EXPECT_EQ("73,1 25x18", maximize_button_->bounds().ToString());
453 EXPECT_EQ("47,1 26x18", minimize_button_->bounds().ToString());
454 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString());
455 EXPECT_EQ("4,1 43x18", close_button_->bounds().ToString());
456
457 // Check the location of the avatar
458 EXPECT_EQ("454,11 40x29", menu_button_->bounds().ToString());
459
460 // Check the tab strip bounds.
461 gfx::Rect tab_strip_bounds = layout_manager_->GetBoundsForTabStrip(
462 delegate_->GetTabstripPreferredSize(), kWidth);
463 EXPECT_GT(tab_strip_bounds.x(), maximize_button_->bounds().x());
464 EXPECT_GT(maximize_button_->bounds().right(), tab_strip_bounds.x());
465 EXPECT_EQ(13, tab_strip_bounds.y());
466 EXPECT_EQ(29, tab_strip_bounds.height());
467 EXPECT_GT(avatar_label_->bounds().x(), tab_strip_bounds.right());
468 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString());
469
470 // Check the relative location of the avatar label to the avatar. The right
471 // end of the avatar label should be slightly to the right of the right end of
472 // the avatar icon.
473 EXPECT_GT(avatar_label_->bounds().right(), menu_button_->bounds().right());
474 EXPECT_GT(menu_button_->bounds().x(), avatar_label_->bounds().x());
475 EXPECT_GT(menu_button_->bounds().bottom(),
476 avatar_label_->bounds().bottom());
477 EXPECT_GT(avatar_label_->bounds().y(), menu_button_->bounds().y());
478
479 // This means that the menu will pop out facing the left (if it were to face
480 // the right, it would go outside the window frame and be clipped).
481 EXPECT_TRUE(menu_button_->button_on_right());
482
483 // If the buttons are on the left, there should be no hidden icon for the user
484 // to double click.
485 EXPECT_EQ("0,0 0x0", layout_manager_->IconBounds().ToString());
486 }
487
488 TEST_F(OpaqueBrowserFrameViewLayoutTest, 446 TEST_F(OpaqueBrowserFrameViewLayoutTest,
489 WindowWithAvatarWithoutCaptionButtonsOnLeft) { 447 WindowWithAvatarWithoutCaptionButtonsOnLeft) {
490 // Tests the layout of a chrome window with an avatar icon and no caption 448 // Tests the layout of a chrome window with an avatar icon and no caption
491 // buttons. However, the caption buttons *would* be on the left if they 449 // buttons. However, the caption buttons *would* be on the left if they
492 // weren't hidden, and therefore, the avatar icon should be on the right. 450 // weren't hidden, and therefore, the avatar icon should be on the right.
493 // The lack of caption buttons should force the tab strip to be condensed. 451 // The lack of caption buttons should force the tab strip to be condensed.
494 AddAvatarButton(); 452 AddAvatarButton();
495 std::vector<views::FrameButton> leading_buttons; 453 std::vector<views::FrameButton> leading_buttons;
496 std::vector<views::FrameButton> trailing_buttons; 454 std::vector<views::FrameButton> trailing_buttons;
497 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE); 455 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 // Check the location of the avatar button. 487 // Check the location of the avatar button.
530 EXPECT_EQ("385,1 12x18", new_avatar_button_->bounds().ToString()); 488 EXPECT_EQ("385,1 12x18", new_avatar_button_->bounds().ToString());
531 // The new tab button is 39px wide and slides completely under the new 489 // The new tab button is 39px wide and slides completely under the new
532 // avatar button, thus increasing the tabstrip by that amount. 490 // avatar button, thus increasing the tabstrip by that amount.
533 EXPECT_EQ("-1,13 420x29", 491 EXPECT_EQ("-1,13 420x29",
534 layout_manager_->GetBoundsForTabStrip( 492 layout_manager_->GetBoundsForTabStrip(
535 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); 493 delegate_->GetTabstripPreferredSize(), kWidth).ToString());
536 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); 494 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString());
537 } 495 }
538 496
497 #if defined(ENABLE_MANAGED_USERS)
498 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarWithButtonsOnLeft) {
499 // Tests the layout of a chrome window with an avatar icon and caption buttons
500 // on the left. The avatar icon should therefore be on the right.
501 // AddAvatarLabel() also adds the avatar button.
502 AddSupervisedUserAvatarLabel();
503 std::vector<views::FrameButton> leading_buttons;
504 std::vector<views::FrameButton> trailing_buttons;
505 leading_buttons.push_back(views::FRAME_BUTTON_CLOSE);
506 leading_buttons.push_back(views::FRAME_BUTTON_MINIMIZE);
507 leading_buttons.push_back(views::FRAME_BUTTON_MAXIMIZE);
508 layout_manager_->SetButtonOrdering(leading_buttons, trailing_buttons);
509 root_view_->Layout();
510
511 EXPECT_EQ("73,1 25x18", maximize_button_->bounds().ToString());
512 EXPECT_EQ("47,1 26x18", minimize_button_->bounds().ToString());
513 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString());
514 EXPECT_EQ("4,1 43x18", close_button_->bounds().ToString());
515
516 // Check the location of the avatar
517 EXPECT_EQ("454,11 40x29", menu_button_->bounds().ToString());
518
519 // Check the tab strip bounds.
520 gfx::Rect tab_strip_bounds = layout_manager_->GetBoundsForTabStrip(
521 delegate_->GetTabstripPreferredSize(), kWidth);
522 EXPECT_GT(tab_strip_bounds.x(), maximize_button_->bounds().x());
523 EXPECT_GT(maximize_button_->bounds().right(), tab_strip_bounds.x());
524 EXPECT_EQ(13, tab_strip_bounds.y());
525 EXPECT_EQ(29, tab_strip_bounds.height());
526 EXPECT_GT(supervised_user_avatar_label_->bounds().x(),
527 tab_strip_bounds.right());
528 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString());
529
530 // Check the relative location of the avatar label to the avatar. The right
531 // end of the avatar label should be slightly to the right of the right end of
532 // the avatar icon.
533 EXPECT_GT(supervised_user_avatar_label_->bounds().right(),
534 menu_button_->bounds().right());
535 EXPECT_GT(menu_button_->bounds().x(),
536 supervised_user_avatar_label_->bounds().x());
537 EXPECT_GT(menu_button_->bounds().bottom(),
538 supervised_user_avatar_label_->bounds().bottom());
539 EXPECT_GT(supervised_user_avatar_label_->bounds().y(),
540 menu_button_->bounds().y());
541
542 // This means that the menu will pop out facing the left (if it were to face
543 // the right, it would go outside the window frame and be clipped).
544 EXPECT_TRUE(menu_button_->button_on_right());
545
546 // If the buttons are on the left, there should be no hidden icon for the user
547 // to double click.
548 EXPECT_EQ("0,0 0x0", layout_manager_->IconBounds().ToString());
549 }
550
539 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarLabelAndButtonOnLeft) { 551 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarLabelAndButtonOnLeft) {
540 AddAvatarLabel(); 552 AddSupervisedUserAvatarLabel();
541 root_view_->Layout(); 553 root_view_->Layout();
542 554
543 ExpectBasicWindowBounds(); 555 ExpectBasicWindowBounds();
544 556
545 // Check the location of the avatar label relative to the avatar button if 557 // Check the location of the avatar label relative to the avatar button if
546 // both are displayed on the left side. 558 // both are displayed on the left side.
547 // The label height and width depends on the font size and the text displayed. 559 // The label height and width depends on the font size and the text displayed.
548 // This may possibly change, so we don't test it here. 560 // This may possibly change, so we don't test it here.
549 EXPECT_EQ(menu_button_->bounds().x() - 2, avatar_label_->bounds().x()); 561 EXPECT_EQ(menu_button_->bounds().x() - 2,
550 EXPECT_EQ( 562 supervised_user_avatar_label_->bounds().x());
551 menu_button_->bounds().bottom() - 3 - avatar_label_->bounds().height(), 563 EXPECT_EQ(menu_button_->bounds().bottom() - 3 -
552 avatar_label_->bounds().y()); 564 supervised_user_avatar_label_->bounds().height(),
565 supervised_user_avatar_label_->bounds().y());
553 } 566 }
567 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.cc ('k') | chrome/browser/ui/views/profiles/avatar_label.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698