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

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

Powered by Google App Engine
This is Rietveld 408576698