OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/md5.h" | 6 #include "base/md5.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "chrome/common/cloud_print/cloud_print_constants.h" | 12 #include "chrome/common/cloud_print/cloud_print_constants.h" |
13 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 13 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
14 #include "chrome/service/cloud_print/cloud_print_token_store.h" | 14 #include "chrome/service/cloud_print/cloud_print_token_store.h" |
15 #include "chrome/service/cloud_print/print_system.h" | 15 #include "chrome/service/cloud_print/print_system.h" |
16 #include "chrome/service/cloud_print/printer_job_handler.h" | 16 #include "chrome/service/cloud_print/printer_job_handler.h" |
17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
18 #include "net/http/http_status_code.h" | |
18 #include "net/url_request/test_url_fetcher_factory.h" | 19 #include "net/url_request/test_url_fetcher_factory.h" |
19 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
20 #include "printing/backend/print_backend.h" | 21 #include "printing/backend/print_backend.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 using ::testing::AtLeast; | 25 using ::testing::AtLeast; |
25 using ::testing::DoAll; | 26 using ::testing::DoAll; |
26 using ::testing::Exactly; | 27 using ::testing::Exactly; |
27 using ::testing::Invoke; | 28 using ::testing::Invoke; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 // This class handles the callback from FakeURLFetcher | 275 // This class handles the callback from FakeURLFetcher |
275 // It is a separate class because callback methods must be | 276 // It is a separate class because callback methods must be |
276 // on RefCounted classes | 277 // on RefCounted classes |
277 | 278 |
278 class TestURLFetcherCallback { | 279 class TestURLFetcherCallback { |
279 public: | 280 public: |
280 scoped_ptr<net::FakeURLFetcher> CreateURLFetcher( | 281 scoped_ptr<net::FakeURLFetcher> CreateURLFetcher( |
281 const GURL& url, | 282 const GURL& url, |
282 net::URLFetcherDelegate* d, | 283 net::URLFetcherDelegate* d, |
283 const std::string& response_data, | 284 const std::string& response_data, |
284 bool success) { | 285 net::HttpStatusCode response_code) { |
285 scoped_ptr<net::FakeURLFetcher> fetcher( | 286 scoped_ptr<net::FakeURLFetcher> fetcher( |
286 new net::FakeURLFetcher(url, d, response_data, success)); | 287 new net::FakeURLFetcher(url, |
288 d, | |
Vitaly Buka (NO REVIEWS)
2013/11/01 21:01:02
According http://google-styleguide.googlecode.com/
Raghu Simha
2013/11/01 21:55:16
After a rebase, this all fits in one line. Fixed.
| |
289 response_data, | |
290 response_code)); | |
287 OnRequestCreate(url, fetcher.get()); | 291 OnRequestCreate(url, fetcher.get()); |
288 return fetcher.Pass(); | 292 return fetcher.Pass(); |
289 } | 293 } |
290 MOCK_METHOD2(OnRequestCreate, | 294 MOCK_METHOD2(OnRequestCreate, |
291 void(const GURL&, net::FakeURLFetcher*)); | 295 void(const GURL&, net::FakeURLFetcher*)); |
292 }; | 296 }; |
293 | 297 |
294 | 298 |
295 class MockPrinterJobHandlerDelegate | 299 class MockPrinterJobHandlerDelegate |
296 : public PrinterJobHandler::Delegate { | 300 : public PrinterJobHandler::Delegate { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 .WillByDefault(Invoke(this, &PrinterJobHandlerTest::GetPrinterInfo)); | 494 .WillByDefault(Invoke(this, &PrinterJobHandlerTest::GetPrinterInfo)); |
491 | 495 |
492 ON_CALL(*print_system_.get(), GetPrinterCapsAndDefaults(_, _)) | 496 ON_CALL(*print_system_.get(), GetPrinterCapsAndDefaults(_, _)) |
493 .WillByDefault(Invoke(this, &PrinterJobHandlerTest::SendCapsAndDefaults)); | 497 .WillByDefault(Invoke(this, &PrinterJobHandlerTest::SendCapsAndDefaults)); |
494 | 498 |
495 CloudPrintURLFetcher::set_factory(&cloud_print_factory_); | 499 CloudPrintURLFetcher::set_factory(&cloud_print_factory_); |
496 } | 500 } |
497 | 501 |
498 void PrinterJobHandlerTest::MakeJobFetchReturnNoJobs() { | 502 void PrinterJobHandlerTest::MakeJobFetchReturnNoJobs() { |
499 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), | 503 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), |
500 JobListResponse(0), true); | 504 JobListResponse(0), net::HTTP_OK); |
501 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), | 505 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), |
502 JobListResponse(0), true); | 506 JobListResponse(0), net::HTTP_OK); |
503 factory_.SetFakeResponse(JobListURI(kJobFetchReasonRetry), | 507 factory_.SetFakeResponse(JobListURI(kJobFetchReasonRetry), |
504 JobListResponse(0), true); | 508 JobListResponse(0), net::HTTP_OK); |
505 } | 509 } |
506 | 510 |
507 void PrinterJobHandlerTest::MessageLoopQuitNowHelper( | 511 void PrinterJobHandlerTest::MessageLoopQuitNowHelper( |
508 base::MessageLoop* message_loop) { | 512 base::MessageLoop* message_loop) { |
509 message_loop->QuitWhenIdle(); | 513 message_loop->QuitWhenIdle(); |
510 } | 514 } |
511 | 515 |
512 void PrinterJobHandlerTest::MessageLoopQuitSoonHelper( | 516 void PrinterJobHandlerTest::MessageLoopQuitSoonHelper( |
513 base::MessageLoop* message_loop) { | 517 base::MessageLoop* message_loop) { |
514 message_loop->message_loop_proxy()->PostTask( | 518 message_loop->message_loop_proxy()->PostTask( |
(...skipping 21 matching lines...) Expand all Loading... | |
536 void PrinterJobHandlerTest::AddMimeHeader(const GURL& url, | 540 void PrinterJobHandlerTest::AddMimeHeader(const GURL& url, |
537 net::FakeURLFetcher* fetcher) { | 541 net::FakeURLFetcher* fetcher) { |
538 scoped_refptr<net::HttpResponseHeaders> download_headers = | 542 scoped_refptr<net::HttpResponseHeaders> download_headers = |
539 new net::HttpResponseHeaders(kExampleJobDownloadResponseHeaders); | 543 new net::HttpResponseHeaders(kExampleJobDownloadResponseHeaders); |
540 fetcher->set_response_headers(download_headers); | 544 fetcher->set_response_headers(download_headers); |
541 } | 545 } |
542 | 546 |
543 | 547 |
544 void PrinterJobHandlerTest::SetUpJobSuccessTest(int job_num) { | 548 void PrinterJobHandlerTest::SetUpJobSuccessTest(int job_num) { |
545 factory_.SetFakeResponse(TicketURI(job_num), | 549 factory_.SetFakeResponse(TicketURI(job_num), |
546 kExamplePrintTicket, true); | 550 kExamplePrintTicket, net::HTTP_OK); |
547 factory_.SetFakeResponse(DownloadURI(job_num), | 551 factory_.SetFakeResponse(DownloadURI(job_num), |
548 kExamplePrintData, true); | 552 kExamplePrintData, net::HTTP_OK); |
549 | 553 |
550 factory_.SetFakeResponse(DoneURI(job_num), | 554 factory_.SetFakeResponse(DoneURI(job_num), |
551 StatusResponse(job_num, "DONE"), | 555 StatusResponse(job_num, "DONE"), |
552 true); | 556 net::HTTP_OK); |
553 factory_.SetFakeResponse(InProgressURI(job_num), | 557 factory_.SetFakeResponse(InProgressURI(job_num), |
554 StatusResponse(job_num, "IN_PROGRESS"), | 558 StatusResponse(job_num, "IN_PROGRESS"), |
555 true); | 559 net::HTTP_OK); |
556 | 560 |
557 // The times requirement is relaxed for the ticket URI | 561 // The times requirement is relaxed for the ticket URI |
558 // in order to accommodate TicketDownloadFailureTest | 562 // in order to accommodate TicketDownloadFailureTest |
559 EXPECT_CALL(url_callback_, OnRequestCreate(TicketURI(job_num), _)) | 563 EXPECT_CALL(url_callback_, OnRequestCreate(TicketURI(job_num), _)) |
560 .Times(AtLeast(1)); | 564 .Times(AtLeast(1)); |
561 | 565 |
562 EXPECT_CALL(url_callback_, OnRequestCreate(DownloadURI(job_num), _)) | 566 EXPECT_CALL(url_callback_, OnRequestCreate(DownloadURI(job_num), _)) |
563 .Times(Exactly(1)) | 567 .Times(Exactly(1)) |
564 .WillOnce(Invoke(this, &PrinterJobHandlerTest::AddMimeHeader)); | 568 .WillOnce(Invoke(this, &PrinterJobHandlerTest::AddMimeHeader)); |
565 | 569 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 | 653 |
650 ON_CALL(*this, ValidatePrintTicket(_, _)). | 654 ON_CALL(*this, ValidatePrintTicket(_, _)). |
651 WillByDefault(Return(true)); | 655 WillByDefault(Return(true)); |
652 }; | 656 }; |
653 | 657 |
654 // This test simulates an end-to-end printing of a document | 658 // This test simulates an end-to-end printing of a document |
655 // but tests only non-failure cases. | 659 // but tests only non-failure cases. |
656 // Disabled - http://crbug.com/184245 | 660 // Disabled - http://crbug.com/184245 |
657 TEST_F(PrinterJobHandlerTest, DISABLED_HappyPathTest) { | 661 TEST_F(PrinterJobHandlerTest, DISABLED_HappyPathTest) { |
658 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), | 662 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), |
659 JobListResponse(1), true); | 663 JobListResponse(1), net::HTTP_OK); |
660 factory_.SetFakeResponse(JobListURI(kJobFetchReasonQueryMore), | 664 factory_.SetFakeResponse(JobListURI(kJobFetchReasonQueryMore), |
661 JobListResponse(0), true); | 665 JobListResponse(0), net::HTTP_OK); |
662 | 666 |
663 EXPECT_CALL(url_callback_, | 667 EXPECT_CALL(url_callback_, |
664 OnRequestCreate(JobListURI(kJobFetchReasonStartup), _)) | 668 OnRequestCreate(JobListURI(kJobFetchReasonStartup), _)) |
665 .Times(Exactly(1)); | 669 .Times(Exactly(1)); |
666 EXPECT_CALL(url_callback_, | 670 EXPECT_CALL(url_callback_, |
667 OnRequestCreate(JobListURI(kJobFetchReasonQueryMore), _)) | 671 OnRequestCreate(JobListURI(kJobFetchReasonQueryMore), _)) |
668 .Times(Exactly(1)); | 672 .Times(Exactly(1)); |
669 | 673 |
670 SetUpJobSuccessTest(1); | 674 SetUpJobSuccessTest(1); |
671 BeginTest(20); | 675 BeginTest(20); |
672 } | 676 } |
673 | 677 |
674 TEST_F(PrinterJobHandlerTest, TicketDownloadFailureTest) { | 678 TEST_F(PrinterJobHandlerTest, TicketDownloadFailureTest) { |
675 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), | 679 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), |
676 JobListResponse(2), true); | 680 JobListResponse(2), net::HTTP_OK); |
677 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), | 681 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), |
678 JobListResponse(2), true); | 682 JobListResponse(2), net::HTTP_OK); |
679 factory_.SetFakeResponse(JobListURI(kJobFetchReasonQueryMore), | 683 factory_.SetFakeResponse(JobListURI(kJobFetchReasonQueryMore), |
680 JobListResponse(0), true); | 684 JobListResponse(0), net::HTTP_OK); |
681 factory_.SetFakeResponse(TicketURI(1), std::string(), false); | 685 factory_.SetFakeResponse(TicketURI(1), |
Vitaly Buka (NO REVIEWS)
2013/11/01 21:01:02
same
Raghu Simha
2013/11/01 21:55:16
Done.
| |
686 std::string(), | |
687 net::HTTP_INTERNAL_SERVER_ERROR); | |
682 | 688 |
683 EXPECT_CALL(url_callback_, OnRequestCreate(TicketURI(1), _)) | 689 EXPECT_CALL(url_callback_, OnRequestCreate(TicketURI(1), _)) |
684 .Times(AtLeast(1)); | 690 .Times(AtLeast(1)); |
685 | 691 |
686 EXPECT_CALL(url_callback_, | 692 EXPECT_CALL(url_callback_, |
687 OnRequestCreate(JobListURI(kJobFetchReasonStartup), _)) | 693 OnRequestCreate(JobListURI(kJobFetchReasonStartup), _)) |
688 .Times(AtLeast(1)); | 694 .Times(AtLeast(1)); |
689 | 695 |
690 EXPECT_CALL(url_callback_, | 696 EXPECT_CALL(url_callback_, |
691 OnRequestCreate(JobListURI(kJobFetchReasonQueryMore), _)) | 697 OnRequestCreate(JobListURI(kJobFetchReasonQueryMore), _)) |
692 .Times(AtLeast(1)); | 698 .Times(AtLeast(1)); |
693 | 699 |
694 EXPECT_CALL(url_callback_, | 700 EXPECT_CALL(url_callback_, |
695 OnRequestCreate(JobListURI(kJobFetchReasonFailure), _)) | 701 OnRequestCreate(JobListURI(kJobFetchReasonFailure), _)) |
696 .Times(AtLeast(1)); | 702 .Times(AtLeast(1)); |
697 | 703 |
698 SetUpJobSuccessTest(2); | 704 SetUpJobSuccessTest(2); |
699 BeginTest(20); | 705 BeginTest(20); |
700 } | 706 } |
701 | 707 |
702 // TODO(noamsml): Figure out how to make this test not take 1 second and | 708 // TODO(noamsml): Figure out how to make this test not take 1 second and |
703 // re-enable it | 709 // re-enable it |
704 TEST_F(PrinterJobHandlerTest, DISABLED_ManyFailureTest) { | 710 TEST_F(PrinterJobHandlerTest, DISABLED_ManyFailureTest) { |
705 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), | 711 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), |
706 JobListResponse(1), true); | 712 JobListResponse(1), net::HTTP_OK); |
707 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), | 713 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), |
708 JobListResponse(1), true); | 714 JobListResponse(1), net::HTTP_OK); |
709 factory_.SetFakeResponse(JobListURI(kJobFetchReasonRetry), | 715 factory_.SetFakeResponse(JobListURI(kJobFetchReasonRetry), |
710 JobListResponse(1), true); | 716 JobListResponse(1), net::HTTP_OK); |
711 factory_.SetFakeResponse(JobListURI(kJobFetchReasonQueryMore), | 717 factory_.SetFakeResponse(JobListURI(kJobFetchReasonQueryMore), |
712 JobListResponse(0), true); | 718 JobListResponse(0), net::HTTP_OK); |
713 | 719 |
714 EXPECT_CALL(url_callback_, | 720 EXPECT_CALL(url_callback_, |
715 OnRequestCreate(JobListURI(kJobFetchReasonStartup), _)) | 721 OnRequestCreate(JobListURI(kJobFetchReasonStartup), _)) |
716 .Times(AtLeast(1)); | 722 .Times(AtLeast(1)); |
717 | 723 |
718 EXPECT_CALL(url_callback_, | 724 EXPECT_CALL(url_callback_, |
719 OnRequestCreate(JobListURI(kJobFetchReasonQueryMore), _)) | 725 OnRequestCreate(JobListURI(kJobFetchReasonQueryMore), _)) |
720 .Times(AtLeast(1)); | 726 .Times(AtLeast(1)); |
721 | 727 |
722 EXPECT_CALL(url_callback_, | 728 EXPECT_CALL(url_callback_, |
723 OnRequestCreate(JobListURI(kJobFetchReasonFailure), _)) | 729 OnRequestCreate(JobListURI(kJobFetchReasonFailure), _)) |
724 .Times(AtLeast(1)); | 730 .Times(AtLeast(1)); |
725 | 731 |
726 EXPECT_CALL(url_callback_, | 732 EXPECT_CALL(url_callback_, |
727 OnRequestCreate(JobListURI(kJobFetchReasonRetry), _)) | 733 OnRequestCreate(JobListURI(kJobFetchReasonRetry), _)) |
728 .Times(AtLeast(1)); | 734 .Times(AtLeast(1)); |
729 | 735 |
730 SetUpJobSuccessTest(1); | 736 SetUpJobSuccessTest(1); |
731 | 737 |
732 factory_.SetFakeResponse(TicketURI(1), std::string(), false); | 738 factory_.SetFakeResponse(TicketURI(1), |
739 std::string(), | |
740 net::HTTP_INTERNAL_SERVER_ERROR); | |
733 | 741 |
734 loop_.PostDelayedTask(FROM_HERE, | 742 loop_.PostDelayedTask(FROM_HERE, |
735 base::Bind(&net::FakeURLFetcherFactory::SetFakeResponse, | 743 base::Bind(&net::FakeURLFetcherFactory::SetFakeResponse, |
736 base::Unretained(&factory_), | 744 base::Unretained(&factory_), |
737 TicketURI(1), | 745 TicketURI(1), |
738 kExamplePrintTicket, | 746 kExamplePrintTicket, |
739 true), | 747 net::HTTP_OK), |
740 base::TimeDelta::FromSeconds(1)); | 748 base::TimeDelta::FromSeconds(1)); |
741 | 749 |
742 | 750 |
743 BeginTest(5); | 751 BeginTest(5); |
744 } | 752 } |
745 | 753 |
746 | 754 |
747 // TODO(noamsml): Figure out how to make this test not take ~64-~2048 (depending | 755 // TODO(noamsml): Figure out how to make this test not take ~64-~2048 (depending |
748 // constant values) seconds and re-enable it | 756 // constant values) seconds and re-enable it |
749 TEST_F(PrinterJobHandlerTest, DISABLED_CompleteFailureTest) { | 757 TEST_F(PrinterJobHandlerTest, DISABLED_CompleteFailureTest) { |
750 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), | 758 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), |
751 JobListResponse(1), true); | 759 JobListResponse(1), net::HTTP_OK); |
752 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), | 760 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), |
753 JobListResponse(1), true); | 761 JobListResponse(1), net::HTTP_OK); |
754 factory_.SetFakeResponse(JobListURI(kJobFetchReasonRetry), | 762 factory_.SetFakeResponse(JobListURI(kJobFetchReasonRetry), |
755 JobListResponse(1), true); | 763 JobListResponse(1), net::HTTP_OK); |
756 factory_.SetFakeResponse(ErrorURI(1), StatusResponse(1, "ERROR"), true); | 764 factory_.SetFakeResponse(ErrorURI(1), |
757 factory_.SetFakeResponse(TicketURI(1), std::string(), false); | 765 StatusResponse(1, "ERROR"), |
Vitaly Buka (NO REVIEWS)
2013/11/01 21:01:02
same
Raghu Simha
2013/11/01 21:55:16
Done here and the line below.
| |
766 net::HTTP_OK); | |
767 factory_.SetFakeResponse(TicketURI(1), | |
768 std::string(), | |
769 net::HTTP_INTERNAL_SERVER_ERROR); | |
758 | 770 |
759 EXPECT_CALL(url_callback_, | 771 EXPECT_CALL(url_callback_, |
760 OnRequestCreate(JobListURI(kJobFetchReasonStartup), _)) | 772 OnRequestCreate(JobListURI(kJobFetchReasonStartup), _)) |
761 .Times(AtLeast(1)); | 773 .Times(AtLeast(1)); |
762 | 774 |
763 EXPECT_CALL(url_callback_, | 775 EXPECT_CALL(url_callback_, |
764 OnRequestCreate(JobListURI(kJobFetchReasonFailure), _)) | 776 OnRequestCreate(JobListURI(kJobFetchReasonFailure), _)) |
765 .Times(AtLeast(1)); | 777 .Times(AtLeast(1)); |
766 | 778 |
767 EXPECT_CALL(url_callback_, | 779 EXPECT_CALL(url_callback_, |
768 OnRequestCreate(JobListURI(kJobFetchReasonRetry), _)) | 780 OnRequestCreate(JobListURI(kJobFetchReasonRetry), _)) |
769 .Times(AtLeast(1)); | 781 .Times(AtLeast(1)); |
770 | 782 |
771 EXPECT_CALL(url_callback_, OnRequestCreate(ErrorURI(1), _)) | 783 EXPECT_CALL(url_callback_, OnRequestCreate(ErrorURI(1), _)) |
772 .Times(Exactly(1)) | 784 .Times(Exactly(1)) |
773 .WillOnce(InvokeWithoutArgs( | 785 .WillOnce(InvokeWithoutArgs( |
774 this, &PrinterJobHandlerTest::MakeJobFetchReturnNoJobs)); | 786 this, &PrinterJobHandlerTest::MakeJobFetchReturnNoJobs)); |
775 | 787 |
776 EXPECT_CALL(url_callback_, OnRequestCreate(TicketURI(1), _)) | 788 EXPECT_CALL(url_callback_, OnRequestCreate(TicketURI(1), _)) |
777 .Times(AtLeast(kNumRetriesBeforeAbandonJob)); | 789 .Times(AtLeast(kNumRetriesBeforeAbandonJob)); |
778 | 790 |
779 BeginTest(70); | 791 BeginTest(70); |
780 } | 792 } |
781 | 793 |
782 } // namespace cloud_print | 794 } // namespace cloud_print |
OLD | NEW |