| 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 <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 const char id[] = "UNIQUE_ID"; | 16 const char id[] = "UNIQUE_ID"; |
| 17 const char display_name[] = "Best Printer Ever"; | 17 const char display_name[] = "Best Printer Ever"; |
| 18 const char description[] = "The green one"; | 18 const char description[] = "The green one"; |
| 19 const char manufacturer[] = "Manufacturer"; | 19 const char manufacturer[] = "Manufacturer"; |
| 20 const char model[] = "MODEL"; | 20 const char model[] = "MODEL"; |
| 21 const char uri[] = "ipps://notaprinter.chromium.org/ipp/print"; | 21 const char uri[] = "ipps://notaprinter.chromium.org/ipp/print"; |
| 22 const char uuid[] = "UUIDUUIDUUID"; | 22 const char uuid[] = "UUIDUUIDUUID"; |
| 23 const base::Time kUpdateTime = base::Time::FromInternalValue(22114455660000); | 23 const base::Time kUpdateTime = base::Time::FromInternalValue(22114455660000); |
| 24 | 24 |
| 25 const char effective_make_and_model[] = "Manufacturer Model T1000"; | 25 const char effective_make_and_model[] = "Manufacturer Model T1000"; |
| 26 const bool kAutoconf = true; |
| 26 | 27 |
| 27 } // namespace | 28 } // namespace |
| 28 | 29 |
| 29 namespace chromeos { | 30 namespace chromeos { |
| 30 namespace printing { | 31 namespace printing { |
| 31 | 32 |
| 32 TEST(SpecificsTranslationTest, SpecificsToPrinter) { | 33 TEST(SpecificsTranslationTest, SpecificsToPrinter) { |
| 33 sync_pb::PrinterSpecifics specifics; | 34 sync_pb::PrinterSpecifics specifics; |
| 34 specifics.set_id(id); | 35 specifics.set_id(id); |
| 35 specifics.set_display_name(display_name); | 36 specifics.set_display_name(display_name); |
| 36 specifics.set_description(description); | 37 specifics.set_description(description); |
| 37 specifics.set_manufacturer(manufacturer); | 38 specifics.set_manufacturer(manufacturer); |
| 38 specifics.set_model(model); | 39 specifics.set_model(model); |
| 39 specifics.set_uri(uri); | 40 specifics.set_uri(uri); |
| 40 specifics.set_uuid(uuid); | 41 specifics.set_uuid(uuid); |
| 41 specifics.set_updated_timestamp(kUpdateTime.ToJavaTime()); | 42 specifics.set_updated_timestamp(kUpdateTime.ToJavaTime()); |
| 42 | 43 |
| 43 sync_pb::PrinterPPDReference ppd; | 44 sync_pb::PrinterPPDReference ppd; |
| 44 ppd.set_effective_make_and_model(effective_make_and_model); | 45 ppd.set_effective_make_and_model(effective_make_and_model); |
| 46 ppd.set_autoconf(kAutoconf); |
| 45 *specifics.mutable_ppd_reference() = ppd; | 47 *specifics.mutable_ppd_reference() = ppd; |
| 46 | 48 |
| 47 std::unique_ptr<Printer> result = SpecificsToPrinter(specifics); | 49 std::unique_ptr<Printer> result = SpecificsToPrinter(specifics); |
| 48 EXPECT_EQ(id, result->id()); | 50 EXPECT_EQ(id, result->id()); |
| 49 EXPECT_EQ(display_name, result->display_name()); | 51 EXPECT_EQ(display_name, result->display_name()); |
| 50 EXPECT_EQ(description, result->description()); | 52 EXPECT_EQ(description, result->description()); |
| 51 EXPECT_EQ(manufacturer, result->manufacturer()); | 53 EXPECT_EQ(manufacturer, result->manufacturer()); |
| 52 EXPECT_EQ(model, result->model()); | 54 EXPECT_EQ(model, result->model()); |
| 53 EXPECT_EQ(uri, result->uri()); | 55 EXPECT_EQ(uri, result->uri()); |
| 54 EXPECT_EQ(uuid, result->uuid()); | 56 EXPECT_EQ(uuid, result->uuid()); |
| 55 EXPECT_EQ(kUpdateTime, result->last_updated()); | 57 EXPECT_EQ(kUpdateTime, result->last_updated()); |
| 56 | 58 |
| 57 EXPECT_EQ(effective_make_and_model, | 59 EXPECT_EQ(effective_make_and_model, |
| 58 result->ppd_reference().effective_make_and_model); | 60 result->ppd_reference().effective_make_and_model); |
| 61 EXPECT_EQ(kAutoconf, result->ppd_reference().autoconf); |
| 59 } | 62 } |
| 60 | 63 |
| 61 TEST(SpecificsTranslationTest, PrinterToSpecifics) { | 64 TEST(SpecificsTranslationTest, PrinterToSpecifics) { |
| 62 Printer printer; | 65 Printer printer; |
| 63 printer.set_id(id); | 66 printer.set_id(id); |
| 64 printer.set_display_name(display_name); | 67 printer.set_display_name(display_name); |
| 65 printer.set_description(description); | 68 printer.set_description(description); |
| 66 printer.set_manufacturer(manufacturer); | 69 printer.set_manufacturer(manufacturer); |
| 67 printer.set_model(model); | 70 printer.set_model(model); |
| 68 printer.set_uri(uri); | 71 printer.set_uri(uri); |
| 69 printer.set_uuid(uuid); | 72 printer.set_uuid(uuid); |
| 70 | 73 |
| 71 Printer::PpdReference ppd; | 74 Printer::PpdReference ppd; |
| 72 ppd.effective_make_and_model = effective_make_and_model; | 75 ppd.effective_make_and_model = effective_make_and_model; |
| 76 ppd.autoconf = kAutoconf; |
| 73 *printer.mutable_ppd_reference() = ppd; | 77 *printer.mutable_ppd_reference() = ppd; |
| 74 | 78 |
| 75 std::unique_ptr<sync_pb::PrinterSpecifics> result = | 79 std::unique_ptr<sync_pb::PrinterSpecifics> result = |
| 76 PrinterToSpecifics(printer); | 80 PrinterToSpecifics(printer); |
| 77 EXPECT_EQ(id, result->id()); | 81 EXPECT_EQ(id, result->id()); |
| 78 EXPECT_EQ(display_name, result->display_name()); | 82 EXPECT_EQ(display_name, result->display_name()); |
| 79 EXPECT_EQ(description, result->description()); | 83 EXPECT_EQ(description, result->description()); |
| 80 EXPECT_EQ(manufacturer, result->manufacturer()); | 84 EXPECT_EQ(manufacturer, result->manufacturer()); |
| 81 EXPECT_EQ(model, result->model()); | 85 EXPECT_EQ(model, result->model()); |
| 82 EXPECT_EQ(uri, result->uri()); | 86 EXPECT_EQ(uri, result->uri()); |
| 83 EXPECT_EQ(uuid, result->uuid()); | 87 EXPECT_EQ(uuid, result->uuid()); |
| 84 | 88 |
| 85 EXPECT_EQ(effective_make_and_model, | 89 EXPECT_EQ(effective_make_and_model, |
| 86 result->ppd_reference().effective_make_and_model()); | 90 result->ppd_reference().effective_make_and_model()); |
| 91 EXPECT_EQ(kAutoconf, result->ppd_reference().autoconf()); |
| 87 } | 92 } |
| 88 | 93 |
| 89 TEST(SpecificsTranslationTest, SpecificsToPrinterRoundTrip) { | 94 TEST(SpecificsTranslationTest, SpecificsToPrinterRoundTrip) { |
| 90 Printer printer; | 95 Printer printer; |
| 91 printer.set_id(id); | 96 printer.set_id(id); |
| 92 printer.set_display_name(display_name); | 97 printer.set_display_name(display_name); |
| 93 printer.set_description(description); | 98 printer.set_description(description); |
| 94 printer.set_manufacturer(manufacturer); | 99 printer.set_manufacturer(manufacturer); |
| 95 printer.set_model(model); | 100 printer.set_model(model); |
| 96 printer.set_uri(uri); | 101 printer.set_uri(uri); |
| 97 printer.set_uuid(uuid); | 102 printer.set_uuid(uuid); |
| 98 | 103 |
| 99 Printer::PpdReference ppd; | 104 Printer::PpdReference ppd; |
| 100 ppd.effective_make_and_model = effective_make_and_model; | 105 ppd.effective_make_and_model = effective_make_and_model; |
| 106 ppd.autoconf = kAutoconf; |
| 101 *printer.mutable_ppd_reference() = ppd; | 107 *printer.mutable_ppd_reference() = ppd; |
| 102 | 108 |
| 103 std::unique_ptr<sync_pb::PrinterSpecifics> temp = PrinterToSpecifics(printer); | 109 std::unique_ptr<sync_pb::PrinterSpecifics> temp = PrinterToSpecifics(printer); |
| 104 std::unique_ptr<Printer> result = SpecificsToPrinter(*temp); | 110 std::unique_ptr<Printer> result = SpecificsToPrinter(*temp); |
| 105 | 111 |
| 106 EXPECT_EQ(id, result->id()); | 112 EXPECT_EQ(id, result->id()); |
| 107 EXPECT_EQ(display_name, result->display_name()); | 113 EXPECT_EQ(display_name, result->display_name()); |
| 108 EXPECT_EQ(description, result->description()); | 114 EXPECT_EQ(description, result->description()); |
| 109 EXPECT_EQ(manufacturer, result->manufacturer()); | 115 EXPECT_EQ(manufacturer, result->manufacturer()); |
| 110 EXPECT_EQ(model, result->model()); | 116 EXPECT_EQ(model, result->model()); |
| 111 EXPECT_EQ(uri, result->uri()); | 117 EXPECT_EQ(uri, result->uri()); |
| 112 EXPECT_EQ(uuid, result->uuid()); | 118 EXPECT_EQ(uuid, result->uuid()); |
| 113 | 119 |
| 114 EXPECT_EQ(effective_make_and_model, | 120 EXPECT_EQ(effective_make_and_model, |
| 115 result->ppd_reference().effective_make_and_model); | 121 result->ppd_reference().effective_make_and_model); |
| 122 EXPECT_EQ(kAutoconf, result->ppd_reference().autoconf); |
| 116 } | 123 } |
| 117 | 124 |
| 118 } // namespace printing | 125 } // namespace printing |
| 119 } // namespace chromeos | 126 } // namespace chromeos |
| OLD | NEW |