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

Side by Side Diff: chrome/renderer/printing/print_web_view_helper_browsertest.cc

Issue 702603004: Renamed DISABLE_BASIC_PRINTING and ENABLE_FULL_PRINTING. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wed Nov 5 02:31:54 PST 2014 Created 6 years, 1 month 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 "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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, post_did_print_page_param.a.page_number);
188 } 188 }
189 #endif // defined(OS_CHROMEOS) 189 #endif // defined(OS_CHROMEOS)
190 } 190 }
191 191
192 #if !defined(DISABLE_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 // !DISABLE_BASIC_PRINTING 197 #endif // ENABLE_BASIC_PRINTING
198 198
199 void VerifyPreviewRequest(bool requested) { 199 void VerifyPreviewRequest(bool requested) {
200 const IPC::Message* print_msg = 200 const IPC::Message* print_msg =
201 render_thread_->sink().GetUniqueMessageMatching( 201 render_thread_->sink().GetUniqueMessageMatching(
202 PrintHostMsg_SetupScriptedPrintPreview::ID); 202 PrintHostMsg_SetupScriptedPrintPreview::ID);
203 bool did_print_msg = (NULL != print_msg); 203 bool did_print_msg = (NULL != print_msg);
204 ASSERT_EQ(requested, did_print_msg); 204 ASSERT_EQ(requested, did_print_msg);
205 } 205 }
206 206
207 void OnPrintPreview(const base::DictionaryValue& dict) { 207 void OnPrintPreview(const base::DictionaryValue& dict) {
(...skipping 20 matching lines...) Expand all
228 PrintWebViewHelperTest() {} 228 PrintWebViewHelperTest() {}
229 ~PrintWebViewHelperTest() override {} 229 ~PrintWebViewHelperTest() override {}
230 230
231 void SetUp() override { ChromeRenderViewTest::SetUp(); } 231 void SetUp() override { ChromeRenderViewTest::SetUp(); }
232 232
233 protected: 233 protected:
234 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest); 234 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest);
235 }; 235 };
236 236
237 // This tests only for platforms without print preview. 237 // This tests only for platforms without print preview.
238 #if !defined(ENABLE_FULL_PRINTING) 238 #if !defined(ENABLE_PRINT_PREVIEW)
239 // Tests that the renderer blocks window.print() calls if they occur too 239 // Tests that the renderer blocks window.print() calls if they occur too
240 // frequently. 240 // frequently.
241 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { 241 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) {
242 // Pretend user will cancel printing. 242 // Pretend user will cancel printing.
243 chrome_render_thread_->set_print_dialog_user_response(false); 243 chrome_render_thread_->set_print_dialog_user_response(false);
244 // Try to print with window.print() a few times. 244 // Try to print with window.print() a few times.
245 PrintWithJavaScript(); 245 PrintWithJavaScript();
246 PrintWithJavaScript(); 246 PrintWithJavaScript();
247 PrintWithJavaScript(); 247 PrintWithJavaScript();
248 VerifyPagesPrinted(false); 248 VerifyPagesPrinted(false);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 VerifyPagesPrinted(true); 299 VerifyPagesPrinted(true);
300 } 300 }
301 301
302 // Duplicate of OnPrintPagesTest only using javascript to print. 302 // Duplicate of OnPrintPagesTest only using javascript to print.
303 TEST_F(PrintWebViewHelperTest, PrintWithJavascript) { 303 TEST_F(PrintWebViewHelperTest, PrintWithJavascript) {
304 PrintWithJavaScript(); 304 PrintWithJavaScript();
305 305
306 VerifyPageCount(1); 306 VerifyPageCount(1);
307 VerifyPagesPrinted(true); 307 VerifyPagesPrinted(true);
308 } 308 }
309 #endif // !ENABLE_FULL_PRINTING 309 #endif // !ENABLE_PRINT_PREVIEW
310 310
311 #if !defined(DISABLE_BASIC_PRINTING) 311 #if defined(ENABLE_BASIC_PRINTING)
312 // Tests that printing pages work and sending and receiving messages through 312 // Tests that printing pages work and sending and receiving messages through
313 // that channel all works. 313 // that channel all works.
314 TEST_F(PrintWebViewHelperTest, OnPrintPages) { 314 TEST_F(PrintWebViewHelperTest, OnPrintPages) {
315 LoadHTML(kHelloWorldHTML); 315 LoadHTML(kHelloWorldHTML);
316 OnPrintPages(); 316 OnPrintPages();
317 317
318 VerifyPageCount(1); 318 VerifyPageCount(1);
319 VerifyPagesPrinted(true); 319 VerifyPagesPrinted(true);
320 } 320 }
321 #endif // !DISABLE_BASIC_PRINTING 321 #endif // ENABLE_BASIC_PRINTING
322 322
323 #if defined(OS_MACOSX) && !defined(DISABLE_BASIC_PRINTING) 323 #if defined(OS_MACOSX) && defined(ENABLE_BASIC_PRINTING)
324 // TODO(estade): I don't think this test is worth porting to Linux. We will have 324 // TODO(estade): I don't think this test is worth porting to Linux. We will have
325 // to rip out and replace most of the IPC code if we ever plan to improve 325 // to rip out and replace most of the IPC code if we ever plan to improve
326 // printing, and the comment below by sverrir suggests that it doesn't do much 326 // printing, and the comment below by sverrir suggests that it doesn't do much
327 // for us anyway. 327 // for us anyway.
328 TEST_F(PrintWebViewHelperTest, PrintWithIframe) { 328 TEST_F(PrintWebViewHelperTest, PrintWithIframe) {
329 // Document that populates an iframe. 329 // Document that populates an iframe.
330 const char html[] = 330 const char html[] =
331 "<html><body>Lorem Ipsum:" 331 "<html><body>Lorem Ipsum:"
332 "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>" 332 "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>"
333 " document.write(frames['sub1'].name);" 333 " document.write(frames['sub1'].name);"
(...skipping 21 matching lines...) Expand all
355 const MockPrinter* printer(chrome_render_thread_->printer()); 355 const MockPrinter* printer(chrome_render_thread_->printer());
356 ASSERT_EQ(1, printer->GetPrintedPages()); 356 ASSERT_EQ(1, printer->GetPrintedPages());
357 const Image& image1(printer->GetPrintedPage(0)->image()); 357 const Image& image1(printer->GetPrintedPage(0)->image());
358 358
359 // TODO(sverrir): Figure out a way to improve this test to actually print 359 // TODO(sverrir): Figure out a way to improve this test to actually print
360 // only the content of the iframe. Currently image1 will contain the full 360 // only the content of the iframe. Currently image1 will contain the full
361 // page. 361 // page.
362 EXPECT_NE(0, image1.size().width()); 362 EXPECT_NE(0, image1.size().width());
363 EXPECT_NE(0, image1.size().height()); 363 EXPECT_NE(0, image1.size().height());
364 } 364 }
365 #endif // OS_MACOSX && !DISABLE_BASIC_PRINTING 365 #endif // OS_MACOSX && ENABLE_BASIC_PRINTING
366 366
367 // Tests if we can print a page and verify its results. 367 // Tests if we can print a page and verify its results.
368 // This test prints HTML pages into a pseudo printer and check their outputs, 368 // This test prints HTML pages into a pseudo printer and check their outputs,
369 // i.e. a simplified version of the PrintingLayoutTextTest UI test. 369 // i.e. a simplified version of the PrintingLayoutTextTest UI test.
370 namespace { 370 namespace {
371 // Test cases used in this test. 371 // Test cases used in this test.
372 struct TestPageData { 372 struct TestPageData {
373 const char* page; 373 const char* page;
374 size_t printed_pages; 374 size_t printed_pages;
375 int width; 375 int width;
(...skipping 25 matching lines...) Expand all
401 NULL, 401 NULL,
402 }, 402 },
403 }; 403 };
404 #endif // defined(OS_WIN) || defined(OS_MACOSX) 404 #endif // defined(OS_WIN) || defined(OS_MACOSX)
405 } // namespace 405 } // namespace
406 406
407 // TODO(estade): need to port MockPrinter to get this on Linux. This involves 407 // TODO(estade): need to port MockPrinter to get this on Linux. This involves
408 // hooking up Cairo to read a pdf stream, or accessing the cairo surface in the 408 // hooking up Cairo to read a pdf stream, or accessing the cairo surface in the
409 // metafile directly. 409 // metafile directly.
410 // Same for printing via PDF on Windows. 410 // Same for printing via PDF on Windows.
411 #if defined(OS_MACOSX) && !defined(DISABLE_BASIC_PRINTING) 411 #if defined(OS_MACOSX) && defined(ENABLE_BASIC_PRINTING)
412 TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { 412 TEST_F(PrintWebViewHelperTest, PrintLayoutTest) {
413 bool baseline = false; 413 bool baseline = false;
414 414
415 EXPECT_TRUE(chrome_render_thread_->printer() != NULL); 415 EXPECT_TRUE(chrome_render_thread_->printer() != NULL);
416 for (size_t i = 0; i < arraysize(kTestPages); ++i) { 416 for (size_t i = 0; i < arraysize(kTestPages); ++i) {
417 // Load an HTML page and print it. 417 // Load an HTML page and print it.
418 LoadHTML(kTestPages[i].page); 418 LoadHTML(kTestPages[i].page);
419 OnPrintPages(); 419 OnPrintPages();
420 VerifyPagesPrinted(true); 420 VerifyPagesPrinted(true);
421 421
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 base::FilePath source_path; 454 base::FilePath source_path;
455 base::CreateTemporaryFile(&source_path); 455 base::CreateTemporaryFile(&source_path);
456 chrome_render_thread_->printer()->SaveSource(0, source_path); 456 chrome_render_thread_->printer()->SaveSource(0, source_path);
457 457
458 base::FilePath bitmap_path; 458 base::FilePath bitmap_path;
459 base::CreateTemporaryFile(&bitmap_path); 459 base::CreateTemporaryFile(&bitmap_path);
460 chrome_render_thread_->printer()->SaveBitmap(0, bitmap_path); 460 chrome_render_thread_->printer()->SaveBitmap(0, bitmap_path);
461 } 461 }
462 } 462 }
463 } 463 }
464 #endif // OS_MACOSX && !DISABLE_BASIC_PRINTING 464 #endif // OS_MACOSX && ENABLE_BASIC_PRINTING
465 465
466 // These print preview tests do not work on Chrome OS yet. 466 // These print preview tests do not work on Chrome OS yet.
467 #if !defined(OS_CHROMEOS) 467 #if !defined(OS_CHROMEOS)
468 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { 468 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase {
469 public: 469 public:
470 PrintWebViewHelperPreviewTest() {} 470 PrintWebViewHelperPreviewTest() {}
471 ~PrintWebViewHelperPreviewTest() override {} 471 ~PrintWebViewHelperPreviewTest() override {}
472 472
473 protected: 473 protected:
474 void VerifyPrintPreviewCancelled(bool did_cancel) { 474 void VerifyPrintPreviewCancelled(bool did_cancel) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 EXPECT_EQ(margin_right, param.a.margin_right); 553 EXPECT_EQ(margin_right, param.a.margin_right);
554 EXPECT_EQ(margin_left, param.a.margin_left); 554 EXPECT_EQ(margin_left, param.a.margin_left);
555 EXPECT_EQ(margin_bottom, param.a.margin_bottom); 555 EXPECT_EQ(margin_bottom, param.a.margin_bottom);
556 EXPECT_EQ(page_has_print_css, param.c); 556 EXPECT_EQ(page_has_print_css, param.c);
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_FULL_PRINTING) 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_);
567 print_web_view_helper->SetScriptedPrintBlocked(true); 567 print_web_view_helper->SetScriptedPrintBlocked(true);
568 PrintWithJavaScript(); 568 PrintWithJavaScript();
569 VerifyPreviewRequest(false); 569 VerifyPreviewRequest(false);
570 570
571 print_web_view_helper->SetScriptedPrintBlocked(false); 571 print_web_view_helper->SetScriptedPrintBlocked(false);
572 PrintWithJavaScript(); 572 PrintWithJavaScript();
573 VerifyPreviewRequest(true); 573 VerifyPreviewRequest(true);
(...skipping 11 matching lines...) Expand all
585 mouse_event.button = blink::WebMouseEvent::ButtonLeft; 585 mouse_event.button = blink::WebMouseEvent::ButtonLeft;
586 mouse_event.x = bounds.CenterPoint().x(); 586 mouse_event.x = bounds.CenterPoint().x();
587 mouse_event.y = bounds.CenterPoint().y(); 587 mouse_event.y = bounds.CenterPoint().y();
588 mouse_event.clickCount = 1; 588 mouse_event.clickCount = 1;
589 SendWebMouseEvent(mouse_event); 589 SendWebMouseEvent(mouse_event);
590 mouse_event.type = blink::WebInputEvent::MouseUp; 590 mouse_event.type = blink::WebInputEvent::MouseUp;
591 SendWebMouseEvent(mouse_event); 591 SendWebMouseEvent(mouse_event);
592 592
593 VerifyPreviewRequest(true); 593 VerifyPreviewRequest(true);
594 } 594 }
595 #endif // ENABLE_FULL_PRINTING 595 #endif // ENABLE_PRINT_PREVIEW
596 596
597 // Tests that print preview work and sending and receiving messages through 597 // Tests that print preview work and sending and receiving messages through
598 // that channel all works. 598 // that channel all works.
599 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { 599 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) {
600 LoadHTML(kHelloWorldHTML); 600 LoadHTML(kHelloWorldHTML);
601 601
602 // Fill in some dummy values. 602 // Fill in some dummy values.
603 base::DictionaryValue dict; 603 base::DictionaryValue dict;
604 CreatePrintSettingsDictionary(&dict); 604 CreatePrintSettingsDictionary(&dict);
605 OnPrintPreview(dict); 605 OnPrintPreview(dict);
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698