| 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" |
| 11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 12 #include "chrome/browser/chromeos/printer_detector/printer_detector_factory.h" | 12 #include "chrome/browser/chromeos/printer_detector/printer_detector_factory.h" |
| 13 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 13 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 14 #include "chrome/browser/extensions/test_extension_system.h" | 14 #include "chrome/browser/extensions/test_extension_system.h" |
| 15 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
| 16 #include "chrome/browser/notifications/notification_test_util.h" | 16 #include "chrome/browser/notifications/notification_test_util.h" |
| 17 #include "chrome/browser/notifications/notification_ui_manager.h" | 17 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "components/user_manager/fake_user_manager.h" | 19 #include "components/user_manager/fake_user_manager.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "device/core/device_client.h" | 21 #include "device/core/device_client.h" |
| 22 #include "device/usb/mock_usb_device.h" |
| 22 #include "device/usb/mock_usb_service.h" | 23 #include "device/usb/mock_usb_service.h" |
| 23 #include "device/usb/usb_descriptors.h" | 24 #include "device/usb/usb_descriptors.h" |
| 24 #include "device/usb/usb_device.h" | |
| 25 #include "device/usb/usb_service.h" | 25 #include "device/usb/usb_service.h" |
| 26 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
| 27 #include "extensions/common/extension_builder.h" | 27 #include "extensions/common/extension_builder.h" |
| 28 #include "extensions/common/value_builder.h" | 28 #include "extensions/common/value_builder.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 using extensions::DictionaryBuilder; | 31 using extensions::DictionaryBuilder; |
| 32 using extensions::ListBuilder; | 32 using extensions::ListBuilder; |
| 33 | 33 |
| 34 namespace chromeos { | 34 namespace chromeos { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 const uint8 kPrinterInterfaceClass = 7; | 38 const uint8 kPrinterInterfaceClass = 7; |
| 39 | 39 |
| 40 const char kTestUserId[] = "test_user"; | 40 const char kTestUserId[] = "test_user"; |
| 41 | 41 |
| 42 const char kPrinterAppExistsDelegateIDTemplate[] = | 42 const char kPrinterAppExistsDelegateIDTemplate[] = |
| 43 "system.printer.printer_provider_exists/%s:%s"; | 43 "system.printer.printer_provider_exists/%s:%s"; |
| 44 | 44 |
| 45 const char kPrinterAppNotFoundDelegateIDTemplate[] = | 45 const char kPrinterAppNotFoundDelegateIDTemplate[] = |
| 46 "system.printer.no_printer_provider_found/%s:%s"; | 46 "system.printer.no_printer_provider_found/%s:%s"; |
| 47 | 47 |
| 48 class FakeUsbDevice : public device::UsbDevice { | |
| 49 public: | |
| 50 FakeUsbDevice(uint16 vendor_id, uint16 product_id, uint8 interface_class) | |
| 51 : device::UsbDevice(vendor_id, | |
| 52 product_id, | |
| 53 base::ASCIIToUTF16("Google"), | |
| 54 base::ASCIIToUTF16("A product"), | |
| 55 base::ASCIIToUTF16("")) { | |
| 56 config_.reset(new device::UsbConfigDescriptor); | |
| 57 device::UsbInterfaceDescriptor interface; | |
| 58 interface.interface_number = 1; | |
| 59 interface.interface_class = interface_class; | |
| 60 config_->interfaces.push_back(interface); | |
| 61 } | |
| 62 | |
| 63 private: | |
| 64 ~FakeUsbDevice() override {} | |
| 65 | |
| 66 // device::UsbDevice overrides: | |
| 67 void Open(const OpenCallback& callback) override { | |
| 68 ADD_FAILURE() << "Not reached"; | |
| 69 } | |
| 70 | |
| 71 bool Close(scoped_refptr<device::UsbDeviceHandle> handle) override { | |
| 72 ADD_FAILURE() << "Not reached"; | |
| 73 return false; | |
| 74 } | |
| 75 | |
| 76 const device::UsbConfigDescriptor* GetActiveConfiguration() override { | |
| 77 return config_.get(); | |
| 78 } | |
| 79 | |
| 80 scoped_ptr<device::UsbConfigDescriptor> config_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(FakeUsbDevice); | |
| 83 }; | |
| 84 | |
| 85 class FakeDeviceClient : public device::DeviceClient { | 48 class FakeDeviceClient : public device::DeviceClient { |
| 86 public: | 49 public: |
| 87 FakeDeviceClient() : usb_service_(nullptr) {} | 50 FakeDeviceClient() : usb_service_(nullptr) {} |
| 88 | 51 |
| 89 ~FakeDeviceClient() override {} | 52 ~FakeDeviceClient() override {} |
| 90 | 53 |
| 91 // device::DeviceClient implementation: | 54 // device::DeviceClient implementation: |
| 92 device::UsbService* GetUsbService() override { | 55 device::UsbService* GetUsbService() override { |
| 93 EXPECT_TRUE(usb_service_); | 56 EXPECT_TRUE(usb_service_); |
| 94 return usb_service_; | 57 return usb_service_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting( | 108 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting( |
| 146 user, profile_.get()); | 109 user, profile_.get()); |
| 147 chromeos::PrinterDetectorFactory::GetInstance() | 110 chromeos::PrinterDetectorFactory::GetInstance() |
| 148 ->Get(profile_.get()) | 111 ->Get(profile_.get()) |
| 149 ->SetNotificationUIManagerForTesting(¬ification_ui_manager_); | 112 ->SetNotificationUIManagerForTesting(¬ification_ui_manager_); |
| 150 } | 113 } |
| 151 | 114 |
| 152 void InvokeUsbAdded(uint16 vendor_id, | 115 void InvokeUsbAdded(uint16 vendor_id, |
| 153 uint16 product_id, | 116 uint16 product_id, |
| 154 uint8 interface_class) { | 117 uint8 interface_class) { |
| 118 device::UsbInterfaceDescriptor interface; |
| 119 interface.interface_number = 1; |
| 120 interface.interface_class = interface_class; |
| 121 device::UsbConfigDescriptor config; |
| 122 config.interfaces.push_back(interface); |
| 155 usb_service_.AddDevice( | 123 usb_service_.AddDevice( |
| 156 new FakeUsbDevice(vendor_id, product_id, interface_class)); | 124 new device::MockUsbDevice(vendor_id, product_id, config)); |
| 157 } | 125 } |
| 158 | 126 |
| 159 // Creates a test extension with the provided permissions. | 127 // Creates a test extension with the provided permissions. |
| 160 scoped_refptr<extensions::Extension> CreateTestExtension( | 128 scoped_refptr<extensions::Extension> CreateTestExtension( |
| 161 ListBuilder& permissions_builder, | 129 ListBuilder& permissions_builder, |
| 162 DictionaryBuilder& usb_printers_builder) { | 130 DictionaryBuilder& usb_printers_builder) { |
| 163 return extensions::ExtensionBuilder() | 131 return extensions::ExtensionBuilder() |
| 164 .SetID("fake_extension_id") | 132 .SetID("fake_extension_id") |
| 165 .SetManifest( | 133 .SetManifest( |
| 166 DictionaryBuilder() | 134 DictionaryBuilder() |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 .Set("interfaceClass", kPrinterInterfaceClass)))).Pass(); | 329 .Set("interfaceClass", kPrinterInterfaceClass)))).Pass(); |
| 362 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) | 330 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) |
| 363 ->AddEnabled(extension)); | 331 ->AddEnabled(extension)); |
| 364 | 332 |
| 365 InvokeUsbAdded(123, 456, 1); | 333 InvokeUsbAdded(123, 456, 1); |
| 366 | 334 |
| 367 ASSERT_EQ(0u, notification_ui_manager_.GetNotificationCount()); | 335 ASSERT_EQ(0u, notification_ui_manager_.GetNotificationCount()); |
| 368 } | 336 } |
| 369 | 337 |
| 370 } // namespace chromeos | 338 } // namespace chromeos |
| OLD | NEW |