| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS | 
| 6 | 6 | 
| 7 #include <limits> | 7 #include <limits> | 
| 8 | 8 | 
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" | 
| 10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" | 
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 318   std::string message; | 318   std::string message; | 
| 319   for (int i = 0; i < 1025; i++) {  // 1025 so it does not end on a kilo-byte | 319   for (int i = 0; i < 1025; i++) {  // 1025 so it does not end on a kilo-byte | 
| 320                                     // boundary. | 320                                     // boundary. | 
| 321     message += "Hello!"; | 321     message += "Hello!"; | 
| 322   } | 322   } | 
| 323   // cmd.exe's echo always adds a \r\n to its output. | 323   // cmd.exe's echo always adds a \r\n to its output. | 
| 324   std::string expected(message); | 324   std::string expected(message); | 
| 325   expected += "\r\n"; | 325   expected += "\r\n"; | 
| 326 | 326 | 
| 327   FilePath cmd(L"cmd.exe"); | 327   FilePath cmd(L"cmd.exe"); | 
| 328   CommandLine cmd_line(cmd); | 328   base::CommandLine cmd_line(cmd); | 
| 329   cmd_line.AppendArg("/c"); | 329   cmd_line.AppendArg("/c"); | 
| 330   cmd_line.AppendArg("echo " + message + ""); | 330   cmd_line.AppendArg("echo " + message + ""); | 
| 331   std::string output; | 331   std::string output; | 
| 332   ASSERT_TRUE(base::GetAppOutput(cmd_line, &output)); | 332   ASSERT_TRUE(base::GetAppOutput(cmd_line, &output)); | 
| 333   EXPECT_EQ(expected, output); | 333   EXPECT_EQ(expected, output); | 
| 334 | 334 | 
| 335   // Let's make sure stderr is ignored. | 335   // Let's make sure stderr is ignored. | 
| 336   CommandLine other_cmd_line(cmd); | 336   base::CommandLine other_cmd_line(cmd); | 
| 337   other_cmd_line.AppendArg("/c"); | 337   other_cmd_line.AppendArg("/c"); | 
| 338   // http://msdn.microsoft.com/library/cc772622.aspx | 338   // http://msdn.microsoft.com/library/cc772622.aspx | 
| 339   cmd_line.AppendArg("echo " + message + " >&2"); | 339   cmd_line.AppendArg("echo " + message + " >&2"); | 
| 340   output.clear(); | 340   output.clear(); | 
| 341   ASSERT_TRUE(base::GetAppOutput(other_cmd_line, &output)); | 341   ASSERT_TRUE(base::GetAppOutput(other_cmd_line, &output)); | 
| 342   EXPECT_EQ("", output); | 342   EXPECT_EQ("", output); | 
| 343 } | 343 } | 
| 344 | 344 | 
| 345 // TODO(estade): if possible, port this test. | 345 // TODO(estade): if possible, port this test. | 
| 346 TEST_F(ProcessUtilTest, LaunchAsUser) { | 346 TEST_F(ProcessUtilTest, LaunchAsUser) { | 
| 347   base::UserTokenHandle token; | 347   base::UserTokenHandle token; | 
| 348   ASSERT_TRUE(OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &token)); | 348   ASSERT_TRUE(OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &token)); | 
| 349   base::LaunchOptions options; | 349   base::LaunchOptions options; | 
| 350   options.as_user = token; | 350   options.as_user = token; | 
| 351   EXPECT_TRUE(base::LaunchProcess(MakeCmdLine("SimpleChildProcess"), options, | 351   EXPECT_TRUE(base::LaunchProcess(MakeCmdLine("SimpleChildProcess"), options, | 
| 352                                   NULL)); | 352                                   NULL)); | 
| 353 } | 353 } | 
| 354 | 354 | 
| 355 static const char kEventToTriggerHandleSwitch[] = "event-to-trigger-handle"; | 355 static const char kEventToTriggerHandleSwitch[] = "event-to-trigger-handle"; | 
| 356 | 356 | 
| 357 MULTIPROCESS_TEST_MAIN(TriggerEventChildProcess) { | 357 MULTIPROCESS_TEST_MAIN(TriggerEventChildProcess) { | 
| 358   std::string handle_value_string = | 358   std::string handle_value_string = | 
| 359       CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 359       base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 
| 360           kEventToTriggerHandleSwitch); | 360           kEventToTriggerHandleSwitch); | 
| 361   CHECK(!handle_value_string.empty()); | 361   CHECK(!handle_value_string.empty()); | 
| 362 | 362 | 
| 363   uint64 handle_value_uint64; | 363   uint64 handle_value_uint64; | 
| 364   CHECK(base::StringToUint64(handle_value_string, &handle_value_uint64)); | 364   CHECK(base::StringToUint64(handle_value_string, &handle_value_uint64)); | 
| 365   // Give ownership of the handle to |event|. | 365   // Give ownership of the handle to |event|. | 
| 366   base::WaitableEvent event(reinterpret_cast<HANDLE>(handle_value_uint64)); | 366   base::WaitableEvent event(reinterpret_cast<HANDLE>(handle_value_uint64)); | 
| 367 | 367 | 
| 368   event.Signal(); | 368   event.Signal(); | 
| 369 | 369 | 
| 370   return 0; | 370   return 0; | 
| 371 } | 371 } | 
| 372 | 372 | 
| 373 TEST_F(ProcessUtilTest, InheritSpecifiedHandles) { | 373 TEST_F(ProcessUtilTest, InheritSpecifiedHandles) { | 
| 374   // Manually create the event, so that it can be inheritable. | 374   // Manually create the event, so that it can be inheritable. | 
| 375   SECURITY_ATTRIBUTES security_attributes = {}; | 375   SECURITY_ATTRIBUTES security_attributes = {}; | 
| 376   security_attributes.nLength = static_cast<DWORD>(sizeof(security_attributes)); | 376   security_attributes.nLength = static_cast<DWORD>(sizeof(security_attributes)); | 
| 377   security_attributes.lpSecurityDescriptor = NULL; | 377   security_attributes.lpSecurityDescriptor = NULL; | 
| 378   security_attributes.bInheritHandle = true; | 378   security_attributes.bInheritHandle = true; | 
| 379 | 379 | 
| 380   // Takes ownership of the event handle. | 380   // Takes ownership of the event handle. | 
| 381   base::WaitableEvent event( | 381   base::WaitableEvent event( | 
| 382       CreateEvent(&security_attributes, true, false, NULL)); | 382       CreateEvent(&security_attributes, true, false, NULL)); | 
| 383   base::HandlesToInheritVector handles_to_inherit; | 383   base::HandlesToInheritVector handles_to_inherit; | 
| 384   handles_to_inherit.push_back(event.handle()); | 384   handles_to_inherit.push_back(event.handle()); | 
| 385   base::LaunchOptions options; | 385   base::LaunchOptions options; | 
| 386   options.handles_to_inherit = &handles_to_inherit; | 386   options.handles_to_inherit = &handles_to_inherit; | 
| 387 | 387 | 
| 388   CommandLine cmd_line = MakeCmdLine("TriggerEventChildProcess"); | 388   base::CommandLine cmd_line = MakeCmdLine("TriggerEventChildProcess"); | 
| 389   cmd_line.AppendSwitchASCII(kEventToTriggerHandleSwitch, | 389   cmd_line.AppendSwitchASCII(kEventToTriggerHandleSwitch, | 
| 390       base::Uint64ToString(reinterpret_cast<uint64>(event.handle()))); | 390       base::Uint64ToString(reinterpret_cast<uint64>(event.handle()))); | 
| 391 | 391 | 
| 392   // This functionality actually requires Vista or later. Make sure that it | 392   // This functionality actually requires Vista or later. Make sure that it | 
| 393   // fails properly on XP. | 393   // fails properly on XP. | 
| 394   if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 394   if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 
| 395     EXPECT_FALSE(base::LaunchProcess(cmd_line, options, NULL)); | 395     EXPECT_FALSE(base::LaunchProcess(cmd_line, options, NULL)); | 
| 396     return; | 396     return; | 
| 397   } | 397   } | 
| 398 | 398 | 
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 703 | 703 | 
| 704 TEST_F(ProcessUtilTest, GetAppOutput) { | 704 TEST_F(ProcessUtilTest, GetAppOutput) { | 
| 705   std::string output; | 705   std::string output; | 
| 706 | 706 | 
| 707 #if defined(OS_ANDROID) | 707 #if defined(OS_ANDROID) | 
| 708   std::vector<std::string> argv; | 708   std::vector<std::string> argv; | 
| 709   argv.push_back("sh");  // Instead of /bin/sh, force path search to find it. | 709   argv.push_back("sh");  // Instead of /bin/sh, force path search to find it. | 
| 710   argv.push_back("-c"); | 710   argv.push_back("-c"); | 
| 711 | 711 | 
| 712   argv.push_back("exit 0"); | 712   argv.push_back("exit 0"); | 
| 713   EXPECT_TRUE(base::GetAppOutput(CommandLine(argv), &output)); | 713   EXPECT_TRUE(base::GetAppOutput(base::CommandLine(argv), &output)); | 
| 714   EXPECT_STREQ("", output.c_str()); | 714   EXPECT_STREQ("", output.c_str()); | 
| 715 | 715 | 
| 716   argv[2] = "exit 1"; | 716   argv[2] = "exit 1"; | 
| 717   EXPECT_FALSE(base::GetAppOutput(CommandLine(argv), &output)); | 717   EXPECT_FALSE(base::GetAppOutput(base::CommandLine(argv), &output)); | 
| 718   EXPECT_STREQ("", output.c_str()); | 718   EXPECT_STREQ("", output.c_str()); | 
| 719 | 719 | 
| 720   argv[2] = "echo foobar42"; | 720   argv[2] = "echo foobar42"; | 
| 721   EXPECT_TRUE(base::GetAppOutput(CommandLine(argv), &output)); | 721   EXPECT_TRUE(base::GetAppOutput(base::CommandLine(argv), &output)); | 
| 722   EXPECT_STREQ("foobar42\n", output.c_str()); | 722   EXPECT_STREQ("foobar42\n", output.c_str()); | 
| 723 #else | 723 #else | 
| 724   EXPECT_TRUE(base::GetAppOutput(CommandLine(FilePath("true")), &output)); | 724   EXPECT_TRUE(base::GetAppOutput(base::CommandLine(FilePath("true")), | 
|  | 725                                  &output)); | 
| 725   EXPECT_STREQ("", output.c_str()); | 726   EXPECT_STREQ("", output.c_str()); | 
| 726 | 727 | 
| 727   EXPECT_FALSE(base::GetAppOutput(CommandLine(FilePath("false")), &output)); | 728   EXPECT_FALSE(base::GetAppOutput(base::CommandLine(FilePath("false")), | 
|  | 729                                   &output)); | 
| 728 | 730 | 
| 729   std::vector<std::string> argv; | 731   std::vector<std::string> argv; | 
| 730   argv.push_back("/bin/echo"); | 732   argv.push_back("/bin/echo"); | 
| 731   argv.push_back("-n"); | 733   argv.push_back("-n"); | 
| 732   argv.push_back("foobar42"); | 734   argv.push_back("foobar42"); | 
| 733   EXPECT_TRUE(base::GetAppOutput(CommandLine(argv), &output)); | 735   EXPECT_TRUE(base::GetAppOutput(base::CommandLine(argv), &output)); | 
| 734   EXPECT_STREQ("foobar42", output.c_str()); | 736   EXPECT_STREQ("foobar42", output.c_str()); | 
| 735 #endif  // defined(OS_ANDROID) | 737 #endif  // defined(OS_ANDROID) | 
| 736 } | 738 } | 
| 737 | 739 | 
| 738 // Flakes on Android, crbug.com/375840 | 740 // Flakes on Android, crbug.com/375840 | 
| 739 #if defined(OS_ANDROID) | 741 #if defined(OS_ANDROID) | 
| 740 #define MAYBE_GetAppOutputRestricted DISABLED_GetAppOutputRestricted | 742 #define MAYBE_GetAppOutputRestricted DISABLED_GetAppOutputRestricted | 
| 741 #else | 743 #else | 
| 742 #define MAYBE_GetAppOutputRestricted GetAppOutputRestricted | 744 #define MAYBE_GetAppOutputRestricted GetAppOutputRestricted | 
| 743 #endif | 745 #endif | 
| 744 TEST_F(ProcessUtilTest, MAYBE_GetAppOutputRestricted) { | 746 TEST_F(ProcessUtilTest, MAYBE_GetAppOutputRestricted) { | 
| 745   // Unfortunately, since we can't rely on the path, we need to know where | 747   // Unfortunately, since we can't rely on the path, we need to know where | 
| 746   // everything is. So let's use /bin/sh, which is on every POSIX system, and | 748   // everything is. So let's use /bin/sh, which is on every POSIX system, and | 
| 747   // its built-ins. | 749   // its built-ins. | 
| 748   std::vector<std::string> argv; | 750   std::vector<std::string> argv; | 
| 749   argv.push_back(std::string(kShellPath));  // argv[0] | 751   argv.push_back(std::string(kShellPath));  // argv[0] | 
| 750   argv.push_back("-c");  // argv[1] | 752   argv.push_back("-c");  // argv[1] | 
| 751 | 753 | 
| 752   // On success, should set |output|. We use |/bin/sh -c 'exit 0'| instead of | 754   // On success, should set |output|. We use |/bin/sh -c 'exit 0'| instead of | 
| 753   // |true| since the location of the latter may be |/bin| or |/usr/bin| (and we | 755   // |true| since the location of the latter may be |/bin| or |/usr/bin| (and we | 
| 754   // need absolute paths). | 756   // need absolute paths). | 
| 755   argv.push_back("exit 0");   // argv[2]; equivalent to "true" | 757   argv.push_back("exit 0");   // argv[2]; equivalent to "true" | 
| 756   std::string output = "abc"; | 758   std::string output = "abc"; | 
| 757   EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 100)); | 759   EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, | 
|  | 760                                            100)); | 
| 758   EXPECT_STREQ("", output.c_str()); | 761   EXPECT_STREQ("", output.c_str()); | 
| 759 | 762 | 
| 760   argv[2] = "exit 1";  // equivalent to "false" | 763   argv[2] = "exit 1";  // equivalent to "false" | 
| 761   output = "before"; | 764   output = "before"; | 
| 762   EXPECT_FALSE(base::GetAppOutputRestricted(CommandLine(argv), | 765   EXPECT_FALSE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, | 
| 763                                             &output, 100)); | 766                                             100)); | 
| 764   EXPECT_STREQ("", output.c_str()); | 767   EXPECT_STREQ("", output.c_str()); | 
| 765 | 768 | 
| 766   // Amount of output exactly equal to space allowed. | 769   // Amount of output exactly equal to space allowed. | 
| 767   argv[2] = "echo 123456789";  // (the sh built-in doesn't take "-n") | 770   argv[2] = "echo 123456789";  // (the sh built-in doesn't take "-n") | 
| 768   output.clear(); | 771   output.clear(); | 
| 769   EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 10)); | 772   EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, | 
|  | 773                                            10)); | 
| 770   EXPECT_STREQ("123456789\n", output.c_str()); | 774   EXPECT_STREQ("123456789\n", output.c_str()); | 
| 771 | 775 | 
| 772   // Amount of output greater than space allowed. | 776   // Amount of output greater than space allowed. | 
| 773   output.clear(); | 777   output.clear(); | 
| 774   EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 5)); | 778   EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, | 
|  | 779                                            5)); | 
| 775   EXPECT_STREQ("12345", output.c_str()); | 780   EXPECT_STREQ("12345", output.c_str()); | 
| 776 | 781 | 
| 777   // Amount of output less than space allowed. | 782   // Amount of output less than space allowed. | 
| 778   output.clear(); | 783   output.clear(); | 
| 779   EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 15)); | 784   EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, | 
|  | 785                                            15)); | 
| 780   EXPECT_STREQ("123456789\n", output.c_str()); | 786   EXPECT_STREQ("123456789\n", output.c_str()); | 
| 781 | 787 | 
| 782   // Zero space allowed. | 788   // Zero space allowed. | 
| 783   output = "abc"; | 789   output = "abc"; | 
| 784   EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 0)); | 790   EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, | 
|  | 791                                            0)); | 
| 785   EXPECT_STREQ("", output.c_str()); | 792   EXPECT_STREQ("", output.c_str()); | 
| 786 } | 793 } | 
| 787 | 794 | 
| 788 #if !defined(OS_MACOSX) && !defined(OS_OPENBSD) | 795 #if !defined(OS_MACOSX) && !defined(OS_OPENBSD) | 
| 789 // TODO(benwells): GetAppOutputRestricted should terminate applications | 796 // TODO(benwells): GetAppOutputRestricted should terminate applications | 
| 790 // with SIGPIPE when we have enough output. http://crbug.com/88502 | 797 // with SIGPIPE when we have enough output. http://crbug.com/88502 | 
| 791 TEST_F(ProcessUtilTest, GetAppOutputRestrictedSIGPIPE) { | 798 TEST_F(ProcessUtilTest, GetAppOutputRestrictedSIGPIPE) { | 
| 792   std::vector<std::string> argv; | 799   std::vector<std::string> argv; | 
| 793   std::string output; | 800   std::string output; | 
| 794 | 801 | 
| 795   argv.push_back(std::string(kShellPath));  // argv[0] | 802   argv.push_back(std::string(kShellPath));  // argv[0] | 
| 796   argv.push_back("-c"); | 803   argv.push_back("-c"); | 
| 797 #if defined(OS_ANDROID) | 804 #if defined(OS_ANDROID) | 
| 798   argv.push_back("while echo 12345678901234567890; do :; done"); | 805   argv.push_back("while echo 12345678901234567890; do :; done"); | 
| 799   EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 10)); | 806   EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, | 
|  | 807                                            10)); | 
| 800   EXPECT_STREQ("1234567890", output.c_str()); | 808   EXPECT_STREQ("1234567890", output.c_str()); | 
| 801 #else | 809 #else | 
| 802   argv.push_back("yes"); | 810   argv.push_back("yes"); | 
| 803   EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 10)); | 811   EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, | 
|  | 812                                            10)); | 
| 804   EXPECT_STREQ("y\ny\ny\ny\ny\n", output.c_str()); | 813   EXPECT_STREQ("y\ny\ny\ny\ny\n", output.c_str()); | 
| 805 #endif | 814 #endif | 
| 806 } | 815 } | 
| 807 #endif | 816 #endif | 
| 808 | 817 | 
| 809 #if defined(ADDRESS_SANITIZER) && defined(OS_MACOSX) && \ | 818 #if defined(ADDRESS_SANITIZER) && defined(OS_MACOSX) && \ | 
| 810     defined(ARCH_CPU_64_BITS) | 819     defined(ARCH_CPU_64_BITS) | 
| 811 // Times out under AddressSanitizer on 64-bit OS X, see | 820 // Times out under AddressSanitizer on 64-bit OS X, see | 
| 812 // http://crbug.com/298197. | 821 // http://crbug.com/298197. | 
| 813 #define MAYBE_GetAppOutputRestrictedNoZombies \ | 822 #define MAYBE_GetAppOutputRestrictedNoZombies \ | 
| 814     DISABLED_GetAppOutputRestrictedNoZombies | 823     DISABLED_GetAppOutputRestrictedNoZombies | 
| 815 #else | 824 #else | 
| 816 #define MAYBE_GetAppOutputRestrictedNoZombies GetAppOutputRestrictedNoZombies | 825 #define MAYBE_GetAppOutputRestrictedNoZombies GetAppOutputRestrictedNoZombies | 
| 817 #endif | 826 #endif | 
| 818 TEST_F(ProcessUtilTest, MAYBE_GetAppOutputRestrictedNoZombies) { | 827 TEST_F(ProcessUtilTest, MAYBE_GetAppOutputRestrictedNoZombies) { | 
| 819   std::vector<std::string> argv; | 828   std::vector<std::string> argv; | 
| 820 | 829 | 
| 821   argv.push_back(std::string(kShellPath));  // argv[0] | 830   argv.push_back(std::string(kShellPath));  // argv[0] | 
| 822   argv.push_back("-c");  // argv[1] | 831   argv.push_back("-c");  // argv[1] | 
| 823   argv.push_back("echo 123456789012345678901234567890");  // argv[2] | 832   argv.push_back("echo 123456789012345678901234567890");  // argv[2] | 
| 824 | 833 | 
| 825   // Run |GetAppOutputRestricted()| 300 (> default per-user processes on Mac OS | 834   // Run |GetAppOutputRestricted()| 300 (> default per-user processes on Mac OS | 
| 826   // 10.5) times with an output buffer big enough to capture all output. | 835   // 10.5) times with an output buffer big enough to capture all output. | 
| 827   for (int i = 0; i < 300; i++) { | 836   for (int i = 0; i < 300; i++) { | 
| 828     std::string output; | 837     std::string output; | 
| 829     EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 100)); | 838     EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, | 
|  | 839                                              100)); | 
| 830     EXPECT_STREQ("123456789012345678901234567890\n", output.c_str()); | 840     EXPECT_STREQ("123456789012345678901234567890\n", output.c_str()); | 
| 831   } | 841   } | 
| 832 | 842 | 
| 833   // Ditto, but with an output buffer too small to capture all output. | 843   // Ditto, but with an output buffer too small to capture all output. | 
| 834   for (int i = 0; i < 300; i++) { | 844   for (int i = 0; i < 300; i++) { | 
| 835     std::string output; | 845     std::string output; | 
| 836     EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 10)); | 846     EXPECT_TRUE(base::GetAppOutputRestricted(base::CommandLine(argv), &output, | 
|  | 847                                              10)); | 
| 837     EXPECT_STREQ("1234567890", output.c_str()); | 848     EXPECT_STREQ("1234567890", output.c_str()); | 
| 838   } | 849   } | 
| 839 } | 850 } | 
| 840 | 851 | 
| 841 TEST_F(ProcessUtilTest, GetAppOutputWithExitCode) { | 852 TEST_F(ProcessUtilTest, GetAppOutputWithExitCode) { | 
| 842   // Test getting output from a successful application. | 853   // Test getting output from a successful application. | 
| 843   std::vector<std::string> argv; | 854   std::vector<std::string> argv; | 
| 844   std::string output; | 855   std::string output; | 
| 845   int exit_code; | 856   int exit_code; | 
| 846   argv.push_back(std::string(kShellPath));  // argv[0] | 857   argv.push_back(std::string(kShellPath));  // argv[0] | 
| 847   argv.push_back("-c");  // argv[1] | 858   argv.push_back("-c");  // argv[1] | 
| 848   argv.push_back("echo foo");  // argv[2]; | 859   argv.push_back("echo foo");  // argv[2]; | 
| 849   EXPECT_TRUE(base::GetAppOutputWithExitCode(CommandLine(argv), &output, | 860   EXPECT_TRUE(base::GetAppOutputWithExitCode(base::CommandLine(argv), &output, | 
| 850                                              &exit_code)); | 861                                              &exit_code)); | 
| 851   EXPECT_STREQ("foo\n", output.c_str()); | 862   EXPECT_STREQ("foo\n", output.c_str()); | 
| 852   EXPECT_EQ(exit_code, 0); | 863   EXPECT_EQ(exit_code, 0); | 
| 853 | 864 | 
| 854   // Test getting output from an application which fails with a specific exit | 865   // Test getting output from an application which fails with a specific exit | 
| 855   // code. | 866   // code. | 
| 856   output.clear(); | 867   output.clear(); | 
| 857   argv[2] = "echo foo; exit 2"; | 868   argv[2] = "echo foo; exit 2"; | 
| 858   EXPECT_TRUE(base::GetAppOutputWithExitCode(CommandLine(argv), &output, | 869   EXPECT_TRUE(base::GetAppOutputWithExitCode(base::CommandLine(argv), &output, | 
| 859                                              &exit_code)); | 870                                              &exit_code)); | 
| 860   EXPECT_STREQ("foo\n", output.c_str()); | 871   EXPECT_STREQ("foo\n", output.c_str()); | 
| 861   EXPECT_EQ(exit_code, 2); | 872   EXPECT_EQ(exit_code, 2); | 
| 862 } | 873 } | 
| 863 | 874 | 
| 864 TEST_F(ProcessUtilTest, GetParentProcessId) { | 875 TEST_F(ProcessUtilTest, GetParentProcessId) { | 
| 865   base::ProcessId ppid = base::GetParentProcessId(base::GetCurrentProcId()); | 876   base::ProcessId ppid = base::GetParentProcessId(base::GetCurrentProcId()); | 
| 866   EXPECT_EQ(ppid, getppid()); | 877   EXPECT_EQ(ppid, getppid()); | 
| 867 } | 878 } | 
| 868 | 879 | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 904   // Check that process was really killed. | 915   // Check that process was really killed. | 
| 905   EXPECT_TRUE(IsProcessDead(child_process)); | 916   EXPECT_TRUE(IsProcessDead(child_process)); | 
| 906   base::CloseProcessHandle(child_process); | 917   base::CloseProcessHandle(child_process); | 
| 907 } | 918 } | 
| 908 | 919 | 
| 909 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { | 920 MULTIPROCESS_TEST_MAIN(process_util_test_die_immediately) { | 
| 910   return 0; | 921   return 0; | 
| 911 } | 922 } | 
| 912 | 923 | 
| 913 #endif  // defined(OS_POSIX) | 924 #endif  // defined(OS_POSIX) | 
| OLD | NEW | 
|---|