OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 printing from invalid printer settings fails and receiving error | |
440 // messages through that channel all works. | |
441 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewInvalidSettingsFail) { | |
kmadhusu
2011/08/26 18:50:40
You also need a separate test to verify "OnPrintFo
arthurhsu
2011/08/29 22:53:16
Done.
| |
442 LoadHTML(kPrintPreviewHTML); | |
443 | |
444 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); | |
445 | |
446 // Set mock printer to provide invalid settings. | |
kmadhusu
2011/08/26 18:50:40
The purpose of orig_params and wrong_params is not
arthurhsu
2011/08/29 22:53:16
Done.
| |
447 PrintMsg_Print_Params orig_params, wrong_params; | |
448 | |
449 render_thread_.printer()->GetDefaultPrintSettings(&orig_params); | |
450 render_thread_.printer()->SetBadSettings(true); | |
451 render_thread_.printer()->SetDefaultPrintSettings(wrong_params); | |
452 render_thread_.printer()->ResetPrinter(); | |
453 | |
454 // Fill in some dummy values. | |
455 DictionaryValue dict; | |
456 CreatePrintSettingsDictionary(&dict); | |
457 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict); | |
458 | |
459 VerifyPrintPreviewInvalidPrinterSettings(true); | |
460 VerifyPrintFailed(false); | |
kmadhusu
2011/08/26 18:50:40
We are verifying that the print preview failed.
arthurhsu
2011/08/29 22:53:16
Done.
| |
461 VerifyPagesPrinted(false); | |
462 | |
463 render_thread_.printer()->SetBadSettings(false); | |
464 render_thread_.printer()->SetDefaultPrintSettings(orig_params); | |
465 render_thread_.printer()->ResetPrinter(); | |
466 } | |
467 | |
431 #endif // !defined(OS_CHROMEOS) | 468 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |