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

Side by Side Diff: services/data_decoder/image_decoder_impl_unittest.cc

Issue 2774463002: image_decoder service -> data_decoder service (Closed)
Patch Set: . Created 3 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 | « services/data_decoder/image_decoder_impl.cc ('k') | services/data_decoder/manifest.json » ('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 <memory> 5 #include <memory>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "gin/array_buffer.h" 11 #include "gin/array_buffer.h"
12 #include "gin/public/isolate_holder.h" 12 #include "gin/public/isolate_holder.h"
13 #include "services/image_decoder/image_decoder_impl.h" 13 #include "services/data_decoder/image_decoder_impl.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/public/platform/scheduler/utility/webthread_impl_fo r_utility_thread.h" 15 #include "third_party/WebKit/public/platform/scheduler/utility/webthread_impl_fo r_utility_thread.h"
16 #include "third_party/WebKit/public/web/WebKit.h" 16 #include "third_party/WebKit/public/web/WebKit.h"
17 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
18 #include "ui/gfx/codec/jpeg_codec.h" 18 #include "ui/gfx/codec/jpeg_codec.h"
19 19
20 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) 20 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
21 #include "gin/v8_initializer.h" 21 #include "gin/v8_initializer.h"
22 #endif 22 #endif
23 23
24 namespace image_decoder { 24 namespace data_decoder {
25 25
26 namespace { 26 namespace {
27 27
28 const int64_t kTestMaxImageSize = 128 * 1024; 28 const int64_t kTestMaxImageSize = 128 * 1024;
29 29
30 bool CreateJPEGImage(int width, 30 bool CreateJPEGImage(int width,
31 int height, 31 int height,
32 SkColor color, 32 SkColor color,
33 std::vector<unsigned char>* output) { 33 std::vector<unsigned char>* output) {
34 SkBitmap bitmap; 34 SkBitmap bitmap;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } // namespace 111 } // namespace
112 112
113 // Test that DecodeImage() doesn't return image message > (max message size) 113 // Test that DecodeImage() doesn't return image message > (max message size)
114 TEST_F(ImageDecoderImplTest, DecodeImageSizeLimit) { 114 TEST_F(ImageDecoderImplTest, DecodeImageSizeLimit) {
115 // Approx max height for 3:2 image that will fit in the allotted space. 115 // Approx max height for 3:2 image that will fit in the allotted space.
116 // 1.5 for width/height ratio, 4 for bytes/pixel. 116 // 1.5 for width/height ratio, 4 for bytes/pixel.
117 int max_height_for_msg = sqrt(kTestMaxImageSize / (1.5 * 4)); 117 int max_height_for_msg = sqrt(kTestMaxImageSize / (1.5 * 4));
118 int base_msg_size = sizeof(skia::mojom::Bitmap::Data_); 118 int base_msg_size = sizeof(skia::mojom::Bitmap::Data_);
119 119
120 // Sizes which should trigger dimension-halving 0, 1 and 2 times 120 // Sizes which should trigger dimension-halving 0, 1 and 2 times
121 int heights[] = {max_height_for_msg - 10, 121 int heights[] = {max_height_for_msg - 10, max_height_for_msg + 10,
122 max_height_for_msg + 10,
123 2 * max_height_for_msg + 10}; 122 2 * max_height_for_msg + 10};
124 int widths[] = {heights[0] * 3 / 2, heights[1] * 3 / 2, heights[2] * 3 / 2}; 123 int widths[] = {heights[0] * 3 / 2, heights[1] * 3 / 2, heights[2] * 3 / 2};
125 for (size_t i = 0; i < arraysize(heights); i++) { 124 for (size_t i = 0; i < arraysize(heights); i++) {
126 std::vector<unsigned char> jpg; 125 std::vector<unsigned char> jpg;
127 ASSERT_TRUE(CreateJPEGImage(widths[i], heights[i], SK_ColorRED, &jpg)); 126 ASSERT_TRUE(CreateJPEGImage(widths[i], heights[i], SK_ColorRED, &jpg));
128 127
129 Request request(decoder()); 128 Request request(decoder());
130 request.DecodeImage(jpg, true); 129 request.DecodeImage(jpg, true);
131 ASSERT_FALSE(request.bitmap().isNull()); 130 ASSERT_FALSE(request.bitmap().isNull());
132 131
(...skipping 21 matching lines...) Expand all
154 // The "jpeg" is just some "random" data; 153 // The "jpeg" is just some "random" data;
155 const char kRandomData[] = "u gycfy7xdjkhfgui bdui "; 154 const char kRandomData[] = "u gycfy7xdjkhfgui bdui ";
156 std::vector<unsigned char> jpg(kRandomData, 155 std::vector<unsigned char> jpg(kRandomData,
157 kRandomData + sizeof(kRandomData)); 156 kRandomData + sizeof(kRandomData));
158 157
159 Request request(decoder()); 158 Request request(decoder());
160 request.DecodeImage(jpg, false); 159 request.DecodeImage(jpg, false);
161 EXPECT_TRUE(request.bitmap().isNull()); 160 EXPECT_TRUE(request.bitmap().isNull());
162 } 161 }
163 162
164 } // namespace image_decoder 163 } // namespace data_decoder
OLDNEW
« no previous file with comments | « services/data_decoder/image_decoder_impl.cc ('k') | services/data_decoder/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698