summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-21 18:55:08 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-21 18:55:08 +0000
commit398328082a9926be75f7a3bb013388d832fd2dcc (patch)
treeb91bba13497015e5e6655c1adee47b5a8dd91968 /ppapi/tests
parent7ee3acb08d9de663e5ec3148ee98b666cd32ad82 (diff)
downloadchromium_src-398328082a9926be75f7a3bb013388d832fd2dcc.zip
chromium_src-398328082a9926be75f7a3bb013388d832fd2dcc.tar.gz
chromium_src-398328082a9926be75f7a3bb013388d832fd2dcc.tar.bz2
Add NetworkListObserver utility class.
BUG=114808 Review URL: https://chromiumcodereview.appspot.com/9696051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/test_network_monitor_private.cc52
-rw-r--r--ppapi/tests/test_network_monitor_private.h8
2 files changed, 50 insertions, 10 deletions
diff --git a/ppapi/tests/test_network_monitor_private.cc b/ppapi/tests/test_network_monitor_private.cc
index fa87ec1..6583cc4 100644
--- a/ppapi/tests/test_network_monitor_private.cc
+++ b/ppapi/tests/test_network_monitor_private.cc
@@ -6,12 +6,14 @@
#include <string.h>
+#include "ppapi/cpp/instance_handle.h"
+#include "ppapi/cpp/module.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"
#include "ppapi/tests/test_utils.h"
-#include "ppapi/cpp/module.h"
+#include "ppapi/utility/private/network_list_observer_private.h"
REGISTER_TEST_CASE(NetworkMonitorPrivate);
@@ -52,6 +54,22 @@ void TestCallback(void* user_data, PP_Resource network_list) {
static_cast<pp::CompletionCallback>(data->completion_callback).Run(PP_OK);
}
+
+class TestNetworkListObserver : public pp::NetworkListObserverPrivate {
+ public:
+ explicit TestNetworkListObserver(const pp::InstanceHandle& instance)
+ : pp::NetworkListObserverPrivate(instance),
+ completion_callback(instance.pp_instance()) {
+ }
+ virtual void OnNetworkListChanged(const pp::NetworkListPrivate& list) {
+ current_list = list;
+ static_cast<pp::CompletionCallback>(completion_callback).Run(PP_OK);
+ }
+
+ pp::NetworkListPrivate current_list;
+ TestCompletionCallback completion_callback;
+};
+
} // namespace
TestNetworkMonitorPrivate::TestNetworkMonitorPrivate(TestingInstance* instance)
@@ -69,12 +87,17 @@ 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);
+ RUN_TEST_FORCEASYNC_AND_NOT(ListObserver, filter);
}
-std::string TestNetworkMonitorPrivate::VerifyNetworkList(
- PP_Resource network_resource) {
- pp::NetworkListPrivate network_list(network_resource);
+std::string TestNetworkMonitorPrivate::VerifyNetworkListResource(
+ PP_Resource network_list_resource) {
+ pp::NetworkListPrivate network_list(network_list_resource);
+ return VerifyNetworkList(network_list);
+}
+std::string TestNetworkMonitorPrivate::VerifyNetworkList(
+ const pp::NetworkListPrivate& network_list) {
// Verify that there is at least one network interface.
size_t count = network_list.GetCount();
ASSERT_TRUE(count >= 1U);
@@ -137,7 +160,7 @@ std::string TestNetworkMonitorPrivate::VerifyNetworkList(
const char kFillValue = 123;
memset(&addresses.front(), kFillValue,
addresses.size() * sizeof(PP_NetAddress_Private));
- int result = interface->GetIpAddresses(network_resource, 0,
+ int result = interface->GetIpAddresses(network_list.pp_resource(), 0,
&addresses.front(), i);
ASSERT_EQ(result, static_cast<int>(address_count));
@@ -160,7 +183,8 @@ std::string TestNetworkMonitorPrivate::TestBasic() {
ASSERT_EQ(callback_data.completion_callback.WaitForResult(), PP_OK);
ASSERT_EQ(callback_data.call_counter, 1);
- ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(callback_data.list_resource));
+ ASSERT_SUBTEST_SUCCESS(
+ VerifyNetworkListResource(callback_data.list_resource));
PASS();
}
@@ -173,7 +197,8 @@ std::string TestNetworkMonitorPrivate::Test2Monitors() {
ASSERT_EQ(callback_data.completion_callback.WaitForResult(), PP_OK);
ASSERT_EQ(callback_data.call_counter, 1);
- ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(callback_data.list_resource));
+ ASSERT_SUBTEST_SUCCESS(
+ VerifyNetworkListResource(callback_data.list_resource));
CallbackData callback_data_2(instance_->pp_instance());
@@ -182,7 +207,8 @@ std::string TestNetworkMonitorPrivate::Test2Monitors() {
ASSERT_EQ(callback_data_2.completion_callback.WaitForResult(), PP_OK);
ASSERT_EQ(callback_data_2.call_counter, 1);
- ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(callback_data_2.list_resource));
+ ASSERT_SUBTEST_SUCCESS(
+ VerifyNetworkListResource(callback_data_2.list_resource));
PASS();
}
@@ -198,7 +224,15 @@ std::string TestNetworkMonitorPrivate::TestDeleteInCallback() {
ASSERT_EQ(callback_data.completion_callback.WaitForResult(), PP_OK);
ASSERT_EQ(callback_data.call_counter, 1);
- ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(callback_data.list_resource));
+ ASSERT_SUBTEST_SUCCESS(
+ VerifyNetworkListResource(callback_data.list_resource));
+
+ PASS();
+}
+std::string TestNetworkMonitorPrivate::TestListObserver() {
+ TestNetworkListObserver observer(instance_);
+ ASSERT_EQ(observer.completion_callback.WaitForResult(), PP_OK);
+ ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(observer.current_list));
PASS();
}
diff --git a/ppapi/tests/test_network_monitor_private.h b/ppapi/tests/test_network_monitor_private.h
index 00a856a..38016d2 100644
--- a/ppapi/tests/test_network_monitor_private.h
+++ b/ppapi/tests/test_network_monitor_private.h
@@ -10,6 +10,10 @@
#include "ppapi/c/pp_stdint.h"
#include "ppapi/tests/test_case.h"
+namespace pp {
+class NetworkListPrivate;
+} // namespace pp
+
class TestNetworkMonitorPrivate : public TestCase {
public:
explicit TestNetworkMonitorPrivate(TestingInstance* instance);
@@ -22,8 +26,10 @@ class TestNetworkMonitorPrivate : public TestCase {
std::string TestBasic();
std::string Test2Monitors();
std::string TestDeleteInCallback();
+ std::string TestListObserver();
- std::string VerifyNetworkList(PP_Resource network_resource);
+ std::string VerifyNetworkListResource(PP_Resource network_resource);
+ std::string VerifyNetworkList(const pp::NetworkListPrivate& network_list);
};
#endif // PAPPI_TESTS_TEST_NETWORK_MONITOR_PRIVATE_H_