#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/image_decoder/image_decoder.h"
#include "base/run_loop.h"
#include "build/build_config.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/browser_child_process_observer.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_util.h"
BrowserThread;
namespace {
std::vector<uint8_t> GetValidPngData() { … }
std::vector<uint8_t> GetValidJpgData() { … }
class TestImageRequest : public ImageDecoder::ImageRequest { … };
}
class ImageDecoderBrowserTest : public InProcessBrowserTest { … };
IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, Basic) { … }
#if BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, BasicDecodeWithOptionsString) {
base::RunLoop run_loop;
TestImageRequest test_request(run_loop.QuitClosure());
const std::vector<uint8_t> data = GetValidPngData();
ImageDecoder::StartWithOptions(&test_request,
std::string(data.begin(), data.end()),
ImageDecoder::PNG_CODEC,
false);
run_loop.Run();
EXPECT_TRUE(test_request.decode_succeeded());
}
IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, RobustJpegCodecWithJpegData) {
base::RunLoop run_loop;
TestImageRequest test_request(run_loop.QuitClosure());
ImageDecoder::StartWithOptions(
&test_request, GetValidJpgData(), ImageDecoder::DEFAULT_CODEC,
false, gfx::Size());
run_loop.Run();
EXPECT_TRUE(test_request.decode_succeeded());
}
IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, RobustPngCodecWithPngData) {
base::RunLoop run_loop;
TestImageRequest test_request(run_loop.QuitClosure());
ImageDecoder::StartWithOptions(
&test_request, GetValidPngData(), ImageDecoder::PNG_CODEC,
false, gfx::Size());
run_loop.Run();
EXPECT_TRUE(test_request.decode_succeeded());
}
IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, RobustPngCodecWithJpegData) {
base::RunLoop run_loop;
TestImageRequest test_request(run_loop.QuitClosure());
ImageDecoder::StartWithOptions(
&test_request, GetValidJpgData(), ImageDecoder::PNG_CODEC,
false, gfx::Size());
run_loop.Run();
EXPECT_FALSE(test_request.decode_succeeded());
}
#endif
IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, BasicDecode) { … }
IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, BasicDecodeString) { … }
IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, BasicDecodeStringJpeg) { … }
IN_PROC_BROWSER_TEST_F(ImageDecoderBrowserTest, StartAndDestroy) { … }