| 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" |
| 11 #include "content/public/renderer/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
| 12 #include "printing/print_job_constants.h" | 12 #include "printing/print_job_constants.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 17 | 18 |
| 18 #if defined(OS_WIN) || defined(OS_MACOSX) | 19 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 19 #include "base/file_util.h" | 20 #include "base/file_util.h" |
| 20 #include "printing/image.h" | 21 #include "printing/image.h" |
| 21 | 22 |
| 22 using WebKit::WebFrame; | 23 using WebKit::WebFrame; |
| 23 using WebKit::WebString; | 24 using WebKit::WebString; |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 namespace printing { | 27 namespace printing { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // A simple web page. | 31 // A simple web page. |
| 31 const char kHelloWorldHTML[] = "<body><p>Hello World!</p></body>"; | 32 const char kHelloWorldHTML[] = "<body><p>Hello World!</p></body>"; |
| 32 | 33 |
| 34 // HTML with 3 pages. |
| 35 const char kMultipageHTML[] = |
| 36 "<html><head><style>" |
| 37 ".break { page-break-after: always; }" |
| 38 "</style></head>" |
| 39 "<body>" |
| 40 "<div class='break'>page1</div>" |
| 41 "<div class='break'>page2</div>" |
| 42 "<div>page3</div>" |
| 43 "</body></html>"; |
| 44 |
| 33 // A simple web page with print page size css. | 45 // A simple web page with print page size css. |
| 34 const char kHTMLWithPageSizeCss[] = | 46 const char kHTMLWithPageSizeCss[] = |
| 35 "<html><head><style>" | 47 "<html><head><style>" |
| 36 "@media print {" | 48 "@media print {" |
| 37 " @page {" | 49 " @page {" |
| 38 " size: 4in 4in;" | 50 " size: 4in 4in;" |
| 39 " }" | 51 " }" |
| 40 "}" | 52 "}" |
| 41 "</style></head>" | 53 "</style></head>" |
| 42 "<body>Lorem Ipsum:" | 54 "<body>Lorem Ipsum:" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 dict->SetInteger(kSettingDuplexMode, SIMPLEX); | 92 dict->SetInteger(kSettingDuplexMode, SIMPLEX); |
| 81 dict->SetInteger(kSettingCopies, 1); | 93 dict->SetInteger(kSettingCopies, 1); |
| 82 dict->SetString(kSettingDeviceName, "dummy"); | 94 dict->SetString(kSettingDeviceName, "dummy"); |
| 83 dict->SetInteger(kPreviewUIID, 4); | 95 dict->SetInteger(kPreviewUIID, 4); |
| 84 dict->SetInteger(kPreviewRequestID, 12345); | 96 dict->SetInteger(kPreviewRequestID, 12345); |
| 85 dict->SetBoolean(kIsFirstRequest, true); | 97 dict->SetBoolean(kIsFirstRequest, true); |
| 86 dict->SetInteger(kSettingMarginsType, DEFAULT_MARGINS); | 98 dict->SetInteger(kSettingMarginsType, DEFAULT_MARGINS); |
| 87 dict->SetBoolean(kSettingPreviewModifiable, false); | 99 dict->SetBoolean(kSettingPreviewModifiable, false); |
| 88 dict->SetBoolean(kSettingHeaderFooterEnabled, false); | 100 dict->SetBoolean(kSettingHeaderFooterEnabled, false); |
| 89 dict->SetBoolean(kSettingGenerateDraftData, true); | 101 dict->SetBoolean(kSettingGenerateDraftData, true); |
| 102 dict->SetBoolean(kSettingShouldPrintBackgrounds, false); |
| 103 dict->SetBoolean(kSettingShouldPrintSelectionOnly, false); |
| 90 } | 104 } |
| 91 | 105 |
| 92 } // namespace | 106 } // namespace |
| 93 | 107 |
| 94 class PrintWebViewHelperTestBase : public ChromeRenderViewTest { | 108 class PrintWebViewHelperTestBase : public ChromeRenderViewTest { |
| 95 public: | 109 public: |
| 96 PrintWebViewHelperTestBase() {} | 110 PrintWebViewHelperTestBase() {} |
| 97 ~PrintWebViewHelperTestBase() {} | 111 ~PrintWebViewHelperTestBase() {} |
| 98 | 112 |
| 99 protected: | 113 protected: |
| 100 // The renderer should be done calculating the number of rendered pages | 114 // The renderer should be done calculating the number of rendered pages |
| 101 // according to the specified settings defined in the mock render thread. | 115 // according to the specified settings defined in the mock render thread. |
| 102 // Verify the page count is correct. | 116 // Verify the page count is correct. |
| 103 void VerifyPageCount(int count) { | 117 void VerifyPageCount(int count) { |
| 104 ProcessPendingMessages(); | |
| 105 #if defined(OS_CHROMEOS) | 118 #if defined(OS_CHROMEOS) |
| 106 // The DidGetPrintedPagesCount message isn't sent on ChromeOS. Right now we | 119 // The DidGetPrintedPagesCount message isn't sent on ChromeOS. Right now we |
| 107 // always print all pages, and there are checks to that effect built into | 120 // always print all pages, and there are checks to that effect built into |
| 108 // the print code. | 121 // the print code. |
| 109 #else | 122 #else |
| 110 const IPC::Message* page_cnt_msg = | 123 const IPC::Message* page_cnt_msg = |
| 111 render_thread_->sink().GetUniqueMessageMatching( | 124 render_thread_->sink().GetUniqueMessageMatching( |
| 112 PrintHostMsg_DidGetPrintedPagesCount::ID); | 125 PrintHostMsg_DidGetPrintedPagesCount::ID); |
| 113 ASSERT_TRUE(page_cnt_msg); | 126 ASSERT_TRUE(page_cnt_msg); |
| 114 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param; | 127 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param; |
| 115 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg, | 128 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg, |
| 116 &post_page_count_param); | 129 &post_page_count_param); |
| 117 EXPECT_EQ(count, post_page_count_param.b); | 130 EXPECT_EQ(count, post_page_count_param.b); |
| 118 #endif // defined(OS_CHROMEOS) | 131 #endif // defined(OS_CHROMEOS) |
| 119 } | 132 } |
| 120 | 133 |
| 134 // The renderer should be done calculating the number of rendered pages |
| 135 // according to the specified settings defined in the mock render thread. |
| 136 // Verify the page count is correct. |
| 137 void VerifyPreviewPageCount(int count) { |
| 138 const IPC::Message* page_cnt_msg = |
| 139 render_thread_->sink().GetUniqueMessageMatching( |
| 140 PrintHostMsg_DidGetPreviewPageCount::ID); |
| 141 ASSERT_TRUE(page_cnt_msg); |
| 142 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param; |
| 143 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg, |
| 144 &post_page_count_param); |
| 145 EXPECT_EQ(count, post_page_count_param.a.page_count); |
| 146 } |
| 147 |
| 121 // Verifies whether the pages printed or not. | 148 // Verifies whether the pages printed or not. |
| 122 void VerifyPagesPrinted(bool printed) { | 149 void VerifyPagesPrinted(bool printed) { |
| 123 ProcessPendingMessages(); | |
| 124 #if defined(OS_CHROMEOS) | 150 #if defined(OS_CHROMEOS) |
| 125 bool did_print_msg = (render_thread_->sink().GetUniqueMessageMatching( | 151 bool did_print_msg = (render_thread_->sink().GetUniqueMessageMatching( |
| 126 PrintHostMsg_TempFileForPrintingWritten::ID) != NULL); | 152 PrintHostMsg_TempFileForPrintingWritten::ID) != NULL); |
| 127 ASSERT_EQ(printed, did_print_msg); | 153 ASSERT_EQ(printed, did_print_msg); |
| 128 #else | 154 #else |
| 129 const IPC::Message* print_msg = | 155 const IPC::Message* print_msg = |
| 130 render_thread_->sink().GetUniqueMessageMatching( | 156 render_thread_->sink().GetUniqueMessageMatching( |
| 131 PrintHostMsg_DidPrintPage::ID); | 157 PrintHostMsg_DidPrintPage::ID); |
| 132 bool did_print_msg = (NULL != print_msg); | 158 bool did_print_msg = (NULL != print_msg); |
| 133 ASSERT_EQ(printed, did_print_msg); | 159 ASSERT_EQ(printed, did_print_msg); |
| 134 if (printed) { | 160 if (printed) { |
| 135 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; | 161 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; |
| 136 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); | 162 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); |
| 137 EXPECT_EQ(0, post_did_print_page_param.a.page_number); | 163 EXPECT_EQ(0, post_did_print_page_param.a.page_number); |
| 138 } | 164 } |
| 139 #endif // defined(OS_CHROMEOS) | 165 #endif // defined(OS_CHROMEOS) |
| 140 } | 166 } |
| 167 void OnPrintPages() { |
| 168 PrintWebViewHelper::Get(view_)->OnPrintPages(); |
| 169 ProcessPendingMessages(); |
| 170 } |
| 141 | 171 |
| 142 void OnPrintPreview(const DictionaryValue& dict) { | 172 void OnPrintPreview(const DictionaryValue& dict) { |
| 143 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); | 173 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); |
| 144 print_web_view_helper->OnInitiatePrintPreview(); | 174 print_web_view_helper->OnInitiatePrintPreview(); |
| 145 print_web_view_helper->OnPrintPreview(dict); | 175 print_web_view_helper->OnPrintPreview(dict); |
| 176 ProcessPendingMessages(); |
| 146 } | 177 } |
| 147 | 178 |
| 148 void OnPrintForPrintPreview(const DictionaryValue& dict) { | 179 void OnPrintForPrintPreview(const DictionaryValue& dict) { |
| 149 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict); | 180 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict); |
| 181 ProcessPendingMessages(); |
| 150 } | 182 } |
| 151 | 183 |
| 152 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase); | 184 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase); |
| 153 }; | 185 }; |
| 154 | 186 |
| 155 class PrintWebViewHelperTest : public PrintWebViewHelperTestBase { | 187 class PrintWebViewHelperTest : public PrintWebViewHelperTestBase { |
| 156 public: | 188 public: |
| 157 PrintWebViewHelperTest() {} | 189 PrintWebViewHelperTest() {} |
| 158 virtual ~PrintWebViewHelperTest() {} | 190 virtual ~PrintWebViewHelperTest() {} |
| 159 | 191 |
| 160 virtual void SetUp() OVERRIDE { | 192 virtual void SetUp() OVERRIDE { |
| 161 ChromeRenderViewTest::SetUp(); | 193 ChromeRenderViewTest::SetUp(); |
| 162 } | 194 } |
| 163 | 195 |
| 164 protected: | 196 protected: |
| 165 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest); | 197 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest); |
| 166 }; | 198 }; |
| 167 | 199 |
| 168 // Tests that printing pages work and sending and receiving messages through | 200 // Tests that printing pages work and sending and receiving messages through |
| 169 // that channel all works. | 201 // that channel all works. |
| 170 TEST_F(PrintWebViewHelperTest, OnPrintPages) { | 202 TEST_F(PrintWebViewHelperTest, OnPrintPages) { |
| 171 LoadHTML(kHelloWorldHTML); | 203 LoadHTML(kHelloWorldHTML); |
| 172 PrintWebViewHelper::Get(view_)->OnPrintPages(); | 204 OnPrintPages(); |
| 173 | 205 |
| 174 VerifyPageCount(1); | 206 VerifyPageCount(1); |
| 175 VerifyPagesPrinted(true); | 207 VerifyPagesPrinted(true); |
| 176 } | 208 } |
| 177 | 209 |
| 178 // Duplicate of OnPrintPagesTest only using javascript to print. | 210 // Duplicate of OnPrintPagesTest only using javascript to print. |
| 179 TEST_F(PrintWebViewHelperTest, PrintWithJavascript) { | 211 TEST_F(PrintWebViewHelperTest, PrintWithJavascript) { |
| 180 // HTML contains a call to window.print() | 212 // HTML contains a call to window.print() |
| 181 LoadHTML(kPrintWithJSHTML); | 213 LoadHTML(kPrintWithJSHTML); |
| 182 | 214 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 EXPECT_FALSE(bounds.IsEmpty()); | 266 EXPECT_FALSE(bounds.IsEmpty()); |
| 235 WebKit::WebMouseEvent mouse_event; | 267 WebKit::WebMouseEvent mouse_event; |
| 236 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 268 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
| 237 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 269 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
| 238 mouse_event.x = bounds.CenterPoint().x(); | 270 mouse_event.x = bounds.CenterPoint().x(); |
| 239 mouse_event.y = bounds.CenterPoint().y(); | 271 mouse_event.y = bounds.CenterPoint().y(); |
| 240 mouse_event.clickCount = 1; | 272 mouse_event.clickCount = 1; |
| 241 SendWebMouseEvent(mouse_event); | 273 SendWebMouseEvent(mouse_event); |
| 242 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 274 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 243 SendWebMouseEvent(mouse_event); | 275 SendWebMouseEvent(mouse_event); |
| 276 ProcessPendingMessages(); |
| 244 | 277 |
| 245 VerifyPageCount(1); | 278 VerifyPageCount(1); |
| 246 VerifyPagesPrinted(true); | 279 VerifyPagesPrinted(true); |
| 247 } | 280 } |
| 248 | 281 |
| 249 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrintingFromPopup) { | 282 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrintingFromPopup) { |
| 250 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); | 283 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); |
| 251 print_web_view_helper->SetScriptedPrintBlocked(true); | 284 print_web_view_helper->SetScriptedPrintBlocked(true); |
| 252 LoadHTML(kPrintWithJSHTML); | 285 LoadHTML(kPrintWithJSHTML); |
| 253 VerifyPagesPrinted(false); | 286 VerifyPagesPrinted(false); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 278 // Find the frame and set it as the focused one. This should mean that that | 311 // Find the frame and set it as the focused one. This should mean that that |
| 279 // the printout should only contain the contents of that frame. | 312 // the printout should only contain the contents of that frame. |
| 280 WebFrame* sub1_frame = | 313 WebFrame* sub1_frame = |
| 281 view_->GetWebView()->findFrameByName(WebString::fromUTF8("sub1")); | 314 view_->GetWebView()->findFrameByName(WebString::fromUTF8("sub1")); |
| 282 ASSERT_TRUE(sub1_frame); | 315 ASSERT_TRUE(sub1_frame); |
| 283 view_->GetWebView()->setFocusedFrame(sub1_frame); | 316 view_->GetWebView()->setFocusedFrame(sub1_frame); |
| 284 ASSERT_NE(view_->GetWebView()->focusedFrame(), | 317 ASSERT_NE(view_->GetWebView()->focusedFrame(), |
| 285 view_->GetWebView()->mainFrame()); | 318 view_->GetWebView()->mainFrame()); |
| 286 | 319 |
| 287 // Initiate printing. | 320 // Initiate printing. |
| 288 PrintWebViewHelper::Get(view_)->OnPrintPages(); | 321 OnPrintPages(); |
| 289 VerifyPagesPrinted(true); | 322 VerifyPagesPrinted(true); |
| 290 | 323 |
| 291 // Verify output through MockPrinter. | 324 // Verify output through MockPrinter. |
| 292 const MockPrinter* printer(chrome_render_thread_->printer()); | 325 const MockPrinter* printer(chrome_render_thread_->printer()); |
| 293 ASSERT_EQ(1, printer->GetPrintedPages()); | 326 ASSERT_EQ(1, printer->GetPrintedPages()); |
| 294 const Image& image1(printer->GetPrintedPage(0)->image()); | 327 const Image& image1(printer->GetPrintedPage(0)->image()); |
| 295 | 328 |
| 296 // TODO(sverrir): Figure out a way to improve this test to actually print | 329 // TODO(sverrir): Figure out a way to improve this test to actually print |
| 297 // only the content of the iframe. Currently image1 will contain the full | 330 // only the content of the iframe. Currently image1 will contain the full |
| 298 // page. | 331 // page. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // hooking up Cairo to read a pdf stream, or accessing the cairo surface in the | 376 // hooking up Cairo to read a pdf stream, or accessing the cairo surface in the |
| 344 // metafile directly. | 377 // metafile directly. |
| 345 #if defined(OS_WIN) || defined(OS_MACOSX) | 378 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 346 TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { | 379 TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { |
| 347 bool baseline = false; | 380 bool baseline = false; |
| 348 | 381 |
| 349 EXPECT_TRUE(chrome_render_thread_->printer() != NULL); | 382 EXPECT_TRUE(chrome_render_thread_->printer() != NULL); |
| 350 for (size_t i = 0; i < arraysize(kTestPages); ++i) { | 383 for (size_t i = 0; i < arraysize(kTestPages); ++i) { |
| 351 // Load an HTML page and print it. | 384 // Load an HTML page and print it. |
| 352 LoadHTML(kTestPages[i].page); | 385 LoadHTML(kTestPages[i].page); |
| 353 PrintWebViewHelper::Get(view_)->OnPrintPages(); | 386 OnPrintPages(); |
| 354 VerifyPagesPrinted(true); | 387 VerifyPagesPrinted(true); |
| 355 | 388 |
| 356 // MockRenderThread::Send() just calls MockRenderThread::OnReceived(). | 389 // MockRenderThread::Send() just calls MockRenderThread::OnReceived(). |
| 357 // So, all IPC messages sent in the above RenderView::OnPrintPages() call | 390 // So, all IPC messages sent in the above RenderView::OnPrintPages() call |
| 358 // has been handled by the MockPrinter object, i.e. this printing job | 391 // has been handled by the MockPrinter object, i.e. this printing job |
| 359 // has been already finished. | 392 // has been already finished. |
| 360 // So, we can start checking the output pages of this printing job. | 393 // So, we can start checking the output pages of this printing job. |
| 361 // Retrieve the number of pages actually printed. | 394 // Retrieve the number of pages actually printed. |
| 362 size_t pages = chrome_render_thread_->printer()->GetPrintedPages(); | 395 size_t pages = chrome_render_thread_->printer()->GetPrintedPages(); |
| 363 EXPECT_EQ(kTestPages[i].printed_pages, pages); | 396 EXPECT_EQ(kTestPages[i].printed_pages, pages); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 if (did_get_preview_msg) { | 469 if (did_get_preview_msg) { |
| 437 PrintHostMsg_MetafileReadyForPrinting::Param preview_param; | 470 PrintHostMsg_MetafileReadyForPrinting::Param preview_param; |
| 438 PrintHostMsg_MetafileReadyForPrinting::Read(preview_msg, &preview_param); | 471 PrintHostMsg_MetafileReadyForPrinting::Read(preview_msg, &preview_param); |
| 439 EXPECT_NE(0, preview_param.a.document_cookie); | 472 EXPECT_NE(0, preview_param.a.document_cookie); |
| 440 EXPECT_NE(0, preview_param.a.expected_pages_count); | 473 EXPECT_NE(0, preview_param.a.expected_pages_count); |
| 441 EXPECT_NE(0U, preview_param.a.data_size); | 474 EXPECT_NE(0U, preview_param.a.data_size); |
| 442 } | 475 } |
| 443 } | 476 } |
| 444 | 477 |
| 445 void VerifyPrintFailed(bool did_fail) { | 478 void VerifyPrintFailed(bool did_fail) { |
| 446 ProcessPendingMessages(); | |
| 447 bool print_failed = (render_thread_->sink().GetUniqueMessageMatching( | 479 bool print_failed = (render_thread_->sink().GetUniqueMessageMatching( |
| 448 PrintHostMsg_PrintingFailed::ID) != NULL); | 480 PrintHostMsg_PrintingFailed::ID) != NULL); |
| 449 EXPECT_EQ(did_fail, print_failed); | 481 EXPECT_EQ(did_fail, print_failed); |
| 450 } | 482 } |
| 451 | 483 |
| 452 void VerifyPrintPreviewInvalidPrinterSettings(bool settings_invalid) { | 484 void VerifyPrintPreviewInvalidPrinterSettings(bool settings_invalid) { |
| 453 bool print_preview_invalid_printer_settings = | 485 bool print_preview_invalid_printer_settings = |
| 454 (render_thread_->sink().GetUniqueMessageMatching( | 486 (render_thread_->sink().GetUniqueMessageMatching( |
| 455 PrintHostMsg_PrintPreviewInvalidPrinterSettings::ID) != NULL); | 487 PrintHostMsg_PrintPreviewInvalidPrinterSettings::ID) != NULL); |
| 456 EXPECT_EQ(settings_invalid, print_preview_invalid_printer_settings); | 488 EXPECT_EQ(settings_invalid, print_preview_invalid_printer_settings); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 | 735 |
| 704 EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); | 736 EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining()); |
| 705 VerifyDefaultPageLayout(748, 568, 21, 23, 21, 23, true); | 737 VerifyDefaultPageLayout(748, 568, 21, 23, 21, 23, true); |
| 706 VerifyPrintPreviewCancelled(false); | 738 VerifyPrintPreviewCancelled(false); |
| 707 VerifyPrintPreviewFailed(false); | 739 VerifyPrintPreviewFailed(false); |
| 708 } | 740 } |
| 709 | 741 |
| 710 // Test to verify that complete metafile is generated for a subset of pages | 742 // Test to verify that complete metafile is generated for a subset of pages |
| 711 // without creating draft pages. | 743 // without creating draft pages. |
| 712 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) { | 744 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) { |
| 713 LoadHTML(kHelloWorldHTML); | 745 LoadHTML(kMultipageHTML); |
| 714 | 746 |
| 715 // Fill in some dummy values. | 747 // Fill in some dummy values. |
| 716 DictionaryValue dict; | 748 DictionaryValue dict; |
| 717 CreatePrintSettingsDictionary(&dict); | 749 CreatePrintSettingsDictionary(&dict); |
| 718 | 750 |
| 719 // Set a page range and update the dictionary to generate only the complete | 751 // Set a page range and update the dictionary to generate only the complete |
| 720 // metafile with the selected pages. Page numbers used in the dictionary | 752 // metafile with the selected pages. Page numbers used in the dictionary |
| 721 // are 1-based. | 753 // are 1-based. |
| 722 DictionaryValue* page_range = new DictionaryValue(); | 754 DictionaryValue* page_range = new DictionaryValue(); |
| 723 page_range->SetInteger(kSettingPageRangeFrom, 1); | 755 page_range->SetInteger(kSettingPageRangeFrom, 2); |
| 724 page_range->SetInteger(kSettingPageRangeTo, 1); | 756 page_range->SetInteger(kSettingPageRangeTo, 3); |
| 725 | 757 |
| 726 ListValue* page_range_array = new ListValue(); | 758 ListValue* page_range_array = new ListValue(); |
| 727 page_range_array->Append(page_range); | 759 page_range_array->Append(page_range); |
| 728 | 760 |
| 729 dict.Set(kSettingPageRange, page_range_array); | 761 dict.Set(kSettingPageRange, page_range_array); |
| 730 dict.SetBoolean(kSettingGenerateDraftData, false); | 762 dict.SetBoolean(kSettingGenerateDraftData, false); |
| 731 | 763 |
| 732 OnPrintPreview(dict); | 764 OnPrintPreview(dict); |
| 733 | 765 |
| 734 // Verify that we did not create the draft metafile for the first page. | |
| 735 VerifyDidPreviewPage(false, 0); | 766 VerifyDidPreviewPage(false, 0); |
| 736 | 767 VerifyDidPreviewPage(false, 1); |
| 768 VerifyDidPreviewPage(false, 2); |
| 769 VerifyPreviewPageCount(3); |
| 737 VerifyPrintPreviewCancelled(false); | 770 VerifyPrintPreviewCancelled(false); |
| 738 VerifyPrintPreviewFailed(false); | 771 VerifyPrintPreviewFailed(false); |
| 739 VerifyPrintPreviewGenerated(true); | 772 VerifyPrintPreviewGenerated(true); |
| 773 VerifyPagesPrinted(false); |
| 774 } |
| 775 |
| 776 // Test to verify that preview generated only for one page. |
| 777 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedText) { |
| 778 LoadHTML(kMultipageHTML); |
| 779 GetMainFrame()->selectRange( |
| 780 WebKit::WebRange::fromDocumentRange(GetMainFrame(), 1, 3)); |
| 781 |
| 782 // Fill in some dummy values. |
| 783 DictionaryValue dict; |
| 784 CreatePrintSettingsDictionary(&dict); |
| 785 dict.SetBoolean(kSettingShouldPrintSelectionOnly, true); |
| 786 |
| 787 OnPrintPreview(dict); |
| 788 |
| 789 VerifyPreviewPageCount(1); |
| 790 VerifyPrintPreviewCancelled(false); |
| 791 VerifyPrintPreviewFailed(false); |
| 792 VerifyPrintPreviewGenerated(true); |
| 740 VerifyPagesPrinted(false); | 793 VerifyPagesPrinted(false); |
| 741 } | 794 } |
| 742 | 795 |
| 743 // Tests that print preview fails and receiving error messages through | 796 // Tests that print preview fails and receiving error messages through |
| 744 // that channel all works. | 797 // that channel all works. |
| 745 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { | 798 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { |
| 746 LoadHTML(kHelloWorldHTML); | 799 LoadHTML(kHelloWorldHTML); |
| 747 | 800 |
| 748 // An empty dictionary should fail. | 801 // An empty dictionary should fail. |
| 749 DictionaryValue empty_dict; | 802 DictionaryValue empty_dict; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 chrome_render_thread_->printer()->ResetPrinter(); | 968 chrome_render_thread_->printer()->ResetPrinter(); |
| 916 VerifyPagesPrinted(false); | 969 VerifyPagesPrinted(false); |
| 917 | 970 |
| 918 // Pretend user will print, should not be throttled. | 971 // Pretend user will print, should not be throttled. |
| 919 chrome_render_thread_->set_print_dialog_user_response(true); | 972 chrome_render_thread_->set_print_dialog_user_response(true); |
| 920 LoadHTML(kPrintWithJSHTML); | 973 LoadHTML(kPrintWithJSHTML); |
| 921 VerifyPagesPrinted(true); | 974 VerifyPagesPrinted(true); |
| 922 } | 975 } |
| 923 | 976 |
| 924 } // namespace printing | 977 } // namespace printing |
| OLD | NEW |