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 "media/base/media_url_demuxer.h" | 5 #include "media/base/media_url_demuxer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.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 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 class MediaUrlDemuxerTest : public testing::Test { | 17 class MediaUrlDemuxerTest : public testing::Test { |
18 public: | 18 public: |
19 MediaUrlDemuxerTest() : default_url_("http://example.com/") {} | 19 MediaUrlDemuxerTest() |
| 20 : default_media_url_("http://example.com/file.mp4"), |
| 21 default_first_party_url_("http://example.com/") {} |
20 | 22 |
21 void InitializeTest(const GURL& gurl) { | 23 void InitializeTest(const GURL& media_url, const GURL& first_party) { |
22 demuxer_.reset( | 24 demuxer_.reset(new MediaUrlDemuxer(base::ThreadTaskRunnerHandle::Get(), |
23 new MediaUrlDemuxer(base::ThreadTaskRunnerHandle::Get(), gurl)); | 25 media_url, first_party)); |
24 } | 26 } |
25 | 27 |
26 void InitializeTest() { InitializeTest(default_url_); } | 28 void InitializeTest() { |
| 29 InitializeTest(default_media_url_, default_first_party_url_); |
| 30 } |
27 | 31 |
28 void VerifyCallbackOk(PipelineStatus status) { | 32 void VerifyCallbackOk(PipelineStatus status) { |
29 EXPECT_EQ(PIPELINE_OK, status); | 33 EXPECT_EQ(PIPELINE_OK, status); |
30 } | 34 } |
31 | 35 |
32 GURL default_url_; | 36 GURL default_media_url_; |
| 37 GURL default_first_party_url_; |
33 std::unique_ptr<Demuxer> demuxer_; | 38 std::unique_ptr<Demuxer> demuxer_; |
34 | 39 |
35 // Necessary, or else base::ThreadTaskRunnerHandle::Get() fails. | 40 // Necessary, or else base::ThreadTaskRunnerHandle::Get() fails. |
36 base::MessageLoop message_loop_; | 41 base::MessageLoop message_loop_; |
37 | 42 |
38 private: | 43 private: |
39 DISALLOW_COPY_AND_ASSIGN(MediaUrlDemuxerTest); | 44 DISALLOW_COPY_AND_ASSIGN(MediaUrlDemuxerTest); |
40 }; | 45 }; |
41 | 46 |
42 TEST_F(MediaUrlDemuxerTest, BaseCase) { | 47 TEST_F(MediaUrlDemuxerTest, BaseCase) { |
43 InitializeTest(); | 48 InitializeTest(); |
44 | 49 |
45 EXPECT_EQ(DemuxerStreamProvider::Type::URL, demuxer_->GetType()); | 50 EXPECT_EQ(DemuxerStreamProvider::Type::URL, demuxer_->GetType()); |
46 EXPECT_EQ(default_url_, demuxer_->GetUrl()); | 51 |
| 52 MediaUrlParams params = demuxer_->GetMediaUrlParams(); |
| 53 EXPECT_EQ(default_media_url_, params.media_url); |
| 54 EXPECT_EQ(default_first_party_url_, params.first_party_for_cookies); |
47 } | 55 } |
48 | 56 |
49 TEST_F(MediaUrlDemuxerTest, AcceptsEmptyStrings) { | 57 TEST_F(MediaUrlDemuxerTest, AcceptsEmptyStrings) { |
50 InitializeTest(GURL()); | 58 InitializeTest(GURL(), GURL()); |
51 | 59 |
52 EXPECT_EQ(GURL::EmptyGURL(), demuxer_->GetUrl()); | 60 MediaUrlParams params = demuxer_->GetMediaUrlParams(); |
| 61 EXPECT_EQ(GURL::EmptyGURL(), params.media_url); |
| 62 EXPECT_EQ(GURL::EmptyGURL(), params.first_party_for_cookies); |
53 } | 63 } |
54 | 64 |
55 TEST_F(MediaUrlDemuxerTest, InitializeReturnsPipelineOk) { | 65 TEST_F(MediaUrlDemuxerTest, InitializeReturnsPipelineOk) { |
56 InitializeTest(); | 66 InitializeTest(); |
57 demuxer_->Initialize(nullptr, | 67 demuxer_->Initialize(nullptr, |
58 base::Bind(&MediaUrlDemuxerTest::VerifyCallbackOk, | 68 base::Bind(&MediaUrlDemuxerTest::VerifyCallbackOk, |
59 base::Unretained(this)), | 69 base::Unretained(this)), |
60 false); | 70 false); |
61 | 71 |
62 base::RunLoop().RunUntilIdle(); | 72 base::RunLoop().RunUntilIdle(); |
63 } | 73 } |
64 | 74 |
65 TEST_F(MediaUrlDemuxerTest, SeekReturnsPipelineOk) { | 75 TEST_F(MediaUrlDemuxerTest, SeekReturnsPipelineOk) { |
66 InitializeTest(); | 76 InitializeTest(); |
67 demuxer_->Seek(base::TimeDelta(), | 77 demuxer_->Seek(base::TimeDelta(), |
68 base::Bind(&MediaUrlDemuxerTest::VerifyCallbackOk, | 78 base::Bind(&MediaUrlDemuxerTest::VerifyCallbackOk, |
69 base::Unretained(this))); | 79 base::Unretained(this))); |
70 | 80 |
71 base::RunLoop().RunUntilIdle(); | 81 base::RunLoop().RunUntilIdle(); |
72 } | 82 } |
73 | 83 |
74 } // namespace media | 84 } // namespace media |
OLD | NEW |