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" |
| 11 #include "base/test/scoped_feature_list.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
12 #include "content/browser/media/session/media_session_impl.h" | 13 #include "content/browser/media/session/media_session_impl.h" |
13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
14 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
15 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
16 #include "content/public/test/content_browser_test.h" | 17 #include "content/public/test/content_browser_test.h" |
17 #include "content/public/test/content_browser_test_utils.h" | 18 #include "content/public/test/content_browser_test_utils.h" |
18 #include "content/public/test/test_navigation_observer.h" | 19 #include "content/public/test/test_navigation_observer.h" |
19 #include "content/shell/browser/shell.h" | 20 #include "content/shell/browser/shell.h" |
20 #include "media/base/media_switches.h" | 21 #include "media/base/media_switches.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 base::Unretained(this))); | 89 base::Unretained(this))); |
89 } | 90 } |
90 | 91 |
91 void TearDownOnMainThread() override { | 92 void TearDownOnMainThread() override { |
92 // Unsubscribe the callback subscription before tearing down, so that the | 93 // Unsubscribe the callback subscription before tearing down, so that the |
93 // CallbackList in MediaSession will be empty when it is destroyed. | 94 // CallbackList in MediaSession will be empty when it is destroyed. |
94 media_session_state_callback_subscription_.reset(); | 95 media_session_state_callback_subscription_.reset(); |
95 } | 96 } |
96 | 97 |
97 void EnableDisableResumingBackgroundVideos(bool enable) { | 98 void EnableDisableResumingBackgroundVideos(bool enable) { |
98 std::string enabled_features; | |
99 std::string disabled_features; | |
100 if (enable) | 99 if (enable) |
101 enabled_features = media::kResumeBackgroundVideo.name; | 100 scoped_feature_list_.InitAndEnableFeature(media::kResumeBackgroundVideo); |
102 else | 101 else |
103 disabled_features = media::kResumeBackgroundVideo.name; | 102 scoped_feature_list_.InitAndDisableFeature(media::kResumeBackgroundVideo); |
104 | |
105 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
106 feature_list->InitializeFromCommandLine(enabled_features, | |
107 disabled_features); | |
108 base::FeatureList::ClearInstanceForTesting(); | |
109 base::FeatureList::SetInstance(std::move(feature_list)); | |
110 } | 103 } |
111 | 104 |
112 void SetUpCommandLine(base::CommandLine* command_line) override { | 105 void SetUpCommandLine(base::CommandLine* command_line) override { |
113 command_line->AppendSwitch( | 106 command_line->AppendSwitch( |
114 switches::kDisableGestureRequirementForMediaPlayback); | 107 switches::kDisableGestureRequirementForMediaPlayback); |
115 #if !defined(OS_ANDROID) | 108 #if !defined(OS_ANDROID) |
116 command_line->AppendSwitch(switches::kEnableDefaultMediaSession); | 109 command_line->AppendSwitch(switches::kEnableDefaultMediaSession); |
117 #endif // !defined(OS_ANDROID) | 110 #endif // !defined(OS_ANDROID) |
118 | 111 |
119 VisibilityTestData params = GetVisibilityTestData(); | 112 VisibilityTestData params = GetVisibilityTestData(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // MessageLoopRunners can accept Quit() before calling Run(), thus the state | 243 // MessageLoopRunners can accept Quit() before calling Run(), thus the state |
251 // change can still be captured before waiting. For example, the MediaSession | 244 // change can still be captured before waiting. For example, the MediaSession |
252 // might go active immediately after calling HTMLMediaElement.play(). A test | 245 // might go active immediately after calling HTMLMediaElement.play(). A test |
253 // can listen to the state change before calling play(), and then wait for the | 246 // can listen to the state change before calling play(), and then wait for the |
254 // state change after play(). | 247 // state change after play(). |
255 std::map<MediaSessionImpl::State, scoped_refptr<MessageLoopRunner>> | 248 std::map<MediaSessionImpl::State, scoped_refptr<MessageLoopRunner>> |
256 media_session_state_loop_runners_; | 249 media_session_state_loop_runners_; |
257 std::unique_ptr< | 250 std::unique_ptr< |
258 base::CallbackList<void(MediaSessionImpl::State)>::Subscription> | 251 base::CallbackList<void(MediaSessionImpl::State)>::Subscription> |
259 media_session_state_callback_subscription_; | 252 media_session_state_callback_subscription_; |
| 253 base::test::ScopedFeatureList scoped_feature_list_; |
260 | 254 |
261 DISALLOW_COPY_AND_ASSIGN(MediaSessionImplVisibilityBrowserTest); | 255 DISALLOW_COPY_AND_ASSIGN(MediaSessionImplVisibilityBrowserTest); |
262 }; | 256 }; |
263 | 257 |
264 namespace { | 258 namespace { |
265 | 259 |
266 VisibilityTestData kTestParams[] = { | 260 VisibilityTestData kTestParams[] = { |
267 {MediaSuspend::ENABLED, BackgroundResuming::DISABLED, | 261 {MediaSuspend::ENABLED, BackgroundResuming::DISABLED, |
268 SessionState::SUSPENDED, SessionState::INACTIVE}, | 262 SessionState::SUSPENDED, SessionState::INACTIVE}, |
269 {MediaSuspend::ENABLED, BackgroundResuming::DISABLED, SessionState::ACTIVE, | 263 {MediaSuspend::ENABLED, BackgroundResuming::DISABLED, SessionState::ACTIVE, |
(...skipping 28 matching lines...) Expand all Loading... |
298 HideTab(); | 292 HideTab(); |
299 CheckSessionStateAfterHide(); | 293 CheckSessionStateAfterHide(); |
300 } | 294 } |
301 | 295 |
302 INSTANTIATE_TEST_CASE_P(MediaSessionImplVisibilityBrowserTestInstances, | 296 INSTANTIATE_TEST_CASE_P(MediaSessionImplVisibilityBrowserTestInstances, |
303 MediaSessionImplVisibilityBrowserTest, | 297 MediaSessionImplVisibilityBrowserTest, |
304 ::testing::Combine(::testing::ValuesIn(kTestParams), | 298 ::testing::Combine(::testing::ValuesIn(kTestParams), |
305 ::testing::ValuesIn(kPipelines))); | 299 ::testing::ValuesIn(kPipelines))); |
306 | 300 |
307 } // namespace content | 301 } // namespace content |
OLD | NEW |