OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "modules/mediasession/MediaSession.h" | 5 #include "modules/mediasession/MediaSession.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/testing/DummyPageHolder.h" | 8 #include "core/testing/DummyPageHolder.h" |
9 #include "modules/mediasession/MediaMetadata.h" | 9 #include "modules/mediasession/MediaMetadata.h" |
10 #include "modules/mediasession/MediaMetadataInit.h" | 10 #include "modules/mediasession/MediaMetadataInit.h" |
11 #include "public/platform/modules/mediasession/WebMediaSession.h" | 11 #include "public/platform/modules/mediasession/WebMediaSession.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "wtf/PtrUtil.h" | |
15 #include <memory> | |
16 | 14 |
17 using ::testing::_; | 15 using ::testing::_; |
18 using ::testing::Invoke; | 16 using ::testing::Invoke; |
19 | 17 |
20 namespace blink { | 18 namespace blink { |
21 | 19 |
22 class MediaSessionTest : public ::testing::Test { | 20 class MediaSessionTest : public ::testing::Test { |
23 protected: | 21 protected: |
24 MediaSessionTest() | 22 MediaSessionTest() |
25 : m_page(DummyPageHolder::create(IntSize(1, 1))) | 23 : m_page(DummyPageHolder::create(IntSize(1, 1))) |
26 {} | 24 {} |
27 | 25 |
28 MediaSession* createMediaSession(WebMediaSession* webMediaSession) | 26 MediaSession* createMediaSession(WebMediaSession* webMediaSession) |
29 { | 27 { |
30 // The MediaSession takes ownership of the WebMediaSession, and the | 28 // The MediaSession takes ownership of the WebMediaSession, and the |
31 // caller must take care to not end up with a stale pointer. | 29 // caller must take care to not end up with a stale pointer. |
32 return new MediaSession(wrapUnique(webMediaSession)); | 30 return new MediaSession(adoptPtr(webMediaSession)); |
33 } | 31 } |
34 | 32 |
35 Document& document() { return m_page->document(); } | 33 Document& document() { return m_page->document(); } |
36 ScriptState* mainScriptState() { return ScriptState::forMainWorld(document()
.frame()); } | 34 ScriptState* mainScriptState() { return ScriptState::forMainWorld(document()
.frame()); } |
37 private: | 35 private: |
38 std::unique_ptr<DummyPageHolder> m_page; | 36 OwnPtr<DummyPageHolder> m_page; |
39 }; | 37 }; |
40 | 38 |
41 namespace { | 39 namespace { |
42 | 40 |
43 class MockWebMediaSession : public WebMediaSession { | 41 class MockWebMediaSession : public WebMediaSession { |
44 public: | 42 public: |
45 MOCK_METHOD1(activate, void(WebMediaSessionActivateCallback*)); | 43 MOCK_METHOD1(activate, void(WebMediaSessionActivateCallback*)); |
46 MOCK_METHOD1(deactivate, void(WebMediaSessionDeactivateCallback*)); | 44 MOCK_METHOD1(deactivate, void(WebMediaSessionDeactivateCallback*)); |
47 MOCK_METHOD1(setMetadata, void(const WebMediaMetadata*)); | 45 MOCK_METHOD1(setMetadata, void(const WebMediaMetadata*)); |
48 }; | 46 }; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 MediaSession* mediaSession = createMediaSession(mockWebMediaSession); | 90 MediaSession* mediaSession = createMediaSession(mockWebMediaSession); |
93 | 91 |
94 EXPECT_CALL(*mockWebMediaSession, setMetadata(testing::NotNull())); | 92 EXPECT_CALL(*mockWebMediaSession, setMetadata(testing::NotNull())); |
95 mediaSession->setMetadata(MediaMetadata::create(&document(), MediaMetadataIn
it())); | 93 mediaSession->setMetadata(MediaMetadata::create(&document(), MediaMetadataIn
it())); |
96 | 94 |
97 EXPECT_NE(nullptr, mediaSession->metadata()); | 95 EXPECT_NE(nullptr, mediaSession->metadata()); |
98 } | 96 } |
99 | 97 |
100 } // namespace | 98 } // namespace |
101 } // namespace blink | 99 } // namespace blink |
OLD | NEW |