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" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 scoped_ptr<base::DictionaryValue> value_; | 372 scoped_ptr<base::DictionaryValue> value_; |
373 }; | 373 }; |
374 | 374 |
375 class MockRegisterDelegate : public PrivetRegisterOperation::Delegate { | 375 class MockRegisterDelegate : public PrivetRegisterOperation::Delegate { |
376 public: | 376 public: |
377 MockRegisterDelegate() { | 377 MockRegisterDelegate() { |
378 } | 378 } |
379 ~MockRegisterDelegate() { | 379 ~MockRegisterDelegate() { |
380 } | 380 } |
381 | 381 |
382 virtual void OnPrivetRegisterClaimToken( | 382 void OnPrivetRegisterClaimToken( |
383 PrivetRegisterOperation* operation, | 383 PrivetRegisterOperation* operation, |
384 const std::string& token, | 384 const std::string& token, |
385 const GURL& url) override { | 385 const GURL& url) override { |
386 OnPrivetRegisterClaimTokenInternal(token, url); | 386 OnPrivetRegisterClaimTokenInternal(token, url); |
387 } | 387 } |
388 | 388 |
389 MOCK_METHOD2(OnPrivetRegisterClaimTokenInternal, void( | 389 MOCK_METHOD2(OnPrivetRegisterClaimTokenInternal, void( |
390 const std::string& token, | 390 const std::string& token, |
391 const GURL& url)); | 391 const GURL& url)); |
392 | 392 |
393 virtual void OnPrivetRegisterError( | 393 void OnPrivetRegisterError( |
394 PrivetRegisterOperation* operation, | 394 PrivetRegisterOperation* operation, |
395 const std::string& action, | 395 const std::string& action, |
396 PrivetRegisterOperation::FailureReason reason, | 396 PrivetRegisterOperation::FailureReason reason, |
397 int printer_http_code, | 397 int printer_http_code, |
398 const base::DictionaryValue* json) override { | 398 const base::DictionaryValue* json) override { |
399 // TODO(noamsml): Save and test for JSON? | 399 // TODO(noamsml): Save and test for JSON? |
400 OnPrivetRegisterErrorInternal(action, reason, printer_http_code); | 400 OnPrivetRegisterErrorInternal(action, reason, printer_http_code); |
401 } | 401 } |
402 | 402 |
403 MOCK_METHOD3(OnPrivetRegisterErrorInternal, | 403 MOCK_METHOD3(OnPrivetRegisterErrorInternal, |
404 void(const std::string& action, | 404 void(const std::string& action, |
405 PrivetRegisterOperation::FailureReason reason, | 405 PrivetRegisterOperation::FailureReason reason, |
406 int printer_http_code)); | 406 int printer_http_code)); |
407 | 407 |
408 virtual void OnPrivetRegisterDone( | 408 void OnPrivetRegisterDone( |
409 PrivetRegisterOperation* operation, | 409 PrivetRegisterOperation* operation, |
410 const std::string& device_id) override { | 410 const std::string& device_id) override { |
411 OnPrivetRegisterDoneInternal(device_id); | 411 OnPrivetRegisterDoneInternal(device_id); |
412 } | 412 } |
413 | 413 |
414 MOCK_METHOD1(OnPrivetRegisterDoneInternal, | 414 MOCK_METHOD1(OnPrivetRegisterDoneInternal, |
415 void(const std::string& device_id)); | 415 void(const std::string& device_id)); |
416 }; | 416 }; |
417 | 417 |
418 class MockLocalPrintDelegate : public PrivetLocalPrintOperation::Delegate { | 418 class MockLocalPrintDelegate : public PrivetLocalPrintOperation::Delegate { |
(...skipping 13 matching lines...) Expand all Loading... |
432 OnPrivetPrintingErrorInternal(http_code); | 432 OnPrivetPrintingErrorInternal(http_code); |
433 } | 433 } |
434 | 434 |
435 MOCK_METHOD1(OnPrivetPrintingErrorInternal, void(int http_code)); | 435 MOCK_METHOD1(OnPrivetPrintingErrorInternal, void(int http_code)); |
436 }; | 436 }; |
437 | 437 |
438 class PrivetInfoTest : public PrivetHTTPTest { | 438 class PrivetInfoTest : public PrivetHTTPTest { |
439 public: | 439 public: |
440 PrivetInfoTest() {} | 440 PrivetInfoTest() {} |
441 | 441 |
442 virtual ~PrivetInfoTest() {} | 442 ~PrivetInfoTest() override {} |
443 | 443 |
444 virtual void SetUp() override { | 444 void SetUp() override { |
445 info_operation_ = privet_client_->CreateInfoOperation( | 445 info_operation_ = privet_client_->CreateInfoOperation( |
446 info_callback_.callback()); | 446 info_callback_.callback()); |
447 } | 447 } |
448 | 448 |
449 protected: | 449 protected: |
450 scoped_ptr<PrivetJSONOperation> info_operation_; | 450 scoped_ptr<PrivetJSONOperation> info_operation_; |
451 StrictMock<MockJSONCallback> info_callback_; | 451 StrictMock<MockJSONCallback> info_callback_; |
452 }; | 452 }; |
453 | 453 |
454 TEST_F(PrivetInfoTest, SuccessfulInfo) { | 454 TEST_F(PrivetInfoTest, SuccessfulInfo) { |
(...skipping 23 matching lines...) Expand all Loading... |
478 fetcher->set_response_code(404); | 478 fetcher->set_response_code(404); |
479 | 479 |
480 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); | 480 EXPECT_CALL(info_callback_, OnPrivetJSONDoneInternal()); |
481 fetcher->delegate()->OnURLFetchComplete(fetcher); | 481 fetcher->delegate()->OnURLFetchComplete(fetcher); |
482 } | 482 } |
483 | 483 |
484 class PrivetRegisterTest : public PrivetHTTPTest { | 484 class PrivetRegisterTest : public PrivetHTTPTest { |
485 public: | 485 public: |
486 PrivetRegisterTest() { | 486 PrivetRegisterTest() { |
487 } | 487 } |
488 virtual ~PrivetRegisterTest() { | 488 ~PrivetRegisterTest() override { |
489 } | 489 } |
490 | 490 |
491 virtual void SetUp() override { | 491 void SetUp() override { |
492 info_operation_ = privet_client_->CreateInfoOperation( | 492 info_operation_ = privet_client_->CreateInfoOperation( |
493 info_callback_.callback()); | 493 info_callback_.callback()); |
494 register_operation_ = | 494 register_operation_ = |
495 privet_client_->CreateRegisterOperation("example@google.com", | 495 privet_client_->CreateRegisterOperation("example@google.com", |
496 ®ister_delegate_); | 496 ®ister_delegate_); |
497 } | 497 } |
498 | 498 |
499 protected: | 499 protected: |
500 bool SuccessfulResponseToURL(const GURL& url, | 500 bool SuccessfulResponseToURL(const GURL& url, |
501 const std::string& response) { | 501 const std::string& response) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 | 668 |
669 // Must keep mocks alive for 3 seconds so the cancelation object can be | 669 // Must keep mocks alive for 3 seconds so the cancelation object can be |
670 // deleted. | 670 // deleted. |
671 RunFor(base::TimeDelta::FromSeconds(3)); | 671 RunFor(base::TimeDelta::FromSeconds(3)); |
672 } | 672 } |
673 | 673 |
674 class PrivetCapabilitiesTest : public PrivetHTTPTest { | 674 class PrivetCapabilitiesTest : public PrivetHTTPTest { |
675 public: | 675 public: |
676 PrivetCapabilitiesTest() {} | 676 PrivetCapabilitiesTest() {} |
677 | 677 |
678 virtual ~PrivetCapabilitiesTest() {} | 678 ~PrivetCapabilitiesTest() override {} |
679 | 679 |
680 virtual void SetUp() override { | 680 void SetUp() override { |
681 capabilities_operation_ = privet_client_->CreateCapabilitiesOperation( | 681 capabilities_operation_ = privet_client_->CreateCapabilitiesOperation( |
682 capabilities_callback_.callback()); | 682 capabilities_callback_.callback()); |
683 } | 683 } |
684 | 684 |
685 protected: | 685 protected: |
686 scoped_ptr<PrivetJSONOperation> capabilities_operation_; | 686 scoped_ptr<PrivetJSONOperation> capabilities_operation_; |
687 StrictMock<MockJSONCallback> capabilities_callback_; | 687 StrictMock<MockJSONCallback> capabilities_callback_; |
688 }; | 688 }; |
689 | 689 |
690 TEST_F(PrivetCapabilitiesTest, SuccessfulCapabilities) { | 690 TEST_F(PrivetCapabilitiesTest, SuccessfulCapabilities) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 } | 778 } |
779 | 779 |
780 private: | 780 private: |
781 printing::PwgRasterSettings bitmap_settings_; | 781 printing::PwgRasterSettings bitmap_settings_; |
782 }; | 782 }; |
783 | 783 |
784 class PrivetLocalPrintTest : public PrivetHTTPTest { | 784 class PrivetLocalPrintTest : public PrivetHTTPTest { |
785 public: | 785 public: |
786 PrivetLocalPrintTest() {} | 786 PrivetLocalPrintTest() {} |
787 | 787 |
788 virtual ~PrivetLocalPrintTest() {} | 788 ~PrivetLocalPrintTest() override {} |
789 | 789 |
790 virtual void SetUp() override { | 790 void SetUp() override { |
791 PrivetURLFetcher::ResetTokenMapForTests(); | 791 PrivetURLFetcher::ResetTokenMapForTests(); |
792 | 792 |
793 local_print_operation_ = privet_client_->CreateLocalPrintOperation( | 793 local_print_operation_ = privet_client_->CreateLocalPrintOperation( |
794 &local_print_delegate_); | 794 &local_print_delegate_); |
795 | 795 |
796 scoped_ptr<FakePWGRasterConverter> pwg_converter( | 796 scoped_ptr<FakePWGRasterConverter> pwg_converter( |
797 new FakePWGRasterConverter); | 797 new FakePWGRasterConverter); |
798 pwg_converter_ = pwg_converter.get(); | 798 pwg_converter_ = pwg_converter.get(); |
799 local_print_operation_->SetPWGRasterConverterForTesting( | 799 local_print_operation_->SetPWGRasterConverterForTesting( |
800 pwg_converter.Pass()); | 800 pwg_converter.Pass()); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 | 1072 |
1073 EXPECT_TRUE(SuccessfulResponseToURL( | 1073 EXPECT_TRUE(SuccessfulResponseToURL( |
1074 GURL("http://10.0.0.8:6006/privet/printer/createjob"), | 1074 GURL("http://10.0.0.8:6006/privet/printer/createjob"), |
1075 kSampleCreatejobResponse)); | 1075 kSampleCreatejobResponse)); |
1076 } | 1076 } |
1077 #endif // ENABLE_PRINT_PREVIEW | 1077 #endif // ENABLE_PRINT_PREVIEW |
1078 | 1078 |
1079 } // namespace | 1079 } // namespace |
1080 | 1080 |
1081 } // namespace local_discovery | 1081 } // namespace local_discovery |
OLD | NEW |