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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file.h" | 6 #include "base/files/file.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
11 #include "base/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" |
14 #include "extensions/browser/api/printer_provider/printer_provider_api.h" | 15 #include "extensions/browser/api/printer_provider/printer_provider_api.h" |
15 #include "extensions/browser/api/printer_provider/printer_provider_api_factory.h
" | 16 #include "extensions/browser/api/printer_provider/printer_provider_api_factory.h
" |
16 #include "extensions/browser/api/printer_provider/printer_provider_print_job.h" | 17 #include "extensions/browser/api/printer_provider/printer_provider_print_job.h" |
17 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
19 #include "extensions/shell/test/shell_apitest.h" | 20 #include "extensions/shell/test/shell_apitest.h" |
20 #include "extensions/test/extension_test_message_listener.h" | 21 #include "extensions/test/extension_test_message_listener.h" |
21 #include "extensions/test/result_catcher.h" | 22 #include "extensions/test/result_catcher.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 PrinterProviderAPIFactory::GetInstance() | 100 PrinterProviderAPIFactory::GetInstance() |
100 ->GetForBrowserContext(browser_context()) | 101 ->GetForBrowserContext(browser_context()) |
101 ->DispatchPrintRequested(job, callback); | 102 ->DispatchPrintRequested(job, callback); |
102 } | 103 } |
103 | 104 |
104 void StartPrintRequestUsingDocumentBytes( | 105 void StartPrintRequestUsingDocumentBytes( |
105 const std::string& extension_id, | 106 const std::string& extension_id, |
106 const PrinterProviderAPI::PrintCallback& callback) { | 107 const PrinterProviderAPI::PrintCallback& callback) { |
107 extensions::PrinterProviderPrintJob job; | 108 extensions::PrinterProviderPrintJob job; |
108 job.printer_id = extension_id + ":printer_id"; | 109 job.printer_id = extension_id + ":printer_id"; |
| 110 job.job_title = base::ASCIIToUTF16("Print job"); |
109 job.ticket_json = "{}"; | 111 job.ticket_json = "{}"; |
110 job.content_type = "application/pdf"; | 112 job.content_type = "application/pdf"; |
111 const unsigned char kDocumentBytes[] = {'b', 'y', 't', 'e', 's'}; | 113 const unsigned char kDocumentBytes[] = {'b', 'y', 't', 'e', 's'}; |
112 job.document_bytes = | 114 job.document_bytes = |
113 new base::RefCountedBytes(kDocumentBytes, arraysize(kDocumentBytes)); | 115 new base::RefCountedBytes(kDocumentBytes, arraysize(kDocumentBytes)); |
114 | 116 |
115 PrinterProviderAPIFactory::GetInstance() | 117 PrinterProviderAPIFactory::GetInstance() |
116 ->GetForBrowserContext(browser_context()) | 118 ->GetForBrowserContext(browser_context()) |
117 ->DispatchPrintRequested(job, callback); | 119 ->DispatchPrintRequested(job, callback); |
118 } | 120 } |
119 | 121 |
120 bool StartPrintRequestUsingFileInfo( | 122 bool StartPrintRequestUsingFileInfo( |
121 const std::string& extension_id, | 123 const std::string& extension_id, |
122 const PrinterProviderAPI::PrintCallback& callback) { | 124 const PrinterProviderAPI::PrintCallback& callback) { |
123 extensions::PrinterProviderPrintJob job; | 125 extensions::PrinterProviderPrintJob job; |
124 | 126 |
125 const char kBytes[] = {'b', 'y', 't', 'e', 's'}; | 127 const char kBytes[] = {'b', 'y', 't', 'e', 's'}; |
126 if (!CreateTempFileWithContents(kBytes, static_cast<int>(arraysize(kBytes)), | 128 if (!CreateTempFileWithContents(kBytes, static_cast<int>(arraysize(kBytes)), |
127 &job.document_path, &job.file_info)) { | 129 &job.document_path, &job.file_info)) { |
128 ADD_FAILURE() << "Failed to create test file."; | 130 ADD_FAILURE() << "Failed to create test file."; |
129 return false; | 131 return false; |
130 } | 132 } |
131 | 133 |
132 job.printer_id = extension_id + ":printer_id"; | 134 job.printer_id = extension_id + ":printer_id"; |
| 135 job.job_title = base::ASCIIToUTF16("Print job"); |
133 job.ticket_json = "{}"; | 136 job.ticket_json = "{}"; |
134 job.content_type = "image/pwg-raster"; | 137 job.content_type = "image/pwg-raster"; |
135 | 138 |
136 PrinterProviderAPIFactory::GetInstance() | 139 PrinterProviderAPIFactory::GetInstance() |
137 ->GetForBrowserContext(browser_context()) | 140 ->GetForBrowserContext(browser_context()) |
138 ->DispatchPrintRequested(job, callback); | 141 ->DispatchPrintRequested(job, callback); |
139 return true; | 142 return true; |
140 } | 143 } |
141 | 144 |
142 void StartCapabilityRequest( | 145 void StartCapabilityRequest( |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 &printers, run_loop.QuitClosure())); | 765 &printers, run_loop.QuitClosure())); |
763 | 766 |
764 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 767 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
765 | 768 |
766 run_loop.Run(); | 769 run_loop.Run(); |
767 | 770 |
768 EXPECT_TRUE(printers.empty()); | 771 EXPECT_TRUE(printers.empty()); |
769 } | 772 } |
770 | 773 |
771 } // namespace | 774 } // namespace |
OLD | NEW |