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

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

Issue 7740005: Print preview not showing if default print is invalid. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Update per code review Created 9 years, 3 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/common/chrome_switches.h" 5 #include "chrome/common/chrome_switches.h"
6 #include "chrome/common/print_messages.h" 6 #include "chrome/common/print_messages.h"
7 #include "chrome/renderer/print_web_view_helper.h" 7 #include "chrome/renderer/print_web_view_helper.h"
8 #include "chrome/test/base/render_view_test.h" 8 #include "chrome/test/base/render_view_test.h"
9 #include "printing/print_job_constants.h" 9 #include "printing/print_job_constants.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 EXPECT_NE(0U, preview_param.a.data_size); 338 EXPECT_NE(0U, preview_param.a.data_size);
339 } 339 }
340 } 340 }
341 341
342 void VerifyPrintFailed(bool did_fail) { 342 void VerifyPrintFailed(bool did_fail) {
343 bool print_failed = (render_thread_.sink().GetUniqueMessageMatching( 343 bool print_failed = (render_thread_.sink().GetUniqueMessageMatching(
344 PrintHostMsg_PrintingFailed::ID) != NULL); 344 PrintHostMsg_PrintingFailed::ID) != NULL);
345 EXPECT_EQ(did_fail, print_failed); 345 EXPECT_EQ(did_fail, print_failed);
346 } 346 }
347 347
348 void VerifyPrintPreviewInvalidPrinterSettings(bool settings_invalid) {
349 bool print_preview_invalid_printer_settings =
350 (render_thread_.sink().GetUniqueMessageMatching(
351 PrintHostMsg_PrintPreviewInvalidPrinterSettings::ID) != NULL);
352 EXPECT_EQ(settings_invalid, print_preview_invalid_printer_settings);
353 }
354
348 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest); 355 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest);
349 }; 356 };
350 357
351 // Tests that print preview work and sending and receiving messages through 358 // Tests that print preview work and sending and receiving messages through
352 // that channel all works. 359 // that channel all works.
353 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { 360 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) {
354 LoadHTML(kHelloWorldHTML); 361 LoadHTML(kHelloWorldHTML);
355 362
356 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); 363 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview();
357 // Fill in some dummy values. 364 // Fill in some dummy values.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { 428 TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) {
422 LoadHTML(kPrintPreviewHTML); 429 LoadHTML(kPrintPreviewHTML);
423 430
424 // An empty dictionary should fail. 431 // An empty dictionary should fail.
425 DictionaryValue empty_dict; 432 DictionaryValue empty_dict;
426 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict); 433 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict);
427 434
428 VerifyPrintFailed(true); 435 VerifyPrintFailed(true);
429 VerifyPagesPrinted(false); 436 VerifyPagesPrinted(false);
430 } 437 }
438
439 // Tests that when default printer has invalid printer settings, print preview
440 // receives error message.
441 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewInvalidDefaultPrinter) {
kmadhusu 2011/08/30 02:11:27 How about? OnPrintPreviewInvalidDefaultPrinter =
arthurhsu 2011/08/30 20:43:03 Done.
442 LoadHTML(kPrintPreviewHTML);
443
444 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview();
445
446 // Set mock printer to provide invalid settings.
447 render_thread_.printer()->UseInvalidSettings();
448 render_thread_.printer()->ResetPrinter();
449
450 // Fill in some dummy values.
451 DictionaryValue dict;
452 CreatePrintSettingsDictionary(&dict);
453 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict);
454
455 // We should have received invalid printer settings from |printer_|.
456 VerifyPrintPreviewInvalidPrinterSettings(true);
457 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining());
kmadhusu 2011/08/30 02:11:27 print_preview_pages_remaining() return 1 because w
arthurhsu 2011/08/30 20:43:03 It should be zero since it can't tell how many pag
458
459 // It should receive the invalid printer settings message only.
460 VerifyPrintPreviewFailed(false);
461
462 VerifyPrintPreviewGenerated(false);
kmadhusu 2011/08/30 02:11:27 nit: Remove the blank line above this statement.
arthurhsu 2011/08/30 20:43:03 Done.
463 }
464
465 TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewInvalidPrinter) {
kmadhusu 2011/08/30 02:11:27 How about? OnPrintForPrintPreviewInvalidPrinter =
arthurhsu 2011/08/30 20:43:03 Done.
466 LoadHTML(kPrintPreviewHTML);
467
468 // Set mock printer to provide invalid settings.
469 render_thread_.printer()->UseInvalidSettings();
470 render_thread_.printer()->ResetPrinter();
kmadhusu 2011/08/30 02:11:27 Is ResetPrinter() required? I think mockprinter is
arthurhsu 2011/08/30 20:43:03 Done.
471
472 // Fill in some dummy values.
473 DictionaryValue dict;
474 CreatePrintSettingsDictionary(&dict);
475 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict);
476
477 VerifyPagesPrinted(false);
478 }
479
431 #endif // !defined(OS_CHROMEOS) 480 #endif // !defined(OS_CHROMEOS)
OLDNEW
« chrome/renderer/mock_printer.h ('K') | « chrome/renderer/print_web_view_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698