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

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;
yzshen1 2013/09/03 17:47:32 nit: Please consider adding break;
Sergey Ulanov 2013/09/03 23:42:54 Done.
112 }
113 }
114 ASSERT_TRUE(!all_zeros);
109 115
110 // Verify that the address is not zero. 116 // Verify that port is set to 0.
111 size_t j; 117 ASSERT_TRUE(ipv4.port == 0);
112 for (j = 0; j < sizeof(ip); ++j) {
113 if (ip[j] != 0)
114 break; 118 break;
119 }
120
121 case PP_NETADDRESS_FAMILY_IPV6: {
122 PP_NetAddress_IPv6 ipv6;
123 ASSERT_TRUE(addresses[i].DescribeAsIPv6Address(&ipv6));
124
125 // Verify that the address is not zero.
126 bool all_zeros = true;
127 for (size_t j = 0; j < sizeof(ipv6.addr); ++j) {
128 if (ipv6.addr[j] != 0) {
129 all_zeros = false;
yzshen1 2013/09/03 17:47:32 ditto.
Sergey Ulanov 2013/09/03 23:42:54 Done.
130 }
131 }
132 ASSERT_TRUE(!all_zeros);
133
134 // Verify that port is set to 0.
135 ASSERT_TRUE(ipv6.port == 0);
136 break;
137 }
138
139 default:
140 ASSERT_TRUE(false);
115 } 141 }
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 } 142 }
121 143
122 // Verify that each interface has a unique name and a display name. 144 // Verify that each interface has a unique name and a display name.
123 ASSERT_FALSE(network_list.GetName(iface).empty()); 145 ASSERT_FALSE(network_list.GetName(iface).empty());
124 ASSERT_FALSE(network_list.GetDisplayName(iface).empty()); 146 ASSERT_FALSE(network_list.GetDisplayName(iface).empty());
125 147
126 PP_NetworkListType_Private type = network_list.GetType(iface); 148 PP_NetworkListType_Private type = network_list.GetType(iface);
127 ASSERT_TRUE(type >= PP_NETWORKLIST_UNKNOWN); 149 ASSERT_TRUE(type >= PP_NETWORKLIST_UNKNOWN);
128 ASSERT_TRUE(type <= PP_NETWORKLIST_CELLULAR); 150 ASSERT_TRUE(type <= PP_NETWORKLIST_CELLULAR);
129 151
130 PP_NetworkListState_Private state = network_list.GetState(iface); 152 PP_NetworkListState_Private state = network_list.GetState(iface);
131 ASSERT_TRUE(state >= PP_NETWORKLIST_DOWN); 153 ASSERT_TRUE(state >= PP_NETWORKLIST_DOWN);
132 ASSERT_TRUE(state <= PP_NETWORKLIST_UP); 154 ASSERT_TRUE(state <= PP_NETWORKLIST_UP);
133 } 155 }
134 156
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(); 157 PASS();
163 } 158 }
164 159
165 std::string TestNetworkMonitorPrivate::TestBasic() { 160 std::string TestNetworkMonitorPrivate::TestBasic() {
166 CallbackData callback_data(instance_->pp_instance()); 161 CallbackData callback_data(instance_->pp_instance());
167 162
168 pp::NetworkMonitorPrivate network_monitor( 163 pp::NetworkMonitorPrivate network_monitor(
169 instance_, &TestCallback, &callback_data); 164 instance_, &TestCallback, &callback_data);
170 callback_data.event.Wait(); 165 callback_data.event.Wait();
171 ASSERT_EQ(callback_data.call_counter, 1); 166 ASSERT_EQ(callback_data.call_counter, 1);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 207
213 PASS(); 208 PASS();
214 } 209 }
215 210
216 std::string TestNetworkMonitorPrivate::TestListObserver() { 211 std::string TestNetworkMonitorPrivate::TestListObserver() {
217 TestNetworkListObserver observer(instance_); 212 TestNetworkListObserver observer(instance_);
218 observer.event.Wait(); 213 observer.event.Wait();
219 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(observer.current_list)); 214 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(observer.current_list));
220 PASS(); 215 PASS();
221 } 216 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698