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

Side by Side Diff: chrome/browser/chromeos/printing/specifics_translation_unittest.cc

Issue 2956173002: Introduce the field make_and_model for synced printers. (Closed)
Patch Set: address comments. Add test Created 3 years, 5 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/time/time.h" 8 #include "base/time/time.h"
9 #include "chrome/browser/chromeos/printing/specifics_translation.h" 9 #include "chrome/browser/chromeos/printing/specifics_translation.h"
10 #include "chromeos/printing/printer_configuration.h" 10 #include "chromeos/printing/printer_configuration.h"
11 #include "components/sync/protocol/printer_specifics.pb.h" 11 #include "components/sync/protocol/printer_specifics.pb.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace { 14 namespace {
15 15
16 constexpr char kId[] = "UNIQUE_ID"; 16 constexpr char kId[] = "UNIQUE_ID";
17 constexpr char kDisplayName[] = "Best Printer Ever"; 17 constexpr char kDisplayName[] = "Best Printer Ever";
18 constexpr char kDescription[] = "The green one"; 18 constexpr char kDescription[] = "The green one";
19 constexpr char kManufacturer[] = "Manufacturer"; 19 constexpr char kManufacturer[] = "Manufacturer";
20 constexpr char kModel[] = "MODEL"; 20 constexpr char kModel[] = "MODEL";
21 constexpr char kMakeAndModel[] = "Manufacturer MODEL";
21 constexpr char kUri[] = "ipps://notaprinter.chromium.org/ipp/print"; 22 constexpr char kUri[] = "ipps://notaprinter.chromium.org/ipp/print";
22 constexpr char kUuid[] = "UUIDUUIDUUID"; 23 constexpr char kUuid[] = "UUIDUUIDUUID";
23 const base::Time kUpdateTime = base::Time::FromInternalValue(22114455660000); 24 const base::Time kUpdateTime = base::Time::FromInternalValue(22114455660000);
24 25
25 constexpr char kUserSuppliedPPD[] = "file://foo/bar/baz/eeaaaffccdd00"; 26 constexpr char kUserSuppliedPPD[] = "file://foo/bar/baz/eeaaaffccdd00";
26 constexpr char kEffectiveMakeAndModel[] = "Manufacturer Model T1000"; 27 constexpr char kEffectiveMakeAndModel[] = "Manufacturer Model T1000";
27 28
28 } // namespace 29 } // namespace
29 30
30 namespace chromeos { 31 namespace chromeos {
31 namespace printing { 32 namespace printing {
32 33
33 TEST(SpecificsTranslationTest, SpecificsToPrinter) { 34 TEST(SpecificsTranslationTest, SpecificsToPrinter) {
34 sync_pb::PrinterSpecifics specifics; 35 sync_pb::PrinterSpecifics specifics;
35 specifics.set_id(kId); 36 specifics.set_id(kId);
36 specifics.set_display_name(kDisplayName); 37 specifics.set_display_name(kDisplayName);
37 specifics.set_description(kDescription); 38 specifics.set_description(kDescription);
38 specifics.set_manufacturer(kManufacturer); 39 specifics.set_make_and_model(kMakeAndModel);
39 specifics.set_model(kModel);
40 specifics.set_uri(kUri); 40 specifics.set_uri(kUri);
41 specifics.set_uuid(kUuid); 41 specifics.set_uuid(kUuid);
42 specifics.set_updated_timestamp(kUpdateTime.ToJavaTime()); 42 specifics.set_updated_timestamp(kUpdateTime.ToJavaTime());
43 43
44 sync_pb::PrinterPPDReference ppd; 44 sync_pb::PrinterPPDReference ppd;
45 ppd.set_effective_make_and_model(kEffectiveMakeAndModel); 45 ppd.set_effective_make_and_model(kEffectiveMakeAndModel);
46 *specifics.mutable_ppd_reference() = ppd; 46 *specifics.mutable_ppd_reference() = ppd;
47 47
48 std::unique_ptr<Printer> result = SpecificsToPrinter(specifics); 48 std::unique_ptr<Printer> result = SpecificsToPrinter(specifics);
49 EXPECT_EQ(kId, result->id()); 49 EXPECT_EQ(kId, result->id());
50 EXPECT_EQ(kDisplayName, result->display_name()); 50 EXPECT_EQ(kDisplayName, result->display_name());
51 EXPECT_EQ(kDescription, result->description()); 51 EXPECT_EQ(kDescription, result->description());
52 EXPECT_EQ(kManufacturer, result->manufacturer()); 52 EXPECT_EQ(kMakeAndModel, result->make_and_model());
53 EXPECT_EQ(kModel, result->model());
54 EXPECT_EQ(kUri, result->uri()); 53 EXPECT_EQ(kUri, result->uri());
55 EXPECT_EQ(kUuid, result->uuid()); 54 EXPECT_EQ(kUuid, result->uuid());
56 EXPECT_EQ(kUpdateTime, result->last_updated()); 55 EXPECT_EQ(kUpdateTime, result->last_updated());
57 56
58 EXPECT_EQ(kEffectiveMakeAndModel, 57 EXPECT_EQ(kEffectiveMakeAndModel,
59 result->ppd_reference().effective_make_and_model); 58 result->ppd_reference().effective_make_and_model);
60 EXPECT_FALSE(result->IsIppEverywhere()); 59 EXPECT_FALSE(result->IsIppEverywhere());
61 } 60 }
62 61
63 TEST(SpecificsTranslationTest, PrinterToSpecifics) { 62 TEST(SpecificsTranslationTest, PrinterToSpecifics) {
64 Printer printer; 63 Printer printer;
65 printer.set_id(kId); 64 printer.set_id(kId);
66 printer.set_display_name(kDisplayName); 65 printer.set_display_name(kDisplayName);
67 printer.set_description(kDescription); 66 printer.set_description(kDescription);
68 printer.set_manufacturer(kManufacturer); 67 printer.set_make_and_model(kMakeAndModel);
69 printer.set_model(kModel);
70 printer.set_uri(kUri); 68 printer.set_uri(kUri);
71 printer.set_uuid(kUuid); 69 printer.set_uuid(kUuid);
72 70
73 Printer::PpdReference ppd; 71 Printer::PpdReference ppd;
74 ppd.effective_make_and_model = kEffectiveMakeAndModel; 72 ppd.effective_make_and_model = kEffectiveMakeAndModel;
75 *printer.mutable_ppd_reference() = ppd; 73 *printer.mutable_ppd_reference() = ppd;
76 74
77 std::unique_ptr<sync_pb::PrinterSpecifics> result = 75 std::unique_ptr<sync_pb::PrinterSpecifics> result =
78 PrinterToSpecifics(printer); 76 PrinterToSpecifics(printer);
79 EXPECT_EQ(kId, result->id()); 77 EXPECT_EQ(kId, result->id());
80 EXPECT_EQ(kDisplayName, result->display_name()); 78 EXPECT_EQ(kDisplayName, result->display_name());
81 EXPECT_EQ(kDescription, result->description()); 79 EXPECT_EQ(kDescription, result->description());
82 EXPECT_EQ(kManufacturer, result->manufacturer()); 80 EXPECT_EQ(kMakeAndModel, result->make_and_model());
83 EXPECT_EQ(kModel, result->model());
84 EXPECT_EQ(kUri, result->uri()); 81 EXPECT_EQ(kUri, result->uri());
85 EXPECT_EQ(kUuid, result->uuid()); 82 EXPECT_EQ(kUuid, result->uuid());
86 83
87 EXPECT_EQ(kEffectiveMakeAndModel, 84 EXPECT_EQ(kEffectiveMakeAndModel,
88 result->ppd_reference().effective_make_and_model()); 85 result->ppd_reference().effective_make_and_model());
89 } 86 }
90 87
91 TEST(SpecificsTranslationTest, SpecificsToPrinterRoundTrip) { 88 TEST(SpecificsTranslationTest, SpecificsToPrinterRoundTrip) {
92 Printer printer; 89 Printer printer;
93 printer.set_id(kId); 90 printer.set_id(kId);
94 printer.set_display_name(kDisplayName); 91 printer.set_display_name(kDisplayName);
95 printer.set_description(kDescription); 92 printer.set_description(kDescription);
96 printer.set_manufacturer(kManufacturer); 93 printer.set_manufacturer(kManufacturer);
97 printer.set_model(kModel); 94 printer.set_model(kModel);
95 printer.set_make_and_model(kMakeAndModel);
98 printer.set_uri(kUri); 96 printer.set_uri(kUri);
99 printer.set_uuid(kUuid); 97 printer.set_uuid(kUuid);
100 98
101 Printer::PpdReference ppd; 99 Printer::PpdReference ppd;
102 ppd.autoconf = true; 100 ppd.autoconf = true;
103 *printer.mutable_ppd_reference() = ppd; 101 *printer.mutable_ppd_reference() = ppd;
104 102
105 std::unique_ptr<sync_pb::PrinterSpecifics> temp = PrinterToSpecifics(printer); 103 std::unique_ptr<sync_pb::PrinterSpecifics> temp = PrinterToSpecifics(printer);
106 std::unique_ptr<Printer> result = SpecificsToPrinter(*temp); 104 std::unique_ptr<Printer> result = SpecificsToPrinter(*temp);
107 105
108 EXPECT_EQ(kId, result->id()); 106 EXPECT_EQ(kId, result->id());
109 EXPECT_EQ(kDisplayName, result->display_name()); 107 EXPECT_EQ(kDisplayName, result->display_name());
110 EXPECT_EQ(kDescription, result->description()); 108 EXPECT_EQ(kDescription, result->description());
111 EXPECT_EQ(kManufacturer, result->manufacturer()); 109 EXPECT_EQ(kManufacturer, result->manufacturer());
112 EXPECT_EQ(kModel, result->model()); 110 EXPECT_EQ(kModel, result->model());
111 EXPECT_EQ(kMakeAndModel, result->make_and_model());
113 EXPECT_EQ(kUri, result->uri()); 112 EXPECT_EQ(kUri, result->uri());
114 EXPECT_EQ(kUuid, result->uuid()); 113 EXPECT_EQ(kUuid, result->uuid());
115 114
116 EXPECT_TRUE(result->ppd_reference().effective_make_and_model.empty()); 115 EXPECT_TRUE(result->ppd_reference().effective_make_and_model.empty());
117 EXPECT_TRUE(result->ppd_reference().autoconf); 116 EXPECT_TRUE(result->ppd_reference().autoconf);
118 } 117 }
119 118
120 TEST(SpecificsTranslationTest, MergePrinterToSpecifics) { 119 TEST(SpecificsTranslationTest, MergePrinterToSpecifics) {
121 sync_pb::PrinterSpecifics original; 120 sync_pb::PrinterSpecifics original;
122 original.set_id(kId); 121 original.set_id(kId);
123 original.mutable_ppd_reference()->set_autoconf(true); 122 original.mutable_ppd_reference()->set_autoconf(true);
123 original.set_manufacturer(kManufacturer);
124 original.set_model(kModel);
125 // make_and_model not set
124 126
125 Printer printer(kId); 127 Printer printer(kId);
126 printer.mutable_ppd_reference()->effective_make_and_model = 128 printer.mutable_ppd_reference()->effective_make_and_model =
127 kEffectiveMakeAndModel; 129 kEffectiveMakeAndModel;
130 printer.set_make_and_model(kMakeAndModel);
131 // manufacturer not set
132 // model not set
128 133
129 MergePrinterToSpecifics(printer, &original); 134 MergePrinterToSpecifics(printer, &original);
130 135
131 EXPECT_EQ(kId, original.id()); 136 EXPECT_EQ(kId, original.id());
132 EXPECT_EQ(kEffectiveMakeAndModel, 137 EXPECT_EQ(kEffectiveMakeAndModel,
133 original.ppd_reference().effective_make_and_model()); 138 original.ppd_reference().effective_make_and_model());
134 139
135 // Verify that autoconf is cleared. 140 // Verify that autoconf is cleared.
136 EXPECT_FALSE(original.ppd_reference().autoconf()); 141 EXPECT_FALSE(original.ppd_reference().autoconf());
142
143 // Verify that both make_and_model and the old fields are retained.
144 EXPECT_EQ(kMakeAndModel, original.make_and_model());
145 EXPECT_EQ(kManufacturer, original.manufacturer());
146 EXPECT_EQ(kModel, original.model());
137 } 147 }
138 148
139 // Tests that the autoconf value overrides other PpdReference fields. 149 // Tests that the autoconf value overrides other PpdReference fields.
140 TEST(SpecificsTranslationTest, AutoconfOverrides) { 150 TEST(SpecificsTranslationTest, AutoconfOverrides) {
141 sync_pb::PrinterSpecifics original; 151 sync_pb::PrinterSpecifics original;
142 original.set_id(kId); 152 original.set_id(kId);
143 auto* ppd_reference = original.mutable_ppd_reference(); 153 auto* ppd_reference = original.mutable_ppd_reference();
144 ppd_reference->set_autoconf(true); 154 ppd_reference->set_autoconf(true);
145 ppd_reference->set_user_supplied_ppd_url(kUserSuppliedPPD); 155 ppd_reference->set_user_supplied_ppd_url(kUserSuppliedPPD);
146 156
(...skipping 13 matching lines...) Expand all
160 ppd_reference->set_user_supplied_ppd_url(kUserSuppliedPPD); 170 ppd_reference->set_user_supplied_ppd_url(kUserSuppliedPPD);
161 ppd_reference->set_effective_make_and_model(kEffectiveMakeAndModel); 171 ppd_reference->set_effective_make_and_model(kEffectiveMakeAndModel);
162 172
163 auto printer = SpecificsToPrinter(original); 173 auto printer = SpecificsToPrinter(original);
164 174
165 EXPECT_FALSE(printer->ppd_reference().autoconf); 175 EXPECT_FALSE(printer->ppd_reference().autoconf);
166 EXPECT_FALSE(printer->ppd_reference().user_supplied_ppd_url.empty()); 176 EXPECT_FALSE(printer->ppd_reference().user_supplied_ppd_url.empty());
167 EXPECT_TRUE(printer->ppd_reference().effective_make_and_model.empty()); 177 EXPECT_TRUE(printer->ppd_reference().effective_make_and_model.empty());
168 } 178 }
169 179
180 TEST(SpecificsTranslationTest, OldProtoExpectedValues) {
181 sync_pb::PrinterSpecifics original;
182 original.set_id(kId);
183 original.set_manufacturer(kManufacturer);
184 original.set_model(kModel);
185
186 auto printer = SpecificsToPrinter(original);
187
188 // make_and_model should be computed
189 EXPECT_EQ(kMakeAndModel, printer->make_and_model());
190
191 // Ensure that manufacturer and model are still populated
192 EXPECT_EQ(kManufacturer, printer->manufacturer());
193 EXPECT_EQ(kModel, printer->model());
194 }
195
196 TEST(SpecificsTranslationTest, OldProtoDuplicateManufacturer) {
197 const std::string make = "IO";
198 const std::string model = "IO Radar 2000";
199
200 sync_pb::PrinterSpecifics original;
201 original.set_id(kId);
202 original.set_manufacturer(make);
203 original.set_model(model);
204
205 auto printer = SpecificsToPrinter(original);
206
207 EXPECT_EQ("IO Radar 2000", printer->make_and_model());
208 }
209
210 TEST(SpecificsTranslationTest, MakeAndModelPreferred) {
211 const std::string make = "UN";
212 const std::string model = "EXPECTED";
213
214 sync_pb::PrinterSpecifics original;
215 original.set_id(kId);
216 original.set_manufacturer(make);
217 original.set_model(model);
218 original.set_make_and_model(kMakeAndModel);
219
220 auto printer = SpecificsToPrinter(original);
221
222 EXPECT_EQ(kMakeAndModel, printer->make_and_model());
223 }
224
170 } // namespace printing 225 } // namespace printing
171 } // namespace chromeos 226 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698