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