Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: ppapi/tests/test_network_monitor_private.cc

Issue 23806003: Use PP_ArrayOutput and PPB_NetAddress in PPB_NetworkList_Private.. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "ppapi/tests/test_network_monitor_private.h" 5 #include "ppapi/tests/test_network_monitor_private.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "ppapi/cpp/instance_handle.h" 9 #include "ppapi/cpp/instance_handle.h"
10 #include "ppapi/cpp/module.h" 10 #include "ppapi/cpp/module.h"
11 #include "ppapi/cpp/private/net_address_private.h" 11 #include "ppapi/cpp/net_address.h"
12 #include "ppapi/cpp/private/network_list_private.h" 12 #include "ppapi/cpp/private/network_list_private.h"
13 #include "ppapi/cpp/private/network_monitor_private.h" 13 #include "ppapi/cpp/private/network_monitor_private.h"
14 #include "ppapi/tests/testing_instance.h" 14 #include "ppapi/tests/testing_instance.h"
15 #include "ppapi/tests/test_utils.h" 15 #include "ppapi/tests/test_utils.h"
16 #include "ppapi/utility/private/network_list_observer_private.h" 16 #include "ppapi/utility/private/network_list_observer_private.h"
17 17
18 REGISTER_TEST_CASE(NetworkMonitorPrivate); 18 REGISTER_TEST_CASE(NetworkMonitorPrivate);
19 19
20 namespace { 20 namespace {
21 21
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 std::string TestNetworkMonitorPrivate::VerifyNetworkList( 86 std::string TestNetworkMonitorPrivate::VerifyNetworkList(
87 const pp::NetworkListPrivate& network_list) { 87 const pp::NetworkListPrivate& network_list) {
88 // Verify that there is at least one network interface. 88 // Verify that there is at least one network interface.
89 size_t count = network_list.GetCount(); 89 size_t count = network_list.GetCount();
90 ASSERT_TRUE(count >= 1U); 90 ASSERT_TRUE(count >= 1U);
91 91
92 // Iterate over all interfaces and verify their properties. 92 // Iterate over all interfaces and verify their properties.
93 for (size_t iface = 0; iface < count; ++iface) { 93 for (size_t iface = 0; iface < count; ++iface) {
94 // Verify that the first interface has at least one address. 94 // Verify that the first interface has at least one address.
95 std::vector<PP_NetAddress_Private> addresses; 95 std::vector<pp::NetAddress> addresses;
96 network_list.GetIpAddresses(iface, &addresses); 96 network_list.GetIpAddresses(iface, &addresses);
97 ASSERT_TRUE(addresses.size() >= 1U); 97 ASSERT_TRUE(addresses.size() >= 1U);
98 // Verify that the addresses are valid. 98 // Verify that the addresses are valid.
99 for (size_t i = 0; i < addresses.size(); ++i) { 99 for (size_t i = 0; i < addresses.size(); ++i) {
100 PP_NetAddressFamily_Private family = 100 PP_NetAddress_Family family = addresses[i].GetFamily();
101 pp::NetAddressPrivate::GetFamily(addresses[i]);
102 101
103 ASSERT_TRUE(family == PP_NETADDRESSFAMILY_PRIVATE_IPV4 || 102 switch (family) {
104 family == PP_NETADDRESSFAMILY_PRIVATE_IPV6); 103 case PP_NETADDRESS_FAMILY_IPV4: {
104 PP_NetAddress_IPv4 ipv4;
105 ASSERT_TRUE(addresses[i].DescribeAsIPv4Address(&ipv4));
105 106
106 char ip[16] = { 0 }; 107 // Verify that the address is not zero.
107 ASSERT_TRUE(pp::NetAddressPrivate::GetAddress( 108 bool all_zeros = true;
108 addresses[i], ip, sizeof(ip))); 109 for (size_t j = 0; j < sizeof(ipv4.addr); ++j) {
110 if (ipv4.addr[j] != 0) {
111 all_zeros = false;
112 break;
113 }
114 }
115 ASSERT_TRUE(!all_zeros);
109 116
110 // Verify that the address is not zero. 117 // Verify that port is set to 0.
111 size_t j; 118 ASSERT_TRUE(ipv4.port == 0);
112 for (j = 0; j < sizeof(ip); ++j) {
113 if (ip[j] != 0)
114 break; 119 break;
120 }
121
122 case PP_NETADDRESS_FAMILY_IPV6: {
123 PP_NetAddress_IPv6 ipv6;
124 ASSERT_TRUE(addresses[i].DescribeAsIPv6Address(&ipv6));
125
126 // Verify that the address is not zero.
127 bool all_zeros = true;
128 for (size_t j = 0; j < sizeof(ipv6.addr); ++j) {
129 if (ipv6.addr[j] != 0) {
130 all_zeros = false;
131 break;
132 }
133 }
134 ASSERT_TRUE(!all_zeros);
135
136 // Verify that port is set to 0.
137 ASSERT_TRUE(ipv6.port == 0);
138 break;
139 }
140
141 default:
142 ASSERT_TRUE(false);
115 } 143 }
116 ASSERT_TRUE(j != addresses[i].size);
117
118 // Verify that port is set to 0.
119 ASSERT_TRUE(pp::NetAddressPrivate::GetPort(addresses[i]) == 0);
120 } 144 }
121 145
122 // Verify that each interface has a unique name and a display name. 146 // Verify that each interface has a unique name and a display name.
123 ASSERT_FALSE(network_list.GetName(iface).empty()); 147 ASSERT_FALSE(network_list.GetName(iface).empty());
124 ASSERT_FALSE(network_list.GetDisplayName(iface).empty()); 148 ASSERT_FALSE(network_list.GetDisplayName(iface).empty());
125 149
126 PP_NetworkListType_Private type = network_list.GetType(iface); 150 PP_NetworkListType_Private type = network_list.GetType(iface);
127 ASSERT_TRUE(type >= PP_NETWORKLIST_UNKNOWN); 151 ASSERT_TRUE(type >= PP_NETWORKLIST_UNKNOWN);
128 ASSERT_TRUE(type <= PP_NETWORKLIST_CELLULAR); 152 ASSERT_TRUE(type <= PP_NETWORKLIST_CELLULAR);
129 153
130 PP_NetworkListState_Private state = network_list.GetState(iface); 154 PP_NetworkListState_Private state = network_list.GetState(iface);
131 ASSERT_TRUE(state >= PP_NETWORKLIST_DOWN); 155 ASSERT_TRUE(state >= PP_NETWORKLIST_DOWN);
132 ASSERT_TRUE(state <= PP_NETWORKLIST_UP); 156 ASSERT_TRUE(state <= PP_NETWORKLIST_UP);
133 } 157 }
134 158
135 // Try to call GetIpAddresses() without C++ wrapper and verify that
136 // it always returns correct value.
137 const PPB_NetworkList_Private* interface =
138 static_cast<const PPB_NetworkList_Private*>(
139 pp::Module::Get()->GetBrowserInterface(
140 PPB_NETWORKLIST_PRIVATE_INTERFACE));
141 ASSERT_TRUE(interface);
142 std::vector<PP_NetAddress_Private> addresses;
143 network_list.GetIpAddresses(0, &addresses);
144 size_t address_count = addresses.size();
145 addresses.resize(addresses.size() + 3);
146 for (size_t i = 0; i < addresses.size(); ++i) {
147 const char kFillValue = 123;
148 memset(&addresses.front(), kFillValue,
149 addresses.size() * sizeof(PP_NetAddress_Private));
150 int result = interface->GetIpAddresses(network_list.pp_resource(), 0,
151 &addresses.front(), i);
152 ASSERT_EQ(result, static_cast<int>(address_count));
153
154 // Verify that nothing outside the buffer was touched.
155 for (char* pos = reinterpret_cast<char*>(&addresses[result]);
156 pos != reinterpret_cast<char*>(&addresses[0] + addresses.size());
157 ++pos) {
158 ASSERT_TRUE(*pos == kFillValue);
159 }
160 }
161
162 PASS(); 159 PASS();
163 } 160 }
164 161
165 std::string TestNetworkMonitorPrivate::TestBasic() { 162 std::string TestNetworkMonitorPrivate::TestBasic() {
166 CallbackData callback_data(instance_->pp_instance()); 163 CallbackData callback_data(instance_->pp_instance());
167 164
168 pp::NetworkMonitorPrivate network_monitor( 165 pp::NetworkMonitorPrivate network_monitor(
169 instance_, &TestCallback, &callback_data); 166 instance_, &TestCallback, &callback_data);
170 callback_data.event.Wait(); 167 callback_data.event.Wait();
171 ASSERT_EQ(callback_data.call_counter, 1); 168 ASSERT_EQ(callback_data.call_counter, 1);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 209
213 PASS(); 210 PASS();
214 } 211 }
215 212
216 std::string TestNetworkMonitorPrivate::TestListObserver() { 213 std::string TestNetworkMonitorPrivate::TestListObserver() {
217 TestNetworkListObserver observer(instance_); 214 TestNetworkListObserver observer(instance_);
218 observer.event.Wait(); 215 observer.event.Wait();
219 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(observer.current_list)); 216 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(observer.current_list));
220 PASS(); 217 PASS();
221 } 218 }
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_network_list_private_shared.cc ('k') | ppapi/thunk/interfaces_ppb_private_no_permissions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698