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

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

Issue 2453623003: Decouple MediaSession messages from WebContents (full patch) (Closed)
Patch Set: nit 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <memory> 5 #include <memory>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "content/browser/media/session/media_session.h" 12 #include "content/browser/media/session/media_session_impl.h"
13 #include "content/browser/media/session/mock_media_session_player_observer.h" 13 #include "content/browser/media/session/mock_media_session_player_observer.h"
14 #include "content/public/test/content_browser_test.h" 14 #include "content/public/test/content_browser_test.h"
15 #include "content/shell/browser/shell.h" 15 #include "content/shell/browser/shell.h"
16 #include "media/base/media_content_type.h" 16 #include "media/base/media_content_type.h"
17 17
18 namespace content { 18 namespace content {
19 19
20 class AudioFocusDelegateAndroidBrowserTest : public ContentBrowserTest {}; 20 class AudioFocusDelegateAndroidBrowserTest : public ContentBrowserTest {};
21 21
22 // MAYBE_OnAudioFocusChangeAfterDtorCrash will hit a DCHECK before the crash, it 22 // MAYBE_OnAudioFocusChangeAfterDtorCrash will hit a DCHECK before the crash, it
23 // is the only way found to actually reproduce the crash so as a result, the 23 // is the only way found to actually reproduce the crash so as a result, the
24 // test will only run on builds without DCHECK's. 24 // test will only run on builds without DCHECK's.
25 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 25 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
26 // TODO(crbug.com/602787) The test is flaky, disabling it everywhere. 26 // TODO(crbug.com/602787) The test is flaky, disabling it everywhere.
27 #define MAYBE_OnAudioFocusChangeAfterDtorCrash \ 27 #define MAYBE_OnAudioFocusChangeAfterDtorCrash \
28 DISABLED_OnAudioFocusChangeAfterDtorCrash 28 DISABLED_OnAudioFocusChangeAfterDtorCrash
29 #else 29 #else
30 #define MAYBE_OnAudioFocusChangeAfterDtorCrash \ 30 #define MAYBE_OnAudioFocusChangeAfterDtorCrash \
31 DISABLED_OnAudioFocusChangeAfterDtorCrash 31 DISABLED_OnAudioFocusChangeAfterDtorCrash
32 #endif 32 #endif
33 33
34 IN_PROC_BROWSER_TEST_F(AudioFocusDelegateAndroidBrowserTest, 34 IN_PROC_BROWSER_TEST_F(AudioFocusDelegateAndroidBrowserTest,
35 MAYBE_OnAudioFocusChangeAfterDtorCrash) { 35 MAYBE_OnAudioFocusChangeAfterDtorCrash) {
36 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer( 36 std::unique_ptr<MockMediaSessionPlayerObserver> player_observer(
37 new MockMediaSessionPlayerObserver); 37 new MockMediaSessionPlayerObserver);
38 38
39 MediaSession* media_session = MediaSession::Get(shell()->web_contents()); 39 MediaSessionImpl* media_session =
40 MediaSessionImpl::Get(shell()->web_contents());
40 ASSERT_TRUE(media_session); 41 ASSERT_TRUE(media_session);
41 42
42 WebContents* other_web_contents = CreateBrowser()->web_contents(); 43 WebContents* other_web_contents = CreateBrowser()->web_contents();
43 MediaSession* other_media_session = MediaSession::Get(other_web_contents); 44 MediaSessionImpl* other_media_session =
45 MediaSessionImpl::Get(other_web_contents);
44 ASSERT_TRUE(other_media_session); 46 ASSERT_TRUE(other_media_session);
45 47
46 player_observer->StartNewPlayer(); 48 player_observer->StartNewPlayer();
47 media_session->AddPlayer(player_observer.get(), 0, 49 media_session->AddPlayer(player_observer.get(), 0,
48 media::MediaContentType::Persistent); 50 media::MediaContentType::Persistent);
49 EXPECT_TRUE(media_session->IsActive()); 51 EXPECT_TRUE(media_session->IsActive());
50 EXPECT_FALSE(other_media_session->IsActive()); 52 EXPECT_FALSE(other_media_session->IsActive());
51 53
52 player_observer->StartNewPlayer(); 54 player_observer->StartNewPlayer();
53 other_media_session->AddPlayer(player_observer.get(), 1, 55 other_media_session->AddPlayer(player_observer.get(), 1,
54 media::MediaContentType::Persistent); 56 media::MediaContentType::Persistent);
55 EXPECT_TRUE(media_session->IsActive()); 57 EXPECT_TRUE(media_session->IsActive());
56 EXPECT_TRUE(other_media_session->IsActive()); 58 EXPECT_TRUE(other_media_session->IsActive());
57 59
58 shell()->CloseAllWindows(); 60 shell()->CloseAllWindows();
59 61
60 // Give some time to the AudioFocusManager to send an audioFocusChange message 62 // Give some time to the AudioFocusManager to send an audioFocusChange message
61 // to the listeners. If the bug is still present, it will crash. 63 // to the listeners. If the bug is still present, it will crash.
62 { 64 {
63 base::RunLoop run_loop; 65 base::RunLoop run_loop;
64 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 66 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
65 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(1)); 67 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(1));
66 run_loop.Run(); 68 run_loop.Run();
67 } 69 }
68 } 70 }
69 71
70 } // namespace content 72 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698