Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: components/printing/test/print_web_view_helper_browsertest.cc

Issue 1159553007: Move Tuple to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/printing/common/print_messages.h" 7 #include "components/printing/common/print_messages.h"
8 #include "components/printing/renderer/print_web_view_helper.h" 8 #include "components/printing/renderer/print_web_view_helper.h"
9 #include "components/printing/test/mock_printer.h" 9 #include "components/printing/test/mock_printer.h"
10 #include "components/printing/test/print_mock_render_thread.h" 10 #include "components/printing/test/print_mock_render_thread.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // always print all pages, and there are checks to that effect built into 165 // always print all pages, and there are checks to that effect built into
166 // the print code. 166 // the print code.
167 #else 167 #else
168 const IPC::Message* page_cnt_msg = 168 const IPC::Message* page_cnt_msg =
169 render_thread_->sink().GetUniqueMessageMatching( 169 render_thread_->sink().GetUniqueMessageMatching(
170 PrintHostMsg_DidGetPrintedPagesCount::ID); 170 PrintHostMsg_DidGetPrintedPagesCount::ID);
171 ASSERT_TRUE(page_cnt_msg); 171 ASSERT_TRUE(page_cnt_msg);
172 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param; 172 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param;
173 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg, 173 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg,
174 &post_page_count_param); 174 &post_page_count_param);
175 EXPECT_EQ(count, get<1>(post_page_count_param)); 175 EXPECT_EQ(count, base::get<1>(post_page_count_param));
176 #endif // defined(OS_CHROMEOS) 176 #endif // defined(OS_CHROMEOS)
177 } 177 }
178 178
179 // The renderer should be done calculating the number of rendered pages 179 // The renderer should be done calculating the number of rendered pages
180 // according to the specified settings defined in the mock render thread. 180 // according to the specified settings defined in the mock render thread.
181 // Verify the page count is correct. 181 // Verify the page count is correct.
182 void VerifyPreviewPageCount(int count) { 182 void VerifyPreviewPageCount(int count) {
183 const IPC::Message* page_cnt_msg = 183 const IPC::Message* page_cnt_msg =
184 render_thread_->sink().GetUniqueMessageMatching( 184 render_thread_->sink().GetUniqueMessageMatching(
185 PrintHostMsg_DidGetPreviewPageCount::ID); 185 PrintHostMsg_DidGetPreviewPageCount::ID);
186 ASSERT_TRUE(page_cnt_msg); 186 ASSERT_TRUE(page_cnt_msg);
187 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param; 187 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param;
188 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg, 188 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg,
189 &post_page_count_param); 189 &post_page_count_param);
190 EXPECT_EQ(count, get<0>(post_page_count_param).page_count); 190 EXPECT_EQ(count, base::get<0>(post_page_count_param).page_count);
191 } 191 }
192 192
193 // Verifies whether the pages printed or not. 193 // Verifies whether the pages printed or not.
194 void VerifyPagesPrinted(bool printed) { 194 void VerifyPagesPrinted(bool printed) {
195 #if defined(OS_CHROMEOS) 195 #if defined(OS_CHROMEOS)
196 bool did_print_msg = 196 bool did_print_msg =
197 (render_thread_->sink().GetUniqueMessageMatching( 197 (render_thread_->sink().GetUniqueMessageMatching(
198 PrintHostMsg_TempFileForPrintingWritten::ID) != NULL); 198 PrintHostMsg_TempFileForPrintingWritten::ID) != NULL);
199 ASSERT_EQ(printed, did_print_msg); 199 ASSERT_EQ(printed, did_print_msg);
200 #else 200 #else
201 const IPC::Message* print_msg = 201 const IPC::Message* print_msg =
202 render_thread_->sink().GetUniqueMessageMatching( 202 render_thread_->sink().GetUniqueMessageMatching(
203 PrintHostMsg_DidPrintPage::ID); 203 PrintHostMsg_DidPrintPage::ID);
204 bool did_print_msg = (NULL != print_msg); 204 bool did_print_msg = (NULL != print_msg);
205 ASSERT_EQ(printed, did_print_msg); 205 ASSERT_EQ(printed, did_print_msg);
206 if (printed) { 206 if (printed) {
207 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; 207 PrintHostMsg_DidPrintPage::Param post_did_print_page_param;
208 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); 208 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param);
209 EXPECT_EQ(0, get<0>(post_did_print_page_param).page_number); 209 EXPECT_EQ(0, base::get<0>(post_did_print_page_param).page_number);
210 } 210 }
211 #endif // defined(OS_CHROMEOS) 211 #endif // defined(OS_CHROMEOS)
212 } 212 }
213 213
214 #if defined(ENABLE_BASIC_PRINTING) 214 #if defined(ENABLE_BASIC_PRINTING)
215 void OnPrintPages() { 215 void OnPrintPages() {
216 PrintWebViewHelper::Get(view_)->OnPrintPages(); 216 PrintWebViewHelper::Get(view_)->OnPrintPages();
217 ProcessPendingMessages(); 217 ProcessPendingMessages();
218 } 218 }
219 #endif // ENABLE_BASIC_PRINTING 219 #endif // ENABLE_BASIC_PRINTING
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 536
537 void VerifyPrintPreviewGenerated(bool generated_preview) { 537 void VerifyPrintPreviewGenerated(bool generated_preview) {
538 const IPC::Message* preview_msg = 538 const IPC::Message* preview_msg =
539 render_thread_->sink().GetUniqueMessageMatching( 539 render_thread_->sink().GetUniqueMessageMatching(
540 PrintHostMsg_MetafileReadyForPrinting::ID); 540 PrintHostMsg_MetafileReadyForPrinting::ID);
541 bool did_get_preview_msg = (NULL != preview_msg); 541 bool did_get_preview_msg = (NULL != preview_msg);
542 ASSERT_EQ(generated_preview, did_get_preview_msg); 542 ASSERT_EQ(generated_preview, did_get_preview_msg);
543 if (did_get_preview_msg) { 543 if (did_get_preview_msg) {
544 PrintHostMsg_MetafileReadyForPrinting::Param preview_param; 544 PrintHostMsg_MetafileReadyForPrinting::Param preview_param;
545 PrintHostMsg_MetafileReadyForPrinting::Read(preview_msg, &preview_param); 545 PrintHostMsg_MetafileReadyForPrinting::Read(preview_msg, &preview_param);
546 EXPECT_NE(0, get<0>(preview_param).document_cookie); 546 EXPECT_NE(0, base::get<0>(preview_param).document_cookie);
547 EXPECT_NE(0, get<0>(preview_param).expected_pages_count); 547 EXPECT_NE(0, base::get<0>(preview_param).expected_pages_count);
548 EXPECT_NE(0U, get<0>(preview_param).data_size); 548 EXPECT_NE(0U, base::get<0>(preview_param).data_size);
549 } 549 }
550 } 550 }
551 551
552 void VerifyPrintFailed(bool did_fail) { 552 void VerifyPrintFailed(bool did_fail) {
553 bool print_failed = (render_thread_->sink().GetUniqueMessageMatching( 553 bool print_failed = (render_thread_->sink().GetUniqueMessageMatching(
554 PrintHostMsg_PrintingFailed::ID) != NULL); 554 PrintHostMsg_PrintingFailed::ID) != NULL);
555 EXPECT_EQ(did_fail, print_failed); 555 EXPECT_EQ(did_fail, print_failed);
556 } 556 }
557 557
558 void VerifyPrintPreviewInvalidPrinterSettings(bool settings_invalid) { 558 void VerifyPrintPreviewInvalidPrinterSettings(bool settings_invalid) {
559 bool print_preview_invalid_printer_settings = 559 bool print_preview_invalid_printer_settings =
560 (render_thread_->sink().GetUniqueMessageMatching( 560 (render_thread_->sink().GetUniqueMessageMatching(
561 PrintHostMsg_PrintPreviewInvalidPrinterSettings::ID) != NULL); 561 PrintHostMsg_PrintPreviewInvalidPrinterSettings::ID) != NULL);
562 EXPECT_EQ(settings_invalid, print_preview_invalid_printer_settings); 562 EXPECT_EQ(settings_invalid, print_preview_invalid_printer_settings);
563 } 563 }
564 564
565 // |page_number| is 0-based. 565 // |page_number| is 0-based.
566 void VerifyDidPreviewPage(bool generate_draft_pages, int page_number) { 566 void VerifyDidPreviewPage(bool generate_draft_pages, int page_number) {
567 bool msg_found = false; 567 bool msg_found = false;
568 size_t msg_count = render_thread_->sink().message_count(); 568 size_t msg_count = render_thread_->sink().message_count();
569 for (size_t i = 0; i < msg_count; ++i) { 569 for (size_t i = 0; i < msg_count; ++i) {
570 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); 570 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i);
571 if (msg->type() == PrintHostMsg_DidPreviewPage::ID) { 571 if (msg->type() == PrintHostMsg_DidPreviewPage::ID) {
572 PrintHostMsg_DidPreviewPage::Param page_param; 572 PrintHostMsg_DidPreviewPage::Param page_param;
573 PrintHostMsg_DidPreviewPage::Read(msg, &page_param); 573 PrintHostMsg_DidPreviewPage::Read(msg, &page_param);
574 if (get<0>(page_param).page_number == page_number) { 574 if (base::get<0>(page_param).page_number == page_number) {
575 msg_found = true; 575 msg_found = true;
576 if (generate_draft_pages) 576 if (generate_draft_pages)
577 EXPECT_NE(0U, get<0>(page_param).data_size); 577 EXPECT_NE(0U, base::get<0>(page_param).data_size);
578 else 578 else
579 EXPECT_EQ(0U, get<0>(page_param).data_size); 579 EXPECT_EQ(0U, base::get<0>(page_param).data_size);
580 break; 580 break;
581 } 581 }
582 } 582 }
583 } 583 }
584 ASSERT_EQ(generate_draft_pages, msg_found); 584 ASSERT_EQ(generate_draft_pages, msg_found);
585 } 585 }
586 586
587 void VerifyDefaultPageLayout(int content_width, 587 void VerifyDefaultPageLayout(int content_width,
588 int content_height, 588 int content_height,
589 int margin_top, 589 int margin_top,
590 int margin_bottom, 590 int margin_bottom,
591 int margin_left, 591 int margin_left,
592 int margin_right, 592 int margin_right,
593 bool page_has_print_css) { 593 bool page_has_print_css) {
594 const IPC::Message* default_page_layout_msg = 594 const IPC::Message* default_page_layout_msg =
595 render_thread_->sink().GetUniqueMessageMatching( 595 render_thread_->sink().GetUniqueMessageMatching(
596 PrintHostMsg_DidGetDefaultPageLayout::ID); 596 PrintHostMsg_DidGetDefaultPageLayout::ID);
597 bool did_get_default_page_layout_msg = (NULL != default_page_layout_msg); 597 bool did_get_default_page_layout_msg = (NULL != default_page_layout_msg);
598 if (did_get_default_page_layout_msg) { 598 if (did_get_default_page_layout_msg) {
599 PrintHostMsg_DidGetDefaultPageLayout::Param param; 599 PrintHostMsg_DidGetDefaultPageLayout::Param param;
600 PrintHostMsg_DidGetDefaultPageLayout::Read(default_page_layout_msg, 600 PrintHostMsg_DidGetDefaultPageLayout::Read(default_page_layout_msg,
601 &param); 601 &param);
602 EXPECT_EQ(content_width, get<0>(param).content_width); 602 EXPECT_EQ(content_width, base::get<0>(param).content_width);
603 EXPECT_EQ(content_height, get<0>(param).content_height); 603 EXPECT_EQ(content_height, base::get<0>(param).content_height);
604 EXPECT_EQ(margin_top, get<0>(param).margin_top); 604 EXPECT_EQ(margin_top, base::get<0>(param).margin_top);
605 EXPECT_EQ(margin_right, get<0>(param).margin_right); 605 EXPECT_EQ(margin_right, base::get<0>(param).margin_right);
606 EXPECT_EQ(margin_left, get<0>(param).margin_left); 606 EXPECT_EQ(margin_left, base::get<0>(param).margin_left);
607 EXPECT_EQ(margin_bottom, get<0>(param).margin_bottom); 607 EXPECT_EQ(margin_bottom, base::get<0>(param).margin_bottom);
608 EXPECT_EQ(page_has_print_css, get<2>(param)); 608 EXPECT_EQ(page_has_print_css, base::get<2>(param));
609 } 609 }
610 } 610 }
611 611
612 DISALLOW_COPY_AND_ASSIGN(MAYBE_PrintWebViewHelperPreviewTest); 612 DISALLOW_COPY_AND_ASSIGN(MAYBE_PrintWebViewHelperPreviewTest);
613 }; 613 };
614 614
615 #if defined(ENABLE_PRINT_PREVIEW) 615 #if defined(ENABLE_PRINT_PREVIEW)
616 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting) { 616 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting) {
617 LoadHTML(kHelloWorldHTML); 617 LoadHTML(kHelloWorldHTML);
618 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); 618 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_);
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 CreatePrintSettingsDictionary(&dict); 1042 CreatePrintSettingsDictionary(&dict);
1043 OnPrintForPrintPreview(dict); 1043 OnPrintForPrintPreview(dict);
1044 1044
1045 VerifyPrintFailed(true); 1045 VerifyPrintFailed(true);
1046 VerifyPagesPrinted(false); 1046 VerifyPagesPrinted(false);
1047 } 1047 }
1048 1048
1049 #endif // !defined(OS_CHROMEOS) 1049 #endif // !defined(OS_CHROMEOS)
1050 1050
1051 } // namespace printing 1051 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698