OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/udp/udp_socket.h" | 5 #include "net/udp/udp_socket.h" |
6 | 6 |
7 #include "net/udp/udp_client_socket.h" | 7 #include "net/udp/udp_client_socket.h" |
8 #include "net/udp/udp_server_socket.h" | 8 #include "net/udp/udp_server_socket.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "net/base/test_completion_callback.h" | 22 #include "net/base/test_completion_callback.h" |
23 #include "net/log/test_net_log.h" | 23 #include "net/log/test_net_log.h" |
24 #include "net/log/test_net_log_entry.h" | 24 #include "net/log/test_net_log_entry.h" |
25 #include "net/log/test_net_log_util.h" | 25 #include "net/log/test_net_log_util.h" |
26 #include "net/test/gtest_util.h" | 26 #include "net/test/gtest_util.h" |
27 #include "net/test/net_test_suite.h" | 27 #include "net/test/net_test_suite.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "testing/platform_test.h" | 30 #include "testing/platform_test.h" |
31 | 31 |
| 32 #if defined(OS_ANDROID) |
| 33 #include "base/android/build_info.h" |
| 34 #endif |
| 35 |
32 #if defined(OS_IOS) | 36 #if defined(OS_IOS) |
33 #include <TargetConditionals.h> | 37 #include <TargetConditionals.h> |
34 #endif | 38 #endif |
35 | 39 |
36 using net::test::IsError; | 40 using net::test::IsError; |
37 using net::test::IsOk; | 41 using net::test::IsOk; |
38 | 42 |
39 namespace net { | 43 namespace net { |
40 | 44 |
41 namespace { | 45 namespace { |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 | 684 |
681 client.SetDiffServCodePoint(DSCP_NO_CHANGE); | 685 client.SetDiffServCodePoint(DSCP_NO_CHANGE); |
682 client.SetDiffServCodePoint(DSCP_AF41); | 686 client.SetDiffServCodePoint(DSCP_AF41); |
683 client.SetDiffServCodePoint(DSCP_DEFAULT); | 687 client.SetDiffServCodePoint(DSCP_DEFAULT); |
684 client.SetDiffServCodePoint(DSCP_CS2); | 688 client.SetDiffServCodePoint(DSCP_CS2); |
685 client.SetDiffServCodePoint(DSCP_NO_CHANGE); | 689 client.SetDiffServCodePoint(DSCP_NO_CHANGE); |
686 client.SetDiffServCodePoint(DSCP_DEFAULT); | 690 client.SetDiffServCodePoint(DSCP_DEFAULT); |
687 client.Close(); | 691 client.Close(); |
688 } | 692 } |
689 | 693 |
| 694 TEST_F(UDPSocketTest, TestBindToNetwork) { |
| 695 UDPSocket socket(DatagramSocket::RANDOM_BIND, base::Bind(&PrivilegedRand), |
| 696 NULL, NetLog::Source()); |
| 697 ASSERT_EQ(OK, socket.Open(ADDRESS_FAMILY_IPV4)); |
| 698 // Test unsuccessful binding, by attempting to bind to a bogus NetworkHandle. |
| 699 int rv = socket.BindToNetwork(65536); |
| 700 #if !defined(OS_ANDROID) |
| 701 EXPECT_EQ(ERR_NOT_IMPLEMENTED, rv); |
| 702 #else |
| 703 if (base::android::BuildInfo::GetInstance()->sdk_int() < |
| 704 base::android::SDK_VERSION_LOLLIPOP) { |
| 705 EXPECT_EQ(ERR_NOT_IMPLEMENTED, rv); |
| 706 } else if (base::android::BuildInfo::GetInstance()->sdk_int() >= |
| 707 base::android::SDK_VERSION_LOLLIPOP && |
| 708 base::android::BuildInfo::GetInstance()->sdk_int() < |
| 709 base::android::SDK_VERSION_MARSHMALLOW) { |
| 710 // On Lollipop, we assume if the user has a NetworkHandle that they must |
| 711 // have gotten it from a legitimate source, so if binding to the network |
| 712 // fails it's assumed to be because the network went away so |
| 713 // ERR_NETWORK_CHANGED is returned. In this test the network never existed |
| 714 // anyhow. ConnectivityService.MAX_NET_ID is 65535, so 65536 won't be used. |
| 715 EXPECT_EQ(ERR_NETWORK_CHANGED, rv); |
| 716 } else if (base::android::BuildInfo::GetInstance()->sdk_int() >= |
| 717 base::android::SDK_VERSION_MARSHMALLOW) { |
| 718 // On Marshmallow and newer releases, the NetworkHandle is munged by |
| 719 // Network.getNetworkHandle() and 65536 isn't munged so it's rejected. |
| 720 EXPECT_EQ(ERR_INVALID_ARGUMENT, rv); |
| 721 } |
| 722 |
| 723 if (base::android::BuildInfo::GetInstance()->sdk_int() >= |
| 724 base::android::SDK_VERSION_LOLLIPOP) { |
| 725 EXPECT_EQ( |
| 726 ERR_INVALID_ARGUMENT, |
| 727 socket.BindToNetwork(NetworkChangeNotifier::kInvalidNetworkHandle)); |
| 728 |
| 729 // Test successful binding, if possible. |
| 730 if (NetworkChangeNotifier::AreNetworkHandlesSupported()) { |
| 731 NetworkChangeNotifier::NetworkHandle network_handle = |
| 732 NetworkChangeNotifier::GetDefaultNetwork(); |
| 733 if (network_handle != NetworkChangeNotifier::kInvalidNetworkHandle) { |
| 734 EXPECT_EQ(OK, socket.BindToNetwork(network_handle)); |
| 735 } |
| 736 } |
| 737 } |
| 738 #endif |
| 739 } |
| 740 |
690 } // namespace | 741 } // namespace |
691 | 742 |
692 #if defined(OS_WIN) | 743 #if defined(OS_WIN) |
693 | 744 |
694 namespace { | 745 namespace { |
695 | 746 |
696 const HANDLE kFakeHandle = (HANDLE)19; | 747 const HANDLE kFakeHandle = (HANDLE)19; |
697 const QOS_FLOWID kFakeFlowId = (QOS_FLOWID)27; | 748 const QOS_FLOWID kFakeFlowId = (QOS_FLOWID)27; |
698 | 749 |
699 BOOL WINAPI FakeQOSCreateHandleFAIL(PQOS_VERSION version, PHANDLE handle) { | 750 BOOL WINAPI FakeQOSCreateHandleFAIL(PQOS_VERSION version, PHANDLE handle) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 g_expected_traffic_type = QOSTrafficTypeExcellentEffort; | 859 g_expected_traffic_type = QOSTrafficTypeExcellentEffort; |
809 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_NO_CHANGE), IsOk()); | 860 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_NO_CHANGE), IsOk()); |
810 g_expected_dscp = DSCP_DEFAULT; | 861 g_expected_dscp = DSCP_DEFAULT; |
811 g_expected_traffic_type = QOSTrafficTypeBestEffort; | 862 g_expected_traffic_type = QOSTrafficTypeBestEffort; |
812 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_DEFAULT), IsOk()); | 863 EXPECT_THAT(client.SetDiffServCodePoint(DSCP_DEFAULT), IsOk()); |
813 client.Close(); | 864 client.Close(); |
814 } | 865 } |
815 #endif | 866 #endif |
816 | 867 |
817 } // namespace net | 868 } // namespace net |
OLD | NEW |