Skip to content

Commit

Permalink
Fix NamedProxyLauncher on windows. Wait for the named pipe to be conn…
Browse files Browse the repository at this point in the history
…ectable.

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
  • Loading branch information
kkania@chromium.org committed Aug 9, 2011
1 parent c230751 commit 313c00e
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 26 deletions.
4 changes: 0 additions & 4 deletions chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions chrome/test/automation/proxy_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/test/automation/proxy_launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions chrome/test/ui/named_interface_uitest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
4 changes: 4 additions & 0 deletions ipc/ipc_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions ipc/ipc_channel_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions ipc/ipc_channel_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions ipc/ipc_channel_posix_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion ipc/ipc_channel_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion ipc/ipc_channel_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 313c00e

Please sign in to comment.