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

Side by Side Diff: content/browser/media/session/media_session_browsertest.cc

Issue 2439483003: Link MediaSessionTabHelper with native MediaSession [CL is going to be split] (Closed)
Patch Set: Don't review, this CL is getting huge and needs to be split Created 4 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/media/session/media_session.h" 5 #include "content/browser/media/session/media_session.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <list> 9 #include <list>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/metrics/histogram_samples.h" 13 #include "base/metrics/histogram_samples.h"
14 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
15 #include "base/test/simple_test_tick_clock.h" 15 #include "base/test/simple_test_tick_clock.h"
16 #include "content/browser/media/session/audio_focus_delegate.h" 16 #include "content/browser/media/session/audio_focus_delegate.h"
17 #include "content/browser/media/session/media_session_observer.h"
17 #include "content/browser/media/session/mock_media_session_player_observer.h" 18 #include "content/browser/media/session/mock_media_session_player_observer.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_observer.h"
20 #include "content/public/test/content_browser_test.h" 20 #include "content/public/test/content_browser_test.h"
21 #include "content/shell/browser/shell.h" 21 #include "content/shell/browser/shell.h"
22 #include "media/base/media_content_type.h" 22 #include "media/base/media_content_type.h"
23 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
24 24
25 using content::WebContents; 25 using content::WebContents;
26 using content::WebContentsObserver;
27 using content::MediaSession; 26 using content::MediaSession;
28 using content::AudioFocusDelegate; 27 using content::AudioFocusDelegate;
29 using content::MediaSessionPlayerObserver; 28 using content::MediaSessionPlayerObserver;
30 using content::MediaSessionUmaHelper; 29 using content::MediaSessionUmaHelper;
31 using content::MockMediaSessionPlayerObserver; 30 using content::MockMediaSessionPlayerObserver;
32 31
33 using ::testing::Expectation; 32 using ::testing::Expectation;
34 33
35 namespace { 34 namespace {
36 35
37 const double kDefaultVolumeMultiplier = 1.0; 36 const double kDefaultVolumeMultiplier = 1.0;
38 const double kDuckingVolumeMultiplier = 0.2; 37 const double kDuckingVolumeMultiplier = 0.2;
39 38
40 class MockAudioFocusDelegate : public AudioFocusDelegate { 39 class MockAudioFocusDelegate : public AudioFocusDelegate {
41 public: 40 public:
42 bool RequestAudioFocus(content::AudioFocusManager::AudioFocusType) override { 41 bool RequestAudioFocus(content::AudioFocusManager::AudioFocusType) override {
43 return true; 42 return true;
44 } 43 }
45 44
46 void AbandonAudioFocus() override { 45 void AbandonAudioFocus() override {
47 } 46 }
48 }; 47 };
49 48
50 class MockWebContentsObserver : public WebContentsObserver { 49 class MockMediaSessionObserver : public content::MediaSessionObserver {
51 public: 50 public:
52 MockWebContentsObserver(WebContents* web_contents) 51 MockMediaSessionObserver(MediaSession* session)
53 : WebContentsObserver(web_contents) {} 52 : MediaSessionObserver(session) {}
54 53
55 MOCK_METHOD2(MediaSessionStateChanged, 54 MOCK_METHOD2(MediaSessionStateChanged,
56 void(bool is_controllable, bool is_suspended)); 55 void(bool is_controllable, bool is_suspended));
57 }; 56 };
58 57
59 } // namespace 58 } // namespace
60 59
61 class MediaSessionBrowserTest : public content::ContentBrowserTest { 60 class MediaSessionBrowserTest : public content::ContentBrowserTest {
62 protected: 61 protected:
63 MediaSessionBrowserTest() = default; 62 MediaSessionBrowserTest() = default;
64 63
65 void SetUpOnMainThread() override { 64 void SetUpOnMainThread() override {
66 ContentBrowserTest::SetUpOnMainThread(); 65 ContentBrowserTest::SetUpOnMainThread();
67 66
68 mock_web_contents_observer_.reset( 67 mock_media_session_observer_.reset(new MockMediaSessionObserver(
69 new MockWebContentsObserver(shell()->web_contents())); 68 MediaSession::Get(shell()->web_contents())));
70 media_session_ = MediaSession::Get(shell()->web_contents()); 69 media_session_ = MediaSession::Get(shell()->web_contents());
71 media_session_->SetDelegateForTests( 70 media_session_->SetDelegateForTests(
72 std::unique_ptr<AudioFocusDelegate>(new MockAudioFocusDelegate())); 71 std::unique_ptr<AudioFocusDelegate>(new MockAudioFocusDelegate()));
73 ASSERT_TRUE(media_session_); 72 ASSERT_TRUE(media_session_);
74 } 73 }
75 74
76 void TearDownOnMainThread() override { 75 void TearDownOnMainThread() override {
77 mock_web_contents_observer_.reset(); 76 mock_media_session_observer_.reset();
78 77
79 media_session_->RemoveAllPlayersForTest(); 78 media_session_->RemoveAllPlayersForTest();
80 media_session_ = nullptr; 79 media_session_ = nullptr;
81 80
82 ContentBrowserTest::TearDownOnMainThread(); 81 ContentBrowserTest::TearDownOnMainThread();
83 } 82 }
84 83
85 void StartNewPlayer( 84 void StartNewPlayer(
86 MockMediaSessionPlayerObserver* player_observer, 85 MockMediaSessionPlayerObserver* player_observer,
87 media::MediaContentType media_content_type) { 86 media::MediaContentType media_content_type) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 144 }
146 145
147 void SystemStartDucking() { 146 void SystemStartDucking() {
148 media_session_->StartDucking(); 147 media_session_->StartDucking();
149 } 148 }
150 149
151 void SystemStopDucking() { 150 void SystemStopDucking() {
152 media_session_->StopDucking(); 151 media_session_->StopDucking();
153 } 152 }
154 153
155 MockWebContentsObserver* mock_web_contents_observer() { 154 MockMediaSessionObserver* mock_media_session_observer() {
156 return mock_web_contents_observer_.get(); 155 return mock_media_session_observer_.get();
157 } 156 }
158 157
159 std::unique_ptr<MediaSession> CreateDummyMediaSession() { 158 std::unique_ptr<MediaSession> CreateDummyMediaSession() {
160 return std::unique_ptr<MediaSession>(new MediaSession(nullptr)); 159 return std::unique_ptr<MediaSession>(new MediaSession(nullptr));
161 } 160 }
162 161
163 MediaSessionUmaHelper* GetMediaSessionUMAHelper() { 162 MediaSessionUmaHelper* GetMediaSessionUMAHelper() {
164 return media_session_->uma_helper_for_test(); 163 return media_session_->uma_helper_for_test();
165 } 164 }
166 165
167 protected: 166 protected:
168 MediaSession* media_session_; 167 MediaSession* media_session_;
169 std::unique_ptr<MockWebContentsObserver> mock_web_contents_observer_; 168 std::unique_ptr<MockMediaSessionObserver> mock_media_session_observer_;
170 169
171 DISALLOW_COPY_AND_ASSIGN(MediaSessionBrowserTest); 170 DISALLOW_COPY_AND_ASSIGN(MediaSessionBrowserTest);
172 }; 171 };
173 172
174 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 173 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
175 PlayersFromSameObserverDoNotStopEachOtherInSameSession) { 174 PlayersFromSameObserverDoNotStopEachOtherInSameSession) {
176 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 175 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
177 new MockMediaSessionPlayerObserver); 176 new MockMediaSessionPlayerObserver);
178 177
179 StartNewPlayer(player_observer.get(), 178 StartNewPlayer(player_observer.get(),
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 EXPECT_TRUE(player_observer->IsPlaying(0)); 582 EXPECT_TRUE(player_observer->IsPlaying(0));
584 EXPECT_TRUE(player_observer->IsPlaying(1)); 583 EXPECT_TRUE(player_observer->IsPlaying(1));
585 EXPECT_TRUE(player_observer->IsPlaying(2)); 584 EXPECT_TRUE(player_observer->IsPlaying(2));
586 EXPECT_TRUE(player_observer->IsPlaying(3)); 585 EXPECT_TRUE(player_observer->IsPlaying(3));
587 586
588 EXPECT_EQ(content::AudioFocusManager::AudioFocusType::Gain, 587 EXPECT_EQ(content::AudioFocusManager::AudioFocusType::Gain,
589 GetSessionAudioFocusType()); 588 GetSessionAudioFocusType());
590 } 589 }
591 590
592 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, ControlsShowForContent) { 591 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, ControlsShowForContent) {
593 EXPECT_CALL(*mock_web_contents_observer(), 592 EXPECT_CALL(*mock_media_session_observer(),
594 MediaSessionStateChanged(true, false)); 593 MediaSessionStateChanged(true, false));
595 594
596 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 595 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
597 new MockMediaSessionPlayerObserver); 596 new MockMediaSessionPlayerObserver);
598 597
599 // Starting a player with a content type should show the media controls. 598 // Starting a player with a content type should show the media controls.
600 StartNewPlayer(player_observer.get(), 599 StartNewPlayer(player_observer.get(),
601 media::MediaContentType::Persistent); 600 media::MediaContentType::Persistent);
602 601
603 EXPECT_TRUE(IsControllable()); 602 EXPECT_TRUE(IsControllable());
604 EXPECT_FALSE(IsSuspended()); 603 EXPECT_FALSE(IsSuspended());
605 } 604 }
606 605
607 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, ControlsNoShowForTransient) { 606 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, ControlsNoShowForTransient) {
608 EXPECT_CALL(*mock_web_contents_observer(), 607 EXPECT_CALL(*mock_media_session_observer(),
609 MediaSessionStateChanged(false, false)); 608 MediaSessionStateChanged(false, false));
610 609
611 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 610 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
612 new MockMediaSessionPlayerObserver); 611 new MockMediaSessionPlayerObserver);
613 612
614 // Starting a player with a transient type should not show the media controls. 613 // Starting a player with a transient type should not show the media controls.
615 StartNewPlayer(player_observer.get(), 614 StartNewPlayer(player_observer.get(),
616 media::MediaContentType::Transient); 615 media::MediaContentType::Transient);
617 616
618 EXPECT_FALSE(IsControllable()); 617 EXPECT_FALSE(IsControllable());
619 EXPECT_FALSE(IsSuspended()); 618 EXPECT_FALSE(IsSuspended());
620 } 619 }
621 620
622 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, ControlsHideWhenStopped) { 621 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, ControlsHideWhenStopped) {
623 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 622 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
624 MediaSessionStateChanged(true, false)); 623 MediaSessionStateChanged(true, false));
625 EXPECT_CALL(*mock_web_contents_observer(), 624 EXPECT_CALL(*mock_media_session_observer(),
626 MediaSessionStateChanged(false, true)) 625 MediaSessionStateChanged(false, true))
627 .After(showControls); 626 .After(showControls);
628 627
629 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 628 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
630 new MockMediaSessionPlayerObserver); 629 new MockMediaSessionPlayerObserver);
631 630
632 StartNewPlayer(player_observer.get(), 631 StartNewPlayer(player_observer.get(),
633 media::MediaContentType::Persistent); 632 media::MediaContentType::Persistent);
634 633
635 RemovePlayers(player_observer.get()); 634 RemovePlayers(player_observer.get());
636 635
637 EXPECT_FALSE(IsControllable()); 636 EXPECT_FALSE(IsControllable());
638 EXPECT_TRUE(IsSuspended()); 637 EXPECT_TRUE(IsSuspended());
639 } 638 }
640 639
641 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, ControlsShownAcceptTransient) { 640 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, ControlsShownAcceptTransient) {
642 EXPECT_CALL(*mock_web_contents_observer(), 641 EXPECT_CALL(*mock_media_session_observer(),
643 MediaSessionStateChanged(true, false)); 642 MediaSessionStateChanged(true, false));
644 643
645 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 644 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
646 new MockMediaSessionPlayerObserver); 645 new MockMediaSessionPlayerObserver);
647 646
648 StartNewPlayer(player_observer.get(), 647 StartNewPlayer(player_observer.get(),
649 media::MediaContentType::Persistent); 648 media::MediaContentType::Persistent);
650 649
651 // Transient player join the session without affecting the controls. 650 // Transient player join the session without affecting the controls.
652 StartNewPlayer(player_observer.get(), 651 StartNewPlayer(player_observer.get(),
653 media::MediaContentType::Transient); 652 media::MediaContentType::Transient);
654 653
655 EXPECT_TRUE(IsControllable()); 654 EXPECT_TRUE(IsControllable());
656 EXPECT_FALSE(IsSuspended()); 655 EXPECT_FALSE(IsSuspended());
657 } 656 }
658 657
659 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 658 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
660 ControlsShownAfterContentAdded) { 659 ControlsShownAfterContentAdded) {
661 Expectation dontShowControls = EXPECT_CALL( 660 Expectation dontShowControls = EXPECT_CALL(
662 *mock_web_contents_observer(), MediaSessionStateChanged(false, false)); 661 *mock_media_session_observer(), MediaSessionStateChanged(false, false));
663 EXPECT_CALL(*mock_web_contents_observer(), 662 EXPECT_CALL(*mock_media_session_observer(),
664 MediaSessionStateChanged(true, false)) 663 MediaSessionStateChanged(true, false))
665 .After(dontShowControls); 664 .After(dontShowControls);
666 665
667 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 666 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
668 new MockMediaSessionPlayerObserver); 667 new MockMediaSessionPlayerObserver);
669 668
670 StartNewPlayer(player_observer.get(), 669 StartNewPlayer(player_observer.get(),
671 media::MediaContentType::Transient); 670 media::MediaContentType::Transient);
672 671
673 // The controls are shown when the content player is added. 672 // The controls are shown when the content player is added.
674 StartNewPlayer(player_observer.get(), 673 StartNewPlayer(player_observer.get(),
675 media::MediaContentType::Persistent); 674 media::MediaContentType::Persistent);
676 675
677 EXPECT_TRUE(IsControllable()); 676 EXPECT_TRUE(IsControllable());
678 EXPECT_FALSE(IsSuspended()); 677 EXPECT_FALSE(IsSuspended());
679 } 678 }
680 679
681 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 680 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
682 ControlsStayIfOnlyOnePlayerHasBeenPaused) { 681 ControlsStayIfOnlyOnePlayerHasBeenPaused) {
683 EXPECT_CALL(*mock_web_contents_observer(), 682 EXPECT_CALL(*mock_media_session_observer(),
684 MediaSessionStateChanged(true, false)); 683 MediaSessionStateChanged(true, false));
685 684
686 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 685 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
687 new MockMediaSessionPlayerObserver); 686 new MockMediaSessionPlayerObserver);
688 687
689 StartNewPlayer(player_observer.get(), 688 StartNewPlayer(player_observer.get(),
690 media::MediaContentType::Persistent); 689 media::MediaContentType::Persistent);
691 StartNewPlayer(player_observer.get(), 690 StartNewPlayer(player_observer.get(),
692 media::MediaContentType::Transient); 691 media::MediaContentType::Transient);
693 692
694 // Removing only content player doesn't hide the controls since the session 693 // Removing only content player doesn't hide the controls since the session
695 // is still active. 694 // is still active.
696 RemovePlayer(player_observer.get(), 0); 695 RemovePlayer(player_observer.get(), 0);
697 696
698 EXPECT_TRUE(IsControllable()); 697 EXPECT_TRUE(IsControllable());
699 EXPECT_FALSE(IsSuspended()); 698 EXPECT_FALSE(IsSuspended());
700 } 699 }
701 700
702 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 701 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
703 ControlsHideWhenTheLastPlayerIsRemoved) { 702 ControlsHideWhenTheLastPlayerIsRemoved) {
704 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 703 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
705 MediaSessionStateChanged(true, false)); 704 MediaSessionStateChanged(true, false));
706 EXPECT_CALL(*mock_web_contents_observer(), 705 EXPECT_CALL(*mock_media_session_observer(),
707 MediaSessionStateChanged(false, true)) 706 MediaSessionStateChanged(false, true))
708 .After(showControls); 707 .After(showControls);
709 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 708 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
710 new MockMediaSessionPlayerObserver); 709 new MockMediaSessionPlayerObserver);
711 710
712 StartNewPlayer(player_observer.get(), 711 StartNewPlayer(player_observer.get(),
713 media::MediaContentType::Persistent); 712 media::MediaContentType::Persistent);
714 StartNewPlayer(player_observer.get(), 713 StartNewPlayer(player_observer.get(),
715 media::MediaContentType::Persistent); 714 media::MediaContentType::Persistent);
716 715
717 RemovePlayer(player_observer.get(), 0); 716 RemovePlayer(player_observer.get(), 0);
718 717
719 EXPECT_TRUE(IsControllable()); 718 EXPECT_TRUE(IsControllable());
720 EXPECT_FALSE(IsSuspended()); 719 EXPECT_FALSE(IsSuspended());
721 720
722 RemovePlayer(player_observer.get(), 1); 721 RemovePlayer(player_observer.get(), 1);
723 722
724 EXPECT_FALSE(IsControllable()); 723 EXPECT_FALSE(IsControllable());
725 EXPECT_TRUE(IsSuspended()); 724 EXPECT_TRUE(IsSuspended());
726 } 725 }
727 726
728 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 727 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
729 ControlsHideWhenAllThePlayersAreRemoved) { 728 ControlsHideWhenAllThePlayersAreRemoved) {
730 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 729 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
731 MediaSessionStateChanged(true, false)); 730 MediaSessionStateChanged(true, false));
732 EXPECT_CALL(*mock_web_contents_observer(), 731 EXPECT_CALL(*mock_media_session_observer(),
733 MediaSessionStateChanged(false, true)) 732 MediaSessionStateChanged(false, true))
734 .After(showControls); 733 .After(showControls);
735 734
736 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 735 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
737 new MockMediaSessionPlayerObserver); 736 new MockMediaSessionPlayerObserver);
738 737
739 StartNewPlayer(player_observer.get(), 738 StartNewPlayer(player_observer.get(),
740 media::MediaContentType::Persistent); 739 media::MediaContentType::Persistent);
741 StartNewPlayer(player_observer.get(), 740 StartNewPlayer(player_observer.get(),
742 media::MediaContentType::Persistent); 741 media::MediaContentType::Persistent);
743 742
744 RemovePlayers(player_observer.get()); 743 RemovePlayers(player_observer.get());
745 744
746 EXPECT_FALSE(IsControllable()); 745 EXPECT_FALSE(IsControllable());
747 EXPECT_TRUE(IsSuspended()); 746 EXPECT_TRUE(IsSuspended());
748 } 747 }
749 748
750 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 749 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
751 ControlsNotHideWhenTheLastPlayerIsPaused) { 750 ControlsNotHideWhenTheLastPlayerIsPaused) {
752 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 751 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
753 MediaSessionStateChanged(true, false)); 752 MediaSessionStateChanged(true, false));
754 EXPECT_CALL(*mock_web_contents_observer(), 753 EXPECT_CALL(*mock_media_session_observer(),
755 MediaSessionStateChanged(true, true)) 754 MediaSessionStateChanged(true, true))
756 .After(showControls); 755 .After(showControls);
757 756
758 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 757 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
759 new MockMediaSessionPlayerObserver); 758 new MockMediaSessionPlayerObserver);
760 759
761 StartNewPlayer(player_observer.get(), 760 StartNewPlayer(player_observer.get(),
762 media::MediaContentType::Persistent); 761 media::MediaContentType::Persistent);
763 StartNewPlayer(player_observer.get(), 762 StartNewPlayer(player_observer.get(),
764 media::MediaContentType::Persistent); 763 media::MediaContentType::Persistent);
765 764
766 OnPlayerPaused(player_observer.get(), 0); 765 OnPlayerPaused(player_observer.get(), 0);
767 766
768 EXPECT_TRUE(IsControllable()); 767 EXPECT_TRUE(IsControllable());
769 EXPECT_FALSE(IsSuspended()); 768 EXPECT_FALSE(IsSuspended());
770 769
771 OnPlayerPaused(player_observer.get(), 1); 770 OnPlayerPaused(player_observer.get(), 1);
772 771
773 EXPECT_TRUE(IsControllable()); 772 EXPECT_TRUE(IsControllable());
774 EXPECT_TRUE(IsSuspended()); 773 EXPECT_TRUE(IsSuspended());
775 } 774 }
776 775
777 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 776 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
778 SuspendTemporaryUpdatesControls) { 777 SuspendTemporaryUpdatesControls) {
779 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 778 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
780 MediaSessionStateChanged(true, false)); 779 MediaSessionStateChanged(true, false));
781 EXPECT_CALL(*mock_web_contents_observer(), 780 EXPECT_CALL(*mock_media_session_observer(),
782 MediaSessionStateChanged(true, true)) 781 MediaSessionStateChanged(true, true))
783 .After(showControls); 782 .After(showControls);
784 783
785 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 784 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
786 new MockMediaSessionPlayerObserver); 785 new MockMediaSessionPlayerObserver);
787 786
788 StartNewPlayer(player_observer.get(), 787 StartNewPlayer(player_observer.get(),
789 media::MediaContentType::Persistent); 788 media::MediaContentType::Persistent);
790 789
791 SystemSuspend(true); 790 SystemSuspend(true);
792 791
793 EXPECT_TRUE(IsControllable()); 792 EXPECT_TRUE(IsControllable());
794 EXPECT_TRUE(IsSuspended()); 793 EXPECT_TRUE(IsSuspended());
795 } 794 }
796 795
797 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, ControlsUpdatedWhenResumed) { 796 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, ControlsUpdatedWhenResumed) {
798 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 797 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
799 MediaSessionStateChanged(true, false)); 798 MediaSessionStateChanged(true, false));
800 Expectation pauseControls = EXPECT_CALL(*mock_web_contents_observer(), 799 Expectation pauseControls = EXPECT_CALL(*mock_media_session_observer(),
801 MediaSessionStateChanged(true, true)) 800 MediaSessionStateChanged(true, true))
802 .After(showControls); 801 .After(showControls);
803 EXPECT_CALL(*mock_web_contents_observer(), 802 EXPECT_CALL(*mock_media_session_observer(),
804 MediaSessionStateChanged(true, false)) 803 MediaSessionStateChanged(true, false))
805 .After(pauseControls); 804 .After(pauseControls);
806 805
807 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 806 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
808 new MockMediaSessionPlayerObserver); 807 new MockMediaSessionPlayerObserver);
809 808
810 StartNewPlayer(player_observer.get(), 809 StartNewPlayer(player_observer.get(),
811 media::MediaContentType::Persistent); 810 media::MediaContentType::Persistent);
812 SystemSuspend(true); 811 SystemSuspend(true);
813 SystemResume(); 812 SystemResume();
814 813
815 EXPECT_TRUE(IsControllable()); 814 EXPECT_TRUE(IsControllable());
816 EXPECT_FALSE(IsSuspended()); 815 EXPECT_FALSE(IsSuspended());
817 } 816 }
818 817
819 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 818 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
820 ControlsHideWhenSessionSuspendedPermanently) { 819 ControlsHideWhenSessionSuspendedPermanently) {
821 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 820 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
822 MediaSessionStateChanged(true, false)); 821 MediaSessionStateChanged(true, false));
823 EXPECT_CALL(*mock_web_contents_observer(), 822 EXPECT_CALL(*mock_media_session_observer(),
824 MediaSessionStateChanged(false, true)) 823 MediaSessionStateChanged(false, true))
825 .After(showControls); 824 .After(showControls);
826 825
827 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 826 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
828 new MockMediaSessionPlayerObserver); 827 new MockMediaSessionPlayerObserver);
829 828
830 StartNewPlayer(player_observer.get(), 829 StartNewPlayer(player_observer.get(),
831 media::MediaContentType::Persistent); 830 media::MediaContentType::Persistent);
832 831
833 SystemSuspend(false); 832 SystemSuspend(false);
834 833
835 EXPECT_FALSE(IsControllable()); 834 EXPECT_FALSE(IsControllable());
836 EXPECT_TRUE(IsSuspended()); 835 EXPECT_TRUE(IsSuspended());
837 } 836 }
838 837
839 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 838 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
840 ConstrolsHideWhenSessionStops) { 839 ConstrolsHideWhenSessionStops) {
841 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 840 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
842 MediaSessionStateChanged(true, false)); 841 MediaSessionStateChanged(true, false));
843 Expectation pauseControls = EXPECT_CALL(*mock_web_contents_observer(), 842 Expectation pauseControls = EXPECT_CALL(*mock_media_session_observer(),
844 MediaSessionStateChanged(true, true)) 843 MediaSessionStateChanged(true, true))
845 .After(showControls); 844 .After(showControls);
846 EXPECT_CALL(*mock_web_contents_observer(), 845 EXPECT_CALL(*mock_media_session_observer(),
847 MediaSessionStateChanged(false, true)) 846 MediaSessionStateChanged(false, true))
848 .After(pauseControls); 847 .After(pauseControls);
849 848
850 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 849 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
851 new MockMediaSessionPlayerObserver); 850 new MockMediaSessionPlayerObserver);
852 851
853 StartNewPlayer(player_observer.get(), 852 StartNewPlayer(player_observer.get(),
854 media::MediaContentType::Persistent); 853 media::MediaContentType::Persistent);
855 854
856 media_session_->Stop(MediaSession::SuspendType::UI); 855 media_session_->Stop(MediaSession::SuspendType::UI);
857 856
858 EXPECT_FALSE(IsControllable()); 857 EXPECT_FALSE(IsControllable());
859 EXPECT_TRUE(IsSuspended()); 858 EXPECT_TRUE(IsSuspended());
860 } 859 }
861 860
862 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 861 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
863 ControlsHideWhenSessionChangesFromContentToTransient) { 862 ControlsHideWhenSessionChangesFromContentToTransient) {
864 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 863 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
865 MediaSessionStateChanged(true, false)); 864 MediaSessionStateChanged(true, false));
866 Expectation pauseControls = EXPECT_CALL(*mock_web_contents_observer(), 865 Expectation pauseControls = EXPECT_CALL(*mock_media_session_observer(),
867 MediaSessionStateChanged(true, true)) 866 MediaSessionStateChanged(true, true))
868 .After(showControls); 867 .After(showControls);
869 EXPECT_CALL(*mock_web_contents_observer(), 868 EXPECT_CALL(*mock_media_session_observer(),
870 MediaSessionStateChanged(false, false)) 869 MediaSessionStateChanged(false, false))
871 .After(pauseControls); 870 .After(pauseControls);
872 871
873 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 872 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
874 new MockMediaSessionPlayerObserver); 873 new MockMediaSessionPlayerObserver);
875 874
876 StartNewPlayer(player_observer.get(), 875 StartNewPlayer(player_observer.get(),
877 media::MediaContentType::Persistent); 876 media::MediaContentType::Persistent);
878 SystemSuspend(true); 877 SystemSuspend(true);
879 878
880 // This should reset the session and change it to a transient, so 879 // This should reset the session and change it to a transient, so
881 // hide the controls. 880 // hide the controls.
882 StartNewPlayer(player_observer.get(), 881 StartNewPlayer(player_observer.get(),
883 media::MediaContentType::Transient); 882 media::MediaContentType::Transient);
884 883
885 EXPECT_FALSE(IsControllable()); 884 EXPECT_FALSE(IsControllable());
886 EXPECT_FALSE(IsSuspended()); 885 EXPECT_FALSE(IsSuspended());
887 } 886 }
888 887
889 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 888 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
890 ControlsUpdatedWhenNewPlayerResetsSession) { 889 ControlsUpdatedWhenNewPlayerResetsSession) {
891 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 890 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
892 MediaSessionStateChanged(true, false)); 891 MediaSessionStateChanged(true, false));
893 Expectation pauseControls = EXPECT_CALL(*mock_web_contents_observer(), 892 Expectation pauseControls = EXPECT_CALL(*mock_media_session_observer(),
894 MediaSessionStateChanged(true, true)) 893 MediaSessionStateChanged(true, true))
895 .After(showControls); 894 .After(showControls);
896 EXPECT_CALL(*mock_web_contents_observer(), 895 EXPECT_CALL(*mock_media_session_observer(),
897 MediaSessionStateChanged(true, false)) 896 MediaSessionStateChanged(true, false))
898 .After(pauseControls); 897 .After(pauseControls);
899 898
900 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 899 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
901 new MockMediaSessionPlayerObserver); 900 new MockMediaSessionPlayerObserver);
902 901
903 StartNewPlayer(player_observer.get(), 902 StartNewPlayer(player_observer.get(),
904 media::MediaContentType::Persistent); 903 media::MediaContentType::Persistent);
905 SystemSuspend(true); 904 SystemSuspend(true);
906 905
907 // This should reset the session and update the controls. 906 // This should reset the session and update the controls.
908 StartNewPlayer(player_observer.get(), 907 StartNewPlayer(player_observer.get(),
909 media::MediaContentType::Persistent); 908 media::MediaContentType::Persistent);
910 909
911 EXPECT_TRUE(IsControllable()); 910 EXPECT_TRUE(IsControllable());
912 EXPECT_FALSE(IsSuspended()); 911 EXPECT_FALSE(IsSuspended());
913 } 912 }
914 913
915 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 914 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
916 ControlsResumedWhenPlayerIsResumed) { 915 ControlsResumedWhenPlayerIsResumed) {
917 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 916 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
918 MediaSessionStateChanged(true, false)); 917 MediaSessionStateChanged(true, false));
919 Expectation pauseControls = EXPECT_CALL(*mock_web_contents_observer(), 918 Expectation pauseControls = EXPECT_CALL(*mock_media_session_observer(),
920 MediaSessionStateChanged(true, true)) 919 MediaSessionStateChanged(true, true))
921 .After(showControls); 920 .After(showControls);
922 EXPECT_CALL(*mock_web_contents_observer(), 921 EXPECT_CALL(*mock_media_session_observer(),
923 MediaSessionStateChanged(true, false)) 922 MediaSessionStateChanged(true, false))
924 .After(pauseControls); 923 .After(pauseControls);
925 924
926 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 925 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
927 new MockMediaSessionPlayerObserver); 926 new MockMediaSessionPlayerObserver);
928 927
929 StartNewPlayer(player_observer.get(), 928 StartNewPlayer(player_observer.get(),
930 media::MediaContentType::Persistent); 929 media::MediaContentType::Persistent);
931 SystemSuspend(true); 930 SystemSuspend(true);
932 931
933 // This should resume the session and update the controls. 932 // This should resume the session and update the controls.
934 AddPlayer(player_observer.get(), 0, 933 AddPlayer(player_observer.get(), 0,
935 media::MediaContentType::Persistent); 934 media::MediaContentType::Persistent);
936 935
937 EXPECT_TRUE(IsControllable()); 936 EXPECT_TRUE(IsControllable());
938 EXPECT_FALSE(IsSuspended()); 937 EXPECT_FALSE(IsSuspended());
939 } 938 }
940 939
941 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 940 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
942 ControlsUpdatedDueToResumeSessionAction) { 941 ControlsUpdatedDueToResumeSessionAction) {
943 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 942 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
944 MediaSessionStateChanged(true, false)); 943 MediaSessionStateChanged(true, false));
945 EXPECT_CALL(*mock_web_contents_observer(), 944 EXPECT_CALL(*mock_media_session_observer(),
946 MediaSessionStateChanged(true, true)) 945 MediaSessionStateChanged(true, true))
947 .After(showControls); 946 .After(showControls);
948 947
949 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 948 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
950 new MockMediaSessionPlayerObserver); 949 new MockMediaSessionPlayerObserver);
951 950
952 StartNewPlayer(player_observer.get(), 951 StartNewPlayer(player_observer.get(),
953 media::MediaContentType::Persistent); 952 media::MediaContentType::Persistent);
954 UISuspend(); 953 UISuspend();
955 954
956 EXPECT_TRUE(IsControllable()); 955 EXPECT_TRUE(IsControllable());
957 EXPECT_TRUE(IsSuspended()); 956 EXPECT_TRUE(IsSuspended());
958 } 957 }
959 958
960 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest, 959 IN_PROC_BROWSER_TEST_F(MediaSessionBrowserTest,
961 ControlsUpdatedDueToSuspendSessionAction) { 960 ControlsUpdatedDueToSuspendSessionAction) {
962 Expectation showControls = EXPECT_CALL(*mock_web_contents_observer(), 961 Expectation showControls = EXPECT_CALL(*mock_media_session_observer(),
963 MediaSessionStateChanged(true, false)); 962 MediaSessionStateChanged(true, false));
964 Expectation pauseControls = EXPECT_CALL(*mock_web_contents_observer(), 963 Expectation pauseControls = EXPECT_CALL(*mock_media_session_observer(),
965 MediaSessionStateChanged(true, true)) 964 MediaSessionStateChanged(true, true))
966 .After(showControls); 965 .After(showControls);
967 EXPECT_CALL(*mock_web_contents_observer(), 966 EXPECT_CALL(*mock_media_session_observer(),
968 MediaSessionStateChanged(true, false)) 967 MediaSessionStateChanged(true, false))
969 .After(pauseControls); 968 .After(pauseControls);
970 969
971 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 970 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
972 new MockMediaSessionPlayerObserver); 971 new MockMediaSessionPlayerObserver);
973 972
974 StartNewPlayer(player_observer.get(), 973 StartNewPlayer(player_observer.get(),
975 media::MediaContentType::Persistent); 974 media::MediaContentType::Persistent);
976 UISuspend(); 975 UISuspend();
977 UIResume(); 976 UIResume();
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 media::MediaContentType::Persistent); 1346 media::MediaContentType::Persistent);
1348 clock->Advance(base::TimeDelta::FromMilliseconds(1000)); 1347 clock->Advance(base::TimeDelta::FromMilliseconds(1000));
1349 media_session_->Stop(MediaSession::SuspendType::UI); 1348 media_session_->Stop(MediaSession::SuspendType::UI);
1350 1349
1351 std::unique_ptr<base::HistogramSamples> samples( 1350 std::unique_ptr<base::HistogramSamples> samples(
1352 tester.GetHistogramSamplesSinceCreation("Media.Session.ActiveTime")); 1351 tester.GetHistogramSamplesSinceCreation("Media.Session.ActiveTime"));
1353 EXPECT_EQ(2, samples->TotalCount()); 1352 EXPECT_EQ(2, samples->TotalCount());
1354 EXPECT_EQ(1, samples->GetCount(1000)); 1353 EXPECT_EQ(1, samples->GetCount(1000));
1355 EXPECT_EQ(1, samples->GetCount(10000)); 1354 EXPECT_EQ(1, samples->GetCount(10000));
1356 } 1355 }
OLDNEW
« no previous file with comments | « content/browser/media/session/media_session_android.cc ('k') | content/browser/media/session/media_session_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698