| 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 #include "printing/native_metafile.h" |
| 17 #include "printing/page_range.h" | 18 #include "printing/page_range.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
| 21 | 22 |
| 22 #if defined(OS_WIN) | |
| 23 #include "printing/native_metafile_factory.h" | |
| 24 #include "printing/native_metafile.h" | |
| 25 #endif | |
| 26 | |
| 27 // Tests that serialize/deserialize correctly understand each other | 23 // Tests that serialize/deserialize correctly understand each other |
| 28 TEST(IPCMessageTest, Serialize) { | 24 TEST(IPCMessageTest, Serialize) { |
| 29 const char* serialize_cases[] = { | 25 const char* serialize_cases[] = { |
| 30 "http://www.google.com/", | 26 "http://www.google.com/", |
| 31 "http://user:pass@host.com:888/foo;bar?baz#nop", | 27 "http://user:pass@host.com:888/foo;bar?baz#nop", |
| 32 "#inva://idurl/", | 28 "#inva://idurl/", |
| 33 }; | 29 }; |
| 34 | 30 |
| 35 for (size_t i = 0; i < arraysize(serialize_cases); i++) { | 31 for (size_t i = 0; i < arraysize(serialize_cases); i++) { |
| 36 GURL input(serialize_cases[i]); | 32 GURL input(serialize_cases[i]); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 220 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 225 IPC::ParamTraits<printing::PageRange>::Write(&msg, input); | 221 IPC::ParamTraits<printing::PageRange>::Write(&msg, input); |
| 226 | 222 |
| 227 printing::PageRange output; | 223 printing::PageRange output; |
| 228 void* iter = NULL; | 224 void* iter = NULL; |
| 229 EXPECT_TRUE(IPC::ParamTraits<printing::PageRange>::Read( | 225 EXPECT_TRUE(IPC::ParamTraits<printing::PageRange>::Read( |
| 230 &msg, &iter, &output)); | 226 &msg, &iter, &output)); |
| 231 EXPECT_TRUE(input == output); | 227 EXPECT_TRUE(input == output); |
| 232 } | 228 } |
| 233 | 229 |
| 234 // Tests printing::Emf serialization. | 230 // Tests printing::NativeMetafile serialization. |
| 235 // TODO(sanjeevr): Make this test meaningful for non-Windows platforms. We | 231 // TODO(sanjeevr): Make this test meaningful for non-Windows platforms. We |
| 236 // need to initialize the metafile using alternate means on the other OSes. | 232 // need to initialize the metafile using alternate means on the other OSes. |
| 237 #if defined(OS_WIN) | 233 #if defined(OS_WIN) |
| 238 TEST(IPCMessageTest, Metafile) { | 234 TEST(IPCMessageTest, Metafile) { |
| 239 scoped_ptr<printing::NativeMetafile> metafile( | 235 printing::NativeMetafile metafile; |
| 240 printing::NativeMetafileFactory::CreateMetafile()); | |
| 241 RECT test_rect = {0, 0, 100, 100}; | 236 RECT test_rect = {0, 0, 100, 100}; |
| 242 // Create a metafile using the screen DC as a reference. | 237 // Create a metsfile using the screen DC as a reference. |
| 243 metafile->CreateDc(NULL, NULL); | 238 metafile.CreateDc(NULL, NULL); |
| 244 metafile->CloseDc(); | 239 metafile.CloseDc(); |
| 245 | 240 |
| 246 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 241 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 247 IPC::ParamTraits<printing::NativeMetafile>::Write(&msg, *metafile); | 242 IPC::ParamTraits<printing::NativeMetafile>::Write(&msg, metafile); |
| 248 | 243 |
| 249 scoped_ptr<printing::NativeMetafile> output( | 244 printing::NativeMetafile output; |
| 250 printing::NativeMetafileFactory::CreateMetafile()); | |
| 251 void* iter = NULL; | 245 void* iter = NULL; |
| 252 EXPECT_TRUE(IPC::ParamTraits<printing::NativeMetafile>::Read( | 246 EXPECT_TRUE(IPC::ParamTraits<printing::NativeMetafile>::Read( |
| 253 &msg, &iter, output.get())); | 247 &msg, &iter, &output)); |
| 254 | 248 |
| 255 EXPECT_EQ(metafile->GetDataSize(), output->GetDataSize()); | 249 EXPECT_EQ(metafile.GetDataSize(), output.GetDataSize()); |
| 256 EXPECT_EQ(metafile->GetBounds(), output->GetBounds()); | 250 EXPECT_EQ(metafile.GetBounds(), output.GetBounds()); |
| 257 EXPECT_EQ(::GetDeviceCaps(metafile->hdc(), LOGPIXELSX), | 251 EXPECT_EQ(::GetDeviceCaps(metafile.hdc(), LOGPIXELSX), |
| 258 ::GetDeviceCaps(output->hdc(), LOGPIXELSX)); | 252 ::GetDeviceCaps(output.hdc(), LOGPIXELSX)); |
| 259 | 253 |
| 260 // Also test the corrupt case. | 254 // Also test the corrupt case. |
| 261 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 255 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 262 // Write some bogus metafile data. | 256 // Write some bogus metafile data. |
| 263 const size_t bogus_data_size = metafile->GetDataSize() * 2; | 257 const size_t bogus_data_size = metafile.GetDataSize() * 2; |
| 264 scoped_array<char> bogus_data(new char[bogus_data_size]); | 258 scoped_array<char> bogus_data(new char[bogus_data_size]); |
| 265 memset(bogus_data.get(), 'B', bogus_data_size); | 259 memset(bogus_data.get(), 'B', bogus_data_size); |
| 266 bad_msg.WriteData(bogus_data.get(), bogus_data_size); | 260 bad_msg.WriteData(bogus_data.get(), bogus_data_size); |
| 267 // Make sure we don't read out the metafile! | 261 // Make sure we don't read out the metafile! |
| 268 scoped_ptr<printing::NativeMetafile> bad_output( | 262 printing::NativeMetafile bad_output; |
| 269 printing::NativeMetafileFactory::CreateMetafile()); | |
| 270 iter = NULL; | 263 iter = NULL; |
| 271 EXPECT_FALSE(IPC::ParamTraits<printing::NativeMetafile>::Read( | 264 EXPECT_FALSE(IPC::ParamTraits<printing::NativeMetafile>::Read( |
| 272 &bad_msg, &iter, bad_output.get())); | 265 &bad_msg, &iter, &bad_output)); |
| 273 } | 266 } |
| 274 #endif // defined(OS_WIN) | 267 #endif // defined(OS_WIN) |
| 275 | 268 |
| 276 // Tests printing::PrinterCapsAndDefaults serialization | 269 // Tests printing::PrinterCapsAndDefaults serialization |
| 277 TEST(IPCMessageTest, PrinterCapsAndDefaults) { | 270 TEST(IPCMessageTest, PrinterCapsAndDefaults) { |
| 278 printing::PrinterCapsAndDefaults input; | 271 printing::PrinterCapsAndDefaults input; |
| 279 input.printer_capabilities = "Test Capabilities"; | 272 input.printer_capabilities = "Test Capabilities"; |
| 280 input.caps_mime_type = "text/plain"; | 273 input.caps_mime_type = "text/plain"; |
| 281 input.printer_defaults = "Test Defaults"; | 274 input.printer_defaults = "Test Defaults"; |
| 282 input.defaults_mime_type = "text/plain"; | 275 input.defaults_mime_type = "text/plain"; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 300 | 293 |
| 301 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 294 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 302 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); | 295 IPC::ParamTraits<net::HostPortPair>::Write(&msg, input); |
| 303 | 296 |
| 304 net::HostPortPair output; | 297 net::HostPortPair output; |
| 305 void* iter = NULL; | 298 void* iter = NULL; |
| 306 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); | 299 EXPECT_TRUE(IPC::ParamTraits<net::HostPortPair>::Read(&msg, &iter, &output)); |
| 307 EXPECT_EQ(input.host(), output.host()); | 300 EXPECT_EQ(input.host(), output.host()); |
| 308 EXPECT_EQ(input.port(), output.port()); | 301 EXPECT_EQ(input.port(), output.port()); |
| 309 } | 302 } |
| OLD | NEW |