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
ash / public / cpp / test / test_image_decoder.h [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_PUBLIC_CPP_TEST_TEST_IMAGE_DECODER_H_
#define ASH_PUBLIC_CPP_TEST_TEST_IMAGE_DECODER_H_
#include <memory>
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/data_decoder/public/cpp/service_provider.h"
#include "services/data_decoder/public/mojom/data_decoder_service.mojom.h"
#include "third_party/skia/include/core/SkColor.h"
class SkBitmap;
namespace ash {
// Instantiating `TestImageDecoder` anywhere in your test will make the
// decoding functions in image_util.h use a stubbed decoder implementation. All
// calls to decode images and animations after instantiation (and before
// destruction) will instead call the given `ImageCallback` or
// `AnimationCallback`, respectively.
//
// It also has the same benefits as
// `InProcessImageDecoder`: it does not rely on blink or go out of process.
//
// Important: If calling `image_util::Decode*File()`, pass in an existing file,
// or the logic will return early. The contents don't matter, as long as it
// exists and isn't empty.
class TestImageDecoder : public data_decoder::ServiceProvider {
public:
using AnimationCallback = base::RepeatingCallback<
std::vector<data_decoder::mojom::AnimationFramePtr>()>;
using ImageCallback = base::RepeatingCallback<SkBitmap()>;
TestImageDecoder(AnimationCallback test_frames_callback,
ImageCallback test_image_callback);
TestImageDecoder(const TestImageDecoder&) = delete;
TestImageDecoder& operator=(const TestImageDecoder&) = delete;
~TestImageDecoder() override;
// data_decoder::ServiceProvider:
void BindDataDecoderService(
mojo::PendingReceiver<data_decoder::mojom::DataDecoderService> receiver)
override;
private:
class DataDecoderServiceImpl;
const std::unique_ptr<DataDecoderServiceImpl> service_;
mojo::ReceiverSet<data_decoder::mojom::DataDecoderService> receivers_;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_TEST_TEST_IMAGE_DECODER_H_