1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/image-decoders/image_decoder_test_helpers.h"
#include "base/strings/strcat.h"
#include "base/test/metrics/histogram_tester.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/image-decoders/image_frame.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hasher.h"
#include "third_party/skia/include/private/chromium/SkPMColor.h"
namespace blink {
Vector<char> ReadFile(StringView file_name) {
StringBuilder file_path;
file_path.Append(test::BlinkWebTestsDir());
file_path.Append(file_name);
std::optional<Vector<char>> data = test::ReadFromFile(file_path.ToString());
CHECK(data && data->size());
return *data;
}
Vector<char> ReadFile(const char* dir, const char* file_name) {
StringBuilder file_path;
if (strncmp(dir, "web_tests/", 10) == 0) {
file_path.Append(test::BlinkWebTestsDir());
file_path.Append('/');
file_path.Append(dir + 10);
} else {
file_path.Append(test::BlinkRootDir());
file_path.Append('/');
file_path.Append(dir);
}
file_path.Append('/');
file_path.Append(file_name);
std::optional<Vector<char>> data = test::ReadFromFile(file_path.ToString());
CHECK(data && data->size());
return *data;
}
scoped_refptr<SharedBuffer> ReadFileToSharedBuffer(StringView file_name) {
return SharedBuffer::Create(ReadFile(file_name));
}
scoped_refptr<SharedBuffer> ReadFileToSharedBuffer(const char* dir,
const char* file_name) {
return SharedBuffer::Create(ReadFile(dir, file_name));
}
unsigned HashBitmap(const SkBitmap& bitmap) {
return StringHasher::HashMemory(
{static_cast<const uint8_t*>(bitmap.getPixels()),
bitmap.computeByteSize()});
}
void CreateDecodingBaseline(DecoderCreator create_decoder,
SharedBuffer* data,
Vector<unsigned>* baseline_hashes) {
std::unique_ptr<ImageDecoder> decoder = create_decoder();
decoder->SetData(data, true);
size_t frame_count = decoder->FrameCount();
for (size_t i = 0; i < frame_count; ++i) {
ImageFrame* frame = decoder->DecodeFrameBufferAtIndex(i);
baseline_hashes->push_back(HashBitmap(frame->Bitmap()));
}
}
void TestByteByByteDecode(DecoderCreator create_decoder,
SharedBuffer* shared_data,
size_t expected_frame_count,
int expected_repetition_count) {
const Vector<char> data = shared_data->CopyAs<Vector<char>>();
Vector<unsigned> baseline_hashes;
CreateDecodingBaseline(create_decoder, shared_data, &baseline_hashes);
std::unique_ptr<ImageDecoder> decoder = create_decoder();
size_t frame_count = 0;
size_t frames_decoded = 0;
// Pass data to decoder byte by byte.
scoped_refptr<SharedBuffer> source_data[2] = {SharedBuffer::Create(),
SharedBuffer::Create()};
base::span<const char> source(data);
for (size_t length = 1; length <= data.size() && !decoder->Failed();
++length) {
auto [single_byte, rest] = source.split_at(1u);
source = rest;
source_data[0]->Append(single_byte);
source_data[1]->Append(single_byte);
// Alternate the buffers to cover the JPEGImageDecoder::OnSetData restart
// code.
decoder->SetData(source_data[length & 1].get(), length == data.size());
EXPECT_LE(frame_count, decoder->FrameCount());
frame_count = decoder->FrameCount();
if (!decoder->IsSizeAvailable()) {
continue;
}
for (size_t i = frames_decoded; i < frame_count; ++i) {
// In ICOImageDecoder memory layout could differ from frame order.
// E.g. memory layout could be |<frame1><frame0>| and frame_count
// would return 1 until receiving full file.
// When file is completely received frame_count would return 2 and
// only then both frames could be completely decoded.
ImageFrame* frame = decoder->DecodeFrameBufferAtIndex(i);
if (frame && frame->GetStatus() == ImageFrame::kFrameComplete) {
EXPECT_EQ(baseline_hashes[i], HashBitmap(frame->Bitmap()));
++frames_decoded;
}
}
}
EXPECT_FALSE(decoder->Failed());
EXPECT_EQ(expected_frame_count, decoder->FrameCount());
EXPECT_EQ(expected_frame_count, frames_decoded);
EXPECT_EQ(expected_repetition_count, decoder->RepetitionCount());
ASSERT_EQ(expected_frame_count, baseline_hashes.size());
for (size_t i = 0; i < decoder->FrameCount(); i++) {
ImageFrame* frame = decoder->DecodeFrameBufferAtIndex(i);
EXPECT_EQ(baseline_hashes[i], HashBitmap(frame->Bitmap()));
}
}
static void TestRandomFrameDecode(DecoderCreator create_decoder,
SharedBuffer* full_data,
size_t skipping_step) {
Vector<unsigned> baseline_hashes;
CreateDecodingBaseline(create_decoder, full_data, &baseline_hashes);
size_t frame_count = baseline_hashes.size();
// Random decoding should get the same results as sequential decoding.
std::unique_ptr<ImageDecoder> decoder = create_decoder();
decoder->SetData(full_data, true);
for (size_t i = 0; i < skipping_step; ++i) {
for (size_t j = i; j < frame_count; j += skipping_step) {
SCOPED_TRACE(testing::Message() << "Random i:" << i << " j:" << j);
ImageFrame* frame = decoder->DecodeFrameBufferAtIndex(j);
EXPECT_EQ(baseline_hashes[j], HashBitmap(frame->Bitmap()));
}
}
// Decoding in reverse order.
decoder = create_decoder();
decoder->SetData(full_data, true);
for (size_t i = frame_count; i; --i) {
SCOPED_TRACE(testing::Message() << "Reverse i:" << i);
ImageFrame* frame = decoder->DecodeFrameBufferAtIndex(i - 1);
EXPECT_EQ(baseline_hashes[i - 1], HashBitmap(frame->Bitmap()));
}
}
static void TestRandomDecodeAfterClearFrameBufferCache(
DecoderCreator create_decoder,
SharedBuffer* data,
size_t skipping_step) {
Vector<unsigned> baseline_hashes;
CreateDecodingBaseline(create_decoder, data, &baseline_hashes);
size_t frame_count = baseline_hashes.size();
std::unique_ptr<ImageDecoder> decoder = create_decoder();
decoder->SetData(data, true);
for (size_t clear_except_frame = 0; clear_except_frame < frame_count;
++clear_except_frame) {
decoder->ClearCacheExceptFrame(clear_except_frame);
for (size_t i = 0; i < skipping_step; ++i) {
for (size_t j = 0; j < frame_count; j += skipping_step) {
SCOPED_TRACE(testing::Message() << "Random i:" << i << " j:" << j);
ImageFrame* frame = decoder->DecodeFrameBufferAtIndex(j);
EXPECT_EQ(baseline_hashes[j], HashBitmap(frame->Bitmap()));
}
}
}
}
static void TestDecodeAfterReallocatingData(DecoderCreator create_decoder,
SharedBuffer* data) {
std::unique_ptr<ImageDecoder> decoder = create_decoder();
// Parse from 'data'.
decoder->SetData(data, true);
size_t frame_count = decoder->FrameCount();
// ... and then decode frames from 'reallocated_data'.
Vector<char> copy = data->CopyAs<Vector<char>>();
scoped_refptr<SharedBuffer> reallocated_data =
SharedBuffer::Create(std::move(copy));
ASSERT_TRUE(reallocated_data.get());
data->Clear();
decoder->SetData(reallocated_data.get(), true);
for (size_t i = 0; i < frame_count; ++i) {
const ImageFrame* const frame = decoder->DecodeFrameBufferAtIndex(i);
EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus());
}
}
static void TestByteByByteSizeAvailable(DecoderCreator create_decoder,
SharedBuffer* data,
size_t frame_offset,
bool has_color_space,
int expected_repetition_count) {
std::unique_ptr<ImageDecoder> decoder = create_decoder();
EXPECT_LT(frame_offset, data->size());
// Send data to the decoder byte-by-byte and use the provided frame offset in
// the data to check that IsSizeAvailable() changes state only when that
// offset is reached. Also check other decoder state.
scoped_refptr<SharedBuffer> temp_data = SharedBuffer::Create();
const Vector<char> source_buffer = data->CopyAs<Vector<char>>();
base::span<const char> source(source_buffer);
for (size_t length = 1; length <= frame_offset; ++length) {
auto [single_byte, rest] = source.split_at(1u);
source = rest;
temp_data->Append(single_byte);
decoder->SetData(temp_data.get(), false);
if (length < frame_offset) {
EXPECT_FALSE(decoder->IsSizeAvailable());
EXPECT_TRUE(decoder->Size().IsEmpty());
EXPECT_FALSE(decoder->HasEmbeddedColorProfile());
EXPECT_EQ(0u, decoder->FrameCount());
EXPECT_EQ(kAnimationLoopOnce, decoder->RepetitionCount());
EXPECT_FALSE(decoder->DecodeFrameBufferAtIndex(0));
} else {
EXPECT_TRUE(decoder->IsSizeAvailable());
EXPECT_FALSE(decoder->Size().IsEmpty());
EXPECT_EQ(decoder->HasEmbeddedColorProfile(), has_color_space);
EXPECT_EQ(1u, decoder->FrameCount());
EXPECT_EQ(expected_repetition_count, decoder->RepetitionCount());
}
ASSERT_FALSE(decoder->Failed());
}
}
static void TestProgressiveDecoding(DecoderCreator create_decoder,
SharedBuffer* full_buffer,
size_t increment) {
const Vector<char> full_data = full_buffer->CopyAs<Vector<char>>();
const size_t full_length = full_data.size();
std::unique_ptr<ImageDecoder> decoder;
Vector<unsigned> truncated_hashes;
Vector<unsigned> progressive_hashes;
// Compute hashes when the file is truncated.
scoped_refptr<SharedBuffer> data = SharedBuffer::Create();
base::span<const char> source(full_data);
for (size_t i = 1; i <= full_length; i += increment) {
decoder = create_decoder();
auto [single_byte, rest] = source.split_at(1u);
source = rest;
data->Append(single_byte);
decoder->SetData(data.get(), i == full_length);
ImageFrame* frame = decoder->DecodeFrameBufferAtIndex(0);
if (!frame) {
truncated_hashes.push_back(0);
continue;
}
truncated_hashes.push_back(HashBitmap(frame->Bitmap()));
}
// Compute hashes when the file is progressively decoded.
decoder = create_decoder();
data = SharedBuffer::Create();
source = base::span(full_data);
for (size_t i = 1; i <= full_length; i += increment) {
auto [single_byte, rest] = source.split_at(1u);
source = rest;
data->Append(single_byte);
decoder->SetData(data.get(), i == full_length);
ImageFrame* frame = decoder->DecodeFrameBufferAtIndex(0);
if (!frame) {
progressive_hashes.push_back(0);
continue;
}
progressive_hashes.push_back(HashBitmap(frame->Bitmap()));
}
for (size_t i = 0; i < truncated_hashes.size(); ++i) {
ASSERT_EQ(truncated_hashes[i], progressive_hashes[i]);
}
}
void TestUpdateRequiredPreviousFrameAfterFirstDecode(
DecoderCreator create_decoder,
SharedBuffer* full_buffer) {
const Vector<char> full_data = full_buffer->CopyAs<Vector<char>>();
std::unique_ptr<ImageDecoder> decoder = create_decoder();
// Give it data that is enough to parse but not decode in order to check the
// status of RequiredPreviousFrameIndex before decoding.
scoped_refptr<SharedBuffer> data = SharedBuffer::Create();
base::span<const char> source(full_data);
do {
auto [single_byte, rest] = source.split_at(1u);
source = rest;
data->Append(single_byte);
decoder->SetData(data.get(), false);
} while (!decoder->FrameCount() ||
decoder->DecodeFrameBufferAtIndex(0)->GetStatus() ==
ImageFrame::kFrameEmpty);
EXPECT_EQ(kNotFound,
decoder->DecodeFrameBufferAtIndex(0)->RequiredPreviousFrameIndex());
unsigned frame_count = decoder->FrameCount();
for (size_t i = 1; i < frame_count; ++i) {
EXPECT_EQ(
i - 1,
decoder->DecodeFrameBufferAtIndex(i)->RequiredPreviousFrameIndex());
}
decoder->SetData(full_buffer, true);
for (size_t i = 0; i < frame_count; ++i) {
EXPECT_EQ(
kNotFound,
decoder->DecodeFrameBufferAtIndex(i)->RequiredPreviousFrameIndex());
}
}
void TestByteByByteDecode(DecoderCreator create_decoder,
const char* file,
size_t expected_frame_count,
int expected_repetition_count) {
SCOPED_TRACE(file);
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(file);
ASSERT_TRUE(data.get());
TestByteByByteDecode(create_decoder, data.get(), expected_frame_count,
expected_repetition_count);
}
void TestByteByByteDecode(DecoderCreator create_decoder,
const char* dir,
const char* file,
size_t expected_frame_count,
int expected_repetition_count) {
SCOPED_TRACE(file);
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(dir, file);
ASSERT_TRUE(data.get());
TestByteByByteDecode(create_decoder, data.get(), expected_frame_count,
expected_repetition_count);
}
void TestRandomFrameDecode(DecoderCreator create_decoder,
const char* file,
size_t skipping_step) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(file);
ASSERT_TRUE(data.get());
SCOPED_TRACE(file);
TestRandomFrameDecode(create_decoder, data.get(), skipping_step);
}
void TestRandomFrameDecode(DecoderCreator create_decoder,
const char* dir,
const char* file,
size_t skipping_step) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(dir, file);
ASSERT_TRUE(data.get());
SCOPED_TRACE(file);
TestRandomFrameDecode(create_decoder, data.get(), skipping_step);
}
void TestRandomDecodeAfterClearFrameBufferCache(DecoderCreator create_decoder,
const char* file,
size_t skipping_step) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(file);
ASSERT_TRUE(data.get());
SCOPED_TRACE(file);
TestRandomDecodeAfterClearFrameBufferCache(create_decoder, data.get(),
skipping_step);
}
void TestRandomDecodeAfterClearFrameBufferCache(DecoderCreator create_decoder,
const char* dir,
const char* file,
size_t skipping_step) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(dir, file);
ASSERT_TRUE(data.get());
SCOPED_TRACE(file);
TestRandomDecodeAfterClearFrameBufferCache(create_decoder, data.get(),
skipping_step);
}
void TestDecodeAfterReallocatingData(DecoderCreator create_decoder,
const char* file) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(file);
ASSERT_TRUE(data.get());
TestDecodeAfterReallocatingData(create_decoder, data.get());
}
void TestDecodeAfterReallocatingData(DecoderCreator create_decoder,
const char* dir,
const char* file) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(dir, file);
ASSERT_TRUE(data.get());
TestDecodeAfterReallocatingData(create_decoder, data.get());
}
void TestByteByByteSizeAvailable(DecoderCreator create_decoder,
const char* file,
size_t frame_offset,
bool has_color_space,
int expected_repetition_count) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(file);
ASSERT_TRUE(data.get());
TestByteByByteSizeAvailable(create_decoder, data.get(), frame_offset,
has_color_space, expected_repetition_count);
}
void TestByteByByteSizeAvailable(DecoderCreator create_decoder,
const char* dir,
const char* file,
size_t frame_offset,
bool has_color_space,
int expected_repetition_count) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(dir, file);
ASSERT_TRUE(data.get());
TestByteByByteSizeAvailable(create_decoder, data.get(), frame_offset,
has_color_space, expected_repetition_count);
}
void TestProgressiveDecoding(DecoderCreator create_decoder,
const char* file,
size_t increment) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(file);
ASSERT_TRUE(data.get());
TestProgressiveDecoding(create_decoder, data.get(), increment);
}
void TestProgressiveDecoding(DecoderCreator create_decoder,
const char* dir,
const char* file,
size_t increment) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(dir, file);
ASSERT_TRUE(data.get());
TestProgressiveDecoding(create_decoder, data.get(), increment);
}
void TestUpdateRequiredPreviousFrameAfterFirstDecode(
DecoderCreator create_decoder,
const char* dir,
const char* file) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(dir, file);
ASSERT_TRUE(data.get());
TestUpdateRequiredPreviousFrameAfterFirstDecode(create_decoder, data.get());
}
void TestUpdateRequiredPreviousFrameAfterFirstDecode(
DecoderCreator create_decoder,
const char* file) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(file);
ASSERT_TRUE(data.get());
TestUpdateRequiredPreviousFrameAfterFirstDecode(create_decoder, data.get());
}
// Takes in a pixel encoded as 8888 and returns it as a premultiplied
// pixel encoded in Skia's N32 format.
static SkPMColor PremultiplyColor(uint32_t pixel, SkColorType ct) {
// If this assumption is false, then SkPreMultiplyARGB will return
// a wrongly-encoded pixel.
CHECK(ct == SkColorType::kN32_SkColorType);
return SkPreMultiplyARGB(SkPMColorGetA(pixel), SkPMColorGetR(pixel),
SkPMColorGetG(pixel), SkPMColorGetB(pixel));
}
static void VerifyFramesMatch(const char* file,
const ImageFrame* const a,
const ImageFrame* const b) {
const SkBitmap& bitmap_a = a->Bitmap();
const SkBitmap& bitmap_b = b->Bitmap();
ASSERT_EQ(bitmap_a.width(), bitmap_b.width());
ASSERT_EQ(bitmap_a.height(), bitmap_b.height());
int max_difference = 0;
for (int y = 0; y < bitmap_a.height(); ++y) {
for (int x = 0; x < bitmap_a.width(); ++x) {
uint32_t color_a = *bitmap_a.getAddr32(x, y);
if (!a->PremultiplyAlpha()) {
color_a = PremultiplyColor(color_a, bitmap_a.colorType());
}
uint32_t color_b = *bitmap_b.getAddr32(x, y);
if (!b->PremultiplyAlpha()) {
color_b = PremultiplyColor(color_b, bitmap_b.colorType());
}
uint8_t* pixel_a = reinterpret_cast<uint8_t*>(&color_a);
uint8_t* pixel_b = reinterpret_cast<uint8_t*>(&color_b);
for (int channel = 0; channel < 4; ++channel) {
const int difference = abs(pixel_a[channel] - pixel_b[channel]);
if (difference > max_difference) {
max_difference = difference;
}
}
}
}
// Pre-multiplication could round the RGBA channel values. So, we declare
// that the frames match if the RGBA channel values differ by at most 2.
EXPECT_GE(2, max_difference) << file;
}
// Verifies that result of alpha blending is similar for AlphaPremultiplied and
// AlphaNotPremultiplied cases.
void TestAlphaBlending(DecoderCreatorWithAlpha create_decoder,
const char* file) {
scoped_refptr<SharedBuffer> data = ReadFileToSharedBuffer(file);
ASSERT_TRUE(data.get());
std::unique_ptr<ImageDecoder> decoder_a =
create_decoder(ImageDecoder::kAlphaPremultiplied);
decoder_a->SetData(data.get(), true);
std::unique_ptr<ImageDecoder> decoder_b =
create_decoder(ImageDecoder::kAlphaNotPremultiplied);
decoder_b->SetData(data.get(), true);
size_t frame_count = decoder_a->FrameCount();
ASSERT_EQ(frame_count, decoder_b->FrameCount());
for (size_t i = 0; i < frame_count; ++i) {
VerifyFramesMatch(file, decoder_a->DecodeFrameBufferAtIndex(i),
decoder_b->DecodeFrameBufferAtIndex(i));
}
}
void TestBppHistogram(DecoderCreator create_decoder,
const char* image_type,
const char* image_name,
const char* histogram_name,
base::HistogramBase::Sample32 sample) {
base::HistogramTester histogram_tester;
std::unique_ptr<ImageDecoder> decoder = create_decoder();
decoder->SetData(ReadFileToSharedBuffer(image_name), true);
ASSERT_TRUE(decoder->IsSizeAvailable());
if (histogram_name) {
histogram_tester.ExpectTotalCount(histogram_name, 0);
}
ImageFrame* frame = decoder->DecodeFrameBufferAtIndex(0);
ASSERT_TRUE(frame);
EXPECT_EQ(ImageFrame::kFrameComplete, frame->GetStatus());
EXPECT_FALSE(decoder->Failed());
base::HistogramTester::CountsMap expected_counts;
if (histogram_name) {
histogram_tester.ExpectUniqueSample(histogram_name, sample, 1);
expected_counts[histogram_name] = 1;
}
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix(base::StrCat(
{"Blink.DecodedImage.", image_type, "Density.Count."})),
testing::ContainerEq(expected_counts));
}
} // namespace blink
|