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

Side by Side Diff: chrome/common/ipc_message_unittest.cc

Issue 99033: Merge r14408 and r14413. (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/branches/172/src/
Patch Set: Created 11 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 | « no previous file | chrome/common/ipc_message_utils.cc » ('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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <string.h> 5 #include <string.h>
6 6
7 #include "chrome/common/ipc_message.h" 7 #include "chrome/common/ipc_message.h"
8 #include "chrome/common/ipc_message_utils.h" 8 #include "chrome/common/ipc_message_utils.h"
9 #include "base/scoped_ptr.h"
9 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
13 #include "SkBitmap.h"
14
12 // Tests that serialize/deserialize correctly understand each other 15 // Tests that serialize/deserialize correctly understand each other
13 TEST(IPCMessageTest, Serialize) { 16 TEST(IPCMessageTest, Serialize) {
14 const char* serialize_cases[] = { 17 const char* serialize_cases[] = {
15 "http://www.google.com/", 18 "http://www.google.com/",
16 "http://user:pass@host.com:888/foo;bar?baz#nop", 19 "http://user:pass@host.com:888/foo;bar?baz#nop",
17 "#inva://idurl/", 20 "#inva://idurl/",
18 }; 21 };
19 22
20 for (size_t i = 0; i < arraysize(serialize_cases); i++) { 23 for (size_t i = 0; i < arraysize(serialize_cases); i++) {
21 GURL input(serialize_cases[i]); 24 GURL input(serialize_cases[i]);
(...skipping 18 matching lines...) Expand all
40 EXPECT_EQ(input.ref(), output.ref()); 43 EXPECT_EQ(input.ref(), output.ref());
41 } 44 }
42 45
43 // Also test the corrupt case. 46 // Also test the corrupt case.
44 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); 47 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
45 msg.WriteInt(99); 48 msg.WriteInt(99);
46 GURL output; 49 GURL output;
47 void* iter = NULL; 50 void* iter = NULL;
48 EXPECT_FALSE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output)); 51 EXPECT_FALSE(IPC::ParamTraits<GURL>::Read(&msg, &iter, &output));
49 } 52 }
53
54 // Tests bitmap serialization.
55 TEST(IPCMessageTest, Bitmap) {
56 SkBitmap bitmap;
57
58 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 5);
59 bitmap.allocPixels();
60 memset(bitmap.getPixels(), 'A', bitmap.getSize());
61
62 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
63 IPC::ParamTraits<SkBitmap>::Write(&msg, bitmap);
64
65 SkBitmap output;
66 void* iter = NULL;
67 EXPECT_TRUE(IPC::ParamTraits<SkBitmap>::Read(&msg, &iter, &output));
68
69 EXPECT_EQ(bitmap.config(), output.config());
70 EXPECT_EQ(bitmap.width(), output.width());
71 EXPECT_EQ(bitmap.height(), output.height());
72 EXPECT_EQ(bitmap.rowBytes(), output.rowBytes());
73 EXPECT_EQ(bitmap.getSize(), output.getSize());
74 EXPECT_EQ(memcmp(bitmap.getPixels(), output.getPixels(), bitmap.getSize()),
75 0);
76
77 // Also test the corrupt case.
78 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
79 // Copy the first message block over to |bad_msg|.
80 const char* fixed_data;
81 int fixed_data_size;
82 iter = NULL;
83 msg.ReadData(&iter, &fixed_data, &fixed_data_size);
84 bad_msg.WriteData(fixed_data, fixed_data_size);
85 // Add some bogus pixel data.
86 const size_t bogus_pixels_size = bitmap.getSize() * 2;
87 scoped_array<char> bogus_pixels(new char[bogus_pixels_size]);
88 memset(bogus_pixels.get(), 'B', bogus_pixels_size);
89 bad_msg.WriteData(bogus_pixels.get(), bogus_pixels_size);
90 // Make sure we don't read out the bitmap!
91 SkBitmap bad_output;
92 iter = NULL;
93 EXPECT_FALSE(IPC::ParamTraits<SkBitmap>::Read(&bad_msg, &iter, &bad_output));
94 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/ipc_message_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698