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

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: histograms.xml changed 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
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip.cc ('k') | chrome/browser/ui/views/tabs/tab_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" 11 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
12 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h" 12 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h"
13 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/geometry/rect_conversions.h" 16 #include "ui/gfx/geometry/rect_conversions.h"
16 #include "ui/gfx/path.h" 17 #include "ui/gfx/path.h"
17 #include "ui/gfx/skia_util.h" 18 #include "ui/gfx/skia_util.h"
18 #include "ui/views/test/views_test_base.h" 19 #include "ui/views/test/views_test_base.h"
19 #include "ui/views/view.h" 20 #include "ui/views/view.h"
20 #include "ui/views/view_targeter.h" 21 #include "ui/views/view_targeter.h"
21 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
22 23
23 namespace { 24 namespace {
24 25
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 init_params.bounds = gfx::Rect(0, 0, 200, 200); 117 init_params.bounds = gfx::Rect(0, 0, 200, 200);
117 widget_->Init(init_params); 118 widget_->Init(init_params);
118 widget_->SetContentsView(&parent_); 119 widget_->SetContentsView(&parent_);
119 } 120 }
120 121
121 void TearDown() override { 122 void TearDown() override {
122 widget_.reset(); 123 widget_.reset();
123 views::ViewsTestBase::TearDown(); 124 views::ViewsTestBase::TearDown();
124 } 125 }
125 126
127 // Forces a call to OnPaint() for each tab in |tab_strip_| in order to
128 // trigger a layout, which is needed to update the visibility of tab
129 // close buttons after a tab switch or close. Note that painting does
130 // not occur in unit tests, which is why this helper is used.
131 void TriggerPaintOfAllTabs() {
132 gfx::Canvas canvas;
133 for (int i = 0; i < tab_strip_->tab_count(); ++i)
134 tab_strip_->tab_at(i)->OnPaint(&canvas);
135 }
136
126 protected: 137 protected:
127 // Returns the rectangular hit test region of |tab| in |tab|'s local 138 // Returns the rectangular hit test region of |tab| in |tab|'s local
128 // coordinate space. 139 // coordinate space.
129 gfx::Rect GetTabHitTestMask(Tab* tab) { 140 gfx::Rect GetTabHitTestMask(Tab* tab) {
130 views::ViewTargeter* targeter = tab->targeter(); 141 views::ViewTargeter* targeter = tab->targeter();
131 DCHECK(targeter); 142 DCHECK(targeter);
132 views::MaskedTargeterDelegate* delegate = 143 views::MaskedTargeterDelegate* delegate =
133 static_cast<views::MaskedTargeterDelegate*>(tab); 144 static_cast<views::MaskedTargeterDelegate*>(tab);
134 145
135 gfx::Path mask; 146 gfx::Path mask;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 320
310 // Now tabs have the immersive height. 321 // Now tabs have the immersive height.
311 int immersive_height = Tab::GetImmersiveHeight(); 322 int immersive_height = Tab::GetImmersiveHeight();
312 EXPECT_EQ(immersive_height, tab_strip_->GetPreferredSize().height()); 323 EXPECT_EQ(immersive_height, tab_strip_->GetPreferredSize().height());
313 324
314 // Sanity-check immersive tabs are shorter than normal tabs. 325 // Sanity-check immersive tabs are shorter than normal tabs.
315 EXPECT_LT(immersive_height, normal_height); 326 EXPECT_LT(immersive_height, normal_height);
316 } 327 }
317 328
318 // Creates a tab strip in stacked layout mode and verifies the correctness 329 // 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 330 // of hit tests against the visible/occluded regions of a tab and the tab
320 // visible/occluded tab close buttons. 331 // close button of the active tab.
321 TEST_F(TabStripTest, TabHitTestMaskWhenStacked) { 332 TEST_F(TabStripTest, TabHitTestMaskWhenStacked) {
322 tab_strip_->SetBounds(0, 0, 300, 20); 333 tab_strip_->SetBounds(0, 0, 300, 20);
323 334
324 controller_->AddTab(0, false); 335 controller_->AddTab(0, false);
325 controller_->AddTab(1, true); 336 controller_->AddTab(1, true);
326 controller_->AddTab(2, false); 337 controller_->AddTab(2, false);
327 controller_->AddTab(3, false); 338 controller_->AddTab(3, false);
328 ASSERT_EQ(4, tab_strip_->tab_count()); 339 ASSERT_EQ(4, tab_strip_->tab_count());
329 340
330 Tab* left_tab = tab_strip_->tab_at(0); 341 Tab* left_tab = tab_strip_->tab_at(0);
331 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20))); 342 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20)));
332 343
333 Tab* active_tab = tab_strip_->tab_at(1); 344 Tab* active_tab = tab_strip_->tab_at(1);
334 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(150, 0), gfx::Size(200, 20))); 345 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(150, 0), gfx::Size(200, 20)));
335 ASSERT_TRUE(active_tab->IsActive()); 346 ASSERT_TRUE(active_tab->IsActive());
336 347
337 Tab* right_tab = tab_strip_->tab_at(2); 348 Tab* right_tab = tab_strip_->tab_at(2);
338 right_tab->SetBoundsRect(gfx::Rect(gfx::Point(300, 0), gfx::Size(200, 20))); 349 right_tab->SetBoundsRect(gfx::Rect(gfx::Point(300, 0), gfx::Size(200, 20)));
339 350
340 Tab* most_right_tab = tab_strip_->tab_at(3); 351 Tab* most_right_tab = tab_strip_->tab_at(3);
341 most_right_tab->SetBoundsRect(gfx::Rect(gfx::Point(450, 0), 352 most_right_tab->SetBoundsRect(gfx::Rect(gfx::Point(450, 0),
342 gfx::Size(200, 20))); 353 gfx::Size(200, 20)));
343 354
344 // Switch to stacked layout mode and force a layout to ensure tabs stack. 355 // Switch to stacked layout mode and force a layout to ensure tabs stack.
345 tab_strip_->SetStackedLayout(true); 356 tab_strip_->SetStackedLayout(true);
346 tab_strip_->DoLayout(); 357 tab_strip_->DoLayout();
347 358
348 359
349 // Tests involving |left_tab|, which has part of its bounds and its tab 360 // Tests involving |left_tab|, which has part of its bounds occluded by
350 // close button completely occluded by |active_tab|. 361 // |active_tab|.
351 362
352 // Bounds of the tab's hit test mask. 363 // Bounds of the tab's hit test mask.
353 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab); 364 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab);
354 EXPECT_EQ(gfx::Rect(6, 2, 61, 27).ToString(), tab_bounds.ToString()); 365 EXPECT_EQ(gfx::Rect(6, 2, 61, 27).ToString(), tab_bounds.ToString());
355 366
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. 367 // Hit tests in the non-occuluded region of the tab.
366 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 2, 2))); 368 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 2, 2)));
367 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 1, 1))); 369 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 1, 1)));
368 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 1, 1))); 370 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 1, 1)));
369 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 25, 35))); 371 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 25, 35)));
370 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(-10, -5, 20, 30))); 372 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(-10, -5, 20, 30)));
371 373
372 // Hit tests in the occluded region of the tab. 374 // Hit tests in the occluded region of the tab.
373 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(70, 15, 2, 2))); 375 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(70, 15, 2, 2)));
374 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(70, -15, 30, 40))); 376 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(70, -15, 30, 40)));
375 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(87, 20, 5, 3))); 377 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(87, 20, 5, 3)));
376 378
377 // Hit tests completely outside of the tab. 379 // Hit tests completely outside of the tab.
378 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(-20, -25, 1, 1))); 380 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(-20, -25, 1, 1)));
379 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(-20, -25, 3, 19))); 381 EXPECT_FALSE(left_tab->HitTestRect(gfx::Rect(-20, -25, 3, 19)));
380 382
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 383
390 // Tests involving |active_tab|, which is completely visible. 384 // Tests involving |active_tab|, which is completely visible.
391 385
392 tab_bounds = GetTabHitTestMask(active_tab); 386 tab_bounds = GetTabHitTestMask(active_tab);
393 EXPECT_EQ(gfx::Rect(6, 2, 108, 27).ToString(), tab_bounds.ToString()); 387 EXPECT_EQ(gfx::Rect(6, 2, 108, 27).ToString(), tab_bounds.ToString());
394 contents_bounds = GetTabCloseHitTestMask(active_tab, false); 388 gfx::Rect contents_bounds = GetTabCloseHitTestMask(active_tab, false);
395 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved. 389 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved.
396 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString()); 390 // EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString());
397 391
398 // Verify that the tab close button is not occluded. 392 // Verify that the tab close button is not occluded.
399 EXPECT_TRUE(tab_bounds.Contains(contents_bounds)); 393 EXPECT_TRUE(tab_bounds.Contains(contents_bounds));
400 394
401 // Bounds of the tab close button (without padding) in the tab's 395 // Bounds of the tab close button (without padding) in the tab's
402 // coordinate space. 396 // coordinate space.
403 gfx::Rect local_bounds = GetTabCloseHitTestMask(active_tab, true); 397 gfx::Rect local_bounds = GetTabCloseHitTestMask(active_tab, true);
404 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString()); 398 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString());
405 399
406 // Hit tests within the tab. 400 // Hit tests within the tab.
407 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 1, 1))); 401 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 1, 1)));
408 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 2, 2))); 402 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 2, 2)));
409 403
410 // Hit tests against the tab close button. Note that hit tests from either 404 // 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 405 // mouse or touch should both fail if they are strictly contained within
412 // the button's padding. 406 // the button's padding.
413 views::ImageButton* active_close = active_tab->close_button_; 407 views::ImageButton* active_close = active_tab->close_button_;
414 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 1, 1))); 408 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 1, 1)));
415 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 2, 2))); 409 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 2, 2)));
416 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 1, 1))); 410 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 1, 1)));
417 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 25, 35))); 411 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 25, 35)));
418 412
419 413
420 // Tests involving |most_right_tab|, which has part of its bounds occluded 414 // Tests involving |most_right_tab|, which has part of its bounds occluded
421 // by |right_tab| but has its tab close button completely visible. 415 // by |right_tab|.
422 416
423 tab_bounds = GetTabHitTestMask(most_right_tab); 417 tab_bounds = GetTabHitTestMask(most_right_tab);
424 EXPECT_EQ(gfx::Rect(84, 2, 30, 27).ToString(), tab_bounds.ToString()); 418 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 419
434 // Hit tests in the occluded region of the tab. 420 // Hit tests in the occluded region of the tab.
435 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 1, 1))); 421 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))); 422 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 5, 6)));
437 423
438 // Hit tests in the non-occluded region of the tab. 424 // Hit tests in the non-occluded region of the tab.
439 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 1, 1))); 425 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))); 426 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 } 427 }
452 428
453 // Creates a tab strip in stacked layout mode and verifies the correctness 429 // 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 430 // the tabstrip is in stacked tab mode.
455 // tab close button. 431 TEST_F(TabStripTest, TabCloseButtonVisibilityWhenStacked) {
456 TEST_F(TabStripTest, ClippedTabCloseButton) { 432 tab_strip_->SetBounds(0, 0, 300, 20);
457 tab_strip_->SetBounds(0, 0, 220, 20);
458
459 controller_->AddTab(0, false); 433 controller_->AddTab(0, false);
460 controller_->AddTab(1, true); 434 controller_->AddTab(1, true);
461 ASSERT_EQ(2, tab_strip_->tab_count()); 435 controller_->AddTab(2, false);
436 ASSERT_EQ(3, tab_strip_->tab_count());
462 437
463 Tab* left_tab = tab_strip_->tab_at(0); 438 Tab* tab0 = tab_strip_->tab_at(0);
464 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20))); 439 Tab* tab1 = tab_strip_->tab_at(1);
440 ASSERT_TRUE(tab1->IsActive());
441 Tab* tab2 = tab_strip_->tab_at(2);
465 442
466 Tab* active_tab = tab_strip_->tab_at(1); 443 // Ensure that all tab close buttons are initially visible.
467 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(180, 0), gfx::Size(200, 20))); 444 TriggerPaintOfAllTabs();
468 ASSERT_TRUE(active_tab->IsActive()); 445 EXPECT_TRUE(tab0->showing_close_button_);
446 EXPECT_TRUE(tab1->showing_close_button_);
447 EXPECT_TRUE(tab2->showing_close_button_);
469 448
470 // Switch to stacked layout mode and force a layout to ensure tabs stack. 449 // Enter stacked layout mode and verify this sets |touch_layout_|.
450 ASSERT_FALSE(tab_strip_->touch_layout_.get());
471 tab_strip_->SetStackedLayout(true); 451 tab_strip_->SetStackedLayout(true);
472 tab_strip_->DoLayout(); 452 TriggerPaintOfAllTabs();
453 ASSERT_TRUE(tab_strip_->touch_layout_.get());
473 454
455 // Only the close button of the active tab should be visible in stacked
456 // layout mode.
457 EXPECT_FALSE(tab0->showing_close_button_);
458 EXPECT_TRUE(tab1->showing_close_button_);
459 EXPECT_FALSE(tab2->showing_close_button_);
474 460
475 // Tests involving |left_tab|, which has part of its bounds and its tab 461 // An inactive tab added to the tabstrip should not show
476 // close button partially occluded by |active_tab|. 462 // its tab close button.
463 controller_->AddTab(3, false);
464 Tab* tab3 = tab_strip_->tab_at(3);
465 EXPECT_FALSE(tab0->showing_close_button_);
466 EXPECT_TRUE(tab1->showing_close_button_);
467 EXPECT_FALSE(tab2->showing_close_button_);
468 EXPECT_FALSE(tab3->showing_close_button_);
477 469
478 // Bounds of the tab's hit test mask. 470 // After switching tabs, the previously-active tab should have its
479 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab); 471 // tab close button hidden and the newly-active tab should show
480 EXPECT_EQ(gfx::Rect(6, 2, 91, 27).ToString(), tab_bounds.ToString()); 472 // its tab close button.
473 tab_strip_->SelectTab(tab2);
474 TriggerPaintOfAllTabs();
475 ASSERT_FALSE(tab1->IsActive());
476 ASSERT_TRUE(tab2->IsActive());
477 EXPECT_FALSE(tab0->showing_close_button_);
478 EXPECT_FALSE(tab1->showing_close_button_);
479 EXPECT_TRUE(tab2->showing_close_button_);
480 EXPECT_FALSE(tab3->showing_close_button_);
481 481
482 // Bounds of the tab close button (without padding) in the tab's 482 // After closing the active tab, the tab which becomes active should
483 // coordinate space. 483 // show its tab close button.
484 gfx::Rect contents_bounds = GetTabCloseHitTestMask(left_tab, false); 484 tab_strip_->CloseTab(tab1, CLOSE_TAB_FROM_TOUCH);
485 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved. 485 tab1 = nullptr;
486 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString()); 486 ASSERT_TRUE(tab2->IsActive());
487 TriggerPaintOfAllTabs();
488 EXPECT_FALSE(tab0->showing_close_button_);
489 EXPECT_TRUE(tab2->showing_close_button_);
490 EXPECT_FALSE(tab3->showing_close_button_);
487 491
488 // Verify that the tab close button is only partially occluded. 492 // All tab close buttons should be shown when disengaging stacked tab mode.
489 EXPECT_FALSE(tab_bounds.Contains(contents_bounds)); 493 tab_strip_->SetStackedLayout(false);
490 EXPECT_TRUE(tab_bounds.Intersects(contents_bounds)); 494 TriggerPaintOfAllTabs();
491 495 ASSERT_FALSE(tab_strip_->touch_layout_.get());
492 views::ImageButton* left_close = left_tab->close_button_; 496 EXPECT_TRUE(tab0->showing_close_button_);
493 497 EXPECT_TRUE(tab2->showing_close_button_);
494 // Hit tests from mouse should return true if and only if the location 498 EXPECT_TRUE(tab3->showing_close_button_);
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 } 499 }
510 500
511 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) { 501 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) {
512 tab_strip_->SetBounds(0, 0, 1000, 20); 502 tab_strip_->SetBounds(0, 0, 1000, 20);
513 503
514 controller_->AddTab(0, false); 504 controller_->AddTab(0, false);
515 controller_->AddTab(1, true); 505 controller_->AddTab(1, true);
516 controller_->AddTab(2, false); 506 controller_->AddTab(2, false);
517 controller_->AddTab(3, false); 507 controller_->AddTab(3, false);
518 ASSERT_EQ(4, tab_strip_->tab_count()); 508 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)); 621 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap));
632 622
633 EXPECT_EQ( 623 EXPECT_EQ(
634 right_tab, 624 right_tab,
635 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); 625 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap)));
636 626
637 // Confirm that tab strip doe not return tooltip handler for points that 627 // Confirm that tab strip doe not return tooltip handler for points that
638 // don't hit it. 628 // don't hit it.
639 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); 629 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2)));
640 } 630 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip.cc ('k') | chrome/browser/ui/views/tabs/tab_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698