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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 virtual ~PrintWebViewHelperTest() {} | 229 virtual ~PrintWebViewHelperTest() {} |
230 | 230 |
231 virtual void SetUp() OVERRIDE { | 231 virtual void SetUp() OVERRIDE { |
232 ChromeRenderViewTest::SetUp(); | 232 ChromeRenderViewTest::SetUp(); |
233 } | 233 } |
234 | 234 |
235 protected: | 235 protected: |
236 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest); | 236 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest); |
237 }; | 237 }; |
238 | 238 |
| 239 // This tests only for platforms without print preview. |
| 240 #if !defined(ENABLE_FULL_PRINTING) |
| 241 // Tests that the renderer blocks window.print() calls if they occur too |
| 242 // frequently. |
| 243 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { |
| 244 // Pretend user will cancel printing. |
| 245 chrome_render_thread_->set_print_dialog_user_response(false); |
| 246 // Try to print with window.print() a few times. |
| 247 PrintWithJavaScript(); |
| 248 PrintWithJavaScript(); |
| 249 PrintWithJavaScript(); |
| 250 VerifyPagesPrinted(false); |
| 251 |
| 252 // Pretend user will print. (but printing is blocked.) |
| 253 chrome_render_thread_->set_print_dialog_user_response(true); |
| 254 PrintWithJavaScript(); |
| 255 VerifyPagesPrinted(false); |
| 256 |
| 257 // Unblock script initiated printing and verify printing works. |
| 258 PrintWebViewHelper::Get(view_)->scripting_throttler_.Reset(); |
| 259 chrome_render_thread_->printer()->ResetPrinter(); |
| 260 PrintWithJavaScript(); |
| 261 VerifyPageCount(1); |
| 262 VerifyPagesPrinted(true); |
| 263 } |
| 264 |
| 265 // Tests that the renderer always allows window.print() calls if they are user |
| 266 // initiated. |
| 267 TEST_F(PrintWebViewHelperTest, AllowUserOriginatedPrinting) { |
| 268 // Pretend user will cancel printing. |
| 269 chrome_render_thread_->set_print_dialog_user_response(false); |
| 270 // Try to print with window.print() a few times. |
| 271 PrintWithJavaScript(); |
| 272 PrintWithJavaScript(); |
| 273 PrintWithJavaScript(); |
| 274 VerifyPagesPrinted(false); |
| 275 |
| 276 // Pretend user will print. (but printing is blocked.) |
| 277 chrome_render_thread_->set_print_dialog_user_response(true); |
| 278 PrintWithJavaScript(); |
| 279 VerifyPagesPrinted(false); |
| 280 |
| 281 // Try again as if user initiated, without resetting the print count. |
| 282 chrome_render_thread_->printer()->ResetPrinter(); |
| 283 LoadHTML(kPrintOnUserAction); |
| 284 gfx::Size new_size(200, 100); |
| 285 Resize(new_size, gfx::Rect(), false); |
| 286 |
| 287 gfx::Rect bounds = GetElementBounds("print"); |
| 288 EXPECT_FALSE(bounds.IsEmpty()); |
| 289 blink::WebMouseEvent mouse_event; |
| 290 mouse_event.type = blink::WebInputEvent::MouseDown; |
| 291 mouse_event.button = blink::WebMouseEvent::ButtonLeft; |
| 292 mouse_event.x = bounds.CenterPoint().x(); |
| 293 mouse_event.y = bounds.CenterPoint().y(); |
| 294 mouse_event.clickCount = 1; |
| 295 SendWebMouseEvent(mouse_event); |
| 296 mouse_event.type = blink::WebInputEvent::MouseUp; |
| 297 SendWebMouseEvent(mouse_event); |
| 298 ProcessPendingMessages(); |
| 299 |
| 300 VerifyPageCount(1); |
| 301 VerifyPagesPrinted(true); |
| 302 } |
| 303 |
| 304 // Duplicate of OnPrintPagesTest only using javascript to print. |
| 305 TEST_F(PrintWebViewHelperTest, PrintWithJavascript) { |
| 306 PrintWithJavaScript(); |
| 307 |
| 308 VerifyPageCount(1); |
| 309 VerifyPagesPrinted(true); |
| 310 } |
| 311 #endif // !ENABLE_FULL_PRINTING |
| 312 |
239 #if !defined(DISABLE_BASIC_PRINTING) | 313 #if !defined(DISABLE_BASIC_PRINTING) |
240 // Tests that printing pages work and sending and receiving messages through | 314 // Tests that printing pages work and sending and receiving messages through |
241 // that channel all works. | 315 // that channel all works. |
242 TEST_F(PrintWebViewHelperTest, OnPrintPages) { | 316 TEST_F(PrintWebViewHelperTest, OnPrintPages) { |
243 LoadHTML(kHelloWorldHTML); | 317 LoadHTML(kHelloWorldHTML); |
244 OnPrintPages(); | 318 OnPrintPages(); |
245 | 319 |
246 VerifyPageCount(1); | 320 VerifyPageCount(1); |
247 VerifyPagesPrinted(true); | 321 VerifyPagesPrinted(true); |
248 } | 322 } |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 EXPECT_EQ(margin_right, param.a.margin_right); | 554 EXPECT_EQ(margin_right, param.a.margin_right); |
481 EXPECT_EQ(margin_left, param.a.margin_left); | 555 EXPECT_EQ(margin_left, param.a.margin_left); |
482 EXPECT_EQ(margin_bottom, param.a.margin_bottom); | 556 EXPECT_EQ(margin_bottom, param.a.margin_bottom); |
483 EXPECT_EQ(page_has_print_css, param.c); | 557 EXPECT_EQ(page_has_print_css, param.c); |
484 } | 558 } |
485 } | 559 } |
486 | 560 |
487 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest); | 561 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest); |
488 }; | 562 }; |
489 | 563 |
| 564 #if defined(ENABLE_FULL_PRINTING) |
490 TEST_F(PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting) { | 565 TEST_F(PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting) { |
491 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); | 566 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); |
492 print_web_view_helper->SetScriptedPrintBlocked(true); | 567 print_web_view_helper->SetScriptedPrintBlocked(true); |
493 PrintWithJavaScript(); | 568 PrintWithJavaScript(); |
494 VerifyPreviewRequest(false); | 569 VerifyPreviewRequest(false); |
495 | 570 |
496 print_web_view_helper->SetScriptedPrintBlocked(false); | 571 print_web_view_helper->SetScriptedPrintBlocked(false); |
497 PrintWithJavaScript(); | 572 PrintWithJavaScript(); |
498 VerifyPreviewRequest(true); | 573 VerifyPreviewRequest(true); |
499 } | 574 } |
(...skipping 10 matching lines...) Expand all Loading... |
510 mouse_event.button = blink::WebMouseEvent::ButtonLeft; | 585 mouse_event.button = blink::WebMouseEvent::ButtonLeft; |
511 mouse_event.x = bounds.CenterPoint().x(); | 586 mouse_event.x = bounds.CenterPoint().x(); |
512 mouse_event.y = bounds.CenterPoint().y(); | 587 mouse_event.y = bounds.CenterPoint().y(); |
513 mouse_event.clickCount = 1; | 588 mouse_event.clickCount = 1; |
514 SendWebMouseEvent(mouse_event); | 589 SendWebMouseEvent(mouse_event); |
515 mouse_event.type = blink::WebInputEvent::MouseUp; | 590 mouse_event.type = blink::WebInputEvent::MouseUp; |
516 SendWebMouseEvent(mouse_event); | 591 SendWebMouseEvent(mouse_event); |
517 | 592 |
518 VerifyPreviewRequest(true); | 593 VerifyPreviewRequest(true); |
519 } | 594 } |
| 595 #endif // ENABLE_FULL_PRINTING |
520 | 596 |
521 // Tests that print preview work and sending and receiving messages through | 597 // Tests that print preview work and sending and receiving messages through |
522 // that channel all works. | 598 // that channel all works. |
523 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { | 599 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { |
524 LoadHTML(kHelloWorldHTML); | 600 LoadHTML(kHelloWorldHTML); |
525 | 601 |
526 // Fill in some dummy values. | 602 // Fill in some dummy values. |
527 base::DictionaryValue dict; | 603 base::DictionaryValue dict; |
528 CreatePrintSettingsDictionary(&dict); | 604 CreatePrintSettingsDictionary(&dict); |
529 OnPrintPreview(dict); | 605 OnPrintPreview(dict); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 CreatePrintSettingsDictionary(&dict); | 988 CreatePrintSettingsDictionary(&dict); |
913 OnPrintForPrintPreview(dict); | 989 OnPrintForPrintPreview(dict); |
914 | 990 |
915 VerifyPrintFailed(true); | 991 VerifyPrintFailed(true); |
916 VerifyPagesPrinted(false); | 992 VerifyPagesPrinted(false); |
917 } | 993 } |
918 | 994 |
919 #endif // !defined(OS_CHROMEOS) | 995 #endif // !defined(OS_CHROMEOS) |
920 | 996 |
921 } // namespace printing | 997 } // namespace printing |
OLD | NEW |