summaryrefslogtreecommitdiffstats
path: root/net/test/spawned_test_server
diff options
context:
space:
mode:
authorbratell@opera.com <bratell@opera.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-19 09:58:13 +0000
committerbratell@opera.com <bratell@opera.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-19 09:58:13 +0000
commit656f57ca2bb070e7b5453a6015a0e667f538aa9c (patch)
tree82db18115e9c958b5ae9c37a6338b0dde3e67d46 /net/test/spawned_test_server
parent4d7db3813ce7faa62cf65f4ee6372fb8a293dc4f (diff)
downloadchromium_src-656f57ca2bb070e7b5453a6015a0e667f538aa9c.zip
chromium_src-656f57ca2bb070e7b5453a6015a0e667f538aa9c.tar.gz
chromium_src-656f57ca2bb070e7b5453a6015a0e667f538aa9c.tar.bz2
Remove hard dependency on bundled python_26 in tests
(solution suggested in https://codereview.chromium.org/16117004/ ) The hardcoded dependency on third_party/python_26 in some unit tests makes it necessary to bundle that python with the test binaries. On other platforms the system python is used and there is no reason Windows can't do the same if one is available. This saves us band-width (25 MB per test machine) when distributing tests. The change is implemented as a removal of the hard coded path in execution and instead it's inserted at the end of the PATH environment variable. That way it will still be used if there is no other python available but otherwise a system python will be used. There is a small risk that the system python is unsuitable but that is a risk we already take on non-Windows platforms. Another solution was discussed in https://codereview.chromium.org/16117004/ before this solution was suggested. Review URL: https://chromiumcodereview.appspot.com/21537002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224096 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/test/spawned_test_server')
-rw-r--r--net/test/spawned_test_server/local_test_server_win.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/net/test/spawned_test_server/local_test_server_win.cc b/net/test/spawned_test_server/local_test_server_win.cc
index a2c2f7b..08d68f8 100644
--- a/net/test/spawned_test_server/local_test_server_win.cc
+++ b/net/test/spawned_test_server/local_test_server_win.cc
@@ -10,6 +10,7 @@
#include "base/base_paths.h"
#include "base/bind.h"
#include "base/command_line.h"
+#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
@@ -81,6 +82,60 @@ bool ReadData(HANDLE read_fd, HANDLE write_fd,
return true;
}
+// Class that sets up a temporary path that includes the supplied path
+// at the end.
+//
+// TODO(bratell): By making this more generic we can possibly reuse
+// it at other places such as
+// chrome/common/multi_process_lock_unittest.cc.
+class ScopedPath {
+ public:
+ // Constructor which sets up the environment to include the path to
+ // |path_to_add|.
+ explicit ScopedPath(const base::FilePath& path_to_add);
+
+ // Destructor that restores the path that were active when the
+ // object was constructed.
+ ~ScopedPath();
+
+ private:
+ // The PATH environment variable before it was changed or an empty
+ // string if there was no PATH environment variable.
+ std::string old_path_;
+
+ // The helper object that allows us to read and set environment
+ // variables more easily.
+ scoped_ptr<base::Environment> environment_;
+
+ // A flag saying if we have actually modified the environment.
+ bool path_modified_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedPath);
+};
+
+ScopedPath::ScopedPath(const base::FilePath& path_to_add)
+ : environment_(base::Environment::Create()),
+ path_modified_(false) {
+ environment_->GetVar("PATH", &old_path_);
+
+ std::string new_value = old_path_;
+ if (!new_value.empty())
+ new_value += ";";
+
+ new_value += WideToUTF8(path_to_add.value());
+
+ path_modified_ = environment_->SetVar("PATH", new_value);
+}
+
+ScopedPath::~ScopedPath() {
+ if (!path_modified_)
+ return;
+ if (old_path_.empty())
+ environment_->UnSetVar("PATH");
+ else
+ environment_->SetVar("PATH", old_path_);
+}
+
} // namespace
namespace net {
@@ -135,6 +190,15 @@ bool LocalTestServer::LaunchPython(const base::FilePath& testserver_path) {
return false;
}
+ // Add our internal python to the path so it can be used if there is
+ // no system python.
+ base::FilePath python_dir;
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &python_dir)) {
+ LOG(ERROR) << "Could not locate source root directory.";
+ return false;
+ }
+ python_dir = python_dir.AppendASCII("third_party").AppendASCII("python_26");
+ ScopedPath python_path(python_dir);
base::LaunchOptions launch_options;
launch_options.inherit_handles = true;
launch_options.job_handle = job_handle_.Get();