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

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

Issue 488853002: Removed --disable-print-preview switch and policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 235 }
236 236
237 // Duplicate of OnPrintPagesTest only using javascript to print. 237 // Duplicate of OnPrintPagesTest only using javascript to print.
238 TEST_F(PrintWebViewHelperTest, PrintWithJavascript) { 238 TEST_F(PrintWebViewHelperTest, PrintWithJavascript) {
239 PrintWithJavaScript(); 239 PrintWithJavaScript();
240 240
241 VerifyPageCount(1); 241 VerifyPageCount(1);
242 VerifyPagesPrinted(true); 242 VerifyPagesPrinted(true);
243 } 243 }
244 244
245 // Tests that the renderer blocks window.print() calls if they occur too
246 // frequently.
247 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) {
248 // Pretend user will cancel printing.
249 chrome_render_thread_->set_print_dialog_user_response(false);
250 // Try to print with window.print() a few times.
251 PrintWithJavaScript();
252 PrintWithJavaScript();
253 PrintWithJavaScript();
254 VerifyPagesPrinted(false);
255
256 // Pretend user will print. (but printing is blocked.)
257 chrome_render_thread_->set_print_dialog_user_response(true);
258 PrintWithJavaScript();
259 VerifyPagesPrinted(false);
260
261 // Unblock script initiated printing and verify printing works.
262 PrintWebViewHelper::Get(view_)->ResetScriptedPrintCount();
263 chrome_render_thread_->printer()->ResetPrinter();
264 PrintWithJavaScript();
265 VerifyPageCount(1);
266 VerifyPagesPrinted(true);
267 }
268
269 // Tests that the renderer always allows window.print() calls if they are user 245 // Tests that the renderer always allows window.print() calls if they are user
270 // initiated. 246 // initiated.
271 TEST_F(PrintWebViewHelperTest, AllowUserOriginatedPrinting) { 247 TEST_F(PrintWebViewHelperTest, AllowUserOriginatedPrinting) {
272 // Pretend user will cancel printing. 248 // Pretend user will cancel printing.
273 chrome_render_thread_->set_print_dialog_user_response(false); 249 chrome_render_thread_->set_print_dialog_user_response(false);
274 // Try to print with window.print() a few times. 250 // Try to print with window.print() a few times.
275 PrintWithJavaScript(); 251 PrintWithJavaScript();
276 PrintWithJavaScript(); 252 PrintWithJavaScript();
277 PrintWithJavaScript(); 253 PrintWithJavaScript();
278 VerifyPagesPrinted(false); 254 VerifyPagesPrinted(false);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 #endif 436 #endif
461 437
462 // These print preview tests do not work on Chrome OS yet. 438 // These print preview tests do not work on Chrome OS yet.
463 #if !defined(OS_CHROMEOS) 439 #if !defined(OS_CHROMEOS)
464 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { 440 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase {
465 public: 441 public:
466 PrintWebViewHelperPreviewTest() {} 442 PrintWebViewHelperPreviewTest() {}
467 virtual ~PrintWebViewHelperPreviewTest() {} 443 virtual ~PrintWebViewHelperPreviewTest() {}
468 444
469 virtual void SetUp() OVERRIDE { 445 virtual void SetUp() OVERRIDE {
470 // Append the print preview switch before creating the PrintWebViewHelper.
471 CommandLine::ForCurrentProcess()->AppendSwitch(
472 switches::kRendererPrintPreview);
473
474 ChromeRenderViewTest::SetUp(); 446 ChromeRenderViewTest::SetUp();
475 } 447 }
476 448
477 protected: 449 protected:
478 void VerifyPrintPreviewCancelled(bool did_cancel) { 450 void VerifyPrintPreviewCancelled(bool did_cancel) {
479 bool print_preview_cancelled = 451 bool print_preview_cancelled =
480 (render_thread_->sink().GetUniqueMessageMatching( 452 (render_thread_->sink().GetUniqueMessageMatching(
481 PrintHostMsg_PrintPreviewCancelled::ID) != NULL); 453 PrintHostMsg_PrintPreviewCancelled::ID) != NULL);
482 EXPECT_EQ(did_cancel, print_preview_cancelled); 454 EXPECT_EQ(did_cancel, print_preview_cancelled);
483 } 455 }
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 VerifyPagesPrinted(false); 934 VerifyPagesPrinted(false);
963 } 935 }
964 936
965 #endif // !defined(OS_CHROMEOS) 937 #endif // !defined(OS_CHROMEOS)
966 938
967 class PrintWebViewHelperKioskTest : public PrintWebViewHelperTestBase { 939 class PrintWebViewHelperKioskTest : public PrintWebViewHelperTestBase {
968 public: 940 public:
969 PrintWebViewHelperKioskTest() {} 941 PrintWebViewHelperKioskTest() {}
970 virtual ~PrintWebViewHelperKioskTest() {} 942 virtual ~PrintWebViewHelperKioskTest() {}
971 943
972 virtual void SetUp() OVERRIDE {
973 // Append the throttling disable switch before creating the
974 // PrintWebViewHelper.
975 CommandLine::ForCurrentProcess()->AppendSwitch(
976 switches::kDisableScriptedPrintThrottling);
977
978 ChromeRenderViewTest::SetUp();
979 }
980
981 protected: 944 protected:
982 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperKioskTest); 945 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperKioskTest);
983 }; 946 };
984 947
985 // Tests that the switch overrides the throttling that blocks window.print() 948 // Tests that the switch overrides the throttling that blocks window.print()
986 // calls if they occur too frequently. Compare with 949 // calls if they occur too frequently. Compare with
987 // PrintWebViewHelperTest.BlockScriptInitiatedPrinting above. 950 // PrintWebViewHelperTest.BlockScriptInitiatedPrinting above.
988 TEST_F(PrintWebViewHelperKioskTest, DontBlockScriptInitiatedPrinting) { 951 TEST_F(PrintWebViewHelperKioskTest, DontBlockScriptInitiatedPrinting) {
989 // Pretend user will cancel printing. 952 // Pretend user will cancel printing.
990 chrome_render_thread_->set_print_dialog_user_response(false); 953 chrome_render_thread_->set_print_dialog_user_response(false);
991 // Try to print with window.print() a few times. 954 // Try to print with window.print() a few times.
992 PrintWithJavaScript(); 955 PrintWithJavaScript();
993 chrome_render_thread_->printer()->ResetPrinter(); 956 chrome_render_thread_->printer()->ResetPrinter();
994 PrintWithJavaScript(); 957 PrintWithJavaScript();
995 chrome_render_thread_->printer()->ResetPrinter(); 958 chrome_render_thread_->printer()->ResetPrinter();
996 PrintWithJavaScript(); 959 PrintWithJavaScript();
997 chrome_render_thread_->printer()->ResetPrinter(); 960 chrome_render_thread_->printer()->ResetPrinter();
998 VerifyPagesPrinted(false); 961 VerifyPagesPrinted(false);
999 962
1000 // Pretend user will print, should not be throttled. 963 // Pretend user will print, should not be throttled.
1001 chrome_render_thread_->set_print_dialog_user_response(true); 964 chrome_render_thread_->set_print_dialog_user_response(true);
1002 PrintWithJavaScript(); 965 PrintWithJavaScript();
1003 VerifyPagesPrinted(true); 966 VerifyPagesPrinted(true);
1004 } 967 }
1005 968
1006 } // namespace printing 969 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698