71 DataVector<uint8_t> test_data(kTestDataSize);
73 pdfium::MakeRetain<CFX_ReadOnlyVectorStream>(std::move(test_data));
74 MockFileAvail file_avail;
78 DataVector<uint8_t> read_buffer(100);
79 EXPECT_FALSE(validator->ReadBlockAtOffset(read_buffer, 5000));
80 EXPECT_FALSE(validator->read_error());
81 EXPECT_TRUE(validator->has_unavailable_data());
83 validator->ResetErrors();
84 file_avail.SetAvailableRange(5000, 5000 + read_buffer.size());
85 EXPECT_TRUE(validator->ReadBlockAtOffset(read_buffer, 5000));
86 EXPECT_FALSE(validator->read_error());
87 EXPECT_FALSE(validator->has_unavailable_data());
91 DataVector<uint8_t> test_data(kTestDataSize);
93 pdfium::MakeRetain<CFX_ReadOnlyVectorStream>(std::move(test_data));
94 MockFileAvail file_avail;
98 MockDownloadHints hints;
99 validator->SetDownloadHints(&hints);
101 DataVector<uint8_t> read_buffer(100);
102 EXPECT_FALSE(validator->ReadBlockAtOffset(read_buffer, 5000));
103 EXPECT_FALSE(validator->read_error());
104 EXPECT_TRUE(validator->has_unavailable_data());
107 EXPECT_EQ(MakeRange(4608, 5120), hints.GetLastRequstedRange());
109 file_avail.SetAvailableRange(hints.GetLastRequstedRange());
112 validator->ResetErrors();
113 EXPECT_TRUE(validator->ReadBlockAtOffset(read_buffer, 5000));
115 EXPECT_EQ(MakeRange(0, 0), hints.GetLastRequstedRange());
116 EXPECT_FALSE(validator->read_error());
117 EXPECT_FALSE(validator->has_unavailable_data());
119 validator->ResetErrors();
121 EXPECT_FALSE(validator->ReadBlockAtOffset(
122 read_buffer, validator->GetSize() - read_buffer.size()));
124 EXPECT_EQ(validator->GetSize(), hints.GetLastRequstedRange().second);
125 EXPECT_FALSE(validator->read_error());
126 EXPECT_TRUE(validator->has_unavailable_data());
128 validator->SetDownloadHints(
nullptr);
132 auto file = pdfium::MakeRetain<InvalidSeekableReadStream>(kTestDataSize);
136 static const uint32_t kBufferSize = 3 * 1000;
137 DataVector<uint8_t> buffer(kBufferSize);
140 validator->ReadBlockAtOffset(pdfium::make_span(buffer).first(100), 5000));
141 EXPECT_TRUE(validator->read_error());
142 EXPECT_TRUE(validator->has_unavailable_data());
146 DataVector<uint8_t> test_data(kTestDataSize);
148 pdfium::MakeRetain<CFX_ReadOnlyVectorStream>(std::move(test_data));
149 MockFileAvail file_avail;
153 DataVector<uint8_t> read_buffer(100);
158 EXPECT_FALSE(validator->ReadBlockAtOffset(
159 read_buffer, std::numeric_limits<
FX_FILESIZE>::max() - 1));
160 EXPECT_FALSE(validator->read_error());
161 EXPECT_FALSE(validator->has_unavailable_data());
165 DataVector<uint8_t> test_data(kTestDataSize);
167 auto file = pdfium::MakeRetain<InvalidSeekableReadStream>(kTestDataSize);
168 MockFileAvail file_avail;
169 MockDownloadHints hints;
172 validator->SetDownloadHints(&hints);
175 ASSERT_FALSE(validator->has_read_problems());
178 validator->ReadBlockAtOffset(pdfium::make_span(test_data).first(100), 0);
179 EXPECT_TRUE(validator->has_read_problems());
180 EXPECT_TRUE(validator->has_unavailable_data());
181 EXPECT_FALSE(validator->read_error());
186 EXPECT_FALSE(validator->has_read_problems());
188 file_avail.SetAvailableRange(0, 100);
190 validator->ReadBlockAtOffset(pdfium::make_span(test_data).first(100), 0);
191 EXPECT_TRUE(validator->has_read_problems());
192 EXPECT_TRUE(validator->has_unavailable_data());
193 EXPECT_TRUE(validator->read_error());
197 EXPECT_TRUE(validator->has_read_problems());
198 EXPECT_TRUE(validator->has_unavailable_data());
199 EXPECT_TRUE(validator->read_error());
203 DataVector<uint8_t> test_data(kTestDataSize);
205 auto file = pdfium::MakeRetain<InvalidSeekableReadStream>(kTestDataSize);
206 MockFileAvail file_avail;
207 MockDownloadHints hints;
210 validator->SetDownloadHints(&hints);
213 ASSERT_FALSE(validator->has_read_problems());
216 validator->ReadBlockAtOffset(pdfium::make_span(test_data).first(100), 0);
217 EXPECT_TRUE(validator->has_read_problems());
218 EXPECT_TRUE(validator->has_unavailable_data());
219 EXPECT_FALSE(validator->read_error());
224 EXPECT_FALSE(validator->has_read_problems());
226 file_avail.SetAvailableRange(0, 100);
228 validator->ReadBlockAtOffset(pdfium::make_span(test_data).first(100), 0);
229 EXPECT_TRUE(validator->has_read_problems());
230 EXPECT_TRUE(validator->has_unavailable_data());
231 EXPECT_TRUE(validator->read_error());
234 validator->ResetErrors();
235 EXPECT_FALSE(validator->has_read_problems());
239 EXPECT_TRUE(validator->has_read_problems());
240 EXPECT_TRUE(validator->has_unavailable_data());
241 EXPECT_FALSE(validator->read_error());
245 DataVector<uint8_t> test_data(kTestDataSize);
247 pdfium::MakeRetain<CFX_ReadOnlyVectorStream>(std::move(test_data));
248 MockFileAvail file_avail;
252 MockDownloadHints hints;
253 validator->SetDownloadHints(&hints);
255 EXPECT_FALSE(validator->CheckDataRangeAndRequestIfUnavailable(5000, 100));
256 EXPECT_FALSE(validator->read_error());
257 EXPECT_TRUE(validator->has_unavailable_data());
260 EXPECT_EQ(MakeRange(4608, 5632), hints.GetLastRequstedRange());
262 file_avail.SetAvailableRange(hints.GetLastRequstedRange());
265 validator->ResetErrors();
266 EXPECT_TRUE(validator->CheckDataRangeAndRequestIfUnavailable(5000, 100));
268 EXPECT_EQ(MakeRange(0, 0), hints.GetLastRequstedRange());
269 EXPECT_FALSE(validator->read_error());
270 EXPECT_FALSE(validator->has_unavailable_data());
272 DataVector<uint8_t> read_buffer(100);
273 EXPECT_TRUE(validator->ReadBlockAtOffset(read_buffer, 5000));
275 EXPECT_EQ(MakeRange(0, 0), hints.GetLastRequstedRange());
276 EXPECT_FALSE(validator->read_error());
277 EXPECT_FALSE(validator->has_unavailable_data());
279 validator->ResetErrors();
281 EXPECT_FALSE(validator->CheckDataRangeAndRequestIfUnavailable(
282 validator->GetSize() - 100, 100));
285 EXPECT_EQ(validator->GetSize(), hints.GetLastRequstedRange().second);
286 EXPECT_FALSE(validator->read_error());
287 EXPECT_TRUE(validator->has_unavailable_data());
289 validator->ResetErrors();
292 validator->CheckDataRangeAndRequestIfUnavailable(kTestDataSize + 1, 1));
294 EXPECT_FALSE(validator->read_error());
295 EXPECT_FALSE(validator->has_unavailable_data());
297 validator->SetDownloadHints(
nullptr);