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 @@
},
},
},
'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
......
......@@ -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));
}
......
......@@ -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 {
......
......@@ -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);
}
};
......
......@@ -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
......
......@@ -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
......@@ -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);
......
......@@ -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;
......
......@@ -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
......@@ -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();
......
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