Revert "[M120 Migration]Fix for crash during chrome exit"
[platform/framework/web/chromium-efl.git] / media / filters / file_data_source_unittest.cc
1 // Copyright 2012 The Chromium Authors
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 <stdint.h>
6
7 #include <string>
8
9 #include "base/base_paths.h"
10 #include "base/files/file_path.h"
11 #include "base/functional/bind.h"
12 #include "base/path_service.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "media/base/test_helpers.h"
15 #include "media/filters/file_data_source.h"
16
17 using ::testing::NiceMock;
18 using ::testing::StrictMock;
19
20 namespace media {
21
22 class ReadCBHandler {
23  public:
24   ReadCBHandler() = default;
25
26   ReadCBHandler(const ReadCBHandler&) = delete;
27   ReadCBHandler& operator=(const ReadCBHandler&) = delete;
28
29   MOCK_METHOD1(ReadCB, void(int size));
30 };
31
32 // Returns a path to the test file which contains the string "0123456789"
33 // without the quotes or any trailing space or null termination.  The file lives
34 // under the media/test/data directory.  Under Windows, strings for the
35 // FilePath class are unicode, and the pipeline wants char strings.  Convert
36 // the string to UTF8 under Windows.  For Mac and Linux, file paths are already
37 // chars so just return the string from the base::FilePath.
38 base::FilePath TestFileURL() {
39   base::FilePath data_dir;
40   EXPECT_TRUE(base::PathService::Get(base::DIR_SRC_TEST_DATA_ROOT, &data_dir));
41   data_dir = data_dir.Append(FILE_PATH_LITERAL("media"))
42                      .Append(FILE_PATH_LITERAL("test"))
43                      .Append(FILE_PATH_LITERAL("data"))
44                      .Append(FILE_PATH_LITERAL("ten_byte_file"));
45   return data_dir;
46 }
47
48 // Use the mock filter host to directly call the Read and GetPosition methods.
49 TEST(FileDataSourceTest, ReadData) {
50   int64_t size;
51   uint8_t ten_bytes[10];
52
53   // Create our mock filter host and initialize the data source.
54   FileDataSource data_source;
55
56   EXPECT_TRUE(data_source.Initialize(TestFileURL()));
57   EXPECT_TRUE(data_source.GetSize(&size));
58   EXPECT_EQ(10, size);
59
60   ReadCBHandler handler;
61   EXPECT_CALL(handler, ReadCB(10));
62   data_source.Read(
63       0, 10, ten_bytes,
64       base::BindOnce(&ReadCBHandler::ReadCB, base::Unretained(&handler)));
65   EXPECT_EQ('0', ten_bytes[0]);
66   EXPECT_EQ('5', ten_bytes[5]);
67   EXPECT_EQ('9', ten_bytes[9]);
68
69   EXPECT_CALL(handler, ReadCB(1));
70   data_source.Read(
71       9, 1, ten_bytes,
72       base::BindOnce(&ReadCBHandler::ReadCB, base::Unretained(&handler)));
73   EXPECT_EQ('9', ten_bytes[0]);
74
75   EXPECT_CALL(handler, ReadCB(0));
76   data_source.Read(
77       10, 10, ten_bytes,
78       base::BindOnce(&ReadCBHandler::ReadCB, base::Unretained(&handler)));
79
80   EXPECT_CALL(handler, ReadCB(5));
81   data_source.Read(
82       5, 10, ten_bytes,
83       base::BindOnce(&ReadCBHandler::ReadCB, base::Unretained(&handler)));
84   EXPECT_EQ('5', ten_bytes[0]);
85
86   data_source.Stop();
87 }
88
89 }  // namespace media