• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "base/memory/ref_counted.h"
6 #include "base/path_service.h"
7 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/extensions/api/system_network/system_network_api.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_function_test_utils.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_test_message_listener.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/extensions/application_launch.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/ui_test_utils.h"
17 
18 using extensions::Extension;
19 using extensions::api::SystemNetworkGetNetworkInterfacesFunction;
20 using extensions::api::system_network::NetworkInterface;
21 
22 namespace utils = extension_function_test_utils;
23 
24 namespace {
25 
26 class SystemNetworkApiTest : public ExtensionApiTest {
27 };
28 
29 }  // namespace
30 
IN_PROC_BROWSER_TEST_F(SystemNetworkApiTest,SystemNetworkExtension)31 IN_PROC_BROWSER_TEST_F(SystemNetworkApiTest, SystemNetworkExtension) {
32   ASSERT_TRUE(RunExtensionTest("system/network")) << message_;
33 }
34 
IN_PROC_BROWSER_TEST_F(SystemNetworkApiTest,GetNetworkInterfaces)35 IN_PROC_BROWSER_TEST_F(SystemNetworkApiTest, GetNetworkInterfaces) {
36   scoped_refptr<SystemNetworkGetNetworkInterfacesFunction> socket_function(
37       new SystemNetworkGetNetworkInterfacesFunction());
38   scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
39 
40   socket_function->set_extension(empty_extension.get());
41   socket_function->set_has_callback(true);
42 
43   scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
44       socket_function.get(), "[]", browser(), utils::NONE));
45   ASSERT_EQ(base::Value::TYPE_LIST, result->GetType());
46 
47   // All we can confirm is that we have at least one address, but not what it
48   // is.
49   base::ListValue *value = static_cast<base::ListValue*>(result.get());
50   ASSERT_TRUE(value->GetSize() > 0);
51 
52   for (base::ListValue::const_iterator it = value->begin();
53       it != value->end(); ++it) {
54     base::Value* network_interface_value = *it;
55 
56     NetworkInterface network_interface;
57     ASSERT_TRUE(NetworkInterface::Populate(*network_interface_value,
58                                            &network_interface));
59 
60     LOG(INFO) << "Network interface: address=" << network_interface.address
61               << ", name=" << network_interface.name
62               << ", prefix length=" << network_interface.prefix_length;
63     ASSERT_NE(std::string(), network_interface.address);
64     ASSERT_NE(std::string(), network_interface.name);
65     ASSERT_LE(0, network_interface.prefix_length);
66   }
67 }
68