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
3 // found in the LICENSE file.
6 #include "base/message_loop/message_loop.h"
7 #include "chrome/browser/local_discovery/privet_http_impl.h"
8 #include "net/base/host_port_pair.h"
9 #include "net/base/net_errors.h"
10 #include "net/url_request/test_url_fetcher_factory.h"
11 #include "net/url_request/url_request_test_util.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 using testing::StrictMock;
16 using testing::NiceMock;
18 namespace local_discovery {
22 const char kSampleInfoResponse[] = "{"
23 " \"version\": \"1.0\","
24 " \"name\": \"Common printer\","
25 " \"description\": \"Printer connected through Chrome connector\","
26 " \"url\": \"https://www.google.com/cloudprint\","
31 " \"device_state\": \"idle\","
32 " \"connection_state\": \"online\","
33 " \"manufacturer\": \"Google\","
34 " \"model\": \"Google Chrome\","
35 " \"serial_number\": \"1111-22222-33333-4444\","
36 " \"firmware\": \"24.0.1312.52\","
38 " \"setup_url\": \"http://support.google.com/\","
39 " \"support_url\": \"http://support.google.com/cloudprint/?hl=en\","
40 " \"update_url\": \"http://support.google.com/cloudprint/?hl=en\","
41 " \"x-privet-token\": \"SampleTokenForTesting\","
43 " \"/privet/accesstoken\","
44 " \"/privet/capabilities\","
45 " \"/privet/printer/submitdoc\","
49 const char kSampleInfoResponseRegistered[] = "{"
50 " \"version\": \"1.0\","
51 " \"name\": \"Common printer\","
52 " \"description\": \"Printer connected through Chrome connector\","
53 " \"url\": \"https://www.google.com/cloudprint\","
57 " \"id\": \"MyDeviceID\","
58 " \"device_state\": \"idle\","
59 " \"connection_state\": \"online\","
60 " \"manufacturer\": \"Google\","
61 " \"model\": \"Google Chrome\","
62 " \"serial_number\": \"1111-22222-33333-4444\","
63 " \"firmware\": \"24.0.1312.52\","
65 " \"setup_url\": \"http://support.google.com/\","
66 " \"support_url\": \"http://support.google.com/cloudprint/?hl=en\","
67 " \"update_url\": \"http://support.google.com/cloudprint/?hl=en\","
68 " \"x-privet-token\": \"SampleTokenForTesting\","
70 " \"/privet/accesstoken\","
71 " \"/privet/capabilities\","
72 " \"/privet/printer/submitdoc\","
77 const char kSampleRegisterStartResponse[] = "{"
78 "\"user\": \"example@google.com\","
79 "\"action\": \"start\""
82 const char kSampleRegisterGetClaimTokenResponse[] = "{"
83 " \"action\": \"getClaimToken\","
84 " \"user\": \"example@google.com\","
85 " \"token\": \"MySampleToken\","
86 " \"claim_url\": \"https://domain.com/SoMeUrL\""
89 const char kSampleRegisterCompleteResponse[] = "{"
90 "\"user\": \"example@google.com\","
91 "\"action\": \"complete\","
92 "\"device_id\": \"MyDeviceID\""
95 const char kSampleXPrivetErrorResponse[] =
96 "{ \"error\": \"invalid_x_privet_token\" }";
98 const char kSampleRegisterErrorTransient[] =
99 "{ \"error\": \"device_busy\", \"timeout\": 1}";
101 const char kSampleRegisterErrorPermanent[] =
102 "{ \"error\": \"user_cancel\" }";
104 const char kSampleInfoResponseBadJson[] = "{";
106 const char kSampleRegisterCancelResponse[] = "{"
107 "\"user\": \"example@google.com\","
108 "\"action\": \"cancel\""
111 const char kSampleLocalPrintResponse[] = "{"
112 "\"job_id\": \"123\","
113 "\"expires_in\": 500,"
114 "\"job_type\": \"application/pdf\","
116 "\"job_name\": \"Sample job name\","
119 const char kSampleCapabilitiesResponse[] = "{"
120 "\"version\" : \"1.0\","
122 " \"supported_content_type\" : ["
123 " { \"content_type\" : \"application/pdf\" },"
124 " { \"content_type\" : \"image/pwg-raster\" }"
129 const char kSampleCapabilitiesResponsePWGOnly[] = "{"
130 "\"version\" : \"1.0\","
132 " \"supported_content_type\" : ["
133 " { \"content_type\" : \"image/pwg-raster\" }"
138 class MockTestURLFetcherFactoryDelegate
139 : public net::TestURLFetcher::DelegateForTests {
141 // Callback issued correspondingly to the call to the |Start()| method.
142 MOCK_METHOD1(OnRequestStart, void(int fetcher_id));
144 // Callback issued correspondingly to the call to |AppendChunkToUpload|.
145 // Uploaded chunks can be retrieved with the |upload_chunks()| getter.
146 MOCK_METHOD1(OnChunkUpload, void(int fetcher_id));
148 // Callback issued correspondingly to the destructor.
149 MOCK_METHOD1(OnRequestEnd, void(int fetcher_id));
152 class PrivetHTTPTest : public ::testing::Test {
155 request_context_= new net::TestURLRequestContextGetter(
156 base::MessageLoopProxy::current());
157 privet_client_.reset(new PrivetHTTPClientImpl(
158 "sampleDevice._privet._tcp.local",
159 net::HostPortPair("10.0.0.8", 6006),
160 request_context_.get()));
161 fetcher_factory_.SetDelegateForTests(&fetcher_delegate_);
164 virtual ~PrivetHTTPTest() {
167 bool SuccessfulResponseToURL(const GURL& url,
168 const std::string& response) {
169 return SuccessfulResponseToURLAndData(url, "", response);
172 bool SuccessfulResponseToURLAndData(const GURL& url,
173 const std::string& data,
174 const std::string& response) {
175 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
176 EXPECT_TRUE(fetcher);
177 EXPECT_EQ(url, fetcher->GetOriginalURL());
180 EXPECT_EQ(data, fetcher->upload_data());
183 if (!fetcher || url != fetcher->GetOriginalURL() ||
184 (!data.empty() && data != fetcher->upload_data()))
187 fetcher->SetResponseString(response);
188 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS,
190 fetcher->set_response_code(200);
191 fetcher->delegate()->OnURLFetchComplete(fetcher);
196 base::MessageLoop loop_;
197 scoped_refptr<net::TestURLRequestContextGetter> request_context_;
198 net::TestURLFetcherFactory fetcher_factory_;
199 scoped_ptr<PrivetHTTPClient> privet_client_;
200 NiceMock<MockTestURLFetcherFactoryDelegate> fetcher_delegate_;
203 class MockInfoDelegate : public PrivetInfoOperation::Delegate {
205 MockInfoDelegate() {}
206 ~MockInfoDelegate() {}
208 virtual void OnPrivetInfoDone(PrivetInfoOperation* operation,
210 const base::DictionaryValue* value) OVERRIDE {
214 value_.reset(value->DeepCopy());
217 OnPrivetInfoDoneInternal(response_code);
220 MOCK_METHOD1(OnPrivetInfoDoneInternal, void(int response_code));
222 const base::DictionaryValue* value() { return value_.get(); }
224 scoped_ptr<base::DictionaryValue> value_;
227 class MockCapabilitiesDelegate : public PrivetCapabilitiesOperation::Delegate {
229 MockCapabilitiesDelegate() {}
230 ~MockCapabilitiesDelegate() {}
232 virtual void OnPrivetCapabilities(
233 PrivetCapabilitiesOperation* operation,
235 const base::DictionaryValue* value) OVERRIDE {
239 value_.reset(value->DeepCopy());
242 OnPrivetCapabilitiesDoneInternal(response_code);
245 MOCK_METHOD1(OnPrivetCapabilitiesDoneInternal, void(int response_code));
247 const base::DictionaryValue* value() { return value_.get(); }
249 scoped_ptr<base::DictionaryValue> value_;
252 class MockRegisterDelegate : public PrivetRegisterOperation::Delegate {
254 MockRegisterDelegate() {
256 ~MockRegisterDelegate() {
259 virtual void OnPrivetRegisterClaimToken(
260 PrivetRegisterOperation* operation,
261 const std::string& token,
262 const GURL& url) OVERRIDE {
263 OnPrivetRegisterClaimTokenInternal(token, url);
266 MOCK_METHOD2(OnPrivetRegisterClaimTokenInternal, void(
267 const std::string& token,
270 virtual void OnPrivetRegisterError(
271 PrivetRegisterOperation* operation,
272 const std::string& action,
273 PrivetRegisterOperation::FailureReason reason,
274 int printer_http_code,
275 const DictionaryValue* json) OVERRIDE {
276 // TODO(noamsml): Save and test for JSON?
277 OnPrivetRegisterErrorInternal(action, reason, printer_http_code);
280 MOCK_METHOD3(OnPrivetRegisterErrorInternal,
281 void(const std::string& action,
282 PrivetRegisterOperation::FailureReason reason,
283 int printer_http_code));
285 virtual void OnPrivetRegisterDone(
286 PrivetRegisterOperation* operation,
287 const std::string& device_id) OVERRIDE {
288 OnPrivetRegisterDoneInternal(device_id);
291 MOCK_METHOD1(OnPrivetRegisterDoneInternal,
292 void(const std::string& device_id));
295 class MockLocalPrintDelegate : public PrivetLocalPrintOperation::Delegate {
297 MockLocalPrintDelegate() {}
298 ~MockLocalPrintDelegate() {}
300 virtual void OnPrivetPrintingRequestPDF(
301 const PrivetLocalPrintOperation* print_operation) {
302 OnPrivetPrintingRequestPDFInternal();
305 MOCK_METHOD0(OnPrivetPrintingRequestPDFInternal, void());
307 virtual void OnPrivetPrintingRequestPWGRaster(
308 const PrivetLocalPrintOperation* print_operation) {
309 OnPrivetPrintingRequestPWGRasterInternal();
312 MOCK_METHOD0(OnPrivetPrintingRequestPWGRasterInternal, void());
314 virtual void OnPrivetPrintingDone(
315 const PrivetLocalPrintOperation* print_operation) {
316 OnPrivetPrintingDoneInternal();
319 MOCK_METHOD0(OnPrivetPrintingDoneInternal, void());
321 virtual void OnPrivetPrintingError(
322 const PrivetLocalPrintOperation* print_operation, int http_code) {
323 OnPrivetPrintingErrorInternal(http_code);
326 MOCK_METHOD1(OnPrivetPrintingErrorInternal, void(int http_code));
329 class PrivetInfoTest : public PrivetHTTPTest {
333 virtual ~PrivetInfoTest() {}
335 virtual void SetUp() OVERRIDE {
336 info_operation_ = privet_client_->CreateInfoOperation(&info_delegate_);
340 scoped_ptr<PrivetInfoOperation> info_operation_;
341 StrictMock<MockInfoDelegate> info_delegate_;
344 TEST_F(PrivetInfoTest, SuccessfulInfo) {
345 info_operation_->Start();
347 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
348 ASSERT_TRUE(fetcher != NULL);
349 EXPECT_EQ(GURL("http://10.0.0.8:6006/privet/info"),
350 fetcher->GetOriginalURL());
352 fetcher->SetResponseString(kSampleInfoResponse);
353 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS,
355 fetcher->set_response_code(200);
357 EXPECT_CALL(info_delegate_, OnPrivetInfoDoneInternal(200));
358 fetcher->delegate()->OnURLFetchComplete(fetcher);
362 privet_client_->GetCachedInfo()->GetString("name", &name);
363 EXPECT_EQ("Common printer", name);
366 TEST_F(PrivetInfoTest, InfoSaveToken) {
367 info_operation_->Start();
369 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
370 ASSERT_TRUE(fetcher != NULL);
371 fetcher->SetResponseString(kSampleInfoResponse);
372 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS,
374 fetcher->set_response_code(200);
376 EXPECT_CALL(info_delegate_, OnPrivetInfoDoneInternal(200));
377 fetcher->delegate()->OnURLFetchComplete(fetcher);
379 info_operation_ = privet_client_->CreateInfoOperation(&info_delegate_);
380 info_operation_->Start();
382 fetcher = fetcher_factory_.GetFetcherByID(0);
383 ASSERT_TRUE(fetcher != NULL);
384 net::HttpRequestHeaders headers;
385 fetcher->GetExtraRequestHeaders(&headers);
386 std::string header_token;
387 ASSERT_TRUE(headers.GetHeader("X-Privet-Token", &header_token));
388 EXPECT_EQ("SampleTokenForTesting", header_token);
391 TEST_F(PrivetInfoTest, InfoFailureHTTP) {
392 info_operation_->Start();
394 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
395 ASSERT_TRUE(fetcher != NULL);
396 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS,
398 fetcher->set_response_code(404);
400 EXPECT_CALL(info_delegate_, OnPrivetInfoDoneInternal(404));
401 fetcher->delegate()->OnURLFetchComplete(fetcher);
402 EXPECT_EQ(NULL, privet_client_->GetCachedInfo());
405 TEST_F(PrivetInfoTest, InfoFailureInternal) {
406 info_operation_->Start();
408 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
409 ASSERT_TRUE(fetcher != NULL);
410 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED,
412 fetcher->set_response_code(200);
414 EXPECT_CALL(info_delegate_, OnPrivetInfoDoneInternal(-1));
415 fetcher->delegate()->OnURLFetchComplete(fetcher);
416 EXPECT_EQ(NULL, privet_client_->GetCachedInfo());
419 class PrivetRegisterTest : public PrivetHTTPTest {
421 PrivetRegisterTest() {
423 virtual ~PrivetRegisterTest() {
426 virtual void SetUp() OVERRIDE {
427 info_operation_ = privet_client_->CreateInfoOperation(&info_delegate_);
428 register_operation_ =
429 privet_client_->CreateRegisterOperation("example@google.com",
430 ®ister_delegate_);
434 bool SuccessfulResponseToURL(const GURL& url,
435 const std::string& response) {
436 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
437 EXPECT_TRUE(fetcher);
438 EXPECT_EQ(url, fetcher->GetOriginalURL());
439 if (!fetcher || url != fetcher->GetOriginalURL())
442 fetcher->SetResponseString(response);
443 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS,
445 fetcher->set_response_code(200);
446 fetcher->delegate()->OnURLFetchComplete(fetcher);
450 void RunFor(base::TimeDelta time_period) {
451 base::CancelableCallback<void()> callback(base::Bind(
452 &PrivetRegisterTest::Stop, base::Unretained(this)));
453 base::MessageLoop::current()->PostDelayedTask(
454 FROM_HERE, callback.callback(), time_period);
456 base::MessageLoop::current()->Run();
461 base::MessageLoop::current()->Quit();
464 scoped_ptr<PrivetInfoOperation> info_operation_;
465 NiceMock<MockInfoDelegate> info_delegate_;
466 scoped_ptr<PrivetRegisterOperation> register_operation_;
467 StrictMock<MockRegisterDelegate> register_delegate_;
470 TEST_F(PrivetRegisterTest, RegisterSuccessSimple) {
471 // Start with info request first to populate XSRF token.
472 info_operation_->Start();
474 EXPECT_TRUE(SuccessfulResponseToURL(
475 GURL("http://10.0.0.8:6006/privet/info"),
476 kSampleInfoResponse));
478 register_operation_->Start();
480 EXPECT_TRUE(SuccessfulResponseToURL(
481 GURL("http://10.0.0.8:6006/privet/register?"
482 "action=start&user=example%40google.com"),
483 kSampleRegisterStartResponse));
485 EXPECT_CALL(register_delegate_, OnPrivetRegisterClaimTokenInternal(
487 GURL("https://domain.com/SoMeUrL")));
489 EXPECT_TRUE(SuccessfulResponseToURL(
490 GURL("http://10.0.0.8:6006/privet/register?"
491 "action=getClaimToken&user=example%40google.com"),
492 kSampleRegisterGetClaimTokenResponse));
494 register_operation_->CompleteRegistration();
496 EXPECT_TRUE(SuccessfulResponseToURL(
497 GURL("http://10.0.0.8:6006/privet/register?"
498 "action=complete&user=example%40google.com"),
499 kSampleRegisterCompleteResponse));
501 EXPECT_CALL(register_delegate_, OnPrivetRegisterDoneInternal(
504 EXPECT_TRUE(SuccessfulResponseToURL(
505 GURL("http://10.0.0.8:6006/privet/info"),
506 kSampleInfoResponseRegistered));
509 TEST_F(PrivetRegisterTest, RegisterNoInfoCall) {
510 register_operation_->Start();
512 EXPECT_TRUE(SuccessfulResponseToURL(
513 GURL("http://10.0.0.8:6006/privet/info"),
514 kSampleInfoResponse));
516 EXPECT_TRUE(SuccessfulResponseToURL(
517 GURL("http://10.0.0.8:6006/privet/register?"
518 "action=start&user=example%40google.com"),
519 kSampleRegisterStartResponse));
522 TEST_F(PrivetRegisterTest, RegisterXSRFFailure) {
523 register_operation_->Start();
525 EXPECT_TRUE(SuccessfulResponseToURL(
526 GURL("http://10.0.0.8:6006/privet/info"),
527 kSampleInfoResponse));
529 EXPECT_TRUE(SuccessfulResponseToURL(
530 GURL("http://10.0.0.8:6006/privet/register?"
531 "action=start&user=example%40google.com"),
532 kSampleRegisterStartResponse));
534 EXPECT_TRUE(SuccessfulResponseToURL(
535 GURL("http://10.0.0.8:6006/privet/register?"
536 "action=getClaimToken&user=example%40google.com"),
537 kSampleXPrivetErrorResponse));
539 EXPECT_TRUE(SuccessfulResponseToURL(
540 GURL("http://10.0.0.8:6006/privet/info"),
541 kSampleInfoResponse));
543 EXPECT_CALL(register_delegate_, OnPrivetRegisterClaimTokenInternal(
544 "MySampleToken", GURL("https://domain.com/SoMeUrL")));
546 EXPECT_TRUE(SuccessfulResponseToURL(
547 GURL("http://10.0.0.8:6006/privet/register?"
548 "action=getClaimToken&user=example%40google.com"),
549 kSampleRegisterGetClaimTokenResponse));
552 TEST_F(PrivetRegisterTest, TransientFailure) {
553 register_operation_->Start();
555 EXPECT_TRUE(SuccessfulResponseToURL(
556 GURL("http://10.0.0.8:6006/privet/info"),
557 kSampleInfoResponse));
559 EXPECT_TRUE(SuccessfulResponseToURL(
560 GURL("http://10.0.0.8:6006/privet/register?"
561 "action=start&user=example%40google.com"),
562 kSampleRegisterErrorTransient));
564 EXPECT_CALL(fetcher_delegate_, OnRequestStart(0));
566 RunFor(base::TimeDelta::FromSeconds(2));
568 testing::Mock::VerifyAndClearExpectations(&fetcher_delegate_);
570 EXPECT_TRUE(SuccessfulResponseToURL(
571 GURL("http://10.0.0.8:6006/privet/register?"
572 "action=start&user=example%40google.com"),
573 kSampleRegisterStartResponse));
576 TEST_F(PrivetRegisterTest, PermanentFailure) {
577 register_operation_->Start();
579 EXPECT_TRUE(SuccessfulResponseToURL(
580 GURL("http://10.0.0.8:6006/privet/info"),
581 kSampleInfoResponse));
583 EXPECT_TRUE(SuccessfulResponseToURL(
584 GURL("http://10.0.0.8:6006/privet/register?"
585 "action=start&user=example%40google.com"),
586 kSampleRegisterStartResponse));
588 EXPECT_CALL(register_delegate_,
589 OnPrivetRegisterErrorInternal(
591 PrivetRegisterOperation::FAILURE_JSON_ERROR,
594 EXPECT_TRUE(SuccessfulResponseToURL(
595 GURL("http://10.0.0.8:6006/privet/register?"
596 "action=getClaimToken&user=example%40google.com"),
597 kSampleRegisterErrorPermanent));
600 TEST_F(PrivetRegisterTest, InfoFailure) {
601 register_operation_->Start();
603 EXPECT_CALL(register_delegate_,
604 OnPrivetRegisterErrorInternal(
606 PrivetRegisterOperation::FAILURE_TOKEN,
609 EXPECT_TRUE(SuccessfulResponseToURL(
610 GURL("http://10.0.0.8:6006/privet/info"),
611 kSampleInfoResponseBadJson));
614 TEST_F(PrivetRegisterTest, RegisterCancel) {
615 // Start with info request first to populate XSRF token.
616 info_operation_->Start();
618 EXPECT_TRUE(SuccessfulResponseToURL(
619 GURL("http://10.0.0.8:6006/privet/info"),
620 kSampleInfoResponse));
622 register_operation_->Start();
624 EXPECT_TRUE(SuccessfulResponseToURL(
625 GURL("http://10.0.0.8:6006/privet/register?"
626 "action=start&user=example%40google.com"),
627 kSampleRegisterStartResponse));
629 register_operation_->Cancel();
631 EXPECT_TRUE(SuccessfulResponseToURL(
632 GURL("http://10.0.0.8:6006/privet/register?"
633 "action=cancel&user=example%40google.com"),
634 kSampleRegisterCancelResponse));
636 // Must keep mocks alive for 3 seconds so the cancelation object can be
638 RunFor(base::TimeDelta::FromSeconds(3));
641 class PrivetCapabilitiesTest : public PrivetHTTPTest {
643 PrivetCapabilitiesTest() {}
645 virtual ~PrivetCapabilitiesTest() {}
647 virtual void SetUp() OVERRIDE {
648 capabilities_operation_ = privet_client_->CreateCapabilitiesOperation(
649 &capabilities_delegate_);
653 scoped_ptr<PrivetCapabilitiesOperation> capabilities_operation_;
654 StrictMock<MockCapabilitiesDelegate> capabilities_delegate_;
657 TEST_F(PrivetCapabilitiesTest, SuccessfulCapabilities) {
658 capabilities_operation_->Start();
660 EXPECT_TRUE(SuccessfulResponseToURL(
661 GURL("http://10.0.0.8:6006/privet/info"),
662 kSampleInfoResponse));
664 EXPECT_CALL(capabilities_delegate_, OnPrivetCapabilitiesDoneInternal(200));
666 EXPECT_TRUE(SuccessfulResponseToURL(
667 GURL("http://10.0.0.8:6006/privet/capabilities"),
668 kSampleCapabilitiesResponse));
671 EXPECT_TRUE(capabilities_delegate_.value()->GetString("version", &version));
672 EXPECT_EQ("1.0", version);
675 TEST_F(PrivetCapabilitiesTest, CacheToken) {
676 capabilities_operation_->Start();
678 EXPECT_TRUE(SuccessfulResponseToURL(
679 GURL("http://10.0.0.8:6006/privet/info"),
680 kSampleInfoResponse));
682 EXPECT_CALL(capabilities_delegate_, OnPrivetCapabilitiesDoneInternal(200));
684 EXPECT_TRUE(SuccessfulResponseToURL(
685 GURL("http://10.0.0.8:6006/privet/capabilities"),
686 kSampleCapabilitiesResponse));
688 capabilities_operation_ = privet_client_->CreateCapabilitiesOperation(
689 &capabilities_delegate_);
691 capabilities_operation_->Start();
693 EXPECT_CALL(capabilities_delegate_, OnPrivetCapabilitiesDoneInternal(200));
695 EXPECT_TRUE(SuccessfulResponseToURL(
696 GURL("http://10.0.0.8:6006/privet/capabilities"),
697 kSampleCapabilitiesResponse));
700 TEST_F(PrivetCapabilitiesTest, BadToken) {
701 capabilities_operation_->Start();
703 EXPECT_TRUE(SuccessfulResponseToURL(
704 GURL("http://10.0.0.8:6006/privet/info"),
705 kSampleInfoResponse));
707 EXPECT_TRUE(SuccessfulResponseToURL(
708 GURL("http://10.0.0.8:6006/privet/capabilities"),
709 kSampleXPrivetErrorResponse));
711 EXPECT_TRUE(SuccessfulResponseToURL(
712 GURL("http://10.0.0.8:6006/privet/info"),
713 kSampleInfoResponse));
715 EXPECT_CALL(capabilities_delegate_, OnPrivetCapabilitiesDoneInternal(200));
717 EXPECT_TRUE(SuccessfulResponseToURL(
718 GURL("http://10.0.0.8:6006/privet/capabilities"),
719 kSampleCapabilitiesResponse));
722 class PrivetLocalPrintTest : public PrivetHTTPTest {
724 PrivetLocalPrintTest() {}
726 virtual ~PrivetLocalPrintTest() {}
728 virtual void SetUp() OVERRIDE {
729 local_print_operation_ = privet_client_->CreateLocalPrintOperation(
730 &local_print_delegate_);
734 scoped_ptr<PrivetLocalPrintOperation> local_print_operation_;
735 StrictMock<MockLocalPrintDelegate> local_print_delegate_;
738 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrint) {
739 local_print_operation_->SetUsername("sample@gmail.com");
740 local_print_operation_->SetJobname("Sample job name");
741 local_print_operation_->Start();
743 EXPECT_TRUE(SuccessfulResponseToURL(
744 GURL("http://10.0.0.8:6006/privet/info"),
745 kSampleInfoResponse));
747 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingRequestPDFInternal());
749 EXPECT_TRUE(SuccessfulResponseToURL(
750 GURL("http://10.0.0.8:6006/privet/capabilities"),
751 kSampleCapabilitiesResponse));
753 local_print_operation_->SendData("Sample print data");
755 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal());
757 // TODO(noamsml): Is encoding spaces as pluses standard?
758 EXPECT_TRUE(SuccessfulResponseToURLAndData(
759 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?"
760 "user=sample%40gmail.com&jobname=Sample+job+name"),
762 kSampleLocalPrintResponse));
765 TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrint) {
766 local_print_operation_->SetUsername("sample@gmail.com");
767 local_print_operation_->SetJobname("Sample job name");
768 local_print_operation_->Start();
770 EXPECT_TRUE(SuccessfulResponseToURL(
771 GURL("http://10.0.0.8:6006/privet/info"),
772 kSampleInfoResponse));
774 EXPECT_CALL(local_print_delegate_,
775 OnPrivetPrintingRequestPWGRasterInternal());
777 EXPECT_TRUE(SuccessfulResponseToURL(
778 GURL("http://10.0.0.8:6006/privet/capabilities"),
779 kSampleCapabilitiesResponsePWGOnly));
781 local_print_operation_->SendData("Sample print data");
783 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal());
785 // TODO(noamsml): Is encoding spaces as pluses standard?
786 EXPECT_TRUE(SuccessfulResponseToURLAndData(
787 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?"
788 "user=sample%40gmail.com&jobname=Sample+job+name"),
790 kSampleLocalPrintResponse));
795 } // namespace local_discovery