| OLD | NEW |
| 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 <tuple> | 5 #include <tuple> |
| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 static const char kStartPlayerScript[] = | 26 static const char kStartPlayerScript[] = |
| 27 "document.getElementById('long-video').play()"; | 27 "document.getElementById('long-video').play()"; |
| 28 static const char kPausePlayerScript[] = | 28 static const char kPausePlayerScript[] = |
| 29 "document.getElementById('long-video').pause()"; | 29 "document.getElementById('long-video').pause()"; |
| 30 | 30 |
| 31 enum class MediaSuspend { | 31 enum class MediaSuspend { |
| 32 ENABLED, | 32 ENABLED, |
| 33 DISABLED, | 33 DISABLED, |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 enum class Pipeline { | |
| 37 WMPI, | |
| 38 WMPA, | |
| 39 }; | |
| 40 | |
| 41 enum class BackgroundResuming { | 36 enum class BackgroundResuming { |
| 42 ENABLED, | 37 ENABLED, |
| 43 DISABLED, | 38 DISABLED, |
| 44 }; | 39 }; |
| 45 | 40 |
| 46 enum class SessionState { | 41 enum class SessionState { |
| 47 ACTIVE, | 42 ACTIVE, |
| 48 SUSPENDED, | 43 SUSPENDED, |
| 49 INACTIVE, | 44 INACTIVE, |
| 50 }; | 45 }; |
| 51 | 46 |
| 52 struct VisibilityTestData { | 47 struct VisibilityTestData { |
| 53 MediaSuspend media_suspend; | 48 MediaSuspend media_suspend; |
| 54 BackgroundResuming background_resuming; | 49 BackgroundResuming background_resuming; |
| 55 SessionState session_state_before_hide; | 50 SessionState session_state_before_hide; |
| 56 SessionState session_state_after_hide; | 51 SessionState session_state_after_hide; |
| 57 }; | 52 }; |
| 58 } | 53 } |
| 59 | 54 |
| 60 // Base class of MediaSession visibility tests. The class is intended | 55 // Base class of MediaSession visibility tests. The class is intended |
| 61 // to be used to run tests under different configurations. Tests | 56 // to be used to run tests under different configurations. Tests |
| 62 // should inheret from this class, set up their own command line per | 57 // should inheret from this class, set up their own command line per |
| 63 // their configuration, and use macro INCLUDE_TEST_FROM_BASE_CLASS to | 58 // their configuration, and use macro INCLUDE_TEST_FROM_BASE_CLASS to |
| 64 // include required tests. See | 59 // include required tests. See |
| 65 // media_session_visibility_browsertest_instances.cc for examples. | 60 // media_session_visibility_browsertest_instances.cc for examples. |
| 66 class MediaSessionImplVisibilityBrowserTest | 61 class MediaSessionImplVisibilityBrowserTest |
| 67 : public ContentBrowserTest, | 62 : public ContentBrowserTest, |
| 68 public ::testing::WithParamInterface< | 63 public ::testing::WithParamInterface<VisibilityTestData> { |
| 69 std::tr1::tuple<VisibilityTestData, Pipeline>> { | |
| 70 public: | 64 public: |
| 71 MediaSessionImplVisibilityBrowserTest() = default; | 65 MediaSessionImplVisibilityBrowserTest() = default; |
| 72 ~MediaSessionImplVisibilityBrowserTest() override = default; | 66 ~MediaSessionImplVisibilityBrowserTest() override = default; |
| 73 | 67 |
| 74 void SetUpOnMainThread() override { | 68 void SetUpOnMainThread() override { |
| 75 ContentBrowserTest::SetUpOnMainThread(); | 69 ContentBrowserTest::SetUpOnMainThread(); |
| 76 web_contents_ = shell()->web_contents(); | 70 web_contents_ = shell()->web_contents(); |
| 77 media_session_ = MediaSessionImpl::Get(web_contents_); | 71 media_session_ = MediaSessionImpl::Get(web_contents_); |
| 78 | 72 |
| 79 media_session_state_loop_runners_[MediaSessionImpl::State::ACTIVE] = | 73 media_session_state_loop_runners_[MediaSessionImpl::State::ACTIVE] = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 109 command_line->AppendSwitch(switches::kEnableDefaultMediaSession); | 103 command_line->AppendSwitch(switches::kEnableDefaultMediaSession); |
| 110 #endif // !defined(OS_ANDROID) | 104 #endif // !defined(OS_ANDROID) |
| 111 | 105 |
| 112 VisibilityTestData params = GetVisibilityTestData(); | 106 VisibilityTestData params = GetVisibilityTestData(); |
| 113 | 107 |
| 114 if (params.media_suspend == MediaSuspend::ENABLED) | 108 if (params.media_suspend == MediaSuspend::ENABLED) |
| 115 command_line->AppendSwitch(switches::kEnableMediaSuspend); | 109 command_line->AppendSwitch(switches::kEnableMediaSuspend); |
| 116 else | 110 else |
| 117 command_line->AppendSwitch(switches::kDisableMediaSuspend); | 111 command_line->AppendSwitch(switches::kDisableMediaSuspend); |
| 118 | 112 |
| 119 #if defined(OS_ANDROID) | |
| 120 Pipeline pipeline = std::tr1::get<1>(GetParam()); | |
| 121 if (pipeline == Pipeline::WMPA) | |
| 122 command_line->AppendSwitch(switches::kDisableUnifiedMediaPipeline); | |
| 123 #endif // defined(OS_ANDROID) | |
| 124 | |
| 125 if (params.background_resuming == BackgroundResuming::ENABLED) { | 113 if (params.background_resuming == BackgroundResuming::ENABLED) { |
| 126 command_line->AppendSwitchASCII(switches::kEnableFeatures, | 114 command_line->AppendSwitchASCII(switches::kEnableFeatures, |
| 127 media::kResumeBackgroundVideo.name); | 115 media::kResumeBackgroundVideo.name); |
| 128 } else { | 116 } else { |
| 129 command_line->AppendSwitchASCII(switches::kDisableFeatures, | 117 command_line->AppendSwitchASCII(switches::kDisableFeatures, |
| 130 media::kResumeBackgroundVideo.name); | 118 media::kResumeBackgroundVideo.name); |
| 131 } | 119 } |
| 132 } | 120 } |
| 133 | 121 |
| 134 const VisibilityTestData& GetVisibilityTestData() { | 122 const VisibilityTestData& GetVisibilityTestData() { |
| 135 return std::tr1::get<0>(GetParam()); | 123 return GetParam(); |
| 136 } | 124 } |
| 137 | 125 |
| 138 void StartPlayer() { | 126 void StartPlayer() { |
| 139 LoadTestPage(); | 127 LoadTestPage(); |
| 140 | 128 |
| 141 LOG(INFO) << "Starting player"; | 129 LOG(INFO) << "Starting player"; |
| 142 ClearMediaSessionStateLoopRunners(); | 130 ClearMediaSessionStateLoopRunners(); |
| 143 RunScript(kStartPlayerScript); | 131 RunScript(kStartPlayerScript); |
| 144 LOG(INFO) << "Waiting for session to be active"; | 132 LOG(INFO) << "Waiting for session to be active"; |
| 145 WaitForMediaSessionState(MediaSessionImpl::State::ACTIVE); | 133 WaitForMediaSessionState(MediaSessionImpl::State::ACTIVE); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 {MediaSuspend::DISABLED, BackgroundResuming::DISABLED, | 257 {MediaSuspend::DISABLED, BackgroundResuming::DISABLED, |
| 270 SessionState::SUSPENDED, SessionState::SUSPENDED}, | 258 SessionState::SUSPENDED, SessionState::SUSPENDED}, |
| 271 {MediaSuspend::DISABLED, BackgroundResuming::DISABLED, SessionState::ACTIVE, | 259 {MediaSuspend::DISABLED, BackgroundResuming::DISABLED, SessionState::ACTIVE, |
| 272 SessionState::ACTIVE}, | 260 SessionState::ACTIVE}, |
| 273 {MediaSuspend::DISABLED, BackgroundResuming::ENABLED, SessionState::ACTIVE, | 261 {MediaSuspend::DISABLED, BackgroundResuming::ENABLED, SessionState::ACTIVE, |
| 274 SessionState::ACTIVE}, | 262 SessionState::ACTIVE}, |
| 275 {MediaSuspend::DISABLED, BackgroundResuming::ENABLED, | 263 {MediaSuspend::DISABLED, BackgroundResuming::ENABLED, |
| 276 SessionState::SUSPENDED, SessionState::SUSPENDED}, | 264 SessionState::SUSPENDED, SessionState::SUSPENDED}, |
| 277 }; | 265 }; |
| 278 | 266 |
| 279 Pipeline kPipelines[] = { | |
| 280 Pipeline::WMPI, | |
| 281 #if defined(OS_ANDROID) | |
| 282 // Disabling WMPA tests because of https://crbug.com/646312 | |
| 283 // Pipeline::WMPA, | |
| 284 #endif // defined(OS_ANDROID) | |
| 285 }; | |
| 286 | |
| 287 } // anonymous namespace | 267 } // anonymous namespace |
| 288 | 268 |
| 289 IN_PROC_BROWSER_TEST_P(MediaSessionImplVisibilityBrowserTest, TestEntryPoint) { | 269 IN_PROC_BROWSER_TEST_P(MediaSessionImplVisibilityBrowserTest, TestEntryPoint) { |
| 290 StartPlayer(); | 270 StartPlayer(); |
| 291 MaybePausePlayer(); | 271 MaybePausePlayer(); |
| 292 HideTab(); | 272 HideTab(); |
| 293 CheckSessionStateAfterHide(); | 273 CheckSessionStateAfterHide(); |
| 294 } | 274 } |
| 295 | 275 |
| 296 INSTANTIATE_TEST_CASE_P(MediaSessionImplVisibilityBrowserTestInstances, | 276 INSTANTIATE_TEST_CASE_P(MediaSessionImplVisibilityBrowserTestInstances, |
| 297 MediaSessionImplVisibilityBrowserTest, | 277 MediaSessionImplVisibilityBrowserTest, |
| 298 ::testing::Combine(::testing::ValuesIn(kTestParams), | 278 ::testing::ValuesIn(kTestParams)); |
| 299 ::testing::ValuesIn(kPipelines))); | |
| 300 | 279 |
| 301 } // namespace content | 280 } // namespace content |
| OLD | NEW |