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 12 matching lines...) Expand all Loading... |
23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
24 #include "content/public/common/media_stream_request.h" | 24 #include "content/public/common/media_stream_request.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #import "testing/gtest_mac.h" | 26 #import "testing/gtest_mac.h" |
27 #include "testing/platform_test.h" | 27 #include "testing/platform_test.h" |
28 #include "ui/events/test/cocoa_test_event_utils.h" | 28 #include "ui/events/test/cocoa_test_event_utils.h" |
29 | 29 |
30 using content::SiteInstance; | 30 using content::SiteInstance; |
31 using content::WebContents; | 31 using content::WebContents; |
32 | 32 |
33 @interface TabStripControllerForMediaTesting : TabStripController { | 33 @interface TabStripControllerForAlertTesting : TabStripController { |
34 // Keeps media state of tabs in browser for testing purpose. | 34 // Keeps alert state of tabs in browser for testing purpose. |
35 std::map<content::WebContents*, TabMediaState> contentsMediaStateMaps_; | 35 std::map<content::WebContents*, TabAlertState> contentsAlertStateMaps_; |
36 } | 36 } |
37 @end | 37 @end |
38 | 38 |
39 @implementation TabStripControllerForMediaTesting | 39 @implementation TabStripControllerForAlertTesting |
40 // Returns the media state of each tab from the map we are keeping. | 40 // Returns the alert state of each tab from the map we are keeping. |
41 - (TabMediaState)mediaStateForContents:(content::WebContents*)contents { | 41 - (TabAlertState)alertStateForContents:(content::WebContents*)contents { |
42 return contentsMediaStateMaps_[contents]; | 42 return contentsAlertStateMaps_[contents]; |
43 } | 43 } |
44 | 44 |
45 - (void)setMediaStateForContents:(content::WebContents*)contents | 45 - (void)setAlertStateForContents:(content::WebContents*)contents |
46 withMediaState:(TabMediaState)media_state { | 46 withAlertState:(TabAlertState)alert_state { |
47 contentsMediaStateMaps_[contents] = media_state; | 47 contentsAlertStateMaps_[contents] = alert_state; |
48 } | 48 } |
49 | 49 |
50 @end | 50 @end |
51 | 51 |
52 @interface TestTabStripControllerDelegate | 52 @interface TestTabStripControllerDelegate |
53 : NSObject<TabStripControllerDelegate> { | 53 : NSObject<TabStripControllerDelegate> { |
54 } | 54 } |
55 @end | 55 @end |
56 | 56 |
57 @implementation TestTabStripControllerDelegate | 57 @implementation TestTabStripControllerDelegate |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 void TearDown() override { | 151 void TearDown() override { |
152 // The call to CocoaTest::TearDown() deletes the Browser and TabStripModel | 152 // The call to CocoaTest::TearDown() deletes the Browser and TabStripModel |
153 // objects, so we first have to delete the controller, which refers to them. | 153 // objects, so we first have to delete the controller, which refers to them. |
154 controller_.reset(); | 154 controller_.reset(); |
155 model_ = NULL; | 155 model_ = NULL; |
156 CocoaProfileTest::TearDown(); | 156 CocoaProfileTest::TearDown(); |
157 } | 157 } |
158 | 158 |
159 // Return a derived TabStripController. | 159 // Return a derived TabStripController. |
160 TabStripControllerForMediaTesting* InitTabStripControllerForMediaTesting() { | 160 TabStripControllerForAlertTesting* InitTabStripControllerForAlertTesting() { |
161 TabStripControllerForMediaTesting* c = | 161 TabStripControllerForAlertTesting* c = |
162 [[TabStripControllerForMediaTesting alloc] | 162 [[TabStripControllerForAlertTesting alloc] |
163 initWithView:static_cast<TabStripView*>(tab_strip_.get()) | 163 initWithView:static_cast<TabStripView*>(tab_strip_.get()) |
164 switchView:switch_view_.get() | 164 switchView:switch_view_.get() |
165 browser:browser() | 165 browser:browser() |
166 delegate:controller_delegate_.get()]; | 166 delegate:controller_delegate_.get()]; |
167 return c; | 167 return c; |
168 } | 168 } |
169 | 169 |
170 TabView* CreateTab() { | 170 TabView* CreateTab() { |
171 SiteInstance* instance = SiteInstance::Create(profile()); | 171 SiteInstance* instance = SiteInstance::Create(profile()); |
172 WebContents* web_contents = WebContents::Create( | 172 WebContents* web_contents = WebContents::Create( |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Initially, tab title and tooltip text are equivalent. | 283 // Initially, tab title and tooltip text are equivalent. |
284 EXPECT_EQ(TAB_MEDIA_STATE_NONE, | 284 EXPECT_EQ(TabAlertState::NONE, |
285 chrome::GetTabMediaStateForContents(contents)); | 285 chrome::GetTabAlertStateForContents(contents)); |
286 [controller_ setTabTitle:tabController withContents:contents]; | 286 [controller_ setTabTitle:tabController withContents:contents]; |
287 NSString* const baseTitle = [tabController title]; | 287 NSString* const baseTitle = [tabController title]; |
288 EXPECT_NSEQ(baseTitle, [tabController toolTip]); | 288 EXPECT_NSEQ(baseTitle, [tabController toolTip]); |
289 | 289 |
290 // Simulate the start of tab video capture. Tab title remains the same, but | 290 // 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; | 291 // the tooltip text should include the following appended: 1) a line break; |
292 // 2) a non-empty string with a localized description of the media state. | 292 // 2) a non-empty string with a localized description of the alert state. |
293 scoped_refptr<MediaStreamCaptureIndicator> indicator = | 293 scoped_refptr<MediaStreamCaptureIndicator> indicator = |
294 MediaCaptureDevicesDispatcher::GetInstance()-> | 294 MediaCaptureDevicesDispatcher::GetInstance()-> |
295 GetMediaStreamCaptureIndicator(); | 295 GetMediaStreamCaptureIndicator(); |
296 const MediaStreamDevice dummyVideoCaptureDevice( | 296 const MediaStreamDevice dummyVideoCaptureDevice( |
297 content::MEDIA_TAB_VIDEO_CAPTURE, "dummy_id", "dummy name"); | 297 content::MEDIA_TAB_VIDEO_CAPTURE, "dummy_id", "dummy name"); |
298 scoped_ptr<MediaStreamUI> streamUi(indicator->RegisterMediaStream( | 298 scoped_ptr<MediaStreamUI> streamUi(indicator->RegisterMediaStream( |
299 contents, MediaStreamDevices(1, dummyVideoCaptureDevice))); | 299 contents, MediaStreamDevices(1, dummyVideoCaptureDevice))); |
300 streamUi->OnStarted(base::Bind(&base::DoNothing)); | 300 streamUi->OnStarted(base::Bind(&base::DoNothing)); |
301 EXPECT_EQ(TAB_MEDIA_STATE_CAPTURING, | 301 EXPECT_EQ(TabAlertState::TAB_CAPTURING, |
302 chrome::GetTabMediaStateForContents(contents)); | 302 chrome::GetTabAlertStateForContents(contents)); |
303 [controller_ setTabTitle:tabController withContents:contents]; | 303 [controller_ setTabTitle:tabController withContents:contents]; |
304 EXPECT_NSEQ(baseTitle, [tabController title]); | 304 EXPECT_NSEQ(baseTitle, [tabController title]); |
305 NSString* const toolTipText = [tabController toolTip]; | 305 NSString* const toolTipText = [tabController toolTip]; |
306 if ([baseTitle length] > 0) { | 306 if ([baseTitle length] > 0) { |
307 EXPECT_TRUE(NSEqualRanges(NSMakeRange(0, [baseTitle length]), | 307 EXPECT_TRUE(NSEqualRanges(NSMakeRange(0, [baseTitle length]), |
308 [toolTipText rangeOfString:baseTitle])); | 308 [toolTipText rangeOfString:baseTitle])); |
309 EXPECT_TRUE(NSEqualRanges(NSMakeRange([baseTitle length], 1), | 309 EXPECT_TRUE(NSEqualRanges(NSMakeRange([baseTitle length], 1), |
310 [toolTipText rangeOfString:@"\n"])); | 310 [toolTipText rangeOfString:@"\n"])); |
311 EXPECT_LT([baseTitle length] + 1, [toolTipText length]); | 311 EXPECT_LT([baseTitle length] + 1, [toolTipText length]); |
312 } else { | 312 } else { |
313 EXPECT_LT(0u, [toolTipText length]); | 313 EXPECT_LT(0u, [toolTipText length]); |
314 } | 314 } |
315 | 315 |
316 // Simulate the end of tab video capture. Tab title and tooltip should become | 316 // Simulate the end of tab video capture. Tab title and tooltip should become |
317 // equivalent again. | 317 // equivalent again. |
318 streamUi.reset(); | 318 streamUi.reset(); |
319 EXPECT_EQ(TAB_MEDIA_STATE_NONE, | 319 EXPECT_EQ(TabAlertState::NONE, |
320 chrome::GetTabMediaStateForContents(contents)); | 320 chrome::GetTabAlertStateForContents(contents)); |
321 [controller_ setTabTitle:tabController withContents:contents]; | 321 [controller_ setTabTitle:tabController withContents:contents]; |
322 EXPECT_NSEQ(baseTitle, [tabController title]); | 322 EXPECT_NSEQ(baseTitle, [tabController title]); |
323 EXPECT_NSEQ(baseTitle, [tabController toolTip]); | 323 EXPECT_NSEQ(baseTitle, [tabController toolTip]); |
324 } | 324 } |
325 | 325 |
326 TEST_F(TabStripControllerTest, TabCloseDuringDrag) { | 326 TEST_F(TabStripControllerTest, TabCloseDuringDrag) { |
327 TabController* tab; | 327 TabController* tab; |
328 // The TabController gets autoreleased when created, but is owned by the | 328 // The TabController gets autoreleased when created, but is owned by the |
329 // tab strip model. Use a ScopedNSAutoreleasePool to get a truly weak ref | 329 // tab strip model. Use a ScopedNSAutoreleasePool to get a truly weak ref |
330 // to it to test that -maybeStartDrag:forTab: can handle that properly. | 330 // to it to test that -maybeStartDrag:forTab: can handle that properly. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 EXPECT_EQ(tab2, value); | 375 EXPECT_EQ(tab2, value); |
376 | 376 |
377 model_->ActivateTabAt(0, false); | 377 model_->ActivateTabAt(0, false); |
378 EXPECT_TRUE([tab1 controller].selected); | 378 EXPECT_TRUE([tab1 controller].selected); |
379 EXPECT_FALSE([tab2 controller].selected); | 379 EXPECT_FALSE([tab2 controller].selected); |
380 value = | 380 value = |
381 [tab_strip_ accessibilityAttributeValue:NSAccessibilityValueAttribute]; | 381 [tab_strip_ accessibilityAttributeValue:NSAccessibilityValueAttribute]; |
382 EXPECT_EQ(tab1, value); | 382 EXPECT_EQ(tab1, value); |
383 } | 383 } |
384 | 384 |
385 TEST_F(TabStripControllerTest, CorrectWindowFromUpdateWindowMediaState) { | 385 TEST_F(TabStripControllerTest, CorrectWindowFromUpdateWindowAlertState) { |
386 controller_.reset(InitTabStripControllerForMediaTesting()); | 386 controller_.reset(InitTabStripControllerForAlertTesting()); |
387 NSWindow* window = [tab_strip_ window]; | 387 NSWindow* window = [tab_strip_ window]; |
388 BrowserWindowController* window_controller = | 388 BrowserWindowController* window_controller = |
389 [BrowserWindowController browserWindowControllerForWindow:window]; | 389 [BrowserWindowController browserWindowControllerForWindow:window]; |
390 TabStripControllerForMediaTesting* tabStripControllerForTesting = | 390 TabStripControllerForAlertTesting* tabStripControllerForTesting = |
391 static_cast<TabStripControllerForMediaTesting*>(controller_); | 391 static_cast<TabStripControllerForAlertTesting*>(controller_); |
392 | 392 |
393 TabView* const tab1 = CreateTab(); | 393 TabView* const tab1 = CreateTab(); |
394 TabView* const tab2 = CreateTab(); | 394 TabView* const tab2 = CreateTab(); |
395 | 395 |
396 // tab2 should be the selected one. | 396 // tab2 should be the selected one. |
397 EXPECT_FALSE([tab1 controller].selected); | 397 EXPECT_FALSE([tab1 controller].selected); |
398 EXPECT_TRUE([tab2 controller].selected); | 398 EXPECT_TRUE([tab2 controller].selected); |
399 WebContents* const contents_at_tab1 = model_->GetActiveWebContents(); | 399 WebContents* const contents_at_tab1 = model_->GetActiveWebContents(); |
400 | 400 |
401 [tabStripControllerForTesting | 401 [tabStripControllerForTesting |
402 setMediaStateForContents:contents_at_tab1 | 402 setAlertStateForContents:contents_at_tab1 |
403 withMediaState:TAB_MEDIA_STATE_AUDIO_PLAYING]; | 403 withAlertState:TabAlertState::AUDIO_PLAYING]; |
404 // Make sure the overriden from base controller correctly handles media | 404 // Make sure the overriden from base controller correctly handles alert |
405 // status of tabs. | 405 // status of tabs. |
406 EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_PLAYING, | 406 EXPECT_EQ(TabAlertState::AUDIO_PLAYING, |
407 [controller_ mediaStateForContents:contents_at_tab1]); | 407 [controller_ alertStateForContents:contents_at_tab1]); |
408 [controller_ updateWindowMediaState:TAB_MEDIA_STATE_AUDIO_PLAYING | 408 [controller_ updateWindowAlertState:TabAlertState::AUDIO_PLAYING |
409 forWebContents:contents_at_tab1]; | 409 forWebContents:contents_at_tab1]; |
410 // Because we have one tab playing, and the other one's media state is none, | 410 // Because we have one tab playing, and the other one's alert state is none, |
411 // window media state should be AUDIO_PLAYING. | 411 // window alert state should be AUDIO_PLAYING. |
412 EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_PLAYING, [window_controller mediaState]); | 412 EXPECT_EQ(TabAlertState::AUDIO_PLAYING, [window_controller alertState]); |
413 | 413 |
414 model_->ActivateTabAt(0, false); | 414 model_->ActivateTabAt(0, false); |
415 // tab1 should be the selected one now. | 415 // tab1 should be the selected one now. |
416 EXPECT_TRUE([tab1 controller].selected); | 416 EXPECT_TRUE([tab1 controller].selected); |
417 EXPECT_FALSE([tab2 controller].selected); | 417 EXPECT_FALSE([tab2 controller].selected); |
418 WebContents* const contents_at_tab0 = model_->GetActiveWebContents(); | 418 WebContents* const contents_at_tab0 = model_->GetActiveWebContents(); |
419 | 419 |
420 [tabStripControllerForTesting | 420 [tabStripControllerForTesting |
421 setMediaStateForContents:contents_at_tab0 | 421 setAlertStateForContents:contents_at_tab0 |
422 withMediaState:TAB_MEDIA_STATE_AUDIO_MUTING]; | 422 withAlertState:TabAlertState::AUDIO_MUTING]; |
423 [controller_ updateWindowMediaState:TAB_MEDIA_STATE_AUDIO_MUTING | 423 [controller_ updateWindowAlertState:TabAlertState::AUDIO_MUTING |
424 forWebContents:contents_at_tab0]; | 424 forWebContents:contents_at_tab0]; |
425 // We have two tabs. One is playing and the other one is muting. The window | 425 // We have two tabs. One is playing and the other one is muting. The window |
426 // media state should be still AUDIO_PLAYING. | 426 // alert state should be still AUDIO_PLAYING. |
427 EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_PLAYING, [window_controller mediaState]); | 427 EXPECT_EQ(TabAlertState::AUDIO_PLAYING, [window_controller alertState]); |
428 | 428 |
429 [tabStripControllerForTesting | 429 [tabStripControllerForTesting |
430 setMediaStateForContents:contents_at_tab1 | 430 setAlertStateForContents:contents_at_tab1 |
431 withMediaState:TAB_MEDIA_STATE_AUDIO_MUTING]; | 431 withAlertState:TabAlertState::AUDIO_MUTING]; |
432 [controller_ updateWindowMediaState:TAB_MEDIA_STATE_AUDIO_MUTING | 432 [controller_ updateWindowAlertState:TabAlertState::AUDIO_MUTING |
433 forWebContents:contents_at_tab1]; | 433 forWebContents:contents_at_tab1]; |
434 // Now both tabs are muting, the window media state should be AUDIO_MUTING. | 434 // Now both tabs are muting, the window alert state should be AUDIO_MUTING. |
435 EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_MUTING, [window_controller mediaState]); | 435 EXPECT_EQ(TabAlertState::AUDIO_MUTING, [window_controller alertState]); |
436 | 436 |
437 [tabStripControllerForTesting | 437 [tabStripControllerForTesting |
438 setMediaStateForContents:contents_at_tab0 | 438 setAlertStateForContents:contents_at_tab0 |
439 withMediaState:TAB_MEDIA_STATE_AUDIO_PLAYING]; | 439 withAlertState:TabAlertState::AUDIO_PLAYING]; |
440 [controller_ updateWindowMediaState:TAB_MEDIA_STATE_AUDIO_PLAYING | 440 [controller_ updateWindowAlertState:TabAlertState::AUDIO_PLAYING |
441 forWebContents:contents_at_tab0]; | 441 forWebContents:contents_at_tab0]; |
442 // Among those tabs which were muting, one is started playing, the window | 442 // Among those tabs which were muting, one is started playing, the window |
443 // media state should be playing. | 443 // alert state should be playing. |
444 EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_PLAYING, [window_controller mediaState]); | 444 EXPECT_EQ(TabAlertState::AUDIO_PLAYING, [window_controller alertState]); |
445 | 445 |
446 // Mute it again for further testing. | 446 // Mute it again for further testing. |
447 [tabStripControllerForTesting | 447 [tabStripControllerForTesting |
448 setMediaStateForContents:contents_at_tab0 | 448 setAlertStateForContents:contents_at_tab0 |
449 withMediaState:TAB_MEDIA_STATE_AUDIO_MUTING]; | 449 withAlertState:TabAlertState::AUDIO_MUTING]; |
450 [controller_ updateWindowMediaState:TAB_MEDIA_STATE_AUDIO_MUTING | 450 [controller_ updateWindowAlertState:TabAlertState::AUDIO_MUTING |
451 forWebContents:contents_at_tab0]; | 451 forWebContents:contents_at_tab0]; |
452 | 452 |
453 [tabStripControllerForTesting setMediaStateForContents:contents_at_tab1 | 453 [tabStripControllerForTesting setAlertStateForContents:contents_at_tab1 |
454 withMediaState:TAB_MEDIA_STATE_NONE]; | 454 withAlertState:TabAlertState::NONE]; |
455 [controller_ updateWindowMediaState:TAB_MEDIA_STATE_NONE | 455 [controller_ updateWindowAlertState:TabAlertState::NONE |
456 forWebContents:contents_at_tab1]; | 456 forWebContents:contents_at_tab1]; |
457 // One of the tabs is muting, the other one is none. So window media state | 457 // One of the tabs is muting, the other one is none. So window alert state |
458 // should be MUTING. | 458 // should be MUTING. |
459 EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_MUTING, [window_controller mediaState]); | 459 EXPECT_EQ(TabAlertState::AUDIO_MUTING, [window_controller alertState]); |
460 | 460 |
461 [tabStripControllerForTesting setMediaStateForContents:contents_at_tab0 | 461 [tabStripControllerForTesting setAlertStateForContents:contents_at_tab0 |
462 withMediaState:TAB_MEDIA_STATE_NONE]; | 462 withAlertState:TabAlertState::NONE]; |
463 [controller_ updateWindowMediaState:TAB_MEDIA_STATE_NONE | 463 [controller_ updateWindowAlertState:TabAlertState::NONE |
464 forWebContents:contents_at_tab0]; | 464 forWebContents:contents_at_tab0]; |
465 // Neither of tabs playing nor muting, so the window media state should be | 465 // Neither of tabs playing nor muting, so the window alert state should be |
466 // NONE. | 466 // NONE. |
467 EXPECT_EQ(TAB_MEDIA_STATE_NONE, [window_controller mediaState]); | 467 EXPECT_EQ(TabAlertState::NONE, [window_controller alertState]); |
468 } | 468 } |
469 | 469 |
470 } // namespace | 470 } // namespace |
OLD | NEW |