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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
| 9 #include <memory> |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
17 #include "chrome/browser/chromeos/printer_detector/printer_detector_factory.h" | 17 #include "chrome/browser/chromeos/printer_detector/printer_detector_factory.h" |
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
19 #include "chrome/browser/extensions/test_extension_system.h" | 19 #include "chrome/browser/extensions/test_extension_system.h" |
20 #include "chrome/browser/notifications/notification.h" | 20 #include "chrome/browser/notifications/notification.h" |
21 #include "chrome/browser/notifications/notification_test_util.h" | 21 #include "chrome/browser/notifications/notification_test_util.h" |
22 #include "chrome/browser/notifications/notification_ui_manager.h" | 22 #include "chrome/browser/notifications/notification_ui_manager.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 void set_usb_service(device::UsbService* service) { usb_service_ = service; } | 65 void set_usb_service(device::UsbService* service) { usb_service_ = service; } |
66 | 66 |
67 private: | 67 private: |
68 device::UsbService* usb_service_; | 68 device::UsbService* usb_service_; |
69 | 69 |
70 DISALLOW_COPY_AND_ASSIGN(FakeDeviceClient); | 70 DISALLOW_COPY_AND_ASSIGN(FakeDeviceClient); |
71 }; | 71 }; |
72 | 72 |
73 scoped_ptr<KeyedService> CreatePrinterDetector( | 73 std::unique_ptr<KeyedService> CreatePrinterDetector( |
74 content::BrowserContext* context) { | 74 content::BrowserContext* context) { |
75 return scoped_ptr<KeyedService>( | 75 return std::unique_ptr<KeyedService>( |
76 new chromeos::PrinterDetector(Profile::FromBrowserContext(context))); | 76 new chromeos::PrinterDetector(Profile::FromBrowserContext(context))); |
77 } | 77 } |
78 | 78 |
79 } // namespace | 79 } // namespace |
80 | 80 |
81 // TODO(tbarzic): Rename this test. | 81 // TODO(tbarzic): Rename this test. |
82 class PrinterDetectorAppSearchEnabledTest : public testing::Test { | 82 class PrinterDetectorAppSearchEnabledTest : public testing::Test { |
83 public: | 83 public: |
84 PrinterDetectorAppSearchEnabledTest() | 84 PrinterDetectorAppSearchEnabledTest() |
85 : user_manager_(new user_manager::FakeUserManager()), | 85 : user_manager_(new user_manager::FakeUserManager()), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 uint16_t product_id, | 122 uint16_t product_id, |
123 uint8_t interface_class) { | 123 uint8_t interface_class) { |
124 device::UsbConfigDescriptor config(1, false, false, 0); | 124 device::UsbConfigDescriptor config(1, false, false, 0); |
125 config.interfaces.emplace_back(1, 0, interface_class, 0, 0); | 125 config.interfaces.emplace_back(1, 0, interface_class, 0, 0); |
126 usb_service_.AddDevice( | 126 usb_service_.AddDevice( |
127 new device::MockUsbDevice(vendor_id, product_id, config)); | 127 new device::MockUsbDevice(vendor_id, product_id, config)); |
128 } | 128 } |
129 | 129 |
130 // Creates a test extension with the provided permissions. | 130 // Creates a test extension with the provided permissions. |
131 scoped_refptr<extensions::Extension> CreateTestExtension( | 131 scoped_refptr<extensions::Extension> CreateTestExtension( |
132 scoped_ptr<base::ListValue> permissions_builder, | 132 std::unique_ptr<base::ListValue> permissions_builder, |
133 scoped_ptr<base::DictionaryValue> usb_printers_builder) { | 133 std::unique_ptr<base::DictionaryValue> usb_printers_builder) { |
134 return extensions::ExtensionBuilder() | 134 return extensions::ExtensionBuilder() |
135 .SetID("fake_extension_id") | 135 .SetID("fake_extension_id") |
136 .SetManifest( | 136 .SetManifest( |
137 DictionaryBuilder() | 137 DictionaryBuilder() |
138 .Set("name", "Printer provider extension") | 138 .Set("name", "Printer provider extension") |
139 .Set("manifest_version", 2) | 139 .Set("manifest_version", 2) |
140 .Set("version", "1.0") | 140 .Set("version", "1.0") |
141 // Needed to enable usb API. | 141 // Needed to enable usb API. |
142 .Set("app", | 142 .Set("app", |
143 DictionaryBuilder() | 143 DictionaryBuilder() |
144 .Set("background", | 144 .Set("background", |
145 DictionaryBuilder() | 145 DictionaryBuilder() |
146 .Set("scripts", | 146 .Set("scripts", |
147 ListBuilder().Append("bg.js").Build()) | 147 ListBuilder().Append("bg.js").Build()) |
148 .Build()) | 148 .Build()) |
149 .Build()) | 149 .Build()) |
150 .Set("permissions", std::move(permissions_builder)) | 150 .Set("permissions", std::move(permissions_builder)) |
151 .Set("usb_printers", std::move(usb_printers_builder)) | 151 .Set("usb_printers", std::move(usb_printers_builder)) |
152 .Build()) | 152 .Build()) |
153 .Build(); | 153 .Build(); |
154 } | 154 } |
155 | 155 |
156 content::TestBrowserThreadBundle thread_bundle_; | 156 content::TestBrowserThreadBundle thread_bundle_; |
157 StubNotificationUIManager notification_ui_manager_; | 157 StubNotificationUIManager notification_ui_manager_; |
158 user_manager::FakeUserManager* user_manager_; | 158 user_manager::FakeUserManager* user_manager_; |
159 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 159 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
160 device::MockUsbService usb_service_; | 160 device::MockUsbService usb_service_; |
161 scoped_ptr<TestingProfile> profile_; | 161 std::unique_ptr<TestingProfile> profile_; |
162 FakeDeviceClient device_client_; | 162 FakeDeviceClient device_client_; |
163 | 163 |
164 DISALLOW_COPY_AND_ASSIGN(PrinterDetectorAppSearchEnabledTest); | 164 DISALLOW_COPY_AND_ASSIGN(PrinterDetectorAppSearchEnabledTest); |
165 }; | 165 }; |
166 | 166 |
167 TEST_F(PrinterDetectorAppSearchEnabledTest, ShowFindAppNotification) { | 167 TEST_F(PrinterDetectorAppSearchEnabledTest, ShowFindAppNotification) { |
168 InvokeUsbAdded(123, 456, kPrinterInterfaceClass); | 168 InvokeUsbAdded(123, 456, kPrinterInterfaceClass); |
169 | 169 |
170 ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount()); | 170 ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount()); |
171 const Notification& notification = | 171 const Notification& notification = |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 .Build()); | 357 .Build()); |
358 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) | 358 ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get()) |
359 ->AddEnabled(extension)); | 359 ->AddEnabled(extension)); |
360 | 360 |
361 InvokeUsbAdded(123, 456, 1); | 361 InvokeUsbAdded(123, 456, 1); |
362 | 362 |
363 ASSERT_EQ(0u, notification_ui_manager_.GetNotificationCount()); | 363 ASSERT_EQ(0u, notification_ui_manager_.GetNotificationCount()); |
364 } | 364 } |
365 | 365 |
366 } // namespace chromeos | 366 } // namespace chromeos |
OLD | NEW |