| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 " \"support_url\": \"http://support.google.com/cloudprint/?hl=en\"," | 66 " \"support_url\": \"http://support.google.com/cloudprint/?hl=en\"," |
| 67 " \"update_url\": \"http://support.google.com/cloudprint/?hl=en\"," | 67 " \"update_url\": \"http://support.google.com/cloudprint/?hl=en\"," |
| 68 " \"x-privet-token\": \"SampleTokenForTesting\"," | 68 " \"x-privet-token\": \"SampleTokenForTesting\"," |
| 69 " \"api\": [" | 69 " \"api\": [" |
| 70 " \"/privet/accesstoken\"," | 70 " \"/privet/accesstoken\"," |
| 71 " \"/privet/capabilities\"," | 71 " \"/privet/capabilities\"," |
| 72 " \"/privet/printer/submitdoc\"," | 72 " \"/privet/printer/submitdoc\"," |
| 73 " ]" | 73 " ]" |
| 74 "}"; | 74 "}"; |
| 75 | 75 |
| 76 const char kSampleInfoResponseWithCreatejob[] = "{" |
| 77 " \"version\": \"1.0\"," |
| 78 " \"name\": \"Common printer\"," |
| 79 " \"description\": \"Printer connected through Chrome connector\"," |
| 80 " \"url\": \"https://www.google.com/cloudprint\"," |
| 81 " \"type\": [" |
| 82 " \"printer\"" |
| 83 " ]," |
| 84 " \"id\": \"\"," |
| 85 " \"device_state\": \"idle\"," |
| 86 " \"connection_state\": \"online\"," |
| 87 " \"manufacturer\": \"Google\"," |
| 88 " \"model\": \"Google Chrome\"," |
| 89 " \"serial_number\": \"1111-22222-33333-4444\"," |
| 90 " \"firmware\": \"24.0.1312.52\"," |
| 91 " \"uptime\": 600," |
| 92 " \"setup_url\": \"http://support.google.com/\"," |
| 93 " \"support_url\": \"http://support.google.com/cloudprint/?hl=en\"," |
| 94 " \"update_url\": \"http://support.google.com/cloudprint/?hl=en\"," |
| 95 " \"x-privet-token\": \"SampleTokenForTesting\"," |
| 96 " \"api\": [" |
| 97 " \"/privet/accesstoken\"," |
| 98 " \"/privet/capabilities\"," |
| 99 " \"/privet/printer/createjob\"," |
| 100 " \"/privet/printer/submitdoc\"," |
| 101 " ]" |
| 102 "}"; |
| 76 | 103 |
| 77 const char kSampleRegisterStartResponse[] = "{" | 104 const char kSampleRegisterStartResponse[] = "{" |
| 78 "\"user\": \"example@google.com\"," | 105 "\"user\": \"example@google.com\"," |
| 79 "\"action\": \"start\"" | 106 "\"action\": \"start\"" |
| 80 "}"; | 107 "}"; |
| 81 | 108 |
| 82 const char kSampleRegisterGetClaimTokenResponse[] = "{" | 109 const char kSampleRegisterGetClaimTokenResponse[] = "{" |
| 83 " \"action\": \"getClaimToken\"," | 110 " \"action\": \"getClaimToken\"," |
| 84 " \"user\": \"example@google.com\"," | 111 " \"user\": \"example@google.com\"," |
| 85 " \"token\": \"MySampleToken\"," | 112 " \"token\": \"MySampleToken\"," |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 155 |
| 129 const char kSampleCapabilitiesResponsePWGOnly[] = "{" | 156 const char kSampleCapabilitiesResponsePWGOnly[] = "{" |
| 130 "\"version\" : \"1.0\"," | 157 "\"version\" : \"1.0\"," |
| 131 "\"printer\" : {" | 158 "\"printer\" : {" |
| 132 " \"supported_content_type\" : [" | 159 " \"supported_content_type\" : [" |
| 133 " { \"content_type\" : \"image/pwg-raster\" }" | 160 " { \"content_type\" : \"image/pwg-raster\" }" |
| 134 " ]" | 161 " ]" |
| 135 "}" | 162 "}" |
| 136 "}"; | 163 "}"; |
| 137 | 164 |
| 165 const char kSampleCreatejobResponse[] = "{ \"job_id\": \"1234\" }"; |
| 166 |
| 138 class MockTestURLFetcherFactoryDelegate | 167 class MockTestURLFetcherFactoryDelegate |
| 139 : public net::TestURLFetcher::DelegateForTests { | 168 : public net::TestURLFetcher::DelegateForTests { |
| 140 public: | 169 public: |
| 141 // Callback issued correspondingly to the call to the |Start()| method. | 170 // Callback issued correspondingly to the call to the |Start()| method. |
| 142 MOCK_METHOD1(OnRequestStart, void(int fetcher_id)); | 171 MOCK_METHOD1(OnRequestStart, void(int fetcher_id)); |
| 143 | 172 |
| 144 // Callback issued correspondingly to the call to |AppendChunkToUpload|. | 173 // Callback issued correspondingly to the call to |AppendChunkToUpload|. |
| 145 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. | 174 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. |
| 146 MOCK_METHOD1(OnChunkUpload, void(int fetcher_id)); | 175 MOCK_METHOD1(OnChunkUpload, void(int fetcher_id)); |
| 147 | 176 |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 812 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 784 | 813 |
| 785 // TODO(noamsml): Is encoding spaces as pluses standard? | 814 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 786 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 815 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 787 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 816 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 788 "user=sample%40gmail.com&jobname=Sample+job+name"), | 817 "user=sample%40gmail.com&jobname=Sample+job+name"), |
| 789 "Sample print data", | 818 "Sample print data", |
| 790 kSampleLocalPrintResponse)); | 819 kSampleLocalPrintResponse)); |
| 791 }; | 820 }; |
| 792 | 821 |
| 822 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithCreatejob) { |
| 823 local_print_operation_->SetUsername("sample@gmail.com"); |
| 824 local_print_operation_->SetJobname("Sample job name"); |
| 825 local_print_operation_->SetTicket("Sample print ticket"); |
| 826 local_print_operation_->Start(); |
| 827 |
| 828 EXPECT_TRUE(SuccessfulResponseToURL( |
| 829 GURL("http://10.0.0.8:6006/privet/info"), |
| 830 kSampleInfoResponseWithCreatejob)); |
| 831 |
| 832 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingRequestPDFInternal()); |
| 833 |
| 834 EXPECT_TRUE(SuccessfulResponseToURL( |
| 835 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 836 kSampleCapabilitiesResponse)); |
| 837 |
| 838 local_print_operation_->SendData("Sample print data"); |
| 839 |
| 840 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 841 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
| 842 "Sample print ticket", |
| 843 kSampleCreatejobResponse)); |
| 844 |
| 845 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 846 |
| 847 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 848 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 849 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 850 "user=sample%40gmail.com&jobname=Sample+job+name&job_id=1234"), |
| 851 "Sample print data", |
| 852 kSampleLocalPrintResponse)); |
| 853 }; |
| 854 |
| 855 |
| 793 } // namespace | 856 } // namespace |
| 794 | 857 |
| 795 } // namespace local_discovery | 858 } // namespace local_discovery |
| OLD | NEW |