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

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

Issue 6544028: Create a Factory for NativeMetafile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ARM compile failure fix 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/browser/printing/print_view_manager.cc ('k') | chrome/plugin/webplugin_delegate_stub.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 #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"
18 #include "printing/page_range.h" 17 #include "printing/page_range.h"
19 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 19 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "ui/gfx/rect.h" 20 #include "ui/gfx/rect.h"
22 21
22 #if defined(OS_WIN)
23 #include "printing/native_metafile_factory.h"
24 #include "printing/native_metafile.h"
25 #endif
26
23 // Tests that serialize/deserialize correctly understand each other 27 // Tests that serialize/deserialize correctly understand each other
24 TEST(IPCMessageTest, Serialize) { 28 TEST(IPCMessageTest, Serialize) {
25 const char* serialize_cases[] = { 29 const char* serialize_cases[] = {
26 "http://www.google.com/", 30 "http://www.google.com/",
27 "http://user:pass@host.com:888/foo;bar?baz#nop", 31 "http://user:pass@host.com:888/foo;bar?baz#nop",
28 "#inva://idurl/", 32 "#inva://idurl/",
29 }; 33 };
30 34
31 for (size_t i = 0; i < arraysize(serialize_cases); i++) { 35 for (size_t i = 0; i < arraysize(serialize_cases); i++) {
32 GURL input(serialize_cases[i]); 36 GURL input(serialize_cases[i]);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); 224 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
221 IPC::ParamTraits<printing::PageRange>::Write(&msg, input); 225 IPC::ParamTraits<printing::PageRange>::Write(&msg, input);
222 226
223 printing::PageRange output; 227 printing::PageRange output;
224 void* iter = NULL; 228 void* iter = NULL;
225 EXPECT_TRUE(IPC::ParamTraits<printing::PageRange>::Read( 229 EXPECT_TRUE(IPC::ParamTraits<printing::PageRange>::Read(
226 &msg, &iter, &output)); 230 &msg, &iter, &output));
227 EXPECT_TRUE(input == output); 231 EXPECT_TRUE(input == output);
228 } 232 }
229 233
230 // Tests printing::NativeMetafile serialization. 234 // Tests printing::Emf serialization.
231 // TODO(sanjeevr): Make this test meaningful for non-Windows platforms. We 235 // TODO(sanjeevr): Make this test meaningful for non-Windows platforms. We
232 // need to initialize the metafile using alternate means on the other OSes. 236 // need to initialize the metafile using alternate means on the other OSes.
233 #if defined(OS_WIN) 237 #if defined(OS_WIN)
234 TEST(IPCMessageTest, Metafile) { 238 TEST(IPCMessageTest, Metafile) {
235 printing::NativeMetafile metafile; 239 scoped_ptr<printing::NativeMetafile> metafile(
240 printing::NativeMetafileFactory::CreateMetafile());
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 scoped_ptr<printing::NativeMetafile> output(
250 printing::NativeMetafileFactory::CreateMetafile());
245 void* iter = NULL; 251 void* iter = NULL;
246 EXPECT_TRUE(IPC::ParamTraits<printing::NativeMetafile>::Read( 252 EXPECT_TRUE(IPC::ParamTraits<printing::NativeMetafile>::Read(
247 &msg, &iter, &output)); 253 &msg, &iter, output.get()));
248 254
249 EXPECT_EQ(metafile.GetDataSize(), output.GetDataSize()); 255 EXPECT_EQ(metafile->GetDataSize(), output->GetDataSize());
250 EXPECT_EQ(metafile.GetBounds(), output.GetBounds()); 256 EXPECT_EQ(metafile->GetBounds(), output->GetBounds());
251 EXPECT_EQ(::GetDeviceCaps(metafile.hdc(), LOGPIXELSX), 257 EXPECT_EQ(::GetDeviceCaps(metafile->hdc(), LOGPIXELSX),
252 ::GetDeviceCaps(output.hdc(), LOGPIXELSX)); 258 ::GetDeviceCaps(output->hdc(), LOGPIXELSX));
253 259
254 // Also test the corrupt case. 260 // Also test the corrupt case.
255 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); 261 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
256 // Write some bogus metafile data. 262 // Write some bogus metafile data.
257 const size_t bogus_data_size = metafile.GetDataSize() * 2; 263 const size_t bogus_data_size = metafile->GetDataSize() * 2;
258 scoped_array<char> bogus_data(new char[bogus_data_size]); 264 scoped_array<char> bogus_data(new char[bogus_data_size]);
259 memset(bogus_data.get(), 'B', bogus_data_size); 265 memset(bogus_data.get(), 'B', bogus_data_size);
260 bad_msg.WriteData(bogus_data.get(), bogus_data_size); 266 bad_msg.WriteData(bogus_data.get(), bogus_data_size);
261 // Make sure we don't read out the metafile! 267 // Make sure we don't read out the metafile!
262 printing::NativeMetafile bad_output; 268 scoped_ptr<printing::NativeMetafile> bad_output(
269 printing::NativeMetafileFactory::CreateMetafile());
263 iter = NULL; 270 iter = NULL;
264 EXPECT_FALSE(IPC::ParamTraits<printing::NativeMetafile>::Read( 271 EXPECT_FALSE(IPC::ParamTraits<printing::NativeMetafile>::Read(
265 &bad_msg, &iter, &bad_output)); 272 &bad_msg, &iter, bad_output.get()));
266 } 273 }
267 #endif // defined(OS_WIN) 274 #endif // defined(OS_WIN)
268 275
269 // Tests printing::PrinterCapsAndDefaults serialization 276 // Tests printing::PrinterCapsAndDefaults serialization
270 TEST(IPCMessageTest, PrinterCapsAndDefaults) { 277 TEST(IPCMessageTest, PrinterCapsAndDefaults) {
271 printing::PrinterCapsAndDefaults input; 278 printing::PrinterCapsAndDefaults input;
272 input.printer_capabilities = "Test Capabilities"; 279 input.printer_capabilities = "Test Capabilities";
273 input.caps_mime_type = "text/plain"; 280 input.caps_mime_type = "text/plain";
274 input.printer_defaults = "Test Defaults"; 281 input.printer_defaults = "Test Defaults";
275 input.defaults_mime_type = "text/plain"; 282 input.defaults_mime_type = "text/plain";
(...skipping 17 matching lines...) Expand all
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 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_view_manager.cc ('k') | chrome/plugin/webplugin_delegate_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698