| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <memory> | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/location.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "base/threading/thread_task_runner_handle.h" | |
| 12 #include "content/browser/media/session/media_session.h" | |
| 13 #include "content/browser/media/session/mock_media_session_observer.h" | |
| 14 #include "content/public/test/content_browser_test.h" | |
| 15 #include "content/shell/browser/shell.h" | |
| 16 #include "media/base/media_content_type.h" | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 class MediaSessionDelegateAndroidBrowserTest : public ContentBrowserTest {}; | |
| 21 | |
| 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 | |
| 24 // test will only run on builds without DCHECK's. | |
| 25 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | |
| 26 // TODO(crbug.com/602787) The test is flaky, disabling it everywhere. | |
| 27 #define MAYBE_OnAudioFocusChangeAfterDtorCrash \ | |
| 28 DISABLED_OnAudioFocusChangeAfterDtorCrash | |
| 29 #else | |
| 30 #define MAYBE_OnAudioFocusChangeAfterDtorCrash \ | |
| 31 DISABLED_OnAudioFocusChangeAfterDtorCrash | |
| 32 #endif | |
| 33 | |
| 34 IN_PROC_BROWSER_TEST_F(MediaSessionDelegateAndroidBrowserTest, | |
| 35 MAYBE_OnAudioFocusChangeAfterDtorCrash) { | |
| 36 std::unique_ptr<MockMediaSessionObserver> media_session_observer( | |
| 37 new MockMediaSessionObserver); | |
| 38 | |
| 39 MediaSession* media_session = MediaSession::Get(shell()->web_contents()); | |
| 40 ASSERT_TRUE(media_session); | |
| 41 | |
| 42 WebContents* other_web_contents = CreateBrowser()->web_contents(); | |
| 43 MediaSession* other_media_session = MediaSession::Get(other_web_contents); | |
| 44 ASSERT_TRUE(other_media_session); | |
| 45 | |
| 46 media_session_observer->StartNewPlayer(); | |
| 47 media_session->AddPlayer(media_session_observer.get(), 0, | |
| 48 media::MediaContentType::Persistent); | |
| 49 EXPECT_TRUE(media_session->IsActive()); | |
| 50 EXPECT_FALSE(other_media_session->IsActive()); | |
| 51 | |
| 52 media_session_observer->StartNewPlayer(); | |
| 53 other_media_session->AddPlayer(media_session_observer.get(), 1, | |
| 54 media::MediaContentType::Persistent); | |
| 55 EXPECT_TRUE(media_session->IsActive()); | |
| 56 EXPECT_TRUE(other_media_session->IsActive()); | |
| 57 | |
| 58 shell()->CloseAllWindows(); | |
| 59 | |
| 60 // Give some time to the AudioFocusManager to send an audioFocusChange message | |
| 61 // to the listeners. If the bug is still present, it will crash. | |
| 62 { | |
| 63 base::RunLoop run_loop; | |
| 64 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 65 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(1)); | |
| 66 run_loop.Run(); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 } // namespace content | |
| OLD | NEW |