OLD | NEW |
---|---|
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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/mac/scoped_nsautorelease_pool.h" | 8 #include "base/mac/scoped_nsautorelease_pool.h" |
9 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 9 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
10 #include "chrome/browser/media/media_stream_capture_indicator.h" | 10 #include "chrome/browser/media/media_stream_capture_indicator.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 | 273 |
274 TEST_F(TabStripControllerTest, CorrectTitleAndToolTipTextFromSetTabTitle) { | 274 TEST_F(TabStripControllerTest, CorrectTitleAndToolTipTextFromSetTabTitle) { |
275 using content::MediaStreamDevice; | 275 using content::MediaStreamDevice; |
276 using content::MediaStreamDevices; | 276 using content::MediaStreamDevices; |
277 using content::MediaStreamUI; | 277 using content::MediaStreamUI; |
278 | 278 |
279 TabView* const tab = CreateTab(); | 279 TabView* const tab = CreateTab(); |
280 TabController* const tabController = [tab controller]; | 280 TabController* const tabController = [tab controller]; |
281 WebContents* const contents = model_->GetActiveWebContents(); | 281 WebContents* const contents = model_->GetActiveWebContents(); |
282 | 282 |
283 // For the duration of the test, assume the tab has been hovered. This adds a | |
284 // subview containing the actual source of the tooltip. | |
285 [controller_ setHoveredTab:tab]; | |
286 // Note -[NSView hitTest:] takes superview coordinates. Then, find a spot that | |
287 // is outside the mask image, but inside the tab. | |
288 NSPoint centerPoint = NSMakePoint(5, NSMidY([tab bounds])); | |
289 NSPoint hitPoint = [tab convertPoint:centerPoint | |
290 toView:[tab_strip_ superview]]; | |
291 NSView* toolTipView = [tab_strip_ hitTest:hitPoint]; | |
292 EXPECT_TRUE(toolTipView); | |
293 EXPECT_NE(toolTipView, tab); | |
294 | |
283 // Initially, tab title and tooltip text are equivalent. | 295 // Initially, tab title and tooltip text are equivalent. |
284 EXPECT_EQ(TabAlertState::NONE, | 296 EXPECT_EQ(TabAlertState::NONE, |
285 chrome::GetTabAlertStateForContents(contents)); | 297 chrome::GetTabAlertStateForContents(contents)); |
286 [controller_ setTabTitle:tabController withContents:contents]; | 298 [controller_ setTabTitle:tabController withContents:contents]; |
287 NSString* const baseTitle = [tabController title]; | 299 NSString* const baseTitle = [tabController title]; |
288 EXPECT_NSEQ(baseTitle, [tabController toolTip]); | 300 EXPECT_NSEQ(baseTitle, [tabController toolTip]); |
301 EXPECT_NSEQ([tabController toolTip], [toolTipView toolTip]); | |
289 | 302 |
290 // Simulate the start of tab video capture. Tab title remains the same, but | 303 // Simulate the start of tab video capture. Tab title remains the same, but |
291 // the tooltip text should include the following appended: 1) a line break; | 304 // the tooltip text should include the following appended: 1) a line break; |
292 // 2) a non-empty string with a localized description of the alert state. | 305 // 2) a non-empty string with a localized description of the alert state. |
293 scoped_refptr<MediaStreamCaptureIndicator> indicator = | 306 scoped_refptr<MediaStreamCaptureIndicator> indicator = |
294 MediaCaptureDevicesDispatcher::GetInstance()-> | 307 MediaCaptureDevicesDispatcher::GetInstance()-> |
295 GetMediaStreamCaptureIndicator(); | 308 GetMediaStreamCaptureIndicator(); |
296 const MediaStreamDevice dummyVideoCaptureDevice( | 309 const MediaStreamDevice dummyVideoCaptureDevice( |
297 content::MEDIA_TAB_VIDEO_CAPTURE, "dummy_id", "dummy name"); | 310 content::MEDIA_TAB_VIDEO_CAPTURE, "dummy_id", "dummy name"); |
298 scoped_ptr<MediaStreamUI> streamUi(indicator->RegisterMediaStream( | 311 scoped_ptr<MediaStreamUI> streamUi(indicator->RegisterMediaStream( |
299 contents, MediaStreamDevices(1, dummyVideoCaptureDevice))); | 312 contents, MediaStreamDevices(1, dummyVideoCaptureDevice))); |
300 streamUi->OnStarted(base::Bind(&base::DoNothing)); | 313 streamUi->OnStarted(base::Bind(&base::DoNothing)); |
301 EXPECT_EQ(TabAlertState::TAB_CAPTURING, | 314 EXPECT_EQ(TabAlertState::TAB_CAPTURING, |
302 chrome::GetTabAlertStateForContents(contents)); | 315 chrome::GetTabAlertStateForContents(contents)); |
303 [controller_ setTabTitle:tabController withContents:contents]; | 316 [controller_ setTabTitle:tabController withContents:contents]; |
304 EXPECT_NSEQ(baseTitle, [tabController title]); | 317 EXPECT_NSEQ(baseTitle, [tabController title]); |
305 NSString* const toolTipText = [tabController toolTip]; | 318 NSString* const toolTipText = [tabController toolTip]; |
319 EXPECT_NSEQ(toolTipText, [toolTipView toolTip]); | |
tapted
2016/04/01 21:50:35
Verified this fails without the fix, with
../../c
| |
306 if ([baseTitle length] > 0) { | 320 if ([baseTitle length] > 0) { |
307 EXPECT_TRUE(NSEqualRanges(NSMakeRange(0, [baseTitle length]), | 321 EXPECT_TRUE(NSEqualRanges(NSMakeRange(0, [baseTitle length]), |
308 [toolTipText rangeOfString:baseTitle])); | 322 [toolTipText rangeOfString:baseTitle])); |
309 EXPECT_TRUE(NSEqualRanges(NSMakeRange([baseTitle length], 1), | 323 EXPECT_TRUE(NSEqualRanges(NSMakeRange([baseTitle length], 1), |
310 [toolTipText rangeOfString:@"\n"])); | 324 [toolTipText rangeOfString:@"\n"])); |
311 EXPECT_LT([baseTitle length] + 1, [toolTipText length]); | 325 EXPECT_LT([baseTitle length] + 1, [toolTipText length]); |
312 } else { | 326 } else { |
313 EXPECT_LT(0u, [toolTipText length]); | 327 EXPECT_LT(0u, [toolTipText length]); |
314 } | 328 } |
315 | 329 |
316 // Simulate the end of tab video capture. Tab title and tooltip should become | 330 // Simulate the end of tab video capture. Tab title and tooltip should become |
317 // equivalent again. | 331 // equivalent again. |
318 streamUi.reset(); | 332 streamUi.reset(); |
319 EXPECT_EQ(TabAlertState::NONE, | 333 EXPECT_EQ(TabAlertState::NONE, |
320 chrome::GetTabAlertStateForContents(contents)); | 334 chrome::GetTabAlertStateForContents(contents)); |
321 [controller_ setTabTitle:tabController withContents:contents]; | 335 [controller_ setTabTitle:tabController withContents:contents]; |
322 EXPECT_NSEQ(baseTitle, [tabController title]); | 336 EXPECT_NSEQ(baseTitle, [tabController title]); |
323 EXPECT_NSEQ(baseTitle, [tabController toolTip]); | 337 EXPECT_NSEQ(baseTitle, [tabController toolTip]); |
338 EXPECT_NSEQ(baseTitle, [toolTipView toolTip]); | |
324 } | 339 } |
325 | 340 |
326 TEST_F(TabStripControllerTest, TabCloseDuringDrag) { | 341 TEST_F(TabStripControllerTest, TabCloseDuringDrag) { |
327 TabController* tab; | 342 TabController* tab; |
328 // The TabController gets autoreleased when created, but is owned by the | 343 // The TabController gets autoreleased when created, but is owned by the |
329 // tab strip model. Use a ScopedNSAutoreleasePool to get a truly weak ref | 344 // tab strip model. Use a ScopedNSAutoreleasePool to get a truly weak ref |
330 // to it to test that -maybeStartDrag:forTab: can handle that properly. | 345 // to it to test that -maybeStartDrag:forTab: can handle that properly. |
331 { | 346 { |
332 base::mac::ScopedNSAutoreleasePool pool; | 347 base::mac::ScopedNSAutoreleasePool pool; |
333 tab = [CreateTab() controller]; | 348 tab = [CreateTab() controller]; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 [tabStripControllerForTesting setAlertStateForContents:contents_at_tab0 | 476 [tabStripControllerForTesting setAlertStateForContents:contents_at_tab0 |
462 withAlertState:TabAlertState::NONE]; | 477 withAlertState:TabAlertState::NONE]; |
463 [controller_ updateWindowAlertState:TabAlertState::NONE | 478 [controller_ updateWindowAlertState:TabAlertState::NONE |
464 forWebContents:contents_at_tab0]; | 479 forWebContents:contents_at_tab0]; |
465 // Neither of tabs playing nor muting, so the window alert state should be | 480 // Neither of tabs playing nor muting, so the window alert state should be |
466 // NONE. | 481 // NONE. |
467 EXPECT_EQ(TabAlertState::NONE, [window_controller alertState]); | 482 EXPECT_EQ(TabAlertState::NONE, [window_controller alertState]); |
468 } | 483 } |
469 | 484 |
470 } // namespace | 485 } // namespace |
OLD | NEW |