| 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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 const char kExampleJobDownloadResponseHeaders[] = | 188 const char kExampleJobDownloadResponseHeaders[] = |
| 189 "Content-Type: Application/PDF\n"; | 189 "Content-Type: Application/PDF\n"; |
| 190 | 190 |
| 191 const char kExamplePrinterName[] = "Example Printer"; | 191 const char kExamplePrinterName[] = "Example Printer"; |
| 192 | 192 |
| 193 const char kExamplePrinterDescription[] = "Example Description"; | 193 const char kExamplePrinterDescription[] = "Example Description"; |
| 194 | 194 |
| 195 // These are functions used to construct the various sample strings. | 195 // These are functions used to construct the various sample strings. |
| 196 std::string JobListResponse(int num_jobs) { | 196 std::string JobListResponse(int num_jobs) { |
| 197 std::string job_objects = ""; | 197 std::string job_objects; |
| 198 for (int i = 0; i < num_jobs; i++) { | 198 for (int i = 0; i < num_jobs; i++) { |
| 199 job_objects = job_objects + StringPrintf(kExampleJobObject, i+1, i+1, i+1, | 199 job_objects = job_objects + StringPrintf(kExampleJobObject, i+1, i+1, i+1, |
| 200 i+1); | 200 i+1); |
| 201 if (i != num_jobs-1) job_objects = job_objects + ","; | 201 if (i != num_jobs-1) job_objects = job_objects + ","; |
| 202 } | 202 } |
| 203 return StringPrintf(kExampleJobListResponse, job_objects.c_str()); | 203 return StringPrintf(kExampleJobListResponse, job_objects.c_str()); |
| 204 } | 204 } |
| 205 | 205 |
| 206 std::string JobListURI(const char* reason) { | 206 std::string JobListURI(const char* reason) { |
| 207 return StringPrintf(kExamplePrinterJobListURI, reason); | 207 return StringPrintf(kExamplePrinterJobListURI, reason); |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 BeginTest(20); | 676 BeginTest(20); |
| 677 } | 677 } |
| 678 | 678 |
| 679 TEST_F(PrinterJobHandlerTest, TicketDownloadFailureTest) { | 679 TEST_F(PrinterJobHandlerTest, TicketDownloadFailureTest) { |
| 680 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), | 680 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), |
| 681 JobListResponse(2), true); | 681 JobListResponse(2), true); |
| 682 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), | 682 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), |
| 683 JobListResponse(2), true); | 683 JobListResponse(2), true); |
| 684 factory_.SetFakeResponse(JobListURI(kJobFetchReasonQueryMore), | 684 factory_.SetFakeResponse(JobListURI(kJobFetchReasonQueryMore), |
| 685 JobListResponse(0), true); | 685 JobListResponse(0), true); |
| 686 factory_.SetFakeResponse(TicketURI(1), "", false); | 686 factory_.SetFakeResponse(TicketURI(1), std::string(), false); |
| 687 | 687 |
| 688 EXPECT_CALL(url_callback_, OnRequestCreate(GURL(TicketURI(1)), _)) | 688 EXPECT_CALL(url_callback_, OnRequestCreate(GURL(TicketURI(1)), _)) |
| 689 .Times(AtLeast(1)); | 689 .Times(AtLeast(1)); |
| 690 | 690 |
| 691 EXPECT_CALL(url_callback_, | 691 EXPECT_CALL(url_callback_, |
| 692 OnRequestCreate(GURL(JobListURI(kJobFetchReasonStartup)), _)) | 692 OnRequestCreate(GURL(JobListURI(kJobFetchReasonStartup)), _)) |
| 693 .Times(AtLeast(1)); | 693 .Times(AtLeast(1)); |
| 694 | 694 |
| 695 EXPECT_CALL(url_callback_, | 695 EXPECT_CALL(url_callback_, |
| 696 OnRequestCreate(GURL(JobListURI(kJobFetchReasonQueryMore)), _)) | 696 OnRequestCreate(GURL(JobListURI(kJobFetchReasonQueryMore)), _)) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 727 EXPECT_CALL(url_callback_, | 727 EXPECT_CALL(url_callback_, |
| 728 OnRequestCreate(GURL(JobListURI(kJobFetchReasonFailure)), _)) | 728 OnRequestCreate(GURL(JobListURI(kJobFetchReasonFailure)), _)) |
| 729 .Times(AtLeast(1)); | 729 .Times(AtLeast(1)); |
| 730 | 730 |
| 731 EXPECT_CALL(url_callback_, | 731 EXPECT_CALL(url_callback_, |
| 732 OnRequestCreate(GURL(JobListURI(kJobFetchReasonRetry)), _)) | 732 OnRequestCreate(GURL(JobListURI(kJobFetchReasonRetry)), _)) |
| 733 .Times(AtLeast(1)); | 733 .Times(AtLeast(1)); |
| 734 | 734 |
| 735 SetUpJobSuccessTest(1); | 735 SetUpJobSuccessTest(1); |
| 736 | 736 |
| 737 factory_.SetFakeResponse(TicketURI(1), "", false); | 737 factory_.SetFakeResponse(TicketURI(1), std::string(), false); |
| 738 | 738 |
| 739 loop_.PostDelayedTask(FROM_HERE, | 739 loop_.PostDelayedTask(FROM_HERE, |
| 740 base::Bind(&net::FakeURLFetcherFactory::SetFakeResponse, | 740 base::Bind(&net::FakeURLFetcherFactory::SetFakeResponse, |
| 741 base::Unretained(&factory_), | 741 base::Unretained(&factory_), |
| 742 TicketURI(1), | 742 TicketURI(1), |
| 743 kExamplePrintTicket, | 743 kExamplePrintTicket, |
| 744 true), | 744 true), |
| 745 base::TimeDelta::FromSeconds(1)); | 745 base::TimeDelta::FromSeconds(1)); |
| 746 | 746 |
| 747 | 747 |
| 748 BeginTest(5); | 748 BeginTest(5); |
| 749 } | 749 } |
| 750 | 750 |
| 751 | 751 |
| 752 // TODO(noamsml): Figure out how to make this test not take ~64-~2048 (depending | 752 // TODO(noamsml): Figure out how to make this test not take ~64-~2048 (depending |
| 753 // constant values) seconds and re-enable it | 753 // constant values) seconds and re-enable it |
| 754 TEST_F(PrinterJobHandlerTest, DISABLED_CompleteFailureTest) { | 754 TEST_F(PrinterJobHandlerTest, DISABLED_CompleteFailureTest) { |
| 755 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), | 755 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), |
| 756 JobListResponse(1), true); | 756 JobListResponse(1), true); |
| 757 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), | 757 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), |
| 758 JobListResponse(1), true); | 758 JobListResponse(1), true); |
| 759 factory_.SetFakeResponse(JobListURI(kJobFetchReasonRetry), | 759 factory_.SetFakeResponse(JobListURI(kJobFetchReasonRetry), |
| 760 JobListResponse(1), true); | 760 JobListResponse(1), true); |
| 761 factory_.SetFakeResponse(ErrorURI(1), StatusResponse(1, "ERROR"), true); | 761 factory_.SetFakeResponse(ErrorURI(1), StatusResponse(1, "ERROR"), true); |
| 762 factory_.SetFakeResponse(TicketURI(1), "", false); | 762 factory_.SetFakeResponse(TicketURI(1), std::string(), false); |
| 763 | 763 |
| 764 EXPECT_CALL(url_callback_, | 764 EXPECT_CALL(url_callback_, |
| 765 OnRequestCreate(GURL(JobListURI(kJobFetchReasonStartup)), _)) | 765 OnRequestCreate(GURL(JobListURI(kJobFetchReasonStartup)), _)) |
| 766 .Times(AtLeast(1)); | 766 .Times(AtLeast(1)); |
| 767 | 767 |
| 768 EXPECT_CALL(url_callback_, | 768 EXPECT_CALL(url_callback_, |
| 769 OnRequestCreate(GURL(JobListURI(kJobFetchReasonFailure)), _)) | 769 OnRequestCreate(GURL(JobListURI(kJobFetchReasonFailure)), _)) |
| 770 .Times(AtLeast(1)); | 770 .Times(AtLeast(1)); |
| 771 | 771 |
| 772 EXPECT_CALL(url_callback_, | 772 EXPECT_CALL(url_callback_, |
| 773 OnRequestCreate(GURL(JobListURI(kJobFetchReasonRetry)), _)) | 773 OnRequestCreate(GURL(JobListURI(kJobFetchReasonRetry)), _)) |
| 774 .Times(AtLeast(1)); | 774 .Times(AtLeast(1)); |
| 775 | 775 |
| 776 EXPECT_CALL(url_callback_, OnRequestCreate(GURL(ErrorURI(1)), _)) | 776 EXPECT_CALL(url_callback_, OnRequestCreate(GURL(ErrorURI(1)), _)) |
| 777 .Times(Exactly(1)) | 777 .Times(Exactly(1)) |
| 778 .WillOnce(InvokeWithoutArgs( | 778 .WillOnce(InvokeWithoutArgs( |
| 779 this, &PrinterJobHandlerTest::MakeJobFetchReturnNoJobs)); | 779 this, &PrinterJobHandlerTest::MakeJobFetchReturnNoJobs)); |
| 780 | 780 |
| 781 EXPECT_CALL(url_callback_, OnRequestCreate(GURL(TicketURI(1)), _)) | 781 EXPECT_CALL(url_callback_, OnRequestCreate(GURL(TicketURI(1)), _)) |
| 782 .Times(AtLeast(kNumRetriesBeforeAbandonJob)); | 782 .Times(AtLeast(kNumRetriesBeforeAbandonJob)); |
| 783 | 783 |
| 784 BeginTest(70); | 784 BeginTest(70); |
| 785 } | 785 } |
| 786 | 786 |
| 787 } // namespace cloud_print | 787 } // namespace cloud_print |
| OLD | NEW |