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

Side by Side Diff: base/process_util_unittest.cc

Issue 7258005: Clean up users of a deprecated base::LaunchApp API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/eintr_wrapper.h" 10 #include "base/eintr_wrapper.h"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 ret = HANDLE_EINTR(close(sockets[0])); 488 ret = HANDLE_EINTR(close(sockets[0]));
489 DPCHECK(ret == 0); 489 DPCHECK(ret == 0);
490 ret = HANDLE_EINTR(close(sockets[1])); 490 ret = HANDLE_EINTR(close(sockets[1]));
491 DPCHECK(ret == 0); 491 DPCHECK(ret == 0);
492 ret = HANDLE_EINTR(close(dev_null)); 492 ret = HANDLE_EINTR(close(dev_null));
493 DPCHECK(ret == 0); 493 DPCHECK(ret == 0);
494 } 494 }
495 495
496 namespace { 496 namespace {
497 497
498 std::string TestLaunchApp(const base::environment_vector& env_changes) { 498 std::string TestLaunchProcess(const base::environment_vector& env_changes) {
499 std::vector<std::string> args; 499 std::vector<std::string> args;
500 base::file_handle_mapping_vector fds_to_remap; 500 base::file_handle_mapping_vector fds_to_remap;
501 base::ProcessHandle handle;
502 501
503 args.push_back("bash"); 502 args.push_back("bash");
504 args.push_back("-c"); 503 args.push_back("-c");
505 args.push_back("echo $BASE_TEST"); 504 args.push_back("echo $BASE_TEST");
506 505
507 int fds[2]; 506 int fds[2];
508 PCHECK(pipe(fds) == 0); 507 PCHECK(pipe(fds) == 0);
509 508
510 fds_to_remap.push_back(std::make_pair(fds[1], 1)); 509 fds_to_remap.push_back(std::make_pair(fds[1], 1));
511 EXPECT_TRUE(base::LaunchApp(args, env_changes, fds_to_remap, 510 base::LaunchOptions options;
512 true /* wait for exit */, &handle)); 511 options.wait = true;
512 options.environ = &env_changes;
513 options.fds_to_remap = &fds_to_remap;
514 EXPECT_TRUE(base::LaunchProcess(args, options));
513 PCHECK(HANDLE_EINTR(close(fds[1])) == 0); 515 PCHECK(HANDLE_EINTR(close(fds[1])) == 0);
514 516
515 char buf[512]; 517 char buf[512];
516 const ssize_t n = HANDLE_EINTR(read(fds[0], buf, sizeof(buf))); 518 const ssize_t n = HANDLE_EINTR(read(fds[0], buf, sizeof(buf)));
517 PCHECK(n > 0); 519 PCHECK(n > 0);
518 520
519 PCHECK(HANDLE_EINTR(close(fds[0])) == 0); 521 PCHECK(HANDLE_EINTR(close(fds[0])) == 0);
520 522
521 return std::string(buf, n); 523 return std::string(buf, n);
522 } 524 }
523 525
524 const char kLargeString[] = 526 const char kLargeString[] =
525 "0123456789012345678901234567890123456789012345678901234567890123456789" 527 "0123456789012345678901234567890123456789012345678901234567890123456789"
526 "0123456789012345678901234567890123456789012345678901234567890123456789" 528 "0123456789012345678901234567890123456789012345678901234567890123456789"
527 "0123456789012345678901234567890123456789012345678901234567890123456789" 529 "0123456789012345678901234567890123456789012345678901234567890123456789"
528 "0123456789012345678901234567890123456789012345678901234567890123456789" 530 "0123456789012345678901234567890123456789012345678901234567890123456789"
529 "0123456789012345678901234567890123456789012345678901234567890123456789" 531 "0123456789012345678901234567890123456789012345678901234567890123456789"
530 "0123456789012345678901234567890123456789012345678901234567890123456789" 532 "0123456789012345678901234567890123456789012345678901234567890123456789"
531 "0123456789012345678901234567890123456789012345678901234567890123456789"; 533 "0123456789012345678901234567890123456789012345678901234567890123456789";
532 534
533 } // namespace 535 } // namespace
534 536
535 TEST_F(ProcessUtilTest, LaunchApp) { 537 TEST_F(ProcessUtilTest, LaunchProcess) {
536 base::environment_vector env_changes; 538 base::environment_vector env_changes;
537 539
538 env_changes.push_back(std::make_pair(std::string("BASE_TEST"), 540 env_changes.push_back(std::make_pair(std::string("BASE_TEST"),
539 std::string("bar"))); 541 std::string("bar")));
540 EXPECT_EQ("bar\n", TestLaunchApp(env_changes)); 542 EXPECT_EQ("bar\n", TestLaunchProcess(env_changes));
541 env_changes.clear(); 543 env_changes.clear();
542 544
543 EXPECT_EQ(0, setenv("BASE_TEST", "testing", 1 /* override */)); 545 EXPECT_EQ(0, setenv("BASE_TEST", "testing", 1 /* override */));
544 EXPECT_EQ("testing\n", TestLaunchApp(env_changes)); 546 EXPECT_EQ("testing\n", TestLaunchProcess(env_changes));
545 547
546 env_changes.push_back(std::make_pair(std::string("BASE_TEST"), 548 env_changes.push_back(std::make_pair(std::string("BASE_TEST"),
547 std::string(""))); 549 std::string("")));
548 EXPECT_EQ("\n", TestLaunchApp(env_changes)); 550 EXPECT_EQ("\n", TestLaunchProcess(env_changes));
549 551
550 env_changes[0].second = "foo"; 552 env_changes[0].second = "foo";
551 EXPECT_EQ("foo\n", TestLaunchApp(env_changes)); 553 EXPECT_EQ("foo\n", TestLaunchProcess(env_changes));
552 554
553 env_changes.clear(); 555 env_changes.clear();
554 EXPECT_EQ(0, setenv("BASE_TEST", kLargeString, 1 /* override */)); 556 EXPECT_EQ(0, setenv("BASE_TEST", kLargeString, 1 /* override */));
555 EXPECT_EQ(std::string(kLargeString) + "\n", TestLaunchApp(env_changes)); 557 EXPECT_EQ(std::string(kLargeString) + "\n", TestLaunchProcess(env_changes));
556 558
557 env_changes.push_back(std::make_pair(std::string("BASE_TEST"), 559 env_changes.push_back(std::make_pair(std::string("BASE_TEST"),
558 std::string("wibble"))); 560 std::string("wibble")));
559 EXPECT_EQ("wibble\n", TestLaunchApp(env_changes)); 561 EXPECT_EQ("wibble\n", TestLaunchProcess(env_changes));
560 } 562 }
561 563
562 TEST_F(ProcessUtilTest, AlterEnvironment) { 564 TEST_F(ProcessUtilTest, AlterEnvironment) {
563 const char* const empty[] = { NULL }; 565 const char* const empty[] = { NULL };
564 const char* const a2[] = { "A=2", NULL }; 566 const char* const a2[] = { "A=2", NULL };
565 base::environment_vector changes; 567 base::environment_vector changes;
566 char** e; 568 char** e;
567 569
568 e = base::AlterEnvironment(changes, empty); 570 e = base::AlterEnvironment(changes, empty);
569 EXPECT_TRUE(e[0] == NULL); 571 EXPECT_TRUE(e[0] == NULL);
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 ASSERT_DEATH({ 985 ASSERT_DEATH({
984 SetUpInDeathAssert(); 986 SetUpInDeathAssert();
985 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} 987 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {}
986 }, ""); 988 }, "");
987 } 989 }
988 990
989 #endif // !ARCH_CPU_64_BITS 991 #endif // !ARCH_CPU_64_BITS
990 #endif // OS_MACOSX 992 #endif // OS_MACOSX
991 993
992 #endif // !defined(OS_WIN) 994 #endif // !defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698