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

Side by Side Diff: chromeos/printing/printer_translator_unittest.cc

Issue 2613683004: Completely rewrite the PpdProvider/PpdCache to use the SCS backend. Along the way, clean it up a l… (Closed)
Patch Set: Address michealpg@ comments Created 3 years, 10 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
« no previous file with comments | « chromeos/printing/printer_translator.cc ('k') | chromeos/printing/printing_constants.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <utility> 5 #include <utility>
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/test/values_test_util.h" 8 #include "base/test/values_test_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chromeos/printing/printer_configuration.h" 10 #include "chromeos/printing/printer_configuration.h"
11 #include "chromeos/printing/printer_translator.h" 11 #include "chromeos/printing/printer_translator.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace chromeos { 14 namespace chromeos {
15 namespace printing { 15 namespace printing {
16 16
17 // Printer test data 17 // Printer test data
18 const char kGUID[] = "GUID-GUID-GUID"; 18 const char kGUID[] = "GUID-GUID-GUID";
19 const char kName[] = "Chrome Super Printer"; 19 const char kName[] = "Chrome Super Printer";
20 const char kDescription[] = "first star on the left"; 20 const char kDescription[] = "first star on the left";
21 const char kMake[] = "Chrome"; 21 const char kMake[] = "Chrome";
22 const char kModel[] = "Inktastic Laser Magic"; 22 const char kModel[] = "Inktastic Laser Magic";
23 const char kUri[] = "ipp://printy.domain.co:555/ipp/print"; 23 const char kUri[] = "ipp://printy.domain.co:555/ipp/print";
24 const char kUUID[] = "UUID-UUID-UUID"; 24 const char kUUID[] = "UUID-UUID-UUID";
25 25
26 // PpdReference test data 26 // PpdReference test data
27 const char kUserSuppliedPpdUrl[] = "/some/path/to/user.url"; 27 const char kUserSuppliedPpdUrl[] = "/some/path/to/user.url";
28 const char kEffectiveManufacturer[] = "Ehch Pea"; 28 const char kEffectiveMakeAndModel[] = "PrintBlaster 2000";
29 const char kEffectiveModel[] = "PrintBlaster 2000";
30 29
31 TEST(PrinterTranslatorTest, PrefToPrinterMissingId) { 30 TEST(PrinterTranslatorTest, PrefToPrinterMissingId) {
32 base::DictionaryValue value; 31 base::DictionaryValue value;
33 std::unique_ptr<Printer> printer = PrefToPrinter(value); 32 std::unique_ptr<Printer> printer = PrefToPrinter(value);
34 33
35 EXPECT_FALSE(printer); 34 EXPECT_FALSE(printer);
36 } 35 }
37 36
38 TEST(PrinterTranslatorTest, PrefToPrinter) { 37 TEST(PrinterTranslatorTest, PrefToPrinter) {
39 base::DictionaryValue preference; 38 base::DictionaryValue preference;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 base::ExpectDictStringValue(kMake, *pref, "manufacturer"); 73 base::ExpectDictStringValue(kMake, *pref, "manufacturer");
75 base::ExpectDictStringValue(kModel, *pref, "model"); 74 base::ExpectDictStringValue(kModel, *pref, "model");
76 base::ExpectDictStringValue(kUri, *pref, "uri"); 75 base::ExpectDictStringValue(kUri, *pref, "uri");
77 base::ExpectDictStringValue(kUUID, *pref, "uuid"); 76 base::ExpectDictStringValue(kUUID, *pref, "uuid");
78 } 77 }
79 78
80 TEST(PrinterTranslatorTest, PrinterToPrefPpdReference) { 79 TEST(PrinterTranslatorTest, PrinterToPrefPpdReference) {
81 Printer printer("UNIQUE_ID"); 80 Printer printer("UNIQUE_ID");
82 auto* ppd = printer.mutable_ppd_reference(); 81 auto* ppd = printer.mutable_ppd_reference();
83 ppd->user_supplied_ppd_url = kUserSuppliedPpdUrl; 82 ppd->user_supplied_ppd_url = kUserSuppliedPpdUrl;
84 ppd->effective_manufacturer = kEffectiveManufacturer; 83 ppd->effective_make_and_model = kEffectiveMakeAndModel;
85 ppd->effective_model = kEffectiveModel;
86 84
87 std::unique_ptr<base::DictionaryValue> actual = PrinterToPref(printer); 85 std::unique_ptr<base::DictionaryValue> actual = PrinterToPref(printer);
88 86
89 base::ExpectDictStringValue(kUserSuppliedPpdUrl, *actual, 87 base::ExpectDictStringValue(kUserSuppliedPpdUrl, *actual,
90 "ppd_reference.user_supplied_ppd_url"); 88 "ppd_reference.user_supplied_ppd_url");
91 base::ExpectDictStringValue(kEffectiveManufacturer, *actual, 89 base::ExpectDictStringValue(kEffectiveMakeAndModel, *actual,
92 "ppd_reference.effective_manufacturer");
93 base::ExpectDictStringValue(kEffectiveModel, *actual,
94 "ppd_reference.effective_model"); 90 "ppd_reference.effective_model");
95 } 91 }
96 92
97 // Make sure we don't serialize empty fields. 93 // Make sure we don't serialize empty fields.
98 TEST(PrinterTranslatorTest, PrinterToPrefPpdReferenceLazy) { 94 TEST(PrinterTranslatorTest, PrinterToPrefPpdReferenceLazy) {
99 Printer printer("UNIQUE_ID"); 95 Printer printer("UNIQUE_ID");
100 std::unique_ptr<base::DictionaryValue> actual = PrinterToPref(printer); 96 std::unique_ptr<base::DictionaryValue> actual = PrinterToPref(printer);
101 97
102 EXPECT_FALSE(actual->HasKey("ppd_reference.user_supplied_ppd_url")); 98 EXPECT_FALSE(actual->HasKey("ppd_reference.user_supplied_ppd_url"));
103 EXPECT_FALSE(actual->HasKey("ppd_reference.effective_manufacturer")); 99 EXPECT_FALSE(actual->HasKey("ppd_reference.ppd_server_key"));
104 EXPECT_FALSE(actual->HasKey("ppd_reference.effective_model"));
105 } 100 }
106 101
107 TEST(PrinterTranslatorTest, PrefToPrinterRoundTrip) { 102 TEST(PrinterTranslatorTest, PrefToPrinterRoundTrip) {
108 base::DictionaryValue preference; 103 base::DictionaryValue preference;
109 preference.SetString("id", kGUID); 104 preference.SetString("id", kGUID);
110 preference.SetString("display_name", kName); 105 preference.SetString("display_name", kName);
111 preference.SetString("description", kDescription); 106 preference.SetString("description", kDescription);
112 preference.SetString("manufacturer", kMake); 107 preference.SetString("manufacturer", kMake);
113 preference.SetString("model", kModel); 108 preference.SetString("model", kModel);
114 preference.SetString("uri", kUri); 109 preference.SetString("uri", kUri);
115 preference.SetString("uuid", kUUID); 110 preference.SetString("uuid", kUUID);
116 111
117 preference.SetString("ppd_reference.user_supplied_ppd_url", 112 preference.SetString("ppd_reference.user_supplied_ppd_url",
118 kUserSuppliedPpdUrl); 113 kUserSuppliedPpdUrl);
119 preference.SetString("ppd_reference.effective_manufacturer", 114 preference.SetString("ppd_reference.effective_model", kEffectiveMakeAndModel);
120 kEffectiveManufacturer);
121 preference.SetString("ppd_reference.effective_model", kEffectiveModel);
122 115
123 std::unique_ptr<Printer> printer = PrefToPrinter(preference); 116 std::unique_ptr<Printer> printer = PrefToPrinter(preference);
124 std::unique_ptr<base::DictionaryValue> pref_copy = PrinterToPref(*printer); 117 std::unique_ptr<base::DictionaryValue> pref_copy = PrinterToPref(*printer);
125 118
126 EXPECT_TRUE(preference.Equals(pref_copy.get())); 119 EXPECT_TRUE(preference.Equals(pref_copy.get()));
127 } 120 }
128 121
129 } // namespace printing 122 } // namespace printing
130 } // namespace chromeos 123 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/printing/printer_translator.cc ('k') | chromeos/printing/printing_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698