| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" | 7 #import "base/mac/scoped_nsobject.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 9 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 10 #import "chrome/browser/ui/cocoa/tabs/media_indicator_view.h" | 10 #import "chrome/browser/ui/cocoa/tabs/media_indicator_button.h" |
| 11 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 11 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" | 12 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" |
| 13 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" | 13 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 14 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #import "testing/gtest_mac.h" | 16 #import "testing/gtest_mac.h" |
| 17 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/resources/grit/ui_resources.h" | 19 #include "ui/resources/grit/ui_resources.h" |
| 20 | 20 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // inherit from CocoaTest to have one created for us. | 99 // inherit from CocoaTest to have one created for us. |
| 100 class TabControllerTest : public CocoaTest { | 100 class TabControllerTest : public CocoaTest { |
| 101 public: | 101 public: |
| 102 TabControllerTest() { } | 102 TabControllerTest() { } |
| 103 | 103 |
| 104 static void CheckForExpectedLayoutAndVisibilityOfSubviews( | 104 static void CheckForExpectedLayoutAndVisibilityOfSubviews( |
| 105 const TabController* controller) { | 105 const TabController* controller) { |
| 106 // Check whether subviews should be visible when they are supposed to be, | 106 // Check whether subviews should be visible when they are supposed to be, |
| 107 // given Tab size and TabRendererData state. | 107 // given Tab size and TabRendererData state. |
| 108 const TabMediaState indicatorState = | 108 const TabMediaState indicatorState = |
| 109 [[controller mediaIndicatorView] mediaState]; | 109 [[controller mediaIndicatorButton] showingMediaState]; |
| 110 if ([controller mini]) { | 110 if ([controller mini]) { |
| 111 EXPECT_EQ(1, [controller iconCapacity]); | 111 EXPECT_EQ(1, [controller iconCapacity]); |
| 112 if (indicatorState != TAB_MEDIA_STATE_NONE) { | 112 if (indicatorState != TAB_MEDIA_STATE_NONE) { |
| 113 EXPECT_FALSE([controller shouldShowIcon]); | 113 EXPECT_FALSE([controller shouldShowIcon]); |
| 114 EXPECT_TRUE([controller shouldShowMediaIndicator]); | 114 EXPECT_TRUE([controller shouldShowMediaIndicator]); |
| 115 } else { | 115 } else { |
| 116 EXPECT_TRUE([controller shouldShowIcon]); | 116 EXPECT_TRUE([controller shouldShowIcon]); |
| 117 EXPECT_FALSE([controller shouldShowMediaIndicator]); | 117 EXPECT_FALSE([controller shouldShowMediaIndicator]); |
| 118 } | 118 } |
| 119 EXPECT_FALSE([controller shouldShowCloseButton]); | 119 EXPECT_FALSE([controller shouldShowCloseButton]); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 EXPECT_FALSE([controller shouldShowMediaIndicator]); | 169 EXPECT_FALSE([controller shouldShowMediaIndicator]); |
| 170 break; | 170 break; |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 // Make sure the NSView's "isHidden" state jives with the "shouldShowXXX." | 174 // Make sure the NSView's "isHidden" state jives with the "shouldShowXXX." |
| 175 EXPECT_TRUE([controller shouldShowIcon] == | 175 EXPECT_TRUE([controller shouldShowIcon] == |
| 176 (!![controller iconView] && ![[controller iconView] isHidden])); | 176 (!![controller iconView] && ![[controller iconView] isHidden])); |
| 177 EXPECT_TRUE([controller mini] == [[controller tabView] titleHidden]); | 177 EXPECT_TRUE([controller mini] == [[controller tabView] titleHidden]); |
| 178 EXPECT_TRUE([controller shouldShowMediaIndicator] == | 178 EXPECT_TRUE([controller shouldShowMediaIndicator] == |
| 179 ![[controller mediaIndicatorView] isHidden]); | 179 ![[controller mediaIndicatorButton] isHidden]); |
| 180 EXPECT_TRUE([controller shouldShowCloseButton] != | 180 EXPECT_TRUE([controller shouldShowCloseButton] != |
| 181 [[controller closeButton] isHidden]); | 181 [[controller closeButton] isHidden]); |
| 182 | 182 |
| 183 // Check positioning of elements with respect to each other, and that they | 183 // Check positioning of elements with respect to each other, and that they |
| 184 // are fully within the tab frame. | 184 // are fully within the tab frame. |
| 185 const NSRect tabFrame = [[controller view] frame]; | 185 const NSRect tabFrame = [[controller view] frame]; |
| 186 const NSRect titleFrame = [[controller tabView] titleFrame]; | 186 const NSRect titleFrame = [[controller tabView] titleFrame]; |
| 187 if ([controller shouldShowIcon]) { | 187 if ([controller shouldShowIcon]) { |
| 188 const NSRect iconFrame = [[controller iconView] frame]; | 188 const NSRect iconFrame = [[controller iconView] frame]; |
| 189 EXPECT_LE(NSMinX(tabFrame), NSMinX(iconFrame)); | 189 EXPECT_LE(NSMinX(tabFrame), NSMinX(iconFrame)); |
| 190 if (NSWidth(titleFrame) > 0) | 190 if (NSWidth(titleFrame) > 0) |
| 191 EXPECT_LE(NSMaxX(iconFrame), NSMinX(titleFrame)); | 191 EXPECT_LE(NSMaxX(iconFrame), NSMinX(titleFrame)); |
| 192 EXPECT_LE(NSMinY(tabFrame), NSMinY(iconFrame)); | 192 EXPECT_LE(NSMinY(tabFrame), NSMinY(iconFrame)); |
| 193 EXPECT_LE(NSMaxY(iconFrame), NSMaxY(tabFrame)); | 193 EXPECT_LE(NSMaxY(iconFrame), NSMaxY(tabFrame)); |
| 194 } | 194 } |
| 195 if ([controller shouldShowIcon] && [controller shouldShowMediaIndicator]) { | 195 if ([controller shouldShowIcon] && [controller shouldShowMediaIndicator]) { |
| 196 EXPECT_LE(NSMaxX([[controller iconView] frame]), | 196 EXPECT_LE(NSMaxX([[controller iconView] frame]), |
| 197 NSMinX([[controller mediaIndicatorView] frame])); | 197 NSMinX([[controller mediaIndicatorButton] frame])); |
| 198 } | 198 } |
| 199 if ([controller shouldShowMediaIndicator]) { | 199 if ([controller shouldShowMediaIndicator]) { |
| 200 const NSRect mediaIndicatorFrame = | 200 const NSRect mediaIndicatorFrame = |
| 201 [[controller mediaIndicatorView] frame]; | 201 [[controller mediaIndicatorButton] frame]; |
| 202 if (NSWidth(titleFrame) > 0) | 202 if (NSWidth(titleFrame) > 0) |
| 203 EXPECT_LE(NSMaxX(titleFrame), NSMinX(mediaIndicatorFrame)); | 203 EXPECT_LE(NSMaxX(titleFrame), NSMinX(mediaIndicatorFrame)); |
| 204 EXPECT_LE(NSMaxX(mediaIndicatorFrame), NSMaxX(tabFrame)); | 204 EXPECT_LE(NSMaxX(mediaIndicatorFrame), NSMaxX(tabFrame)); |
| 205 EXPECT_LE(NSMinY(tabFrame), NSMinY(mediaIndicatorFrame)); | 205 EXPECT_LE(NSMinY(tabFrame), NSMinY(mediaIndicatorFrame)); |
| 206 EXPECT_LE(NSMaxY(mediaIndicatorFrame), NSMaxY(tabFrame)); | 206 EXPECT_LE(NSMaxY(mediaIndicatorFrame), NSMaxY(tabFrame)); |
| 207 } | 207 } |
| 208 if ([controller shouldShowMediaIndicator] && | 208 if ([controller shouldShowMediaIndicator] && |
| 209 [controller shouldShowCloseButton]) { | 209 [controller shouldShowCloseButton]) { |
| 210 EXPECT_LE(NSMaxX([[controller mediaIndicatorView] frame]), | 210 EXPECT_LE(NSMaxX([[controller mediaIndicatorButton] frame]), |
| 211 NSMinX([[controller closeButton] frame])); | 211 NSMinX([[controller closeButton] frame])); |
| 212 } | 212 } |
| 213 if ([controller shouldShowCloseButton]) { | 213 if ([controller shouldShowCloseButton]) { |
| 214 const NSRect closeButtonFrame = [[controller closeButton] frame]; | 214 const NSRect closeButtonFrame = [[controller closeButton] frame]; |
| 215 if (NSWidth(titleFrame) > 0) | 215 if (NSWidth(titleFrame) > 0) |
| 216 EXPECT_LE(NSMaxX(titleFrame), NSMinX(closeButtonFrame)); | 216 EXPECT_LE(NSMaxX(titleFrame), NSMinX(closeButtonFrame)); |
| 217 EXPECT_LE(NSMaxX(closeButtonFrame), NSMaxX(tabFrame)); | 217 EXPECT_LE(NSMaxX(closeButtonFrame), NSMaxX(tabFrame)); |
| 218 EXPECT_LE(NSMinY(tabFrame), NSMinY(closeButtonFrame)); | 218 EXPECT_LE(NSMinY(tabFrame), NSMinY(closeButtonFrame)); |
| 219 EXPECT_LE(NSMaxY(closeButtonFrame), NSMaxY(tabFrame)); | 219 EXPECT_LE(NSMaxY(closeButtonFrame), NSMaxY(tabFrame)); |
| 220 } | 220 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 NSWidth([[controller tabView] titleFrame])); | 461 NSWidth([[controller tabView] titleFrame])); |
| 462 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame), | 462 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame), |
| 463 LeftMargin([[controller view] frame], | 463 LeftMargin([[controller view] frame], |
| 464 [[controller tabView] titleFrame])); | 464 [[controller tabView] titleFrame])); |
| 465 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame), | 465 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame), |
| 466 RightMargin([[controller view] frame], | 466 RightMargin([[controller view] frame], |
| 467 [[controller tabView] titleFrame])); | 467 [[controller tabView] titleFrame])); |
| 468 } | 468 } |
| 469 | 469 |
| 470 // A comprehensive test of the layout and visibility of all elements (favicon, | 470 // A comprehensive test of the layout and visibility of all elements (favicon, |
| 471 // throbber indicators, titile text, audio indicator, and close button) over all | 471 // throbber indicators, titile text, media indicator button, and close button) |
| 472 // relevant combinations of tab state. This test overlaps with parts of the | 472 // over all relevant combinations of tab state. This test overlaps with parts |
| 473 // other tests above. | 473 // of the other tests above. |
| 474 // Flaky: https://code.google.com/p/chromium/issues/detail?id=311668 | 474 // Flaky: https://code.google.com/p/chromium/issues/detail?id=311668 |
| 475 TEST_F(TabControllerTest, DISABLED_LayoutAndVisibilityOfSubviews) { | 475 TEST_F(TabControllerTest, DISABLED_LayoutAndVisibilityOfSubviews) { |
| 476 static const TabMediaState kMediaStatesToTest[] = { | 476 static const TabMediaState kMediaStatesToTest[] = { |
| 477 TAB_MEDIA_STATE_NONE, TAB_MEDIA_STATE_CAPTURING, | 477 TAB_MEDIA_STATE_NONE, TAB_MEDIA_STATE_CAPTURING, |
| 478 TAB_MEDIA_STATE_AUDIO_PLAYING | 478 TAB_MEDIA_STATE_AUDIO_PLAYING, TAB_MEDIA_STATE_AUDIO_MUTING |
| 479 }; | 479 }; |
| 480 | 480 |
| 481 NSWindow* const window = test_window(); | 481 NSWindow* const window = test_window(); |
| 482 | 482 |
| 483 // Create TabController instance and place its view into the test window. | 483 // Create TabController instance and place its view into the test window. |
| 484 base::scoped_nsobject<TabController> controller([[TabController alloc] init]); | 484 base::scoped_nsobject<TabController> controller([[TabController alloc] init]); |
| 485 [[window contentView] addSubview:[controller view]]; | 485 [[window contentView] addSubview:[controller view]]; |
| 486 | 486 |
| 487 // Create favicon and media indicator views. Disable animation in the media | 487 // Create favicon and media indicator button. |
| 488 // indicator view so that TabController's "what should be shown" logic can be | |
| 489 // tested effectively. If animations were left enabled, the | |
| 490 // shouldShowMediaIndicator method would return true during fade-out | |
| 491 // transitions. | |
| 492 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 488 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 493 base::scoped_nsobject<NSImage> favicon( | 489 base::scoped_nsobject<NSImage> favicon( |
| 494 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage()); | 490 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage()); |
| 495 base::scoped_nsobject<MediaIndicatorView> mediaIndicatorView( | 491 base::scoped_nsobject<MediaIndicatorButton> mediaIndicatorButton( |
| 496 [[MediaIndicatorView alloc] init]); | 492 [[controller mediaIndicatorButton] retain]); |
| 497 [mediaIndicatorView disableAnimations]; | 493 ASSERT_TRUE(mediaIndicatorButton.get()); |
| 498 [controller setMediaIndicatorView:mediaIndicatorView]; | |
| 499 | 494 |
| 500 // Perform layout over all possible combinations, checking for correct | 495 // Perform layout over all possible combinations, checking for correct |
| 501 // results. | 496 // results. |
| 502 for (int isMiniTab = 0; isMiniTab < 2; ++isMiniTab) { | 497 for (int isMiniTab = 0; isMiniTab < 2; ++isMiniTab) { |
| 503 for (int isActiveTab = 0; isActiveTab < 2; ++isActiveTab) { | 498 for (int isActiveTab = 0; isActiveTab < 2; ++isActiveTab) { |
| 504 for (size_t mediaStateIndex = 0; | 499 for (size_t mediaStateIndex = 0; |
| 505 mediaStateIndex < arraysize(kMediaStatesToTest); | 500 mediaStateIndex < arraysize(kMediaStatesToTest); |
| 506 ++mediaStateIndex) { | 501 ++mediaStateIndex) { |
| 507 const TabMediaState mediaState = kMediaStatesToTest[mediaStateIndex]; | 502 const TabMediaState mediaState = kMediaStatesToTest[mediaStateIndex]; |
| 508 SCOPED_TRACE(::testing::Message() | 503 SCOPED_TRACE(::testing::Message() |
| 509 << (isActiveTab ? "Active" : "Inactive") << ' ' | 504 << (isActiveTab ? "Active" : "Inactive") << ' ' |
| 510 << (isMiniTab ? "Mini " : "") | 505 << (isMiniTab ? "Mini " : "") |
| 511 << "Tab with media indicator state " << mediaState); | 506 << "Tab with media indicator state " << mediaState); |
| 512 | 507 |
| 513 // Simulate what tab_strip_controller would do to set up the | 508 // Simulate what tab_strip_controller would do to set up the |
| 514 // TabController state. | 509 // TabController state. |
| 515 [controller setMini:(isMiniTab ? YES : NO)]; | 510 [controller setMini:(isMiniTab ? YES : NO)]; |
| 516 [controller setActive:(isActiveTab ? YES : NO)]; | 511 [controller setActive:(isActiveTab ? YES : NO)]; |
| 517 [[controller mediaIndicatorView] updateIndicator:mediaState]; | 512 [[controller mediaIndicatorButton] transitionToMediaState:mediaState]; |
| 518 [controller setIconImage:favicon]; | 513 [controller setIconImage:favicon]; |
| 514 [controller updateVisibility]; |
| 519 | 515 |
| 520 // Test layout for every width from maximum to minimum. | 516 // Test layout for every width from maximum to minimum. |
| 521 NSRect tabFrame = [[controller view] frame]; | 517 NSRect tabFrame = [[controller view] frame]; |
| 522 int minWidth; | 518 int minWidth; |
| 523 if (isMiniTab) { | 519 if (isMiniTab) { |
| 524 tabFrame.size.width = minWidth = [TabController miniTabWidth]; | 520 tabFrame.size.width = minWidth = [TabController miniTabWidth]; |
| 525 } else { | 521 } else { |
| 526 tabFrame.size.width = [TabController maxTabWidth]; | 522 tabFrame.size.width = [TabController maxTabWidth]; |
| 527 minWidth = isActiveTab ? [TabController minActiveTabWidth] : | 523 minWidth = isActiveTab ? [TabController minActiveTabWidth] : |
| 528 [TabController minTabWidth]; | 524 [TabController minTabWidth]; |
| 529 } | 525 } |
| 530 while (NSWidth(tabFrame) >= minWidth) { | 526 while (NSWidth(tabFrame) >= minWidth) { |
| 531 SCOPED_TRACE(::testing::Message() << "width=" << tabFrame.size.width); | 527 SCOPED_TRACE(::testing::Message() << "width=" << tabFrame.size.width); |
| 532 [[controller view] setFrame:tabFrame]; | 528 [[controller view] setFrame:tabFrame]; |
| 533 CheckForExpectedLayoutAndVisibilityOfSubviews(controller); | 529 CheckForExpectedLayoutAndVisibilityOfSubviews(controller); |
| 534 --tabFrame.size.width; | 530 --tabFrame.size.width; |
| 535 } | 531 } |
| 536 } | 532 } |
| 537 } | 533 } |
| 538 } | 534 } |
| 539 } | 535 } |
| 540 | 536 |
| 541 } // namespace | 537 } // namespace |
| OLD | NEW |