0

Fix and re-enable NetworkChangeNotifierAndroidTest.InitialSignal

NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead()
may not be called if the initial DNS config has been read
prior to the DNSObserver being registered.  HostResolverImpl
accounts for this already, but the test did not.  I've
updated the test and added an API comment to explain this.

Bug: 833659
Change-Id: I0c7eeb296a990fb69c9f0fac58483243079c3481
Reviewed-on: https://chromium-review.googlesource.com/1035222
Reviewed-by: Helen Li <xunjieli@chromium.org>
Commit-Queue: Paul Jensen <pauljensen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556060}
This commit is contained in:
Paul Jensen
2018-05-04 15:12:15 +00:00
committed by Commit Bot
parent 2ad2b06d37
commit 1ef04a37ab
2 changed files with 13 additions and 4 deletions

@ -420,12 +420,16 @@ TEST_F(NetworkChangeNotifierDelegateAndroidTest,
EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count());
}
TEST_F(NetworkChangeNotifierAndroidTest, DISABLED_InitialSignal) {
TEST_F(NetworkChangeNotifierAndroidTest, InitialSignal) {
DNSChangeObserver dns_change_observer;
NetworkChangeNotifier::AddDNSObserver(&dns_change_observer);
base::RunLoop().Run();
EXPECT_EQ(1, dns_change_observer.initial_notifications_count());
EXPECT_EQ(0, dns_change_observer.change_notifications_count());
net::DnsConfig dns_config;
NetworkChangeNotifier::GetDnsConfig(&dns_config);
if (!dns_config.IsValid()) {
base::RunLoop().Run();
EXPECT_EQ(1, dns_change_observer.initial_notifications_count());
EXPECT_EQ(0, dns_change_observer.change_notifications_count());
}
NetworkChangeNotifier::RemoveDNSObserver(&dns_change_observer);
}

@ -141,6 +141,11 @@ class NET_EXPORT NetworkChangeNotifier {
virtual void OnDNSChanged() = 0;
// Will be called when DNS settings of the system have been loaded.
// Use GetDnsConfig to obtain the current settings.
// NOTE(pauljensen): This will not be called if the initial DNS config
// has already been read before this observer is registered.
// Determining if a DNS config has already been read can be done by
// calling GetDnsConfig() after registering an observer, and seeing if
// the DnsConfig's IsValid() returns true.
virtual void OnInitialDNSConfigRead();
protected: