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