Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / printing / backend / cups_helper_unittest.cc
blob01c5c65d36427647bf5218790045d7277928750c
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
3 // found in the LICENSE file.
5 #include "printing/backend/cups_helper.h"
6 #include "printing/backend/print_backend.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorDuplexLongEdge) {
10 std::string test_ppd_data;
11 test_ppd_data.append(
12 "*PPD-Adobe: \"4.3\"\n\n"
13 "*OpenGroup: General/General\n\n"
14 "*OpenUI *ColorModel/Color Model: PickOne\n"
15 "*DefaultColorModel: Gray\n"
16 "*ColorModel Gray/Grayscale: \""
17 "<</cupsColorSpace 0/cupsColorOrder 0>>"
18 "setpagedevice\"\n"
19 "*ColorModel Black/Inverted Grayscale: \""
20 "<</cupsColorSpace 3/cupsColorOrder 0>>"
21 "setpagedevice\"\n"
22 "*CloseUI: *ColorModel\n"
23 "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
24 "*DefaultDuplex: DuplexTumble\n"
25 "*Duplex None/Off: \"<</Duplex false>>"
26 "setpagedevice\"\n"
27 "*Duplex DuplexNoTumble/LongEdge: \""
28 "<</Duplex true/Tumble false>>setpagedevice\"\n"
29 "*Duplex DuplexTumble/ShortEdge: \""
30 "<</Duplex true/Tumble true>>setpagedevice\"\n"
31 "*CloseUI: *Duplex\n\n"
32 "*CloseGroup: General\n");
34 printing::PrinterSemanticCapsAndDefaults caps;
35 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps));
36 EXPECT_TRUE(caps.collate_capable);
37 EXPECT_TRUE(caps.collate_default);
38 EXPECT_TRUE(caps.copies_capable);
39 EXPECT_TRUE(caps.duplex_capable);
40 EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
41 EXPECT_FALSE(caps.color_changeable);
42 EXPECT_FALSE(caps.color_default);
45 // Test duplex detection code, which regressed in http://crbug.com/103999.
46 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorDuplexSimples) {
47 std::string test_ppd_data;
48 test_ppd_data.append(
49 "*PPD-Adobe: \"4.3\"\n\n"
50 "*OpenGroup: General/General\n\n"
51 "*OpenUI *Duplex/Double-Sided Printing: PickOne\n"
52 "*DefaultDuplex: None\n"
53 "*Duplex None/Off: "
54 "\"<</Duplex false>>setpagedevice\"\n"
55 "*Duplex DuplexNoTumble/Long Edge (Standard): "
56 "\"<</Duplex true/Tumble false>>setpagedevice\"\n"
57 "*Duplex DuplexTumble/Short Edge (Flip): "
58 "\"<</Duplex true/Tumble true>>setpagedevice\"\n"
59 "*CloseUI: *Duplex\n\n"
60 "*CloseGroup: General\n");
62 printing::PrinterSemanticCapsAndDefaults caps;
63 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps));
64 EXPECT_TRUE(caps.collate_capable);
65 EXPECT_TRUE(caps.collate_default);
66 EXPECT_TRUE(caps.copies_capable);
67 EXPECT_TRUE(caps.duplex_capable);
68 EXPECT_EQ(caps.duplex_default, printing::SIMPLEX);
69 EXPECT_FALSE(caps.color_changeable);
70 EXPECT_FALSE(caps.color_default);
73 TEST(PrintBackendCupsHelperTest, TestPpdParsingNoColorNoDuplex) {
74 std::string test_ppd_data;
75 test_ppd_data.append(
76 "*PPD-Adobe: \"4.3\"\n\n"
77 "*OpenGroup: General/General\n\n"
78 "*OpenUI *ColorModel/Color Model: PickOne\n"
79 "*DefaultColorModel: Gray\n"
80 "*ColorModel Gray/Grayscale: \""
81 "<</cupsColorSpace 0/cupsColorOrder 0>>"
82 "setpagedevice\"\n"
83 "*ColorModel Black/Inverted Grayscale: \""
84 "<</cupsColorSpace 3/cupsColorOrder 0>>"
85 "setpagedevice\"\n"
86 "*CloseUI: *ColorModel\n"
87 "*CloseGroup: General\n");
89 printing::PrinterSemanticCapsAndDefaults caps;
90 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps));
91 EXPECT_TRUE(caps.collate_capable);
92 EXPECT_TRUE(caps.collate_default);
93 EXPECT_TRUE(caps.copies_capable);
94 EXPECT_FALSE(caps.duplex_capable);
95 EXPECT_EQ(caps.duplex_default, printing::UNKNOWN_DUPLEX_MODE);
96 EXPECT_FALSE(caps.color_changeable);
97 EXPECT_FALSE(caps.color_default);
100 TEST(PrintBackendCupsHelperTest, TestPpdParsingColorTrueDuplexLongEdge) {
101 std::string test_ppd_data;
102 test_ppd_data.append(
103 "*PPD-Adobe: \"4.3\"\n\n"
104 "*ColorDevice: True\n"
105 "*DefaultColorSpace: CMYK\n\n"
106 "*OpenGroup: General/General\n\n"
107 "*OpenUI *ColorModel/Color Model: PickOne\n"
108 "*DefaultColorModel: CMYK\n"
109 "*ColorModel CMYK/Color: "
110 "\"(cmyk) RCsetdevicecolor\"\n"
111 "*ColorModel Gray/Black and White: "
112 "\"(gray) RCsetdevicecolor\"\n"
113 "*CloseUI: *ColorModel\n"
114 "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
115 "*DefaultDuplex: DuplexTumble\n"
116 "*Duplex None/Off: \"<</Duplex false>>"
117 "setpagedevice\"\n"
118 "*Duplex DuplexNoTumble/LongEdge: \""
119 "<</Duplex true/Tumble false>>setpagedevice\"\n"
120 "*Duplex DuplexTumble/ShortEdge: \""
121 "<</Duplex true/Tumble true>>setpagedevice\"\n"
122 "*CloseUI: *Duplex\n\n"
123 "*CloseGroup: General\n");
125 printing::PrinterSemanticCapsAndDefaults caps;
126 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps));
127 EXPECT_TRUE(caps.collate_capable);
128 EXPECT_TRUE(caps.collate_default);
129 EXPECT_TRUE(caps.copies_capable);
130 EXPECT_TRUE(caps.duplex_capable);
131 EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
132 EXPECT_TRUE(caps.color_changeable);
133 EXPECT_TRUE(caps.color_default);
136 TEST(PrintBackendCupsHelperTest, TestPpdParsingColorFalseDuplexLongEdge) {
137 std::string test_ppd_data;
138 test_ppd_data.append(
139 "*PPD-Adobe: \"4.3\"\n\n"
140 "*ColorDevice: True\n"
141 "*DefaultColorSpace: CMYK\n\n"
142 "*OpenGroup: General/General\n\n"
143 "*OpenUI *ColorModel/Color Model: PickOne\n"
144 "*DefaultColorModel: Grayscale\n"
145 "*ColorModel Color/Color: "
146 "\"%% FoomaticRIPOptionSetting: ColorModel=Color\"\n"
147 "*FoomaticRIPOptionSetting ColorModel=Color: "
148 "\"JCLDatamode=Color GSCmdLine=Color\"\n"
149 "*ColorModel Grayscale/Grayscale: "
150 "\"%% FoomaticRIPOptionSetting: ColorModel=Grayscale\"\n"
151 "*FoomaticRIPOptionSetting ColorModel=Grayscale: "
152 "\"JCLDatamode=Grayscale GSCmdLine=Grayscale\"\n"
153 "*CloseUI: *ColorModel\n"
154 "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
155 "*DefaultDuplex: DuplexTumble\n"
156 "*Duplex None/Off: \"<</Duplex false>>"
157 "setpagedevice\"\n"
158 "*Duplex DuplexNoTumble/LongEdge: \""
159 "<</Duplex true/Tumble false>>setpagedevice\"\n"
160 "*Duplex DuplexTumble/ShortEdge: \""
161 "<</Duplex true/Tumble true>>setpagedevice\"\n"
162 "*CloseUI: *Duplex\n\n"
163 "*CloseGroup: General\n");
165 printing::PrinterSemanticCapsAndDefaults caps;
166 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps));
167 EXPECT_TRUE(caps.collate_capable);
168 EXPECT_TRUE(caps.collate_default);
169 EXPECT_TRUE(caps.copies_capable);
170 EXPECT_TRUE(caps.duplex_capable);
171 EXPECT_EQ(caps.duplex_default, printing::LONG_EDGE);
172 EXPECT_TRUE(caps.color_changeable);
173 EXPECT_FALSE(caps.color_default);
176 TEST(PrintBackendCupsHelperTest, TestPpdParsingPageSize) {
177 std::string test_ppd_data;
178 test_ppd_data.append(
179 "*PPD-Adobe: \"4.3\"\n\n"
180 "*OpenUI *PageSize: PickOne\n"
181 "*OrderDependency: 30 AnySetup *PageSize\n"
182 "*DefaultPageSize: Letter\n"
183 "*PageSize Letter/US Letter: \""
184 " <</DeferredMediaSelection true /PageSize [612 792] "
185 " /ImagingBBox null /MediaClass null >> setpagedevice\"\n"
186 "*End\n"
187 "*PageSize Legal/US Legal: \""
188 " <</DeferredMediaSelection true /PageSize [612 1008] "
189 " /ImagingBBox null /MediaClass null >> setpagedevice\"\n"
190 "*End\n"
191 "*DefaultPaperDimension: Letter\n"
192 "*PaperDimension Letter/US Letter: \"612 792\"\n"
193 "*PaperDimension Legal/US Legal: \"612 1008\"\n\n"
194 "*CloseUI: *PageSize\n\n");
196 printing::PrinterSemanticCapsAndDefaults caps;
197 EXPECT_TRUE(printing::ParsePpdCapabilities("test", test_ppd_data, &caps));
198 ASSERT_EQ(2UL, caps.papers.size());
199 EXPECT_EQ("Letter", caps.papers[0].vendor_id);
200 EXPECT_EQ("US Letter", caps.papers[0].display_name);
201 EXPECT_EQ(215900, caps.papers[0].size_um.width());
202 EXPECT_EQ(279400, caps.papers[0].size_um.height());
203 EXPECT_EQ("Legal", caps.papers[1].vendor_id);
204 EXPECT_EQ("US Legal", caps.papers[1].display_name);
205 EXPECT_EQ(215900, caps.papers[1].size_um.width());
206 EXPECT_EQ(355600, caps.papers[1].size_um.height());