OLD | NEW |
---|---|
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 #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" | 10 #include "chrome/common/common_param_traits.h" |
11 #include "chrome/common/geoposition.h" | 11 #include "chrome/common/geoposition.h" |
12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 #include "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
14 #include "ipc/ipc_message_utils.h" | 14 #include "ipc/ipc_message_utils.h" |
15 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
16 #include "printing/backend/print_backend.h" | 16 #include "printing/backend/print_backend.h" |
17 #if defined(OS_WIN) | |
kmadhusu
2011/03/01 19:42:38
Platform-specific headers needs to follow the cros
dpapad
2011/03/01 22:41:24
Done. I did it also for platform specific includes
| |
18 #include "printing/emf_win.h" | |
17 #include "printing/native_metafile.h" | 19 #include "printing/native_metafile.h" |
20 #endif | |
18 #include "printing/page_range.h" | 21 #include "printing/page_range.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
22 | 25 |
23 // Tests that serialize/deserialize correctly understand each other | 26 // Tests that serialize/deserialize correctly understand each other |
24 TEST(IPCMessageTest, Serialize) { | 27 TEST(IPCMessageTest, Serialize) { |
25 const char* serialize_cases[] = { | 28 const char* serialize_cases[] = { |
26 "http://www.google.com/", | 29 "http://www.google.com/", |
27 "http://user:pass@host.com:888/foo;bar?baz#nop", | 30 "http://user:pass@host.com:888/foo;bar?baz#nop", |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 std::string log_message; | 208 std::string log_message; |
206 IPC::LogParam(output, &log_message); | 209 IPC::LogParam(output, &log_message); |
207 EXPECT_STREQ("<Geoposition>" | 210 EXPECT_STREQ("<Geoposition>" |
208 "0.100000 51.300000 13.700000 42.240000 " | 211 "0.100000 51.300000 13.700000 42.240000 " |
209 "9.300000 55.000000 120.000000 " | 212 "9.300000 55.000000 120.000000 " |
210 "1977 unittest error message for geoposition" | 213 "1977 unittest error message for geoposition" |
211 "<Geoposition::ErrorCode>2", | 214 "<Geoposition::ErrorCode>2", |
212 log_message.c_str()); | 215 log_message.c_str()); |
213 } | 216 } |
214 | 217 |
218 namespace printing { | |
219 | |
215 // Tests printing::PageRange serialization | 220 // Tests printing::PageRange serialization |
216 TEST(IPCMessageTest, PageRange) { | 221 TEST(IPCMessageTest, PageRange) { |
217 printing::PageRange input; | 222 printing::PageRange input; |
218 input.from = 2; | 223 input.from = 2; |
219 input.to = 45; | 224 input.to = 45; |
220 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 225 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
221 IPC::ParamTraits<printing::PageRange>::Write(&msg, input); | 226 IPC::ParamTraits<printing::PageRange>::Write(&msg, input); |
222 | 227 |
223 printing::PageRange output; | 228 printing::PageRange output; |
224 void* iter = NULL; | 229 void* iter = NULL; |
225 EXPECT_TRUE(IPC::ParamTraits<printing::PageRange>::Read( | 230 EXPECT_TRUE(IPC::ParamTraits<printing::PageRange>::Read( |
226 &msg, &iter, &output)); | 231 &msg, &iter, &output)); |
227 EXPECT_TRUE(input == output); | 232 EXPECT_TRUE(input == output); |
228 } | 233 } |
229 | 234 |
230 // Tests printing::NativeMetafile serialization. | 235 // Tests printing::Emf serialization. |
vandebo (ex-Chrome)
2011/03/01 19:01:01
This is trying to tests NativeMetafile, not EMF.
dpapad
2011/03/01 22:41:24
Done. I also removed this test from the friend lis
| |
231 // TODO(sanjeevr): Make this test meaningful for non-Windows platforms. We | 236 // TODO(sanjeevr): Make this test meaningful for non-Windows platforms. We |
232 // need to initialize the metafile using alternate means on the other OSes. | 237 // need to initialize the metafile using alternate means on the other OSes. |
233 #if defined(OS_WIN) | 238 #if defined(OS_WIN) |
234 TEST(IPCMessageTest, Metafile) { | 239 TEST(IPCMessageTest, Metafile) { |
235 printing::NativeMetafile metafile; | 240 printing::Emf metafile; |
236 RECT test_rect = {0, 0, 100, 100}; | 241 RECT test_rect = {0, 0, 100, 100}; |
237 // Create a metsfile using the screen DC as a reference. | 242 // Create a metafile using the screen DC as a reference. |
238 metafile.CreateDc(NULL, NULL); | 243 metafile.CreateDc(NULL, NULL); |
239 metafile.CloseDc(); | 244 metafile.CloseDc(); |
240 | 245 |
241 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 246 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
242 IPC::ParamTraits<printing::NativeMetafile>::Write(&msg, metafile); | 247 IPC::ParamTraits<printing::NativeMetafile>::Write(&msg, metafile); |
243 | 248 |
244 printing::NativeMetafile output; | 249 printing::Emf output; |
245 void* iter = NULL; | 250 void* iter = NULL; |
246 EXPECT_TRUE(IPC::ParamTraits<printing::NativeMetafile>::Read( | 251 EXPECT_TRUE(IPC::ParamTraits<printing::NativeMetafile>::Read( |
247 &msg, &iter, &output)); | 252 &msg, &iter, &output)); |
248 | 253 |
249 EXPECT_EQ(metafile.GetDataSize(), output.GetDataSize()); | 254 EXPECT_EQ(metafile.GetDataSize(), output.GetDataSize()); |
250 EXPECT_EQ(metafile.GetBounds(), output.GetBounds()); | 255 EXPECT_EQ(metafile.GetBounds(), output.GetBounds()); |
251 EXPECT_EQ(::GetDeviceCaps(metafile.hdc(), LOGPIXELSX), | 256 EXPECT_EQ(::GetDeviceCaps(metafile.hdc(), LOGPIXELSX), |
252 ::GetDeviceCaps(output.hdc(), LOGPIXELSX)); | 257 ::GetDeviceCaps(output.hdc(), LOGPIXELSX)); |
253 | 258 |
254 // Also test the corrupt case. | 259 // Also test the corrupt case. |
255 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 260 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
256 // Write some bogus metafile data. | 261 // Write some bogus metafile data. |
257 const size_t bogus_data_size = metafile.GetDataSize() * 2; | 262 const size_t bogus_data_size = metafile.GetDataSize() * 2; |
258 scoped_array<char> bogus_data(new char[bogus_data_size]); | 263 scoped_array<char> bogus_data(new char[bogus_data_size]); |
259 memset(bogus_data.get(), 'B', bogus_data_size); | 264 memset(bogus_data.get(), 'B', bogus_data_size); |
260 bad_msg.WriteData(bogus_data.get(), bogus_data_size); | 265 bad_msg.WriteData(bogus_data.get(), bogus_data_size); |
261 // Make sure we don't read out the metafile! | 266 // Make sure we don't read out the metafile! |
262 printing::NativeMetafile bad_output; | 267 printing::Emf bad_output; |
263 iter = NULL; | 268 iter = NULL; |
264 EXPECT_FALSE(IPC::ParamTraits<printing::NativeMetafile>::Read( | 269 EXPECT_FALSE(IPC::ParamTraits<printing::NativeMetafile>::Read( |
265 &bad_msg, &iter, &bad_output)); | 270 &bad_msg, &iter, &bad_output)); |
266 } | 271 } |
267 #endif // defined(OS_WIN) | 272 #endif // defined(OS_WIN) |
268 | 273 |
269 // Tests printing::PrinterCapsAndDefaults serialization | 274 // Tests printing::PrinterCapsAndDefaults serialization |
270 TEST(IPCMessageTest, PrinterCapsAndDefaults) { | 275 TEST(IPCMessageTest, PrinterCapsAndDefaults) { |
271 printing::PrinterCapsAndDefaults input; | 276 printing::PrinterCapsAndDefaults input; |
272 input.printer_capabilities = "Test Capabilities"; | 277 input.printer_capabilities = "Test Capabilities"; |
273 input.caps_mime_type = "text/plain"; | 278 input.caps_mime_type = "text/plain"; |
274 input.printer_defaults = "Test Defaults"; | 279 input.printer_defaults = "Test Defaults"; |
275 input.defaults_mime_type = "text/plain"; | 280 input.defaults_mime_type = "text/plain"; |
276 | 281 |
277 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 282 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
278 IPC::ParamTraits<printing::PrinterCapsAndDefaults>::Write(&msg, input); | 283 IPC::ParamTraits<printing::PrinterCapsAndDefaults>::Write(&msg, input); |
279 | 284 |
280 printing::PrinterCapsAndDefaults output; | 285 printing::PrinterCapsAndDefaults output; |
281 void* iter = NULL; | 286 void* iter = NULL; |
282 EXPECT_TRUE(IPC::ParamTraits<printing::PrinterCapsAndDefaults>::Read( | 287 EXPECT_TRUE(IPC::ParamTraits<printing::PrinterCapsAndDefaults>::Read( |
283 &msg, &iter, &output)); | 288 &msg, &iter, &output)); |
284 EXPECT_TRUE(input.printer_capabilities == output.printer_capabilities); | 289 EXPECT_TRUE(input.printer_capabilities == output.printer_capabilities); |
285 EXPECT_TRUE(input.caps_mime_type == output.caps_mime_type); | 290 EXPECT_TRUE(input.caps_mime_type == output.caps_mime_type); |
286 EXPECT_TRUE(input.printer_defaults == output.printer_defaults); | 291 EXPECT_TRUE(input.printer_defaults == output.printer_defaults); |
287 EXPECT_TRUE(input.defaults_mime_type == output.defaults_mime_type); | 292 EXPECT_TRUE(input.defaults_mime_type == output.defaults_mime_type); |
288 } | 293 } |
289 | 294 |
295 } // namespace printing | |
296 | |
290 // Tests net::HostPortPair serialization | 297 // Tests net::HostPortPair serialization |
291 TEST(IPCMessageTest, HostPortPair) { | 298 TEST(IPCMessageTest, HostPortPair) { |
292 net::HostPortPair input("host.com", 12345); | 299 net::HostPortPair input("host.com", 12345); |
293 | 300 |
294 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 301 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
295 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); | 302 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); |
296 | 303 |
297 net::HostPortPair output; | 304 net::HostPortPair output; |
298 void* iter = NULL; | 305 void* iter = NULL; |
299 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); | 306 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); |
300 EXPECT_EQ(input.host(), output.host()); | 307 EXPECT_EQ(input.host(), output.host()); |
301 EXPECT_EQ(input.port(), output.port()); | 308 EXPECT_EQ(input.port(), output.port()); |
302 } | 309 } |
OLD | NEW |