| OLD | NEW |
| 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/time/time.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chromeos/printing/printer_configuration.h" | 11 #include "chromeos/printing/printer_configuration.h" |
| 12 #include "chromeos/printing/printer_translator.h" | 12 #include "chromeos/printing/printer_translator.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace chromeos { | 15 namespace chromeos { |
| 16 namespace printing { | 16 namespace printing { |
| 17 | 17 |
| 18 // Printer test data | 18 // Printer test data |
| 19 const char kHash[] = "ABCDEF123456"; | 19 const char kHash[] = "ABCDEF123456"; |
| 20 const char kName[] = "Chrome Super Printer"; | 20 const char kName[] = "Chrome Super Printer"; |
| 21 const char kDescription[] = "first star on the left"; | 21 const char kDescription[] = "first star on the left"; |
| 22 const char kUri[] = "ipp://printy.domain.co:555/ipp/print"; |
| 23 const char kUUID[] = "UUID-UUID-UUID"; |
| 24 |
| 22 const char kMake[] = "Chrome"; | 25 const char kMake[] = "Chrome"; |
| 23 const char kModel[] = "Inktastic Laser Magic"; | 26 const char kModel[] = "Inktastic Laser Magic"; |
| 24 const char kUri[] = "ipp://printy.domain.co:555/ipp/print"; | 27 const char kMakeAndModel[] = "Chrome Inktastic Laser Magic"; |
| 25 const char kUUID[] = "UUID-UUID-UUID"; | |
| 26 | 28 |
| 27 const base::Time kTimestamp = base::Time::FromInternalValue(445566); | 29 const base::Time kTimestamp = base::Time::FromInternalValue(445566); |
| 28 | 30 |
| 29 // PpdReference test data | 31 // PpdReference test data |
| 30 const char kEffectiveMakeAndModel[] = "PrintBlaster LazerInker 2000"; | 32 const char kEffectiveMakeAndModel[] = "PrintBlaster LazerInker 2000"; |
| 31 | 33 |
| 32 TEST(PrinterTranslatorTest, RecommendedPrinterToPrinterMissingId) { | 34 TEST(PrinterTranslatorTest, RecommendedPrinterToPrinterMissingId) { |
| 33 base::DictionaryValue value; | 35 base::DictionaryValue value; |
| 34 std::unique_ptr<Printer> printer = | 36 std::unique_ptr<Printer> printer = |
| 35 RecommendedPrinterToPrinter(value, kTimestamp); | 37 RecommendedPrinterToPrinter(value, kTimestamp); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 113 |
| 112 std::unique_ptr<Printer> printer = | 114 std::unique_ptr<Printer> printer = |
| 113 RecommendedPrinterToPrinter(preference, kTimestamp); | 115 RecommendedPrinterToPrinter(preference, kTimestamp); |
| 114 EXPECT_TRUE(printer); | 116 EXPECT_TRUE(printer); |
| 115 | 117 |
| 116 EXPECT_EQ(kHash, printer->id()); | 118 EXPECT_EQ(kHash, printer->id()); |
| 117 EXPECT_EQ(kName, printer->display_name()); | 119 EXPECT_EQ(kName, printer->display_name()); |
| 118 EXPECT_EQ(kDescription, printer->description()); | 120 EXPECT_EQ(kDescription, printer->description()); |
| 119 EXPECT_EQ(kMake, printer->manufacturer()); | 121 EXPECT_EQ(kMake, printer->manufacturer()); |
| 120 EXPECT_EQ(kModel, printer->model()); | 122 EXPECT_EQ(kModel, printer->model()); |
| 123 EXPECT_EQ(kMakeAndModel, printer->make_and_model()); |
| 121 EXPECT_EQ(kUri, printer->uri()); | 124 EXPECT_EQ(kUri, printer->uri()); |
| 122 EXPECT_EQ(kUUID, printer->uuid()); | 125 EXPECT_EQ(kUUID, printer->uuid()); |
| 123 EXPECT_EQ(kTimestamp, printer->last_updated()); | 126 EXPECT_EQ(kTimestamp, printer->last_updated()); |
| 124 | 127 |
| 125 EXPECT_EQ(kEffectiveMakeAndModel, | 128 EXPECT_EQ(kEffectiveMakeAndModel, |
| 126 printer->ppd_reference().effective_make_and_model); | 129 printer->ppd_reference().effective_make_and_model); |
| 127 } | 130 } |
| 128 | 131 |
| 132 TEST(PrinterTranslatorTest, RecommendedPrinterToPrinterBlankManufacturer) { |
| 133 base::DictionaryValue preference; |
| 134 preference.SetString("id", kHash); |
| 135 preference.SetString("display_name", kName); |
| 136 preference.SetString("model", kModel); |
| 137 preference.SetString("uri", kUri); |
| 138 preference.SetString("ppd_resource.effective_model", kEffectiveMakeAndModel); |
| 139 |
| 140 std::unique_ptr<Printer> printer = |
| 141 RecommendedPrinterToPrinter(preference, kTimestamp); |
| 142 EXPECT_TRUE(printer); |
| 143 |
| 144 EXPECT_EQ(kModel, printer->model()); |
| 145 EXPECT_EQ(kModel, printer->make_and_model()); |
| 146 } |
| 147 |
| 148 TEST(PrinterTranslatorTest, RecommendedPrinterToPrinterBlankModel) { |
| 149 base::DictionaryValue preference; |
| 150 preference.SetString("id", kHash); |
| 151 preference.SetString("display_name", kName); |
| 152 preference.SetString("manufacturer", kMake); |
| 153 preference.SetString("uri", kUri); |
| 154 preference.SetString("ppd_resource.effective_model", kEffectiveMakeAndModel); |
| 155 |
| 156 std::unique_ptr<Printer> printer = |
| 157 RecommendedPrinterToPrinter(preference, kTimestamp); |
| 158 EXPECT_TRUE(printer); |
| 159 |
| 160 EXPECT_EQ(kMake, printer->manufacturer()); |
| 161 EXPECT_EQ(kMake, printer->make_and_model()); |
| 162 } |
| 163 |
| 129 } // namespace printing | 164 } // namespace printing |
| 130 } // namespace chromeos | 165 } // namespace chromeos |
| OLD | NEW |