OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "chrome/browser/local_discovery/privet_http_impl.h" | 7 #include "chrome/browser/local_discovery/privet_http_impl.h" |
8 #include "net/base/host_port_pair.h" | 8 #include "net/base/host_port_pair.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/url_request/test_url_fetcher_factory.h" | 10 #include "net/url_request/test_url_fetcher_factory.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 " { \"content_type\" : \"image/pwg-raster\" }" | 170 " { \"content_type\" : \"image/pwg-raster\" }" |
171 " ]" | 171 " ]" |
172 "}" | 172 "}" |
173 "}"; | 173 "}"; |
174 | 174 |
175 const char kSampleErrorResponsePrinterBusy[] = "{" | 175 const char kSampleErrorResponsePrinterBusy[] = "{" |
176 "\"error\": \"invalid_print_job\"," | 176 "\"error\": \"invalid_print_job\"," |
177 "\"timeout\": 1 " | 177 "\"timeout\": 1 " |
178 "}"; | 178 "}"; |
179 | 179 |
| 180 const char kSampleInvalidDocumentTypeResponse[] = "{" |
| 181 "\"error\" : \"invalid_document_type\"" |
| 182 "}"; |
| 183 |
180 const char kSampleCreatejobResponse[] = "{ \"job_id\": \"1234\" }"; | 184 const char kSampleCreatejobResponse[] = "{ \"job_id\": \"1234\" }"; |
181 | 185 |
182 class MockTestURLFetcherFactoryDelegate | 186 class MockTestURLFetcherFactoryDelegate |
183 : public net::TestURLFetcher::DelegateForTests { | 187 : public net::TestURLFetcher::DelegateForTests { |
184 public: | 188 public: |
185 // Callback issued correspondingly to the call to the |Start()| method. | 189 // Callback issued correspondingly to the call to the |Start()| method. |
186 MOCK_METHOD1(OnRequestStart, void(int fetcher_id)); | 190 MOCK_METHOD1(OnRequestStart, void(int fetcher_id)); |
187 | 191 |
188 // Callback issued correspondingly to the call to |AppendChunkToUpload|. | 192 // Callback issued correspondingly to the call to |AppendChunkToUpload|. |
189 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. | 193 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 897 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
894 | 898 |
895 // TODO(noamsml): Is encoding spaces as pluses standard? | 899 // TODO(noamsml): Is encoding spaces as pluses standard? |
896 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 900 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
897 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 901 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
898 "user=sample%40gmail.com&jobname=Sample+job+name&job_id=1234"), | 902 "user=sample%40gmail.com&jobname=Sample+job+name&job_id=1234"), |
899 "Sample print data", | 903 "Sample print data", |
900 kSampleLocalPrintResponse)); | 904 kSampleLocalPrintResponse)); |
901 }; | 905 }; |
902 | 906 |
| 907 TEST_F(PrivetLocalPrintTest, PDFPrintInvalidDocumentTypeRetry) { |
| 908 local_print_operation_->SetUsername("sample@gmail.com"); |
| 909 local_print_operation_->SetJobname("Sample job name"); |
| 910 local_print_operation_->SetTicket("Sample print ticket"); |
| 911 local_print_operation_->Start(); |
| 912 |
| 913 EXPECT_TRUE(SuccessfulResponseToURL( |
| 914 GURL("http://10.0.0.8:6006/privet/info"), |
| 915 kSampleInfoResponseWithCreatejob)); |
| 916 |
| 917 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingRequestPDFInternal()); |
| 918 |
| 919 EXPECT_TRUE(SuccessfulResponseToURL( |
| 920 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 921 kSampleCapabilitiesResponse)); |
| 922 |
| 923 local_print_operation_->SendData("Sample print data"); |
| 924 |
| 925 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 926 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
| 927 "Sample print ticket", |
| 928 kSampleCreatejobResponse)); |
| 929 |
| 930 EXPECT_CALL(local_print_delegate_, |
| 931 OnPrivetPrintingRequestPWGRasterInternal()); |
| 932 |
| 933 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 934 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 935 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 936 "user=sample%40gmail.com&jobname=Sample+job+name&job_id=1234"), |
| 937 "Sample print data", |
| 938 kSampleInvalidDocumentTypeResponse)); |
| 939 |
| 940 local_print_operation_->SendData("Sample print data2"); |
| 941 |
| 942 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 943 |
| 944 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 945 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 946 "user=sample%40gmail.com&jobname=Sample+job+name&job_id=1234"), |
| 947 "Sample print data2", |
| 948 kSampleLocalPrintResponse)); |
| 949 }; |
| 950 |
903 TEST_F(PrivetLocalPrintTest, LocalPrintRetryOnInvalidJobID) { | 951 TEST_F(PrivetLocalPrintTest, LocalPrintRetryOnInvalidJobID) { |
904 local_print_operation_->SetUsername("sample@gmail.com"); | 952 local_print_operation_->SetUsername("sample@gmail.com"); |
905 local_print_operation_->SetJobname("Sample job name"); | 953 local_print_operation_->SetJobname("Sample job name"); |
906 local_print_operation_->SetTicket("Sample print ticket"); | 954 local_print_operation_->SetTicket("Sample print ticket"); |
907 local_print_operation_->Start(); | 955 local_print_operation_->Start(); |
908 | 956 |
909 EXPECT_TRUE(SuccessfulResponseToURL( | 957 EXPECT_TRUE(SuccessfulResponseToURL( |
910 GURL("http://10.0.0.8:6006/privet/info"), | 958 GURL("http://10.0.0.8:6006/privet/info"), |
911 kSampleInfoResponseWithCreatejob)); | 959 kSampleInfoResponseWithCreatejob)); |
912 | 960 |
(...skipping 20 matching lines...) Expand all Loading... |
933 | 981 |
934 EXPECT_TRUE(SuccessfulResponseToURL( | 982 EXPECT_TRUE(SuccessfulResponseToURL( |
935 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 983 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
936 kSampleCreatejobResponse)); | 984 kSampleCreatejobResponse)); |
937 }; | 985 }; |
938 | 986 |
939 | 987 |
940 } // namespace | 988 } // namespace |
941 | 989 |
942 } // namespace local_discovery | 990 } // namespace local_discovery |
OLD | NEW |