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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 "\"error\": \"invalid_print_job\"," | 176 "\"error\": \"invalid_print_job\"," |
177 "\"timeout\": 1 " | 177 "\"timeout\": 1 " |
178 "}"; | 178 "}"; |
179 | 179 |
180 const char kSampleInvalidDocumentTypeResponse[] = "{" | 180 const char kSampleInvalidDocumentTypeResponse[] = "{" |
181 "\"error\" : \"invalid_document_type\"" | 181 "\"error\" : \"invalid_document_type\"" |
182 "}"; | 182 "}"; |
183 | 183 |
184 const char kSampleCreatejobResponse[] = "{ \"job_id\": \"1234\" }"; | 184 const char kSampleCreatejobResponse[] = "{ \"job_id\": \"1234\" }"; |
185 | 185 |
| 186 const char kSampleEmptyJSONResponse[] = "{}"; |
| 187 |
186 class MockTestURLFetcherFactoryDelegate | 188 class MockTestURLFetcherFactoryDelegate |
187 : public net::TestURLFetcher::DelegateForTests { | 189 : public net::TestURLFetcher::DelegateForTests { |
188 public: | 190 public: |
189 // Callback issued correspondingly to the call to the |Start()| method. | 191 // Callback issued correspondingly to the call to the |Start()| method. |
190 MOCK_METHOD1(OnRequestStart, void(int fetcher_id)); | 192 MOCK_METHOD1(OnRequestStart, void(int fetcher_id)); |
191 | 193 |
192 // Callback issued correspondingly to the call to |AppendChunkToUpload|. | 194 // Callback issued correspondingly to the call to |AppendChunkToUpload|. |
193 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. | 195 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. |
194 MOCK_METHOD1(OnChunkUpload, void(int fetcher_id)); | 196 MOCK_METHOD1(OnChunkUpload, void(int fetcher_id)); |
195 | 197 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 } | 386 } |
385 | 387 |
386 virtual void Start(base::RefCountedMemory* data, | 388 virtual void Start(base::RefCountedMemory* data, |
387 const printing::PdfRenderSettings& conversion_settings, | 389 const printing::PdfRenderSettings& conversion_settings, |
388 const ResultCallback& callback) OVERRIDE { | 390 const ResultCallback& callback) OVERRIDE { |
389 std::string data_str((const char*)data->front(), data->size()); | 391 std::string data_str((const char*)data->front(), data->size()); |
390 callback.Run(true, base::FilePath().AppendASCII(data_str + "test.pdf")); | 392 callback.Run(true, base::FilePath().AppendASCII(data_str + "test.pdf")); |
391 } | 393 } |
392 }; | 394 }; |
393 | 395 |
| 396 TEST_F(PrivetHTTPTest, CreatePrivetStorageList) { |
| 397 MockJSONCallback mock_callback; |
| 398 scoped_ptr<PrivetJSONOperation> storage_list_operation = |
| 399 privet_client_->CreateStorageListOperation( |
| 400 "/path/to/nothing", |
| 401 mock_callback.callback()); |
| 402 storage_list_operation->Start(); |
| 403 |
| 404 EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), |
| 405 kSampleInfoResponse)); |
| 406 |
| 407 EXPECT_CALL(mock_callback, OnPrivetJSONDoneInternal()); |
| 408 |
| 409 EXPECT_TRUE(SuccessfulResponseToURL( |
| 410 GURL("http://10.0.0.8:6006/privet/storage/list?path=/path/to/nothing"), |
| 411 kSampleEmptyJSONResponse)); |
| 412 } |
394 | 413 |
395 class PrivetInfoTest : public PrivetHTTPTest { | 414 class PrivetInfoTest : public PrivetHTTPTest { |
396 public: | 415 public: |
397 PrivetInfoTest() {} | 416 PrivetInfoTest() {} |
398 | 417 |
399 virtual ~PrivetInfoTest() {} | 418 virtual ~PrivetInfoTest() {} |
400 | 419 |
401 virtual void SetUp() OVERRIDE { | 420 virtual void SetUp() OVERRIDE { |
402 info_operation_ = privet_client_->CreateInfoOperation( | 421 info_operation_ = privet_client_->CreateInfoOperation( |
403 info_callback_.callback()); | 422 info_callback_.callback()); |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 | 980 |
962 EXPECT_TRUE(SuccessfulResponseToURL( | 981 EXPECT_TRUE(SuccessfulResponseToURL( |
963 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 982 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
964 kSampleCreatejobResponse)); | 983 kSampleCreatejobResponse)); |
965 }; | 984 }; |
966 | 985 |
967 | 986 |
968 } // namespace | 987 } // namespace |
969 | 988 |
970 } // namespace local_discovery | 989 } // namespace local_discovery |
OLD | NEW |