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

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

Issue 2858353004: Track printer installations for each configuration. (Closed)
Patch Set: rebase 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
« no previous file with comments | « chromeos/printing/printer_translator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/time/time.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 #include "chromeos/printing/printer_configuration.h" 11 #include "chromeos/printing/printer_configuration.h"
11 #include "chromeos/printing/printer_translator.h" 12 #include "chromeos/printing/printer_translator.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace chromeos { 15 namespace chromeos {
15 namespace printing { 16 namespace printing {
16 17
17 // Printer test data 18 // Printer test data
18 const char kHash[] = "ABCDEF123456"; 19 const char kHash[] = "ABCDEF123456";
19 const char kName[] = "Chrome Super Printer"; 20 const char kName[] = "Chrome Super Printer";
20 const char kDescription[] = "first star on the left"; 21 const char kDescription[] = "first star on the left";
21 const char kMake[] = "Chrome"; 22 const char kMake[] = "Chrome";
22 const char kModel[] = "Inktastic Laser Magic"; 23 const char kModel[] = "Inktastic Laser Magic";
23 const char kUri[] = "ipp://printy.domain.co:555/ipp/print"; 24 const char kUri[] = "ipp://printy.domain.co:555/ipp/print";
24 const char kUUID[] = "UUID-UUID-UUID"; 25 const char kUUID[] = "UUID-UUID-UUID";
25 26
27 const base::Time kTimestamp = base::Time::FromInternalValue(445566);
28
26 // PpdReference test data 29 // PpdReference test data
27 const char kEffectiveMakeAndModel[] = "PrintBlaster LazerInker 2000"; 30 const char kEffectiveMakeAndModel[] = "PrintBlaster LazerInker 2000";
28 31
29 TEST(PrinterTranslatorTest, RecommendedPrinterToPrinterMissingId) { 32 TEST(PrinterTranslatorTest, RecommendedPrinterToPrinterMissingId) {
30 base::DictionaryValue value; 33 base::DictionaryValue value;
31 std::unique_ptr<Printer> printer = RecommendedPrinterToPrinter(value); 34 std::unique_ptr<Printer> printer =
35 RecommendedPrinterToPrinter(value, kTimestamp);
32 36
33 EXPECT_FALSE(printer); 37 EXPECT_FALSE(printer);
34 } 38 }
35 39
36 TEST(PrinterTranslatorTest, MissingDisplayNameFails) { 40 TEST(PrinterTranslatorTest, MissingDisplayNameFails) {
37 base::DictionaryValue preference; 41 base::DictionaryValue preference;
38 preference.SetString("id", kHash); 42 preference.SetString("id", kHash);
39 // display name omitted 43 // display name omitted
40 preference.SetString("uri", kUri); 44 preference.SetString("uri", kUri);
41 preference.SetString("ppd_resource.effective_model", kEffectiveMakeAndModel); 45 preference.SetString("ppd_resource.effective_model", kEffectiveMakeAndModel);
42 46
43 std::unique_ptr<Printer> printer = RecommendedPrinterToPrinter(preference); 47 std::unique_ptr<Printer> printer =
48 RecommendedPrinterToPrinter(preference, kTimestamp);
44 EXPECT_FALSE(printer); 49 EXPECT_FALSE(printer);
45 } 50 }
46 51
47 TEST(PrinterTranslatorTest, MissingUriFails) { 52 TEST(PrinterTranslatorTest, MissingUriFails) {
48 base::DictionaryValue preference; 53 base::DictionaryValue preference;
49 preference.SetString("id", kHash); 54 preference.SetString("id", kHash);
50 preference.SetString("display_name", kName); 55 preference.SetString("display_name", kName);
51 // uri omitted 56 // uri omitted
52 preference.SetString("ppd_resource.effective_model", kEffectiveMakeAndModel); 57 preference.SetString("ppd_resource.effective_model", kEffectiveMakeAndModel);
53 58
54 std::unique_ptr<Printer> printer = RecommendedPrinterToPrinter(preference); 59 std::unique_ptr<Printer> printer =
60 RecommendedPrinterToPrinter(preference, kTimestamp);
55 EXPECT_FALSE(printer); 61 EXPECT_FALSE(printer);
56 } 62 }
57 63
58 TEST(PrinterTranslatorTest, MissingPpdResourceFails) { 64 TEST(PrinterTranslatorTest, MissingPpdResourceFails) {
59 base::DictionaryValue preference; 65 base::DictionaryValue preference;
60 preference.SetString("id", kHash); 66 preference.SetString("id", kHash);
61 preference.SetString("display_name", kName); 67 preference.SetString("display_name", kName);
62 preference.SetString("uri", kUri); 68 preference.SetString("uri", kUri);
63 // ppd resource omitted 69 // ppd resource omitted
64 70
65 std::unique_ptr<Printer> printer = RecommendedPrinterToPrinter(preference); 71 std::unique_ptr<Printer> printer =
72 RecommendedPrinterToPrinter(preference, kTimestamp);
66 EXPECT_FALSE(printer); 73 EXPECT_FALSE(printer);
67 } 74 }
68 75
69 TEST(PrinterTranslatorTest, MissingEffectiveMakeModelFails) { 76 TEST(PrinterTranslatorTest, MissingEffectiveMakeModelFails) {
70 base::DictionaryValue preference; 77 base::DictionaryValue preference;
71 preference.SetString("id", kHash); 78 preference.SetString("id", kHash);
72 preference.SetString("display_name", kName); 79 preference.SetString("display_name", kName);
73 preference.SetString("uri", kUri); 80 preference.SetString("uri", kUri);
74 preference.SetString("ppd_resource.foobarwrongfield", "gibberish"); 81 preference.SetString("ppd_resource.foobarwrongfield", "gibberish");
75 82
76 std::unique_ptr<Printer> printer = RecommendedPrinterToPrinter(preference); 83 std::unique_ptr<Printer> printer =
84 RecommendedPrinterToPrinter(preference, kTimestamp);
77 EXPECT_FALSE(printer); 85 EXPECT_FALSE(printer);
78 } 86 }
79 87
80 TEST(PrinterTranslatorTest, RecommendedPrinterMinimalSetup) { 88 TEST(PrinterTranslatorTest, RecommendedPrinterMinimalSetup) {
81 base::DictionaryValue preference; 89 base::DictionaryValue preference;
82 preference.SetString("id", kHash); 90 preference.SetString("id", kHash);
83 preference.SetString("display_name", kName); 91 preference.SetString("display_name", kName);
84 preference.SetString("uri", kUri); 92 preference.SetString("uri", kUri);
85 preference.SetString("ppd_resource.effective_model", kEffectiveMakeAndModel); 93 preference.SetString("ppd_resource.effective_model", kEffectiveMakeAndModel);
86 94
87 std::unique_ptr<Printer> printer = RecommendedPrinterToPrinter(preference); 95 std::unique_ptr<Printer> printer =
96 RecommendedPrinterToPrinter(preference, kTimestamp);
88 EXPECT_TRUE(printer); 97 EXPECT_TRUE(printer);
89 } 98 }
90 99
91 TEST(PrinterTranslatorTest, RecommendedPrinterToPrinter) { 100 TEST(PrinterTranslatorTest, RecommendedPrinterToPrinter) {
92 base::DictionaryValue preference; 101 base::DictionaryValue preference;
93 preference.SetString("id", kHash); 102 preference.SetString("id", kHash);
94 preference.SetString("display_name", kName); 103 preference.SetString("display_name", kName);
95 preference.SetString("description", kDescription); 104 preference.SetString("description", kDescription);
96 preference.SetString("manufacturer", kMake); 105 preference.SetString("manufacturer", kMake);
97 preference.SetString("model", kModel); 106 preference.SetString("model", kModel);
98 preference.SetString("uri", kUri); 107 preference.SetString("uri", kUri);
99 preference.SetString("uuid", kUUID); 108 preference.SetString("uuid", kUUID);
100 109
101 preference.SetString("ppd_resource.effective_model", kEffectiveMakeAndModel); 110 preference.SetString("ppd_resource.effective_model", kEffectiveMakeAndModel);
102 111
103 std::unique_ptr<Printer> printer = RecommendedPrinterToPrinter(preference); 112 std::unique_ptr<Printer> printer =
113 RecommendedPrinterToPrinter(preference, kTimestamp);
104 EXPECT_TRUE(printer); 114 EXPECT_TRUE(printer);
105 115
106 EXPECT_EQ(kHash, printer->id()); 116 EXPECT_EQ(kHash, printer->id());
107 EXPECT_EQ(kName, printer->display_name()); 117 EXPECT_EQ(kName, printer->display_name());
108 EXPECT_EQ(kDescription, printer->description()); 118 EXPECT_EQ(kDescription, printer->description());
109 EXPECT_EQ(kMake, printer->manufacturer()); 119 EXPECT_EQ(kMake, printer->manufacturer());
110 EXPECT_EQ(kModel, printer->model()); 120 EXPECT_EQ(kModel, printer->model());
111 EXPECT_EQ(kUri, printer->uri()); 121 EXPECT_EQ(kUri, printer->uri());
112 EXPECT_EQ(kUUID, printer->uuid()); 122 EXPECT_EQ(kUUID, printer->uuid());
123 EXPECT_EQ(kTimestamp, printer->last_updated());
113 124
114 EXPECT_EQ(kEffectiveMakeAndModel, 125 EXPECT_EQ(kEffectiveMakeAndModel,
115 printer->ppd_reference().effective_make_and_model); 126 printer->ppd_reference().effective_make_and_model);
116 } 127 }
117 128
118 } // namespace printing 129 } // namespace printing
119 } // namespace chromeos 130 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/printing/printer_translator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698