Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Side by Side Diff: media/filters/file_data_source_unittest.cc

Issue 8936014: Removing DataSource from Filter hierarchy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved preload into a separate file. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "media/base/mock_callback.h" 12 #include "media/base/mock_callback.h"
13 #include "media/base/mock_filter_host.h" 13 #include "media/base/mock_data_source_host.h"
14 #include "media/base/mock_filters.h" 14 #include "media/base/mock_filters.h"
15 #include "media/filters/file_data_source.h" 15 #include "media/filters/file_data_source.h"
16 16
17 using ::testing::NiceMock; 17 using ::testing::NiceMock;
18 using ::testing::StrictMock; 18 using ::testing::StrictMock;
19 19
20 namespace media { 20 namespace media {
21 21
22 class ReadCallbackHandler { 22 class ReadCallbackHandler {
23 public: 23 public:
(...skipping 20 matching lines...) Expand all
44 .Append(FILE_PATH_LITERAL("ten_byte_file")); 44 .Append(FILE_PATH_LITERAL("ten_byte_file"));
45 #if defined (OS_WIN) 45 #if defined (OS_WIN)
46 return WideToUTF8(data_dir.value()); 46 return WideToUTF8(data_dir.value());
47 #else 47 #else
48 return data_dir.value(); 48 return data_dir.value();
49 #endif 49 #endif
50 } 50 }
51 51
52 // Test that FileDataSource call the appropriate methods on its filter host. 52 // Test that FileDataSource call the appropriate methods on its filter host.
53 TEST(FileDataSourceTest, OpenFile) { 53 TEST(FileDataSourceTest, OpenFile) {
54 StrictMock<MockFilterHost> host; 54 StrictMock<MockDataSourceHost> host;
55 EXPECT_CALL(host, SetTotalBytes(10)); 55 EXPECT_CALL(host, SetTotalBytes(10));
56 EXPECT_CALL(host, SetBufferedBytes(10)); 56 EXPECT_CALL(host, SetBufferedBytes(10));
57 57
58 scoped_refptr<FileDataSource> filter(new FileDataSource()); 58 scoped_refptr<FileDataSource> filter(new FileDataSource());
59 filter->set_host(&host); 59 filter->set_host(&host);
60 EXPECT_EQ(PIPELINE_OK, filter->Initialize(TestFileURL())); 60 EXPECT_EQ(PIPELINE_OK, filter->Initialize(TestFileURL()));
61 61
62 filter->Stop(NewExpectedClosure()); 62 filter->Stop(NewExpectedClosure());
63 } 63 }
64 64
65 // Use the mock filter host to directly call the Read and GetPosition methods. 65 // Use the mock filter host to directly call the Read and GetPosition methods.
66 TEST(FileDataSourceTest, ReadData) { 66 TEST(FileDataSourceTest, ReadData) {
67 int64 size; 67 int64 size;
68 uint8 ten_bytes[10]; 68 uint8 ten_bytes[10];
69 69
70 // Create our mock filter host and initialize the data source. 70 // Create our mock filter host and initialize the data source.
71 NiceMock<MockFilterHost> host; 71 NiceMock<MockDataSourceHost> host;
72 scoped_refptr<FileDataSource> filter(new FileDataSource()); 72 scoped_refptr<FileDataSource> filter(new FileDataSource());
73 73
74 filter->set_host(&host); 74 filter->set_host(&host);
75 EXPECT_EQ(PIPELINE_OK, filter->Initialize(TestFileURL())); 75 EXPECT_EQ(PIPELINE_OK, filter->Initialize(TestFileURL()));
76 76
77 EXPECT_TRUE(filter->GetSize(&size)); 77 EXPECT_TRUE(filter->GetSize(&size));
78 EXPECT_EQ(10, size); 78 EXPECT_EQ(10, size);
79 79
80 ReadCallbackHandler handler; 80 ReadCallbackHandler handler;
81 EXPECT_CALL(handler, ReadCallback(10)); 81 EXPECT_CALL(handler, ReadCallback(10));
82 filter->Read(0, 10, ten_bytes, base::Bind( 82 filter->Read(0, 10, ten_bytes, base::Bind(
83 &ReadCallbackHandler::ReadCallback, base::Unretained(&handler))); 83 &ReadCallbackHandler::ReadCallback, base::Unretained(&handler)));
84 EXPECT_EQ('0', ten_bytes[0]); 84 EXPECT_EQ('0', ten_bytes[0]);
85 EXPECT_EQ('5', ten_bytes[5]); 85 EXPECT_EQ('5', ten_bytes[5]);
86 EXPECT_EQ('9', ten_bytes[9]); 86 EXPECT_EQ('9', ten_bytes[9]);
87 87
88 EXPECT_CALL(handler, ReadCallback(0)); 88 EXPECT_CALL(handler, ReadCallback(0));
89 filter->Read(10, 10, ten_bytes, base::Bind( 89 filter->Read(10, 10, ten_bytes, base::Bind(
90 &ReadCallbackHandler::ReadCallback, base::Unretained(&handler))); 90 &ReadCallbackHandler::ReadCallback, base::Unretained(&handler)));
91 91
92 EXPECT_CALL(handler, ReadCallback(5)); 92 EXPECT_CALL(handler, ReadCallback(5));
93 filter->Read(5, 10, ten_bytes, base::Bind( 93 filter->Read(5, 10, ten_bytes, base::Bind(
94 &ReadCallbackHandler::ReadCallback, base::Unretained(&handler))); 94 &ReadCallbackHandler::ReadCallback, base::Unretained(&handler)));
95 EXPECT_EQ('5', ten_bytes[0]); 95 EXPECT_EQ('5', ten_bytes[0]);
96 96
97 filter->Stop(NewExpectedClosure()); 97 filter->Stop(NewExpectedClosure());
98 } 98 }
99 99
100 // Test that FileDataSource does nothing on Seek().
101 TEST(FileDataSourceTest, Seek) {
102 const base::TimeDelta kZero;
103
104 scoped_refptr<FileDataSource> filter(new FileDataSource());
105 filter->Seek(kZero, NewExpectedStatusCB(PIPELINE_OK));
106
107 filter->Stop(NewExpectedClosure());
108 }
109
110 } // namespace media 100 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/file_data_source.cc ('k') | media/media.gyp » ('j') | media/media.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698