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 // PPDFile test data | 26 // PpdReference test data |
27 const int kPPDiD = 13334; | 27 const char kUserSuppliedPpdUrl[] = "/some/path/to/user.url"; |
28 const char kFileName[] = "path/to/ppd/file.ppd"; | 28 const char kEffectiveManufacturer[] = "Ehch Pea"; |
29 const int kVersion = 47773; | 29 const char kEffectiveModel[] = "PrintBlaster 2000"; |
30 const bool kQuirks = false; | |
31 | 30 |
32 TEST(PrinterTranslatorTest, PrefToPrinterMissingId) { | 31 TEST(PrinterTranslatorTest, PrefToPrinterMissingId) { |
33 base::DictionaryValue value; | 32 base::DictionaryValue value; |
34 std::unique_ptr<Printer> printer = PrefToPrinter(value); | 33 std::unique_ptr<Printer> printer = PrefToPrinter(value); |
35 | 34 |
36 EXPECT_FALSE(printer); | 35 EXPECT_FALSE(printer); |
37 } | 36 } |
38 | 37 |
39 TEST(PrinterTranslatorTest, PrefToPrinter) { | 38 TEST(PrinterTranslatorTest, PrefToPrinter) { |
40 base::DictionaryValue preference; | 39 base::DictionaryValue preference; |
(...skipping 30 matching lines...) Expand all Loading... |
71 | 70 |
72 base::ExpectDictStringValue("GLOBALLY_UNIQUE_ID", *pref, "id"); | 71 base::ExpectDictStringValue("GLOBALLY_UNIQUE_ID", *pref, "id"); |
73 base::ExpectDictStringValue(kName, *pref, "display_name"); | 72 base::ExpectDictStringValue(kName, *pref, "display_name"); |
74 base::ExpectDictStringValue(kDescription, *pref, "description"); | 73 base::ExpectDictStringValue(kDescription, *pref, "description"); |
75 base::ExpectDictStringValue(kMake, *pref, "manufacturer"); | 74 base::ExpectDictStringValue(kMake, *pref, "manufacturer"); |
76 base::ExpectDictStringValue(kModel, *pref, "model"); | 75 base::ExpectDictStringValue(kModel, *pref, "model"); |
77 base::ExpectDictStringValue(kUri, *pref, "uri"); | 76 base::ExpectDictStringValue(kUri, *pref, "uri"); |
78 base::ExpectDictStringValue(kUUID, *pref, "uuid"); | 77 base::ExpectDictStringValue(kUUID, *pref, "uuid"); |
79 } | 78 } |
80 | 79 |
81 TEST(PrinterTranslatorTest, PrinterToPrefPPDFile) { | 80 TEST(PrinterTranslatorTest, PrinterToPrefPpdReference) { |
82 Printer::PPDFile ppd; | |
83 ppd.id = kPPDiD; | |
84 ppd.file_name = kFileName; | |
85 ppd.version_number = kVersion; | |
86 ppd.from_quirks_server = kQuirks; | |
87 | |
88 Printer printer("UNIQUE_ID"); | 81 Printer printer("UNIQUE_ID"); |
89 printer.SetPPD(base::MakeUnique<Printer::PPDFile>(std::move(ppd))); | 82 auto* ppd = printer.mutable_ppd_reference(); |
| 83 ppd->user_supplied_ppd_url = kUserSuppliedPpdUrl; |
| 84 ppd->effective_manufacturer = kEffectiveManufacturer; |
| 85 ppd->effective_model = kEffectiveModel; |
90 | 86 |
91 std::unique_ptr<base::DictionaryValue> actual = PrinterToPref(printer); | 87 std::unique_ptr<base::DictionaryValue> actual = PrinterToPref(printer); |
92 | 88 |
93 base::ExpectDictIntegerValue(kPPDiD, *actual, "ppd.id"); | 89 base::ExpectDictStringValue(kUserSuppliedPpdUrl, *actual, |
94 base::ExpectDictStringValue(kFileName, *actual, "ppd.file_name"); | 90 "ppd_reference.user_supplied_ppd_url"); |
95 base::ExpectDictIntegerValue(kVersion, *actual, "ppd.version_number"); | 91 base::ExpectDictStringValue(kEffectiveManufacturer, *actual, |
96 base::ExpectDictBooleanValue(kQuirks, *actual, "ppd.from_quirks_server"); | 92 "ppd_reference.effective_manufacturer"); |
| 93 base::ExpectDictStringValue(kEffectiveModel, *actual, |
| 94 "ppd_reference.effective_model"); |
| 95 } |
| 96 |
| 97 // Make sure we don't serialize empty fields. |
| 98 TEST(PrinterTranslatorTest, PrinterToPrefPpdReferenceLazy) { |
| 99 Printer printer("UNIQUE_ID"); |
| 100 std::unique_ptr<base::DictionaryValue> actual = PrinterToPref(printer); |
| 101 |
| 102 EXPECT_FALSE(actual->HasKey("ppd_reference.user_supplied_ppd_url")); |
| 103 EXPECT_FALSE(actual->HasKey("ppd_reference.effective_manufacturer")); |
| 104 EXPECT_FALSE(actual->HasKey("ppd_reference.effective_model")); |
97 } | 105 } |
98 | 106 |
99 TEST(PrinterTranslatorTest, PrefToPrinterRoundTrip) { | 107 TEST(PrinterTranslatorTest, PrefToPrinterRoundTrip) { |
100 base::DictionaryValue preference; | 108 base::DictionaryValue preference; |
101 preference.SetString("id", kGUID); | 109 preference.SetString("id", kGUID); |
102 preference.SetString("display_name", kName); | 110 preference.SetString("display_name", kName); |
103 preference.SetString("description", kDescription); | 111 preference.SetString("description", kDescription); |
104 preference.SetString("manufacturer", kMake); | 112 preference.SetString("manufacturer", kMake); |
105 preference.SetString("model", kModel); | 113 preference.SetString("model", kModel); |
106 preference.SetString("uri", kUri); | 114 preference.SetString("uri", kUri); |
107 preference.SetString("uuid", kUUID); | 115 preference.SetString("uuid", kUUID); |
108 | 116 |
109 preference.SetInteger("ppd.id", kPPDiD); | 117 preference.SetString("ppd_reference.user_supplied_ppd_url", |
110 preference.SetString("ppd.file_name", kFileName); | 118 kUserSuppliedPpdUrl); |
111 preference.SetInteger("ppd.version_number", kVersion); | 119 preference.SetString("ppd_reference.effective_manufacturer", |
112 preference.SetBoolean("ppd.from_quirks_server", kQuirks); | 120 kEffectiveManufacturer); |
| 121 preference.SetString("ppd_reference.effective_model", kEffectiveModel); |
113 | 122 |
114 std::unique_ptr<Printer> printer = PrefToPrinter(preference); | 123 std::unique_ptr<Printer> printer = PrefToPrinter(preference); |
115 std::unique_ptr<base::DictionaryValue> pref_copy = PrinterToPref(*printer); | 124 std::unique_ptr<base::DictionaryValue> pref_copy = PrinterToPref(*printer); |
116 | 125 |
117 EXPECT_TRUE(preference.Equals(pref_copy.get())); | 126 EXPECT_TRUE(preference.Equals(pref_copy.get())); |
118 } | 127 } |
119 | 128 |
120 } // namespace printing | 129 } // namespace printing |
121 } // namespace chromeos | 130 } // namespace chromeos |
OLD | NEW |