diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 23:37:40 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-05 23:37:40 +0000 |
commit | f164cea41472f9e9ec21579233e2c42a7b9d5184 (patch) | |
tree | 523c6aa180be86ace3ac7797e4c9c75c369dff57 /base/process_util_unittest.cc | |
parent | 422c0f17466cddf30fd6815f9d3519a3815264c6 (diff) | |
download | chromium_src-f164cea41472f9e9ec21579233e2c42a7b9d5184.zip chromium_src-f164cea41472f9e9ec21579233e2c42a7b9d5184.tar.gz chromium_src-f164cea41472f9e9ec21579233e2c42a7b9d5184.tar.bz2 |
Mac: Implement about:memory.
This implements about:memory on Mac. It calls /bin/ps to obtain information
about processes (this is Apple's officially supported "API"). Unfortunately, ps
provides fairly minimal information (rss and vsize); top is better, but not a
stable API -- it has changed greatly between Mac OS 10.5 and 10.6, and moreover
the 10.6 version is more limited in its output formatting.
BUG=9653
TEST=Go to about:memory under a variety of conditions (with a variety of browsers loaded).
Review URL: http://codereview.chromium.org/333008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31168 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r-- | base/process_util_unittest.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index e2fb5bf..961ac7e 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -287,6 +287,51 @@ TEST_F(ProcessUtilTest, GetAppOutput) { EXPECT_STREQ("foobar42", output.c_str()); } +TEST_F(ProcessUtilTest, GetAppOutputRestricted) { + // Unfortunately, since we can't rely on the path, we need to know where + // everything is. So let's use /bin/sh, which is on every POSIX system, and + // its built-ins. + std::vector<std::string> argv; + argv.push_back("/bin/sh"); // argv[0] + argv.push_back("-c"); // argv[1] + + // On success, should set |output|. We use |/bin/sh -c 'exit 0'| instead of + // |true| since the location of the latter may be |/bin| or |/usr/bin| (and we + // need absolute paths). + argv.push_back("exit 0"); // argv[2]; equivalent to "true" + std::string output = "abc"; + EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 100)); + EXPECT_STREQ("", output.c_str()); + + // On failure, should not touch |output|. As above, but for |false|. + argv[2] = "exit 1"; // equivalent to "false" + output = "abc"; + EXPECT_FALSE(GetAppOutputRestricted(CommandLine(argv), + &output, 100)); + EXPECT_STREQ("abc", output.c_str()); + + // Amount of output exactly equal to space allowed. + argv[2] = "echo 123456789"; // (the sh built-in doesn't take "-n") + output.clear(); + EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 10)); + EXPECT_STREQ("123456789\n", output.c_str()); + + // Amount of output greater than space allowed. + output.clear(); + EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 5)); + EXPECT_STREQ("12345", output.c_str()); + + // Amount of output less than space allowed. + output.clear(); + EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 15)); + EXPECT_STREQ("123456789\n", output.c_str()); + + // Zero space allowed. + output = "abc"; + EXPECT_TRUE(GetAppOutputRestricted(CommandLine(argv), &output, 0)); + EXPECT_STREQ("", output.c_str()); +} + #if defined(OS_LINUX) TEST_F(ProcessUtilTest, GetParentProcessId) { base::ProcessId ppid = GetParentProcessId(GetCurrentProcId()); |