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

Side by Side Diff: chrome/browser/ui/views/tabs/tab_strip_unittest.cc

Issue 983853002: Hide close buttons of inactive stacked tabs by default (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new tests Created 5 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/tabs/tab_strip.h" 5 #include "chrome/browser/ui/views/tabs/tab_strip.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h" 8 #include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h"
9 #include "chrome/browser/ui/views/tabs/tab.h" 9 #include "chrome/browser/ui/views/tabs/tab.h"
10 #include "chrome/browser/ui/views/tabs/tab_strip.h" 10 #include "chrome/browser/ui/views/tabs/tab_strip.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 309
310 // Now tabs have the immersive height. 310 // Now tabs have the immersive height.
311 int immersive_height = Tab::GetImmersiveHeight(); 311 int immersive_height = Tab::GetImmersiveHeight();
312 EXPECT_EQ(immersive_height, tab_strip_->GetPreferredSize().height()); 312 EXPECT_EQ(immersive_height, tab_strip_->GetPreferredSize().height());
313 313
314 // Sanity-check immersive tabs are shorter than normal tabs. 314 // Sanity-check immersive tabs are shorter than normal tabs.
315 EXPECT_LT(immersive_height, normal_height); 315 EXPECT_LT(immersive_height, normal_height);
316 } 316 }
317 317
318 // Creates a tab strip in stacked layout mode and verifies the correctness 318 // Creates a tab strip in stacked layout mode and verifies the correctness
319 // of hit tests against the visible/occluded regions of a tab and 319 // of hit tests against the visible/occluded regions of a tab and the tab
320 // visible/occluded tab close buttons. 320 // close button of the active tab.
321 TEST_F(TabStripTest, TabHitTestMaskWhenStacked) { 321 TEST_F(TabStripTest, TabHitTestMaskWhenStacked) {
322 tab_strip_->SetBounds(0, 0, 300, 20); 322 tab_strip_->SetBounds(0, 0, 300, 20);
323 323
324 controller_->AddTab(0, false); 324 controller_->AddTab(0, false);
325 controller_->AddTab(1, true); 325 controller_->AddTab(1, true);
326 controller_->AddTab(2, false); 326 controller_->AddTab(2, false);
327 controller_->AddTab(3, false); 327 controller_->AddTab(3, false);
328 ASSERT_EQ(4, tab_strip_->tab_count()); 328 ASSERT_EQ(4, tab_strip_->tab_count());
329 329
330 Tab* left_tab = tab_strip_->tab_at(0); 330 Tab* left_tab = tab_strip_->tab_at(0);
331 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20))); 331 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20)));
332 332
333 Tab* active_tab = tab_strip_->tab_at(1); 333 Tab* active_tab = tab_strip_->tab_at(1);
334 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(150, 0), gfx::Size(200, 20))); 334 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(150, 0), gfx::Size(200, 20)));
335 ASSERT_TRUE(active_tab->IsActive()); 335 ASSERT_TRUE(active_tab->IsActive());
336 336
337 Tab* right_tab = tab_strip_->tab_at(2); 337 Tab* right_tab = tab_strip_->tab_at(2);
338 right_tab->SetBoundsRect(gfx::Rect(gfx::Point(300, 0), gfx::Size(200, 20))); 338 right_tab->SetBoundsRect(gfx::Rect(gfx::Point(300, 0), gfx::Size(200, 20)));
339 339
340 Tab* most_right_tab = tab_strip_->tab_at(3); 340 Tab* most_right_tab = tab_strip_->tab_at(3);
341 most_right_tab->SetBoundsRect(gfx::Rect(gfx::Point(450, 0), 341 most_right_tab->SetBoundsRect(gfx::Rect(gfx::Point(450, 0),
342 gfx::Size(200, 20))); 342 gfx::Size(200, 20)));
343 343
344 // Switch to stacked layout mode and force a layout to ensure tabs stack. 344 // Switch to stacked layout mode and force a layout to ensure tabs stack.
345 tab_strip_->SetStackedLayout(true); 345 tab_strip_->SetStackedLayout(true);
346 tab_strip_->DoLayout(); 346 tab_strip_->DoLayout();
347 347
348 348
349 // Tests involving |left_tab|, which has part of its bounds and its tab 349 // Tests involving |left_tab|, which has part of its bounds occluded by
350 // close button completely occluded by |active_tab|. 350 // |active_tab|.
351 351
352 // Bounds of the tab's hit test mask. 352 // Bounds of the tab's hit test mask.
353 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab); 353 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab);
354 EXPECT_EQ(gfx::Rect(6, 2, 61, 27).ToString(), tab_bounds.ToString()); 354 EXPECT_EQ(gfx::Rect(6, 2, 61, 27).ToString(), tab_bounds.ToString());
355 355
356 // Bounds of the tab close button (without padding) in the tab's
357 // coordinate space.
358 gfx::Rect contents_bounds = GetTabCloseHitTestMask(left_tab, false);
359 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved.
360 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString());
361
362 // Verify that the tab close button is completely occluded.
363 EXPECT_FALSE(tab_bounds.Contains(contents_bounds));
364
365 // Hit tests in the non-occuluded region of the tab. 356 // Hit tests in the non-occuluded region of the tab.
366 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 2, 2))); 357 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 2, 2)));
367 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 1, 1))); 358 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 1, 1)));
368 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 1, 1))); 359 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 1, 1)));
369 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 25, 35))); 360 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 25, 35)));
370 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(-10, -5, 20, 30))); 361 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(-10, -5, 20, 30)));
371 362
372 // Hit tests in the occluded region of the tab. 363 // Hit tests in the occluded region of the tab.
373 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(70, 15, 2, 2))); 364 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(70, 15, 2, 2)));
374 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(70, -15, 30, 40))); 365 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(70, -15, 30, 40)));
375 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(87, 20, 5, 3))); 366 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(87, 20, 5, 3)));
376 367
377 // Hit tests completely outside of the tab. 368 // Hit tests completely outside of the tab.
378 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(-20, -25, 1, 1))); 369 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(-20, -25, 1, 1)));
379 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(-20, -25, 3, 19))); 370 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(-20, -25, 3, 19)));
380 371
381 // All hit tests against the tab close button should fail because
382 // it is occluded by |active_tab|.
383 views::ImageButton* left_close = left_tab->close_button_;
384 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(1, 1, 1, 1)));
385 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(1, 1, 5, 10)));
386 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(10, 10, 1, 1)));
387 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(10, 10, 3, 4)));
388
389 372
390 // Tests involving |active_tab|, which is completely visible. 373 // Tests involving |active_tab|, which is completely visible.
391 374
392 tab_bounds = GetTabHitTestMask(active_tab); 375 tab_bounds = GetTabHitTestMask(active_tab);
393 EXPECT_EQ(gfx::Rect(6, 2, 108, 27).ToString(), tab_bounds.ToString()); 376 EXPECT_EQ(gfx::Rect(6, 2, 108, 27).ToString(), tab_bounds.ToString());
394 contents_bounds = GetTabCloseHitTestMask(active_tab, false); 377 gfx::Rect contents_bounds = GetTabCloseHitTestMask(active_tab, false);
395 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved. 378 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved.
396 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString()); 379 // EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString());
397 380
398 // Verify that the tab close button is not occluded. 381 // Verify that the tab close button is not occluded.
399 EXPECT_TRUE(tab_bounds.Contains(contents_bounds)); 382 EXPECT_TRUE(tab_bounds.Contains(contents_bounds));
400 383
401 // Bounds of the tab close button (without padding) in the tab's 384 // Bounds of the tab close button (without padding) in the tab's
402 // coordinate space. 385 // coordinate space.
403 gfx::Rect local_bounds = GetTabCloseHitTestMask(active_tab, true); 386 gfx::Rect local_bounds = GetTabCloseHitTestMask(active_tab, true);
404 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString()); 387 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString());
405 388
406 // Hit tests within the tab. 389 // Hit tests within the tab.
407 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 1, 1))); 390 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 1, 1)));
408 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 2, 2))); 391 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 2, 2)));
409 392
410 // Hit tests against the tab close button. Note that hit tests from either 393 // Hit tests against the tab close button. Note that hit tests from either
411 // mouse or touch should both fail if they are strictly contained within 394 // mouse or touch should both fail if they are strictly contained within
412 // the button's padding. 395 // the button's padding.
413 views::ImageButton* active_close = active_tab->close_button_; 396 views::ImageButton* active_close = active_tab->close_button_;
414 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 1, 1))); 397 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 1, 1)));
415 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 2, 2))); 398 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 2, 2)));
416 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 1, 1))); 399 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 1, 1)));
417 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 25, 35))); 400 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 25, 35)));
418 401
419 402
420 // Tests involving |most_right_tab|, which has part of its bounds occluded 403 // Tests involving |most_right_tab|, which has part of its bounds occluded
421 // by |right_tab| but has its tab close button completely visible. 404 // by |right_tab|.
422 405
423 tab_bounds = GetTabHitTestMask(most_right_tab); 406 tab_bounds = GetTabHitTestMask(most_right_tab);
424 EXPECT_EQ(gfx::Rect(84, 2, 30, 27).ToString(), tab_bounds.ToString()); 407 EXPECT_EQ(gfx::Rect(84, 2, 30, 27).ToString(), tab_bounds.ToString());
425 contents_bounds = GetTabCloseHitTestMask(active_tab, false);
426 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved.
427 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString());
428 local_bounds = GetTabCloseHitTestMask(active_tab, true);
429 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString());
430
431 // Verify that the tab close button is not occluded.
432 EXPECT_TRUE(tab_bounds.Contains(contents_bounds));
433 408
434 // Hit tests in the occluded region of the tab. 409 // Hit tests in the occluded region of the tab.
435 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 1, 1))); 410 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 1, 1)));
436 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 5, 6))); 411 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 5, 6)));
437 412
438 // Hit tests in the non-occluded region of the tab. 413 // Hit tests in the non-occluded region of the tab.
439 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 1, 1))); 414 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 1, 1)));
440 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 2, 2))); 415 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 2, 2)));
441
442 // Hit tests against the tab close button. Note that hit tests from either
443 // mouse or touch should both fail if they are strictly contained within
444 // the button's padding.
445 views::ImageButton* most_right_close = most_right_tab->close_button_;
446 EXPECT_FALSE(most_right_close->HitTestRect(gfx::Rect(1, 1, 1, 1)));
447 EXPECT_FALSE(most_right_close->HitTestRect(gfx::Rect(1, 1, 2, 2)));
448 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(10, 10, 1, 1)));
449 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(10, 10, 25, 35)));
450 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(-10, 10, 25, 35)));
451 } 416 }
452 417
453 // Creates a tab strip in stacked layout mode and verifies the correctness 418 // Tests that the tab close buttons of non-active tabs are hidden when
454 // of hit tests against the visible/occluded region of a partially-occluded 419 // the tabstrip is in stacked tab mode.
455 // tab close button. 420 TEST_F(TabStripTest, TabCloseButtonVisibilityWhenStacked) {
tdanderson 2015/03/06 19:59:21 My test approach here feels like a bit of a hack,
sky 2015/03/09 19:55:59 Your change means we need to make sure SetStackedL
tdanderson 2015/03/11 18:01:38 I've made comments about this in the latest patchs
456 TEST_F(TabStripTest, ClippedTabCloseButton) {
457 tab_strip_->SetBounds(0, 0, 220, 20);
458
459 controller_->AddTab(0, false); 421 controller_->AddTab(0, false);
460 controller_->AddTab(1, true); 422 controller_->AddTab(1, true);
461 ASSERT_EQ(2, tab_strip_->tab_count()); 423 controller_->AddTab(2, false);
424 ASSERT_EQ(3, tab_strip_->tab_count());
462 425
463 Tab* left_tab = tab_strip_->tab_at(0); 426 Tab* tab0 = tab_strip_->tab_at(0);
464 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20))); 427 tab0->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(100, 20)));
465 428
466 Tab* active_tab = tab_strip_->tab_at(1); 429 Tab* tab1 = tab_strip_->tab_at(1);
467 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(180, 0), gfx::Size(200, 20))); 430 tab1->SetBoundsRect(gfx::Rect(gfx::Point(100, 0), gfx::Size(100, 20)));
468 ASSERT_TRUE(active_tab->IsActive()); 431 ASSERT_TRUE(tab1->IsActive());
469 432
470 // Switch to stacked layout mode and force a layout to ensure tabs stack. 433 Tab* tab2 = tab_strip_->tab_at(2);
434 tab2->SetBoundsRect(gfx::Rect(gfx::Point(200, 0), gfx::Size(100, 20)));
435
436 tab_strip_->SetBounds(0, 0, 300, 20);
437
438 // Ensure that all tab close buttons are visible.
439 EXPECT_TRUE(tab0->showing_close_button_);
440 EXPECT_TRUE(tab1->showing_close_button_);
441 EXPECT_TRUE(tab2->showing_close_button_);
442
443 // Only the close button of the active tab should be visible
444 // in stacked tab mode. Setting the tab strip size triggers
445 // a relayout.
471 tab_strip_->SetStackedLayout(true); 446 tab_strip_->SetStackedLayout(true);
472 tab_strip_->DoLayout(); 447 tab_strip_->SetBounds(0, 0, 200, 20);
448 EXPECT_FALSE(tab0->showing_close_button_);
449 EXPECT_TRUE(tab1->showing_close_button_);
450 EXPECT_FALSE(tab2->showing_close_button_);
473 451
474 452 // When exiting stacked layout mode all tab close buttons should
475 // Tests involving |left_tab|, which has part of its bounds and its tab 453 // become visible again. Setting the tab strip size triggers
476 // close button partially occluded by |active_tab|. 454 // a relayout.
477 455 tab_strip_->SetStackedLayout(false);
478 // Bounds of the tab's hit test mask. 456 tab_strip_->SetBounds(0, 0, 300, 20);
479 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab); 457 EXPECT_TRUE(tab0->showing_close_button_);
480 EXPECT_EQ(gfx::Rect(6, 2, 91, 27).ToString(), tab_bounds.ToString()); 458 EXPECT_TRUE(tab1->showing_close_button_);
481 459 EXPECT_TRUE(tab2->showing_close_button_);
482 // Bounds of the tab close button (without padding) in the tab's
483 // coordinate space.
484 gfx::Rect contents_bounds = GetTabCloseHitTestMask(left_tab, false);
485 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved.
486 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString());
487
488 // Verify that the tab close button is only partially occluded.
489 EXPECT_FALSE(tab_bounds.Contains(contents_bounds));
490 EXPECT_TRUE(tab_bounds.Intersects(contents_bounds));
491
492 views::ImageButton* left_close = left_tab->close_button_;
493
494 // Hit tests from mouse should return true if and only if the location
495 // is within a visible region.
496 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(2, 15, 1, 1)));
497 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(3, 15, 1, 1)));
498 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(10, 10, 1, 1)));
499 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(15, 12, 1, 1)));
500 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(16, 10, 1, 1)));
501
502 // All hit tests from touch should return false because the button is
503 // not fully visible.
504 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(2, 15, 2, 2)));
505 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(3, 15, 25, 25)));
506 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(10, 10, 4, 5)));
507 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(15, 12, 2, 2)));
508 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(16, 10, 20, 20)));
509 } 460 }
510 461
511 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) { 462 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) {
512 tab_strip_->SetBounds(0, 0, 1000, 20); 463 tab_strip_->SetBounds(0, 0, 1000, 20);
513 464
514 controller_->AddTab(0, false); 465 controller_->AddTab(0, false);
515 controller_->AddTab(1, true); 466 controller_->AddTab(1, true);
516 controller_->AddTab(2, false); 467 controller_->AddTab(2, false);
517 controller_->AddTab(3, false); 468 controller_->AddTab(3, false);
518 ASSERT_EQ(4, tab_strip_->tab_count()); 469 ASSERT_EQ(4, tab_strip_->tab_count());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap)); 582 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap));
632 583
633 EXPECT_EQ( 584 EXPECT_EQ(
634 right_tab, 585 right_tab,
635 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); 586 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap)));
636 587
637 // Confirm that tab strip doe not return tooltip handler for points that 588 // Confirm that tab strip doe not return tooltip handler for points that
638 // don't hit it. 589 // don't hit it.
639 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); 590 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2)));
640 } 591 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698