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

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

Issue 6713084: Move the rest of the renderer->browser messages that belong in content. Also do a bunch of cleanup: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 | « chrome/common/common_param_traits.cc ('k') | chrome/common/devtools_messages.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <utility> 6 #include <utility>
7 7
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/common/common_param_traits.h"
11 #include "content/common/common_param_traits.h" 10 #include "content/common/common_param_traits.h"
12 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
13 #include "ipc/ipc_message.h" 12 #include "ipc/ipc_message.h"
14 #include "ipc/ipc_message_utils.h" 13 #include "ipc/ipc_message_utils.h"
15 #include "net/base/host_port_pair.h" 14 #include "net/base/host_port_pair.h"
16 #include "printing/backend/print_backend.h" 15 #include "printing/backend/print_backend.h"
17 #include "printing/page_range.h" 16 #include "printing/page_range.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/skia/include/core/SkBitmap.h" 18 #include "third_party/skia/include/core/SkBitmap.h"
20 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 169
171 EXPECT_TRUE(input.Equals(&output)); 170 EXPECT_TRUE(input.Equals(&output));
172 171
173 // Also test the corrupt case. 172 // Also test the corrupt case.
174 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); 173 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
175 bad_msg.WriteInt(99); 174 bad_msg.WriteInt(99);
176 iter = NULL; 175 iter = NULL;
177 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); 176 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output));
178 } 177 }
179 178
180 // Tests printing::PageRange serialization
181 TEST(IPCMessageTest, PageRange) {
182 printing::PageRange input;
183 input.from = 2;
184 input.to = 45;
185 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
186 IPC::ParamTraits<printing::PageRange>::Write(&msg, input);
187
188 printing::PageRange output;
189 void* iter = NULL;
190 EXPECT_TRUE(IPC::ParamTraits<printing::PageRange>::Read(
191 &msg, &iter, &output));
192 EXPECT_TRUE(input == output);
193 }
194
195 // Tests printing::Emf serialization.
196 // TODO(sanjeevr): Make this test meaningful for non-Windows platforms. We
197 // need to initialize the metafile using alternate means on the other OSes.
198 #if defined(OS_WIN)
199 TEST(IPCMessageTest, Metafile) {
200 scoped_ptr<printing::NativeMetafile> metafile(
201 printing::NativeMetafileFactory::Create());
202 RECT test_rect = {0, 0, 100, 100};
203 // Create a metafile using the screen DC as a reference.
204 metafile->Init();
205 metafile->FinishDocument();
206
207 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
208 IPC::ParamTraits<printing::NativeMetafile>::Write(&msg, *metafile);
209
210 scoped_ptr<printing::NativeMetafile> output(
211 printing::NativeMetafileFactory::Create());
212 void* iter = NULL;
213 EXPECT_TRUE(IPC::ParamTraits<printing::NativeMetafile>::Read(
214 &msg, &iter, output.get()));
215
216 EXPECT_EQ(metafile->GetDataSize(), output->GetDataSize());
217 EXPECT_EQ(metafile->GetPageBounds(1), output->GetPageBounds(1));
218 EXPECT_EQ(::GetDeviceCaps(metafile->context(), LOGPIXELSX),
219 ::GetDeviceCaps(output->context(), LOGPIXELSX));
220
221 // Also test the corrupt case.
222 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
223 // Write some bogus metafile data.
224 const size_t bogus_data_size = metafile->GetDataSize() * 2;
225 scoped_array<char> bogus_data(new char[bogus_data_size]);
226 memset(bogus_data.get(), 'B', bogus_data_size);
227 bad_msg.WriteData(bogus_data.get(), bogus_data_size);
228 // Make sure we don't read out the metafile!
229 scoped_ptr<printing::NativeMetafile> bad_output(
230 printing::NativeMetafileFactory::Create());
231 iter = NULL;
232 EXPECT_FALSE(IPC::ParamTraits<printing::NativeMetafile>::Read(
233 &bad_msg, &iter, bad_output.get()));
234 }
235 #endif // defined(OS_WIN)
236
237 // Tests printing::PrinterCapsAndDefaults serialization
238 TEST(IPCMessageTest, PrinterCapsAndDefaults) {
239 printing::PrinterCapsAndDefaults input;
240 input.printer_capabilities = "Test Capabilities";
241 input.caps_mime_type = "text/plain";
242 input.printer_defaults = "Test Defaults";
243 input.defaults_mime_type = "text/plain";
244
245 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
246 IPC::ParamTraits<printing::PrinterCapsAndDefaults>::Write(&msg, input);
247
248 printing::PrinterCapsAndDefaults output;
249 void* iter = NULL;
250 EXPECT_TRUE(IPC::ParamTraits<printing::PrinterCapsAndDefaults>::Read(
251 &msg, &iter, &output));
252 EXPECT_TRUE(input.printer_capabilities == output.printer_capabilities);
253 EXPECT_TRUE(input.caps_mime_type == output.caps_mime_type);
254 EXPECT_TRUE(input.printer_defaults == output.printer_defaults);
255 EXPECT_TRUE(input.defaults_mime_type == output.defaults_mime_type);
256 }
257
258 // Tests net::HostPortPair serialization 179 // Tests net::HostPortPair serialization
259 TEST(IPCMessageTest, HostPortPair) { 180 TEST(IPCMessageTest, HostPortPair) {
260 net::HostPortPair input("host.com", 12345); 181 net::HostPortPair input("host.com", 12345);
261 182
262 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); 183 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
263 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); 184 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input);
264 185
265 net::HostPortPair output; 186 net::HostPortPair output;
266 void* iter = NULL; 187 void* iter = NULL;
267 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); 188 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output));
268 EXPECT_EQ(input.host(), output.host()); 189 EXPECT_EQ(input.host(), output.host());
269 EXPECT_EQ(input.port(), output.port()); 190 EXPECT_EQ(input.port(), output.port());
270 } 191 }
OLDNEW
« no previous file with comments | « chrome/common/common_param_traits.cc ('k') | chrome/common/devtools_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698