| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/json/json_string_value_serializer.h" | 15 #include "base/json/json_string_value_serializer.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted_memory.h" | 17 #include "base/memory/ref_counted_memory.h" |
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/threading/thread_restrictions.h" |
| 21 #include "device/usb/mock_usb_device.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 "extensions/browser/api/printer_provider/printer_provider_api.h" | 24 #include "extensions/browser/api/printer_provider/printer_provider_api.h" |
| 24 #include "extensions/browser/api/printer_provider/printer_provider_api_factory.h
" | 25 #include "extensions/browser/api/printer_provider/printer_provider_api_factory.h
" |
| 25 #include "extensions/browser/api/printer_provider/printer_provider_print_job.h" | 26 #include "extensions/browser/api/printer_provider/printer_provider_print_job.h" |
| 26 #include "extensions/browser/api/usb/usb_guid_map.h" | 27 #include "extensions/browser/api/usb/usb_guid_map.h" |
| 27 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
| 28 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 29 #include "extensions/common/value_builder.h" | 30 #include "extensions/common/value_builder.h" |
| 30 #include "extensions/shell/test/shell_apitest.h" | 31 #include "extensions/shell/test/shell_apitest.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 class PrinterProviderApiTest : public ShellApiTest { | 93 class PrinterProviderApiTest : public ShellApiTest { |
| 93 public: | 94 public: |
| 94 enum PrintRequestDataType { | 95 enum PrintRequestDataType { |
| 95 PRINT_REQUEST_DATA_TYPE_NOT_SET, | 96 PRINT_REQUEST_DATA_TYPE_NOT_SET, |
| 96 PRINT_REQUEST_DATA_TYPE_FILE, | 97 PRINT_REQUEST_DATA_TYPE_FILE, |
| 97 PRINT_REQUEST_DATA_TYPE_FILE_DELETED, | 98 PRINT_REQUEST_DATA_TYPE_FILE_DELETED, |
| 98 PRINT_REQUEST_DATA_TYPE_BYTES | 99 PRINT_REQUEST_DATA_TYPE_BYTES |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 PrinterProviderApiTest() {} | 102 PrinterProviderApiTest() {} |
| 102 ~PrinterProviderApiTest() override {} | 103 ~PrinterProviderApiTest() override { |
| 104 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 105 ignore_result(data_dir_.Delete()); |
| 106 } |
| 103 | 107 |
| 104 void StartGetPrintersRequest( | 108 void StartGetPrintersRequest( |
| 105 const PrinterProviderAPI::GetPrintersCallback& callback) { | 109 const PrinterProviderAPI::GetPrintersCallback& callback) { |
| 106 PrinterProviderAPIFactory::GetInstance() | 110 PrinterProviderAPIFactory::GetInstance() |
| 107 ->GetForBrowserContext(browser_context()) | 111 ->GetForBrowserContext(browser_context()) |
| 108 ->DispatchGetPrintersRequested(callback); | 112 ->DispatchGetPrintersRequested(callback); |
| 109 } | 113 } |
| 110 | 114 |
| 111 void StartGetUsbPrinterInfoRequest( | 115 void StartGetUsbPrinterInfoRequest( |
| 112 const std::string& extension_id, | 116 const std::string& extension_id, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 base::Bind(&RecordPrintResultAndRunCallback, &success, &print_status, | 235 base::Bind(&RecordPrintResultAndRunCallback, &success, &print_status, |
| 232 run_loop.QuitClosure()); | 236 run_loop.QuitClosure()); |
| 233 | 237 |
| 234 switch (data_type) { | 238 switch (data_type) { |
| 235 case PRINT_REQUEST_DATA_TYPE_NOT_SET: | 239 case PRINT_REQUEST_DATA_TYPE_NOT_SET: |
| 236 StartPrintRequestWithNoData(extension_id, callback); | 240 StartPrintRequestWithNoData(extension_id, callback); |
| 237 break; | 241 break; |
| 238 case PRINT_REQUEST_DATA_TYPE_FILE: | 242 case PRINT_REQUEST_DATA_TYPE_FILE: |
| 239 ASSERT_TRUE(StartPrintRequestUsingFileInfo(extension_id, callback)); | 243 ASSERT_TRUE(StartPrintRequestUsingFileInfo(extension_id, callback)); |
| 240 break; | 244 break; |
| 241 case PRINT_REQUEST_DATA_TYPE_FILE_DELETED: | 245 case PRINT_REQUEST_DATA_TYPE_FILE_DELETED: { |
| 242 ASSERT_TRUE(StartPrintRequestUsingFileInfo(extension_id, callback)); | 246 ASSERT_TRUE(StartPrintRequestUsingFileInfo(extension_id, callback)); |
| 247 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 243 ASSERT_TRUE(data_dir_.Delete()); | 248 ASSERT_TRUE(data_dir_.Delete()); |
| 244 break; | 249 break; |
| 250 } |
| 245 case PRINT_REQUEST_DATA_TYPE_BYTES: | 251 case PRINT_REQUEST_DATA_TYPE_BYTES: |
| 246 StartPrintRequestUsingDocumentBytes(extension_id, callback); | 252 StartPrintRequestUsingDocumentBytes(extension_id, callback); |
| 247 break; | 253 break; |
| 248 } | 254 } |
| 249 | 255 |
| 250 if (data_type != PRINT_REQUEST_DATA_TYPE_NOT_SET) | 256 if (data_type != PRINT_REQUEST_DATA_TYPE_NOT_SET) |
| 251 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 257 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 252 | 258 |
| 253 run_loop.Run(); | 259 run_loop.Run(); |
| 254 EXPECT_EQ(expected_result, print_status); | 260 EXPECT_EQ(expected_result, print_status); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 protected: | 348 protected: |
| 343 device::MockUsbService usb_service_; | 349 device::MockUsbService usb_service_; |
| 344 | 350 |
| 345 private: | 351 private: |
| 346 // Initializes |data_dir_| if needed and creates a file in it containing | 352 // Initializes |data_dir_| if needed and creates a file in it containing |
| 347 // provided data. | 353 // provided data. |
| 348 bool CreateTempFileWithContents(const char* data, | 354 bool CreateTempFileWithContents(const char* data, |
| 349 int size, | 355 int size, |
| 350 base::FilePath* path, | 356 base::FilePath* path, |
| 351 base::File::Info* file_info) { | 357 base::File::Info* file_info) { |
| 358 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 352 if (!data_dir_.IsValid() && !data_dir_.CreateUniqueTempDir()) | 359 if (!data_dir_.IsValid() && !data_dir_.CreateUniqueTempDir()) |
| 353 return false; | 360 return false; |
| 354 | 361 |
| 355 *path = data_dir_.GetPath().AppendASCII("data.pwg"); | 362 *path = data_dir_.GetPath().AppendASCII("data.pwg"); |
| 356 int written = base::WriteFile(*path, data, size); | 363 int written = base::WriteFile(*path, data, size); |
| 357 if (written != size) | 364 if (written != size) |
| 358 return false; | 365 return false; |
| 359 if (!base::GetFileInfo(*path, file_info)) | 366 if (!base::GetFileInfo(*path, file_info)) |
| 360 return false; | 367 return false; |
| 361 return true; | 368 return true; |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 RunUsbPrinterInfoRequestTest("EMPTY_RESPONSE"); | 864 RunUsbPrinterInfoRequestTest("EMPTY_RESPONSE"); |
| 858 } | 865 } |
| 859 | 866 |
| 860 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetUsbPrinterInfoNoListener) { | 867 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetUsbPrinterInfoNoListener) { |
| 861 RunUsbPrinterInfoRequestTest("NO_LISTENER"); | 868 RunUsbPrinterInfoRequestTest("NO_LISTENER"); |
| 862 } | 869 } |
| 863 | 870 |
| 864 } // namespace | 871 } // namespace |
| 865 | 872 |
| 866 } // namespace extensions | 873 } // namespace extensions |
| OLD | NEW |