| 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/printer_detector/printer_detector.h" | 5 #include "chrome/browser/chromeos/printer_detector/printer_detector.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 const Notification& notification = | 240 const Notification& notification = |
| 241 notification_ui_manager_.GetNotificationAt(0); | 241 notification_ui_manager_.GetNotificationAt(0); |
| 242 EXPECT_EQ("123:456", notification.tag()); | 242 EXPECT_EQ("123:456", notification.tag()); |
| 243 EXPECT_EQ( | 243 EXPECT_EQ( |
| 244 base::StringPrintf(kPrinterAppNotFoundDelegateIDTemplate, "123", "456"), | 244 base::StringPrintf(kPrinterAppNotFoundDelegateIDTemplate, "123", "456"), |
| 245 notification.delegate_id()); | 245 notification.delegate_id()); |
| 246 } | 246 } |
| 247 | 247 |
| 248 TEST_F(PrinterDetectorAppSearchEnabledTest, | 248 TEST_F(PrinterDetectorAppSearchEnabledTest, |
| 249 PrinterProvider_UsbPrinters_NotFound) { | 249 PrinterProvider_UsbPrinters_NotFound) { |
| 250 scoped_refptr<extensions::Extension> extension = | 250 scoped_refptr<extensions::Extension> extension = CreateTestExtension( |
| 251 CreateTestExtension( | 251 ListBuilder().Append("usb").Append("printerProvider").Pass(), |
| 252 ListBuilder().Append("usb").Append("printerProvider").Pass(), | 252 DictionaryBuilder().Set( |
| 253 DictionaryBuilder().Set( | 253 "filters", |
| 254 "filters", ListBuilder().Append(DictionaryBuilder() | 254 ListBuilder().Append( |
| 255 .Set("vendorId", 123) | 255 DictionaryBuilder().Set("vendorId", 123).Set("productId", 001)))); |
| 256 .Set("productId", 001)))) | |
| 257 .Pass(); | |
| 258 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) | 256 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) |
| 259 ->AddEnabled(extension)); | 257 ->AddEnabled(extension)); |
| 260 | 258 |
| 261 InvokeUsbAdded(123, 456, kPrinterInterfaceClass); | 259 InvokeUsbAdded(123, 456, kPrinterInterfaceClass); |
| 262 | 260 |
| 263 ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount()); | 261 ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount()); |
| 264 const Notification& notification = | 262 const Notification& notification = |
| 265 notification_ui_manager_.GetNotificationAt(0); | 263 notification_ui_manager_.GetNotificationAt(0); |
| 266 EXPECT_EQ("123:456", notification.tag()); | 264 EXPECT_EQ("123:456", notification.tag()); |
| 267 EXPECT_EQ( | 265 EXPECT_EQ( |
| 268 base::StringPrintf(kPrinterAppNotFoundDelegateIDTemplate, "123", "456"), | 266 base::StringPrintf(kPrinterAppNotFoundDelegateIDTemplate, "123", "456"), |
| 269 notification.delegate_id()); | 267 notification.delegate_id()); |
| 270 } | 268 } |
| 271 | 269 |
| 272 TEST_F(PrinterDetectorAppSearchEnabledTest, | 270 TEST_F(PrinterDetectorAppSearchEnabledTest, |
| 273 PrinterProvider_UsbPrinters_WithProductId) { | 271 PrinterProvider_UsbPrinters_WithProductId) { |
| 274 scoped_refptr<extensions::Extension> extension = | 272 scoped_refptr<extensions::Extension> extension = CreateTestExtension( |
| 275 CreateTestExtension( | 273 ListBuilder().Append("usb").Append("printerProvider").Pass(), |
| 276 ListBuilder().Append("usb").Append("printerProvider").Pass(), | 274 DictionaryBuilder().Set( |
| 277 DictionaryBuilder().Set( | 275 "filters", |
| 278 "filters", ListBuilder().Append(DictionaryBuilder() | 276 ListBuilder().Append( |
| 279 .Set("vendorId", 123) | 277 DictionaryBuilder().Set("vendorId", 123).Set("productId", 456)))); |
| 280 .Set("productId", 456)))) | |
| 281 .Pass(); | |
| 282 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) | 278 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) |
| 283 ->AddEnabled(extension)); | 279 ->AddEnabled(extension)); |
| 284 | 280 |
| 285 InvokeUsbAdded(123, 456, kPrinterInterfaceClass); | 281 InvokeUsbAdded(123, 456, kPrinterInterfaceClass); |
| 286 | 282 |
| 287 ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount()); | 283 ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount()); |
| 288 const Notification& notification = | 284 const Notification& notification = |
| 289 notification_ui_manager_.GetNotificationAt(0); | 285 notification_ui_manager_.GetNotificationAt(0); |
| 290 EXPECT_EQ("123:456", notification.tag()); | 286 EXPECT_EQ("123:456", notification.tag()); |
| 291 EXPECT_EQ( | 287 EXPECT_EQ( |
| 292 base::StringPrintf(kPrinterAppExistsDelegateIDTemplate, "123", "456"), | 288 base::StringPrintf(kPrinterAppExistsDelegateIDTemplate, "123", "456"), |
| 293 notification.delegate_id()); | 289 notification.delegate_id()); |
| 294 } | 290 } |
| 295 | 291 |
| 296 TEST_F(PrinterDetectorAppSearchEnabledTest, | 292 TEST_F(PrinterDetectorAppSearchEnabledTest, |
| 297 PrinterProvider_UsbPrinters_WithInterfaceClass) { | 293 PrinterProvider_UsbPrinters_WithInterfaceClass) { |
| 298 scoped_refptr<extensions::Extension> extension = | 294 scoped_refptr<extensions::Extension> extension = CreateTestExtension( |
| 299 CreateTestExtension( | 295 ListBuilder().Append("usb").Append("printerProvider").Pass(), |
| 300 ListBuilder().Append("usb").Append("printerProvider").Pass(), | 296 DictionaryBuilder().Set( |
| 301 DictionaryBuilder().Set( | 297 "filters", ListBuilder().Append( |
| 302 "filters", | 298 DictionaryBuilder() |
| 303 ListBuilder().Append( | 299 .Set("vendorId", 123) |
| 304 DictionaryBuilder() | 300 .Set("interfaceClass", kPrinterInterfaceClass)))); |
| 305 .Set("vendorId", 123) | |
| 306 .Set("interfaceClass", kPrinterInterfaceClass)))).Pass(); | |
| 307 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) | 301 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) |
| 308 ->AddEnabled(extension)); | 302 ->AddEnabled(extension)); |
| 309 | 303 |
| 310 InvokeUsbAdded(123, 456, kPrinterInterfaceClass); | 304 InvokeUsbAdded(123, 456, kPrinterInterfaceClass); |
| 311 | 305 |
| 312 ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount()); | 306 ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount()); |
| 313 const Notification& notification = | 307 const Notification& notification = |
| 314 notification_ui_manager_.GetNotificationAt(0); | 308 notification_ui_manager_.GetNotificationAt(0); |
| 315 EXPECT_EQ("123:456", notification.tag()); | 309 EXPECT_EQ("123:456", notification.tag()); |
| 316 EXPECT_EQ( | 310 EXPECT_EQ( |
| 317 base::StringPrintf(kPrinterAppExistsDelegateIDTemplate, "123", "456"), | 311 base::StringPrintf(kPrinterAppExistsDelegateIDTemplate, "123", "456"), |
| 318 notification.delegate_id()); | 312 notification.delegate_id()); |
| 319 } | 313 } |
| 320 | 314 |
| 321 TEST_F(PrinterDetectorAppSearchEnabledTest, IgnoreNonPrinters) { | 315 TEST_F(PrinterDetectorAppSearchEnabledTest, IgnoreNonPrinters) { |
| 322 scoped_refptr<extensions::Extension> extension = | 316 scoped_refptr<extensions::Extension> extension = CreateTestExtension( |
| 323 CreateTestExtension( | 317 ListBuilder().Append("usb").Append("printerProvider").Pass(), |
| 324 ListBuilder().Append("usb").Append("printerProvider").Pass(), | 318 DictionaryBuilder().Set( |
| 325 DictionaryBuilder().Set( | 319 "filters", ListBuilder().Append( |
| 326 "filters", | 320 DictionaryBuilder() |
| 327 ListBuilder().Append( | 321 .Set("vendorId", 123) |
| 328 DictionaryBuilder() | 322 .Set("interfaceClass", kPrinterInterfaceClass)))); |
| 329 .Set("vendorId", 123) | |
| 330 .Set("interfaceClass", kPrinterInterfaceClass)))).Pass(); | |
| 331 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) | 323 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) |
| 332 ->AddEnabled(extension)); | 324 ->AddEnabled(extension)); |
| 333 | 325 |
| 334 InvokeUsbAdded(123, 456, 1); | 326 InvokeUsbAdded(123, 456, 1); |
| 335 | 327 |
| 336 ASSERT_EQ(0u, notification_ui_manager_.GetNotificationCount()); | 328 ASSERT_EQ(0u, notification_ui_manager_.GetNotificationCount()); |
| 337 } | 329 } |
| 338 | 330 |
| 339 } // namespace chromeos | 331 } // namespace chromeos |
| OLD | NEW |