summaryrefslogtreecommitdiff
path: root/chromium/net/dns/mdns_client_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/net/dns/mdns_client_unittest.cc')
-rw-r--r--chromium/net/dns/mdns_client_unittest.cc198
1 files changed, 85 insertions, 113 deletions
diff --git a/chromium/net/dns/mdns_client_unittest.cc b/chromium/net/dns/mdns_client_unittest.cc
index f524a5401c7..7ea4ac97448 100644
--- a/chromium/net/dns/mdns_client_unittest.cc
+++ b/chromium/net/dns/mdns_client_unittest.cc
@@ -372,10 +372,7 @@ class PtrRecordCopyContainer {
class MDnsTest : public ::testing::Test {
public:
- MDnsTest();
- virtual ~MDnsTest();
virtual void SetUp() OVERRIDE;
- virtual void TearDown() OVERRIDE;
void DeleteTransaction();
void DeleteBothListeners();
void RunFor(base::TimeDelta time_period);
@@ -392,9 +389,9 @@ class MDnsTest : public ::testing::Test {
void ExpectPacket(const uint8* packet, unsigned size);
void SimulatePacketReceive(const uint8* packet, unsigned size);
- scoped_ptr<MDnsClientImpl> test_client_;
+ MDnsClientImpl test_client_;
IPEndPoint mdns_ipv4_endpoint_;
- StrictMock<MockMDnsSocketFactory>* socket_factory_;
+ StrictMock<MockMDnsSocketFactory> socket_factory_;
// Transactions and listeners that can be deleted by class methods for
// reentrancy tests.
@@ -412,28 +409,16 @@ class MockListenerDelegate : public MDnsListener::Delegate {
MOCK_METHOD0(OnCachePurged, void());
};
-MDnsTest::MDnsTest() {
- socket_factory_ = new StrictMock<MockMDnsSocketFactory>();
- test_client_.reset(new MDnsClientImpl(
- scoped_ptr<MDnsConnection::SocketFactory>(socket_factory_)));
-}
-
-MDnsTest::~MDnsTest() {
-}
-
void MDnsTest::SetUp() {
- test_client_->StartListening();
-}
-
-void MDnsTest::TearDown() {
+ test_client_.StartListening(&socket_factory_);
}
void MDnsTest::SimulatePacketReceive(const uint8* packet, unsigned size) {
- socket_factory_->SimulateReceive(packet, size);
+ socket_factory_.SimulateReceive(packet, size);
}
void MDnsTest::ExpectPacket(const uint8* packet, unsigned size) {
- EXPECT_CALL(*socket_factory_, OnSendTo(MakeString(packet, size)))
+ EXPECT_CALL(socket_factory_, OnSendTo(MakeString(packet, size)))
.Times(2);
}
@@ -467,10 +452,12 @@ TEST_F(MDnsTest, PassiveListeners) {
PtrRecordCopyContainer record_privet;
PtrRecordCopyContainer record_printer;
- scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener(
- dns_protocol::kTypePTR, "_privet._tcp.local", &delegate_privet);
- scoped_ptr<MDnsListener> listener_printer = test_client_->CreateListener(
- dns_protocol::kTypePTR, "_printer._tcp.local", &delegate_printer);
+ scoped_ptr<MDnsListener> listener_privet =
+ test_client_.CreateListener(dns_protocol::kTypePTR, "_privet._tcp.local",
+ &delegate_privet);
+ scoped_ptr<MDnsListener> listener_printer =
+ test_client_.CreateListener(dns_protocol::kTypePTR, "_printer._tcp.local",
+ &delegate_printer);
ASSERT_TRUE(listener_privet->Start());
ASSERT_TRUE(listener_printer->Start());
@@ -509,8 +496,9 @@ TEST_F(MDnsTest, PassiveListenersCacheCleanup) {
PtrRecordCopyContainer record_privet;
PtrRecordCopyContainer record_privet2;
- scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener(
- dns_protocol::kTypePTR, "_privet._tcp.local", &delegate_privet);
+ scoped_ptr<MDnsListener> listener_privet =
+ test_client_.CreateListener(dns_protocol::kTypePTR, "_privet._tcp.local",
+ &delegate_privet);
ASSERT_TRUE(listener_privet->Start());
@@ -543,8 +531,9 @@ TEST_F(MDnsTest, MalformedPacket) {
PtrRecordCopyContainer record_printer;
- scoped_ptr<MDnsListener> listener_printer = test_client_->CreateListener(
- dns_protocol::kTypePTR, "_printer._tcp.local", &delegate_printer);
+ scoped_ptr<MDnsListener> listener_printer =
+ test_client_.CreateListener(dns_protocol::kTypePTR, "_printer._tcp.local",
+ &delegate_printer);
ASSERT_TRUE(listener_printer->Start());
@@ -574,7 +563,7 @@ TEST_F(MDnsTest, TransactionWithEmptyCache) {
ExpectPacket(kQueryPacketPrivet, sizeof(kQueryPacketPrivet));
scoped_ptr<MDnsTransaction> transaction_privet =
- test_client_->CreateTransaction(
+ test_client_.CreateTransaction(
dns_protocol::kTypePTR, "_privet._tcp.local",
MDnsTransaction::QUERY_NETWORK |
MDnsTransaction::QUERY_CACHE |
@@ -599,7 +588,7 @@ TEST_F(MDnsTest, TransactionWithEmptyCache) {
TEST_F(MDnsTest, TransactionCacheOnlyNoResult) {
scoped_ptr<MDnsTransaction> transaction_privet =
- test_client_->CreateTransaction(
+ test_client_.CreateTransaction(
dns_protocol::kTypePTR, "_privet._tcp.local",
MDnsTransaction::QUERY_CACHE |
MDnsTransaction::SINGLE_RESULT,
@@ -616,9 +605,10 @@ TEST_F(MDnsTest, TransactionCacheOnlyNoResult) {
TEST_F(MDnsTest, TransactionWithCache) {
// Listener to force the client to listen
StrictMock<MockListenerDelegate> delegate_irrelevant;
- scoped_ptr<MDnsListener> listener_irrelevant = test_client_->CreateListener(
- dns_protocol::kTypeA, "codereview.chromium.local",
- &delegate_irrelevant);
+ scoped_ptr<MDnsListener> listener_irrelevant =
+ test_client_.CreateListener(dns_protocol::kTypeA,
+ "codereview.chromium.local",
+ &delegate_irrelevant);
ASSERT_TRUE(listener_irrelevant->Start());
@@ -632,7 +622,7 @@ TEST_F(MDnsTest, TransactionWithCache) {
&PtrRecordCopyContainer::SaveWithDummyArg));
scoped_ptr<MDnsTransaction> transaction_privet =
- test_client_->CreateTransaction(
+ test_client_.CreateTransaction(
dns_protocol::kTypePTR, "_privet._tcp.local",
MDnsTransaction::QUERY_NETWORK |
MDnsTransaction::QUERY_CACHE |
@@ -651,9 +641,9 @@ TEST_F(MDnsTest, AdditionalRecords) {
PtrRecordCopyContainer record_privet;
- scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener(
- dns_protocol::kTypePTR, "_privet._tcp.local",
- &delegate_privet);
+ scoped_ptr<MDnsListener> listener_privet =
+ test_client_.CreateListener(dns_protocol::kTypePTR, "_privet._tcp.local",
+ &delegate_privet);
ASSERT_TRUE(listener_privet->Start());
@@ -674,7 +664,7 @@ TEST_F(MDnsTest, TransactionTimeout) {
ExpectPacket(kQueryPacketPrivet, sizeof(kQueryPacketPrivet));
scoped_ptr<MDnsTransaction> transaction_privet =
- test_client_->CreateTransaction(
+ test_client_.CreateTransaction(
dns_protocol::kTypePTR, "_privet._tcp.local",
MDnsTransaction::QUERY_NETWORK |
MDnsTransaction::QUERY_CACHE |
@@ -696,7 +686,7 @@ TEST_F(MDnsTest, TransactionMultipleRecords) {
ExpectPacket(kQueryPacketPrivet, sizeof(kQueryPacketPrivet));
scoped_ptr<MDnsTransaction> transaction_privet =
- test_client_->CreateTransaction(
+ test_client_.CreateTransaction(
dns_protocol::kTypePTR, "_privet._tcp.local",
MDnsTransaction::QUERY_NETWORK |
MDnsTransaction::QUERY_CACHE ,
@@ -733,7 +723,7 @@ TEST_F(MDnsTest, TransactionMultipleRecords) {
TEST_F(MDnsTest, TransactionReentrantDelete) {
ExpectPacket(kQueryPacketPrivet, sizeof(kQueryPacketPrivet));
- transaction_ = test_client_->CreateTransaction(
+ transaction_ = test_client_.CreateTransaction(
dns_protocol::kTypePTR, "_privet._tcp.local",
MDnsTransaction::QUERY_NETWORK |
MDnsTransaction::QUERY_CACHE |
@@ -756,14 +746,14 @@ TEST_F(MDnsTest, TransactionReentrantDelete) {
TEST_F(MDnsTest, TransactionReentrantDeleteFromCache) {
StrictMock<MockListenerDelegate> delegate_irrelevant;
- scoped_ptr<MDnsListener> listener_irrelevant = test_client_->CreateListener(
+ scoped_ptr<MDnsListener> listener_irrelevant = test_client_.CreateListener(
dns_protocol::kTypeA, "codereview.chromium.local",
&delegate_irrelevant);
ASSERT_TRUE(listener_irrelevant->Start());
SimulatePacketReceive(kSamplePacket1, sizeof(kSamplePacket1));
- transaction_ = test_client_->CreateTransaction(
+ transaction_ = test_client_.CreateTransaction(
dns_protocol::kTypePTR, "_privet._tcp.local",
MDnsTransaction::QUERY_NETWORK |
MDnsTransaction::QUERY_CACHE,
@@ -782,20 +772,22 @@ TEST_F(MDnsTest, TransactionReentrantDeleteFromCache) {
TEST_F(MDnsTest, TransactionReentrantCacheLookupStart) {
ExpectPacket(kQueryPacketPrivet, sizeof(kQueryPacketPrivet));
- scoped_ptr<MDnsTransaction> transaction1 = test_client_->CreateTransaction(
- dns_protocol::kTypePTR, "_privet._tcp.local",
- MDnsTransaction::QUERY_NETWORK |
- MDnsTransaction::QUERY_CACHE |
- MDnsTransaction::SINGLE_RESULT,
- base::Bind(&MDnsTest::MockableRecordCallback,
- base::Unretained(this)));
+ scoped_ptr<MDnsTransaction> transaction1 =
+ test_client_.CreateTransaction(
+ dns_protocol::kTypePTR, "_privet._tcp.local",
+ MDnsTransaction::QUERY_NETWORK |
+ MDnsTransaction::QUERY_CACHE |
+ MDnsTransaction::SINGLE_RESULT,
+ base::Bind(&MDnsTest::MockableRecordCallback,
+ base::Unretained(this)));
- scoped_ptr<MDnsTransaction> transaction2 = test_client_->CreateTransaction(
- dns_protocol::kTypePTR, "_printer._tcp.local",
- MDnsTransaction::QUERY_CACHE |
- MDnsTransaction::SINGLE_RESULT,
- base::Bind(&MDnsTest::MockableRecordCallback2,
- base::Unretained(this)));
+ scoped_ptr<MDnsTransaction> transaction2 =
+ test_client_.CreateTransaction(
+ dns_protocol::kTypePTR, "_printer._tcp.local",
+ MDnsTransaction::QUERY_CACHE |
+ MDnsTransaction::SINGLE_RESULT,
+ base::Bind(&MDnsTest::MockableRecordCallback2,
+ base::Unretained(this)));
EXPECT_CALL(*this, MockableRecordCallback2(MDnsTransaction::RESULT_RECORD,
_))
@@ -815,7 +807,7 @@ TEST_F(MDnsTest, TransactionReentrantCacheLookupStart) {
TEST_F(MDnsTest, GoodbyePacketNotification) {
StrictMock<MockListenerDelegate> delegate_privet;
- scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener(
+ scoped_ptr<MDnsListener> listener_privet = test_client_.CreateListener(
dns_protocol::kTypePTR, "_privet._tcp.local", &delegate_privet);
ASSERT_TRUE(listener_privet->Start());
@@ -827,8 +819,9 @@ TEST_F(MDnsTest, GoodbyePacketNotification) {
TEST_F(MDnsTest, GoodbyePacketRemoval) {
StrictMock<MockListenerDelegate> delegate_privet;
- scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener(
- dns_protocol::kTypePTR, "_privet._tcp.local", &delegate_privet);
+ scoped_ptr<MDnsListener> listener_privet =
+ test_client_.CreateListener(dns_protocol::kTypePTR, "_privet._tcp.local",
+ &delegate_privet);
ASSERT_TRUE(listener_privet->Start());
EXPECT_CALL(delegate_privet, OnRecordUpdate(MDnsListener::RECORD_ADDED, _))
@@ -851,13 +844,13 @@ TEST_F(MDnsTest, GoodbyePacketRemoval) {
TEST_F(MDnsTest, ListenerReentrantDelete) {
StrictMock<MockListenerDelegate> delegate_privet;
- listener1_ = test_client_->CreateListener(
- dns_protocol::kTypePTR, "_privet._tcp.local",
- &delegate_privet);
+ listener1_ = test_client_.CreateListener(dns_protocol::kTypePTR,
+ "_privet._tcp.local",
+ &delegate_privet);
- listener2_ = test_client_->CreateListener(
- dns_protocol::kTypePTR, "_privet._tcp.local",
- &delegate_privet);
+ listener2_ = test_client_.CreateListener(dns_protocol::kTypePTR,
+ "_privet._tcp.local",
+ &delegate_privet);
ASSERT_TRUE(listener1_->Start());
@@ -884,8 +877,9 @@ TEST_F(MDnsTest, DoubleRecordDisagreeing) {
IPAddressNumber address;
StrictMock<MockListenerDelegate> delegate_privet;
- scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener(
- dns_protocol::kTypeA, "privet.local", &delegate_privet);
+ scoped_ptr<MDnsListener> listener_privet =
+ test_client_.CreateListener(dns_protocol::kTypeA, "privet.local",
+ &delegate_privet);
ASSERT_TRUE(listener_privet->Start());
@@ -901,14 +895,16 @@ TEST_F(MDnsTest, DoubleRecordDisagreeing) {
TEST_F(MDnsTest, NsecWithListener) {
StrictMock<MockListenerDelegate> delegate_privet;
- scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener(
- dns_protocol::kTypeA, "_privet._tcp.local", &delegate_privet);
+ scoped_ptr<MDnsListener> listener_privet =
+ test_client_.CreateListener(dns_protocol::kTypeA, "_privet._tcp.local",
+ &delegate_privet);
// Test to make sure nsec callback is NOT called for PTR
// (which is marked as existing).
StrictMock<MockListenerDelegate> delegate_privet2;
- scoped_ptr<MDnsListener> listener_privet2 = test_client_->CreateListener(
- dns_protocol::kTypePTR, "_privet._tcp.local", &delegate_privet2);
+ scoped_ptr<MDnsListener> listener_privet2 =
+ test_client_.CreateListener(dns_protocol::kTypePTR, "_privet._tcp.local",
+ &delegate_privet2);
ASSERT_TRUE(listener_privet->Start());
@@ -921,7 +917,7 @@ TEST_F(MDnsTest, NsecWithListener) {
TEST_F(MDnsTest, NsecWithTransactionFromNetwork) {
scoped_ptr<MDnsTransaction> transaction_privet =
- test_client_->CreateTransaction(
+ test_client_.CreateTransaction(
dns_protocol::kTypeA, "_privet._tcp.local",
MDnsTransaction::QUERY_NETWORK |
MDnsTransaction::QUERY_CACHE |
@@ -929,8 +925,7 @@ TEST_F(MDnsTest, NsecWithTransactionFromNetwork) {
base::Bind(&MDnsTest::MockableRecordCallback,
base::Unretained(this)));
- EXPECT_CALL(*socket_factory_, OnSendTo(_))
- .Times(2);
+ EXPECT_CALL(socket_factory_, OnSendTo(_)).Times(2);
ASSERT_TRUE(transaction_privet->Start());
@@ -945,8 +940,8 @@ TEST_F(MDnsTest, NsecWithTransactionFromCache) {
// Force mDNS to listen.
StrictMock<MockListenerDelegate> delegate_irrelevant;
scoped_ptr<MDnsListener> listener_irrelevant =
- test_client_->CreateListener(dns_protocol::kTypePTR, "_privet._tcp.local",
- &delegate_irrelevant);
+ test_client_.CreateListener(dns_protocol::kTypePTR, "_privet._tcp.local",
+ &delegate_irrelevant);
listener_irrelevant->Start();
SimulatePacketReceive(kSamplePacketNsec,
@@ -956,7 +951,7 @@ TEST_F(MDnsTest, NsecWithTransactionFromCache) {
MockableRecordCallback(MDnsTransaction::RESULT_NSEC, NULL));
scoped_ptr<MDnsTransaction> transaction_privet_a =
- test_client_->CreateTransaction(
+ test_client_.CreateTransaction(
dns_protocol::kTypeA, "_privet._tcp.local",
MDnsTransaction::QUERY_NETWORK |
MDnsTransaction::QUERY_CACHE |
@@ -970,7 +965,7 @@ TEST_F(MDnsTest, NsecWithTransactionFromCache) {
// valid answer to the query
scoped_ptr<MDnsTransaction> transaction_privet_ptr =
- test_client_->CreateTransaction(
+ test_client_.CreateTransaction(
dns_protocol::kTypePTR, "_privet._tcp.local",
MDnsTransaction::QUERY_NETWORK |
MDnsTransaction::QUERY_CACHE |
@@ -978,16 +973,16 @@ TEST_F(MDnsTest, NsecWithTransactionFromCache) {
base::Bind(&MDnsTest::MockableRecordCallback,
base::Unretained(this)));
- EXPECT_CALL(*socket_factory_, OnSendTo(_))
- .Times(2);
+ EXPECT_CALL(socket_factory_, OnSendTo(_)).Times(2);
ASSERT_TRUE(transaction_privet_ptr->Start());
}
TEST_F(MDnsTest, NsecConflictRemoval) {
StrictMock<MockListenerDelegate> delegate_privet;
- scoped_ptr<MDnsListener> listener_privet = test_client_->CreateListener(
- dns_protocol::kTypeA, "_privet._tcp.local", &delegate_privet);
+ scoped_ptr<MDnsListener> listener_privet =
+ test_client_.CreateListener(dns_protocol::kTypeA, "_privet._tcp.local",
+ &delegate_privet);
ASSERT_TRUE(listener_privet->Start());
@@ -1015,27 +1010,20 @@ TEST_F(MDnsTest, NsecConflictRemoval) {
// Note: These tests assume that the ipv4 socket will always be created first.
// This is a simplifying assumption based on the way the code works now.
-
-class SimpleMockSocketFactory
- : public MDnsConnection::SocketFactory {
+class SimpleMockSocketFactory : public MDnsSocketFactory {
public:
- SimpleMockSocketFactory() {
- }
- virtual ~SimpleMockSocketFactory() {
- }
-
- virtual scoped_ptr<DatagramServerSocket> CreateSocket() OVERRIDE {
- MockMDnsDatagramServerSocket* socket = sockets_.back();
- sockets_.weak_erase(sockets_.end() - 1);
- return scoped_ptr<DatagramServerSocket>(socket);
+ virtual void CreateSockets(
+ ScopedVector<DatagramServerSocket>* sockets) OVERRIDE {
+ sockets->clear();
+ sockets->swap(sockets_);
}
- void PushSocket(MockMDnsDatagramServerSocket* socket) {
+ void PushSocket(DatagramServerSocket* socket) {
sockets_.push_back(socket);
}
private:
- ScopedVector<MockMDnsDatagramServerSocket> sockets_;
+ ScopedVector<DatagramServerSocket> sockets_;
};
class MockMDnsConnectionDelegate : public MDnsConnection::Delegate {
@@ -1057,29 +1045,13 @@ class MDnsConnectionTest : public ::testing::Test {
protected:
// Follow successful connection initialization.
virtual void SetUp() OVERRIDE {
- socket_ipv4_ = new MockMDnsDatagramServerSocket;
- socket_ipv6_ = new MockMDnsDatagramServerSocket;
+ socket_ipv4_ = new MockMDnsDatagramServerSocket(ADDRESS_FAMILY_IPV4);
+ socket_ipv6_ = new MockMDnsDatagramServerSocket(ADDRESS_FAMILY_IPV6);
factory_.PushSocket(socket_ipv6_);
factory_.PushSocket(socket_ipv4_);
}
bool InitConnection() {
- EXPECT_CALL(*socket_ipv4_, AllowAddressReuse());
- EXPECT_CALL(*socket_ipv6_, AllowAddressReuse());
-
- EXPECT_CALL(*socket_ipv4_, SetMulticastLoopbackMode(false));
- EXPECT_CALL(*socket_ipv6_, SetMulticastLoopbackMode(false));
-
- EXPECT_CALL(*socket_ipv4_, ListenInternal("0.0.0.0:5353"))
- .WillOnce(Return(OK));
- EXPECT_CALL(*socket_ipv6_, ListenInternal("[::]:5353"))
- .WillOnce(Return(OK));
-
- EXPECT_CALL(*socket_ipv4_, JoinGroupInternal("224.0.0.251"))
- .WillOnce(Return(OK));
- EXPECT_CALL(*socket_ipv6_, JoinGroupInternal("ff02::fb"))
- .WillOnce(Return(OK));
-
return connection_.Init(&factory_);
}