Chromium Code Reviews| Index: content/browser/media/session/media_session_visibility_browsertest_base.h |
| diff --git a/content/browser/media/session/media_session_visibility_browsertest_base.h b/content/browser/media/session/media_session_visibility_browsertest_base.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f5224beeb9a175d0e079ab6a9e88c3eb55c8e28f |
| --- /dev/null |
| +++ b/content/browser/media/session/media_session_visibility_browsertest_base.h |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_VISIBILITY_BROWSER_TEST_BASE_H_ |
| +#define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_VISIBILITY_BROWSER_TEST_BASE_H_ |
| + |
| +#include "content/browser/media/session/media_session.h" |
| +#include "content/public/test/content_browser_test.h" |
| +#include "content/public/test/test_utils.h" |
| + |
| +namespace base { |
| +class CommandLine; |
| +class TimeDelta; |
| +} |
| + |
| +namespace content { |
| + |
| +class WebContents; |
| + |
| +// Base class of MediaSession visibility tests. The class is intended |
| +// to be used to run tests under different configurations. Tests |
| +// should inheret from this class, set up their own command line per |
| +// their configuration, and use macro INCLUDE_TEST_FROM_BASE_CLASS to |
| +// include required tests. See |
| +// media_session_visibility_browsertest_instances.cc for examples. |
| +class MediaSessionVisibilityBrowserTestBase |
| + : public ContentBrowserTest { |
| + public: |
| + MediaSessionVisibilityBrowserTestBase(); |
| + ~MediaSessionVisibilityBrowserTestBase() override; |
| + |
| + void SetUpOnMainThread() override; |
| + void TearDownOnMainThread() override; |
| + |
| + void SetUpCommandLine(base::CommandLine* command_line) override; |
| + |
| + void LoadTestPage(); |
| + |
| + void RunScript(std::string script); |
| + |
| + void ClearMediaSessionStateLoopRunners(); |
| + |
| + void OnMediaSessionStateChanged(MediaSession::State state); |
| + |
| + // TODO(zqzhang): This method is shared with |
| + // MediaRouterIntegrationTests. Move it into a general place. |
| + void Wait(base::TimeDelta timeout); |
| + |
| + void WaitForMediaSessionState(MediaSession::State state); |
| + |
| + protected: |
| + void TestSessionInactiveWhenHiddenAfterContentPause(); |
| + void TestSessionInactiveWhenHiddenWhilePlaying(); |
| + void TestSessionSuspendedWhenHiddenAfterContentPause(); |
| + void TestSessionActiveWhenHiddenWhilePlaying(); |
| + |
| + WebContents* web_contents_; |
| + MediaSession* media_session_; |
| + // MessageLoopRunners for waiting MediaSession state to change. Note that the |
| + // MessageLoopRunners can accept Quit() before calling Run(), thus the state |
| + // change can still be captured before waiting. For example, the MediaSession |
| + // might go active immediately after calling HTMLMediaElement.play(). A test |
| + // can listen to the state change before calling play(), and then wait for the |
| + // state change after play(). |
| + std::map<MediaSession::State, scoped_refptr<MessageLoopRunner> > |
| + media_session_state_loop_runners_; |
| + scoped_ptr<base::CallbackList<void(MediaSession::State)>::Subscription> |
| + media_session_state_callback_subscription_; |
| +}; |
|
DaleCurtis
2016/03/31 16:50:26
DISALLOW_COPY_AND_ASSIGN()
Zhiqiang Zhang (Slow)
2016/03/31 19:58:39
Done.
|
| + |
| +} // namespace content |
| + |
| +#define INCLUDE_TEST_FROM_BASE_CLASS(test_fixture, test_name) \ |
|
DaleCurtis
2016/03/31 16:50:26
We generally try to avoid #define's. Can you avoid
Zhiqiang Zhang (Slow)
2016/03/31 19:58:39
Moved to .cc file
|
| + IN_PROC_BROWSER_TEST_F(test_fixture, test_name) {\ |
| + test_name();\ |
| + } |
| + |
| +#endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_VISIBILITY_BROWSER_TEST_BASE_H_ |