diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 08:09:30 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 08:09:30 +0000 |
commit | 1912cfef3207b30c2691a3f71c524a69ac969b19 (patch) | |
tree | e13101b5a3c721dfd3a00179a49e43b454dcd5d5 /chrome/test | |
parent | 37f876a54ffb14d1630b1c0ebdbeda82ed150816 (diff) | |
download | chromium_src-1912cfef3207b30c2691a3f71c524a69ac969b19.zip chromium_src-1912cfef3207b30c2691a3f71c524a69ac969b19.tar.gz chromium_src-1912cfef3207b30c2691a3f71c524a69ac969b19.tar.bz2 |
More solid detection of browser process in chrome_process_util_linux.cc:
- use GetAppOutput instead of popen
- make unexpected conditions fatal (otherwise the tests using this code
would mistakenly assume that there is no running browser process)
Also add a constant for SingletonSocket.
Make necessary adjustments to GetAppOutput - ignore stderr (because fuser
prints the file name to stderr and having stderr in |output| would
require more parsing).
Review URL: http://codereview.chromium.org/77031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14091 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/chrome_process_util_linux.cc | 34 | ||||
-rw-r--r-- | chrome/test/chrome_process_util_uitest.cc | 20 |
2 files changed, 34 insertions, 20 deletions
diff --git a/chrome/test/chrome_process_util_linux.cc b/chrome/test/chrome_process_util_linux.cc index f5c1df1..f1c7601 100644 --- a/chrome/test/chrome_process_util_linux.cc +++ b/chrome/test/chrome_process_util_linux.cc @@ -9,41 +9,35 @@ #include <string> #include <vector> +#include "base/command_line.h" #include "base/logging.h" +#include "base/process_util.h" #include "base/string_util.h" +#include "chrome/common/chrome_constants.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; - } + FilePath socket_name = data_dir.Append(chrome::kSingletonSocketFilename); - char* rv = fgets(fuser_output, 256, fuser_pipe); - pclose(fuser_pipe); + std::vector<std::string> argv; + argv.push_back("fuser"); + argv.push_back(socket_name.value()); - if (!rv) + std::string fuser_output; + if (!base::GetAppOutput(CommandLine(argv), &fuser_output)) 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; - } + if (trimmed_output.find(' ') != std::string::npos) { + LOG(FATAL) << "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; + LOG(FATAL) << "Unexpected fuser output: " << fuser_output; return -1; } return pid; diff --git a/chrome/test/chrome_process_util_uitest.cc b/chrome/test/chrome_process_util_uitest.cc new file mode 100644 index 0000000..78f3fa9 --- /dev/null +++ b/chrome/test/chrome_process_util_uitest.cc @@ -0,0 +1,20 @@ +// 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 "chrome/test/ui/ui_test.h" + +class ChromeProcessUtilTest : public UITest { +}; + +TEST_F(ChromeProcessUtilTest, SanityTest) { + EXPECT_TRUE(IsBrowserRunning()); + EXPECT_NE(-1, ChromeBrowserProcessId(user_data_dir())); + EXPECT_GE(GetRunningChromeProcesses(user_data_dir()).size(), 1U); + QuitBrowser(); + EXPECT_FALSE(IsBrowserRunning()); + EXPECT_EQ(-1, ChromeBrowserProcessId(user_data_dir())); + EXPECT_EQ(0U, GetRunningChromeProcesses(user_data_dir()).size()); +} |