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

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

Issue 23450012: Make NetworkList and NetworkMonitor APIs public (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.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "ppapi/cpp/completion_callback.h" 9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/instance_handle.h" 10 #include "ppapi/cpp/instance_handle.h"
11 #include "ppapi/cpp/module.h" 11 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/net_address.h" 12 #include "ppapi/cpp/net_address.h"
13 #include "ppapi/cpp/private/network_list_private.h" 13 #include "ppapi/cpp/network_list.h"
14 #include "ppapi/cpp/private/network_monitor_private.h" 14 #include "ppapi/cpp/network_monitor.h"
15 #include "ppapi/tests/test_utils.h"
15 #include "ppapi/tests/testing_instance.h" 16 #include "ppapi/tests/testing_instance.h"
16 #include "ppapi/tests/test_utils.h"
17 17
18 REGISTER_TEST_CASE(NetworkMonitorPrivate); 18 REGISTER_TEST_CASE(NetworkMonitor);
19 19
20 namespace { 20 namespace {
21 21
22 class MonitorDeletionCallbackDelegate 22 class MonitorDeletionCallbackDelegate
23 : public TestCompletionCallback::Delegate { 23 : public TestCompletionCallback::Delegate {
24 public: 24 public:
25 explicit MonitorDeletionCallbackDelegate(pp::NetworkMonitorPrivate* monitor) 25 explicit MonitorDeletionCallbackDelegate(pp::NetworkMonitor* monitor)
26 : monitor_(monitor) { 26 : monitor_(monitor) {
27 } 27 }
28 28
29 // TestCompletionCallback::Delegate interface. 29 // TestCompletionCallback::Delegate interface.
30 virtual void OnCallback(void* user_data, int32_t result) { 30 virtual void OnCallback(void* user_data, int32_t result) {
31 delete monitor_; 31 delete monitor_;
32 } 32 }
33 33
34 private: 34 private:
35 pp::NetworkMonitorPrivate* monitor_; 35 pp::NetworkMonitor* monitor_;
36 }; 36 };
37 37
38 } // namespace 38 } // namespace
39 39
40 TestNetworkMonitorPrivate::TestNetworkMonitorPrivate(TestingInstance* instance) 40 TestNetworkMonitor::TestNetworkMonitor(TestingInstance* instance)
41 : TestCase(instance) { 41 : TestCase(instance) {
42 } 42 }
43 43
44 bool TestNetworkMonitorPrivate::Init() { 44 bool TestNetworkMonitor::Init() {
45 if (!pp::NetworkMonitorPrivate::IsAvailable()) 45 if (!pp::NetworkMonitor::IsAvailable())
46 return false; 46 return false;
47 47
48 return CheckTestingInterface(); 48 return CheckTestingInterface();
49 } 49 }
50 50
51 void TestNetworkMonitorPrivate::RunTests(const std::string& filter) { 51 void TestNetworkMonitor::RunTests(const std::string& filter) {
52 RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter); 52 RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter);
53 RUN_TEST_FORCEASYNC_AND_NOT(2Monitors, filter); 53 RUN_TEST_FORCEASYNC_AND_NOT(2Monitors, filter);
54 RUN_TEST_FORCEASYNC_AND_NOT(DeleteInCallback, filter); 54 RUN_TEST_FORCEASYNC_AND_NOT(DeleteInCallback, filter);
55 } 55 }
56 56
57 std::string TestNetworkMonitorPrivate::VerifyNetworkList( 57 std::string TestNetworkMonitor::VerifyNetworkList(
58 const pp::NetworkListPrivate& network_list) { 58 const pp::NetworkList& network_list) {
59 // Verify that there is at least one network interface. 59 // Verify that there is at least one network interface.
60 size_t count = network_list.GetCount(); 60 size_t count = network_list.GetCount();
61 ASSERT_TRUE(count >= 1U); 61 ASSERT_TRUE(count >= 1U);
62 62
63 // Iterate over all interfaces and verify their properties. 63 // Iterate over all interfaces and verify their properties.
64 for (size_t iface = 0; iface < count; ++iface) { 64 for (size_t iface = 0; iface < count; ++iface) {
65 // Verify that the first interface has at least one address. 65 // Verify that the first interface has at least one address.
66 std::vector<pp::NetAddress> addresses; 66 std::vector<pp::NetAddress> addresses;
67 network_list.GetIpAddresses(iface, &addresses); 67 network_list.GetIpAddresses(iface, &addresses);
68 ASSERT_TRUE(addresses.size() >= 1U); 68 ASSERT_TRUE(addresses.size() >= 1U);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 default: 112 default:
113 ASSERT_TRUE(false); 113 ASSERT_TRUE(false);
114 } 114 }
115 } 115 }
116 116
117 // Verify that each interface has a unique name and a display name. 117 // Verify that each interface has a unique name and a display name.
118 ASSERT_FALSE(network_list.GetName(iface).empty()); 118 ASSERT_FALSE(network_list.GetName(iface).empty());
119 ASSERT_FALSE(network_list.GetDisplayName(iface).empty()); 119 ASSERT_FALSE(network_list.GetDisplayName(iface).empty());
120 120
121 PP_NetworkListType_Private type = network_list.GetType(iface); 121 PP_NetworkList_Type type = network_list.GetType(iface);
122 ASSERT_TRUE(type >= PP_NETWORKLIST_UNKNOWN); 122 ASSERT_TRUE(type >= PP_NETWORKLIST_TYPE_UNKNOWN);
123 ASSERT_TRUE(type <= PP_NETWORKLIST_CELLULAR); 123 ASSERT_TRUE(type <= PP_NETWORKLIST_TYPE_CELLULAR);
124 124
125 PP_NetworkListState_Private state = network_list.GetState(iface); 125 PP_NetworkList_State state = network_list.GetState(iface);
126 ASSERT_TRUE(state >= PP_NETWORKLIST_DOWN); 126 ASSERT_TRUE(state >= PP_NETWORKLIST_STATE_DOWN);
127 ASSERT_TRUE(state <= PP_NETWORKLIST_UP); 127 ASSERT_TRUE(state <= PP_NETWORKLIST_STATE_UP);
128 } 128 }
129 129
130 PASS(); 130 PASS();
131 } 131 }
132 132
133 std::string TestNetworkMonitorPrivate::TestBasic() { 133 std::string TestNetworkMonitor::TestBasic() {
134 TestCompletionCallbackWithOutput<pp::NetworkListPrivate> test_callback( 134 TestCompletionCallbackWithOutput<pp::NetworkList> test_callback(
135 instance_->pp_instance()); 135 instance_->pp_instance());
136 pp::NetworkMonitorPrivate network_monitor(instance_); 136 pp::NetworkMonitor network_monitor(instance_);
137 test_callback.WaitForResult( 137 test_callback.WaitForResult(
138 network_monitor.UpdateNetworkList(test_callback.GetCallback())); 138 network_monitor.UpdateNetworkList(test_callback.GetCallback()));
139 139
140 ASSERT_EQ(test_callback.result(), PP_OK); 140 ASSERT_EQ(test_callback.result(), PP_OK);
141 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(test_callback.output())); 141 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(test_callback.output()));
142 142
143 PASS(); 143 PASS();
144 } 144 }
145 145
146 std::string TestNetworkMonitorPrivate::Test2Monitors() { 146 std::string TestNetworkMonitor::Test2Monitors() {
147 TestCompletionCallbackWithOutput<pp::NetworkListPrivate> test_callback( 147 TestCompletionCallbackWithOutput<pp::NetworkList> test_callback(
148 instance_->pp_instance()); 148 instance_->pp_instance());
149 pp::NetworkMonitorPrivate network_monitor(instance_); 149 pp::NetworkMonitor network_monitor(instance_);
150 test_callback.WaitForResult( 150 test_callback.WaitForResult(
151 network_monitor.UpdateNetworkList(test_callback.GetCallback())); 151 network_monitor.UpdateNetworkList(test_callback.GetCallback()));
152 152
153 ASSERT_EQ(test_callback.result(), PP_OK); 153 ASSERT_EQ(test_callback.result(), PP_OK);
154 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(test_callback.output())); 154 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(test_callback.output()));
155 155
156 TestCompletionCallbackWithOutput<pp::NetworkListPrivate> test_callback_2( 156 TestCompletionCallbackWithOutput<pp::NetworkList> test_callback_2(
157 instance_->pp_instance()); 157 instance_->pp_instance());
158 pp::NetworkMonitorPrivate network_monitor_2(instance_); 158 pp::NetworkMonitor network_monitor_2(instance_);
159 test_callback_2.WaitForResult( 159 test_callback_2.WaitForResult(
160 network_monitor_2.UpdateNetworkList(test_callback_2.GetCallback())); 160 network_monitor_2.UpdateNetworkList(test_callback_2.GetCallback()));
161 161
162 ASSERT_EQ(test_callback_2.result(), PP_OK); 162 ASSERT_EQ(test_callback_2.result(), PP_OK);
163 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(test_callback_2.output())); 163 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(test_callback_2.output()));
164 164
165 PASS(); 165 PASS();
166 } 166 }
167 167
168 std::string TestNetworkMonitorPrivate::TestDeleteInCallback() { 168 std::string TestNetworkMonitor::TestDeleteInCallback() {
169 pp::NetworkMonitorPrivate* network_monitor = 169 pp::NetworkMonitor* network_monitor =
170 new pp::NetworkMonitorPrivate(instance_); 170 new pp::NetworkMonitor(instance_);
171 MonitorDeletionCallbackDelegate deletion_delegate(network_monitor); 171 MonitorDeletionCallbackDelegate deletion_delegate(network_monitor);
172 TestCompletionCallbackWithOutput<pp::NetworkListPrivate> test_callback( 172 TestCompletionCallbackWithOutput<pp::NetworkList> test_callback(
173 instance_->pp_instance()); 173 instance_->pp_instance());
174 test_callback.SetDelegate(&deletion_delegate); 174 test_callback.SetDelegate(&deletion_delegate);
175 test_callback.WaitForResult( 175 test_callback.WaitForResult(
176 network_monitor->UpdateNetworkList(test_callback.GetCallback())); 176 network_monitor->UpdateNetworkList(test_callback.GetCallback()));
177 177
178 ASSERT_EQ(test_callback.result(), PP_OK); 178 ASSERT_EQ(test_callback.result(), PP_OK);
179 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(test_callback.output())); 179 ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(test_callback.output()));
180 180
181 PASS(); 181 PASS();
182 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698