1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "net/base/network_change_notifier_linux.h" 6 7 #include <unordered_set> 8 9 #include "base/functional/callback_helpers.h" 10 #include "base/test/task_environment.h" 11 #include "net/base/address_map_linux.h" 12 #include "net/base/address_tracker_linux.h" 13 #include "net/dns/dns_config_service.h" 14 #include "net/dns/system_dns_config_change_notifier.h" 15 #include "testing/gtest/include/gtest/gtest.h" 16 17 namespace net { 18 19 class NetworkChangeNotifierLinuxTest : public testing::Test { 20 public: 21 NetworkChangeNotifierLinuxTest() = default; 22 NetworkChangeNotifierLinuxTest(const NetworkChangeNotifierLinuxTest&) = 23 delete; 24 NetworkChangeNotifierLinuxTest& operator=( 25 const NetworkChangeNotifierLinuxTest&) = delete; 26 ~NetworkChangeNotifierLinuxTest() override = default; 27 CreateNotifier()28 void CreateNotifier() { 29 // Use a noop DNS notifier. 30 dns_config_notifier_ = std::make_unique<SystemDnsConfigChangeNotifier>( 31 nullptr /* task_runner */, nullptr /* dns_config_service */); 32 notifier_ = std::make_unique<NetworkChangeNotifierLinux>( 33 std::unordered_set<std::string>()); 34 } 35 TearDown()36 void TearDown() override { base::RunLoop().RunUntilIdle(); } 37 38 protected: 39 base::test::TaskEnvironment task_environment_; 40 41 // Allows us to allocate our own NetworkChangeNotifier for unit testing. 42 NetworkChangeNotifier::DisableForTest disable_for_test_; 43 std::unique_ptr<SystemDnsConfigChangeNotifier> dns_config_notifier_; 44 std::unique_ptr<NetworkChangeNotifierLinux> notifier_; 45 }; 46 47 // https://crbug.com/1441671 TEST_F(NetworkChangeNotifierLinuxTest,AddressTrackerLinuxSetDiffCallback)48TEST_F(NetworkChangeNotifierLinuxTest, AddressTrackerLinuxSetDiffCallback) { 49 CreateNotifier(); 50 AddressMapOwnerLinux* address_map_owner = notifier_->GetAddressMapOwner(); 51 ASSERT_TRUE(address_map_owner); 52 internal::AddressTrackerLinux* address_tracker_linux = 53 address_map_owner->GetAddressTrackerLinux(); 54 ASSERT_TRUE(address_tracker_linux); 55 address_tracker_linux->GetInitialDataAndStartRecordingDiffs(); 56 address_tracker_linux->SetDiffCallback(base::DoNothing()); 57 } 58 59 } // namespace net 60