1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/memory/ref_counted.h"
6 #include "base/strings/stringprintf.h"
7 #include "extensions/browser/api/system_network/system_network_api.h"
8 #include "extensions/browser/api_test_utils.h"
9 #include "extensions/common/test_util.h"
10 #include "extensions/shell/test/shell_apitest.h"
11 #include "extensions/test/extension_test_message_listener.h"
13 using extensions::Extension
;
14 using extensions::api_test_utils::RunFunctionAndReturnSingleResult
;
15 using extensions::api::SystemNetworkGetNetworkInterfacesFunction
;
16 using extensions::api::system_network::NetworkInterface
;
20 class SystemNetworkApiTest
: public extensions::ShellApiTest
{};
24 IN_PROC_BROWSER_TEST_F(SystemNetworkApiTest
, SystemNetworkExtension
) {
25 ASSERT_TRUE(RunAppTest("system/network")) << message_
;
28 IN_PROC_BROWSER_TEST_F(SystemNetworkApiTest
, GetNetworkInterfaces
) {
29 scoped_refptr
<SystemNetworkGetNetworkInterfacesFunction
> socket_function(
30 new SystemNetworkGetNetworkInterfacesFunction());
31 scoped_refptr
<Extension
> empty_extension(
32 extensions::test_util::CreateEmptyExtension());
34 socket_function
->set_extension(empty_extension
.get());
35 socket_function
->set_has_callback(true);
37 scoped_ptr
<base::Value
> result(RunFunctionAndReturnSingleResult(
38 socket_function
.get(), "[]", browser_context()));
39 ASSERT_EQ(base::Value::TYPE_LIST
, result
->GetType());
41 // All we can confirm is that we have at least one address, but not what it
43 base::ListValue
* value
= static_cast<base::ListValue
*>(result
.get());
44 ASSERT_TRUE(value
->GetSize() > 0);
46 for (base::ListValue::const_iterator it
= value
->begin(); it
!= value
->end();
48 base::Value
* network_interface_value
= *it
;
50 NetworkInterface network_interface
;
51 ASSERT_TRUE(NetworkInterface::Populate(*network_interface_value
,
54 LOG(INFO
) << "Network interface: address=" << network_interface
.address
55 << ", name=" << network_interface
.name
56 << ", prefix length=" << network_interface
.prefix_length
;
57 ASSERT_NE(std::string(), network_interface
.address
);
58 ASSERT_NE(std::string(), network_interface
.name
);
59 ASSERT_LE(0, network_interface
.prefix_length
);