Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Unified Diff: base/process_util_unittest.cc

Issue 173261: (Mac) Implement about:memory. (Closed)
Patch Set: Fixed per jrg's (re)review. Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process_util_posix.cc ('k') | chrome/browser/browser_resources.grd » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_util_unittest.cc
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc
index 0dfcd2b76cf5f6a0ce4764ad089de44d2bb1b4fe..c6605163b1367626f668986c63256c14bba4b29f 100644
--- a/base/process_util_unittest.cc
+++ b/base/process_util_unittest.cc
@@ -273,6 +273,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());
« no previous file with comments | « base/process_util_posix.cc ('k') | chrome/browser/browser_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698