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

Side by Side Diff: chrome/browser/printing/print_system_task_proxy_unittest.cc

Issue 8572036: CUPS: Add a regression test for duplex detection. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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_system_task_proxy.cc ('k') | chrome/chrome_tests.gypi » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <cups/cups.h> 5 #include <cups/cups.h>
6 6
7 #include <cstring> 7 #include <cstring>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
14 #include "chrome/browser/printing/print_system_task_proxy.h" 14 #include "chrome/browser/printing/print_system_task_proxy.h"
15 #include "printing/backend/print_backend.h" 15 #include "printing/backend/print_backend.h"
16 #include "printing/print_job_constants.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
19 #if !defined(OS_MACOSX)
18 namespace { 20 namespace {
19 21
20 // TestEntry stores the printer name and the expected number of options. 22 // TestEntry stores the printer name and the expected number of options.
21 struct TestEntry { 23 struct TestEntry {
22 TestEntry(std::string name, int count) 24 TestEntry(std::string name, int count)
23 : printer_name(name), 25 : printer_name(name),
24 expected_option_count(count) {} 26 expected_option_count(count) {}
25 27
26 std::string printer_name; 28 std::string printer_name;
27 int expected_option_count; 29 int expected_option_count;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 user_lpoptions.append("Dest printerE Duplex="+kDuplexNoTumble+"\n"); 79 user_lpoptions.append("Dest printerE Duplex="+kDuplexNoTumble+"\n");
78 80
79 // Create and write the user lpoptions to a temp file. 81 // Create and write the user lpoptions to a temp file.
80 FilePath user_lp_options_file; 82 FilePath user_lp_options_file;
81 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_directory.path(), 83 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_directory.path(),
82 &user_lp_options_file)); 84 &user_lp_options_file));
83 ASSERT_TRUE(file_util::WriteFile(user_lp_options_file, user_lpoptions.c_str(), 85 ASSERT_TRUE(file_util::WriteFile(user_lp_options_file, user_lpoptions.c_str(),
84 user_lpoptions.size())); 86 user_lpoptions.size()));
85 // Specifies the test ppd data. 87 // Specifies the test ppd data.
86 std::string test_ppd_data; 88 std::string test_ppd_data;
87 test_ppd_data.append("*PPD-Adobe: \"4.3\"\n"); 89 test_ppd_data.append("*PPD-Adobe: \"4.3\"\n\n"
88 test_ppd_data.append("\n*OpenGroup: General/General\n\n"); 90 "*OpenGroup: General/General\n\n"
89 test_ppd_data.append("*OpenUI *ColorModel/Color Model: PickOne\n"); 91 "*OpenUI *ColorModel/Color Model: PickOne\n"
90 test_ppd_data.append("*DefaultColorModel: Gray\n"); 92 "*DefaultColorModel: Gray\n"
91 test_ppd_data.append("*ColorModel Gray/Grayscale: \""); 93 "*ColorModel Gray/Grayscale: \""
92 test_ppd_data.append("<</cupsColorSpace 0/cupsColorOrder 0>>"); 94 "<</cupsColorSpace 0/cupsColorOrder 0>>"
93 test_ppd_data.append("setpagedevice\"\n"); 95 "setpagedevice\"\n"
94 test_ppd_data.append("*ColorModel Black/Inverted Grayscale: \""); 96 "*ColorModel Black/Inverted Grayscale: \""
95 test_ppd_data.append("<</cupsColorSpace 3/cupsColorOrder 0>>"); 97 "<</cupsColorSpace 3/cupsColorOrder 0>>"
96 test_ppd_data.append("setpagedevice\"\n"); 98 "setpagedevice\"\n"
97 test_ppd_data.append("*CloseUI: *ColorModel\n"); 99 "*CloseUI: *ColorModel\n"
98 test_ppd_data.append("*OpenUI *Duplex/2-Sided Printing: PickOne\n"); 100 "*OpenUI *Duplex/2-Sided Printing: PickOne\n"
99 test_ppd_data.append("*DefaultDuplex: DuplexTumble\n"); 101 "*DefaultDuplex: DuplexTumble\n"
100 test_ppd_data.append("*Duplex None/Off: \"<</Duplex false>>"); 102 "*Duplex None/Off: \"<</Duplex false>>"
101 test_ppd_data.append("setpagedevice\"\n"); 103 "setpagedevice\"\n"
102 test_ppd_data.append("*Duplex DuplexNoTumble/LongEdge: \""); 104 "*Duplex DuplexNoTumble/LongEdge: \""
103 test_ppd_data.append("<</Duplex true/Tumble false>>setpagedevice\"\n"); 105 "<</Duplex true/Tumble false>>setpagedevice\"\n"
104 test_ppd_data.append("*Duplex DuplexTumble/ShortEdge: \""); 106 "*Duplex DuplexTumble/ShortEdge: \""
105 test_ppd_data.append("<</Duplex true/Tumble true>>setpagedevice\"\n"); 107 "<</Duplex true/Tumble true>>setpagedevice\"\n"
106 test_ppd_data.append("*CloseUI: *Duplex\n\n"); 108 "*CloseUI: *Duplex\n\n"
107 test_ppd_data.append("*CloseGroup: General\n"); 109 "*CloseGroup: General\n");
108 110
109 // Create a test ppd file. 111 // Create a test ppd file.
110 FilePath ppd_file_path; 112 FilePath ppd_file_path;
111 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_directory.path(), 113 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_directory.path(),
112 &ppd_file_path)); 114 &ppd_file_path));
113 ASSERT_TRUE(file_util::WriteFile(ppd_file_path, test_ppd_data.c_str(), 115 ASSERT_TRUE(file_util::WriteFile(ppd_file_path, test_ppd_data.c_str(),
114 test_ppd_data.size())); 116 test_ppd_data.size()));
115 117
116 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str()); 118 ppd_file_t* ppd = ppdOpenFile(ppd_file_path.value().c_str());
117 ASSERT_TRUE(ppd); 119 ASSERT_TRUE(ppd);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 it != test_cases.end(); ++it) { 216 it != test_cases.end(); ++it) {
215 num_options = 0; 217 num_options = 0;
216 options = NULL; 218 options = NULL;
217 printing_internal::parse_lpoptions(userLpOptionsFile, it->printer_name, 219 printing_internal::parse_lpoptions(userLpOptionsFile, it->printer_name,
218 &num_options, &options); 220 &num_options, &options);
219 ASSERT_EQ(num_options, it->expected_option_count); 221 ASSERT_EQ(num_options, it->expected_option_count);
220 EXPECT_EQ(num_options != 0, options != NULL); 222 EXPECT_EQ(num_options != 0, options != NULL);
221 cupsFreeOptions(num_options, options); 223 cupsFreeOptions(num_options, options);
222 } 224 }
223 } 225 }
226 #endif // !defined(OS_MACOSX)
227
228 // Test duplex detection code, which regressed in http://crbug.com/103999.
229 TEST(PrintSystemTaskProxyTest, DetectDuplexModeCUPS) {
230 // Specifies the test ppd data.
231 printing::PrinterCapsAndDefaults printer_info;
232 printer_info.printer_capabilities.append(
233 "*PPD-Adobe: \"4.3\"\n\n"
234 "*OpenGroup: General/General\n\n"
235 "*OpenUI *Duplex/Double-Sided Printing: PickOne\n"
236 "*DefaultDuplex: None\n"
237 "*Duplex None/Off: "
238 "\"<</Duplex false>>setpagedevice\"\n"
239 "*Duplex DuplexNoTumble/Long Edge (Standard): "
240 "\"<</Duplex true/Tumble false>>setpagedevice\"\n"
241 "*Duplex DuplexTumble/Short Edge (Flip): "
242 "\"<</Duplex true/Tumble true>>setpagedevice\"\n"
243 "*CloseUI: *Duplex\n\n"
244 "*CloseGroup: General\n");
245
246 bool set_color_as_default = false;
247 bool set_duplex_as_default = false;
248 int printer_color_space_for_color = printing::UNKNOWN_COLOR_MODEL;
249 int printer_color_space_for_black = printing::UNKNOWN_COLOR_MODEL;
250 int default_duplex_setting_value = printing::UNKNOWN_DUPLEX_MODE;
251
252 scoped_refptr<PrintSystemTaskProxy> test_proxy;
253 bool res = test_proxy->GetPrinterCapabilitiesCUPS(
254 printer_info,
255 "InvalidPrinter",
256 &set_color_as_default,
257 &printer_color_space_for_color,
258 &printer_color_space_for_black,
259 &set_duplex_as_default,
260 &default_duplex_setting_value);
261 ASSERT_TRUE(res);
262 EXPECT_FALSE(set_duplex_as_default);
263 EXPECT_EQ(printing::SIMPLEX, default_duplex_setting_value);
264 }
265
266 TEST(PrintSystemTaskProxyTest, DetectNoDuplexModeCUPS) {
267 // Specifies the test ppd data.
268 printing::PrinterCapsAndDefaults printer_info;
269 printer_info.printer_capabilities.append(
270 "*PPD-Adobe: \"4.3\"\n\n"
271 "*OpenGroup: General/General\n\n"
272 "*CloseGroup: General\n");
273
274 bool set_color_as_default = false;
275 bool set_duplex_as_default = false;
276 int printer_color_space_for_color = printing::UNKNOWN_COLOR_MODEL;
277 int printer_color_space_for_black = printing::UNKNOWN_COLOR_MODEL;
278 int default_duplex_setting_value = printing::UNKNOWN_DUPLEX_MODE;
279
280 scoped_refptr<PrintSystemTaskProxy> test_proxy;
281 bool res = test_proxy->GetPrinterCapabilitiesCUPS(
282 printer_info,
283 "InvalidPrinter",
284 &set_color_as_default,
285 &printer_color_space_for_color,
286 &printer_color_space_for_black,
287 &set_duplex_as_default,
288 &default_duplex_setting_value);
289 ASSERT_TRUE(res);
290 EXPECT_FALSE(set_duplex_as_default);
291 EXPECT_EQ(printing::UNKNOWN_DUPLEX_MODE, default_duplex_setting_value);
292 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_system_task_proxy.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698