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

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

Issue 2161933003: Define printer configuration objects for Chrome OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/test/values_test_util.h"
6 #include "base/values.h"
7 #include "chromeos/printing/printer_configuration.h"
8 #include "chromeos/printing/printer_translator.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace chromeos {
12 namespace printing {
13
14 // Printer test data
15 const char kGUID[] = "GUID-GUID-GUID";
16 const char kName[] = "Chrome Super Printer";
17 const char kDescription[] = "first star on the left";
18 const char kMake[] = "Chrome";
19 const char kModel[] = "Inktastic Laser Magic";
20 const char kUri[] = "ipp://printy.domain.co:555/ipp/print";
21 const char kUUID[] = "UUID-UUID-UUID";
22
23 // PPDFile test data
24 const int kPPDiD = 13334;
25 const char kFileName[] = "path/to/ppd/file.ppd";
26 const int kVersion = 47773;
27 const bool kQuirks = false;
28
29 TEST(PrinterTranslatorTest, MergePrinterPreferenceMissingId) {
30 base::DictionaryValue value;
31 Printer printer;
32
33 EXPECT_FALSE(MergePrinterPreference(value, &printer));
34 }
35
36 TEST(PrinterTranslatorTest, MergePrinterPreference) {
37 base::DictionaryValue preference;
38 preference.SetString("id", kGUID);
39 preference.SetString("display_name", kName);
40 preference.SetString("description", kDescription);
41 preference.SetString("manufacturer", kMake);
42 preference.SetString("model", kModel);
43 preference.SetString("uri", kUri);
44 preference.SetString("uuid", kUUID);
45
46 Printer printer;
47 EXPECT_TRUE(MergePrinterPreference(preference, &printer));
48
49 EXPECT_EQ(kGUID, printer.id());
50 EXPECT_EQ(kName, printer.display_name());
51 EXPECT_EQ(kDescription, printer.description());
52 EXPECT_EQ(kMake, printer.manufacturer());
53 EXPECT_EQ(kModel, printer.model());
54 EXPECT_EQ(kUri, printer.uri());
55 EXPECT_EQ(kUUID, printer.uuid());
56 }
57
58 TEST(PrinterTranslatorTest, PrinterToPref) {
59 Printer printer("GLOBALLY_UNIQUE_ID");
60 printer.set_display_name(kName);
61 printer.set_description(kDescription);
62 printer.set_manufacturer(kMake);
63 printer.set_model(kModel);
64 printer.set_uri(kUri);
65 printer.set_uuid(kUUID);
66
67 base::DictionaryValue pref;
68 PrinterToPref(printer, &pref);
69
70 base::ExpectDictStringValue("GLOBALLY_UNIQUE_ID", pref, "id");
71 base::ExpectDictStringValue(kName, pref, "display_name");
72 base::ExpectDictStringValue(kDescription, pref, "description");
73 base::ExpectDictStringValue(kMake, pref, "manufacturer");
74 base::ExpectDictStringValue(kModel, pref, "model");
75 base::ExpectDictStringValue(kUri, pref, "uri");
76 base::ExpectDictStringValue(kUUID, pref, "uuid");
77 }
78
79 TEST(PrinterTranslatorTest, PrinterToPrefPPDFile) {
80 Printer::PPDFile ppd;
81 ppd.id = kPPDiD;
82 ppd.file_name = kFileName;
83 ppd.version_number = kVersion;
84 ppd.from_quirks_server = kQuirks;
85
86 Printer printer("UNIQUE_ID");
87 printer.set_ppd(ppd);
88
89 base::DictionaryValue actual;
90 PrinterToPref(printer, &actual);
91
92 base::ExpectDictIntegerValue(kPPDiD, actual, "ppd.id");
93 base::ExpectDictStringValue(kFileName, actual, "ppd.file_name");
94 base::ExpectDictIntegerValue(kVersion, actual, "ppd.version_number");
95 base::ExpectDictBooleanValue(kQuirks, actual, "ppd.from_quirks_server");
96 }
97
98 TEST(PrinterTranslatorTest, MergePrinterPreferenceRoundTrip) {
99 base::DictionaryValue preference;
100 preference.SetString("id", kGUID);
101 preference.SetString("display_name", kName);
102 preference.SetString("description", kDescription);
103 preference.SetString("manufacturer", kMake);
104 preference.SetString("model", kModel);
105 preference.SetString("uri", kUri);
106 preference.SetString("uuid", kUUID);
107
108 preference.SetInteger("ppd.id", kPPDiD);
109 preference.SetString("ppd.file_name", kFileName);
110 preference.SetInteger("ppd.version_number", kVersion);
111 preference.SetBoolean("ppd.from_quirks_server", kQuirks);
112
113 base::DictionaryValue pref_copy;
114 Printer printer;
115 MergePrinterPreference(preference, &printer);
116 PrinterToPref(printer, &pref_copy);
117
118 EXPECT_TRUE(preference.Equals(&pref_copy));
119 }
120
121 } // namespace printing
122 } // namespace chromeos
OLDNEW
« chromeos/printing/OWNERS ('K') | « chromeos/printing/printer_translator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698