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

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

Issue 1710253003: Misc. Tab-related cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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.h" 5 #include "chrome/browser/ui/views/tabs/tab.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 244 }
245 245
246 std::string original_locale_; 246 std::string original_locale_;
247 }; 247 };
248 248
249 TEST_F(TabTest, HitTestTopPixel) { 249 TEST_F(TabTest, HitTestTopPixel) {
250 Widget widget; 250 Widget widget;
251 InitWidget(&widget); 251 InitWidget(&widget);
252 252
253 FakeTabController tab_controller; 253 FakeTabController tab_controller;
254 Tab tab(&tab_controller); 254 Tab tab(&tab_controller, nullptr);
255 widget.GetContentsView()->AddChildView(&tab); 255 widget.GetContentsView()->AddChildView(&tab);
256 tab.SetBoundsRect(gfx::Rect(gfx::Point(0, 0), Tab::GetStandardSize())); 256 tab.SetBoundsRect(gfx::Rect(gfx::Point(0, 0), Tab::GetStandardSize()));
257 257
258 // Tabs are slanted, so a click halfway down the left edge won't hit it. 258 // Tabs are slanted, so a click halfway down the left edge won't hit it.
259 int middle_y = tab.height() / 2; 259 int middle_y = tab.height() / 2;
260 EXPECT_FALSE(tab.HitTestPoint(gfx::Point(0, middle_y))); 260 EXPECT_FALSE(tab.HitTestPoint(gfx::Point(0, middle_y)));
261 261
262 // Normally, tabs should not be hit if we click in the exclusion region, only 262 // Normally, tabs should not be hit if we click in the exclusion region, only
263 // if we click below it. 263 // if we click below it.
264 const int exclusion = GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT); 264 const int exclusion = GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT);
(...skipping 14 matching lines...) Expand all
279 TEST_F(TabTest, LayoutAndVisibilityOfElements) { 279 TEST_F(TabTest, LayoutAndVisibilityOfElements) {
280 static const TabMediaState kMediaStatesToTest[] = { 280 static const TabMediaState kMediaStatesToTest[] = {
281 TAB_MEDIA_STATE_NONE, TAB_MEDIA_STATE_CAPTURING, 281 TAB_MEDIA_STATE_NONE, TAB_MEDIA_STATE_CAPTURING,
282 TAB_MEDIA_STATE_AUDIO_PLAYING, TAB_MEDIA_STATE_AUDIO_MUTING 282 TAB_MEDIA_STATE_AUDIO_PLAYING, TAB_MEDIA_STATE_AUDIO_MUTING
283 }; 283 };
284 284
285 Widget widget; 285 Widget widget;
286 InitWidget(&widget); 286 InitWidget(&widget);
287 287
288 FakeTabController controller; 288 FakeTabController controller;
289 Tab tab(&controller); 289 Tab tab(&controller, nullptr);
290 widget.GetContentsView()->AddChildView(&tab); 290 widget.GetContentsView()->AddChildView(&tab);
291 291
292 SkBitmap bitmap; 292 SkBitmap bitmap;
293 bitmap.allocN32Pixels(16, 16); 293 bitmap.allocN32Pixels(16, 16);
294 TabRendererData data; 294 TabRendererData data;
295 data.favicon = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 295 data.favicon = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
296 296
297 // Perform layout over all possible combinations, checking for correct 297 // Perform layout over all possible combinations, checking for correct
298 // results. 298 // results.
299 for (int is_pinned_tab = 0; is_pinned_tab < 2; ++is_pinned_tab) { 299 for (int is_pinned_tab = 0; is_pinned_tab < 2; ++is_pinned_tab) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 334 }
335 335
336 // Regression test for http://crbug.com/420313: Confirms that any child Views of 336 // Regression test for http://crbug.com/420313: Confirms that any child Views of
337 // Tab do not attempt to provide their own tooltip behavior/text. It also tests 337 // Tab do not attempt to provide their own tooltip behavior/text. It also tests
338 // that Tab provides the expected tooltip text (according to tab_utils). 338 // that Tab provides the expected tooltip text (according to tab_utils).
339 TEST_F(TabTest, TooltipProvidedByTab) { 339 TEST_F(TabTest, TooltipProvidedByTab) {
340 Widget widget; 340 Widget widget;
341 InitWidget(&widget); 341 InitWidget(&widget);
342 342
343 FakeTabController controller; 343 FakeTabController controller;
344 Tab tab(&controller); 344 Tab tab(&controller, nullptr);
345 widget.GetContentsView()->AddChildView(&tab); 345 widget.GetContentsView()->AddChildView(&tab);
346 tab.SetBoundsRect(gfx::Rect(Tab::GetStandardSize())); 346 tab.SetBoundsRect(gfx::Rect(Tab::GetStandardSize()));
347 347
348 SkBitmap bitmap; 348 SkBitmap bitmap;
349 bitmap.allocN32Pixels(16, 16); 349 bitmap.allocN32Pixels(16, 16);
350 TabRendererData data; 350 TabRendererData data;
351 data.favicon = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 351 data.favicon = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
352 352
353 data.title = base::UTF8ToUTF16( 353 data.title = base::UTF8ToUTF16(
354 "This is a really long tab title that would case views::Label to provide " 354 "This is a really long tab title that would case views::Label to provide "
(...skipping 29 matching lines...) Expand all
384 EXPECT_EQ(chrome::AssembleTabTooltipText(data.title, data.media_state), 384 EXPECT_EQ(chrome::AssembleTabTooltipText(data.title, data.media_state),
385 tooltip); 385 tooltip);
386 } 386 }
387 } 387 }
388 } 388 }
389 389
390 // Regression test for http://crbug.com/226253. Calling Layout() more than once 390 // Regression test for http://crbug.com/226253. Calling Layout() more than once
391 // shouldn't change the insets of the close button. 391 // shouldn't change the insets of the close button.
392 TEST_F(TabTest, CloseButtonLayout) { 392 TEST_F(TabTest, CloseButtonLayout) {
393 FakeTabController tab_controller; 393 FakeTabController tab_controller;
394 Tab tab(&tab_controller); 394 Tab tab(&tab_controller, nullptr);
395 tab.SetBounds(0, 0, 100, 50); 395 tab.SetBounds(0, 0, 100, 50);
396 LayoutTab(&tab); 396 LayoutTab(&tab);
397 gfx::Insets close_button_insets = GetCloseButton(tab)->GetInsets(); 397 gfx::Insets close_button_insets = GetCloseButton(tab)->GetInsets();
398 LayoutTab(&tab); 398 LayoutTab(&tab);
399 gfx::Insets close_button_insets_2 = GetCloseButton(tab)->GetInsets(); 399 gfx::Insets close_button_insets_2 = GetCloseButton(tab)->GetInsets();
400 EXPECT_EQ(close_button_insets.top(), close_button_insets_2.top()); 400 EXPECT_EQ(close_button_insets.top(), close_button_insets_2.top());
401 EXPECT_EQ(close_button_insets.left(), close_button_insets_2.left()); 401 EXPECT_EQ(close_button_insets.left(), close_button_insets_2.left());
402 EXPECT_EQ(close_button_insets.bottom(), close_button_insets_2.bottom()); 402 EXPECT_EQ(close_button_insets.bottom(), close_button_insets_2.bottom());
403 EXPECT_EQ(close_button_insets.right(), close_button_insets_2.right()); 403 EXPECT_EQ(close_button_insets.right(), close_button_insets_2.right());
404 404
405 // Also make sure the close button is sized as large as the tab. 405 // Also make sure the close button is sized as large as the tab.
406 EXPECT_EQ(50, GetCloseButton(tab)->bounds().height()); 406 EXPECT_EQ(50, GetCloseButton(tab)->bounds().height());
407 } 407 }
408 408
409 // Tests expected changes to the ThrobberView state when the WebContents loading 409 // Tests expected changes to the ThrobberView state when the WebContents loading
410 // state changes or the animation timer (usually in BrowserView) triggers. 410 // state changes or the animation timer (usually in BrowserView) triggers.
411 TEST_F(TabTest, LayeredThrobber) { 411 TEST_F(TabTest, LayeredThrobber) {
412 Widget widget; 412 Widget widget;
413 InitWidget(&widget); 413 InitWidget(&widget);
414 414
415 FakeTabController tab_controller; 415 FakeTabController tab_controller;
416 Tab tab(&tab_controller); 416 Tab tab(&tab_controller, nullptr);
417 widget.GetContentsView()->AddChildView(&tab); 417 widget.GetContentsView()->AddChildView(&tab);
418 tab.SetBoundsRect(gfx::Rect(Tab::GetStandardSize())); 418 tab.SetBoundsRect(gfx::Rect(Tab::GetStandardSize()));
419 419
420 views::View* throbber = GetThrobberView(tab); 420 views::View* throbber = GetThrobberView(tab);
421 EXPECT_FALSE(throbber->visible()); 421 EXPECT_FALSE(throbber->visible());
422 EXPECT_EQ(TabRendererData::NETWORK_STATE_NONE, tab.data().network_state); 422 EXPECT_EQ(TabRendererData::NETWORK_STATE_NONE, tab.data().network_state);
423 EXPECT_EQ(throbber->bounds(), GetFaviconBounds(tab)); 423 EXPECT_EQ(throbber->bounds(), GetFaviconBounds(tab));
424 424
425 tab.UpdateLoadingAnimation(TabRendererData::NETWORK_STATE_NONE); 425 tab.UpdateLoadingAnimation(TabRendererData::NETWORK_STATE_NONE);
426 EXPECT_FALSE(throbber->visible()); 426 EXPECT_FALSE(throbber->visible());
(...skipping 30 matching lines...) Expand all
457 tab_controller.set_paint_throbber_to_layer(false); 457 tab_controller.set_paint_throbber_to_layer(false);
458 tab.UpdateLoadingAnimation(TabRendererData::NETWORK_STATE_WAITING); 458 tab.UpdateLoadingAnimation(TabRendererData::NETWORK_STATE_WAITING);
459 EXPECT_TRUE(throbber->visible()); 459 EXPECT_TRUE(throbber->visible());
460 EXPECT_FALSE(throbber->layer()); 460 EXPECT_FALSE(throbber->layer());
461 tab.UpdateLoadingAnimation(TabRendererData::NETWORK_STATE_NONE); 461 tab.UpdateLoadingAnimation(TabRendererData::NETWORK_STATE_NONE);
462 EXPECT_FALSE(throbber->visible()); 462 EXPECT_FALSE(throbber->visible());
463 } 463 }
464 464
465 TEST_F(TabTest, TitleHiddenWhenSmall) { 465 TEST_F(TabTest, TitleHiddenWhenSmall) {
466 FakeTabController tab_controller; 466 FakeTabController tab_controller;
467 Tab tab(&tab_controller); 467 Tab tab(&tab_controller, nullptr);
468 tab.SetBounds(0, 0, 100, 50); 468 tab.SetBounds(0, 0, 100, 50);
469 EXPECT_GT(GetTitleWidth(tab), 0); 469 EXPECT_GT(GetTitleWidth(tab), 0);
470 tab.SetBounds(0, 0, 0, 50); 470 tab.SetBounds(0, 0, 0, 50);
471 EXPECT_EQ(0, GetTitleWidth(tab)); 471 EXPECT_EQ(0, GetTitleWidth(tab));
472 } 472 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698