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