summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 20:19:39 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 20:19:39 +0000
commit5b9b80e284fb0b6a4885209ade02093aecc7eb86 (patch)
treebadaaf0bccfb0ea5413c8949250ba50fec420aba /ppapi/tests
parent1769870244a943241f8d34dc01b2d98b4f2b38f4 (diff)
downloadchromium_src-5b9b80e284fb0b6a4885209ade02093aecc7eb86.zip
chromium_src-5b9b80e284fb0b6a4885209ade02093aecc7eb86.tar.gz
chromium_src-5b9b80e284fb0b6a4885209ade02093aecc7eb86.tar.bz2
Out-of-process implementation of the PPB_NetworkMonitor_Private interface.
BUG=114808 Review URL: http://codereview.chromium.org/9677060 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127762 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/test_network_monitor_private.cc50
-rw-r--r--ppapi/tests/test_network_monitor_private.h1
2 files changed, 44 insertions, 7 deletions
diff --git a/ppapi/tests/test_network_monitor_private.cc b/ppapi/tests/test_network_monitor_private.cc
index 6b7d49f..fa87ec1 100644
--- a/ppapi/tests/test_network_monitor_private.cc
+++ b/ppapi/tests/test_network_monitor_private.cc
@@ -6,6 +6,7 @@
#include <string.h>
+#include "ppapi/cpp/private/net_address_private.h"
#include "ppapi/cpp/private/network_list_private.h"
#include "ppapi/cpp/private/network_monitor_private.h"
#include "ppapi/tests/testing_instance.h"
@@ -20,7 +21,9 @@ struct CallbackData {
explicit CallbackData(PP_Instance instance)
: call_counter(0),
completion_callback(instance),
- list_resource(0) {
+ list_resource(0),
+ delete_monitor(false),
+ monitor(NULL) {
}
~CallbackData() {
if (list_resource)
@@ -29,6 +32,8 @@ struct CallbackData {
int call_counter;
TestCompletionCallback completion_callback;
PP_Resource list_resource;
+ bool delete_monitor;
+ pp::NetworkMonitorPrivate* monitor;
};
void TestCallback(void* user_data, PP_Resource network_list) {
@@ -39,6 +44,9 @@ void TestCallback(void* user_data, PP_Resource network_list) {
pp::Module::Get()->core()->ReleaseResource(data->list_resource);
data->list_resource = network_list;
+ if (data->delete_monitor)
+ delete data->monitor;
+
// Invoke completion callback only for the first change notification.
if (data->call_counter == 1)
static_cast<pp::CompletionCallback>(data->completion_callback).Run(PP_OK);
@@ -60,6 +68,7 @@ bool TestNetworkMonitorPrivate::Init() {
void TestNetworkMonitorPrivate::RunTests(const std::string& filter) {
RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter);
RUN_TEST_FORCEASYNC_AND_NOT(2Monitors, filter);
+ RUN_TEST_FORCEASYNC_AND_NOT(DeleteInCallback, filter);
}
std::string TestNetworkMonitorPrivate::VerifyNetworkList(
@@ -78,15 +87,26 @@ std::string TestNetworkMonitorPrivate::VerifyNetworkList(
ASSERT_TRUE(addresses.size() >= 1U);
// Verify that the addresses are valid.
for (size_t i = 0; i < addresses.size(); ++i) {
- ASSERT_TRUE(addresses[i].size == 4 || addresses[i].size == 16);
+ PP_NetAddressFamily_Private family =
+ pp::NetAddressPrivate::GetFamily(addresses[i]);
+
+ ASSERT_TRUE(family == PP_NETADDRESSFAMILY_IPV4 ||
+ family == PP_NETADDRESSFAMILY_IPV6);
+
+ char ip[16] = { 0 };
+ ASSERT_TRUE(pp::NetAddressPrivate::GetAddress(
+ addresses[i], ip, sizeof(ip)));
// Verify that the address is not zero.
size_t j;
- for (j = 0; j < addresses[i].size; ++j) {
- if (addresses[i].data[j] != 0)
+ for (j = 0; j < sizeof(ip); ++j) {
+ if (ip[j] != 0)
break;
}
ASSERT_TRUE(j != addresses[i].size);
+
+ // Verify that port is set to 0.
+ ASSERT_TRUE(pp::NetAddressPrivate::GetPort(addresses[i]) == 0);
}
// Verify that each interface has a unique name and a display name.
@@ -136,7 +156,7 @@ std::string TestNetworkMonitorPrivate::TestBasic() {
CallbackData callback_data(instance_->pp_instance());
pp::NetworkMonitorPrivate network_monitor(
- instance_, &TestCallback, reinterpret_cast<void*>(&callback_data));
+ instance_, &TestCallback, &callback_data);
ASSERT_EQ(callback_data.completion_callback.WaitForResult(), PP_OK);
ASSERT_EQ(callback_data.call_counter, 1);
@@ -149,7 +169,7 @@ std::string TestNetworkMonitorPrivate::Test2Monitors() {
CallbackData callback_data(instance_->pp_instance());
pp::NetworkMonitorPrivate network_monitor(
- instance_, &TestCallback, reinterpret_cast<void*>(&callback_data));
+ instance_, &TestCallback, &callback_data);
ASSERT_EQ(callback_data.completion_callback.WaitForResult(), PP_OK);
ASSERT_EQ(callback_data.call_counter, 1);
@@ -158,7 +178,7 @@ std::string TestNetworkMonitorPrivate::Test2Monitors() {
CallbackData callback_data_2(instance_->pp_instance());
pp::NetworkMonitorPrivate network_monitor_2(
- instance_, &TestCallback, reinterpret_cast<void*>(&callback_data_2));
+ instance_, &TestCallback, &callback_data_2);
ASSERT_EQ(callback_data_2.completion_callback.WaitForResult(), PP_OK);
ASSERT_EQ(callback_data_2.call_counter, 1);
@@ -166,3 +186,19 @@ std::string TestNetworkMonitorPrivate::Test2Monitors() {
PASS();
}
+
+std::string TestNetworkMonitorPrivate::TestDeleteInCallback() {
+ CallbackData callback_data(instance_->pp_instance());
+
+ pp::NetworkMonitorPrivate* network_monitor = new pp::NetworkMonitorPrivate(
+ instance_, &TestCallback, &callback_data);
+ callback_data.delete_monitor = true;
+ callback_data.monitor = network_monitor;
+
+ ASSERT_EQ(callback_data.completion_callback.WaitForResult(), PP_OK);
+ ASSERT_EQ(callback_data.call_counter, 1);
+
+ ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(callback_data.list_resource));
+
+ PASS();
+}
diff --git a/ppapi/tests/test_network_monitor_private.h b/ppapi/tests/test_network_monitor_private.h
index 20a99d4..00a856a 100644
--- a/ppapi/tests/test_network_monitor_private.h
+++ b/ppapi/tests/test_network_monitor_private.h
@@ -21,6 +21,7 @@ class TestNetworkMonitorPrivate : public TestCase {
private:
std::string TestBasic();
std::string Test2Monitors();
+ std::string TestDeleteInCallback();
std::string VerifyNetworkList(PP_Resource network_resource);
};