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

Side by Side Diff: chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm

Issue 1827083004: UI: Rename MediaState to AlertState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-tab-indicator
Patch Set: Keep gypi ordered Created 4 years, 8 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) 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 #include <stddef.h> 6 #include <stddef.h>
7 7
8 #import "base/mac/scoped_nsobject.h" 8 #import "base/mac/scoped_nsobject.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" 12 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
13 #import "chrome/browser/ui/cocoa/tabs/media_indicator_button_cocoa.h" 13 #import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h"
14 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" 14 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h"
15 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" 15 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h"
16 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" 16 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h"
17 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" 17 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #import "testing/gtest_mac.h" 19 #import "testing/gtest_mac.h"
20 #include "testing/platform_test.h" 20 #include "testing/platform_test.h"
21 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/resources/grit/ui_resources.h" 22 #include "ui/resources/grit/ui_resources.h"
23 23
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // The dragging code in TabView makes heavy use of autorelease pools so 101 // The dragging code in TabView makes heavy use of autorelease pools so
102 // inherit from CocoaTest to have one created for us. 102 // inherit from CocoaTest to have one created for us.
103 class TabControllerTest : public CocoaTest { 103 class TabControllerTest : public CocoaTest {
104 public: 104 public:
105 TabControllerTest() { } 105 TabControllerTest() { }
106 106
107 static void CheckForExpectedLayoutAndVisibilityOfSubviews( 107 static void CheckForExpectedLayoutAndVisibilityOfSubviews(
108 const TabController* controller) { 108 const TabController* controller) {
109 // Check whether subviews should be visible when they are supposed to be, 109 // Check whether subviews should be visible when they are supposed to be,
110 // given Tab size and TabRendererData state. 110 // given Tab size and TabRendererData state.
111 const TabMediaState indicatorState = 111 const TabAlertState indicatorState =
112 [[controller mediaIndicatorButton] showingMediaState]; 112 [[controller alertIndicatorButton] showingAlertState];
113 if ([controller pinned]) { 113 if ([controller pinned]) {
114 EXPECT_EQ(1, [controller iconCapacity]); 114 EXPECT_EQ(1, [controller iconCapacity]);
115 if (indicatorState != TAB_MEDIA_STATE_NONE) { 115 if (indicatorState != TabAlertState::NONE) {
116 EXPECT_FALSE([controller shouldShowIcon]); 116 EXPECT_FALSE([controller shouldShowIcon]);
117 EXPECT_TRUE([controller shouldShowMediaIndicator]); 117 EXPECT_TRUE([controller shouldShowAlertIndicator]);
118 } else { 118 } else {
119 EXPECT_TRUE([controller shouldShowIcon]); 119 EXPECT_TRUE([controller shouldShowIcon]);
120 EXPECT_FALSE([controller shouldShowMediaIndicator]); 120 EXPECT_FALSE([controller shouldShowAlertIndicator]);
121 } 121 }
122 EXPECT_FALSE([controller shouldShowCloseButton]); 122 EXPECT_FALSE([controller shouldShowCloseButton]);
123 } else if ([controller selected]) { 123 } else if ([controller selected]) {
124 EXPECT_TRUE([controller shouldShowCloseButton]); 124 EXPECT_TRUE([controller shouldShowCloseButton]);
125 switch ([controller iconCapacity]) { 125 switch ([controller iconCapacity]) {
126 case 0: 126 case 0:
127 case 1: 127 case 1:
128 EXPECT_FALSE([controller shouldShowIcon]); 128 EXPECT_FALSE([controller shouldShowIcon]);
129 EXPECT_FALSE([controller shouldShowMediaIndicator]); 129 EXPECT_FALSE([controller shouldShowAlertIndicator]);
130 break; 130 break;
131 case 2: 131 case 2:
132 if (indicatorState != TAB_MEDIA_STATE_NONE) { 132 if (indicatorState != TabAlertState::NONE) {
133 EXPECT_FALSE([controller shouldShowIcon]); 133 EXPECT_FALSE([controller shouldShowIcon]);
134 EXPECT_TRUE([controller shouldShowMediaIndicator]); 134 EXPECT_TRUE([controller shouldShowAlertIndicator]);
135 } else { 135 } else {
136 EXPECT_TRUE([controller shouldShowIcon]); 136 EXPECT_TRUE([controller shouldShowIcon]);
137 EXPECT_FALSE([controller shouldShowMediaIndicator]); 137 EXPECT_FALSE([controller shouldShowAlertIndicator]);
138 } 138 }
139 break; 139 break;
140 default: 140 default:
141 EXPECT_LE(3, [controller iconCapacity]); 141 EXPECT_LE(3, [controller iconCapacity]);
142 EXPECT_TRUE([controller shouldShowIcon]); 142 EXPECT_TRUE([controller shouldShowIcon]);
143 if (indicatorState != TAB_MEDIA_STATE_NONE) 143 if (indicatorState != TabAlertState::NONE)
144 EXPECT_TRUE([controller shouldShowMediaIndicator]); 144 EXPECT_TRUE([controller shouldShowAlertIndicator]);
145 else 145 else
146 EXPECT_FALSE([controller shouldShowMediaIndicator]); 146 EXPECT_FALSE([controller shouldShowAlertIndicator]);
147 break; 147 break;
148 } 148 }
149 } else { // Tab not selected/active and not pinned tab. 149 } else { // Tab not selected/active and not pinned tab.
150 switch ([controller iconCapacity]) { 150 switch ([controller iconCapacity]) {
151 case 0: 151 case 0:
152 EXPECT_FALSE([controller shouldShowCloseButton]); 152 EXPECT_FALSE([controller shouldShowCloseButton]);
153 EXPECT_FALSE([controller shouldShowIcon]); 153 EXPECT_FALSE([controller shouldShowIcon]);
154 EXPECT_FALSE([controller shouldShowMediaIndicator]); 154 EXPECT_FALSE([controller shouldShowAlertIndicator]);
155 break; 155 break;
156 case 1: 156 case 1:
157 EXPECT_FALSE([controller shouldShowCloseButton]); 157 EXPECT_FALSE([controller shouldShowCloseButton]);
158 if (indicatorState != TAB_MEDIA_STATE_NONE) { 158 if (indicatorState != TabAlertState::NONE) {
159 EXPECT_FALSE([controller shouldShowIcon]); 159 EXPECT_FALSE([controller shouldShowIcon]);
160 EXPECT_TRUE([controller shouldShowMediaIndicator]); 160 EXPECT_TRUE([controller shouldShowAlertIndicator]);
161 } else { 161 } else {
162 EXPECT_TRUE([controller shouldShowIcon]); 162 EXPECT_TRUE([controller shouldShowIcon]);
163 EXPECT_FALSE([controller shouldShowMediaIndicator]); 163 EXPECT_FALSE([controller shouldShowAlertIndicator]);
164 } 164 }
165 break; 165 break;
166 default: 166 default:
167 EXPECT_LE(2, [controller iconCapacity]); 167 EXPECT_LE(2, [controller iconCapacity]);
168 EXPECT_TRUE([controller shouldShowIcon]); 168 EXPECT_TRUE([controller shouldShowIcon]);
169 if (indicatorState != TAB_MEDIA_STATE_NONE) 169 if (indicatorState != TabAlertState::NONE)
170 EXPECT_TRUE([controller shouldShowMediaIndicator]); 170 EXPECT_TRUE([controller shouldShowAlertIndicator]);
171 else 171 else
172 EXPECT_FALSE([controller shouldShowMediaIndicator]); 172 EXPECT_FALSE([controller shouldShowAlertIndicator]);
173 break; 173 break;
174 } 174 }
175 } 175 }
176 176
177 // Make sure the NSView's "isHidden" state jives with the "shouldShowXXX." 177 // Make sure the NSView's "isHidden" state jives with the "shouldShowXXX."
178 EXPECT_TRUE([controller shouldShowIcon] == 178 EXPECT_TRUE([controller shouldShowIcon] ==
179 (!![controller iconView] && ![[controller iconView] isHidden])); 179 (!![controller iconView] && ![[controller iconView] isHidden]));
180 EXPECT_TRUE([controller pinned] == [[controller tabView] titleHidden]); 180 EXPECT_TRUE([controller pinned] == [[controller tabView] titleHidden]);
181 EXPECT_TRUE([controller shouldShowMediaIndicator] == 181 EXPECT_TRUE([controller shouldShowAlertIndicator] ==
182 ![[controller mediaIndicatorButton] isHidden]); 182 ![[controller alertIndicatorButton] isHidden]);
183 EXPECT_TRUE([controller shouldShowCloseButton] != 183 EXPECT_TRUE([controller shouldShowCloseButton] !=
184 [[controller closeButton] isHidden]); 184 [[controller closeButton] isHidden]);
185 185
186 // Check positioning of elements with respect to each other, and that they 186 // Check positioning of elements with respect to each other, and that they
187 // are fully within the tab frame. 187 // are fully within the tab frame.
188 const NSRect tabFrame = [[controller view] frame]; 188 const NSRect tabFrame = [[controller view] frame];
189 const NSRect titleFrame = [[controller tabView] titleFrame]; 189 const NSRect titleFrame = [[controller tabView] titleFrame];
190 if ([controller shouldShowIcon]) { 190 if ([controller shouldShowIcon]) {
191 const NSRect iconFrame = [[controller iconView] frame]; 191 const NSRect iconFrame = [[controller iconView] frame];
192 EXPECT_LE(NSMinX(tabFrame), NSMinX(iconFrame)); 192 EXPECT_LE(NSMinX(tabFrame), NSMinX(iconFrame));
193 if (NSWidth(titleFrame) > 0) 193 if (NSWidth(titleFrame) > 0)
194 EXPECT_LE(NSMaxX(iconFrame), NSMinX(titleFrame)); 194 EXPECT_LE(NSMaxX(iconFrame), NSMinX(titleFrame));
195 EXPECT_LE(NSMinY(tabFrame), NSMinY(iconFrame)); 195 EXPECT_LE(NSMinY(tabFrame), NSMinY(iconFrame));
196 EXPECT_LE(NSMaxY(iconFrame), NSMaxY(tabFrame)); 196 EXPECT_LE(NSMaxY(iconFrame), NSMaxY(tabFrame));
197 } 197 }
198 if ([controller shouldShowIcon] && [controller shouldShowMediaIndicator]) { 198 if ([controller shouldShowIcon] && [controller shouldShowAlertIndicator]) {
199 EXPECT_LE(NSMaxX([[controller iconView] frame]), 199 EXPECT_LE(NSMaxX([[controller iconView] frame]),
200 NSMinX([[controller mediaIndicatorButton] frame])); 200 NSMinX([[controller alertIndicatorButton] frame]));
201 } 201 }
202 if ([controller shouldShowMediaIndicator]) { 202 if ([controller shouldShowAlertIndicator]) {
203 const NSRect mediaIndicatorFrame = 203 const NSRect alertIndicatorFrame =
204 [[controller mediaIndicatorButton] frame]; 204 [[controller alertIndicatorButton] frame];
205 if (NSWidth(titleFrame) > 0) 205 if (NSWidth(titleFrame) > 0)
206 EXPECT_LE(NSMaxX(titleFrame), NSMinX(mediaIndicatorFrame)); 206 EXPECT_LE(NSMaxX(titleFrame), NSMinX(alertIndicatorFrame));
207 EXPECT_LE(NSMaxX(mediaIndicatorFrame), NSMaxX(tabFrame)); 207 EXPECT_LE(NSMaxX(alertIndicatorFrame), NSMaxX(tabFrame));
208 EXPECT_LE(NSMinY(tabFrame), NSMinY(mediaIndicatorFrame)); 208 EXPECT_LE(NSMinY(tabFrame), NSMinY(alertIndicatorFrame));
209 EXPECT_LE(NSMaxY(mediaIndicatorFrame), NSMaxY(tabFrame)); 209 EXPECT_LE(NSMaxY(alertIndicatorFrame), NSMaxY(tabFrame));
210 } 210 }
211 if ([controller shouldShowMediaIndicator] && 211 if ([controller shouldShowAlertIndicator] &&
212 [controller shouldShowCloseButton]) { 212 [controller shouldShowCloseButton]) {
213 EXPECT_LE(NSMaxX([[controller mediaIndicatorButton] frame]), 213 EXPECT_LE(NSMaxX([[controller alertIndicatorButton] frame]),
214 NSMinX([[controller closeButton] frame])); 214 NSMinX([[controller closeButton] frame]));
215 } 215 }
216 if ([controller shouldShowCloseButton]) { 216 if ([controller shouldShowCloseButton]) {
217 const NSRect closeButtonFrame = [[controller closeButton] frame]; 217 const NSRect closeButtonFrame = [[controller closeButton] frame];
218 if (NSWidth(titleFrame) > 0) 218 if (NSWidth(titleFrame) > 0)
219 EXPECT_LE(NSMaxX(titleFrame), NSMinX(closeButtonFrame)); 219 EXPECT_LE(NSMaxX(titleFrame), NSMinX(closeButtonFrame));
220 EXPECT_LE(NSMaxX(closeButtonFrame), NSMaxX(tabFrame)); 220 EXPECT_LE(NSMaxX(closeButtonFrame), NSMaxX(tabFrame));
221 EXPECT_LE(NSMinY(tabFrame), NSMinY(closeButtonFrame)); 221 EXPECT_LE(NSMinY(tabFrame), NSMinY(closeButtonFrame));
222 EXPECT_LE(NSMaxY(closeButtonFrame), NSMaxY(tabFrame)); 222 EXPECT_LE(NSMaxY(closeButtonFrame), NSMaxY(tabFrame));
223 } 223 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 NSWidth([[controller tabView] titleFrame])); 467 NSWidth([[controller tabView] titleFrame]));
468 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame), 468 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame),
469 LeftMargin([[controller view] frame], 469 LeftMargin([[controller view] frame],
470 [[controller tabView] titleFrame])); 470 [[controller tabView] titleFrame]));
471 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame), 471 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame),
472 RightMargin([[controller view] frame], 472 RightMargin([[controller view] frame],
473 [[controller tabView] titleFrame])); 473 [[controller tabView] titleFrame]));
474 } 474 }
475 475
476 // A comprehensive test of the layout and visibility of all elements (favicon, 476 // A comprehensive test of the layout and visibility of all elements (favicon,
477 // throbber indicators, titile text, media indicator button, and close button) 477 // throbber indicators, titile text, alert indicator button, and close button)
478 // over all relevant combinations of tab state. This test overlaps with parts 478 // over all relevant combinations of tab state. This test overlaps with parts
479 // of the other tests above. 479 // of the other tests above.
480 // Flaky: https://code.google.com/p/chromium/issues/detail?id=311668 480 // Flaky: https://code.google.com/p/chromium/issues/detail?id=311668
481 TEST_F(TabControllerTest, DISABLED_LayoutAndVisibilityOfSubviews) { 481 TEST_F(TabControllerTest, DISABLED_LayoutAndVisibilityOfSubviews) {
482 static const TabMediaState kMediaStatesToTest[] = { 482 static const TabAlertState kAlertStatesToTest[] = {
483 TAB_MEDIA_STATE_NONE, TAB_MEDIA_STATE_CAPTURING, 483 TabAlertState::NONE, TabAlertState::TAB_CAPTURING,
484 TAB_MEDIA_STATE_AUDIO_PLAYING, TAB_MEDIA_STATE_AUDIO_MUTING 484 TabAlertState::AUDIO_PLAYING, TabAlertState::AUDIO_MUTING
485 }; 485 };
486 486
487 NSWindow* const window = test_window(); 487 NSWindow* const window = test_window();
488 488
489 // Create TabController instance and place its view into the test window. 489 // Create TabController instance and place its view into the test window.
490 base::scoped_nsobject<TabController> controller([[TabController alloc] init]); 490 base::scoped_nsobject<TabController> controller([[TabController alloc] init]);
491 [[window contentView] addSubview:[controller view]]; 491 [[window contentView] addSubview:[controller view]];
492 492
493 // Create favicon. 493 // Create favicon.
494 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 494 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
495 base::scoped_nsobject<NSImage> favicon( 495 base::scoped_nsobject<NSImage> favicon(
496 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage()); 496 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage());
497 497
498 // Trigger TabController to auto-create the MediaIndicatorButton. 498 // Trigger TabController to auto-create the AlertIndicatorButton.
499 [controller setMediaState:TAB_MEDIA_STATE_AUDIO_PLAYING]; 499 [controller setAlertState:TabAlertState::AUDIO_PLAYING];
500 [controller setMediaState:TAB_MEDIA_STATE_NONE]; 500 [controller setAlertState:TabAlertState::NONE];
501 base::scoped_nsobject<MediaIndicatorButton> mediaIndicatorButton( 501 base::scoped_nsobject<AlertIndicatorButton> alertIndicatorButton(
502 [[controller mediaIndicatorButton] retain]); 502 [[controller alertIndicatorButton] retain]);
503 ASSERT_TRUE(mediaIndicatorButton.get()); 503 ASSERT_TRUE(alertIndicatorButton.get());
504 504
505 // Perform layout over all possible combinations, checking for correct 505 // Perform layout over all possible combinations, checking for correct
506 // results. 506 // results.
507 for (int isPinnedTab = 0; isPinnedTab < 2; ++isPinnedTab) { 507 for (int isPinnedTab = 0; isPinnedTab < 2; ++isPinnedTab) {
508 for (int isActiveTab = 0; isActiveTab < 2; ++isActiveTab) { 508 for (int isActiveTab = 0; isActiveTab < 2; ++isActiveTab) {
509 for (size_t mediaStateIndex = 0; 509 for (size_t alertStateIndex = 0;
510 mediaStateIndex < arraysize(kMediaStatesToTest); 510 alertStateIndex < arraysize(kAlertStatesToTest);
511 ++mediaStateIndex) { 511 ++alertStateIndex) {
512 const TabMediaState mediaState = kMediaStatesToTest[mediaStateIndex]; 512 const TabAlertState alertState = kAlertStatesToTest[alertStateIndex];
513 SCOPED_TRACE(::testing::Message() 513 SCOPED_TRACE(::testing::Message()
514 << (isActiveTab ? "Active" : "Inactive") << ' ' 514 << (isActiveTab ? "Active" : "Inactive") << ' '
515 << (isPinnedTab ? "Pinned " : "") 515 << (isPinnedTab ? "Pinned " : "")
516 << "Tab with media indicator state " << mediaState); 516 << "Tab with alert indicator state "
517 << static_cast<uint8_t>(alertState));
517 518
518 // Simulate what tab_strip_controller would do to set up the 519 // Simulate what tab_strip_controller would do to set up the
519 // TabController state. 520 // TabController state.
520 [controller setPinned:(isPinnedTab ? YES : NO)]; 521 [controller setPinned:(isPinnedTab ? YES : NO)];
521 [controller setActive:(isActiveTab ? YES : NO)]; 522 [controller setActive:(isActiveTab ? YES : NO)];
522 [controller setIconImage:favicon]; 523 [controller setIconImage:favicon];
523 [controller setMediaState:mediaState]; 524 [controller setAlertState:alertState];
524 [controller updateVisibility]; 525 [controller updateVisibility];
525 526
526 // Test layout for every width from maximum to minimum. 527 // Test layout for every width from maximum to minimum.
527 NSRect tabFrame = [[controller view] frame]; 528 NSRect tabFrame = [[controller view] frame];
528 int minWidth; 529 int minWidth;
529 if (isPinnedTab) { 530 if (isPinnedTab) {
530 tabFrame.size.width = minWidth = [TabController pinnedTabWidth]; 531 tabFrame.size.width = minWidth = [TabController pinnedTabWidth];
531 } else { 532 } else {
532 tabFrame.size.width = [TabController maxTabWidth]; 533 tabFrame.size.width = [TabController maxTabWidth];
533 minWidth = isActiveTab ? [TabController minActiveTabWidth] : 534 minWidth = isActiveTab ? [TabController minActiveTabWidth] :
534 [TabController minTabWidth]; 535 [TabController minTabWidth];
535 } 536 }
536 while (NSWidth(tabFrame) >= minWidth) { 537 while (NSWidth(tabFrame) >= minWidth) {
537 SCOPED_TRACE(::testing::Message() << "width=" << tabFrame.size.width); 538 SCOPED_TRACE(::testing::Message() << "width=" << tabFrame.size.width);
538 [[controller view] setFrame:tabFrame]; 539 [[controller view] setFrame:tabFrame];
539 CheckForExpectedLayoutAndVisibilityOfSubviews(controller); 540 CheckForExpectedLayoutAndVisibilityOfSubviews(controller);
540 --tabFrame.size.width; 541 --tabFrame.size.width;
541 } 542 }
542 } 543 }
543 } 544 }
544 } 545 }
545 } 546 }
546 547
547 } // namespace 548 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_controller.mm ('k') | chrome/browser/ui/cocoa/tabs/tab_strip_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698