Commit 313c00e5 authored by kkania@chromium.org's avatar kkania@chromium.org

Fix NamedProxyLauncher on windows. Wait for the named pipe to be connectable.

Enable NamedInterfaceTest on windows.
BUG=chromium-os:8515
TEST=none


Review URL: http://codereview.chromium.org/7486007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95957 0039d316-1c4b-4281-b951-d872f2087c98
parent c230751b
...@@ -788,10 +788,6 @@ ...@@ -788,10 +788,6 @@
}, },
}, },
}, },
'sources!': [
# TODO(dtu): port to windows http://crosbug.com/8515
'test/ui/named_interface_uitest.cc',
],
}, { # else: OS != "win" }, { # else: OS != "win"
'sources!': [ 'sources!': [
# TODO(port): http://crbug.com/45770 # TODO(port): http://crbug.com/45770
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/test/ui/ui_test.h" #include "chrome/test/ui/ui_test.h"
#include "content/common/child_process_info.h" #include "content/common/child_process_info.h"
#include "content/common/debug_flags.h" #include "content/common/debug_flags.h"
#include "ipc/ipc_channel.h"
#include "sql/connection.h" #include "sql/connection.h"
namespace { namespace {
...@@ -62,8 +63,12 @@ void UpdateHistoryDates(const FilePath& user_data_dir) { ...@@ -62,8 +63,12 @@ void UpdateHistoryDates(const FilePath& user_data_dir) {
// ProxyLauncher functions // 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"; "/var/tmp/ChromeTestingInterface";
#endif
bool ProxyLauncher::in_process_renderer_ = false; bool ProxyLauncher::in_process_renderer_ = false;
bool ProxyLauncher::no_sandbox_ = false; bool ProxyLauncher::no_sandbox_ = false;
...@@ -516,33 +521,28 @@ AutomationProxy* NamedProxyLauncher::CreateAutomationProxy( ...@@ -516,33 +521,28 @@ AutomationProxy* NamedProxyLauncher::CreateAutomationProxy(
void NamedProxyLauncher::InitializeConnection(const LaunchState& state, void NamedProxyLauncher::InitializeConnection(const LaunchState& state,
bool wait_for_initial_loads) { 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 (launch_browser_) {
#if defined(OS_POSIX)
// Because we are waiting on the existence of the testing file below, // Because we are waiting on the existence of the testing file below,
// make sure there isn't one already there before browser launch. // 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. // Set up IPC testing interface as a client.
ASSERT_TRUE(LaunchBrowser(state)); ASSERT_TRUE(LaunchBrowser(state));
} }
// Wait for browser to be ready for connections. // Wait for browser to be ready for connections.
bool testing_channel_exists = false; bool channel_initialized = false;
for (int wait_time = 0; for (int wait_time = 0;
wait_time < TestTimeouts::action_max_timeout_ms(); wait_time < TestTimeouts::action_max_timeout_ms();
wait_time += automation::kSleepTime) { wait_time += automation::kSleepTime) {
testing_channel_exists = file_util::PathExists(testing_channel_path); channel_initialized = IPC::Channel::IsNamedServerInitialized(channel_id_);
if (testing_channel_exists) if (channel_initialized)
break; break;
base::PlatformThread::Sleep(automation::kSleepTime); base::PlatformThread::Sleep(automation::kSleepTime);
} }
EXPECT_TRUE(testing_channel_exists); EXPECT_TRUE(channel_initialized);
ASSERT_TRUE(ConnectToRunningBrowser(wait_for_initial_loads)); ASSERT_TRUE(ConnectToRunningBrowser(wait_for_initial_loads));
} }
......
...@@ -27,8 +27,8 @@ class AutomationProxy; ...@@ -27,8 +27,8 @@ class AutomationProxy;
// implementation or to override browser launching behavior. // implementation or to override browser launching behavior.
class ProxyLauncher { class ProxyLauncher {
public: public:
// Default path for named testing interface. // Default ID for named testing interface.
static const char kDefaultInterfacePath[]; static const char kDefaultInterfaceId[];
// Different ways to quit the browser. // Different ways to quit the browser.
enum ShutdownType { enum ShutdownType {
......
...@@ -21,13 +21,13 @@ class NamedInterfaceTest : public UITest { ...@@ -21,13 +21,13 @@ class NamedInterfaceTest : public UITest {
} }
virtual ProxyLauncher *CreateProxyLauncher() { virtual ProxyLauncher *CreateProxyLauncher() {
CommandLine::StringType channel_path = std::string channel_id =
CommandLine::ForCurrentProcess()->GetSwitchValueNative( CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kTestingChannel); switches::kTestingChannel);
if (channel_path.empty()) if (channel_id.empty())
channel_path = ProxyLauncher::kDefaultInterfacePath; channel_id = ProxyLauncher::kDefaultInterfaceId;
return new NamedProxyLauncher(channel_path, true, true); return new NamedProxyLauncher(channel_id, true, true);
} }
}; };
......
...@@ -171,6 +171,10 @@ class Channel : public Message::Sender { ...@@ -171,6 +171,10 @@ class Channel : public Message::Sender {
void ResetToAcceptingConnectionState(); void ResetToAcceptingConnectionState();
#endif // defined(OS_POSIX) && !defined(OS_NACL) #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: protected:
// Used in Chrome by the TestSink to provide a dummy channel implementation // Used in Chrome by the TestSink to provide a dummy channel implementation
// for testing. TestSink overrides the "interesting" functions in Channel so // for testing. TestSink overrides the "interesting" functions in Channel so
......
...@@ -993,6 +993,12 @@ void Channel::ChannelImpl::ResetToAcceptingConnectionState() { ...@@ -993,6 +993,12 @@ void Channel::ChannelImpl::ResetToAcceptingConnectionState() {
input_overflow_fds_.clear(); 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. // Called by libevent when we can read from the pipe without blocking.
void Channel::ChannelImpl::OnFileCanReadWithoutBlocking(int fd) { void Channel::ChannelImpl::OnFileCanReadWithoutBlocking(int fd) {
bool send_server_hello_msg = false; bool send_server_hello_msg = false;
...@@ -1202,4 +1208,9 @@ void Channel::ResetToAcceptingConnectionState() { ...@@ -1202,4 +1208,9 @@ void Channel::ResetToAcceptingConnectionState() {
channel_impl_->ResetToAcceptingConnectionState(); channel_impl_->ResetToAcceptingConnectionState();
} }
// static
bool Channel::IsNamedServerInitialized(const std::string& channel_id) {
return ChannelImpl::IsNamedServerInitialized(channel_id);
}
} // namespace IPC } // namespace IPC
...@@ -62,6 +62,7 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher { ...@@ -62,6 +62,7 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
bool HasAcceptedConnection() const; bool HasAcceptedConnection() const;
bool GetClientEuid(uid_t* client_euid) const; bool GetClientEuid(uid_t* client_euid) const;
void ResetToAcceptingConnectionState(); void ResetToAcceptingConnectionState();
static bool IsNamedServerInitialized(const std::string& channel_id);
private: private:
bool CreatePipe(const IPC::ChannelHandle& channel_handle); bool CreatePipe(const IPC::ChannelHandle& channel_handle);
......
...@@ -337,6 +337,20 @@ TEST_F(IPCChannelPosixTest, BadMode) { ...@@ -337,6 +337,20 @@ TEST_F(IPCChannelPosixTest, BadMode) {
ASSERT_FALSE(channel.Connect()); 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 // A long running process that connects to us
MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) {
MessageLoopForIO message_loop; MessageLoopForIO message_loop;
......
...@@ -93,8 +93,19 @@ bool Channel::ChannelImpl::Send(Message* message) { ...@@ -93,8 +93,19 @@ bool Channel::ChannelImpl::Send(Message* message) {
return true; 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::wstring Channel::ChannelImpl::PipeName(
const std::string& channel_id) const { const std::string& channel_id) {
std::string name("\\\\.\\pipe\\chrome."); std::string name("\\\\.\\pipe\\chrome.");
return ASCIIToWide(name.append(channel_id)); return ASCIIToWide(name.append(channel_id));
} }
...@@ -411,4 +422,9 @@ bool Channel::Send(Message* message) { ...@@ -411,4 +422,9 @@ bool Channel::Send(Message* message) {
return channel_impl_->Send(message); return channel_impl_->Send(message);
} }
// static
bool Channel::IsNamedServerInitialized(const std::string& channel_id) {
return ChannelImpl::IsNamedServerInitialized(channel_id);
}
} // namespace IPC } // namespace IPC
...@@ -30,8 +30,9 @@ class Channel::ChannelImpl : public MessageLoopForIO::IOHandler { ...@@ -30,8 +30,9 @@ class Channel::ChannelImpl : public MessageLoopForIO::IOHandler {
void Close(); void Close();
void set_listener(Listener* listener) { listener_ = listener; } void set_listener(Listener* listener) { listener_ = listener; }
bool Send(Message* message); bool Send(Message* message);
static bool IsNamedServerInitialized(const std::string& channel_id);
private: 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 CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode);
bool ProcessConnection(); bool ProcessConnection();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment