Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: net/dns/mdns_client_unittest.cc

Issue 17922002: Add an explicit way of forcing the MDnsClient to listen on the network (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/dns/mdns_client_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <queue> 5 #include <queue>
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "net/base/rand_callback.h" 9 #include "net/base/rand_callback.h"
10 #include "net/base/test_completion_callback.h" 10 #include "net/base/test_completion_callback.h"
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 bool set_; 340 bool set_;
341 std::string name_; 341 std::string name_;
342 std::string ptrdomain_; 342 std::string ptrdomain_;
343 int ttl_; 343 int ttl_;
344 }; 344 };
345 345
346 class MDnsTest : public ::testing::Test { 346 class MDnsTest : public ::testing::Test {
347 public: 347 public:
348 MDnsTest(); 348 MDnsTest();
349 virtual ~MDnsTest(); 349 virtual ~MDnsTest();
350 virtual void SetUp() OVERRIDE;
350 virtual void TearDown() OVERRIDE; 351 virtual void TearDown() OVERRIDE;
351 void DeleteTransaction(); 352 void DeleteTransaction();
352 void DeleteBothListeners(); 353 void DeleteBothListeners();
353 void RunFor(base::TimeDelta time_period); 354 void RunFor(base::TimeDelta time_period);
354 void Stop(); 355 void Stop();
355 356
356 MOCK_METHOD2(MockableRecordCallback, void(MDnsTransaction::Result result, 357 MOCK_METHOD2(MockableRecordCallback, void(MDnsTransaction::Result result,
357 const RecordParsed* record)); 358 const RecordParsed* record));
358 359
359 MOCK_METHOD2(MockableRecordCallback2, void(MDnsTransaction::Result result, 360 MOCK_METHOD2(MockableRecordCallback2, void(MDnsTransaction::Result result,
(...skipping 26 matching lines...) Expand all
386 387
387 MDnsTest::MDnsTest() { 388 MDnsTest::MDnsTest() {
388 socket_factory_ = new StrictMock<MockMDnsSocketFactory>(); 389 socket_factory_ = new StrictMock<MockMDnsSocketFactory>();
389 test_client_.reset(new MDnsClientImpl( 390 test_client_.reset(new MDnsClientImpl(
390 scoped_ptr<MDnsConnection::SocketFactory>(socket_factory_))); 391 scoped_ptr<MDnsConnection::SocketFactory>(socket_factory_)));
391 } 392 }
392 393
393 MDnsTest::~MDnsTest() { 394 MDnsTest::~MDnsTest() {
394 } 395 }
395 396
397 void MDnsTest::SetUp() {
398 test_client_->StartListening();
399 }
400
396 void MDnsTest::TearDown() { 401 void MDnsTest::TearDown() {
397 base::MessageLoop::current()->RunUntilIdle();
398
399 ASSERT_FALSE(test_client_->IsListeningForTests());
400
401 base::MessageLoop::current()->AssertIdle();
402 } 402 }
403 403
404 void MDnsTest::SimulatePacketReceive(const char* packet, unsigned size) { 404 void MDnsTest::SimulatePacketReceive(const char* packet, unsigned size) {
405 socket_factory_->SimulateReceive(packet, size); 405 socket_factory_->SimulateReceive(packet, size);
406 } 406 }
407 407
408 void MDnsTest::ExpectPacket( 408 void MDnsTest::ExpectPacket(
409 const char* packet, 409 const char* packet,
410 unsigned size) { 410 unsigned size) {
411 EXPECT_CALL(*socket_factory_, OnSendTo(std::string(packet, size))) 411 EXPECT_CALL(*socket_factory_, OnSendTo(std::string(packet, size)))
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 PtrRecordCopyContainer record_printer; 443 PtrRecordCopyContainer record_printer;
444 444
445 scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener( 445 scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener(
446 dns_protocol::kTypePTR, "_privet._tcp.local", &delegate_privet); 446 dns_protocol::kTypePTR, "_privet._tcp.local", &delegate_privet);
447 scoped_ptr<MDnsListener> listener_printer = test_client_->CreateListener( 447 scoped_ptr<MDnsListener> listener_printer = test_client_->CreateListener(
448 dns_protocol::kTypePTR, "_printer._tcp.local", &delegate_printer); 448 dns_protocol::kTypePTR, "_printer._tcp.local", &delegate_printer);
449 449
450 ASSERT_TRUE(listener_privet->Start()); 450 ASSERT_TRUE(listener_privet->Start());
451 ASSERT_TRUE(listener_printer->Start()); 451 ASSERT_TRUE(listener_printer->Start());
452 452
453 ASSERT_TRUE(test_client_->IsListeningForTests());
454
455 // Send the same packet twice to ensure no records are double-counted. 453 // Send the same packet twice to ensure no records are double-counted.
456 454
457 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_ADDED, _)) 455 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_ADDED, _))
458 .Times(Exactly(1)) 456 .Times(Exactly(1))
459 .WillOnce(Invoke( 457 .WillOnce(Invoke(
460 &record_privet, 458 &record_privet,
461 &PtrRecordCopyContainer::SaveWithDummyArg)); 459 &PtrRecordCopyContainer::SaveWithDummyArg));
462 460
463 EXPECT_CALL(delegate_printer, OnRecordUpdate(MDnsListener::RECORD_ADDED, _)) 461 EXPECT_CALL(delegate_printer, OnRecordUpdate(MDnsListener::RECORD_ADDED, _))
464 .Times(Exactly(1)) 462 .Times(Exactly(1))
465 .WillOnce(Invoke( 463 .WillOnce(Invoke(
466 &record_printer, 464 &record_printer,
467 &PtrRecordCopyContainer::SaveWithDummyArg)); 465 &PtrRecordCopyContainer::SaveWithDummyArg));
468 466
469 467
470 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1)); 468 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1));
471 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1)); 469 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1));
472 470
473 EXPECT_TRUE(record_privet.IsRecordWith("_privet._tcp.local", 471 EXPECT_TRUE(record_privet.IsRecordWith("_privet._tcp.local",
474 "hello._privet._tcp.local")); 472 "hello._privet._tcp.local"));
475 473
476 EXPECT_TRUE(record_printer.IsRecordWith("_printer._tcp.local", 474 EXPECT_TRUE(record_printer.IsRecordWith("_printer._tcp.local",
477 "hello._printer._tcp.local")); 475 "hello._printer._tcp.local"));
478 476
479 listener_privet.reset(); 477 listener_privet.reset();
480 listener_printer.reset(); 478 listener_printer.reset();
481
482 ASSERT_TRUE(test_client_->IsListeningForTests());
483 } 479 }
484 480
485 TEST_F(MDnsTest, PassiveListenersCacheCleanup) { 481 TEST_F(MDnsTest, PassiveListenersCacheCleanup) {
486 StrictMock<MockListenerDelegate> delegate_privet; 482 StrictMock<MockListenerDelegate> delegate_privet;
487 483
488 PtrRecordCopyContainer record_privet; 484 PtrRecordCopyContainer record_privet;
489 PtrRecordCopyContainer record_privet2; 485 PtrRecordCopyContainer record_privet2;
490 486
491 scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener( 487 scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener(
492 dns_protocol::kTypePTR, "_privet._tcp.local", &delegate_privet); 488 dns_protocol::kTypePTR, "_privet._tcp.local", &delegate_privet);
493 489
494 ASSERT_TRUE(listener_privet->Start()); 490 ASSERT_TRUE(listener_privet->Start());
495 491
496 ASSERT_TRUE(test_client_->IsListeningForTests());
497
498 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_ADDED, _)) 492 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_ADDED, _))
499 .Times(Exactly(1)) 493 .Times(Exactly(1))
500 .WillOnce(Invoke( 494 .WillOnce(Invoke(
501 &record_privet, 495 &record_privet,
502 &PtrRecordCopyContainer::SaveWithDummyArg)); 496 &PtrRecordCopyContainer::SaveWithDummyArg));
503 497
504 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1)); 498 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1));
505 499
506 EXPECT_TRUE(record_privet.IsRecordWith("_privet._tcp.local", 500 EXPECT_TRUE(record_privet.IsRecordWith("_privet._tcp.local",
507 "hello._privet._tcp.local")); 501 "hello._privet._tcp.local"));
(...skipping 14 matching lines...) Expand all
522 TEST_F(MDnsTest, MalformedPacket) { 516 TEST_F(MDnsTest, MalformedPacket) {
523 StrictMock<MockListenerDelegate> delegate_printer; 517 StrictMock<MockListenerDelegate> delegate_printer;
524 518
525 PtrRecordCopyContainer record_printer; 519 PtrRecordCopyContainer record_printer;
526 520
527 scoped_ptr<MDnsListener> listener_printer = test_client_->CreateListener( 521 scoped_ptr<MDnsListener> listener_printer = test_client_->CreateListener(
528 dns_protocol::kTypePTR, "_printer._tcp.local", &delegate_printer); 522 dns_protocol::kTypePTR, "_printer._tcp.local", &delegate_printer);
529 523
530 ASSERT_TRUE(listener_printer->Start()); 524 ASSERT_TRUE(listener_printer->Start());
531 525
532 ASSERT_TRUE(test_client_->IsListeningForTests());
533
534 EXPECT_CALL(delegate_printer, OnRecordUpdate(MDnsListener::RECORD_ADDED, _)) 526 EXPECT_CALL(delegate_printer, OnRecordUpdate(MDnsListener::RECORD_ADDED, _))
535 .Times(Exactly(1)) 527 .Times(Exactly(1))
536 .WillOnce(Invoke( 528 .WillOnce(Invoke(
537 &record_printer, 529 &record_printer,
538 &PtrRecordCopyContainer::SaveWithDummyArg)); 530 &PtrRecordCopyContainer::SaveWithDummyArg));
539 531
540 // First, send unsalvagable packet to ensure we can deal with it. 532 // First, send unsalvagable packet to ensure we can deal with it.
541 SimulatePacketReceive(kCorruptedPacketUnsalvagable, 533 SimulatePacketReceive(kCorruptedPacketUnsalvagable,
542 sizeof(kCorruptedPacketUnsalvagable)); 534 sizeof(kCorruptedPacketUnsalvagable));
543 535
(...skipping 16 matching lines...) Expand all
560 test_client_->CreateTransaction( 552 test_client_->CreateTransaction(
561 dns_protocol::kTypePTR, "_privet._tcp.local", 553 dns_protocol::kTypePTR, "_privet._tcp.local",
562 MDnsTransaction::QUERY_NETWORK | 554 MDnsTransaction::QUERY_NETWORK |
563 MDnsTransaction::QUERY_CACHE | 555 MDnsTransaction::QUERY_CACHE |
564 MDnsTransaction::SINGLE_RESULT, 556 MDnsTransaction::SINGLE_RESULT,
565 base::Bind(&MDnsTest::MockableRecordCallback, 557 base::Bind(&MDnsTest::MockableRecordCallback,
566 base::Unretained(this))); 558 base::Unretained(this)));
567 559
568 ASSERT_TRUE(transaction_privet->Start()); 560 ASSERT_TRUE(transaction_privet->Start());
569 561
570 EXPECT_TRUE(test_client_->IsListeningForTests());
571
572 PtrRecordCopyContainer record_privet; 562 PtrRecordCopyContainer record_privet;
573 563
574 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_RECORD, _)) 564 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_RECORD, _))
575 .Times(Exactly(1)) 565 .Times(Exactly(1))
576 .WillOnce(Invoke(&record_privet, 566 .WillOnce(Invoke(&record_privet,
577 &PtrRecordCopyContainer::SaveWithDummyArg)); 567 &PtrRecordCopyContainer::SaveWithDummyArg));
578 568
579 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1)); 569 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1));
580 570
581 EXPECT_TRUE(record_privet.IsRecordWith("_privet._tcp.local", 571 EXPECT_TRUE(record_privet.IsRecordWith("_privet._tcp.local",
582 "hello._privet._tcp.local")); 572 "hello._privet._tcp.local"));
583 } 573 }
584 574
585 TEST_F(MDnsTest, TransactionCacheOnlyNoResult) { 575 TEST_F(MDnsTest, TransactionCacheOnlyNoResult) {
586 scoped_ptr<MDnsTransaction> transaction_privet = 576 scoped_ptr<MDnsTransaction> transaction_privet =
587 test_client_->CreateTransaction( 577 test_client_->CreateTransaction(
588 dns_protocol::kTypePTR, "_privet._tcp.local", 578 dns_protocol::kTypePTR, "_privet._tcp.local",
589 MDnsTransaction::QUERY_CACHE | 579 MDnsTransaction::QUERY_CACHE |
590 MDnsTransaction::SINGLE_RESULT, 580 MDnsTransaction::SINGLE_RESULT,
591 base::Bind(&MDnsTest::MockableRecordCallback, 581 base::Bind(&MDnsTest::MockableRecordCallback,
592 base::Unretained(this))); 582 base::Unretained(this)));
593 583
594 EXPECT_CALL(*this, 584 EXPECT_CALL(*this,
595 MockableRecordCallback(MDnsTransaction::RESULT_NO_RESULTS, _)) 585 MockableRecordCallback(MDnsTransaction::RESULT_NO_RESULTS, _))
596 .Times(Exactly(1)); 586 .Times(Exactly(1));
597 587
598 ASSERT_TRUE(transaction_privet->Start()); 588 ASSERT_TRUE(transaction_privet->Start());
599
600 EXPECT_FALSE(test_client_->IsListeningForTests());
601 } 589 }
602 590
603 TEST_F(MDnsTest, TransactionWithCache) { 591 TEST_F(MDnsTest, TransactionWithCache) {
604 // Listener to force the client to listen 592 // Listener to force the client to listen
605 StrictMock<MockListenerDelegate> delegate_irrelevant; 593 StrictMock<MockListenerDelegate> delegate_irrelevant;
606 scoped_ptr<MDnsListener> listener_irrelevant = test_client_->CreateListener( 594 scoped_ptr<MDnsListener> listener_irrelevant = test_client_->CreateListener(
607 dns_protocol::kTypeA, "codereview.chromium.local", 595 dns_protocol::kTypeA, "codereview.chromium.local",
608 &delegate_irrelevant); 596 &delegate_irrelevant);
609 597
610 ASSERT_TRUE(listener_irrelevant->Start()); 598 ASSERT_TRUE(listener_irrelevant->Start());
611 599
612 EXPECT_TRUE(test_client_->IsListeningForTests());
613
614 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1)); 600 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1));
615 601
616 602
617 PtrRecordCopyContainer record_privet; 603 PtrRecordCopyContainer record_privet;
618 604
619 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_RECORD, _)) 605 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_RECORD, _))
620 .WillOnce(Invoke(&record_privet, 606 .WillOnce(Invoke(&record_privet,
621 &PtrRecordCopyContainer::SaveWithDummyArg)); 607 &PtrRecordCopyContainer::SaveWithDummyArg));
622 608
623 scoped_ptr<MDnsTransaction> transaction_privet = 609 scoped_ptr<MDnsTransaction> transaction_privet =
(...skipping 15 matching lines...) Expand all
639 StrictMock<MockListenerDelegate> delegate_privet; 625 StrictMock<MockListenerDelegate> delegate_privet;
640 626
641 PtrRecordCopyContainer record_privet; 627 PtrRecordCopyContainer record_privet;
642 628
643 scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener( 629 scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener(
644 dns_protocol::kTypePTR, "_privet._tcp.local", 630 dns_protocol::kTypePTR, "_privet._tcp.local",
645 &delegate_privet); 631 &delegate_privet);
646 632
647 ASSERT_TRUE(listener_privet->Start()); 633 ASSERT_TRUE(listener_privet->Start());
648 634
649 ASSERT_TRUE(test_client_->IsListeningForTests());
650
651 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_ADDED, _)) 635 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_ADDED, _))
652 .Times(Exactly(1)) 636 .Times(Exactly(1))
653 .WillOnce(Invoke( 637 .WillOnce(Invoke(
654 &record_privet, 638 &record_privet,
655 &PtrRecordCopyContainer::SaveWithDummyArg)); 639 &PtrRecordCopyContainer::SaveWithDummyArg));
656 640
657 SimulatePacketReceive(kSamplePacketAdditionalOnly, 641 SimulatePacketReceive(kSamplePacketAdditionalOnly,
658 sizeof(kSamplePacketAdditionalOnly)); 642 sizeof(kSamplePacketAdditionalOnly));
659 643
660 EXPECT_TRUE(record_privet.IsRecordWith("_privet._tcp.local", 644 EXPECT_TRUE(record_privet.IsRecordWith("_privet._tcp.local",
661 "hello._privet._tcp.local")); 645 "hello._privet._tcp.local"));
662 } 646 }
663 647
664 TEST_F(MDnsTest, TransactionTimeout) { 648 TEST_F(MDnsTest, TransactionTimeout) {
665 ExpectPacket(kQueryPacketPrivet, sizeof(kQueryPacketPrivet)); 649 ExpectPacket(kQueryPacketPrivet, sizeof(kQueryPacketPrivet));
666 650
667 scoped_ptr<MDnsTransaction> transaction_privet = 651 scoped_ptr<MDnsTransaction> transaction_privet =
668 test_client_->CreateTransaction( 652 test_client_->CreateTransaction(
669 dns_protocol::kTypePTR, "_privet._tcp.local", 653 dns_protocol::kTypePTR, "_privet._tcp.local",
670 MDnsTransaction::QUERY_NETWORK | 654 MDnsTransaction::QUERY_NETWORK |
671 MDnsTransaction::QUERY_CACHE | 655 MDnsTransaction::QUERY_CACHE |
672 MDnsTransaction::SINGLE_RESULT, 656 MDnsTransaction::SINGLE_RESULT,
673 base::Bind(&MDnsTest::MockableRecordCallback, 657 base::Bind(&MDnsTest::MockableRecordCallback,
674 base::Unretained(this))); 658 base::Unretained(this)));
675 659
676 ASSERT_TRUE(transaction_privet->Start()); 660 ASSERT_TRUE(transaction_privet->Start());
677 661
678 EXPECT_TRUE(test_client_->IsListeningForTests());
679
680 EXPECT_CALL(*this, 662 EXPECT_CALL(*this,
681 MockableRecordCallback(MDnsTransaction::RESULT_NO_RESULTS, NULL)) 663 MockableRecordCallback(MDnsTransaction::RESULT_NO_RESULTS, NULL))
682 .Times(Exactly(1)) 664 .Times(Exactly(1))
683 .WillOnce(InvokeWithoutArgs(this, &MDnsTest::Stop)); 665 .WillOnce(InvokeWithoutArgs(this, &MDnsTest::Stop));
684 666
685 RunFor(base::TimeDelta::FromSeconds(4)); 667 RunFor(base::TimeDelta::FromSeconds(4));
686 } 668 }
687 669
688 TEST_F(MDnsTest, TransactionMultipleRecords) { 670 TEST_F(MDnsTest, TransactionMultipleRecords) {
689 ExpectPacket(kQueryPacketPrivet, sizeof(kQueryPacketPrivet)); 671 ExpectPacket(kQueryPacketPrivet, sizeof(kQueryPacketPrivet));
690 672
691 scoped_ptr<MDnsTransaction> transaction_privet = 673 scoped_ptr<MDnsTransaction> transaction_privet =
692 test_client_->CreateTransaction( 674 test_client_->CreateTransaction(
693 dns_protocol::kTypePTR, "_privet._tcp.local", 675 dns_protocol::kTypePTR, "_privet._tcp.local",
694 MDnsTransaction::QUERY_NETWORK | 676 MDnsTransaction::QUERY_NETWORK |
695 MDnsTransaction::QUERY_CACHE , 677 MDnsTransaction::QUERY_CACHE ,
696 base::Bind(&MDnsTest::MockableRecordCallback, 678 base::Bind(&MDnsTest::MockableRecordCallback,
697 base::Unretained(this))); 679 base::Unretained(this)));
698 680
699 ASSERT_TRUE(transaction_privet->Start()); 681 ASSERT_TRUE(transaction_privet->Start());
700 682
701 EXPECT_TRUE(test_client_->IsListeningForTests());
702
703 PtrRecordCopyContainer record_privet; 683 PtrRecordCopyContainer record_privet;
704 PtrRecordCopyContainer record_privet2; 684 PtrRecordCopyContainer record_privet2;
705 685
706 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_RECORD, _)) 686 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_RECORD, _))
707 .Times(Exactly(2)) 687 .Times(Exactly(2))
708 .WillOnce(Invoke(&record_privet, 688 .WillOnce(Invoke(&record_privet,
709 &PtrRecordCopyContainer::SaveWithDummyArg)) 689 &PtrRecordCopyContainer::SaveWithDummyArg))
710 .WillOnce(Invoke(&record_privet2, 690 .WillOnce(Invoke(&record_privet2,
711 &PtrRecordCopyContainer::SaveWithDummyArg)); 691 &PtrRecordCopyContainer::SaveWithDummyArg));
712 692
(...skipping 18 matching lines...) Expand all
731 transaction_ = test_client_->CreateTransaction( 711 transaction_ = test_client_->CreateTransaction(
732 dns_protocol::kTypePTR, "_privet._tcp.local", 712 dns_protocol::kTypePTR, "_privet._tcp.local",
733 MDnsTransaction::QUERY_NETWORK | 713 MDnsTransaction::QUERY_NETWORK |
734 MDnsTransaction::QUERY_CACHE | 714 MDnsTransaction::QUERY_CACHE |
735 MDnsTransaction::SINGLE_RESULT, 715 MDnsTransaction::SINGLE_RESULT,
736 base::Bind(&MDnsTest::MockableRecordCallback, 716 base::Bind(&MDnsTest::MockableRecordCallback,
737 base::Unretained(this))); 717 base::Unretained(this)));
738 718
739 ASSERT_TRUE(transaction_->Start()); 719 ASSERT_TRUE(transaction_->Start());
740 720
741 EXPECT_TRUE(test_client_->IsListeningForTests());
742
743 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_NO_RESULTS, 721 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_NO_RESULTS,
744 NULL)) 722 NULL))
745 .Times(Exactly(1)) 723 .Times(Exactly(1))
746 .WillOnce(DoAll(InvokeWithoutArgs(this, &MDnsTest::DeleteTransaction), 724 .WillOnce(DoAll(InvokeWithoutArgs(this, &MDnsTest::DeleteTransaction),
747 InvokeWithoutArgs(this, &MDnsTest::Stop))); 725 InvokeWithoutArgs(this, &MDnsTest::Stop)));
748 726
749 RunFor(base::TimeDelta::FromSeconds(4)); 727 RunFor(base::TimeDelta::FromSeconds(4));
750 728
751 EXPECT_EQ(NULL, transaction_.get()); 729 EXPECT_EQ(NULL, transaction_.get());
752 } 730 }
753 731
754 TEST_F(MDnsTest, TransactionReentrantDeleteFromCache) { 732 TEST_F(MDnsTest, TransactionReentrantDeleteFromCache) {
755 StrictMock<MockListenerDelegate> delegate_irrelevant; 733 StrictMock<MockListenerDelegate> delegate_irrelevant;
756 scoped_ptr<MDnsListener> listener_irrelevant = test_client_->CreateListener( 734 scoped_ptr<MDnsListener> listener_irrelevant = test_client_->CreateListener(
757 dns_protocol::kTypeA, "codereview.chromium.local", 735 dns_protocol::kTypeA, "codereview.chromium.local",
758 &delegate_irrelevant); 736 &delegate_irrelevant);
759 ASSERT_TRUE(listener_irrelevant->Start()); 737 ASSERT_TRUE(listener_irrelevant->Start());
760 738
761 ASSERT_TRUE(test_client_->IsListeningForTests());
762
763 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1)); 739 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1));
764 740
765 transaction_ = test_client_->CreateTransaction( 741 transaction_ = test_client_->CreateTransaction(
766 dns_protocol::kTypePTR, "_privet._tcp.local", 742 dns_protocol::kTypePTR, "_privet._tcp.local",
767 MDnsTransaction::QUERY_NETWORK | 743 MDnsTransaction::QUERY_NETWORK |
768 MDnsTransaction::QUERY_CACHE, 744 MDnsTransaction::QUERY_CACHE,
769 base::Bind(&MDnsTest::MockableRecordCallback, 745 base::Bind(&MDnsTest::MockableRecordCallback,
770 base::Unretained(this))); 746 base::Unretained(this)));
771 747
772 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_RECORD, _)) 748 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_RECORD, _))
(...skipping 28 matching lines...) Expand all
801 .Times(Exactly(1)); 777 .Times(Exactly(1));
802 778
803 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_RECORD, 779 EXPECT_CALL(*this, MockableRecordCallback(MDnsTransaction::RESULT_RECORD,
804 _)) 780 _))
805 .Times(Exactly(1)) 781 .Times(Exactly(1))
806 .WillOnce(IgnoreResult(InvokeWithoutArgs(transaction2.get(), 782 .WillOnce(IgnoreResult(InvokeWithoutArgs(transaction2.get(),
807 &MDnsTransaction::Start))); 783 &MDnsTransaction::Start)));
808 784
809 ASSERT_TRUE(transaction1->Start()); 785 ASSERT_TRUE(transaction1->Start());
810 786
811 EXPECT_TRUE(test_client_->IsListeningForTests());
812
813 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1)); 787 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1));
814 } 788 }
815 789
816 // In order to reliably test reentrant listener deletes, we create two listeners 790 // In order to reliably test reentrant listener deletes, we create two listeners
817 // and have each of them delete both, so we're guaranteed to try and deliver a 791 // and have each of them delete both, so we're guaranteed to try and deliver a
818 // callback to at least one deleted listener. 792 // callback to at least one deleted listener.
819 793
820 TEST_F(MDnsTest, ListenerReentrantDelete) { 794 TEST_F(MDnsTest, ListenerReentrantDelete) {
821 StrictMock<MockListenerDelegate> delegate_privet; 795 StrictMock<MockListenerDelegate> delegate_privet;
822 796
823 listener1_ = test_client_->CreateListener( 797 listener1_ = test_client_->CreateListener(
824 dns_protocol::kTypePTR, "_privet._tcp.local", 798 dns_protocol::kTypePTR, "_privet._tcp.local",
825 &delegate_privet); 799 &delegate_privet);
826 800
827 listener2_ = test_client_->CreateListener( 801 listener2_ = test_client_->CreateListener(
828 dns_protocol::kTypePTR, "_privet._tcp.local", 802 dns_protocol::kTypePTR, "_privet._tcp.local",
829 &delegate_privet); 803 &delegate_privet);
830 804
831 ASSERT_TRUE(listener1_->Start()); 805 ASSERT_TRUE(listener1_->Start());
832 806
833 ASSERT_TRUE(listener2_->Start()); 807 ASSERT_TRUE(listener2_->Start());
834 808
835 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_ADDED, _)) 809 EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_ADDED, _))
836 .Times(Exactly(1)) 810 .Times(Exactly(1))
837 .WillOnce(InvokeWithoutArgs(this, &MDnsTest::DeleteBothListeners)); 811 .WillOnce(InvokeWithoutArgs(this, &MDnsTest::DeleteBothListeners));
838 812
839 EXPECT_TRUE(test_client_->IsListeningForTests());
840
841 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1)); 813 SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1));
842 814
843 EXPECT_EQ(NULL, listener1_.get()); 815 EXPECT_EQ(NULL, listener1_.get());
844 EXPECT_EQ(NULL, listener2_.get()); 816 EXPECT_EQ(NULL, listener2_.get());
845 } 817 }
846 818
847 ACTION_P(SaveIPAddress, ip_container) { 819 ACTION_P(SaveIPAddress, ip_container) {
848 ::testing::StaticAssertTypeEq<const RecordParsed*, arg1_type>(); 820 ::testing::StaticAssertTypeEq<const RecordParsed*, arg1_type>();
849 ::testing::StaticAssertTypeEq<IPAddressNumber*, ip_container_type>(); 821 ::testing::StaticAssertTypeEq<IPAddressNumber*, ip_container_type>();
850 822
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 1110
1139 ASSERT_TRUE(InitConnection()); 1111 ASSERT_TRUE(InitConnection());
1140 1112
1141 EXPECT_CALL(delegate_, OnConnectionError(ERR_SOCKET_NOT_CONNECTED)); 1113 EXPECT_CALL(delegate_, OnConnectionError(ERR_SOCKET_NOT_CONNECTED));
1142 callback.Run(ERR_SOCKET_NOT_CONNECTED); 1114 callback.Run(ERR_SOCKET_NOT_CONNECTED);
1143 } 1115 }
1144 1116
1145 } // namespace 1117 } // namespace
1146 1118
1147 } // namespace net 1119 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/mdns_client_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698