| OLD | NEW |
| 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 Loading... |
| 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"); | 90 "ppd_reference.effective_make_and_model"); |
| 93 base::ExpectDictStringValue(kEffectiveModel, *actual, | |
| 94 "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_kery")); |
| 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_make_and_model", |
| 120 kEffectiveManufacturer); | 115 kEffectiveMakeAndModel); |
| 121 preference.SetString("ppd_reference.effective_model", kEffectiveModel); | |
| 122 | 116 |
| 123 std::unique_ptr<Printer> printer = PrefToPrinter(preference); | 117 std::unique_ptr<Printer> printer = PrefToPrinter(preference); |
| 124 std::unique_ptr<base::DictionaryValue> pref_copy = PrinterToPref(*printer); | 118 std::unique_ptr<base::DictionaryValue> pref_copy = PrinterToPref(*printer); |
| 125 | 119 |
| 126 EXPECT_TRUE(preference.Equals(pref_copy.get())); | 120 EXPECT_TRUE(preference.Equals(pref_copy.get())); |
| 127 } | 121 } |
| 128 | 122 |
| 129 } // namespace printing | 123 } // namespace printing |
| 130 } // namespace chromeos | 124 } // namespace chromeos |
| OLD | NEW |