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/json/json_reader.h" | 6 #include "base/json/json_reader.h" |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "chrome/browser/local_discovery/privet_http_impl.h" | 9 #include "chrome/browser/local_discovery/privet_http_impl.h" |
10 #include "net/base/host_port_pair.h" | 10 #include "net/base/host_port_pair.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 #include "net/url_request/test_url_fetcher_factory.h" | 12 #include "net/url_request/test_url_fetcher_factory.h" |
13 #include "net/url_request/url_request_test_util.h" | 13 #include "net/url_request/url_request_test_util.h" |
14 #include "printing/pwg_raster_settings.h" | 14 #include "printing/pwg_raster_settings.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
| 18 #if defined(ENABLE_FULL_PRINTING) |
| 19 #include "chrome/browser/local_discovery/pwg_raster_converter.h" |
| 20 #endif // ENABLE_FULL_PRINTING |
| 21 |
18 using testing::StrictMock; | 22 using testing::StrictMock; |
19 using testing::NiceMock; | 23 using testing::NiceMock; |
20 | 24 |
21 namespace local_discovery { | 25 namespace local_discovery { |
22 | 26 |
23 namespace { | 27 namespace { |
24 | 28 |
25 const char kSampleInfoResponse[] = "{" | 29 const char kSampleInfoResponse[] = "{" |
26 " \"version\": \"1.0\"," | 30 " \"version\": \"1.0\"," |
27 " \"name\": \"Common printer\"," | 31 " \"name\": \"Common printer\"," |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 " \"support_url\": \"http://support.google.com/cloudprint/?hl=en\"," | 73 " \"support_url\": \"http://support.google.com/cloudprint/?hl=en\"," |
70 " \"update_url\": \"http://support.google.com/cloudprint/?hl=en\"," | 74 " \"update_url\": \"http://support.google.com/cloudprint/?hl=en\"," |
71 " \"x-privet-token\": \"SampleTokenForTesting\"," | 75 " \"x-privet-token\": \"SampleTokenForTesting\"," |
72 " \"api\": [" | 76 " \"api\": [" |
73 " \"/privet/accesstoken\"," | 77 " \"/privet/accesstoken\"," |
74 " \"/privet/capabilities\"," | 78 " \"/privet/capabilities\"," |
75 " \"/privet/printer/submitdoc\"," | 79 " \"/privet/printer/submitdoc\"," |
76 " ]" | 80 " ]" |
77 "}"; | 81 "}"; |
78 | 82 |
79 const char kSampleInfoResponseWithCreatejob[] = "{" | |
80 " \"version\": \"1.0\"," | |
81 " \"name\": \"Common printer\"," | |
82 " \"description\": \"Printer connected through Chrome connector\"," | |
83 " \"url\": \"https://www.google.com/cloudprint\"," | |
84 " \"type\": [" | |
85 " \"printer\"" | |
86 " ]," | |
87 " \"id\": \"\"," | |
88 " \"device_state\": \"idle\"," | |
89 " \"connection_state\": \"online\"," | |
90 " \"manufacturer\": \"Google\"," | |
91 " \"model\": \"Google Chrome\"," | |
92 " \"serial_number\": \"1111-22222-33333-4444\"," | |
93 " \"firmware\": \"24.0.1312.52\"," | |
94 " \"uptime\": 600," | |
95 " \"setup_url\": \"http://support.google.com/\"," | |
96 " \"support_url\": \"http://support.google.com/cloudprint/?hl=en\"," | |
97 " \"update_url\": \"http://support.google.com/cloudprint/?hl=en\"," | |
98 " \"x-privet-token\": \"SampleTokenForTesting\"," | |
99 " \"api\": [" | |
100 " \"/privet/accesstoken\"," | |
101 " \"/privet/capabilities\"," | |
102 " \"/privet/printer/createjob\"," | |
103 " \"/privet/printer/submitdoc\"," | |
104 " ]" | |
105 "}"; | |
106 | |
107 const char kSampleRegisterStartResponse[] = "{" | 83 const char kSampleRegisterStartResponse[] = "{" |
108 "\"user\": \"example@google.com\"," | 84 "\"user\": \"example@google.com\"," |
109 "\"action\": \"start\"" | 85 "\"action\": \"start\"" |
110 "}"; | 86 "}"; |
111 | 87 |
112 const char kSampleRegisterGetClaimTokenResponse[] = "{" | 88 const char kSampleRegisterGetClaimTokenResponse[] = "{" |
113 " \"action\": \"getClaimToken\"," | 89 " \"action\": \"getClaimToken\"," |
114 " \"user\": \"example@google.com\"," | 90 " \"user\": \"example@google.com\"," |
115 " \"token\": \"MySampleToken\"," | 91 " \"token\": \"MySampleToken\"," |
116 " \"claim_url\": \"https://domain.com/SoMeUrL\"" | 92 " \"claim_url\": \"https://domain.com/SoMeUrL\"" |
(...skipping 14 matching lines...) Expand all Loading... |
131 const char kSampleRegisterErrorPermanent[] = | 107 const char kSampleRegisterErrorPermanent[] = |
132 "{ \"error\": \"user_cancel\" }"; | 108 "{ \"error\": \"user_cancel\" }"; |
133 | 109 |
134 const char kSampleInfoResponseBadJson[] = "{"; | 110 const char kSampleInfoResponseBadJson[] = "{"; |
135 | 111 |
136 const char kSampleRegisterCancelResponse[] = "{" | 112 const char kSampleRegisterCancelResponse[] = "{" |
137 "\"user\": \"example@google.com\"," | 113 "\"user\": \"example@google.com\"," |
138 "\"action\": \"cancel\"" | 114 "\"action\": \"cancel\"" |
139 "}"; | 115 "}"; |
140 | 116 |
141 const char kSampleLocalPrintResponse[] = "{" | |
142 "\"job_id\": \"123\"," | |
143 "\"expires_in\": 500," | |
144 "\"job_type\": \"application/pdf\"," | |
145 "\"job_size\": 16," | |
146 "\"job_name\": \"Sample job name\"," | |
147 "}"; | |
148 | |
149 const char kSampleCapabilitiesResponse[] = "{" | 117 const char kSampleCapabilitiesResponse[] = "{" |
150 "\"version\" : \"1.0\"," | 118 "\"version\" : \"1.0\"," |
151 "\"printer\" : {" | 119 "\"printer\" : {" |
152 " \"supported_content_type\" : [" | 120 " \"supported_content_type\" : [" |
153 " { \"content_type\" : \"application/pdf\" }," | 121 " { \"content_type\" : \"application/pdf\" }," |
154 " { \"content_type\" : \"image/pwg-raster\" }" | 122 " { \"content_type\" : \"image/pwg-raster\" }" |
155 " ]" | 123 " ]" |
156 "}" | 124 "}" |
157 "}"; | 125 "}"; |
158 | 126 |
| 127 #if defined(ENABLE_FULL_PRINTING) |
| 128 const char kSampleInfoResponseWithCreatejob[] = "{" |
| 129 " \"version\": \"1.0\"," |
| 130 " \"name\": \"Common printer\"," |
| 131 " \"description\": \"Printer connected through Chrome connector\"," |
| 132 " \"url\": \"https://www.google.com/cloudprint\"," |
| 133 " \"type\": [" |
| 134 " \"printer\"" |
| 135 " ]," |
| 136 " \"id\": \"\"," |
| 137 " \"device_state\": \"idle\"," |
| 138 " \"connection_state\": \"online\"," |
| 139 " \"manufacturer\": \"Google\"," |
| 140 " \"model\": \"Google Chrome\"," |
| 141 " \"serial_number\": \"1111-22222-33333-4444\"," |
| 142 " \"firmware\": \"24.0.1312.52\"," |
| 143 " \"uptime\": 600," |
| 144 " \"setup_url\": \"http://support.google.com/\"," |
| 145 " \"support_url\": \"http://support.google.com/cloudprint/?hl=en\"," |
| 146 " \"update_url\": \"http://support.google.com/cloudprint/?hl=en\"," |
| 147 " \"x-privet-token\": \"SampleTokenForTesting\"," |
| 148 " \"api\": [" |
| 149 " \"/privet/accesstoken\"," |
| 150 " \"/privet/capabilities\"," |
| 151 " \"/privet/printer/createjob\"," |
| 152 " \"/privet/printer/submitdoc\"," |
| 153 " ]" |
| 154 "}"; |
| 155 |
| 156 const char kSampleLocalPrintResponse[] = "{" |
| 157 "\"job_id\": \"123\"," |
| 158 "\"expires_in\": 500," |
| 159 "\"job_type\": \"application/pdf\"," |
| 160 "\"job_size\": 16," |
| 161 "\"job_name\": \"Sample job name\"," |
| 162 "}"; |
| 163 |
159 const char kSampleCapabilitiesResponsePWGOnly[] = "{" | 164 const char kSampleCapabilitiesResponsePWGOnly[] = "{" |
160 "\"version\" : \"1.0\"," | 165 "\"version\" : \"1.0\"," |
161 "\"printer\" : {" | 166 "\"printer\" : {" |
162 " \"supported_content_type\" : [" | 167 " \"supported_content_type\" : [" |
163 " { \"content_type\" : \"image/pwg-raster\" }" | 168 " { \"content_type\" : \"image/pwg-raster\" }" |
164 " ]" | 169 " ]" |
165 "}" | 170 "}" |
166 "}"; | |
167 | |
168 const char kSampleCapabilitiesResponseWithAnyMimetype[] = "{" | |
169 "\"version\" : \"1.0\"," | |
170 "\"printer\" : {" | |
171 " \"supported_content_type\" : [" | |
172 " { \"content_type\" : \"*/*\" }," | |
173 " { \"content_type\" : \"image/pwg-raster\" }" | |
174 " ]" | |
175 "}" | |
176 "}"; | 171 "}"; |
177 | 172 |
178 const char kSampleErrorResponsePrinterBusy[] = "{" | 173 const char kSampleErrorResponsePrinterBusy[] = "{" |
179 "\"error\": \"invalid_print_job\"," | 174 "\"error\": \"invalid_print_job\"," |
180 "\"timeout\": 1 " | 175 "\"timeout\": 1 " |
181 "}"; | 176 "}"; |
182 | 177 |
183 const char kSampleInvalidDocumentTypeResponse[] = "{" | 178 const char kSampleInvalidDocumentTypeResponse[] = "{" |
184 "\"error\" : \"invalid_document_type\"" | 179 "\"error\" : \"invalid_document_type\"" |
185 "}"; | 180 "}"; |
186 | 181 |
187 const char kSampleCreatejobResponse[] = "{ \"job_id\": \"1234\" }"; | 182 const char kSampleCreatejobResponse[] = "{ \"job_id\": \"1234\" }"; |
188 | 183 |
| 184 const char kSampleCapabilitiesResponseWithAnyMimetype[] = "{" |
| 185 "\"version\" : \"1.0\"," |
| 186 "\"printer\" : {" |
| 187 " \"supported_content_type\" : [" |
| 188 " { \"content_type\" : \"*/*\" }," |
| 189 " { \"content_type\" : \"image/pwg-raster\" }" |
| 190 " ]" |
| 191 "}" |
| 192 "}"; |
| 193 |
189 const char kSampleCJT[] = "{ \"version\" : \"1.0\" }"; | 194 const char kSampleCJT[] = "{ \"version\" : \"1.0\" }"; |
190 | 195 |
191 const char kSampleCapabilitiesResponsePWGSettings[] = | 196 const char kSampleCapabilitiesResponsePWGSettings[] = |
192 "{" | 197 "{" |
193 "\"version\" : \"1.0\"," | 198 "\"version\" : \"1.0\"," |
194 "\"printer\" : {" | 199 "\"printer\" : {" |
195 " \"pwg_raster_config\" : {" | 200 " \"pwg_raster_config\" : {" |
196 " \"document_sheet_back\" : \"MANUAL_TUMBLE\"," | 201 " \"document_sheet_back\" : \"MANUAL_TUMBLE\"," |
197 " \"reverse_order_streaming\": true" | 202 " \"reverse_order_streaming\": true" |
198 " }," | 203 " }," |
199 " \"supported_content_type\" : [" | 204 " \"supported_content_type\" : [" |
200 " { \"content_type\" : \"image/pwg-raster\" }" | 205 " { \"content_type\" : \"image/pwg-raster\" }" |
201 " ]" | 206 " ]" |
202 "}" | 207 "}" |
203 "}"; | 208 "}"; |
204 | 209 |
205 const char kSampleCJTDuplex[] = | 210 const char kSampleCJTDuplex[] = |
206 "{" | 211 "{" |
207 "\"version\" : \"1.0\"," | 212 "\"version\" : \"1.0\"," |
208 "\"print\": { \"duplex\": {\"type\": \"SHORT_EDGE\"} }" | 213 "\"print\": { \"duplex\": {\"type\": \"SHORT_EDGE\"} }" |
209 "}"; | 214 "}"; |
| 215 #endif // ENABLE_FULL_PRINTING |
210 | 216 |
211 // Return the representation of the given JSON that would be outputted by | 217 // Return the representation of the given JSON that would be outputted by |
212 // JSONWriter. This ensures the same JSON values are represented by the same | 218 // JSONWriter. This ensures the same JSON values are represented by the same |
213 // string. | 219 // string. |
214 std::string NormalizeJson(const std::string& json) { | 220 std::string NormalizeJson(const std::string& json) { |
215 std::string result = json; | 221 std::string result = json; |
216 scoped_ptr<base::Value> value(base::JSONReader::Read(result)); | 222 scoped_ptr<base::Value> value(base::JSONReader::Read(result)); |
217 DCHECK(value); | 223 DCHECK(value); |
218 base::JSONWriter::Write(value.get(), &result); | 224 base::JSONWriter::Write(value.get(), &result); |
219 return result; | 225 return result; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 MOCK_METHOD0(OnPrivetPrintingDoneInternal, void()); | 428 MOCK_METHOD0(OnPrivetPrintingDoneInternal, void()); |
423 | 429 |
424 virtual void OnPrivetPrintingError( | 430 virtual void OnPrivetPrintingError( |
425 const PrivetLocalPrintOperation* print_operation, int http_code) { | 431 const PrivetLocalPrintOperation* print_operation, int http_code) { |
426 OnPrivetPrintingErrorInternal(http_code); | 432 OnPrivetPrintingErrorInternal(http_code); |
427 } | 433 } |
428 | 434 |
429 MOCK_METHOD1(OnPrivetPrintingErrorInternal, void(int http_code)); | 435 MOCK_METHOD1(OnPrivetPrintingErrorInternal, void(int http_code)); |
430 }; | 436 }; |
431 | 437 |
432 // A note on PWG raster conversion: The PWG raster converter used simply | |
433 // converts strings to file paths based on them by appending "test.pdf", since | |
434 // it's easier to test that way. Instead of using a mock, we simply check if the | |
435 // request is uploading a file that is based on this pattern. | |
436 class FakePWGRasterConverter : public PWGRasterConverter { | |
437 public: | |
438 FakePWGRasterConverter() { | |
439 } | |
440 | |
441 virtual ~FakePWGRasterConverter() { | |
442 } | |
443 | |
444 virtual void Start(base::RefCountedMemory* data, | |
445 const printing::PdfRenderSettings& conversion_settings, | |
446 const printing::PwgRasterSettings& bitmap_settings, | |
447 const ResultCallback& callback) OVERRIDE { | |
448 bitmap_settings_ = bitmap_settings; | |
449 std::string data_str(data->front_as<char>(), data->size()); | |
450 callback.Run(true, base::FilePath().AppendASCII(data_str + "test.pdf")); | |
451 } | |
452 | |
453 const printing::PwgRasterSettings& bitmap_settings() { | |
454 return bitmap_settings_; | |
455 } | |
456 | |
457 private: | |
458 printing::PwgRasterSettings bitmap_settings_; | |
459 }; | |
460 | |
461 class PrivetInfoTest : public PrivetHTTPTest { | 438 class PrivetInfoTest : public PrivetHTTPTest { |
462 public: | 439 public: |
463 PrivetInfoTest() {} | 440 PrivetInfoTest() {} |
464 | 441 |
465 virtual ~PrivetInfoTest() {} | 442 virtual ~PrivetInfoTest() {} |
466 | 443 |
467 virtual void SetUp() OVERRIDE { | 444 virtual void SetUp() OVERRIDE { |
468 info_operation_ = privet_client_->CreateInfoOperation( | 445 info_operation_ = privet_client_->CreateInfoOperation( |
469 info_callback_.callback()); | 446 info_callback_.callback()); |
470 } | 447 } |
(...skipping 11 matching lines...) Expand all Loading... |
482 EXPECT_EQ(GURL("http://10.0.0.8:6006/privet/info"), | 459 EXPECT_EQ(GURL("http://10.0.0.8:6006/privet/info"), |
483 fetcher->GetOriginalURL()); | 460 fetcher->GetOriginalURL()); |
484 | 461 |
485 fetcher->SetResponseString(kSampleInfoResponse); | 462 fetcher->SetResponseString(kSampleInfoResponse); |
486 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, | 463 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, |
487 net::OK)); | 464 net::OK)); |
488 fetcher->set_response_code(200); | 465 fetcher->set_response_code(200); |
489 | 466 |
490 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); | 467 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); |
491 fetcher->delegate()->OnURLFetchComplete(fetcher); | 468 fetcher->delegate()->OnURLFetchComplete(fetcher); |
492 }; | 469 } |
493 | 470 |
494 TEST_F(PrivetInfoTest, InfoFailureHTTP) { | 471 TEST_F(PrivetInfoTest, InfoFailureHTTP) { |
495 info_operation_->Start(); | 472 info_operation_->Start(); |
496 | 473 |
497 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); | 474 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); |
498 ASSERT_TRUE(fetcher != NULL); | 475 ASSERT_TRUE(fetcher != NULL); |
499 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, | 476 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, |
500 net::OK)); | 477 net::OK)); |
501 fetcher->set_response_code(404); | 478 fetcher->set_response_code(404); |
502 | 479 |
503 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); | 480 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); |
504 fetcher->delegate()->OnURLFetchComplete(fetcher); | 481 fetcher->delegate()->OnURLFetchComplete(fetcher); |
505 }; | 482 } |
506 | 483 |
507 class PrivetRegisterTest : public PrivetHTTPTest { | 484 class PrivetRegisterTest : public PrivetHTTPTest { |
508 public: | 485 public: |
509 PrivetRegisterTest() { | 486 PrivetRegisterTest() { |
510 } | 487 } |
511 virtual ~PrivetRegisterTest() { | 488 virtual ~PrivetRegisterTest() { |
512 } | 489 } |
513 | 490 |
514 virtual void SetUp() OVERRIDE { | 491 virtual void SetUp() OVERRIDE { |
515 info_operation_ = privet_client_->CreateInfoOperation( | 492 info_operation_ = privet_client_->CreateInfoOperation( |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 | 696 |
720 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); | 697 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); |
721 | 698 |
722 EXPECT_TRUE(SuccessfulResponseToURL( | 699 EXPECT_TRUE(SuccessfulResponseToURL( |
723 GURL("http://10.0.0.8:6006/privet/capabilities"), | 700 GURL("http://10.0.0.8:6006/privet/capabilities"), |
724 kSampleCapabilitiesResponse)); | 701 kSampleCapabilitiesResponse)); |
725 | 702 |
726 std::string version; | 703 std::string version; |
727 EXPECT_TRUE(capabilities_callback_.value()->GetString("version", &version)); | 704 EXPECT_TRUE(capabilities_callback_.value()->GetString("version", &version)); |
728 EXPECT_EQ("1.0", version); | 705 EXPECT_EQ("1.0", version); |
729 }; | 706 } |
730 | 707 |
731 TEST_F(PrivetCapabilitiesTest, CacheToken) { | 708 TEST_F(PrivetCapabilitiesTest, CacheToken) { |
732 capabilities_operation_->Start(); | 709 capabilities_operation_->Start(); |
733 | 710 |
734 EXPECT_TRUE(SuccessfulResponseToURL( | 711 EXPECT_TRUE(SuccessfulResponseToURL( |
735 GURL("http://10.0.0.8:6006/privet/info"), | 712 GURL("http://10.0.0.8:6006/privet/info"), |
736 kSampleInfoResponse)); | 713 kSampleInfoResponse)); |
737 | 714 |
738 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); | 715 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); |
739 | 716 |
740 EXPECT_TRUE(SuccessfulResponseToURL( | 717 EXPECT_TRUE(SuccessfulResponseToURL( |
741 GURL("http://10.0.0.8:6006/privet/capabilities"), | 718 GURL("http://10.0.0.8:6006/privet/capabilities"), |
742 kSampleCapabilitiesResponse)); | 719 kSampleCapabilitiesResponse)); |
743 | 720 |
744 capabilities_operation_ = privet_client_->CreateCapabilitiesOperation( | 721 capabilities_operation_ = privet_client_->CreateCapabilitiesOperation( |
745 capabilities_callback_.callback()); | 722 capabilities_callback_.callback()); |
746 | 723 |
747 capabilities_operation_->Start(); | 724 capabilities_operation_->Start(); |
748 | 725 |
749 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); | 726 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); |
750 | 727 |
751 EXPECT_TRUE(SuccessfulResponseToURL( | 728 EXPECT_TRUE(SuccessfulResponseToURL( |
752 GURL("http://10.0.0.8:6006/privet/capabilities"), | 729 GURL("http://10.0.0.8:6006/privet/capabilities"), |
753 kSampleCapabilitiesResponse)); | 730 kSampleCapabilitiesResponse)); |
754 }; | 731 } |
755 | 732 |
756 TEST_F(PrivetCapabilitiesTest, BadToken) { | 733 TEST_F(PrivetCapabilitiesTest, BadToken) { |
757 capabilities_operation_->Start(); | 734 capabilities_operation_->Start(); |
758 | 735 |
759 EXPECT_TRUE(SuccessfulResponseToURL( | 736 EXPECT_TRUE(SuccessfulResponseToURL( |
760 GURL("http://10.0.0.8:6006/privet/info"), | 737 GURL("http://10.0.0.8:6006/privet/info"), |
761 kSampleInfoResponse)); | 738 kSampleInfoResponse)); |
762 | 739 |
763 EXPECT_TRUE(SuccessfulResponseToURL( | 740 EXPECT_TRUE(SuccessfulResponseToURL( |
764 GURL("http://10.0.0.8:6006/privet/capabilities"), | 741 GURL("http://10.0.0.8:6006/privet/capabilities"), |
765 kSampleXPrivetErrorResponse)); | 742 kSampleXPrivetErrorResponse)); |
766 | 743 |
767 EXPECT_TRUE(SuccessfulResponseToURL( | 744 EXPECT_TRUE(SuccessfulResponseToURL( |
768 GURL("http://10.0.0.8:6006/privet/info"), | 745 GURL("http://10.0.0.8:6006/privet/info"), |
769 kSampleInfoResponse)); | 746 kSampleInfoResponse)); |
770 | 747 |
771 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); | 748 EXPECT_CALL(capabilities_callback_, OnPrivetJSONDoneInternal()); |
772 | 749 |
773 EXPECT_TRUE(SuccessfulResponseToURL( | 750 EXPECT_TRUE(SuccessfulResponseToURL( |
774 GURL("http://10.0.0.8:6006/privet/capabilities"), | 751 GURL("http://10.0.0.8:6006/privet/capabilities"), |
775 kSampleCapabilitiesResponse)); | 752 kSampleCapabilitiesResponse)); |
| 753 } |
| 754 |
| 755 #if defined(ENABLE_FULL_PRINTING) |
| 756 // A note on PWG raster conversion: The PWG raster converter used simply |
| 757 // converts strings to file paths based on them by appending "test.pdf", since |
| 758 // it's easier to test that way. Instead of using a mock, we simply check if the |
| 759 // request is uploading a file that is based on this pattern. |
| 760 class FakePWGRasterConverter : public PWGRasterConverter { |
| 761 public: |
| 762 FakePWGRasterConverter() { |
| 763 } |
| 764 |
| 765 virtual ~FakePWGRasterConverter() { |
| 766 } |
| 767 |
| 768 virtual void Start(base::RefCountedMemory* data, |
| 769 const printing::PdfRenderSettings& conversion_settings, |
| 770 const printing::PwgRasterSettings& bitmap_settings, |
| 771 const ResultCallback& callback) OVERRIDE { |
| 772 bitmap_settings_ = bitmap_settings; |
| 773 std::string data_str(data->front_as<char>(), data->size()); |
| 774 callback.Run(true, base::FilePath().AppendASCII(data_str + "test.pdf")); |
| 775 } |
| 776 |
| 777 const printing::PwgRasterSettings& bitmap_settings() { |
| 778 return bitmap_settings_; |
| 779 } |
| 780 |
| 781 private: |
| 782 printing::PwgRasterSettings bitmap_settings_; |
776 }; | 783 }; |
777 | 784 |
778 class PrivetLocalPrintTest : public PrivetHTTPTest { | 785 class PrivetLocalPrintTest : public PrivetHTTPTest { |
779 public: | 786 public: |
780 PrivetLocalPrintTest() {} | 787 PrivetLocalPrintTest() {} |
781 | 788 |
782 virtual ~PrivetLocalPrintTest() {} | 789 virtual ~PrivetLocalPrintTest() {} |
783 | 790 |
784 virtual void SetUp() OVERRIDE { | 791 virtual void SetUp() OVERRIDE { |
785 PrivetURLFetcher::ResetTokenMapForTests(); | 792 PrivetURLFetcher::ResetTokenMapForTests(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 | 832 |
826 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 833 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
827 | 834 |
828 // TODO(noamsml): Is encoding spaces as pluses standard? | 835 // TODO(noamsml): Is encoding spaces as pluses standard? |
829 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 836 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
830 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 837 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
831 "client_name=Chrome&user_name=sample%40gmail.com&" | 838 "client_name=Chrome&user_name=sample%40gmail.com&" |
832 "job_name=Sample+job+name"), | 839 "job_name=Sample+job+name"), |
833 "Sample print data", | 840 "Sample print data", |
834 kSampleLocalPrintResponse)); | 841 kSampleLocalPrintResponse)); |
835 }; | 842 } |
836 | 843 |
837 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithAnyMimetype) { | 844 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithAnyMimetype) { |
838 local_print_operation_->SetUsername("sample@gmail.com"); | 845 local_print_operation_->SetUsername("sample@gmail.com"); |
839 local_print_operation_->SetJobname("Sample job name"); | 846 local_print_operation_->SetJobname("Sample job name"); |
840 local_print_operation_->SetData( | 847 local_print_operation_->SetData( |
841 RefCountedBytesFromString("Sample print data")); | 848 RefCountedBytesFromString("Sample print data")); |
842 local_print_operation_->SetCapabilities( | 849 local_print_operation_->SetCapabilities( |
843 kSampleCapabilitiesResponseWithAnyMimetype); | 850 kSampleCapabilitiesResponseWithAnyMimetype); |
844 local_print_operation_->Start(); | 851 local_print_operation_->Start(); |
845 | 852 |
846 EXPECT_TRUE(SuccessfulResponseToURL( | 853 EXPECT_TRUE(SuccessfulResponseToURL( |
847 GURL("http://10.0.0.8:6006/privet/info"), | 854 GURL("http://10.0.0.8:6006/privet/info"), |
848 kSampleInfoResponse)); | 855 kSampleInfoResponse)); |
849 | 856 |
850 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), | 857 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), |
851 kSampleInfoResponse)); | 858 kSampleInfoResponse)); |
852 | 859 |
853 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 860 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
854 | 861 |
855 // TODO(noamsml): Is encoding spaces as pluses standard? | 862 // TODO(noamsml): Is encoding spaces as pluses standard? |
856 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 863 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
857 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 864 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
858 "client_name=Chrome&user_name=sample%40gmail.com&" | 865 "client_name=Chrome&user_name=sample%40gmail.com&" |
859 "job_name=Sample+job+name"), | 866 "job_name=Sample+job+name"), |
860 "Sample print data", | 867 "Sample print data", |
861 kSampleLocalPrintResponse)); | 868 kSampleLocalPrintResponse)); |
862 }; | 869 } |
863 | 870 |
864 TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrint) { | 871 TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrint) { |
865 local_print_operation_->SetUsername("sample@gmail.com"); | 872 local_print_operation_->SetUsername("sample@gmail.com"); |
866 local_print_operation_->SetJobname("Sample job name"); | 873 local_print_operation_->SetJobname("Sample job name"); |
867 local_print_operation_->SetData( | 874 local_print_operation_->SetData( |
868 RefCountedBytesFromString("path/to/")); | 875 RefCountedBytesFromString("path/to/")); |
869 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponsePWGOnly); | 876 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponsePWGOnly); |
870 local_print_operation_->Start(); | 877 local_print_operation_->Start(); |
871 | 878 |
872 EXPECT_TRUE(SuccessfulResponseToURL( | 879 EXPECT_TRUE(SuccessfulResponseToURL( |
(...skipping 10 matching lines...) Expand all Loading... |
883 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 890 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
884 "client_name=Chrome&user_name=sample%40gmail.com" | 891 "client_name=Chrome&user_name=sample%40gmail.com" |
885 "&job_name=Sample+job+name"), | 892 "&job_name=Sample+job+name"), |
886 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), | 893 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), |
887 kSampleLocalPrintResponse)); | 894 kSampleLocalPrintResponse)); |
888 | 895 |
889 EXPECT_EQ(printing::TRANSFORM_NORMAL, | 896 EXPECT_EQ(printing::TRANSFORM_NORMAL, |
890 pwg_converter_->bitmap_settings().odd_page_transform); | 897 pwg_converter_->bitmap_settings().odd_page_transform); |
891 EXPECT_FALSE(pwg_converter_->bitmap_settings().rotate_all_pages); | 898 EXPECT_FALSE(pwg_converter_->bitmap_settings().rotate_all_pages); |
892 EXPECT_FALSE(pwg_converter_->bitmap_settings().reverse_page_order); | 899 EXPECT_FALSE(pwg_converter_->bitmap_settings().reverse_page_order); |
893 }; | 900 } |
894 | 901 |
895 TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrintDuplex) { | 902 TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrintDuplex) { |
896 local_print_operation_->SetUsername("sample@gmail.com"); | 903 local_print_operation_->SetUsername("sample@gmail.com"); |
897 local_print_operation_->SetJobname("Sample job name"); | 904 local_print_operation_->SetJobname("Sample job name"); |
898 local_print_operation_->SetData(RefCountedBytesFromString("path/to/")); | 905 local_print_operation_->SetData(RefCountedBytesFromString("path/to/")); |
899 local_print_operation_->SetTicket(kSampleCJTDuplex); | 906 local_print_operation_->SetTicket(kSampleCJTDuplex); |
900 local_print_operation_->SetCapabilities( | 907 local_print_operation_->SetCapabilities( |
901 kSampleCapabilitiesResponsePWGSettings); | 908 kSampleCapabilitiesResponsePWGSettings); |
902 local_print_operation_->Start(); | 909 local_print_operation_->Start(); |
903 | 910 |
(...skipping 16 matching lines...) Expand all Loading... |
920 "http://10.0.0.8:6006/privet/printer/submitdoc?" | 927 "http://10.0.0.8:6006/privet/printer/submitdoc?" |
921 "client_name=Chrome&user_name=sample%40gmail.com" | 928 "client_name=Chrome&user_name=sample%40gmail.com" |
922 "&job_name=Sample+job+name&job_id=1234"), | 929 "&job_name=Sample+job+name&job_id=1234"), |
923 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), | 930 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), |
924 kSampleLocalPrintResponse)); | 931 kSampleLocalPrintResponse)); |
925 | 932 |
926 EXPECT_EQ(printing::TRANSFORM_ROTATE_180, | 933 EXPECT_EQ(printing::TRANSFORM_ROTATE_180, |
927 pwg_converter_->bitmap_settings().odd_page_transform); | 934 pwg_converter_->bitmap_settings().odd_page_transform); |
928 EXPECT_FALSE(pwg_converter_->bitmap_settings().rotate_all_pages); | 935 EXPECT_FALSE(pwg_converter_->bitmap_settings().rotate_all_pages); |
929 EXPECT_TRUE(pwg_converter_->bitmap_settings().reverse_page_order); | 936 EXPECT_TRUE(pwg_converter_->bitmap_settings().reverse_page_order); |
930 }; | 937 } |
931 | 938 |
932 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithCreatejob) { | 939 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithCreatejob) { |
933 local_print_operation_->SetUsername("sample@gmail.com"); | 940 local_print_operation_->SetUsername("sample@gmail.com"); |
934 local_print_operation_->SetJobname("Sample job name"); | 941 local_print_operation_->SetJobname("Sample job name"); |
935 local_print_operation_->SetTicket(kSampleCJT); | 942 local_print_operation_->SetTicket(kSampleCJT); |
936 local_print_operation_->SetData( | 943 local_print_operation_->SetData( |
937 RefCountedBytesFromString("Sample print data")); | 944 RefCountedBytesFromString("Sample print data")); |
938 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); | 945 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); |
939 local_print_operation_->Start(); | 946 local_print_operation_->Start(); |
940 | 947 |
(...skipping 11 matching lines...) Expand all Loading... |
952 | 959 |
953 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 960 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
954 | 961 |
955 // TODO(noamsml): Is encoding spaces as pluses standard? | 962 // TODO(noamsml): Is encoding spaces as pluses standard? |
956 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 963 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
957 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 964 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
958 "client_name=Chrome&user_name=sample%40gmail.com&" | 965 "client_name=Chrome&user_name=sample%40gmail.com&" |
959 "job_name=Sample+job+name&job_id=1234"), | 966 "job_name=Sample+job+name&job_id=1234"), |
960 "Sample print data", | 967 "Sample print data", |
961 kSampleLocalPrintResponse)); | 968 kSampleLocalPrintResponse)); |
962 }; | 969 } |
963 | 970 |
964 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithOverlongName) { | 971 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithOverlongName) { |
965 local_print_operation_->SetUsername("sample@gmail.com"); | 972 local_print_operation_->SetUsername("sample@gmail.com"); |
966 local_print_operation_->SetJobname( | 973 local_print_operation_->SetJobname( |
967 "123456789:123456789:123456789:123456789:123456789:123456789:123456789:"); | 974 "123456789:123456789:123456789:123456789:123456789:123456789:123456789:"); |
968 local_print_operation_->SetTicket(kSampleCJT); | 975 local_print_operation_->SetTicket(kSampleCJT); |
969 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); | 976 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); |
970 local_print_operation_->SetData( | 977 local_print_operation_->SetData( |
971 RefCountedBytesFromString("Sample print data")); | 978 RefCountedBytesFromString("Sample print data")); |
972 local_print_operation_->Start(); | 979 local_print_operation_->Start(); |
(...skipping 13 matching lines...) Expand all Loading... |
986 | 993 |
987 // TODO(noamsml): Is encoding spaces as pluses standard? | 994 // TODO(noamsml): Is encoding spaces as pluses standard? |
988 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 995 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
989 GURL( | 996 GURL( |
990 "http://10.0.0.8:6006/privet/printer/submitdoc?" | 997 "http://10.0.0.8:6006/privet/printer/submitdoc?" |
991 "client_name=Chrome&user_name=sample%40gmail.com&" | 998 "client_name=Chrome&user_name=sample%40gmail.com&" |
992 "job_name=123456789%3A123456789%3A123456789%3A1...123456789" | 999 "job_name=123456789%3A123456789%3A123456789%3A1...123456789" |
993 "%3A123456789%3A123456789%3A&job_id=1234"), | 1000 "%3A123456789%3A123456789%3A&job_id=1234"), |
994 "Sample print data", | 1001 "Sample print data", |
995 kSampleLocalPrintResponse)); | 1002 kSampleLocalPrintResponse)); |
996 }; | 1003 } |
997 | 1004 |
998 TEST_F(PrivetLocalPrintTest, PDFPrintInvalidDocumentTypeRetry) { | 1005 TEST_F(PrivetLocalPrintTest, PDFPrintInvalidDocumentTypeRetry) { |
999 local_print_operation_->SetUsername("sample@gmail.com"); | 1006 local_print_operation_->SetUsername("sample@gmail.com"); |
1000 local_print_operation_->SetJobname("Sample job name"); | 1007 local_print_operation_->SetJobname("Sample job name"); |
1001 local_print_operation_->SetTicket(kSampleCJT); | 1008 local_print_operation_->SetTicket(kSampleCJT); |
1002 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); | 1009 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); |
1003 local_print_operation_->SetData( | 1010 local_print_operation_->SetData( |
1004 RefCountedBytesFromString("sample/path/")); | 1011 RefCountedBytesFromString("sample/path/")); |
1005 local_print_operation_->Start(); | 1012 local_print_operation_->Start(); |
1006 | 1013 |
(...skipping 18 matching lines...) Expand all Loading... |
1025 kSampleInvalidDocumentTypeResponse)); | 1032 kSampleInvalidDocumentTypeResponse)); |
1026 | 1033 |
1027 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 1034 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
1028 | 1035 |
1029 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( | 1036 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( |
1030 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 1037 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
1031 "client_name=Chrome&user_name=sample%40gmail.com&" | 1038 "client_name=Chrome&user_name=sample%40gmail.com&" |
1032 "job_name=Sample+job+name&job_id=1234"), | 1039 "job_name=Sample+job+name&job_id=1234"), |
1033 base::FilePath(FILE_PATH_LITERAL("sample/path/test.pdf")), | 1040 base::FilePath(FILE_PATH_LITERAL("sample/path/test.pdf")), |
1034 kSampleLocalPrintResponse)); | 1041 kSampleLocalPrintResponse)); |
1035 }; | 1042 } |
1036 | 1043 |
1037 TEST_F(PrivetLocalPrintTest, LocalPrintRetryOnInvalidJobID) { | 1044 TEST_F(PrivetLocalPrintTest, LocalPrintRetryOnInvalidJobID) { |
1038 local_print_operation_->SetUsername("sample@gmail.com"); | 1045 local_print_operation_->SetUsername("sample@gmail.com"); |
1039 local_print_operation_->SetJobname("Sample job name"); | 1046 local_print_operation_->SetJobname("Sample job name"); |
1040 local_print_operation_->SetTicket(kSampleCJT); | 1047 local_print_operation_->SetTicket(kSampleCJT); |
1041 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); | 1048 local_print_operation_->SetCapabilities(kSampleCapabilitiesResponse); |
1042 local_print_operation_->SetData( | 1049 local_print_operation_->SetData( |
1043 RefCountedBytesFromString("Sample print data")); | 1050 RefCountedBytesFromString("Sample print data")); |
1044 local_print_operation_->Start(); | 1051 local_print_operation_->Start(); |
1045 | 1052 |
(...skipping 14 matching lines...) Expand all Loading... |
1060 "client_name=Chrome&user_name=sample%40gmail.com&" | 1067 "client_name=Chrome&user_name=sample%40gmail.com&" |
1061 "job_name=Sample+job+name&job_id=1234"), | 1068 "job_name=Sample+job+name&job_id=1234"), |
1062 "Sample print data", | 1069 "Sample print data", |
1063 kSampleErrorResponsePrinterBusy)); | 1070 kSampleErrorResponsePrinterBusy)); |
1064 | 1071 |
1065 RunFor(base::TimeDelta::FromSeconds(3)); | 1072 RunFor(base::TimeDelta::FromSeconds(3)); |
1066 | 1073 |
1067 EXPECT_TRUE(SuccessfulResponseToURL( | 1074 EXPECT_TRUE(SuccessfulResponseToURL( |
1068 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 1075 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
1069 kSampleCreatejobResponse)); | 1076 kSampleCreatejobResponse)); |
1070 }; | 1077 } |
1071 | 1078 #endif // ENABLE_FULL_PRINTING |
1072 | 1079 |
1073 } // namespace | 1080 } // namespace |
1074 | 1081 |
1075 } // namespace local_discovery | 1082 } // namespace local_discovery |
OLD | NEW |