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

Side by Side Diff: chromeos/printing/printer_translator_unittest.cc

Issue 2343983004: Add PPDProvider barebones implementation and associated cache skeleton. (Closed)
Patch Set: Initial PPDProvider/PPDCache implementation. Also, add associated unittests. This doesn't plumb th… Created 4 years, 2 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 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
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");
97 } 95 }
98 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"));
105 }
106
107 // FIXME add a test that we don't set fields that are empty.
skau 2016/10/14 22:10:17 FIXME
Carlson 2016/10/14 23:05:56 apparently chromium presubmits don't pickup FIXME?
108
99 TEST(PrinterTranslatorTest, PrefToPrinterRoundTrip) { 109 TEST(PrinterTranslatorTest, PrefToPrinterRoundTrip) {
100 base::DictionaryValue preference; 110 base::DictionaryValue preference;
101 preference.SetString("id", kGUID); 111 preference.SetString("id", kGUID);
102 preference.SetString("display_name", kName); 112 preference.SetString("display_name", kName);
103 preference.SetString("description", kDescription); 113 preference.SetString("description", kDescription);
104 preference.SetString("manufacturer", kMake); 114 preference.SetString("manufacturer", kMake);
105 preference.SetString("model", kModel); 115 preference.SetString("model", kModel);
106 preference.SetString("uri", kUri); 116 preference.SetString("uri", kUri);
107 preference.SetString("uuid", kUUID); 117 preference.SetString("uuid", kUUID);
108 118
109 preference.SetInteger("ppd.id", kPPDiD); 119 preference.SetString("ppd_reference.user_supplied_ppd_url",
110 preference.SetString("ppd.file_name", kFileName); 120 kUserSuppliedPpdUrl);
111 preference.SetInteger("ppd.version_number", kVersion); 121 preference.SetString("ppd_reference.effective_manufacturer",
112 preference.SetBoolean("ppd.from_quirks_server", kQuirks); 122 kEffectiveManufacturer);
123 preference.SetString("ppd_reference.effective_model", kEffectiveModel);
113 124
114 std::unique_ptr<Printer> printer = PrefToPrinter(preference); 125 std::unique_ptr<Printer> printer = PrefToPrinter(preference);
115 std::unique_ptr<base::DictionaryValue> pref_copy = PrinterToPref(*printer); 126 std::unique_ptr<base::DictionaryValue> pref_copy = PrinterToPref(*printer);
116 127
117 EXPECT_TRUE(preference.Equals(pref_copy.get())); 128 EXPECT_TRUE(preference.Equals(pref_copy.get()));
118 } 129 }
119 130
120 } // namespace printing 131 } // namespace printing
121 } // namespace chromeos 132 } // namespace chromeos
OLDNEW
« chromeos/printing/printer_configuration.h ('K') | « chromeos/printing/printer_translator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698