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 kUserSuppliedPPD[] = "file://foo/bar/baz/eeaaaffccdd00"; | |
25 const char effective_make_and_model[] = "Manufacturer Model T1000"; | 26 const char effective_make_and_model[] = "Manufacturer Model T1000"; |
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); |
(...skipping 14 matching lines...) Expand all Loading... | |
49 EXPECT_EQ(display_name, result->display_name()); | 50 EXPECT_EQ(display_name, result->display_name()); |
50 EXPECT_EQ(description, result->description()); | 51 EXPECT_EQ(description, result->description()); |
51 EXPECT_EQ(manufacturer, result->manufacturer()); | 52 EXPECT_EQ(manufacturer, result->manufacturer()); |
52 EXPECT_EQ(model, result->model()); | 53 EXPECT_EQ(model, result->model()); |
53 EXPECT_EQ(uri, result->uri()); | 54 EXPECT_EQ(uri, result->uri()); |
54 EXPECT_EQ(uuid, result->uuid()); | 55 EXPECT_EQ(uuid, result->uuid()); |
55 EXPECT_EQ(kUpdateTime, result->last_updated()); | 56 EXPECT_EQ(kUpdateTime, result->last_updated()); |
56 | 57 |
57 EXPECT_EQ(effective_make_and_model, | 58 EXPECT_EQ(effective_make_and_model, |
58 result->ppd_reference().effective_make_and_model); | 59 result->ppd_reference().effective_make_and_model); |
60 EXPECT_FALSE(result->IsIppEverywhere()); | |
59 } | 61 } |
60 | 62 |
61 TEST(SpecificsTranslationTest, PrinterToSpecifics) { | 63 TEST(SpecificsTranslationTest, PrinterToSpecifics) { |
62 Printer printer; | 64 Printer printer; |
63 printer.set_id(id); | 65 printer.set_id(id); |
64 printer.set_display_name(display_name); | 66 printer.set_display_name(display_name); |
65 printer.set_description(description); | 67 printer.set_description(description); |
66 printer.set_manufacturer(manufacturer); | 68 printer.set_manufacturer(manufacturer); |
67 printer.set_model(model); | 69 printer.set_model(model); |
68 printer.set_uri(uri); | 70 printer.set_uri(uri); |
(...skipping 21 matching lines...) Expand all Loading... | |
90 Printer printer; | 92 Printer printer; |
91 printer.set_id(id); | 93 printer.set_id(id); |
92 printer.set_display_name(display_name); | 94 printer.set_display_name(display_name); |
93 printer.set_description(description); | 95 printer.set_description(description); |
94 printer.set_manufacturer(manufacturer); | 96 printer.set_manufacturer(manufacturer); |
95 printer.set_model(model); | 97 printer.set_model(model); |
96 printer.set_uri(uri); | 98 printer.set_uri(uri); |
97 printer.set_uuid(uuid); | 99 printer.set_uuid(uuid); |
98 | 100 |
99 Printer::PpdReference ppd; | 101 Printer::PpdReference ppd; |
100 ppd.effective_make_and_model = effective_make_and_model; | 102 ppd.autoconf = true; |
101 *printer.mutable_ppd_reference() = ppd; | 103 *printer.mutable_ppd_reference() = ppd; |
102 | 104 |
103 std::unique_ptr<sync_pb::PrinterSpecifics> temp = PrinterToSpecifics(printer); | 105 std::unique_ptr<sync_pb::PrinterSpecifics> temp = PrinterToSpecifics(printer); |
104 std::unique_ptr<Printer> result = SpecificsToPrinter(*temp); | 106 std::unique_ptr<Printer> result = SpecificsToPrinter(*temp); |
105 | 107 |
106 EXPECT_EQ(id, result->id()); | 108 EXPECT_EQ(id, result->id()); |
107 EXPECT_EQ(display_name, result->display_name()); | 109 EXPECT_EQ(display_name, result->display_name()); |
108 EXPECT_EQ(description, result->description()); | 110 EXPECT_EQ(description, result->description()); |
109 EXPECT_EQ(manufacturer, result->manufacturer()); | 111 EXPECT_EQ(manufacturer, result->manufacturer()); |
110 EXPECT_EQ(model, result->model()); | 112 EXPECT_EQ(model, result->model()); |
111 EXPECT_EQ(uri, result->uri()); | 113 EXPECT_EQ(uri, result->uri()); |
112 EXPECT_EQ(uuid, result->uuid()); | 114 EXPECT_EQ(uuid, result->uuid()); |
113 | 115 |
116 EXPECT_TRUE(result->ppd_reference().effective_make_and_model.empty()); | |
117 EXPECT_TRUE(result->ppd_reference().autoconf); | |
118 } | |
119 | |
120 TEST(SpecificsTranslationTest, AutoconfUnset) { | |
121 sync_pb::PrinterSpecifics original; | |
122 original.set_id(id); | |
123 | |
124 auto printer = SpecificsToPrinter(original); | |
125 | |
126 EXPECT_FALSE(printer->IsIppEverywhere()); | |
127 } | |
128 | |
129 TEST(SpecificsTranslationTest, MergePrinterToSpecifics) { | |
130 sync_pb::PrinterSpecifics original; | |
131 original.set_id(id); | |
132 original.mutable_ppd_reference()->set_autoconf(true); | |
133 | |
134 Printer printer(id); | |
135 printer.mutable_ppd_reference()->effective_make_and_model = | |
136 effective_make_and_model; | |
137 | |
138 MergePrinterToSpecifics(printer, &original); | |
139 | |
140 EXPECT_EQ(id, original.id()); | |
114 EXPECT_EQ(effective_make_and_model, | 141 EXPECT_EQ(effective_make_and_model, |
115 result->ppd_reference().effective_make_and_model); | 142 original.ppd_reference().effective_make_and_model()); |
143 | |
144 // Verify that autoconf is cleared. | |
145 EXPECT_FALSE(original.ppd_reference().autoconf()); | |
146 } | |
147 | |
Carlson
2017/05/22 23:46:07
Comment for what this is testing for? (Also, belo
skau
2017/05/23 01:00:22
Done.
| |
148 TEST(SpecificsTranslationTest, AutoconfOverrides) { | |
149 sync_pb::PrinterSpecifics original; | |
150 original.set_id(id); | |
151 auto* ppd_reference = original.mutable_ppd_reference(); | |
152 ppd_reference->set_autoconf(true); | |
153 ppd_reference->set_user_supplied_ppd_url(kUserSuppliedPPD); | |
154 | |
155 auto printer = SpecificsToPrinter(original); | |
156 | |
157 EXPECT_TRUE(printer->ppd_reference().autoconf); | |
158 EXPECT_TRUE(printer->ppd_reference().user_supplied_ppd_url.empty()); | |
159 EXPECT_TRUE(printer->ppd_reference().effective_make_and_model.empty()); | |
160 } | |
161 | |
162 TEST(SpecificsTranslationTest, UserSuppliedOverrides) { | |
163 sync_pb::PrinterSpecifics original; | |
164 original.set_id(id); | |
165 auto* ppd_reference = original.mutable_ppd_reference(); | |
166 ppd_reference->set_user_supplied_ppd_url(kUserSuppliedPPD); | |
167 ppd_reference->set_effective_make_and_model(effective_make_and_model); | |
168 | |
169 auto printer = SpecificsToPrinter(original); | |
170 | |
171 EXPECT_FALSE(printer->ppd_reference().autoconf); | |
172 EXPECT_FALSE(printer->ppd_reference().user_supplied_ppd_url.empty()); | |
173 EXPECT_TRUE(printer->ppd_reference().effective_make_and_model.empty()); | |
116 } | 174 } |
117 | 175 |
118 } // namespace printing | 176 } // namespace printing |
119 } // namespace chromeos | 177 } // namespace chromeos |
OLD | NEW |