Chromium Code Reviews| Index: ppapi/tests/test_network_monitor_private.cc |
| diff --git a/ppapi/tests/test_network_monitor_private.cc b/ppapi/tests/test_network_monitor_private.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cf072a57170ca03b0c331a206a598c6647667f93 |
| --- /dev/null |
| +++ b/ppapi/tests/test_network_monitor_private.cc |
| @@ -0,0 +1,93 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ppapi/tests/test_network_monitor_private.h" |
| + |
| +#include "ppapi/cpp/private/network_list_private.h" |
| +#include "ppapi/cpp/private/network_monitor_private.h" |
| +#include "ppapi/tests/testing_instance.h" |
| +#include "ppapi/tests/test_utils.h" |
| +#include "ppapi/cpp/module.h" |
| + |
| +REGISTER_TEST_CASE(NetworkMonitorPrivate); |
| + |
| +namespace { |
| + |
| +struct CallbackData { |
| + CallbackData(PP_Instance instance) |
|
dmichael (off chromium)
2012/03/01 18:58:04
nit: explicit
Sergey Ulanov
2012/03/03 02:26:08
Done.
|
| + : call_counter(0), |
| + completion_callback(instance), |
| + list_resource(0) { |
| + } |
| + int call_counter; |
| + TestCompletionCallback completion_callback; |
| + PP_Resource list_resource; |
|
dmichael (off chromium)
2012/03/01 18:58:04
You probably should add a destructor that releases
Sergey Ulanov
2012/03/03 02:26:08
Done.
|
| +}; |
| + |
| +void TestCallback(void* user_data, PP_Resource network_list) { |
| + CallbackData* data = reinterpret_cast<CallbackData*>(user_data); |
|
dmichael (off chromium)
2012/03/01 18:58:04
nit: static_cast
Sergey Ulanov
2012/03/03 02:26:08
Done.
|
| + data->call_counter++; |
| + if (data->call_counter == 1) { |
| + data->list_resource = network_list; |
| + static_cast<pp::CompletionCallback>(data->completion_callback).Run(PP_OK); |
| + } else { |
| + pp::Module::Get()->core()->ReleaseResource(network_list); |
|
dmichael (off chromium)
2012/03/01 18:58:04
Can you explain what's going on? You're saving the
Sergey Ulanov
2012/03/03 02:26:08
Yes, that was the idea, but now I changed it to al
|
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +TestNetworkMonitorPrivate::TestNetworkMonitorPrivate(TestingInstance* instance) |
| + : TestCase(instance) { |
| +} |
| + |
| +bool TestNetworkMonitorPrivate::Init() { |
| + if (!pp::NetworkMonitorPrivate::IsAvailable()) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +void TestNetworkMonitorPrivate::RunTests(const std::string& filter) { |
| + RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter); |
| + RUN_TEST_FORCEASYNC_AND_NOT(2Monitors, filter); |
| +} |
| + |
| +std::string TestNetworkMonitorPrivate::TestBasic() { |
| + CallbackData callback_data(instance_->pp_instance()); |
| + |
| + pp::NetworkMonitorPrivate network_monitor( |
| + instance_, &TestCallback, reinterpret_cast<void*>(&callback_data)); |
| + ASSERT_EQ(callback_data.completion_callback.WaitForResult(), PP_OK); |
| + ASSERT_EQ(callback_data.call_counter, 1); |
| + |
| + // Verify that there is at least one interface |
| + pp::NetworkListPrivate network_list(callback_data.list_resource); |
| + ASSERT_TRUE(network_list.GetCount() >= 1U); |
| + |
| + // Verify that the first interface has at least one address. |
| + std::vector<PP_NetAddress_Private> addresses; |
| + network_list.GetIpAddresses(0, &addresses); |
| + ASSERT_TRUE(addresses.size() >= 1U); |
| + |
| + PASS(); |
| +} |
| + |
| +std::string TestNetworkMonitorPrivate::Test2Monitors() { |
| + CallbackData callback_data(instance_->pp_instance()); |
| + |
| + pp::NetworkMonitorPrivate network_monitor( |
| + instance_, &TestCallback, reinterpret_cast<void*>(&callback_data)); |
| + ASSERT_EQ(callback_data.completion_callback.WaitForResult(), PP_OK); |
| + ASSERT_EQ(callback_data.call_counter, 1); |
| + |
| + CallbackData callback_data_2(instance_->pp_instance()); |
| + |
| + pp::NetworkMonitorPrivate network_monitor_2( |
| + instance_, &TestCallback, reinterpret_cast<void*>(&callback_data_2)); |
| + ASSERT_EQ(callback_data_2.completion_callback.WaitForResult(), PP_OK); |
| + ASSERT_EQ(callback_data_2.call_counter, 1); |
| + |
| + PASS(); |
| +} |