| 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 "chrome/browser/chromeos/printing/printer_pref_manager.h" | 5 #include "chrome/browser/chromeos/printing/printer_pref_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h" | 11 #include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace chromeos { | 16 namespace chromeos { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const char kPrinterId[] = "UUID-UUID-UUID-PRINTER"; | 20 const char kPrinterId[] = "UUID-UUID-UUID-PRINTER"; |
| 20 const char kUri[] = "ipps://printer.chromium.org/ipp/print"; | 21 const char kUri[] = "ipps://printer.chromium.org/ipp/print"; |
| 21 | 22 |
| 22 } // namespace | 23 } // namespace |
| 23 | 24 |
| 24 TEST(PrinterPrefManagerTest, AddPrinter) { | 25 TEST(PrinterPrefManagerTest, AddPrinter) { |
| 26 content::TestBrowserThreadBundle thread_bundle; |
| 25 std::unique_ptr<Profile> profile = base::MakeUnique<TestingProfile>(); | 27 std::unique_ptr<Profile> profile = base::MakeUnique<TestingProfile>(); |
| 26 PrinterPrefManager* manager = | 28 PrinterPrefManager* manager = |
| 27 PrinterPrefManagerFactory::GetForBrowserContext(profile.get()); | 29 PrinterPrefManagerFactory::GetForBrowserContext(profile.get()); |
| 28 | 30 |
| 29 manager->RegisterPrinter(base::MakeUnique<Printer>(kPrinterId)); | 31 manager->RegisterPrinter(base::MakeUnique<Printer>(kPrinterId)); |
| 30 | 32 |
| 31 auto printers = manager->GetPrinters(); | 33 auto printers = manager->GetPrinters(); |
| 32 ASSERT_EQ(1U, printers.size()); | 34 ASSERT_EQ(1U, printers.size()); |
| 33 EXPECT_EQ(kPrinterId, printers[0]->id()); | 35 EXPECT_EQ(kPrinterId, printers[0]->id()); |
| 34 } | 36 } |
| 35 | 37 |
| 36 TEST(PrinterPrefManagerTest, UpdatePrinterAssignsId) { | 38 TEST(PrinterPrefManagerTest, UpdatePrinterAssignsId) { |
| 39 content::TestBrowserThreadBundle thread_bundle; |
| 37 std::unique_ptr<Profile> profile = base::MakeUnique<TestingProfile>(); | 40 std::unique_ptr<Profile> profile = base::MakeUnique<TestingProfile>(); |
| 38 PrinterPrefManager* manager = | 41 PrinterPrefManager* manager = |
| 39 PrinterPrefManagerFactory::GetForBrowserContext(profile.get()); | 42 PrinterPrefManagerFactory::GetForBrowserContext(profile.get()); |
| 40 | 43 |
| 41 manager->RegisterPrinter(base::MakeUnique<Printer>()); | 44 manager->RegisterPrinter(base::MakeUnique<Printer>()); |
| 42 | 45 |
| 43 auto printers = manager->GetPrinters(); | 46 auto printers = manager->GetPrinters(); |
| 44 ASSERT_EQ(1U, printers.size()); | 47 ASSERT_EQ(1U, printers.size()); |
| 45 EXPECT_FALSE(printers[0]->id().empty()); | 48 EXPECT_FALSE(printers[0]->id().empty()); |
| 46 } | 49 } |
| 47 | 50 |
| 48 TEST(PrinterPrefManagerTest, UpdatePrinter) { | 51 TEST(PrinterPrefManagerTest, UpdatePrinter) { |
| 52 content::TestBrowserThreadBundle thread_bundle; |
| 49 std::unique_ptr<Profile> profile = base::MakeUnique<TestingProfile>(); | 53 std::unique_ptr<Profile> profile = base::MakeUnique<TestingProfile>(); |
| 50 PrinterPrefManager* manager = | 54 PrinterPrefManager* manager = |
| 51 PrinterPrefManagerFactory::GetForBrowserContext(profile.get()); | 55 PrinterPrefManagerFactory::GetForBrowserContext(profile.get()); |
| 52 | 56 |
| 53 manager->RegisterPrinter(base::MakeUnique<Printer>(kPrinterId)); | 57 manager->RegisterPrinter(base::MakeUnique<Printer>(kPrinterId)); |
| 54 std::unique_ptr<Printer> updated_printer = | 58 std::unique_ptr<Printer> updated_printer = |
| 55 base::MakeUnique<Printer>(kPrinterId); | 59 base::MakeUnique<Printer>(kPrinterId); |
| 56 updated_printer->set_uri(kUri); | 60 updated_printer->set_uri(kUri); |
| 57 manager->RegisterPrinter(std::move(updated_printer)); | 61 manager->RegisterPrinter(std::move(updated_printer)); |
| 58 | 62 |
| 59 auto printers = manager->GetPrinters(); | 63 auto printers = manager->GetPrinters(); |
| 60 ASSERT_EQ(1U, printers.size()); | 64 ASSERT_EQ(1U, printers.size()); |
| 61 EXPECT_EQ(kUri, printers[0]->uri()); | 65 EXPECT_EQ(kUri, printers[0]->uri()); |
| 62 } | 66 } |
| 63 | 67 |
| 64 TEST(PrinterPrefManagerTest, RemovePrinter) { | 68 TEST(PrinterPrefManagerTest, RemovePrinter) { |
| 69 content::TestBrowserThreadBundle thread_bundle; |
| 65 std::unique_ptr<Profile> profile = base::MakeUnique<TestingProfile>(); | 70 std::unique_ptr<Profile> profile = base::MakeUnique<TestingProfile>(); |
| 66 PrinterPrefManager* manager = | 71 PrinterPrefManager* manager = |
| 67 PrinterPrefManagerFactory::GetForBrowserContext(profile.get()); | 72 PrinterPrefManagerFactory::GetForBrowserContext(profile.get()); |
| 68 | 73 |
| 69 manager->RegisterPrinter(base::MakeUnique<Printer>("OtherUUID")); | 74 manager->RegisterPrinter(base::MakeUnique<Printer>("OtherUUID")); |
| 70 manager->RegisterPrinter(base::MakeUnique<Printer>(kPrinterId)); | 75 manager->RegisterPrinter(base::MakeUnique<Printer>(kPrinterId)); |
| 71 manager->RegisterPrinter(base::MakeUnique<Printer>()); | 76 manager->RegisterPrinter(base::MakeUnique<Printer>()); |
| 72 | 77 |
| 73 manager->RemovePrinter(kPrinterId); | 78 manager->RemovePrinter(kPrinterId); |
| 74 | 79 |
| 75 auto printers = manager->GetPrinters(); | 80 auto printers = manager->GetPrinters(); |
| 76 ASSERT_EQ(2U, printers.size()); | 81 ASSERT_EQ(2U, printers.size()); |
| 77 EXPECT_NE(kPrinterId, printers.at(0)->id()); | 82 EXPECT_NE(kPrinterId, printers.at(0)->id()); |
| 78 EXPECT_NE(kPrinterId, printers.at(1)->id()); | 83 EXPECT_NE(kPrinterId, printers.at(1)->id()); |
| 79 } | 84 } |
| 80 | 85 |
| 81 } // namespace chromeos | 86 } // namespace chromeos |
| OLD | NEW |