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 "chrome/common/chrome_switches.h" | 6 #include "chrome/common/chrome_switches.h" |
7 #include "chrome/common/print_messages.h" | 7 #include "chrome/common/print_messages.h" |
8 #include "chrome/renderer/mock_printer.h" | 8 #include "chrome/renderer/mock_printer.h" |
9 #include "chrome/renderer/printing/print_web_view_helper.h" | 9 #include "chrome/renderer/printing/print_web_view_helper.h" |
10 #include "chrome/test/base/chrome_render_view_test.h" | 10 #include "chrome/test/base/chrome_render_view_test.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 // A simple web page with print page size css. | 45 // A simple web page with print page size css. |
46 const char kHTMLWithPageSizeCss[] = | 46 const char kHTMLWithPageSizeCss[] = |
47 "<html><head><style>" | 47 "<html><head><style>" |
48 "@media print {" | 48 "@media print {" |
49 " @page {" | 49 " @page {" |
50 " size: 4in 4in;" | 50 " size: 4in 4in;" |
51 " }" | 51 " }" |
52 "}" | 52 "}" |
53 "</style></head>" | 53 "</style></head>" |
54 "<body>Lorem Ipsum:" | 54 "<body>Lorem Ipsum:<p>" |
55 "</body></html>"; | 55 "</body></html>"; |
56 | 56 |
57 // A simple web page with print page layout css. | 57 // A simple web page with print page layout css. |
58 const char kHTMLWithLandscapePageCss[] = | 58 const char kHTMLWithLandscapePageCss[] = |
59 "<html><head><style>" | 59 "<html><head><style>" |
60 "@media print {" | 60 "@media print {" |
61 " @page {" | 61 " @page {" |
62 " size: landscape;" | 62 " size: landscape;" |
63 " }" | 63 " }" |
64 "}" | 64 "}" |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 LoadHTML(kHTMLWithPageSizeCss); | 662 LoadHTML(kHTMLWithPageSizeCss); |
663 | 663 |
664 // Fill in some dummy values. | 664 // Fill in some dummy values. |
665 base::DictionaryValue dict; | 665 base::DictionaryValue dict; |
666 CreatePrintSettingsDictionary(&dict); | 666 CreatePrintSettingsDictionary(&dict); |
667 dict.SetBoolean(kSettingPrintToPDF, false); | 667 dict.SetBoolean(kSettingPrintToPDF, false); |
668 dict.SetInteger(kSettingMarginsType, DEFAULT_MARGINS); | 668 dict.SetInteger(kSettingMarginsType, DEFAULT_MARGINS); |
669 OnPrintPreview(dict); | 669 OnPrintPreview(dict); |
670 | 670 |
671 EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); | 671 EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); |
672 VerifyDefaultPageLayout(288, 288, 252, 252, 162, 162, true); | 672 VerifyDefaultPageLayout(216, 216, 288, 288, 198, 198, true); |
673 VerifyPrintPreviewCancelled(false); | 673 VerifyPrintPreviewCancelled(false); |
674 VerifyPrintPreviewFailed(false); | 674 VerifyPrintPreviewFailed(false); |
675 VerifyPrintPreviewGenerated(true); | 675 VerifyPrintPreviewGenerated(true); |
676 } | 676 } |
677 | 677 |
678 // Test to verify that print preview workflow scale the html page contents to | 678 // Test to verify that print preview workflow scale the html page contents to |
679 // fit the page size. | 679 // fit the page size. |
680 TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewShrinkToFitPage) { | 680 TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewShrinkToFitPage) { |
681 // A simple web page with print margins css. | 681 // A simple web page with print margins css. |
682 const char kHTMLWithPageCss[] = | 682 const char kHTMLWithPageCss[] = |
683 "<html><head><style>" | 683 "<html><head><style>" |
684 "@media print {" | 684 "@media print {" |
685 " @page {" | 685 " @page {" |
686 " size: 15in 17in;" | 686 " size: 15in 17in;" |
687 " }" | 687 " }" |
688 "}" | 688 "}" |
689 "</style></head>" | 689 "</style></head>" |
690 "<body>Lorem Ipsum:" | 690 "<body>Lorem Ipsum:<p>" |
691 "</body></html>"; | 691 "</body></html>"; |
692 LoadHTML(kHTMLWithPageCss); | 692 LoadHTML(kHTMLWithPageCss); |
693 | 693 |
694 // Fill in some dummy values. | 694 // Fill in some dummy values. |
695 base::DictionaryValue dict; | 695 base::DictionaryValue dict; |
696 CreatePrintSettingsDictionary(&dict); | 696 CreatePrintSettingsDictionary(&dict); |
697 dict.SetBoolean(kSettingPrintToPDF, false); | 697 dict.SetBoolean(kSettingPrintToPDF, false); |
698 dict.SetInteger(kSettingMarginsType, DEFAULT_MARGINS); | 698 dict.SetInteger(kSettingMarginsType, DEFAULT_MARGINS); |
699 OnPrintPreview(dict); | 699 OnPrintPreview(dict); |
700 | 700 |
701 EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); | 701 EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); |
702 VerifyDefaultPageLayout(612, 693, 49, 50, 0, 0, true); | 702 VerifyDefaultPageLayout(571, 652, 69, 71, 20, 21, true); |
703 VerifyPrintPreviewCancelled(false); | 703 VerifyPrintPreviewCancelled(false); |
704 VerifyPrintPreviewFailed(false); | 704 VerifyPrintPreviewFailed(false); |
705 } | 705 } |
706 | 706 |
707 // Test to verify that print preview workflow honor the orientation settings | 707 // Test to verify that print preview workflow honor the orientation settings |
708 // specified in css. | 708 // specified in css. |
709 TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewHonorsOrientationCss) { | 709 TEST_F(PrintWebViewHelperPreviewTest, PrintPreviewHonorsOrientationCss) { |
710 LoadHTML(kHTMLWithLandscapePageCss); | 710 LoadHTML(kHTMLWithLandscapePageCss); |
711 | 711 |
712 // Fill in some dummy values. | 712 // Fill in some dummy values. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 chrome_render_thread_->printer()->ResetPrinter(); | 969 chrome_render_thread_->printer()->ResetPrinter(); |
970 VerifyPagesPrinted(false); | 970 VerifyPagesPrinted(false); |
971 | 971 |
972 // Pretend user will print, should not be throttled. | 972 // Pretend user will print, should not be throttled. |
973 chrome_render_thread_->set_print_dialog_user_response(true); | 973 chrome_render_thread_->set_print_dialog_user_response(true); |
974 PrintWithJavaScript(); | 974 PrintWithJavaScript(); |
975 VerifyPagesPrinted(true); | 975 VerifyPagesPrinted(true); |
976 } | 976 } |
977 | 977 |
978 } // namespace printing | 978 } // namespace printing |
OLD | NEW |