| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. | 195 // Uploaded chunks can be retrieved with the |upload_chunks()| getter. |
| 196 MOCK_METHOD1(OnChunkUpload, void(int fetcher_id)); | 196 MOCK_METHOD1(OnChunkUpload, void(int fetcher_id)); |
| 197 | 197 |
| 198 // Callback issued correspondingly to the destructor. | 198 // Callback issued correspondingly to the destructor. |
| 199 MOCK_METHOD1(OnRequestEnd, void(int fetcher_id)); | 199 MOCK_METHOD1(OnRequestEnd, void(int fetcher_id)); |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 class PrivetHTTPTest : public ::testing::Test { | 202 class PrivetHTTPTest : public ::testing::Test { |
| 203 public: | 203 public: |
| 204 PrivetHTTPTest() { | 204 PrivetHTTPTest() { |
| 205 PrivetURLFetcher::ResetTokenMapForTests(); |
| 206 |
| 205 request_context_= new net::TestURLRequestContextGetter( | 207 request_context_= new net::TestURLRequestContextGetter( |
| 206 base::MessageLoopProxy::current()); | 208 base::MessageLoopProxy::current()); |
| 207 privet_client_.reset(new PrivetHTTPClientImpl( | 209 privet_client_.reset(new PrivetHTTPClientImpl( |
| 208 "sampleDevice._privet._tcp.local", | 210 "sampleDevice._privet._tcp.local", |
| 209 net::HostPortPair("10.0.0.8", 6006), | 211 net::HostPortPair("10.0.0.8", 6006), |
| 210 request_context_.get())); | 212 request_context_.get())); |
| 211 fetcher_factory_.SetDelegateForTests(&fetcher_delegate_); | 213 fetcher_factory_.SetDelegateForTests(&fetcher_delegate_); |
| 212 } | 214 } |
| 213 | 215 |
| 214 virtual ~PrivetHTTPTest() { | 216 virtual ~PrivetHTTPTest() { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 EXPECT_EQ(GURL("http://10.0.0.8:6006/privet/info"), | 437 EXPECT_EQ(GURL("http://10.0.0.8:6006/privet/info"), |
| 436 fetcher->GetOriginalURL()); | 438 fetcher->GetOriginalURL()); |
| 437 | 439 |
| 438 fetcher->SetResponseString(kSampleInfoResponse); | 440 fetcher->SetResponseString(kSampleInfoResponse); |
| 439 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, | 441 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, |
| 440 net::OK)); | 442 net::OK)); |
| 441 fetcher->set_response_code(200); | 443 fetcher->set_response_code(200); |
| 442 | 444 |
| 443 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); | 445 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); |
| 444 fetcher->delegate()->OnURLFetchComplete(fetcher); | 446 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 445 | |
| 446 std::string name; | |
| 447 | |
| 448 privet_client_->GetCachedInfo()->GetString("name", &name); | |
| 449 EXPECT_EQ("Common printer", name); | |
| 450 }; | |
| 451 | |
| 452 TEST_F(PrivetInfoTest, InfoSaveToken) { | |
| 453 info_operation_->Start(); | |
| 454 | |
| 455 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); | |
| 456 ASSERT_TRUE(fetcher != NULL); | |
| 457 fetcher->SetResponseString(kSampleInfoResponse); | |
| 458 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, | |
| 459 net::OK)); | |
| 460 fetcher->set_response_code(200); | |
| 461 | |
| 462 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); | |
| 463 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 464 | |
| 465 info_operation_ = | |
| 466 privet_client_->CreateInfoOperation(info_callback_.callback()); | |
| 467 info_operation_->Start(); | |
| 468 | |
| 469 fetcher = fetcher_factory_.GetFetcherByID(0); | |
| 470 ASSERT_TRUE(fetcher != NULL); | |
| 471 net::HttpRequestHeaders headers; | |
| 472 fetcher->GetExtraRequestHeaders(&headers); | |
| 473 std::string header_token; | |
| 474 ASSERT_TRUE(headers.GetHeader("X-Privet-Token", &header_token)); | |
| 475 EXPECT_EQ("SampleTokenForTesting", header_token); | |
| 476 }; | 447 }; |
| 477 | 448 |
| 478 TEST_F(PrivetInfoTest, InfoFailureHTTP) { | 449 TEST_F(PrivetInfoTest, InfoFailureHTTP) { |
| 479 info_operation_->Start(); | 450 info_operation_->Start(); |
| 480 | 451 |
| 481 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); | 452 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); |
| 482 ASSERT_TRUE(fetcher != NULL); | 453 ASSERT_TRUE(fetcher != NULL); |
| 483 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, | 454 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, |
| 484 net::OK)); | 455 net::OK)); |
| 485 fetcher->set_response_code(404); | 456 fetcher->set_response_code(404); |
| 486 | 457 |
| 487 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); | 458 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); |
| 488 fetcher->delegate()->OnURLFetchComplete(fetcher); | 459 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 489 EXPECT_EQ(NULL, privet_client_->GetCachedInfo()); | |
| 490 }; | 460 }; |
| 491 | 461 |
| 492 class PrivetRegisterTest : public PrivetHTTPTest { | 462 class PrivetRegisterTest : public PrivetHTTPTest { |
| 493 public: | 463 public: |
| 494 PrivetRegisterTest() { | 464 PrivetRegisterTest() { |
| 495 } | 465 } |
| 496 virtual ~PrivetRegisterTest() { | 466 virtual ~PrivetRegisterTest() { |
| 497 } | 467 } |
| 498 | 468 |
| 499 virtual void SetUp() OVERRIDE { | 469 virtual void SetUp() OVERRIDE { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 521 return true; | 491 return true; |
| 522 } | 492 } |
| 523 | 493 |
| 524 scoped_ptr<PrivetJSONOperation> info_operation_; | 494 scoped_ptr<PrivetJSONOperation> info_operation_; |
| 525 NiceMock<MockJSONCallback> info_callback_; | 495 NiceMock<MockJSONCallback> info_callback_; |
| 526 scoped_ptr<PrivetRegisterOperation> register_operation_; | 496 scoped_ptr<PrivetRegisterOperation> register_operation_; |
| 527 StrictMock<MockRegisterDelegate> register_delegate_; | 497 StrictMock<MockRegisterDelegate> register_delegate_; |
| 528 }; | 498 }; |
| 529 | 499 |
| 530 TEST_F(PrivetRegisterTest, RegisterSuccessSimple) { | 500 TEST_F(PrivetRegisterTest, RegisterSuccessSimple) { |
| 531 // Start with info request first to populate XSRF token. | 501 register_operation_->Start(); |
| 532 info_operation_->Start(); | |
| 533 | 502 |
| 534 EXPECT_TRUE(SuccessfulResponseToURL( | 503 EXPECT_TRUE(SuccessfulResponseToURL( |
| 535 GURL("http://10.0.0.8:6006/privet/info"), | 504 GURL("http://10.0.0.8:6006/privet/info"), |
| 536 kSampleInfoResponse)); | 505 kSampleInfoResponse)); |
| 537 | 506 |
| 538 register_operation_->Start(); | |
| 539 | |
| 540 EXPECT_TRUE(SuccessfulResponseToURL( | 507 EXPECT_TRUE(SuccessfulResponseToURL( |
| 541 GURL("http://10.0.0.8:6006/privet/register?" | 508 GURL("http://10.0.0.8:6006/privet/register?" |
| 542 "action=start&user=example%40google.com"), | 509 "action=start&user=example%40google.com"), |
| 543 kSampleRegisterStartResponse)); | 510 kSampleRegisterStartResponse)); |
| 544 | 511 |
| 545 EXPECT_CALL(register_delegate_, OnPrivetRegisterClaimTokenInternal( | 512 EXPECT_CALL(register_delegate_, OnPrivetRegisterClaimTokenInternal( |
| 546 "MySampleToken", | 513 "MySampleToken", |
| 547 GURL("https://domain.com/SoMeUrL"))); | 514 GURL("https://domain.com/SoMeUrL"))); |
| 548 | 515 |
| 549 EXPECT_TRUE(SuccessfulResponseToURL( | 516 EXPECT_TRUE(SuccessfulResponseToURL( |
| 550 GURL("http://10.0.0.8:6006/privet/register?" | 517 GURL("http://10.0.0.8:6006/privet/register?" |
| 551 "action=getClaimToken&user=example%40google.com"), | 518 "action=getClaimToken&user=example%40google.com"), |
| 552 kSampleRegisterGetClaimTokenResponse)); | 519 kSampleRegisterGetClaimTokenResponse)); |
| 553 | 520 |
| 554 register_operation_->CompleteRegistration(); | 521 register_operation_->CompleteRegistration(); |
| 555 | 522 |
| 556 EXPECT_TRUE(SuccessfulResponseToURL( | 523 EXPECT_TRUE(SuccessfulResponseToURL( |
| 557 GURL("http://10.0.0.8:6006/privet/register?" | 524 GURL("http://10.0.0.8:6006/privet/register?" |
| 558 "action=complete&user=example%40google.com"), | 525 "action=complete&user=example%40google.com"), |
| 559 kSampleRegisterCompleteResponse)); | 526 kSampleRegisterCompleteResponse)); |
| 560 | 527 |
| 561 EXPECT_CALL(register_delegate_, OnPrivetRegisterDoneInternal( | 528 EXPECT_CALL(register_delegate_, OnPrivetRegisterDoneInternal( |
| 562 "MyDeviceID")); | 529 "MyDeviceID")); |
| 563 | 530 |
| 564 EXPECT_TRUE(SuccessfulResponseToURL( | 531 EXPECT_TRUE(SuccessfulResponseToURL( |
| 565 GURL("http://10.0.0.8:6006/privet/info"), | 532 GURL("http://10.0.0.8:6006/privet/info"), |
| 566 kSampleInfoResponseRegistered)); | 533 kSampleInfoResponseRegistered)); |
| 567 } | 534 } |
| 568 | 535 |
| 569 TEST_F(PrivetRegisterTest, RegisterNoInfoCall) { | |
| 570 register_operation_->Start(); | |
| 571 | |
| 572 EXPECT_TRUE(SuccessfulResponseToURL( | |
| 573 GURL("http://10.0.0.8:6006/privet/info"), | |
| 574 kSampleInfoResponse)); | |
| 575 | |
| 576 EXPECT_TRUE(SuccessfulResponseToURL( | |
| 577 GURL("http://10.0.0.8:6006/privet/register?" | |
| 578 "action=start&user=example%40google.com"), | |
| 579 kSampleRegisterStartResponse)); | |
| 580 } | |
| 581 | |
| 582 TEST_F(PrivetRegisterTest, RegisterXSRFFailure) { | 536 TEST_F(PrivetRegisterTest, RegisterXSRFFailure) { |
| 583 register_operation_->Start(); | 537 register_operation_->Start(); |
| 584 | 538 |
| 585 EXPECT_TRUE(SuccessfulResponseToURL( | 539 EXPECT_TRUE(SuccessfulResponseToURL( |
| 586 GURL("http://10.0.0.8:6006/privet/info"), | 540 GURL("http://10.0.0.8:6006/privet/info"), |
| 587 kSampleInfoResponse)); | 541 kSampleInfoResponse)); |
| 588 | 542 |
| 589 EXPECT_TRUE(SuccessfulResponseToURL( | 543 EXPECT_TRUE(SuccessfulResponseToURL( |
| 590 GURL("http://10.0.0.8:6006/privet/register?" | 544 GURL("http://10.0.0.8:6006/privet/register?" |
| 591 "action=start&user=example%40google.com"), | 545 "action=start&user=example%40google.com"), |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 "start", | 619 "start", |
| 666 PrivetRegisterOperation::FAILURE_TOKEN, | 620 PrivetRegisterOperation::FAILURE_TOKEN, |
| 667 -1)); | 621 -1)); |
| 668 | 622 |
| 669 EXPECT_TRUE(SuccessfulResponseToURL( | 623 EXPECT_TRUE(SuccessfulResponseToURL( |
| 670 GURL("http://10.0.0.8:6006/privet/info"), | 624 GURL("http://10.0.0.8:6006/privet/info"), |
| 671 kSampleInfoResponseBadJson)); | 625 kSampleInfoResponseBadJson)); |
| 672 } | 626 } |
| 673 | 627 |
| 674 TEST_F(PrivetRegisterTest, RegisterCancel) { | 628 TEST_F(PrivetRegisterTest, RegisterCancel) { |
| 675 // Start with info request first to populate XSRF token. | 629 register_operation_->Start(); |
| 676 info_operation_->Start(); | |
| 677 | 630 |
| 678 EXPECT_TRUE(SuccessfulResponseToURL( | 631 EXPECT_TRUE(SuccessfulResponseToURL( |
| 679 GURL("http://10.0.0.8:6006/privet/info"), | 632 GURL("http://10.0.0.8:6006/privet/info"), |
| 680 kSampleInfoResponse)); | 633 kSampleInfoResponse)); |
| 681 | 634 |
| 682 register_operation_->Start(); | |
| 683 | |
| 684 EXPECT_TRUE(SuccessfulResponseToURL( | 635 EXPECT_TRUE(SuccessfulResponseToURL( |
| 685 GURL("http://10.0.0.8:6006/privet/register?" | 636 GURL("http://10.0.0.8:6006/privet/register?" |
| 686 "action=start&user=example%40google.com"), | 637 "action=start&user=example%40google.com"), |
| 687 kSampleRegisterStartResponse)); | 638 kSampleRegisterStartResponse)); |
| 688 | 639 |
| 689 register_operation_->Cancel(); | 640 register_operation_->Cancel(); |
| 690 | 641 |
| 691 EXPECT_TRUE(SuccessfulResponseToURL( | 642 EXPECT_TRUE(SuccessfulResponseToURL( |
| 692 GURL("http://10.0.0.8:6006/privet/register?" | 643 GURL("http://10.0.0.8:6006/privet/register?" |
| 693 "action=cancel&user=example%40google.com"), | 644 "action=cancel&user=example%40google.com"), |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 kSampleCapabilitiesResponse)); | 730 kSampleCapabilitiesResponse)); |
| 780 }; | 731 }; |
| 781 | 732 |
| 782 class PrivetLocalPrintTest : public PrivetHTTPTest { | 733 class PrivetLocalPrintTest : public PrivetHTTPTest { |
| 783 public: | 734 public: |
| 784 PrivetLocalPrintTest() {} | 735 PrivetLocalPrintTest() {} |
| 785 | 736 |
| 786 virtual ~PrivetLocalPrintTest() {} | 737 virtual ~PrivetLocalPrintTest() {} |
| 787 | 738 |
| 788 virtual void SetUp() OVERRIDE { | 739 virtual void SetUp() OVERRIDE { |
| 740 PrivetURLFetcher::ResetTokenMapForTests(); |
| 741 |
| 789 local_print_operation_ = privet_client_->CreateLocalPrintOperation( | 742 local_print_operation_ = privet_client_->CreateLocalPrintOperation( |
| 790 &local_print_delegate_); | 743 &local_print_delegate_); |
| 791 | 744 |
| 792 local_print_operation_->SetPWGRasterConverterForTesting( | 745 local_print_operation_->SetPWGRasterConverterForTesting( |
| 793 scoped_ptr<PWGRasterConverter>(new FakePWGRasterConverter)); | 746 scoped_ptr<PWGRasterConverter>(new FakePWGRasterConverter)); |
| 794 } | 747 } |
| 795 | 748 |
| 796 scoped_refptr<base::RefCountedBytes> RefCountedBytesFromString( | 749 scoped_refptr<base::RefCountedBytes> RefCountedBytesFromString( |
| 797 std::string str) { | 750 std::string str) { |
| 798 std::vector<unsigned char> str_vec; | 751 std::vector<unsigned char> str_vec; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 811 local_print_operation_->SetJobname("Sample job name"); | 764 local_print_operation_->SetJobname("Sample job name"); |
| 812 local_print_operation_->SetData(RefCountedBytesFromString( | 765 local_print_operation_->SetData(RefCountedBytesFromString( |
| 813 "Sample print data")); | 766 "Sample print data")); |
| 814 local_print_operation_->Start(); | 767 local_print_operation_->Start(); |
| 815 | 768 |
| 816 EXPECT_TRUE(SuccessfulResponseToURL( | 769 EXPECT_TRUE(SuccessfulResponseToURL( |
| 817 GURL("http://10.0.0.8:6006/privet/info"), | 770 GURL("http://10.0.0.8:6006/privet/info"), |
| 818 kSampleInfoResponse)); | 771 kSampleInfoResponse)); |
| 819 | 772 |
| 820 EXPECT_TRUE(SuccessfulResponseToURL( | 773 EXPECT_TRUE(SuccessfulResponseToURL( |
| 774 GURL("http://10.0.0.8:6006/privet/info"), |
| 775 kSampleInfoResponse)); |
| 776 |
| 777 EXPECT_TRUE(SuccessfulResponseToURL( |
| 821 GURL("http://10.0.0.8:6006/privet/capabilities"), | 778 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 822 kSampleCapabilitiesResponse)); | 779 kSampleCapabilitiesResponse)); |
| 823 | 780 |
| 824 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 781 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 825 | 782 |
| 826 // TODO(noamsml): Is encoding spaces as pluses standard? | 783 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 827 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 784 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 828 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 785 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 829 "client_name=Chrome&user_name=sample%40gmail.com&" | 786 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 830 "job_name=Sample+job+name"), | 787 "job_name=Sample+job+name"), |
| 831 "Sample print data", | 788 "Sample print data", |
| 832 kSampleLocalPrintResponse)); | 789 kSampleLocalPrintResponse)); |
| 833 }; | 790 }; |
| 834 | 791 |
| 835 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithAnyMimetype) { | 792 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithAnyMimetype) { |
| 836 local_print_operation_->SetUsername("sample@gmail.com"); | 793 local_print_operation_->SetUsername("sample@gmail.com"); |
| 837 local_print_operation_->SetJobname("Sample job name"); | 794 local_print_operation_->SetJobname("Sample job name"); |
| 838 local_print_operation_->SetData( | 795 local_print_operation_->SetData( |
| 839 RefCountedBytesFromString("Sample print data")); | 796 RefCountedBytesFromString("Sample print data")); |
| 840 local_print_operation_->Start(); | 797 local_print_operation_->Start(); |
| 841 | 798 |
| 842 EXPECT_TRUE(SuccessfulResponseToURL( | 799 EXPECT_TRUE(SuccessfulResponseToURL( |
| 843 GURL("http://10.0.0.8:6006/privet/info"), | 800 GURL("http://10.0.0.8:6006/privet/info"), |
| 844 kSampleInfoResponse)); | 801 kSampleInfoResponse)); |
| 845 | 802 |
| 846 EXPECT_TRUE(SuccessfulResponseToURL( | 803 EXPECT_TRUE(SuccessfulResponseToURL( |
| 804 GURL("http://10.0.0.8:6006/privet/info"), |
| 805 kSampleInfoResponse)); |
| 806 |
| 807 EXPECT_TRUE(SuccessfulResponseToURL( |
| 847 GURL("http://10.0.0.8:6006/privet/capabilities"), | 808 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 848 kSampleCapabilitiesResponseWithAnyMimetype)); | 809 kSampleCapabilitiesResponseWithAnyMimetype)); |
| 849 | 810 |
| 850 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 811 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 851 | 812 |
| 852 // TODO(noamsml): Is encoding spaces as pluses standard? | 813 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 853 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 814 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 854 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 815 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 855 "client_name=Chrome&user_name=sample%40gmail.com&" | 816 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 856 "job_name=Sample+job+name"), | 817 "job_name=Sample+job+name"), |
| 857 "Sample print data", | 818 "Sample print data", |
| 858 kSampleLocalPrintResponse)); | 819 kSampleLocalPrintResponse)); |
| 859 }; | 820 }; |
| 860 | 821 |
| 861 TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrint) { | 822 TEST_F(PrivetLocalPrintTest, SuccessfulPWGLocalPrint) { |
| 862 local_print_operation_->SetUsername("sample@gmail.com"); | 823 local_print_operation_->SetUsername("sample@gmail.com"); |
| 863 local_print_operation_->SetJobname("Sample job name"); | 824 local_print_operation_->SetJobname("Sample job name"); |
| 864 local_print_operation_->SetData( | 825 local_print_operation_->SetData( |
| 865 RefCountedBytesFromString("path/to/")); | 826 RefCountedBytesFromString("path/to/")); |
| 866 local_print_operation_->Start(); | 827 local_print_operation_->Start(); |
| 867 | 828 |
| 868 EXPECT_TRUE(SuccessfulResponseToURL( | 829 EXPECT_TRUE(SuccessfulResponseToURL( |
| 869 GURL("http://10.0.0.8:6006/privet/info"), | 830 GURL("http://10.0.0.8:6006/privet/info"), |
| 870 kSampleInfoResponse)); | 831 kSampleInfoResponse)); |
| 871 | 832 |
| 872 EXPECT_TRUE(SuccessfulResponseToURL( | 833 EXPECT_TRUE(SuccessfulResponseToURL( |
| 834 GURL("http://10.0.0.8:6006/privet/info"), |
| 835 kSampleInfoResponse)); |
| 836 |
| 837 EXPECT_TRUE(SuccessfulResponseToURL( |
| 873 GURL("http://10.0.0.8:6006/privet/capabilities"), | 838 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 874 kSampleCapabilitiesResponsePWGOnly)); | 839 kSampleCapabilitiesResponsePWGOnly)); |
| 875 | 840 |
| 876 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 841 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 877 | 842 |
| 878 // TODO(noamsml): Is encoding spaces as pluses standard? | 843 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 879 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( | 844 EXPECT_TRUE(SuccessfulResponseToURLAndFilePath( |
| 880 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 845 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 881 "client_name=Chrome&user_name=sample%40gmail.com" | 846 "client_name=Chrome&user_name=sample%40gmail.com" |
| 882 "&job_name=Sample+job+name"), | 847 "&job_name=Sample+job+name"), |
| 883 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), | 848 base::FilePath(FILE_PATH_LITERAL("path/to/test.pdf")), |
| 884 kSampleLocalPrintResponse)); | 849 kSampleLocalPrintResponse)); |
| 885 }; | 850 }; |
| 886 | 851 |
| 887 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithCreatejob) { | 852 TEST_F(PrivetLocalPrintTest, SuccessfulLocalPrintWithCreatejob) { |
| 888 local_print_operation_->SetUsername("sample@gmail.com"); | 853 local_print_operation_->SetUsername("sample@gmail.com"); |
| 889 local_print_operation_->SetJobname("Sample job name"); | 854 local_print_operation_->SetJobname("Sample job name"); |
| 890 local_print_operation_->SetTicket("Sample print ticket"); | 855 local_print_operation_->SetTicket("Sample print ticket"); |
| 891 local_print_operation_->SetData( | 856 local_print_operation_->SetData( |
| 892 RefCountedBytesFromString("Sample print data")); | 857 RefCountedBytesFromString("Sample print data")); |
| 893 local_print_operation_->Start(); | 858 local_print_operation_->Start(); |
| 894 | 859 |
| 895 EXPECT_TRUE(SuccessfulResponseToURL( | 860 EXPECT_TRUE(SuccessfulResponseToURL( |
| 896 GURL("http://10.0.0.8:6006/privet/info"), | 861 GURL("http://10.0.0.8:6006/privet/info"), |
| 897 kSampleInfoResponseWithCreatejob)); | 862 kSampleInfoResponseWithCreatejob)); |
| 898 | 863 |
| 899 EXPECT_TRUE(SuccessfulResponseToURL( | 864 EXPECT_TRUE(SuccessfulResponseToURL( |
| 865 GURL("http://10.0.0.8:6006/privet/info"), |
| 866 kSampleInfoResponse)); |
| 867 |
| 868 EXPECT_TRUE(SuccessfulResponseToURL( |
| 900 GURL("http://10.0.0.8:6006/privet/capabilities"), | 869 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 901 kSampleCapabilitiesResponse)); | 870 kSampleCapabilitiesResponse)); |
| 902 | 871 |
| 903 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 872 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 904 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 873 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
| 905 "Sample print ticket", | 874 "Sample print ticket", |
| 906 kSampleCreatejobResponse)); | 875 kSampleCreatejobResponse)); |
| 907 | 876 |
| 908 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); | 877 EXPECT_CALL(local_print_delegate_, OnPrivetPrintingDoneInternal()); |
| 909 | 878 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 922 local_print_operation_->SetTicket("Sample print ticket"); | 891 local_print_operation_->SetTicket("Sample print ticket"); |
| 923 local_print_operation_->SetData( | 892 local_print_operation_->SetData( |
| 924 RefCountedBytesFromString("sample/path/")); | 893 RefCountedBytesFromString("sample/path/")); |
| 925 local_print_operation_->Start(); | 894 local_print_operation_->Start(); |
| 926 | 895 |
| 927 EXPECT_TRUE(SuccessfulResponseToURL( | 896 EXPECT_TRUE(SuccessfulResponseToURL( |
| 928 GURL("http://10.0.0.8:6006/privet/info"), | 897 GURL("http://10.0.0.8:6006/privet/info"), |
| 929 kSampleInfoResponseWithCreatejob)); | 898 kSampleInfoResponseWithCreatejob)); |
| 930 | 899 |
| 931 EXPECT_TRUE(SuccessfulResponseToURL( | 900 EXPECT_TRUE(SuccessfulResponseToURL( |
| 901 GURL("http://10.0.0.8:6006/privet/info"), |
| 902 kSampleInfoResponse)); |
| 903 |
| 904 EXPECT_TRUE(SuccessfulResponseToURL( |
| 932 GURL("http://10.0.0.8:6006/privet/capabilities"), | 905 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 933 kSampleCapabilitiesResponse)); | 906 kSampleCapabilitiesResponse)); |
| 934 | 907 |
| 935 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 908 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 936 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 909 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
| 937 "Sample print ticket", | 910 "Sample print ticket", |
| 938 kSampleCreatejobResponse)); | 911 kSampleCreatejobResponse)); |
| 939 | 912 |
| 940 // TODO(noamsml): Is encoding spaces as pluses standard? | 913 // TODO(noamsml): Is encoding spaces as pluses standard? |
| 941 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 914 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 960 local_print_operation_->SetJobname("Sample job name"); | 933 local_print_operation_->SetJobname("Sample job name"); |
| 961 local_print_operation_->SetTicket("Sample print ticket"); | 934 local_print_operation_->SetTicket("Sample print ticket"); |
| 962 local_print_operation_->SetData( | 935 local_print_operation_->SetData( |
| 963 RefCountedBytesFromString("Sample print data")); | 936 RefCountedBytesFromString("Sample print data")); |
| 964 local_print_operation_->Start(); | 937 local_print_operation_->Start(); |
| 965 | 938 |
| 966 EXPECT_TRUE(SuccessfulResponseToURL( | 939 EXPECT_TRUE(SuccessfulResponseToURL( |
| 967 GURL("http://10.0.0.8:6006/privet/info"), | 940 GURL("http://10.0.0.8:6006/privet/info"), |
| 968 kSampleInfoResponseWithCreatejob)); | 941 kSampleInfoResponseWithCreatejob)); |
| 969 | 942 |
| 943 |
| 944 EXPECT_TRUE(SuccessfulResponseToURL( |
| 945 GURL("http://10.0.0.8:6006/privet/info"), |
| 946 kSampleInfoResponse)); |
| 947 |
| 970 EXPECT_TRUE(SuccessfulResponseToURL( | 948 EXPECT_TRUE(SuccessfulResponseToURL( |
| 971 GURL("http://10.0.0.8:6006/privet/capabilities"), | 949 GURL("http://10.0.0.8:6006/privet/capabilities"), |
| 972 kSampleCapabilitiesResponse)); | 950 kSampleCapabilitiesResponse)); |
| 973 | 951 |
| 974 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 952 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 975 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 953 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
| 976 "Sample print ticket", | 954 "Sample print ticket", |
| 977 kSampleCreatejobResponse)); | 955 kSampleCreatejobResponse)); |
| 978 | 956 |
| 979 EXPECT_TRUE(SuccessfulResponseToURLAndData( | 957 EXPECT_TRUE(SuccessfulResponseToURLAndData( |
| 980 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" | 958 GURL("http://10.0.0.8:6006/privet/printer/submitdoc?" |
| 981 "client_name=Chrome&user_name=sample%40gmail.com&" | 959 "client_name=Chrome&user_name=sample%40gmail.com&" |
| 982 "job_name=Sample+job+name&job_id=1234"), | 960 "job_name=Sample+job+name&job_id=1234"), |
| 983 "Sample print data", | 961 "Sample print data", |
| 984 kSampleErrorResponsePrinterBusy)); | 962 kSampleErrorResponsePrinterBusy)); |
| 985 | 963 |
| 986 RunFor(base::TimeDelta::FromSeconds(3)); | 964 RunFor(base::TimeDelta::FromSeconds(3)); |
| 987 | 965 |
| 988 EXPECT_TRUE(SuccessfulResponseToURL( | 966 EXPECT_TRUE(SuccessfulResponseToURL( |
| 989 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 967 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
| 990 kSampleCreatejobResponse)); | 968 kSampleCreatejobResponse)); |
| 991 }; | 969 }; |
| 992 | 970 |
| 993 | 971 |
| 994 } // namespace | 972 } // namespace |
| 995 | 973 |
| 996 } // namespace local_discovery | 974 } // namespace local_discovery |
| OLD | NEW |