Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/chromeos/printing/specifics_translation_unittest.cc

Issue 2884863002: Add an autoconf field to printer objects. (Closed)
Patch Set: more comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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, MergePrinterToSpecifics) {
121 sync_pb::PrinterSpecifics original;
122 original.set_id(id);
123 original.mutable_ppd_reference()->set_autoconf(true);
124
125 Printer printer(id);
126 printer.mutable_ppd_reference()->effective_make_and_model =
127 effective_make_and_model;
128
129 MergePrinterToSpecifics(printer, &original);
130
131 EXPECT_EQ(id, original.id());
114 EXPECT_EQ(effective_make_and_model, 132 EXPECT_EQ(effective_make_and_model,
115 result->ppd_reference().effective_make_and_model); 133 original.ppd_reference().effective_make_and_model());
134
135 // Verify that autoconf is cleared.
136 EXPECT_FALSE(original.ppd_reference().autoconf());
137 }
138
139 // Tests that the autoconf value overwrites other PpdReference fields.
Carlson 2017/05/23 17:03:00 overrides is probably a little better word.
skau 2017/05/23 17:50:46 Done.
140 TEST(SpecificsTranslationTest, AutoconfOverrides) {
141 sync_pb::PrinterSpecifics original;
142 original.set_id(id);
143 auto* ppd_reference = original.mutable_ppd_reference();
144 ppd_reference->set_autoconf(true);
145 ppd_reference->set_user_supplied_ppd_url(kUserSuppliedPPD);
146
147 auto printer = SpecificsToPrinter(original);
148
149 EXPECT_TRUE(printer->ppd_reference().autoconf);
150 EXPECT_TRUE(printer->ppd_reference().user_supplied_ppd_url.empty());
151 EXPECT_TRUE(printer->ppd_reference().effective_make_and_model.empty());
152 }
153
154 // Tests that user_supplied_ppd_url overwrites other PpdReference fields if
155 // autoconf is false.
156 TEST(SpecificsTranslationTest, UserSuppliedOverrides) {
157 sync_pb::PrinterSpecifics original;
158 original.set_id(id);
159 auto* ppd_reference = original.mutable_ppd_reference();
160 ppd_reference->set_user_supplied_ppd_url(kUserSuppliedPPD);
161 ppd_reference->set_effective_make_and_model(effective_make_and_model);
162
163 auto printer = SpecificsToPrinter(original);
164
165 EXPECT_FALSE(printer->ppd_reference().autoconf);
166 EXPECT_FALSE(printer->ppd_reference().user_supplied_ppd_url.empty());
167 EXPECT_TRUE(printer->ppd_reference().effective_make_and_model.empty());
116 } 168 }
117 169
118 } // namespace printing 170 } // namespace printing
119 } // namespace chromeos 171 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/printing/specifics_translation.cc ('k') | chromeos/printing/printer_configuration.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698