Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/utility/image_decoder_impl_unittest.cc

Issue 1906773003: Enable SkBitmap to be used by Mojo in Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/utility/image_decoder_impl.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/utility/image_decoder_impl.h" 5 #include "chrome/utility/image_decoder_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "ipc/ipc_channel.h" 10 #include "ipc/ipc_channel.h"
(...skipping 28 matching lines...) Expand all
39 class Request { 39 class Request {
40 public: 40 public:
41 explicit Request(ImageDecoderImpl* decoder) : decoder_(decoder) {} 41 explicit Request(ImageDecoderImpl* decoder) : decoder_(decoder) {}
42 42
43 void DecodeImage(const std::vector<unsigned char>& image, bool shrink) { 43 void DecodeImage(const std::vector<unsigned char>& image, bool shrink) {
44 decoder_->DecodeImage( 44 decoder_->DecodeImage(
45 mojo::Array<uint8_t>::From(image), ImageCodec::DEFAULT, 45 mojo::Array<uint8_t>::From(image), ImageCodec::DEFAULT,
46 shrink, base::Bind(&Request::OnRequestDone, base::Unretained(this))); 46 shrink, base::Bind(&Request::OnRequestDone, base::Unretained(this)));
47 } 47 }
48 48
49 const skia::mojom::BitmapPtr& bitmap() const { return bitmap_; } 49 const blink::mojom::BitmapPtr& bitmap() const { return bitmap_; }
50 50
51 private: 51 private:
52 void OnRequestDone(skia::mojom::BitmapPtr result_image) { 52 void OnRequestDone(blink::mojom::BitmapPtr result_image) {
53 bitmap_ = std::move(result_image); 53 bitmap_ = std::move(result_image);
54 } 54 }
55 55
56 ImageDecoderImpl* decoder_; 56 ImageDecoderImpl* decoder_;
57 skia::mojom::BitmapPtr bitmap_; 57 blink::mojom::BitmapPtr bitmap_;
58 }; 58 };
59 59
60 } // namespace 60 } // namespace
61 61
62 // Test that DecodeImage() doesn't return image message > (max message size) 62 // Test that DecodeImage() doesn't return image message > (max message size)
63 TEST(ImageDecoderImplTest, DecodeImageSizeLimit) { 63 TEST(ImageDecoderImplTest, DecodeImageSizeLimit) {
64 // Using actual limit generates 14000 x 9400 images, which causes the test to 64 // Using actual limit generates 14000 x 9400 images, which causes the test to
65 // timeout. We test with a smaller limit for efficiency. 65 // timeout. We test with a smaller limit for efficiency.
66 const size_t kTestMessageSize = IPC::Channel::kMaximumMessageSize / 1024; 66 const size_t kTestMessageSize = IPC::Channel::kMaximumMessageSize / 1024;
67 67
68 ImageDecoderImpl decoder(kTestMessageSize); 68 ImageDecoderImpl decoder(kTestMessageSize);
69 69
70 // Approx max height for 3:2 image that will fit in IPC message; 70 // Approx max height for 3:2 image that will fit in IPC message;
71 // 1.5 for width/height ratio, 4 for bytes/pixel 71 // 1.5 for width/height ratio, 4 for bytes/pixel
72 int max_height_for_msg = sqrt(kTestMessageSize / (1.5 * 4)); 72 int max_height_for_msg = sqrt(kTestMessageSize / (1.5 * 4));
73 int base_msg_size = sizeof(skia::mojom::Bitmap::Data_); 73 int base_msg_size = sizeof(blink::mojom::Bitmap::Data_);
74 74
75 // Sizes which should trigger dimension-halving 0, 1 and 2 times 75 // Sizes which should trigger dimension-halving 0, 1 and 2 times
76 int heights[] = {max_height_for_msg - 10, 76 int heights[] = {max_height_for_msg - 10,
77 max_height_for_msg + 10, 77 max_height_for_msg + 10,
78 2 * max_height_for_msg + 10}; 78 2 * max_height_for_msg + 10};
79 int widths[] = {heights[0] * 3 / 2, heights[1] * 3 / 2, heights[2] * 3 / 2}; 79 int widths[] = {heights[0] * 3 / 2, heights[1] * 3 / 2, heights[2] * 3 / 2};
80 for (size_t i = 0; i < arraysize(heights); i++) { 80 for (size_t i = 0; i < arraysize(heights); i++) {
81 std::vector<unsigned char> jpg; 81 std::vector<unsigned char> jpg;
82 ASSERT_TRUE(CreateJPEGImage(widths[i], heights[i], SK_ColorRED, &jpg)); 82 ASSERT_TRUE(CreateJPEGImage(widths[i], heights[i], SK_ColorRED, &jpg));
83 83
(...skipping 29 matching lines...) Expand all
113 const char kRandomData[] = "u gycfy7xdjkhfgui bdui "; 113 const char kRandomData[] = "u gycfy7xdjkhfgui bdui ";
114 std::vector<unsigned char> jpg(kRandomData, 114 std::vector<unsigned char> jpg(kRandomData,
115 kRandomData + sizeof(kRandomData)); 115 kRandomData + sizeof(kRandomData));
116 116
117 Request request(&decoder); 117 Request request(&decoder);
118 request.DecodeImage(jpg, false); 118 request.DecodeImage(jpg, false);
119 EXPECT_TRUE(request.bitmap().is_null()); 119 EXPECT_TRUE(request.bitmap().is_null());
120 } 120 }
121 121
122 } // namespace mojom 122 } // namespace mojom
OLDNEW
« no previous file with comments | « chrome/utility/image_decoder_impl.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698