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

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

Issue 115491: Add IPC serialization for DictionaryValue, with unit tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/ipc_message_utils.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 (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 "base/scoped_ptr.h"
8 #include "base/values.h"
7 #include "chrome/common/ipc_message.h" 9 #include "chrome/common/ipc_message.h"
8 #include "chrome/common/ipc_message_utils.h" 10 #include "chrome/common/ipc_message_utils.h"
9 #include "base/scoped_ptr.h"
10 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/skia/include/core/SkBitmap.h" 13 #include "third_party/skia/include/core/SkBitmap.h"
13 14
14 // Tests that serialize/deserialize correctly understand each other 15 // Tests that serialize/deserialize correctly understand each other
15 TEST(IPCMessageTest, Serialize) { 16 TEST(IPCMessageTest, Serialize) {
16 const char* serialize_cases[] = { 17 const char* serialize_cases[] = {
17 "http://www.google.com/", 18 "http://www.google.com/",
18 "http://user:pass@host.com:888/foo;bar?baz#nop", 19 "http://user:pass@host.com:888/foo;bar?baz#nop",
19 "#inva://idurl/", 20 "#inva://idurl/",
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // Add some bogus pixel data. 85 // Add some bogus pixel data.
85 const size_t bogus_pixels_size = bitmap.getSize() * 2; 86 const size_t bogus_pixels_size = bitmap.getSize() * 2;
86 scoped_array<char> bogus_pixels(new char[bogus_pixels_size]); 87 scoped_array<char> bogus_pixels(new char[bogus_pixels_size]);
87 memset(bogus_pixels.get(), 'B', bogus_pixels_size); 88 memset(bogus_pixels.get(), 'B', bogus_pixels_size);
88 bad_msg.WriteData(bogus_pixels.get(), bogus_pixels_size); 89 bad_msg.WriteData(bogus_pixels.get(), bogus_pixels_size);
89 // Make sure we don't read out the bitmap! 90 // Make sure we don't read out the bitmap!
90 SkBitmap bad_output; 91 SkBitmap bad_output;
91 iter = NULL; 92 iter = NULL;
92 EXPECT_FALSE(IPC::ParamTraits<SkBitmap>::Read(&bad_msg, &iter, &bad_output)); 93 EXPECT_FALSE(IPC::ParamTraits<SkBitmap>::Read(&bad_msg, &iter, &bad_output));
93 } 94 }
95
96 TEST(IPCMessageTest, ListValue) {
97 ListValue input;
98 input.Set(0, Value::CreateRealValue(42.42));
99 input.Set(1, Value::CreateStringValue("forty"));
100 input.Set(2, Value::CreateNullValue());
101
102 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
103 IPC::WriteParam(&msg, input);
104
105 ListValue output;
106 void* iter = NULL;
107 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
108
109 EXPECT_TRUE(input.Equals(&output));
110
111 // Also test the corrupt case.
112 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
113 bad_msg.WriteInt(99);
114 iter = NULL;
115 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output));
116 }
117
118 TEST(IPCMessageTest, DictionaryValue) {
119 DictionaryValue input;
120 input.Set(L"null", Value::CreateNullValue());
121 input.Set(L"bool", Value::CreateBooleanValue(true));
122 input.Set(L"int", Value::CreateIntegerValue(42));
123
124 scoped_ptr<DictionaryValue> subdict(new DictionaryValue());
125 subdict->Set(L"str", Value::CreateStringValue("forty two"));
126 subdict->Set(L"bool", Value::CreateBooleanValue(false));
127
128 scoped_ptr<ListValue> sublist(new ListValue());
129 sublist->Set(0, Value::CreateRealValue(42.42));
130 sublist->Set(1, Value::CreateStringValue("forty"));
131 sublist->Set(2, Value::CreateStringValue("two"));
132 subdict->Set(L"list", sublist.release());
133
134 input.Set(L"dict", subdict.release());
135
136 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
137 IPC::WriteParam(&msg, input);
138
139 DictionaryValue output;
140 void* iter = NULL;
141 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
142
143 EXPECT_TRUE(input.Equals(&output));
144
145 // Also test the corrupt case.
146 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
147 bad_msg.WriteInt(99);
148 iter = NULL;
149 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output));
150 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/ipc_message_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698