Chromium Code Reviews| 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 <string> | |
| 6 | |
| 5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 6 #include "base/location.h" | 8 #include "base/location.h" |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "content/browser/media/session/media_session.h" | 12 #include "content/browser/media/session/media_session.h" |
| 11 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
| 13 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
| 14 #include "content/public/test/content_browser_test.h" | 16 #include "content/public/test/content_browser_test.h" |
| 15 #include "content/public/test/content_browser_test_utils.h" | 17 #include "content/public/test/content_browser_test_utils.h" |
| 16 #include "content/public/test/test_navigation_observer.h" | 18 #include "content/public/test/test_navigation_observer.h" |
| 17 #include "content/shell/browser/shell.h" | 19 #include "content/shell/browser/shell.h" |
| 18 #include "media/base/media_switches.h" | 20 #include "media/base/media_switches.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 22 |
| 21 namespace content { | 23 namespace content { |
| 22 namespace { | 24 namespace { |
| 23 static const char kStartPlayerScript[] = | 25 static const char kStartPlayerScript[] = |
| 24 "document.getElementById('long-video').play()"; | 26 "document.getElementById('long-video').play()"; |
| 25 static const char kPausePlayerScript[] = | 27 static const char kPausePlayerScript[] = |
| 26 "document.getElementById('long-video').pause()"; | 28 "document.getElementById('long-video').pause()"; |
| 29 | |
| 30 struct VisibilityTestData { | |
| 31 bool is_enable_media_suspend; | |
|
whywhat
2016/09/02 19:49:26
nit: rename is_enable_xxx to xxx_enabled (or is_xx
Zhiqiang Zhang (Slow)
2016/09/05 12:21:53
I'm using enums now, and the problem got addressed
| |
| 32 bool is_enable_unified_pipeline; | |
| 33 bool is_enable_background_resuming_video; | |
| 34 std::string test_method_name; | |
| 35 }; | |
| 36 | |
| 27 } | 37 } |
| 28 | 38 |
| 29 | 39 |
| 30 // Base class of MediaSession visibility tests. The class is intended | 40 // Base class of MediaSession visibility tests. The class is intended |
| 31 // to be used to run tests under different configurations. Tests | 41 // to be used to run tests under different configurations. Tests |
| 32 // should inheret from this class, set up their own command line per | 42 // should inheret from this class, set up their own command line per |
| 33 // their configuration, and use macro INCLUDE_TEST_FROM_BASE_CLASS to | 43 // their configuration, and use macro INCLUDE_TEST_FROM_BASE_CLASS to |
| 34 // include required tests. See | 44 // include required tests. See |
| 35 // media_session_visibility_browsertest_instances.cc for examples. | 45 // media_session_visibility_browsertest_instances.cc for examples. |
| 36 class MediaSessionVisibilityBrowserTest | 46 class MediaSessionVisibilityBrowserTest |
| 37 : public ContentBrowserTest { | 47 : public ContentBrowserTest, |
| 48 public ::testing::WithParamInterface<VisibilityTestData> { | |
| 38 public: | 49 public: |
| 39 MediaSessionVisibilityBrowserTest() = default; | 50 MediaSessionVisibilityBrowserTest() = default; |
| 40 ~MediaSessionVisibilityBrowserTest() override = default; | 51 ~MediaSessionVisibilityBrowserTest() override = default; |
| 41 | 52 |
| 42 void SetUpOnMainThread() override { | 53 void SetUpOnMainThread() override { |
| 43 ContentBrowserTest::SetUpOnMainThread(); | 54 ContentBrowserTest::SetUpOnMainThread(); |
| 44 web_contents_ = shell()->web_contents(); | 55 web_contents_ = shell()->web_contents(); |
| 45 media_session_ = MediaSession::Get(web_contents_); | 56 media_session_ = MediaSession::Get(web_contents_); |
| 46 | 57 |
| 47 media_session_state_loop_runners_[MediaSession::State::ACTIVE] = | 58 media_session_state_loop_runners_[MediaSession::State::ACTIVE] = |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 72 disabled_features = media::kResumeBackgroundVideo.name; | 83 disabled_features = media::kResumeBackgroundVideo.name; |
| 73 | 84 |
| 74 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 85 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 75 feature_list->InitializeFromCommandLine( | 86 feature_list->InitializeFromCommandLine( |
| 76 enabled_features, disabled_features); | 87 enabled_features, disabled_features); |
| 77 base::FeatureList::ClearInstanceForTesting(); | 88 base::FeatureList::ClearInstanceForTesting(); |
| 78 base::FeatureList::SetInstance(std::move(feature_list)); | 89 base::FeatureList::SetInstance(std::move(feature_list)); |
| 79 } | 90 } |
| 80 | 91 |
| 81 void SetUpCommandLine(base::CommandLine* command_line) override { | 92 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 82 EnableDisableResumingBackgroundVideos(false); | |
| 83 | |
| 84 command_line->AppendSwitch( | 93 command_line->AppendSwitch( |
| 85 switches::kDisableGestureRequirementForMediaPlayback); | 94 switches::kDisableGestureRequirementForMediaPlayback); |
| 86 #if !defined(OS_ANDROID) | 95 #if !defined(OS_ANDROID) |
| 87 command_line->AppendSwitch( | 96 command_line->AppendSwitch( |
| 88 switches::kEnableDefaultMediaSession); | 97 switches::kEnableDefaultMediaSession); |
| 89 #endif // !defined(OS_ANDROID) | 98 #endif // !defined(OS_ANDROID) |
| 99 | |
| 100 VisibilityTestData params = GetParam(); | |
| 101 | |
| 102 if (params.is_enable_media_suspend) | |
| 103 command_line->AppendSwitch(switches::kEnableMediaSuspend); | |
| 104 else | |
| 105 command_line->AppendSwitch(switches::kDisableMediaSuspend); | |
| 106 | |
| 107 #if defined(OS_ANDROID) | |
| 108 if (!params.is_enable_unified_pipeline) | |
| 109 command_line->AppendSwitch(switches::kDisableUnifiedMediaPipeline); | |
| 110 #endif // defined(OS_ANDROID) | |
| 111 | |
| 112 if (params.is_enable_background_resuming_video) { | |
| 113 command_line->AppendSwitchASCII(switches::kEnableFeatures, | |
| 114 media::kResumeBackgroundVideo.name); | |
| 115 } else { | |
| 116 command_line->AppendSwitchASCII(switches::kDisableFeatures, | |
| 117 media::kResumeBackgroundVideo.name); | |
| 118 } | |
| 90 } | 119 } |
| 91 | 120 |
| 92 void LoadTestPage() { | 121 void LoadTestPage() { |
| 93 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); | 122 TestNavigationObserver navigation_observer(shell()->web_contents(), 1); |
| 94 shell()->LoadURL(GetTestUrl("media/session", "media-session.html")); | 123 shell()->LoadURL(GetTestUrl("media/session", "media-session.html")); |
| 95 navigation_observer.Wait(); | 124 navigation_observer.Wait(); |
| 96 } | 125 } |
| 97 | 126 |
| 98 void RunScript(const std::string& script) { | 127 void RunScript(const std::string& script) { |
| 99 ASSERT_TRUE(ExecuteScript(web_contents_->GetMainFrame(), script)); | 128 ASSERT_TRUE(ExecuteScript(web_contents_->GetMainFrame(), script)); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 // state change after play(). | 269 // state change after play(). |
| 241 std::map<MediaSession::State, scoped_refptr<MessageLoopRunner> > | 270 std::map<MediaSession::State, scoped_refptr<MessageLoopRunner> > |
| 242 media_session_state_loop_runners_; | 271 media_session_state_loop_runners_; |
| 243 std::unique_ptr<base::CallbackList<void(MediaSession::State)>::Subscription> | 272 std::unique_ptr<base::CallbackList<void(MediaSession::State)>::Subscription> |
| 244 media_session_state_callback_subscription_; | 273 media_session_state_callback_subscription_; |
| 245 | 274 |
| 246 private: | 275 private: |
| 247 DISALLOW_COPY_AND_ASSIGN(MediaSessionVisibilityBrowserTest); | 276 DISALLOW_COPY_AND_ASSIGN(MediaSessionVisibilityBrowserTest); |
| 248 }; | 277 }; |
| 249 | 278 |
| 250 // Helper macro to include tests from the base class. | 279 IN_PROC_BROWSER_TEST_P(MediaSessionVisibilityBrowserTest, |
| 251 #define INCLUDE_TEST_FROM_BASE_CLASS(test_fixture, test_name) \ | 280 TestEntryPoint) { |
| 252 IN_PROC_BROWSER_TEST_F(test_fixture, test_name) { \ | 281 std::string test_method_name = GetParam().test_method_name; |
| 253 test_name(); \ | 282 LOG(INFO) << "Running test: " << test_method_name; |
| 283 | |
| 284 if (test_method_name == "TestSessionInactiveWhenHiddenAfterContentPause") { | |
|
whywhat
2016/09/02 19:49:26
Can we generalize to what commands to run on the p
Zhiqiang Zhang (Slow)
2016/09/05 12:21:53
Done in another way. Please check the changes.
| |
| 285 TestSessionInactiveWhenHiddenAfterContentPause(); | |
| 286 } else if (test_method_name == "TestSessionInactiveWhenHiddenWhilePlaying") { | |
| 287 TestSessionInactiveWhenHiddenWhilePlaying(); | |
| 288 } else if (test_method_name == "TestSessionSuspendedWhenHiddenWhilePlaying") { | |
| 289 TestSessionSuspendedWhenHiddenWhilePlaying(); | |
| 290 } else if (test_method_name == | |
| 291 "TestSessionSuspendedWhenHiddenAfterContentPause") { | |
| 292 TestSessionSuspendedWhenHiddenAfterContentPause(); | |
| 293 } else if (test_method_name == "TestSessionActiveWhenHiddenWhilePlaying") { | |
| 294 TestSessionActiveWhenHiddenWhilePlaying(); | |
| 295 } else { | |
| 296 FAIL() << "unrecognized test method"; | |
| 254 } | 297 } |
| 298 } | |
| 255 | 299 |
| 256 /////////////////////////////////////////////////////////////////////////////// | 300 namespace { |
| 257 // Configuration instances. | |
| 258 | 301 |
| 259 // UnifiedPipeline + SuspendOnHide | 302 VisibilityTestData kTestParams[] = { |
| 260 class MediaSessionVisibilityBrowserTest_UnifiedPipeline_SuspendOnHide : | 303 { true, true, false, "TestSessionInactiveWhenHiddenAfterContentPause" }, |
|
whywhat
2016/09/02 19:49:26
The combination list is incomplete. You definitely
Zhiqiang Zhang (Slow)
2016/09/05 12:21:53
Now WMPI and WMPA have the same instances.
| |
| 261 public MediaSessionVisibilityBrowserTest { | 304 { true, true, false, "TestSessionInactiveWhenHiddenWhilePlaying" }, |
| 262 void SetUpCommandLine(base::CommandLine* command_line) override { | 305 { true, true, true, "TestSessionSuspendedWhenHiddenWhilePlaying" }, |
| 263 MediaSessionVisibilityBrowserTest::SetUpCommandLine(command_line); | 306 { true, true, true, "TestSessionSuspendedWhenHiddenAfterContentPause" }, |
| 264 #if !defined(OS_ANDROID) | 307 { false, true, false, "TestSessionSuspendedWhenHiddenAfterContentPause" }, |
| 265 command_line->AppendSwitch(switches::kEnableMediaSuspend); | 308 { false, true, false, "TestSessionActiveWhenHiddenWhilePlaying" }, |
| 309 { false, true, true, "TestSessionActiveWhenHiddenWhilePlaying" }, | |
| 310 | |
| 311 #if defined(OS_ANDROID) | |
| 312 { true, false, false, "TestSessionInactiveWhenHiddenAfterContentPause" }, | |
| 313 { true, false, false, "TestSessionInactiveWhenHiddenWhilePlaying" }, | |
| 314 { false, false, false, "TestSessionSuspendedWhenHiddenAfterContentPause" }, | |
| 315 { false, false, false, "TestSessionActiveWhenHiddenWhilePlaying" }, | |
|
whywhat
2016/09/02 19:49:26
These tests never check that background video can
Zhiqiang Zhang (Slow)
2016/09/05 12:21:53
Now WMPI and WMPA have the same instances.
| |
| 266 #endif // defined(OS_ANDROID) | 316 #endif // defined(OS_ANDROID) |
| 267 } | 317 |
| 268 }; | 318 }; |
| 269 | 319 |
| 270 INCLUDE_TEST_FROM_BASE_CLASS( | 320 } // anonymous namespace |
| 271 MediaSessionVisibilityBrowserTest_UnifiedPipeline_SuspendOnHide, | |
| 272 TestSessionInactiveWhenHiddenAfterContentPause) | |
| 273 INCLUDE_TEST_FROM_BASE_CLASS( | |
| 274 MediaSessionVisibilityBrowserTest_UnifiedPipeline_SuspendOnHide, | |
| 275 TestSessionInactiveWhenHiddenWhilePlaying) | |
| 276 | 321 |
| 277 IN_PROC_BROWSER_TEST_F( | 322 INSTANTIATE_TEST_CASE_P(MediaSessionVisibilityBrowserTestInstances, |
| 278 MediaSessionVisibilityBrowserTest_UnifiedPipeline_SuspendOnHide, | 323 MediaSessionVisibilityBrowserTest, |
| 279 TestSessionSuspendedWhenHiddenWhilePlaying) { | 324 testing::ValuesIn(kTestParams)); |
| 280 EnableDisableResumingBackgroundVideos(true); | |
| 281 TestSessionSuspendedWhenHiddenWhilePlaying(); | |
| 282 } | |
| 283 | |
| 284 IN_PROC_BROWSER_TEST_F( | |
| 285 MediaSessionVisibilityBrowserTest_UnifiedPipeline_SuspendOnHide, | |
| 286 TestSessionSuspendedWhenHiddenAfterContentPause) { | |
| 287 EnableDisableResumingBackgroundVideos(true); | |
| 288 TestSessionSuspendedWhenHiddenAfterContentPause(); | |
| 289 } | |
| 290 | |
| 291 // UnifiedPipeline + NosuspendOnHide | |
| 292 class MediaSessionVisibilityBrowserTest_UnifiedPipeline_NosuspendOnHide : | |
| 293 public MediaSessionVisibilityBrowserTest { | |
| 294 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 295 MediaSessionVisibilityBrowserTest::SetUpCommandLine(command_line); | |
| 296 #if defined(OS_ANDROID) | |
| 297 command_line->AppendSwitch(switches::kDisableMediaSuspend); | |
| 298 #endif // defined(OS_ANDROID) | |
| 299 } | |
| 300 }; | |
| 301 | |
| 302 INCLUDE_TEST_FROM_BASE_CLASS( | |
| 303 MediaSessionVisibilityBrowserTest_UnifiedPipeline_NosuspendOnHide, | |
| 304 TestSessionSuspendedWhenHiddenAfterContentPause) | |
| 305 INCLUDE_TEST_FROM_BASE_CLASS( | |
| 306 MediaSessionVisibilityBrowserTest_UnifiedPipeline_NosuspendOnHide, | |
| 307 TestSessionActiveWhenHiddenWhilePlaying) | |
| 308 | |
| 309 IN_PROC_BROWSER_TEST_F( | |
| 310 MediaSessionVisibilityBrowserTest_UnifiedPipeline_NosuspendOnHide, | |
| 311 TestSessionActiveWhenHiddenWhilePlayingWithResume) { | |
| 312 EnableDisableResumingBackgroundVideos(true); | |
| 313 TestSessionActiveWhenHiddenWhilePlaying(); | |
| 314 } | |
| 315 | |
| 316 #if defined(OS_ANDROID) | |
| 317 // AndroidPipeline + SuspendOnHide | |
| 318 class MediaSessionVisibilityBrowserTest_AndroidPipeline_SuspendOnHide : | |
| 319 public MediaSessionVisibilityBrowserTest { | |
| 320 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 321 MediaSessionVisibilityBrowserTest::SetUpCommandLine(command_line); | |
| 322 command_line->AppendSwitch(switches::kDisableUnifiedMediaPipeline); | |
| 323 } | |
| 324 }; | |
| 325 | |
| 326 // The following tests are flaky. Re-enabling with logging to see what's | |
| 327 // happening on the bots. See crbug.com/619096. | |
| 328 INCLUDE_TEST_FROM_BASE_CLASS( | |
| 329 MediaSessionVisibilityBrowserTest_AndroidPipeline_SuspendOnHide, | |
| 330 TestSessionInactiveWhenHiddenAfterContentPause) | |
| 331 INCLUDE_TEST_FROM_BASE_CLASS( | |
| 332 MediaSessionVisibilityBrowserTest_AndroidPipeline_SuspendOnHide, | |
| 333 TestSessionInactiveWhenHiddenWhilePlaying) | |
| 334 | |
| 335 // AndroidPipeline + NosuspendOnHide | |
| 336 class MediaSessionVisibilityBrowserTest_AndroidPipeline_NosuspendOnHide : | |
| 337 public MediaSessionVisibilityBrowserTest { | |
| 338 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 339 MediaSessionVisibilityBrowserTest::SetUpCommandLine(command_line); | |
| 340 command_line->AppendSwitch(switches::kDisableUnifiedMediaPipeline); | |
| 341 command_line->AppendSwitch(switches::kDisableMediaSuspend); | |
| 342 } | |
| 343 }; | |
| 344 | |
| 345 // The following tests are flaky. Re-enabling with logging to see what's | |
| 346 // happening on the bots. See crbug.com/619096. | |
| 347 INCLUDE_TEST_FROM_BASE_CLASS( | |
| 348 MediaSessionVisibilityBrowserTest_AndroidPipeline_NosuspendOnHide, | |
| 349 TestSessionSuspendedWhenHiddenAfterContentPause) | |
| 350 INCLUDE_TEST_FROM_BASE_CLASS( | |
| 351 MediaSessionVisibilityBrowserTest_AndroidPipeline_NosuspendOnHide, | |
| 352 TestSessionActiveWhenHiddenWhilePlaying) | |
| 353 | |
| 354 #endif // defined(OS_ANDROID) | |
| 355 | 325 |
| 356 } // namespace content | 326 } // namespace content |
| OLD | NEW |