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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "chrome/common/chrome_switches.h" | 7 #include "chrome/common/chrome_switches.h" |
8 #include "chrome/common/print_messages.h" | 8 #include "chrome/common/print_messages.h" |
9 #include "chrome/renderer/printing/mock_printer.h" | 9 #include "chrome/renderer/printing/mock_printer.h" |
10 #include "chrome/renderer/printing/print_web_view_helper.h" | 10 #include "chrome/renderer/printing/print_web_view_helper.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // always print all pages, and there are checks to that effect built into | 144 // always print all pages, and there are checks to that effect built into |
145 // the print code. | 145 // the print code. |
146 #else | 146 #else |
147 const IPC::Message* page_cnt_msg = | 147 const IPC::Message* page_cnt_msg = |
148 render_thread_->sink().GetUniqueMessageMatching( | 148 render_thread_->sink().GetUniqueMessageMatching( |
149 PrintHostMsg_DidGetPrintedPagesCount::ID); | 149 PrintHostMsg_DidGetPrintedPagesCount::ID); |
150 ASSERT_TRUE(page_cnt_msg); | 150 ASSERT_TRUE(page_cnt_msg); |
151 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param; | 151 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param; |
152 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg, | 152 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg, |
153 &post_page_count_param); | 153 &post_page_count_param); |
154 EXPECT_EQ(count, post_page_count_param.b); | 154 EXPECT_EQ(count, get<1>(post_page_count_param)); |
155 #endif // defined(OS_CHROMEOS) | 155 #endif // defined(OS_CHROMEOS) |
156 } | 156 } |
157 | 157 |
158 // The renderer should be done calculating the number of rendered pages | 158 // The renderer should be done calculating the number of rendered pages |
159 // according to the specified settings defined in the mock render thread. | 159 // according to the specified settings defined in the mock render thread. |
160 // Verify the page count is correct. | 160 // Verify the page count is correct. |
161 void VerifyPreviewPageCount(int count) { | 161 void VerifyPreviewPageCount(int count) { |
162 const IPC::Message* page_cnt_msg = | 162 const IPC::Message* page_cnt_msg = |
163 render_thread_->sink().GetUniqueMessageMatching( | 163 render_thread_->sink().GetUniqueMessageMatching( |
164 PrintHostMsg_DidGetPreviewPageCount::ID); | 164 PrintHostMsg_DidGetPreviewPageCount::ID); |
165 ASSERT_TRUE(page_cnt_msg); | 165 ASSERT_TRUE(page_cnt_msg); |
166 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param; | 166 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param; |
167 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg, | 167 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg, |
168 &post_page_count_param); | 168 &post_page_count_param); |
169 EXPECT_EQ(count, post_page_count_param.a.page_count); | 169 EXPECT_EQ(count, get<0>(post_page_count_param).page_count); |
170 } | 170 } |
171 | 171 |
172 // Verifies whether the pages printed or not. | 172 // Verifies whether the pages printed or not. |
173 void VerifyPagesPrinted(bool printed) { | 173 void VerifyPagesPrinted(bool printed) { |
174 #if defined(OS_CHROMEOS) | 174 #if defined(OS_CHROMEOS) |
175 bool did_print_msg = (render_thread_->sink().GetUniqueMessageMatching( | 175 bool did_print_msg = (render_thread_->sink().GetUniqueMessageMatching( |
176 PrintHostMsg_TempFileForPrintingWritten::ID) != NULL); | 176 PrintHostMsg_TempFileForPrintingWritten::ID) != NULL); |
177 ASSERT_EQ(printed, did_print_msg); | 177 ASSERT_EQ(printed, did_print_msg); |
178 #else | 178 #else |
179 const IPC::Message* print_msg = | 179 const IPC::Message* print_msg = |
180 render_thread_->sink().GetUniqueMessageMatching( | 180 render_thread_->sink().GetUniqueMessageMatching( |
181 PrintHostMsg_DidPrintPage::ID); | 181 PrintHostMsg_DidPrintPage::ID); |
182 bool did_print_msg = (NULL != print_msg); | 182 bool did_print_msg = (NULL != print_msg); |
183 ASSERT_EQ(printed, did_print_msg); | 183 ASSERT_EQ(printed, did_print_msg); |
184 if (printed) { | 184 if (printed) { |
185 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; | 185 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; |
186 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); | 186 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); |
187 EXPECT_EQ(0, post_did_print_page_param.a.page_number); | 187 EXPECT_EQ(0, get<0>(post_did_print_page_param).page_number); |
188 } | 188 } |
189 #endif // defined(OS_CHROMEOS) | 189 #endif // defined(OS_CHROMEOS) |
190 } | 190 } |
191 | 191 |
192 #if defined(ENABLE_BASIC_PRINTING) | 192 #if defined(ENABLE_BASIC_PRINTING) |
193 void OnPrintPages() { | 193 void OnPrintPages() { |
194 PrintWebViewHelper::Get(view_)->OnPrintPages(); | 194 PrintWebViewHelper::Get(view_)->OnPrintPages(); |
195 ProcessPendingMessages(); | 195 ProcessPendingMessages(); |
196 } | 196 } |
197 #endif // ENABLE_BASIC_PRINTING | 197 #endif // ENABLE_BASIC_PRINTING |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 487 |
488 void VerifyPrintPreviewGenerated(bool generated_preview) { | 488 void VerifyPrintPreviewGenerated(bool generated_preview) { |
489 const IPC::Message* preview_msg = | 489 const IPC::Message* preview_msg = |
490 render_thread_->sink().GetUniqueMessageMatching( | 490 render_thread_->sink().GetUniqueMessageMatching( |
491 PrintHostMsg_MetafileReadyForPrinting::ID); | 491 PrintHostMsg_MetafileReadyForPrinting::ID); |
492 bool did_get_preview_msg = (NULL != preview_msg); | 492 bool did_get_preview_msg = (NULL != preview_msg); |
493 ASSERT_EQ(generated_preview, did_get_preview_msg); | 493 ASSERT_EQ(generated_preview, did_get_preview_msg); |
494 if (did_get_preview_msg) { | 494 if (did_get_preview_msg) { |
495 PrintHostMsg_MetafileReadyForPrinting::Param preview_param; | 495 PrintHostMsg_MetafileReadyForPrinting::Param preview_param; |
496 PrintHostMsg_MetafileReadyForPrinting::Read(preview_msg, &preview_param); | 496 PrintHostMsg_MetafileReadyForPrinting::Read(preview_msg, &preview_param); |
497 EXPECT_NE(0, preview_param.a.document_cookie); | 497 EXPECT_NE(0, get<0>(preview_param).document_cookie); |
498 EXPECT_NE(0, preview_param.a.expected_pages_count); | 498 EXPECT_NE(0, get<0>(preview_param).expected_pages_count); |
499 EXPECT_NE(0U, preview_param.a.data_size); | 499 EXPECT_NE(0U, get<0>(preview_param).data_size); |
500 } | 500 } |
501 } | 501 } |
502 | 502 |
503 void VerifyPrintFailed(bool did_fail) { | 503 void VerifyPrintFailed(bool did_fail) { |
504 bool print_failed = (render_thread_->sink().GetUniqueMessageMatching( | 504 bool print_failed = (render_thread_->sink().GetUniqueMessageMatching( |
505 PrintHostMsg_PrintingFailed::ID) != NULL); | 505 PrintHostMsg_PrintingFailed::ID) != NULL); |
506 EXPECT_EQ(did_fail, print_failed); | 506 EXPECT_EQ(did_fail, print_failed); |
507 } | 507 } |
508 | 508 |
509 void VerifyPrintPreviewInvalidPrinterSettings(bool settings_invalid) { | 509 void VerifyPrintPreviewInvalidPrinterSettings(bool settings_invalid) { |
510 bool print_preview_invalid_printer_settings = | 510 bool print_preview_invalid_printer_settings = |
511 (render_thread_->sink().GetUniqueMessageMatching( | 511 (render_thread_->sink().GetUniqueMessageMatching( |
512 PrintHostMsg_PrintPreviewInvalidPrinterSettings::ID) != NULL); | 512 PrintHostMsg_PrintPreviewInvalidPrinterSettings::ID) != NULL); |
513 EXPECT_EQ(settings_invalid, print_preview_invalid_printer_settings); | 513 EXPECT_EQ(settings_invalid, print_preview_invalid_printer_settings); |
514 } | 514 } |
515 | 515 |
516 // |page_number| is 0-based. | 516 // |page_number| is 0-based. |
517 void VerifyDidPreviewPage(bool generate_draft_pages, int page_number) { | 517 void VerifyDidPreviewPage(bool generate_draft_pages, int page_number) { |
518 bool msg_found = false; | 518 bool msg_found = false; |
519 size_t msg_count = render_thread_->sink().message_count(); | 519 size_t msg_count = render_thread_->sink().message_count(); |
520 for (size_t i = 0; i < msg_count; ++i) { | 520 for (size_t i = 0; i < msg_count; ++i) { |
521 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); | 521 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); |
522 if (msg->type() == PrintHostMsg_DidPreviewPage::ID) { | 522 if (msg->type() == PrintHostMsg_DidPreviewPage::ID) { |
523 PrintHostMsg_DidPreviewPage::Param page_param; | 523 PrintHostMsg_DidPreviewPage::Param page_param; |
524 PrintHostMsg_DidPreviewPage::Read(msg, &page_param); | 524 PrintHostMsg_DidPreviewPage::Read(msg, &page_param); |
525 if (page_param.a.page_number == page_number) { | 525 if (get<0>(page_param).page_number == page_number) { |
526 msg_found = true; | 526 msg_found = true; |
527 if (generate_draft_pages) | 527 if (generate_draft_pages) |
528 EXPECT_NE(0U, page_param.a.data_size); | 528 EXPECT_NE(0U, get<0>(page_param).data_size); |
529 else | 529 else |
530 EXPECT_EQ(0U, page_param.a.data_size); | 530 EXPECT_EQ(0U, get<0>(page_param).data_size); |
531 break; | 531 break; |
532 } | 532 } |
533 } | 533 } |
534 } | 534 } |
535 ASSERT_EQ(generate_draft_pages, msg_found); | 535 ASSERT_EQ(generate_draft_pages, msg_found); |
536 } | 536 } |
537 | 537 |
538 void VerifyDefaultPageLayout(int content_width, int content_height, | 538 void VerifyDefaultPageLayout(int content_width, int content_height, |
539 int margin_top, int margin_bottom, | 539 int margin_top, int margin_bottom, |
540 int margin_left, int margin_right, | 540 int margin_left, int margin_right, |
541 bool page_has_print_css) { | 541 bool page_has_print_css) { |
542 const IPC::Message* default_page_layout_msg = | 542 const IPC::Message* default_page_layout_msg = |
543 render_thread_->sink().GetUniqueMessageMatching( | 543 render_thread_->sink().GetUniqueMessageMatching( |
544 PrintHostMsg_DidGetDefaultPageLayout::ID); | 544 PrintHostMsg_DidGetDefaultPageLayout::ID); |
545 bool did_get_default_page_layout_msg = (NULL != default_page_layout_msg); | 545 bool did_get_default_page_layout_msg = (NULL != default_page_layout_msg); |
546 if (did_get_default_page_layout_msg) { | 546 if (did_get_default_page_layout_msg) { |
547 PrintHostMsg_DidGetDefaultPageLayout::Param param; | 547 PrintHostMsg_DidGetDefaultPageLayout::Param param; |
548 PrintHostMsg_DidGetDefaultPageLayout::Read(default_page_layout_msg, | 548 PrintHostMsg_DidGetDefaultPageLayout::Read(default_page_layout_msg, |
549 ¶m); | 549 ¶m); |
550 EXPECT_EQ(content_width, param.a.content_width); | 550 EXPECT_EQ(content_width, get<0>(param).content_width); |
551 EXPECT_EQ(content_height, param.a.content_height); | 551 EXPECT_EQ(content_height, get<0>(param).content_height); |
552 EXPECT_EQ(margin_top, param.a.margin_top); | 552 EXPECT_EQ(margin_top, get<0>(param).margin_top); |
553 EXPECT_EQ(margin_right, param.a.margin_right); | 553 EXPECT_EQ(margin_right, get<0>(param).margin_right); |
554 EXPECT_EQ(margin_left, param.a.margin_left); | 554 EXPECT_EQ(margin_left, get<0>(param).margin_left); |
555 EXPECT_EQ(margin_bottom, param.a.margin_bottom); | 555 EXPECT_EQ(margin_bottom, get<0>(param).margin_bottom); |
556 EXPECT_EQ(page_has_print_css, param.c); | 556 EXPECT_EQ(page_has_print_css, get<2>(param)); |
557 } | 557 } |
558 } | 558 } |
559 | 559 |
560 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest); | 560 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest); |
561 }; | 561 }; |
562 | 562 |
563 #if defined(ENABLE_PRINT_PREVIEW) | 563 #if defined(ENABLE_PRINT_PREVIEW) |
564 TEST_F(PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting) { | 564 TEST_F(PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting) { |
565 LoadHTML(kHelloWorldHTML); | 565 LoadHTML(kHelloWorldHTML); |
566 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); | 566 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 CreatePrintSettingsDictionary(&dict); | 988 CreatePrintSettingsDictionary(&dict); |
989 OnPrintForPrintPreview(dict); | 989 OnPrintForPrintPreview(dict); |
990 | 990 |
991 VerifyPrintFailed(true); | 991 VerifyPrintFailed(true); |
992 VerifyPagesPrinted(false); | 992 VerifyPagesPrinted(false); |
993 } | 993 } |
994 | 994 |
995 #endif // !defined(OS_CHROMEOS) | 995 #endif // !defined(OS_CHROMEOS) |
996 | 996 |
997 } // namespace printing | 997 } // namespace printing |
OLD | NEW |