OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/base/network.h" | 11 #include "webrtc/base/network.h" |
12 | 12 |
| 13 #include "webrtc/base/networkchangenotifier.h" |
13 #include <vector> | 14 #include <vector> |
14 #if defined(WEBRTC_POSIX) | 15 #if defined(WEBRTC_POSIX) |
15 #include <sys/types.h> | 16 #include <sys/types.h> |
16 #if !defined(WEBRTC_ANDROID) | 17 #if !defined(WEBRTC_ANDROID) |
17 #include <ifaddrs.h> | 18 #include <ifaddrs.h> |
18 #else | 19 #else |
19 #include "webrtc/base/ifaddrs-android.h" | 20 #include "webrtc/base/ifaddrs-android.h" |
20 #endif | 21 #endif |
21 #endif | 22 #endif |
22 #include "webrtc/base/gunit.h" | 23 #include "webrtc/base/gunit.h" |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 ipv6_network.AddIP(ip); | 784 ipv6_network.AddIP(ip); |
784 EXPECT_EQ(ipv6_network.GetBestIP(), static_cast<IPAddress>(ip)); | 785 EXPECT_EQ(ipv6_network.GetBestIP(), static_cast<IPAddress>(ip)); |
785 | 786 |
786 // Add global dynamic temporary one. | 787 // Add global dynamic temporary one. |
787 ipstr = "2401:fa00:4:1000:be30:5bff:fee5:c6"; | 788 ipstr = "2401:fa00:4:1000:be30:5bff:fee5:c6"; |
788 ASSERT_TRUE(IPFromString(ipstr, IPV6_ADDRESS_FLAG_TEMPORARY, &ip)); | 789 ASSERT_TRUE(IPFromString(ipstr, IPV6_ADDRESS_FLAG_TEMPORARY, &ip)); |
789 ipv6_network.AddIP(ip); | 790 ipv6_network.AddIP(ip); |
790 EXPECT_EQ(ipv6_network.GetBestIP(), static_cast<IPAddress>(ip)); | 791 EXPECT_EQ(ipv6_network.GetBestIP(), static_cast<IPAddress>(ip)); |
791 } | 792 } |
792 | 793 |
| 794 TEST_F(NetworkTest, TestNetworkChangeNotified) { |
| 795 BasicNetworkManager manager; |
| 796 manager.SignalNetworksChanged.connect( |
| 797 static_cast<NetworkTest*>(this), &NetworkTest::OnNetworksChanged); |
| 798 scoped_ptr<NetworkChangeNotifierFactory> factory( |
| 799 NetworkChangeNotifierFactory::CreateFactory()); |
| 800 NetworkChangeNotifier::SetFactory(factory.get()); |
| 801 NetworkChangeNotifierDelegate* delegate = factory->CreateDelegate(); |
| 802 manager.StartUpdating(); |
| 803 Thread::Current()->ProcessMessages(0); |
| 804 EXPECT_TRUE(callback_called_); |
| 805 callback_called_ = false; |
| 806 |
| 807 // Network manager is started, so the callback is called when the delegate |
| 808 // fires the network-change event. |
| 809 delegate->OnNetworkChangeNotified(); |
| 810 Thread::Current()->ProcessMessages(0); |
| 811 EXPECT_TRUE(callback_called_); |
| 812 callback_called_ = false; |
| 813 |
| 814 // Network manager is stopped, so the callback is not called when the delegate |
| 815 // fires the network-change event. |
| 816 manager.StopUpdating(); |
| 817 delegate->OnNetworkChangeNotified(); |
| 818 Thread::Current()->ProcessMessages(1000); |
| 819 EXPECT_FALSE(callback_called_); |
| 820 } |
| 821 |
793 } // namespace rtc | 822 } // namespace rtc |
OLD | NEW |