Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / test / python_utils_unittest.cc
blob57b7f476d47d67b9a788f761e8422196dd22209c
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
3 // found in the LICENSE file.
5 #include <string>
7 #include "base/command_line.h"
8 #include "base/environment.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/process/launch.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h"
14 #include "net/test/python_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 TEST(PythonUtils, Append) {
18 const base::FilePath::CharType kAppendDir1[] =
19 FILE_PATH_LITERAL("test/path_append1");
20 const base::FilePath::CharType kAppendDir2[] =
21 FILE_PATH_LITERAL("test/path_append2");
23 scoped_ptr<base::Environment> env(base::Environment::Create());
25 std::string python_path;
26 base::FilePath append_path1(kAppendDir1);
27 base::FilePath append_path2(kAppendDir2);
29 // Get a clean start
30 env->UnSetVar(kPythonPathEnv);
32 // Append the path
33 AppendToPythonPath(append_path1);
34 env->GetVar(kPythonPathEnv, &python_path);
35 ASSERT_EQ(python_path, "test/path_append1");
37 // Append the safe path again, nothing changes
38 AppendToPythonPath(append_path2);
39 env->GetVar(kPythonPathEnv, &python_path);
40 #if defined(OS_WIN)
41 ASSERT_EQ(std::string("test/path_append1;test/path_append2"), python_path);
42 #elif defined(OS_POSIX)
43 ASSERT_EQ(std::string("test/path_append1:test/path_append2"), python_path);
44 #endif
47 #if defined(OS_ANDROID)
48 #define MAYBE_PythonRunTime DISABLED_PythonRunTime
49 #else
50 #define MAYBE_PythonRunTime PythonRunTime
51 #endif
52 TEST(PythonUtils, MAYBE_PythonRunTime) {
53 base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM);
54 EXPECT_TRUE(GetPythonCommand(&cmd_line));
56 // Run a python command to print a string and make sure the output is what
57 // we want.
58 cmd_line.AppendArg("-c");
59 std::string input("PythonUtilsTest");
60 std::string python_cmd = base::StringPrintf("print '%s';", input.c_str());
61 cmd_line.AppendArg(python_cmd);
62 std::string output;
63 EXPECT_TRUE(base::GetAppOutput(cmd_line, &output));
64 base::TrimWhitespace(output, base::TRIM_TRAILING, &output);
65 EXPECT_EQ(input, output);