0

Get url_request_unittest.cc to build on Linux.

See http://code.google.com/p/chromium/issues/detail?id=3661

Also change LaunchApp to check PATH, 
and fixed a useful gcc-4.3 warning re operator precedence.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4515 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
dkegel@google.com
2008-11-03 23:17:33 +00:00
parent ed931012a5
commit 82fc7c72f6
4 changed files with 40 additions and 9 deletions

@ -40,7 +40,7 @@ bool LaunchApp(const std::vector<std::string>& argv,
int pid = fork();
if (pid == 0) {
execv(argv_copy[0], argv_copy);
execvp(argv_copy[0], argv_copy);
} else if (pid < 0) {
retval = false;
} else {

@ -119,6 +119,11 @@ if env['PLATFORM'] == 'darwin':
'../base/platform_test_mac$OBJSUFFIX',
])
if env['PLATFORM'] == 'posix':
input_files.extend([
'url_request/url_request_unittest.cc',
])
if env['PLATFORM'] in ('darwin', 'posix'):
input_files.extend([
'base/ssl_client_socket_unittest.cc',

@ -331,6 +331,7 @@ TEST(URLRequestTest, PostFileTest) {
MessageLoop::current()->Run();
#if defined(OS_WIN)
HANDLE file = CreateFile(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
ASSERT_NE(INVALID_HANDLE_VALUE, file);
@ -352,6 +353,9 @@ TEST(URLRequestTest, PostFileTest) {
ASSERT_EQ(size, d.bytes_received());
EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size));
#else
NOTIMPLEMENTED();
#endif
}
#ifndef NDEBUG
DCHECK_EQ(url_request_metrics.object_count,0);
@ -696,7 +700,7 @@ TEST(URLRequestTest, VaryHeader) {
// Make sure that the response time of a future response will be in the
// future!
Sleep(10);
PlatformThread::Sleep(10);
// expect a cache hit
{
@ -748,7 +752,7 @@ TEST(URLRequestTest, BasicAuth) {
// Let some time pass so we can ensure that a future response will have a
// response time value in the future.
Sleep(10 /* milliseconds */);
PlatformThread::Sleep(10 /* milliseconds */);
// repeat request with end-to-end validation. since auth-basic results in a
// cachable page, we expect this test to result in a 304. in which case, the

@ -15,11 +15,13 @@
#include "base/process_util.h"
#include "base/string_util.h"
#include "base/thread.h"
#include "base/time.h"
#include "base/waitable_event.h"
#include "net/base/net_errors.h"
#include "net/http/http_network_layer.h"
#include "net/url_request/url_request.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "googleurl/src/url_util.h"
const int kDefaultPort = 1337;
const std::string kDefaultHostName("localhost");
@ -202,7 +204,8 @@ class TestServer : public process_util::ProcessFilter {
// filter.
if (!process_handle_)
return false;
return pid == process_util::GetProcId(process_handle_);
// TODO(port): rationalize return value of GetProcId
return pid == (uint32)process_util::GetProcId(process_handle_);
}
GURL TestServerPage(const std::string& path) {
@ -210,7 +213,7 @@ class TestServer : public process_util::ProcessFilter {
}
GURL TestServerPageW(const std::wstring& path) {
return GURL(UTF8ToWide(base_address_) + path);
return GURL(base_address_ + WideToUTF8(path));
}
// A subclass may wish to send the request in a different manner
@ -254,7 +257,7 @@ class TestServer : public process_util::ProcessFilter {
const std::wstring& cert_path) {
std::stringstream ss;
std::string port_str;
ss << port ? port : kDefaultPort;
ss << (port ? port : kDefaultPort);
ss >> port_str;
base_address_ = scheme() + "://" + host_name + ":" + port_str + "/";
@ -278,6 +281,7 @@ class TestServer : public process_util::ProcessFilter {
L'/', file_util::kPathSeparator);
file_util::AppendToPath(&test_data_directory, normalized_document_root);
#if defined(OS_WIN)
std::wstring command_line =
L"\"" + python_runtime_ + L"\" " + L"\"" + testserver_path +
L"\" --port=" + UTF8ToWide(port_str) + L" --data-dir=\"" +
@ -291,6 +295,22 @@ class TestServer : public process_util::ProcessFilter {
ASSERT_TRUE(
process_util::LaunchApp(command_line, false, true, &process_handle_)) <<
"Failed to launch " << command_line;
#elif defined(OS_LINUX)
bool tlslite_installed = !access("/usr/bin/tls.py", X_OK);
ASSERT_TRUE(tlslite_installed) << "tlslite not installed? Please run 'python setup.py install' in third_party/tlslite.";
std::vector<std::string> command_line;
command_line.push_back("python");
command_line.push_back(WideToUTF8(testserver_path));
command_line.push_back("--port=" + port_str);
command_line.push_back("--data-dir=" + WideToUTF8(test_data_directory));
if (!cert_path.empty())
command_line.push_back("--https=" + WideToUTF8(cert_path));
ASSERT_TRUE(
process_util::LaunchApp(command_line, false, &process_handle_)) <<
"Failed to launch " << command_line[0] << " ...";
#endif
// Verify that the webserver is actually started.
// Otherwise tests can fail if they run faster than Python can start.
@ -300,7 +320,7 @@ class TestServer : public process_util::ProcessFilter {
retries--;
PlatformThread::Sleep(500);
}
ASSERT_TRUE(success) << "Webserver not starting properly.";
ASSERT_TRUE(success) << "Webserver not starting properly. (On Linux, you need to install third_party/tlslite.)";
is_shutdown_ = false;
}
@ -312,7 +332,7 @@ class TestServer : public process_util::ProcessFilter {
// here we append the time to avoid problems where the kill page
// is being cached rather than being executed on the server
std::ostringstream page_name;
page_name << "kill?" << GetTickCount();
page_name << "kill?" << (unsigned int)(base::Time::Now().ToInternalValue());
int retry_count = 5;
while (retry_count > 0) {
bool r = MakeGETRequest(page_name.str());
@ -328,7 +348,9 @@ class TestServer : public process_util::ProcessFilter {
DCHECK(retry_count > 0);
if (process_handle_) {
#if defined(OS_WIN)
CloseHandle(process_handle_);
#endif
process_handle_ = NULL;
}
@ -369,7 +391,7 @@ class TestServer : public process_util::ProcessFilter {
std::string base_address_;
std::wstring python_runtime_;
HANDLE process_handle_;
ProcessHandle process_handle_;
bool is_shutdown_;
};