| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/platform_thread.h" | 7 #include "base/platform_thread.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/waitable_event.h" | 9 #include "base/waitable_event.h" |
| 10 #include "media/base/pipeline_impl.h" | 10 #include "media/base/pipeline_impl.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 factories->AddFactory(MockAudioRenderer::CreateFactory(config)); | 39 factories->AddFactory(MockAudioRenderer::CreateFactory(config)); |
| 40 factories->AddFactory(MockVideoDecoder::CreateFactory(config)); | 40 factories->AddFactory(MockVideoDecoder::CreateFactory(config)); |
| 41 factories->AddFactory(MockVideoRenderer::CreateFactory(config)); | 41 factories->AddFactory(MockVideoRenderer::CreateFactory(config)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 // TODO(ralphl): Get rid of single character variable names in these tests. | 46 // TODO(ralphl): Get rid of single character variable names in these tests. |
| 47 TEST(PipelineImplTest, Initialization) { | 47 TEST(PipelineImplTest, Initialization) { |
| 48 std::string u(""); | 48 std::string u(""); |
| 49 |
| 50 // This test hangs during initialization of the data source (it never |
| 51 // calls InitializationComplete). Make sure we tear down the pipeline |
| 52 // propertly. |
| 49 PipelineImpl p; | 53 PipelineImpl p; |
| 50 InitializationHelper h; | 54 InitializationHelper h; |
| 51 MockFilterConfig config; | 55 MockFilterConfig config; |
| 52 config.data_source_behavior = media::MOCK_DATA_SOURCE_NEVER_INIT; | 56 config.data_source_behavior = media::MOCK_DATA_SOURCE_NEVER_INIT; |
| 53 h.Start(&p, MockDataSource::CreateFactory(&config), u); | 57 h.Start(&p, MockDataSource::CreateFactory(&config), u, |
| 54 h.TimedWait(base::TimeDelta::FromMilliseconds(300)); | 58 media::PIPELINE_OK, true); |
| 55 EXPECT_TRUE(h.waiting_for_callback()); | |
| 56 EXPECT_FALSE(p.IsInitialized()); | |
| 57 EXPECT_TRUE(media::PIPELINE_OK == p.GetError()); | |
| 58 p.Stop(); | 59 p.Stop(); |
| 59 EXPECT_FALSE(h.waiting_for_callback()); | 60 EXPECT_FALSE(h.waiting_for_callback()); |
| 60 EXPECT_FALSE(h.callback_success_status()); | 61 EXPECT_FALSE(h.callback_success_status()); |
| 61 EXPECT_TRUE(media::PIPELINE_OK == p.GetError()); | 62 EXPECT_TRUE(media::PIPELINE_OK == p.GetError()); |
| 62 | 63 |
| 64 // This test should not hang. Should return an error indicating that we are |
| 65 // missing a requried filter. |
| 63 config.data_source_behavior = media::MOCK_DATA_SOURCE_TASK_INIT; | 66 config.data_source_behavior = media::MOCK_DATA_SOURCE_TASK_INIT; |
| 64 h.Start(&p, MockDataSource::CreateFactory(&config), u); | 67 h.Start(&p, MockDataSource::CreateFactory(&config), u, |
| 65 h.TimedWait(base::TimeDelta::FromSeconds(5)); | 68 media::PIPELINE_ERROR_REQUIRED_FILTER_MISSING); |
| 66 EXPECT_FALSE(h.waiting_for_callback()); | |
| 67 EXPECT_FALSE(h.callback_success_status()); | |
| 68 EXPECT_FALSE(p.IsInitialized()); | |
| 69 EXPECT_FALSE(media::PIPELINE_OK == p.GetError()); | |
| 70 p.Stop(); | 69 p.Stop(); |
| 71 | 70 |
| 72 config.data_source_behavior = media::MOCK_DATA_SOURCE_ERROR_IN_INIT; | 71 // This test should return a specific error from the mock data source. |
| 73 h.Start(&p, MockDataSource::CreateFactory(&config), u); | 72 config.data_source_behavior = media::MOCK_DATA_SOURCE_URL_ERROR_IN_INIT; |
| 74 h.TimedWait(base::TimeDelta::FromSeconds(5)); | 73 h.Start(&p, MockDataSource::CreateFactory(&config), u, |
| 75 EXPECT_FALSE(h.waiting_for_callback()); | 74 media::PIPELINE_ERROR_URL_NOT_FOUND); |
| 76 EXPECT_FALSE(h.callback_success_status()); | |
| 77 EXPECT_FALSE(p.IsInitialized()); | |
| 78 EXPECT_FALSE(media::PIPELINE_OK == p.GetError()); | |
| 79 p.Stop(); | 75 p.Stop(); |
| 80 } | 76 } |
| 81 | 77 |
| 82 TEST(PipelineImplTest, MockAudioPipeline) { | 78 TEST(PipelineImplTest, MockAudioPipeline) { |
| 83 std::string url(""); | 79 std::string url(""); |
| 84 PipelineImpl p; | 80 PipelineImpl p; |
| 85 MockFilterConfig config; | 81 MockFilterConfig config; |
| 86 config.has_video = false; | 82 config.has_video = false; |
| 87 scoped_refptr<FilterFactoryCollection> c = new FilterFactoryCollection(); | 83 scoped_refptr<FilterFactoryCollection> c = new FilterFactoryCollection(); |
| 88 AddAllMockFilters(c, &config); | 84 AddAllMockFilters(c, &config); |
| 89 InitializationHelper h; | 85 InitializationHelper h; |
| 90 h.Start(&p, c, url); | 86 h.Start(&p, c, url); |
| 91 h.TimedWait(base::TimeDelta::FromSeconds(5)); | |
| 92 EXPECT_FALSE(h.waiting_for_callback()); | |
| 93 EXPECT_TRUE(h.callback_success_status()); | |
| 94 EXPECT_TRUE(p.IsInitialized()); | |
| 95 EXPECT_TRUE(media::PIPELINE_OK == p.GetError()); | |
| 96 size_t width, height; | 87 size_t width, height; |
| 97 p.GetVideoSize(&width, &height); | 88 p.GetVideoSize(&width, &height); |
| 89 EXPECT_TRUE(p.IsRendered(media::mime_type::kMajorTypeAudio)); |
| 90 EXPECT_FALSE(p.IsRendered(media::mime_type::kMajorTypeVideo)); |
| 98 EXPECT_EQ(0u, width); | 91 EXPECT_EQ(0u, width); |
| 99 EXPECT_EQ(0u, height); | 92 EXPECT_EQ(0u, height); |
| 100 p.SetPlaybackRate(1.0f); | 93 p.SetPlaybackRate(1.0f); |
| 101 p.SetVolume(0.5f); | 94 p.SetVolume(0.5f); |
| 102 p.Stop(); | 95 p.Stop(); |
| 103 EXPECT_FALSE(p.IsInitialized()); | 96 EXPECT_FALSE(p.IsInitialized()); |
| 104 } | 97 } |
| 105 | 98 |
| 106 TEST(PipelineImplTest, MockVideoPipeline) { | 99 TEST(PipelineImplTest, MockVideoPipeline) { |
| 107 std::string url(""); | 100 std::string url(""); |
| 108 PipelineImpl p; | 101 PipelineImpl p; |
| 109 scoped_refptr<FilterFactoryCollection> c = new FilterFactoryCollection(); | 102 scoped_refptr<FilterFactoryCollection> c = new FilterFactoryCollection(); |
| 110 MockFilterConfig config; | 103 MockFilterConfig config; |
| 111 AddAllMockFilters(c, &config); | 104 AddAllMockFilters(c, &config); |
| 112 InitializationHelper h; | 105 InitializationHelper h; |
| 113 h.Start(&p, c, url); | 106 h.Start(&p, c, url); |
| 114 h.TimedWait(base::TimeDelta::FromSeconds(5)); | |
| 115 EXPECT_FALSE(h.waiting_for_callback()); | |
| 116 EXPECT_TRUE(h.callback_success_status()); | |
| 117 EXPECT_TRUE(p.IsInitialized()); | |
| 118 EXPECT_TRUE(media::PIPELINE_OK == p.GetError()); | |
| 119 size_t width, height; | 107 size_t width, height; |
| 120 p.GetVideoSize(&width, &height); | 108 p.GetVideoSize(&width, &height); |
| 121 EXPECT_EQ(config.video_width, width); | 109 EXPECT_EQ(config.video_width, width); |
| 122 EXPECT_EQ(config.video_height, height); | 110 EXPECT_EQ(config.video_height, height); |
| 111 EXPECT_TRUE(p.IsRendered(media::mime_type::kMajorTypeAudio)); |
| 112 EXPECT_TRUE(p.IsRendered(media::mime_type::kMajorTypeVideo)); |
| 123 p.SetPlaybackRate(1.0f); | 113 p.SetPlaybackRate(1.0f); |
| 124 p.SetVolume(0.5f); | 114 p.SetVolume(0.5f); |
| 125 p.Stop(); | 115 p.Stop(); |
| 126 EXPECT_FALSE(p.IsInitialized()); | 116 EXPECT_FALSE(p.IsInitialized()); |
| 127 } | 117 } |
| 128 | 118 |
| 119 TEST(PipelineImplTest, MockVideoOnlyPipeline) { |
| 120 std::string url(""); |
| 121 PipelineImpl p; |
| 122 scoped_refptr<FilterFactoryCollection> c = new FilterFactoryCollection(); |
| 123 MockFilterConfig config; |
| 124 config.has_audio = false; |
| 125 AddAllMockFilters(c, &config); |
| 126 InitializationHelper h; |
| 127 h.Start(&p, c, url); |
| 128 size_t width, height; |
| 129 p.GetVideoSize(&width, &height); |
| 130 EXPECT_EQ(config.video_width, width); |
| 131 EXPECT_EQ(config.video_height, height); |
| 132 EXPECT_FALSE(p.IsRendered(media::mime_type::kMajorTypeAudio)); |
| 133 EXPECT_TRUE(p.IsRendered(media::mime_type::kMajorTypeVideo)); |
| 134 p.SetPlaybackRate(1.0f); |
| 135 p.Stop(); |
| 136 EXPECT_FALSE(p.IsInitialized()); |
| 137 } |
| 138 |
| 139 TEST(PipelineImplTest, MockNothingToRenderPipeline) { |
| 140 std::string url(""); |
| 141 PipelineImpl p; |
| 142 scoped_refptr<FilterFactoryCollection> c = new FilterFactoryCollection(); |
| 143 MockFilterConfig config; |
| 144 config.has_audio = false; |
| 145 config.has_video = false; |
| 146 AddAllMockFilters(c, &config); |
| 147 InitializationHelper h; |
| 148 h.Start(&p, c, url, media::PIPELINE_ERROR_COULD_NOT_RENDER); |
| 149 p.Stop(); |
| 150 } |
| 151 |
| 152 // TODO(ralphl): Add a unit test that makes sure that the mock audio filter |
| 153 // is actually called on a SetVolume() call to the pipeline. I almost checked |
| 154 // in code that broke this, but all unit tests were passing. |
| OLD | NEW |