diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-14 23:15:47 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-14 23:15:47 +0000 |
commit | 3753f52d42975eaefcafca9fc0257ec24e161a9c (patch) | |
tree | c9622baf613dd1b47c304d30e1ded74fa84fce54 /chrome/test/chrome_process_util_linux.cc | |
parent | 9e23bb1bba29dad5305e8f8a08341aefe7275502 (diff) | |
download | chromium_src-3753f52d42975eaefcafca9fc0257ec24e161a9c.zip chromium_src-3753f52d42975eaefcafca9fc0257ec24e161a9c.tar.gz chromium_src-3753f52d42975eaefcafca9fc0257ec24e161a9c.tar.bz2 |
Implement chrome_proces_util for linux and enable download ui test.
To get the PID from the socket, we use lsof (fuser doesn't work with unix sockets apparently).
The download shelf, save page, and browser ui tests now pass.
Review URL: http://codereview.chromium.org/66071
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13716 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/chrome_process_util_linux.cc')
-rw-r--r-- | chrome/test/chrome_process_util_linux.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/chrome/test/chrome_process_util_linux.cc b/chrome/test/chrome_process_util_linux.cc new file mode 100644 index 0000000..f5c1df1 --- /dev/null +++ b/chrome/test/chrome_process_util_linux.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/chrome_process_util.h" + +#include <stdio.h> + +#include <string> +#include <vector> + +#include "base/logging.h" +#include "base/string_util.h" + +base::ProcessId ChromeBrowserProcessId(const FilePath& data_dir) { + char fuser_output[256]; + + FilePath socket_name = data_dir.Append("SingletonSocket"); + // TODO(phajdan.jr): Do better quoting around the socket name. + std::string cmd = "fuser \"" + socket_name.value() + "\""; + FILE* fuser_pipe = popen(cmd.c_str(), "r"); + if (!fuser_pipe) { + DLOG(ERROR) << "Error launching fuser."; + return -1; + } + + char* rv = fgets(fuser_output, 256, fuser_pipe); + pclose(fuser_pipe); + + if (!rv) + return -1; + + std::string trimmed_output; + TrimWhitespace(fuser_output, TRIM_ALL, &trimmed_output); + + for (size_t i = 0; i < trimmed_output.size(); ++i) { + if (trimmed_output[i] == ' '){ + DLOG(ERROR) << "Expected exactly 1 process to have socket open: " << + fuser_output; + return -1; + } + } + + int pid; + if (!StringToInt(trimmed_output, &pid)) { + DLOG(ERROR) << "Unexpected fuser output: " << fuser_output; + return -1; + } + return pid; +} |