diff options
-rw-r--r-- | chrome/chrome_tests.gypi | 4 | ||||
-rw-r--r-- | chrome/test/automation/proxy_launcher.cc | 26 | ||||
-rw-r--r-- | chrome/test/automation/proxy_launcher.h | 4 | ||||
-rw-r--r-- | chrome/test/ui/named_interface_uitest.cc | 10 | ||||
-rw-r--r-- | ipc/ipc_channel.h | 4 | ||||
-rw-r--r-- | ipc/ipc_channel_posix.cc | 11 | ||||
-rw-r--r-- | ipc/ipc_channel_posix.h | 1 | ||||
-rw-r--r-- | ipc/ipc_channel_posix_unittest.cc | 14 | ||||
-rw-r--r-- | ipc/ipc_channel_win.cc | 18 | ||||
-rw-r--r-- | ipc/ipc_channel_win.h | 3 |
10 files changed, 69 insertions, 26 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 449fafa..847cd3a 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -788,10 +788,6 @@ }, }, }, - 'sources!': [ - # TODO(dtu): port to windows http://crosbug.com/8515 - 'test/ui/named_interface_uitest.cc', - ], }, { # else: OS != "win" 'sources!': [ # TODO(port): http://crbug.com/45770 diff --git a/chrome/test/automation/proxy_launcher.cc b/chrome/test/automation/proxy_launcher.cc index 2fb04c6..b914470 100644 --- a/chrome/test/automation/proxy_launcher.cc +++ b/chrome/test/automation/proxy_launcher.cc @@ -25,6 +25,7 @@ #include "chrome/test/ui/ui_test.h" #include "content/common/child_process_info.h" #include "content/common/debug_flags.h" +#include "ipc/ipc_channel.h" #include "sql/connection.h" namespace { @@ -62,8 +63,12 @@ void UpdateHistoryDates(const FilePath& user_data_dir) { // ProxyLauncher functions -const char ProxyLauncher::kDefaultInterfacePath[] = +#if defined(OS_WIN) +const char ProxyLauncher::kDefaultInterfaceId[] = "ChromeTestingInterface"; +#elif defined(OS_POSIX) +const char ProxyLauncher::kDefaultInterfaceId[] = "/var/tmp/ChromeTestingInterface"; +#endif bool ProxyLauncher::in_process_renderer_ = false; bool ProxyLauncher::no_sandbox_ = false; @@ -516,33 +521,28 @@ AutomationProxy* NamedProxyLauncher::CreateAutomationProxy( void NamedProxyLauncher::InitializeConnection(const LaunchState& state, bool wait_for_initial_loads) { - FilePath testing_channel_path; -#if defined(OS_WIN) - testing_channel_path = FilePath(ASCIIToWide(channel_id_)); -#else - testing_channel_path = FilePath(channel_id_); -#endif - if (launch_browser_) { +#if defined(OS_POSIX) // Because we are waiting on the existence of the testing file below, // make sure there isn't one already there before browser launch. - EXPECT_TRUE(file_util::Delete(testing_channel_path, false)); + EXPECT_TRUE(file_util::Delete(FilePath(channel_id_), false)); +#endif // Set up IPC testing interface as a client. ASSERT_TRUE(LaunchBrowser(state)); } // Wait for browser to be ready for connections. - bool testing_channel_exists = false; + bool channel_initialized = false; for (int wait_time = 0; wait_time < TestTimeouts::action_max_timeout_ms(); wait_time += automation::kSleepTime) { - testing_channel_exists = file_util::PathExists(testing_channel_path); - if (testing_channel_exists) + channel_initialized = IPC::Channel::IsNamedServerInitialized(channel_id_); + if (channel_initialized) break; base::PlatformThread::Sleep(automation::kSleepTime); } - EXPECT_TRUE(testing_channel_exists); + EXPECT_TRUE(channel_initialized); ASSERT_TRUE(ConnectToRunningBrowser(wait_for_initial_loads)); } diff --git a/chrome/test/automation/proxy_launcher.h b/chrome/test/automation/proxy_launcher.h index d306a33..8c8a0db 100644 --- a/chrome/test/automation/proxy_launcher.h +++ b/chrome/test/automation/proxy_launcher.h @@ -27,8 +27,8 @@ class AutomationProxy; // implementation or to override browser launching behavior. class ProxyLauncher { public: - // Default path for named testing interface. - static const char kDefaultInterfacePath[]; + // Default ID for named testing interface. + static const char kDefaultInterfaceId[]; // Different ways to quit the browser. enum ShutdownType { diff --git a/chrome/test/ui/named_interface_uitest.cc b/chrome/test/ui/named_interface_uitest.cc index 0c60cea..3401f71 100644 --- a/chrome/test/ui/named_interface_uitest.cc +++ b/chrome/test/ui/named_interface_uitest.cc @@ -21,13 +21,13 @@ class NamedInterfaceTest : public UITest { } virtual ProxyLauncher *CreateProxyLauncher() { - CommandLine::StringType channel_path = - CommandLine::ForCurrentProcess()->GetSwitchValueNative( + std::string channel_id = + CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kTestingChannel); - if (channel_path.empty()) - channel_path = ProxyLauncher::kDefaultInterfacePath; + if (channel_id.empty()) + channel_id = ProxyLauncher::kDefaultInterfaceId; - return new NamedProxyLauncher(channel_path, true, true); + return new NamedProxyLauncher(channel_id, true, true); } }; diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h index 6bfcded..f3bf78f 100644 --- a/ipc/ipc_channel.h +++ b/ipc/ipc_channel.h @@ -171,6 +171,10 @@ class Channel : public Message::Sender { void ResetToAcceptingConnectionState(); #endif // defined(OS_POSIX) && !defined(OS_NACL) + // Returns true if a named server channel is initialized on the given channel + // ID. Even if true, the server may have already accepted a connection. + static bool IsNamedServerInitialized(const std::string& channel_id); + protected: // Used in Chrome by the TestSink to provide a dummy channel implementation // for testing. TestSink overrides the "interesting" functions in Channel so diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc index 462d442..fe60691 100644 --- a/ipc/ipc_channel_posix.cc +++ b/ipc/ipc_channel_posix.cc @@ -993,6 +993,12 @@ void Channel::ChannelImpl::ResetToAcceptingConnectionState() { input_overflow_fds_.clear(); } +// static +bool Channel::ChannelImpl::IsNamedServerInitialized( + const std::string& channel_id) { + return file_util::PathExists(FilePath(channel_id)); +} + // Called by libevent when we can read from the pipe without blocking. void Channel::ChannelImpl::OnFileCanReadWithoutBlocking(int fd) { bool send_server_hello_msg = false; @@ -1202,4 +1208,9 @@ void Channel::ResetToAcceptingConnectionState() { channel_impl_->ResetToAcceptingConnectionState(); } +// static +bool Channel::IsNamedServerInitialized(const std::string& channel_id) { + return ChannelImpl::IsNamedServerInitialized(channel_id); +} + } // namespace IPC diff --git a/ipc/ipc_channel_posix.h b/ipc/ipc_channel_posix.h index 652a29a..b66b1fc 100644 --- a/ipc/ipc_channel_posix.h +++ b/ipc/ipc_channel_posix.h @@ -62,6 +62,7 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher { bool HasAcceptedConnection() const; bool GetClientEuid(uid_t* client_euid) const; void ResetToAcceptingConnectionState(); + static bool IsNamedServerInitialized(const std::string& channel_id); private: bool CreatePipe(const IPC::ChannelHandle& channel_handle); diff --git a/ipc/ipc_channel_posix_unittest.cc b/ipc/ipc_channel_posix_unittest.cc index 5e9677d..cc6f20b 100644 --- a/ipc/ipc_channel_posix_unittest.cc +++ b/ipc/ipc_channel_posix_unittest.cc @@ -337,6 +337,20 @@ TEST_F(IPCChannelPosixTest, BadMode) { ASSERT_FALSE(channel.Connect()); } +TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { + IPCChannelPosixTestListener listener(false); + IPC::ChannelHandle chan_handle(kConnectionSocketTestName); + ASSERT_TRUE(file_util::Delete(FilePath(kConnectionSocketTestName), false)); + ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( + kConnectionSocketTestName)); + IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); + ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( + kConnectionSocketTestName)); + channel.Close(); + ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( + kConnectionSocketTestName)); +} + // A long running process that connects to us MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { MessageLoopForIO message_loop; diff --git a/ipc/ipc_channel_win.cc b/ipc/ipc_channel_win.cc index e56235d..3a85a16 100644 --- a/ipc/ipc_channel_win.cc +++ b/ipc/ipc_channel_win.cc @@ -93,8 +93,19 @@ bool Channel::ChannelImpl::Send(Message* message) { return true; } +// static +bool Channel::ChannelImpl::IsNamedServerInitialized( + const std::string& channel_id) { + if (WaitNamedPipe(PipeName(channel_id).c_str(), 1)) + return true; + // If ERROR_SEM_TIMEOUT occurred, the pipe exists but is handling another + // connection. + return GetLastError() == ERROR_SEM_TIMEOUT; +} + +// static const std::wstring Channel::ChannelImpl::PipeName( - const std::string& channel_id) const { + const std::string& channel_id) { std::string name("\\\\.\\pipe\\chrome."); return ASCIIToWide(name.append(channel_id)); } @@ -411,4 +422,9 @@ bool Channel::Send(Message* message) { return channel_impl_->Send(message); } +// static +bool Channel::IsNamedServerInitialized(const std::string& channel_id) { + return ChannelImpl::IsNamedServerInitialized(channel_id); +} + } // namespace IPC diff --git a/ipc/ipc_channel_win.h b/ipc/ipc_channel_win.h index 358d6fa..ada88ac 100644 --- a/ipc/ipc_channel_win.h +++ b/ipc/ipc_channel_win.h @@ -30,8 +30,9 @@ class Channel::ChannelImpl : public MessageLoopForIO::IOHandler { void Close(); void set_listener(Listener* listener) { listener_ = listener; } bool Send(Message* message); + static bool IsNamedServerInitialized(const std::string& channel_id); private: - const std::wstring PipeName(const std::string& channel_id) const; + static const std::wstring PipeName(const std::string& channel_id); bool CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode); bool ProcessConnection(); |