1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/nacl/zygote/nacl_fork_delegate_linux.h"
6
7 #include <memory>
8
9 #include "base/environment.h"
10 #include "base/process/launch.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace nacl {
14
TEST(NaClForkDelegateLinuxTest,EnvPassthrough)15 TEST(NaClForkDelegateLinuxTest, EnvPassthrough) {
16 std::unique_ptr<base::Environment> env(base::Environment::Create());
17 const char passthrough1[] = "HELPER_PASSTHROUGH1";
18 const char passthrough2[] = "HELPER_PASSTHROUGH2";
19 const char passthrough3[] = "HELPER_PASSTHROUGH3";
20 const char passthrough4[] = "HELPER_PASSTHROUGH4";
21 const char passthrough5[] = "NACL_EXE_STDOUT";
22 const char value1[] = "passthrough_value1";
23 const char value3[] = "passthrough_value3";
24 const char value4[] = "passthrough_value4";
25 const char value5[] = "passthrough_value5";
26 std::string passthrough_value;
27 passthrough_value += passthrough1;
28 passthrough_value += ",";
29 passthrough_value += passthrough2;
30 passthrough_value += ",";
31 passthrough_value += passthrough3;
32 // Not adding passthrough4 to the passthrough variable.
33 // Not adding passthrough5 either because it is implicitly allowed.
34 env->SetVar("NACL_ENV_PASSTHROUGH", passthrough_value.c_str());
35 env->SetVar(passthrough1, value1);
36 // Intentionally skip setting a value for passthrough2.
37 env->SetVar(passthrough3, value3);
38 env->SetVar(passthrough4, value4);
39 env->SetVar(passthrough5, value5);
40
41 base::LaunchOptions options;
42 NaClForkDelegate::AddPassthroughEnvToOptions(&options);
43 EXPECT_EQ(value1, options.environment[passthrough1]);
44 EXPECT_EQ(0U, options.environment.count(passthrough2));
45 EXPECT_EQ(value3, options.environment[passthrough3]);
46 EXPECT_EQ(0U, options.environment.count(passthrough4));
47 EXPECT_EQ(value5, options.environment[passthrough5]);
48 }
49
50 } // namespace nacl
51