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

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

Issue 149753007: Merge 249331 "Tab close buttons can only be targeted with touch ..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1750/src/
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip.h ('k') | no next file » | 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"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 Tab* most_right_tab = tab_strip_->tab_at(3); 255 Tab* most_right_tab = tab_strip_->tab_at(3);
256 most_right_tab->SetBoundsRect(gfx::Rect(gfx::Point(450, 0), 256 most_right_tab->SetBoundsRect(gfx::Rect(gfx::Point(450, 0),
257 gfx::Size(200, 20))); 257 gfx::Size(200, 20)));
258 258
259 // Switch to stacked layout mode and force a layout to ensure tabs stack. 259 // Switch to stacked layout mode and force a layout to ensure tabs stack.
260 tab_strip_->SetLayoutType(TAB_STRIP_LAYOUT_STACKED, false); 260 tab_strip_->SetLayoutType(TAB_STRIP_LAYOUT_STACKED, false);
261 tab_strip_->DoLayout(); 261 tab_strip_->DoLayout();
262 262
263 263
264 // Tests involving |left_tab|, which has part of its bounds and its tab 264 // Tests involving |left_tab|, which has part of its bounds and its tab
265 // close button occluded by |active_tab|. 265 // close button completely occluded by |active_tab|.
266 266
267 // Bounds of the tab's hit test mask. 267 // Bounds of the tab's hit test mask.
268 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab); 268 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab);
269 EXPECT_EQ(gfx::Rect(6, 2, 61, 27).ToString(), tab_bounds.ToString()); 269 EXPECT_EQ(gfx::Rect(6, 2, 61, 27).ToString(), tab_bounds.ToString());
270 270
271 // Bounds of the tab close button (without padding) in the tab's 271 // Bounds of the tab close button (without padding) in the tab's
272 // coordinate space. 272 // coordinate space.
273 gfx::Rect contents_bounds = GetTabCloseHitTestMask(left_tab, false); 273 gfx::Rect contents_bounds = GetTabCloseHitTestMask(left_tab, false);
274 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved. 274 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved.
275 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString()); 275 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString());
276 276
277 // Verify that the tab close button is occluded. 277 // Verify that the tab close button is completely occluded.
278 EXPECT_FALSE(tab_bounds.Contains(contents_bounds)); 278 EXPECT_FALSE(tab_bounds.Contains(contents_bounds));
279 279
280 // Hit tests in the non-occuluded region of the tab. 280 // Hit tests in the non-occuluded region of the tab.
281 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 2, 2))); 281 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 2, 2)));
282 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 1, 1))); 282 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 1, 1)));
283 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 1, 1))); 283 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 1, 1)));
284 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 25, 35))); 284 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 25, 35)));
285 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(-10, -5, 20, 30))); 285 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(-10, -5, 20, 30)));
286 286
287 // Hit tests in the occluded region of the tab. 287 // Hit tests in the occluded region of the tab.
(...skipping 27 matching lines...) Expand all
315 315
316 // Bounds of the tab close button (without padding) in the tab's 316 // Bounds of the tab close button (without padding) in the tab's
317 // coordinate space. 317 // coordinate space.
318 gfx::Rect local_bounds = GetTabCloseHitTestMask(active_tab, true); 318 gfx::Rect local_bounds = GetTabCloseHitTestMask(active_tab, true);
319 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString()); 319 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString());
320 320
321 // Hit tests within the tab. 321 // Hit tests within the tab.
322 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 1, 1))); 322 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 1, 1)));
323 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 2, 2))); 323 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 2, 2)));
324 324
325 // Hit tests against the tab close button. Note that if the hit test 325 // Hit tests against the tab close button. Note that hit tests from either
326 // source is a mouse, a hit test within the button's padding should fail. 326 // mouse or touch should both fail if they are strictly contained within
327 // the button's padding.
327 views::ImageButton* active_close = active_tab->close_button_; 328 views::ImageButton* active_close = active_tab->close_button_;
328 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 1, 1))); 329 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 1, 1)));
329 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(1, 1, 2, 2))); 330 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 2, 2)));
330 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 1, 1))); 331 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 1, 1)));
331 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 25, 35))); 332 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 25, 35)));
332 333
333 334
334 // Tests involving |most_right_tab|, which has part of its bounds occluded 335 // Tests involving |most_right_tab|, which has part of its bounds occluded
335 // by |right_tab| but has its tab close button completely visible. 336 // by |right_tab| but has its tab close button completely visible.
336 337
337 tab_bounds = GetTabHitTestMask(most_right_tab); 338 tab_bounds = GetTabHitTestMask(most_right_tab);
338 EXPECT_EQ(gfx::Rect(84, 2, 30, 27).ToString(), tab_bounds.ToString()); 339 EXPECT_EQ(gfx::Rect(84, 2, 30, 27).ToString(), tab_bounds.ToString());
339 contents_bounds = GetTabCloseHitTestMask(active_tab, false); 340 contents_bounds = GetTabCloseHitTestMask(active_tab, false);
340 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved. 341 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved.
341 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString()); 342 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString());
342 local_bounds = GetTabCloseHitTestMask(active_tab, true); 343 local_bounds = GetTabCloseHitTestMask(active_tab, true);
343 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString()); 344 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString());
344 345
345 // Verify that the tab close button is not occluded. 346 // Verify that the tab close button is not occluded.
346 EXPECT_TRUE(tab_bounds.Contains(contents_bounds)); 347 EXPECT_TRUE(tab_bounds.Contains(contents_bounds));
347 348
348 // Hit tests in the occluded region of the tab. 349 // Hit tests in the occluded region of the tab.
349 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 1, 1))); 350 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 1, 1)));
350 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 5, 6))); 351 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 5, 6)));
351 352
352 // Hit tests in the non-occluded region of the tab. 353 // Hit tests in the non-occluded region of the tab.
353 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 1, 1))); 354 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 1, 1)));
354 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 2, 2))); 355 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 2, 2)));
355 356
356 // Hit tests against the tab close button. Note that if the hit test 357 // Hit tests against the tab close button. Note that hit tests from either
357 // source is a mouse, a hit test within the button's padding should fail. 358 // mouse or touch should both fail if they are strictly contained within
359 // the button's padding.
358 views::ImageButton* most_right_close = most_right_tab->close_button_; 360 views::ImageButton* most_right_close = most_right_tab->close_button_;
359 EXPECT_FALSE(most_right_close->HitTestRect(gfx::Rect(1, 1, 1, 1))); 361 EXPECT_FALSE(most_right_close->HitTestRect(gfx::Rect(1, 1, 1, 1)));
360 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(1, 1, 2, 2))); 362 EXPECT_FALSE(most_right_close->HitTestRect(gfx::Rect(1, 1, 2, 2)));
361 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(10, 10, 1, 1))); 363 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(10, 10, 1, 1)));
362 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(10, 10, 25, 35))); 364 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(10, 10, 25, 35)));
363 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(-10, 10, 25, 35))); 365 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(-10, 10, 25, 35)));
364 } 366 }
365 367
368 // Creates a tab strip in stacked layout mode and verifies the correctness
369 // of hit tests against the visible/occluded region of a partially-occluded
370 // tab close button.
371 TEST_F(TabStripTest, ClippedTabCloseButton) {
372 tab_strip_->SetBounds(0, 0, 220, 20);
373
374 controller_->AddTab(0, false);
375 controller_->AddTab(1, true);
376 ASSERT_EQ(2, tab_strip_->tab_count());
377
378 Tab* left_tab = tab_strip_->tab_at(0);
379 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20)));
380
381 Tab* active_tab = tab_strip_->tab_at(1);
382 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(180, 0), gfx::Size(200, 20)));
383 ASSERT_TRUE(active_tab->IsActive());
384
385 // Switch to stacked layout mode and force a layout to ensure tabs stack.
386 tab_strip_->SetLayoutType(TAB_STRIP_LAYOUT_STACKED, false);
387 tab_strip_->DoLayout();
388
389
390 // Tests involving |left_tab|, which has part of its bounds and its tab
391 // close button partially occluded by |active_tab|.
392
393 // Bounds of the tab's hit test mask.
394 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab);
395 EXPECT_EQ(gfx::Rect(6, 2, 91, 27).ToString(), tab_bounds.ToString());
396
397 // Bounds of the tab close button (without padding) in the tab's
398 // coordinate space.
399 gfx::Rect contents_bounds = GetTabCloseHitTestMask(left_tab, false);
400 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved.
401 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString());
402
403 // Verify that the tab close button is only partially occluded.
404 EXPECT_FALSE(tab_bounds.Contains(contents_bounds));
405 EXPECT_TRUE(tab_bounds.Intersects(contents_bounds));
406
407 views::ImageButton* left_close = left_tab->close_button_;
408
409 // Hit tests from mouse should return true if and only if the location
410 // is within a visible region.
411 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(2, 15, 1, 1)));
412 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(3, 15, 1, 1)));
413 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(10, 10, 1, 1)));
414 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(15, 12, 1, 1)));
415 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(16, 10, 1, 1)));
416
417 // All hit tests from touch should return false because the button is
418 // not fully visible.
419 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(2, 15, 2, 2)));
420 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(3, 15, 25, 25)));
421 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(10, 10, 4, 5)));
422 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(15, 12, 2, 2)));
423 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(16, 10, 20, 20)));
424 }
425
366 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) { 426 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) {
367 tab_strip_->SetBounds(0, 0, 1000, 20); 427 tab_strip_->SetBounds(0, 0, 1000, 20);
368 428
369 controller_->AddTab(0, false); 429 controller_->AddTab(0, false);
370 controller_->AddTab(1, true); 430 controller_->AddTab(1, true);
371 controller_->AddTab(2, false); 431 controller_->AddTab(2, false);
372 controller_->AddTab(3, false); 432 controller_->AddTab(3, false);
373 ASSERT_EQ(4, tab_strip_->tab_count()); 433 ASSERT_EQ(4, tab_strip_->tab_count());
374 434
375 // Verify that the active tab will be a tooltip handler for points that hit 435 // Verify that the active tab will be a tooltip handler for points that hit
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap)); 546 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap));
487 547
488 EXPECT_EQ( 548 EXPECT_EQ(
489 right_tab, 549 right_tab,
490 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); 550 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap)));
491 551
492 // Confirm that tab strip doe not return tooltip handler for points that 552 // Confirm that tab strip doe not return tooltip handler for points that
493 // don't hit it. 553 // don't hit it.
494 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); 554 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2)));
495 } 555 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698