| 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 "components/printing/test/print_mock_render_thread.h" | 5 #include "components/printing/test/print_mock_render_thread.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "components/printing/test/mock_printer.h" | 13 #include "components/printing/test/mock_printer.h" |
| 14 #include "ipc/ipc_sync_message.h" | 14 #include "ipc/ipc_sync_message.h" |
| 15 #include "printing/features/features.h" | 15 #include "printing/features/features.h" |
| 16 #include "printing/page_range.h" | 16 #include "printing/page_range.h" |
| 17 #include "printing/print_job_constants.h" | 17 #include "printing/print_job_constants.h" |
| 18 #include "printing/units.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 #if BUILDFLAG(ENABLE_PRINTING) | 21 #if BUILDFLAG(ENABLE_PRINTING) |
| 21 #include "components/printing/common/print_messages.h" | 22 #include "components/printing/common/print_messages.h" |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 PrintMockRenderThread::PrintMockRenderThread() | 25 PrintMockRenderThread::PrintMockRenderThread() |
| 25 #if BUILDFLAG(ENABLE_PRINTING) | 26 #if BUILDFLAG(ENABLE_PRINTING) |
| 26 : printer_(new MockPrinter), | 27 : printer_(new MockPrinter), |
| 27 print_dialog_user_response_(true), | 28 print_dialog_user_response_(true), |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) { | 156 !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) { |
| 156 continue; | 157 continue; |
| 157 } | 158 } |
| 158 // Page numbers are 1-based in the dictionary. | 159 // Page numbers are 1-based in the dictionary. |
| 159 // Page numbers are 0-based for the printing context. | 160 // Page numbers are 0-based for the printing context. |
| 160 range.from--; | 161 range.from--; |
| 161 range.to--; | 162 range.to--; |
| 162 new_ranges.push_back(range); | 163 new_ranges.push_back(range); |
| 163 } | 164 } |
| 164 } | 165 } |
| 166 |
| 167 // Get media size |
| 168 const base::DictionaryValue* media_size_value = nullptr; |
| 169 gfx::Size page_size; |
| 170 if (job_settings.GetDictionary(printing::kSettingMediaSize, |
| 171 &media_size_value)) { |
| 172 int width_microns = 0; |
| 173 int height_microns = 0; |
| 174 if (media_size_value->GetInteger(printing::kSettingMediaSizeWidthMicrons, |
| 175 &width_microns) && |
| 176 media_size_value->GetInteger(printing::kSettingMediaSizeHeightMicrons, |
| 177 &height_microns)) { |
| 178 float device_microns_per_unit = |
| 179 (printing::kHundrethsMMPerInch * 10.0f) / printing::kDefaultPdfDpi; |
| 180 page_size = gfx::Size(width_microns / device_microns_per_unit, |
| 181 height_microns / device_microns_per_unit); |
| 182 } |
| 183 } |
| 184 |
| 185 // Get scaling |
| 186 int scale_factor = 100; |
| 187 job_settings.GetInteger(printing::kSettingScaleFactor, &scale_factor); |
| 188 |
| 165 std::vector<int> pages(printing::PageRange::GetPages(new_ranges)); | 189 std::vector<int> pages(printing::PageRange::GetPages(new_ranges)); |
| 166 printer_->UpdateSettings(document_cookie, params, pages, margins_type); | 190 printer_->UpdateSettings(document_cookie, params, pages, margins_type, |
| 167 | 191 page_size, scale_factor); |
| 168 job_settings.GetBoolean(printing::kSettingShouldPrintSelectionOnly, | 192 job_settings.GetBoolean(printing::kSettingShouldPrintSelectionOnly, |
| 169 ¶ms->params.selection_only); | 193 ¶ms->params.selection_only); |
| 170 job_settings.GetBoolean(printing::kSettingShouldPrintBackgrounds, | 194 job_settings.GetBoolean(printing::kSettingShouldPrintBackgrounds, |
| 171 ¶ms->params.should_print_backgrounds); | 195 ¶ms->params.should_print_backgrounds); |
| 172 } | 196 } |
| 173 | 197 |
| 174 MockPrinter* PrintMockRenderThread::printer() { | 198 MockPrinter* PrintMockRenderThread::printer() { |
| 175 return printer_.get(); | 199 return printer_.get(); |
| 176 } | 200 } |
| 177 | 201 |
| 178 void PrintMockRenderThread::set_print_dialog_user_response(bool response) { | 202 void PrintMockRenderThread::set_print_dialog_user_response(bool response) { |
| 179 print_dialog_user_response_ = response; | 203 print_dialog_user_response_ = response; |
| 180 } | 204 } |
| 181 | 205 |
| 182 void PrintMockRenderThread::set_print_preview_cancel_page_number(int page) { | 206 void PrintMockRenderThread::set_print_preview_cancel_page_number(int page) { |
| 183 print_preview_cancel_page_number_ = page; | 207 print_preview_cancel_page_number_ = page; |
| 184 } | 208 } |
| 185 | 209 |
| 186 int PrintMockRenderThread::print_preview_pages_remaining() const { | 210 int PrintMockRenderThread::print_preview_pages_remaining() const { |
| 187 return print_preview_pages_remaining_; | 211 return print_preview_pages_remaining_; |
| 188 } | 212 } |
| 189 #endif // BUILDFLAG(ENABLE_PRINTING) | 213 #endif // BUILDFLAG(ENABLE_PRINTING) |
| OLD | NEW |