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

Side by Side Diff: printing/emf_win_unittest.cc

Issue 478183005: Added PrintingContext::Delegate to get parent view handle and application locale. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "printing/emf_win.h" 5 #include "printing/emf_win.h"
6 6
7 // For quick access. 7 // For quick access.
8 #include <wingdi.h> 8 #include <wingdi.h>
9 #include <winspool.h> 9 #include <winspool.h>
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/win/scoped_hdc.h" 19 #include "base/win/scoped_hdc.h"
20 #include "printing/printing_context.h" 20 #include "printing/printing_context.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/gfx/point.h" 22 #include "ui/gfx/point.h"
23 #include "ui/gfx/size.h" 23 #include "ui/gfx/size.h"
24 24
25 namespace printing {
26
25 namespace { 27 namespace {
26 28
27 // This test is automatically disabled if no printer named "UnitTest Printer" is 29 // This test is automatically disabled if no printer named "UnitTest Printer" is
28 // available. 30 // available.
29 class EmfPrintingTest : public testing::Test { 31 class EmfPrintingTest : public testing::Test, public PrintingContext::Delegate {
30 public: 32 public:
31 typedef testing::Test Parent; 33 typedef testing::Test Parent;
32 static bool IsTestCaseDisabled() { 34 static bool IsTestCaseDisabled() {
33 // It is assumed this printer is a HP Color LaserJet 4550 PCL or 4700. 35 // It is assumed this printer is a HP Color LaserJet 4550 PCL or 4700.
34 HDC hdc = CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL); 36 HDC hdc = CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL);
35 if (!hdc) 37 if (!hdc)
36 return true; 38 return true;
37 DeleteDC(hdc); 39 DeleteDC(hdc);
38 return false; 40 return false;
39 } 41 }
42
43 // PrintingContext::Delegate methods.
44 virtual gfx::NativeView GetParentView() OVERRIDE { return NULL; }
45 virtual std::string GetAppLocale() OVERRIDE { return std::string(); }
40 }; 46 };
41 47
42 const uint32 EMF_HEADER_SIZE = 128; 48 const uint32 EMF_HEADER_SIZE = 128;
43 49
44 } // namespace 50 } // namespace
45 51
46 namespace printing {
47
48 TEST(EmfTest, DC) { 52 TEST(EmfTest, DC) {
49 // Simplest use case. 53 // Simplest use case.
50 uint32 size; 54 uint32 size;
51 std::vector<BYTE> data; 55 std::vector<BYTE> data;
52 { 56 {
53 Emf emf; 57 Emf emf;
54 EXPECT_TRUE(emf.Init()); 58 EXPECT_TRUE(emf.Init());
55 EXPECT_TRUE(emf.context() != NULL); 59 EXPECT_TRUE(emf.context() != NULL);
56 // An empty EMF is invalid, so we put at least a rectangle in it. 60 // An empty EMF is invalid, so we put at least a rectangle in it.
57 ::Rectangle(emf.context(), 10, 10, 190, 190); 61 ::Rectangle(emf.context(), 10, 10, 190, 190);
(...skipping 18 matching lines...) Expand all
76 TEST_F(EmfPrintingTest, Enumerate) { 80 TEST_F(EmfPrintingTest, Enumerate) {
77 if (IsTestCaseDisabled()) 81 if (IsTestCaseDisabled())
78 return; 82 return;
79 83
80 PrintSettings settings; 84 PrintSettings settings;
81 85
82 // My test case is a HP Color LaserJet 4550 PCL. 86 // My test case is a HP Color LaserJet 4550 PCL.
83 settings.set_device_name(L"UnitTest Printer"); 87 settings.set_device_name(L"UnitTest Printer");
84 88
85 // Initialize it. 89 // Initialize it.
86 scoped_ptr<PrintingContext> context(PrintingContext::Create(std::string())); 90 scoped_ptr<PrintingContext> context(PrintingContext::Create(this));
87 EXPECT_EQ(context->InitWithSettings(settings), PrintingContext::OK); 91 EXPECT_EQ(context->InitWithSettings(settings), PrintingContext::OK);
88 92
89 base::FilePath emf_file; 93 base::FilePath emf_file;
90 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &emf_file)); 94 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &emf_file));
91 emf_file = emf_file.Append(FILE_PATH_LITERAL("printing")) 95 emf_file = emf_file.Append(FILE_PATH_LITERAL("printing"))
92 .Append(FILE_PATH_LITERAL("test")) 96 .Append(FILE_PATH_LITERAL("test"))
93 .Append(FILE_PATH_LITERAL("data")) 97 .Append(FILE_PATH_LITERAL("data"))
94 .Append(FILE_PATH_LITERAL("test4.emf")); 98 .Append(FILE_PATH_LITERAL("test4.emf"));
95 // Load any EMF with an image. 99 // Load any EMF with an image.
96 Emf emf; 100 Emf emf;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); 225 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1));
222 226
223 raster.reset(emf.RasterizeMetafile(16*1024*1024)); 227 raster.reset(emf.RasterizeMetafile(16*1024*1024));
224 // Expected size about 64MB. 228 // Expected size about 64MB.
225 EXPECT_LE(abs(int(raster->GetDataSize()) - 64*1024*1024), 1024*1024); 229 EXPECT_LE(abs(int(raster->GetDataSize()) - 64*1024*1024), 1024*1024);
226 // Bounds should still be the same. 230 // Bounds should still be the same.
227 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1)); 231 EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1));
228 } 232 }
229 233
230 } // namespace printing 234 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698