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

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

Issue 1844103004: Convert the utility process image decoder into a Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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/chrome_content_utility_client.cc ('k') | chrome/utility/image_decoder_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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stddef.h>
6 #include <stdint.h>
7
8 #include "base/macros.h"
9 #include "build/build_config.h"
10 #include "chrome/common/chrome_utility_messages.h"
11 #include "chrome/utility/chrome_content_utility_client.h"
12 #include "ipc/ipc_channel.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/gfx/codec/jpeg_codec.h"
15
16 namespace {
17
18 bool CreateJPEGImage(int width,
19 int height,
20 SkColor color,
21 std::vector<unsigned char>* output) {
22 SkBitmap bitmap;
23 bitmap.allocN32Pixels(width, height);
24 bitmap.eraseColor(color);
25
26 const int kQuality = 50;
27 if (!gfx::JPEGCodec::Encode(
28 static_cast<const unsigned char*>(bitmap.getPixels()),
29 gfx::JPEGCodec::FORMAT_SkBitmap,
30 width,
31 height,
32 bitmap.rowBytes(),
33 kQuality,
34 output)) {
35 LOG(ERROR) << "Unable to encode " << width << "x" << height << " bitmap";
36 return false;
37 }
38 return true;
39 }
40
41 } // namespace
42
43 typedef testing::Test ChromeContentUtilityClientTest;
44
45 // Test that DecodeImage() doesn't return image message > (max message size)
46 TEST_F(ChromeContentUtilityClientTest, DecodeImageSizeLimit) {
47 // Using actual limit generates 14000 x 9400 images, which causes the test to
48 // timeout. We test with a smaller limit for efficiency.
49 const size_t kTestMessageSize = IPC::Channel::kMaximumMessageSize / 1024;
50 ChromeContentUtilityClient::set_max_ipc_message_size_for_test(
51 kTestMessageSize);
52 // Approx max height for 3:2 image that will fit in IPC message;
53 // 1.5 for width/height ratio, 4 for bytes/pixel
54 int max_height_for_msg = sqrt(kTestMessageSize / (1.5 * 4));
55 int base_msg_size = sizeof(ChromeUtilityHostMsg_DecodeImage_Succeeded);
56
57 // Sizes which should trigger dimension-halving 0, 1 and 2 times
58 int heights[] = { max_height_for_msg - 10,
59 max_height_for_msg + 10,
60 2 * max_height_for_msg + 10 };
61 int widths[] = { heights[0] * 3 / 2, heights[1] * 3 / 2, heights[2] * 3 / 2 };
62 for (size_t i = 0; i < arraysize(heights); i++) {
63 std::vector<unsigned char> jpg;
64 CreateJPEGImage(widths[i], heights[i], SK_ColorRED, &jpg);
65 SkBitmap bitmap = ChromeContentUtilityClient::DecodeImage(jpg, true);
66
67 // Check that image has been shrunk appropriately
68 EXPECT_LT(bitmap.computeSize64() + base_msg_size,
69 static_cast<int64_t>(kTestMessageSize));
70 // Android does its own image shrinking for memory conservation deeper in
71 // the decode, so more specific tests here won't work.
72 #if !defined(OS_ANDROID)
73 EXPECT_EQ(widths[i] >> i, bitmap.width());
74 EXPECT_EQ(heights[i] >> i, bitmap.height());
75
76 // Check that if resize not requested and image exceeds IPC size limit,
77 // an empty image is returned
78 if (heights[i] > max_height_for_msg) {
79 SkBitmap empty_bmp = ChromeContentUtilityClient::DecodeImage(jpg, false);
80 EXPECT_TRUE(empty_bmp.empty());
81 }
82 #endif
83 }
84 }
OLDNEW
« no previous file with comments | « chrome/utility/chrome_content_utility_client.cc ('k') | chrome/utility/image_decoder_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698