Chromium Code Reviews| Index: chrome/browser/extensions/api/socket/socket_apitest.cc |
| diff --git a/chrome/browser/extensions/api/socket/socket_apitest.cc b/chrome/browser/extensions/api/socket/socket_apitest.cc |
| index 7921ce9ce97a4dbb44703dd6c2c8496cd2b97f63..97cf78094dc58b0ca6ba9e3a7b9f905b53074625 100644 |
| --- a/chrome/browser/extensions/api/socket/socket_apitest.cc |
| +++ b/chrome/browser/extensions/api/socket/socket_apitest.cc |
| @@ -3,6 +3,7 @@ |
| // found in the LICENSE file. |
| #include "base/memory/ref_counted.h" |
| +#include "base/path_service.h" |
| #include "base/stringprintf.h" |
| #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h" |
| #include "chrome/browser/extensions/api/dns/mock_host_resolver_creator.h" |
| @@ -12,6 +13,8 @@ |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/extensions/extension_test_message_listener.h" |
| #include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/extensions/application_launch.h" |
| +#include "chrome/common/chrome_paths.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| @@ -62,6 +65,46 @@ class SocketApiTest : public ExtensionApiTest { |
| scoped_refptr<extensions::MockHostResolverCreator> resolver_creator_; |
| }; |
| +#if !defined(DISABLE_NACL) |
| +// TODO(yzshen): Build testing framework for all extensions APIs in Pepper. And |
| +// move these Pepper API tests there. |
| +class SocketPpapiTest : public SocketApiTest { |
| + public: |
| + SocketPpapiTest() { |
| + } |
| + virtual ~SocketPpapiTest() { |
| + } |
| + |
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| + SocketApiTest::SetUpCommandLine(command_line); |
| + // TODO(yzshen): It is better to use switches::kEnablePepperTesting. |
| + // However, that requires adding a new DEPS entry. Considering that we are |
| + // going to move the Pepper API tests to a new place, use a string literal |
| + // for now. |
| + command_line->AppendSwitch("enable-pepper-testing"); |
| + |
| + PathService::Get(chrome::DIR_GEN_TEST_DATA, &app_dir_); |
| + app_dir_ = app_dir_.AppendASCII( |
| + "chrome/test/data/extensions/socket/ppapi/newlib"); |
|
asargent_no_longer_on_chrome
2013/04/12 21:37:52
I think you're missing 'api_test' in the path here
yzshen1
2013/04/12 22:16:55
Thanks! I updated the output path that the test da
asargent_no_longer_on_chrome
2013/04/15 17:54:05
Oops, sorry, I missed that.
|
| + } |
| + |
| + protected: |
| + void LaunchTestingApp() { |
| + const Extension* extension = LoadExtension(app_dir_); |
| + ASSERT_TRUE(extension); |
| + |
| + chrome::AppLaunchParams params(browser()->profile(), extension, |
| + extension_misc::LAUNCH_NONE, |
| + NEW_WINDOW); |
| + params.command_line = CommandLine::ForCurrentProcess(); |
| + chrome::OpenApplication(params); |
| + } |
| + |
| + private: |
| + base::FilePath app_dir_; |
| +}; |
| +#endif |
| + |
| } // namespace |
| IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketUDPCreateGood) { |
| @@ -199,3 +242,75 @@ IN_PROC_BROWSER_TEST_F(SocketApiTest, SocketTCPServerUnbindOnUnload) { |
| << message_; |
| EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| } |
| + |
| +#if !defined(DISABLE_NACL) |
| +IN_PROC_BROWSER_TEST_F(SocketPpapiTest, UDP) { |
| + scoped_ptr<net::TestServer> test_server( |
| + new net::TestServer(net::TestServer::TYPE_UDP_ECHO, |
| + net::TestServer::kLocalhost, |
| + base::FilePath(FILE_PATH_LITERAL("net/data")))); |
| + EXPECT_TRUE(test_server->Start()); |
| + |
| + net::HostPortPair host_port_pair = test_server->host_port_pair(); |
| + int port = host_port_pair.port(); |
| + ASSERT_TRUE(port > 0); |
| + |
| + // Test that sendTo() is properly resolving hostnames. |
| + host_port_pair.set_host("LOCALhost"); |
| + |
| + ResultCatcher catcher; |
| + catcher.RestrictToProfile(browser()->profile()); |
| + |
| + ExtensionTestMessageListener listener("info_please", true); |
| + |
| + LaunchTestingApp(); |
| + |
| + EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| + listener.Reply( |
| + base::StringPrintf("udp:%s:%d", host_port_pair.host().c_str(), port)); |
| + |
| + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(SocketPpapiTest, TCP) { |
| + scoped_ptr<net::TestServer> test_server( |
| + new net::TestServer(net::TestServer::TYPE_TCP_ECHO, |
| + net::TestServer::kLocalhost, |
| + base::FilePath(FILE_PATH_LITERAL("net/data")))); |
| + EXPECT_TRUE(test_server->Start()); |
| + |
| + net::HostPortPair host_port_pair = test_server->host_port_pair(); |
| + int port = host_port_pair.port(); |
| + ASSERT_TRUE(port > 0); |
| + |
| + // Test that connect() is properly resolving hostnames. |
| + host_port_pair.set_host("lOcAlHoSt"); |
| + |
| + ResultCatcher catcher; |
| + catcher.RestrictToProfile(browser()->profile()); |
| + |
| + ExtensionTestMessageListener listener("info_please", true); |
| + |
| + LaunchTestingApp(); |
| + |
| + EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| + listener.Reply( |
| + base::StringPrintf("tcp:%s:%d", host_port_pair.host().c_str(), port)); |
| + |
| + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(SocketPpapiTest, TCPServer) { |
| + ResultCatcher catcher; |
| + catcher.RestrictToProfile(browser()->profile()); |
| + ExtensionTestMessageListener listener("info_please", true); |
| + |
| + LaunchTestingApp(); |
| + |
| + EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| + listener.Reply( |
| + base::StringPrintf("tcp_server:%s:%d", kHostname.c_str(), kPort)); |
| + |
| + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| +} |
| +#endif |