summaryrefslogtreecommitdiffstats
path: root/chrome/utility/local_discovery
diff options
context:
space:
mode:
authornoamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-07 19:21:12 +0000
committernoamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-07 19:21:12 +0000
commit63b43f3ec006affb94b65bb19c40ed61ed96ca47 (patch)
treef045fdaa230afe43a9a70a6eb2d6a00ae210ecf5 /chrome/utility/local_discovery
parent657f34a20f7a3a67302a76e0c2400d821a07e4f5 (diff)
downloadchromium_src-63b43f3ec006affb94b65bb19c40ed61ed96ca47.zip
chromium_src-63b43f3ec006affb94b65bb19c40ed61ed96ca47.tar.gz
chromium_src-63b43f3ec006affb94b65bb19c40ed61ed96ca47.tar.bz2
Fix bug affecting cache lookups with multiple records
In MDns cache lookups with multiple results return the first result over and over again. This is the result of a simple oversight. Fix this and add regression test. BUG= Review URL: https://chromiumcodereview.appspot.com/22472002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216246 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/utility/local_discovery')
-rw-r--r--chrome/utility/local_discovery/service_discovery_client_unittest.cc64
1 files changed, 58 insertions, 6 deletions
diff --git a/chrome/utility/local_discovery/service_discovery_client_unittest.cc b/chrome/utility/local_discovery/service_discovery_client_unittest.cc
index 2f7a15d..43914ee 100644
--- a/chrome/utility/local_discovery/service_discovery_client_unittest.cc
+++ b/chrome/utility/local_discovery/service_discovery_client_unittest.cc
@@ -135,6 +135,40 @@ const uint8 kSamplePacketSRVA[] = {
0x03, 0x04,
};
+const uint8 kSamplePacketPTR2[] = {
+ // Header
+ 0x00, 0x00, // ID is zeroed out
+ 0x81, 0x80, // Standard query response, RA, no error
+ 0x00, 0x00, // No questions (for simplicity)
+ 0x00, 0x02, // 2 RR (answers)
+ 0x00, 0x00, // 0 authority RRs
+ 0x00, 0x00, // 0 additional RRs
+
+ 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't',
+ 0x04, '_', 't', 'c', 'p',
+ 0x05, 'l', 'o', 'c', 'a', 'l',
+ 0x00,
+ 0x00, 0x0c, // TYPE is PTR.
+ 0x00, 0x01, // CLASS is IN.
+ 0x02, 0x00, // TTL (4 bytes) is 1 second.
+ 0x00, 0x01,
+ 0x00, 0x08, // RDLENGTH is 8 bytes.
+ 0x05, 'g', 'd', 'b', 'y', 'e',
+ 0xc0, 0x0c,
+
+ 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't',
+ 0x04, '_', 't', 'c', 'p',
+ 0x05, 'l', 'o', 'c', 'a', 'l',
+ 0x00,
+ 0x00, 0x0c, // TYPE is PTR.
+ 0x00, 0x01, // CLASS is IN.
+ 0x02, 0x00, // TTL (4 bytes) is 1 second.
+ 0x00, 0x01,
+ 0x00, 0x08, // RDLENGTH is 8 bytes.
+ 0x05, 'h', 'e', 'l', 'l', 'o',
+ 0xc0, 0x0c
+};
+
class MockServiceWatcherClient {
public:
MOCK_METHOD2(OnServiceUpdated,
@@ -220,12 +254,6 @@ TEST_F(ServiceDiscoveryTest, DiscoverNewServices) {
};
TEST_F(ServiceDiscoveryTest, ReadCachedServices) {
- scoped_ptr<ServiceWatcher> watcher_irrelevant(
- service_discovery_client_.CreateServiceWatcher(
- "_privet._tcp.local", ServiceWatcher::UpdatedCallback()));
-
- watcher_irrelevant->Start();
-
socket_factory_->SimulateReceive(
kSamplePacketPTR, sizeof(kSamplePacketPTR));
@@ -244,6 +272,30 @@ TEST_F(ServiceDiscoveryTest, ReadCachedServices) {
base::MessageLoop::current()->RunUntilIdle();
};
+
+TEST_F(ServiceDiscoveryTest, ReadCachedServicesMultiple) {
+ socket_factory_->SimulateReceive(
+ kSamplePacketPTR2, sizeof(kSamplePacketPTR2));
+
+ StrictMock<MockServiceWatcherClient> delegate;
+ scoped_ptr<ServiceWatcher> watcher =
+ service_discovery_client_.CreateServiceWatcher(
+ "_privet._tcp.local", delegate.GetCallback());
+
+ watcher->Start();
+
+ EXPECT_CALL(delegate, OnServiceUpdated(ServiceWatcher::UPDATE_ADDED,
+ "hello._privet._tcp.local"))
+ .Times(Exactly(1));
+
+ EXPECT_CALL(delegate, OnServiceUpdated(ServiceWatcher::UPDATE_ADDED,
+ "gdbye._privet._tcp.local"))
+ .Times(Exactly(1));
+
+ base::MessageLoop::current()->RunUntilIdle();
+};
+
+
TEST_F(ServiceDiscoveryTest, OnServiceChanged) {
StrictMock<MockServiceWatcherClient> delegate;
scoped_ptr<ServiceWatcher> watcher(