| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/dbus/printer_service_provider.h" | 5 #include "chrome/browser/chromeos/dbus/printer_service_provider.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 9 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 10 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 10 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 const char kPrinterAdded[] = "PrinterAdded"; | 27 const char kPrinterAdded[] = "PrinterAdded"; |
| 28 | 28 |
| 29 const char kTestUserId[] = "test_user"; | 29 const char kTestUserId[] = "test_user"; |
| 30 | 30 |
| 31 const char kPrinterAppExistsDelegateIDTemplate[] = | 31 const char kPrinterAppExistsDelegateIDTemplate[] = |
| 32 "system.printer.printer_provider_exists/%s:%s"; | 32 "system.printer.printer_provider_exists/%s:%s"; |
| 33 | 33 |
| 34 const char kPrinterAppNotFoundDelegateIDTemplate[] = | 34 const char kPrinterAppNotFoundDelegateIDTemplate[] = |
| 35 "system.printer.no_printer_provider_found/%s:%s"; | 35 "system.printer.no_printer_provider_found/%s:%s"; |
| 36 | 36 |
| 37 class MockPrinterServiceProvider : public PrinterServiceProvider { | |
| 38 public: | |
| 39 MOCK_METHOD2(ShowCloudPrintHelp, | |
| 40 void(const std::string& vendor, const std::string& product)); | |
| 41 }; | |
| 42 | |
| 43 class PrinterServiceProviderTest : public testing::Test { | |
| 44 public: | |
| 45 void SetUp() override { | |
| 46 test_helper_.SetUp(kPrinterAdded, &service_provider_); | |
| 47 } | |
| 48 | |
| 49 void TearDown() override { test_helper_.TearDown(); } | |
| 50 | |
| 51 protected: | |
| 52 MockPrinterServiceProvider service_provider_; | |
| 53 ServiceProviderTestHelper test_helper_; | |
| 54 }; | |
| 55 | |
| 56 class PrinterServiceProviderAppSearchEnabledTest : public testing::Test { | 37 class PrinterServiceProviderAppSearchEnabledTest : public testing::Test { |
| 57 public: | 38 public: |
| 58 PrinterServiceProviderAppSearchEnabledTest() | 39 PrinterServiceProviderAppSearchEnabledTest() |
| 59 : user_manager_(new user_manager::FakeUserManager()), | 40 : user_manager_(new user_manager::FakeUserManager()), |
| 60 user_manager_enabler_(user_manager_) {} | 41 user_manager_enabler_(user_manager_) {} |
| 61 | 42 |
| 62 ~PrinterServiceProviderAppSearchEnabledTest() override = default; | 43 ~PrinterServiceProviderAppSearchEnabledTest() override = default; |
| 63 | 44 |
| 64 void SetUp() override { | 45 void SetUp() override { |
| 65 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 46 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 66 switches::kEnablePrinterAppSearch); | 47 switches::kEnablePrinterAppSearch); |
| 67 EXPECT_CALL(service_provider_, ShowCloudPrintHelp(testing::_, testing::_)) | |
| 68 .Times(0); | |
| 69 service_provider_.SetNotificationUIManagerForTesting( | 48 service_provider_.SetNotificationUIManagerForTesting( |
| 70 ¬ification_ui_manager_); | 49 ¬ification_ui_manager_); |
| 71 } | 50 } |
| 72 | 51 |
| 73 protected: | 52 protected: |
| 74 void AddTestUser() { | 53 void AddTestUser() { |
| 75 const user_manager::User* user = user_manager_->AddUser(kTestUserId); | 54 const user_manager::User* user = user_manager_->AddUser(kTestUserId); |
| 76 profile_.set_profile_name(kTestUserId); | 55 profile_.set_profile_name(kTestUserId); |
| 77 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting( | 56 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting( |
| 78 user, &profile_); | 57 user, &profile_); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 .Set("permissions", *permissions_builder)) | 109 .Set("permissions", *permissions_builder)) |
| 131 .Build(); | 110 .Build(); |
| 132 } | 111 } |
| 133 | 112 |
| 134 content::TestBrowserThreadBundle thread_bundle_; | 113 content::TestBrowserThreadBundle thread_bundle_; |
| 135 StubNotificationUIManager notification_ui_manager_; | 114 StubNotificationUIManager notification_ui_manager_; |
| 136 TestingProfile profile_; | 115 TestingProfile profile_; |
| 137 user_manager::FakeUserManager* user_manager_; | 116 user_manager::FakeUserManager* user_manager_; |
| 138 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 117 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
| 139 | 118 |
| 140 MockPrinterServiceProvider service_provider_; | 119 PrinterServiceProvider service_provider_; |
| 141 ServiceProviderTestHelper test_helper_; | 120 ServiceProviderTestHelper test_helper_; |
| 142 | 121 |
| 143 private: | 122 private: |
| 144 DISALLOW_COPY_AND_ASSIGN(PrinterServiceProviderAppSearchEnabledTest); | 123 DISALLOW_COPY_AND_ASSIGN(PrinterServiceProviderAppSearchEnabledTest); |
| 145 }; | 124 }; |
| 146 | 125 |
| 147 TEST_F(PrinterServiceProviderTest, ShowCloudPrintHelp) { | |
| 148 dbus::MethodCall method_call(kLibCrosServiceInterface, kPrinterAdded); | |
| 149 dbus::MessageWriter writer(&method_call); | |
| 150 writer.AppendString("123"); | |
| 151 writer.AppendString("456"); | |
| 152 | |
| 153 EXPECT_CALL(service_provider_, ShowCloudPrintHelp("123", "456")) | |
| 154 .Times(1); | |
| 155 | |
| 156 // Call the PrinterAdded method. | |
| 157 scoped_ptr<dbus::Response> response(test_helper_.CallMethod(&method_call)); | |
| 158 | |
| 159 // An empty response should be returned. | |
| 160 ASSERT_TRUE(response.get()); | |
| 161 dbus::MessageReader reader(response.get()); | |
| 162 ASSERT_FALSE(reader.HasMoreData()); | |
| 163 } | |
| 164 | |
| 165 TEST_F(PrinterServiceProviderAppSearchEnabledTest, ShowFindAppNotification) { | 126 TEST_F(PrinterServiceProviderAppSearchEnabledTest, ShowFindAppNotification) { |
| 166 AddTestUser(); | 127 AddTestUser(); |
| 167 | 128 |
| 168 std::string error; | 129 std::string error; |
| 169 ASSERT_TRUE(InvokePrinterAdded("123", "456", &error)) << error; | 130 ASSERT_TRUE(InvokePrinterAdded("123", "456", &error)) << error; |
| 170 | 131 |
| 171 ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount()); | 132 ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount()); |
| 172 const Notification& notification = | 133 const Notification& notification = |
| 173 notification_ui_manager_.GetNotificationAt(0); | 134 notification_ui_manager_.GetNotificationAt(0); |
| 174 EXPECT_EQ("123:456", notification.tag()); | 135 EXPECT_EQ("123:456", notification.tag()); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 ASSERT_TRUE(response.get()); | 278 ASSERT_TRUE(response.get()); |
| 318 dbus::MessageReader reader(response.get()); | 279 dbus::MessageReader reader(response.get()); |
| 319 ASSERT_FALSE(reader.HasMoreData()); | 280 ASSERT_FALSE(reader.HasMoreData()); |
| 320 test_helper_.TearDown(); | 281 test_helper_.TearDown(); |
| 321 | 282 |
| 322 EXPECT_EQ(0u, notification_ui_manager_.GetNotificationCount()); | 283 EXPECT_EQ(0u, notification_ui_manager_.GetNotificationCount()); |
| 323 } | 284 } |
| 324 | 285 |
| 325 } // namespace chromeos | 286 } // namespace chromeos |
| 326 | 287 |
| OLD | NEW |