OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "config.h" |
| 6 #include "modules/mediasession/MediaSession.h" |
| 7 |
| 8 #include "core/dom/Document.h" |
| 9 #include "core/testing/DummyPageHolder.h" |
| 10 #include "public/platform/modules/mediasession/WebMediaSession.h" |
| 11 #include <gmock/gmock.h> |
| 12 #include <gtest/gtest.h> |
| 13 |
| 14 using testing::_; |
| 15 |
| 16 namespace blink { |
| 17 namespace { |
| 18 |
| 19 class MockWebMediaSession : public WebMediaSession { |
| 20 public: |
| 21 MOCK_METHOD1(activate, void(WebMediaSessionCommandCallback*)); |
| 22 MOCK_METHOD1(deactivate, void(WebMediaSessionCommandCallback*)); |
| 23 }; |
| 24 |
| 25 class MediaSessionTest : public ::testing::Test { |
| 26 protected: |
| 27 MediaSessionTest() |
| 28 : m_page(DummyPageHolder::create(IntSize(1, 1))) |
| 29 {} |
| 30 |
| 31 MediaSession* createMediaSession(WebMediaSession* webMediaSession) |
| 32 { |
| 33 // The MediaSession takes ownership of the WebMediaSession, and the |
| 34 // caller must take care to not end up with a stale pointer. |
| 35 return MediaSession::createForTesting(adoptPtr(webMediaSession)); |
| 36 } |
| 37 |
| 38 Document& document() { return m_page->document(); } |
| 39 ScriptState* mainScriptState() { return ScriptState::forMainWorld(document()
.frame()); } |
| 40 private: |
| 41 OwnPtr<DummyPageHolder> m_page; |
| 42 }; |
| 43 |
| 44 TEST_F(MediaSessionTest, Activate) |
| 45 { |
| 46 MockWebMediaSession* mockWebMediaSession = new MockWebMediaSession; |
| 47 MediaSession* mediaSession = createMediaSession(mockWebMediaSession); |
| 48 EXPECT_CALL(*mockWebMediaSession, activate(_)); |
| 49 |
| 50 mediaSession->activate(mainScriptState()); |
| 51 } |
| 52 |
| 53 TEST_F(MediaSessionTest, Deactivate) |
| 54 { |
| 55 MockWebMediaSession* mockWebMediaSession = new MockWebMediaSession; |
| 56 MediaSession* mediaSession = createMediaSession(mockWebMediaSession); |
| 57 EXPECT_CALL(*mockWebMediaSession, deactivate(_)); |
| 58 mediaSession->deactivate(mainScriptState()); |
| 59 } |
| 60 |
| 61 } // namespace |
| 62 } // namespace blink |
OLD | NEW |