| OLD | NEW |
| 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 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "chrome/browser/policy/policy_path_parser.h" | 6 #include "chrome/browser/policy/policy_path_parser.h" |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace policy { | 10 namespace policy { |
| 11 | 11 |
| 12 class PolicyPathParserTests : public testing::Test { | 12 class PolicyPathParserTests : public testing::Test { |
| 13 protected: | 13 protected: |
| 14 void CheckForSubstitution(base::FilePath::StringType test_string, | 14 void CheckForSubstitution(base::FilePath::StringType test_string, |
| 15 base::FilePath::StringType var_name) { | 15 base::FilePath::StringType var_name) { |
| 16 base::FilePath::StringType var(test_string); | 16 base::FilePath::StringType var(test_string); |
| 17 base::FilePath::StringType var_result = | 17 base::FilePath::StringType var_result = |
| 18 path_parser::ExpandPathVariables(var); | 18 path_parser::ExpandPathVariables(var); |
| 19 ASSERT_EQ(var_result.find(var_name), base::FilePath::StringType::npos); | 19 ASSERT_EQ(var_result.find(var_name), base::FilePath::StringType::npos); |
| 20 } | 20 } |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 namespace path_parser { | 23 #if defined(OS_MACOSX) |
| 24 | 24 // http://crbug.com/327520 |
| 25 // The test needs access to a routine that is not exposed via the public header. | 25 #define MAYBE_AllPlatformVariables DISABLED_AllPlatformVariables |
| 26 void ReplaceVariableInPathWithValue( | 26 #else |
| 27 const base::FilePath::StringType& variable, | 27 #define MAYBE_AllPlatformVariables AllPlatformVariables |
| 28 const policy::path_parser::internal::GetValueFuncPtr& value_func_ptr, | 28 #endif |
| 29 base::FilePath::StringType* path); | 29 TEST_F(PolicyPathParserTests, MAYBE_AllPlatformVariables) { |
| 30 | |
| 31 } // namespace path_parser; | |
| 32 | |
| 33 bool GetBuggy(base::FilePath::StringType* value) { | |
| 34 *value = base::FilePath::StringType(FILE_PATH_LITERAL("ok")); | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 TEST_F(PolicyPathParserTests, ReplaceVariableInPathWithValue) { | |
| 39 // This is custom variable with custom callback. It should replace ${buggy} | |
| 40 // with ok. | |
| 41 base::FilePath::StringType custom_vars(FILE_PATH_LITERAL("//$C/${buggy}")); | |
| 42 base::FilePath::StringType custom_vars_expected(FILE_PATH_LITERAL("//$C/ok")); | |
| 43 base::FilePath::StringType buggy(FILE_PATH_LITERAL("${buggy}")); | |
| 44 | |
| 45 path_parser::ReplaceVariableInPathWithValue(buggy, &GetBuggy, &custom_vars); | |
| 46 ASSERT_EQ(custom_vars, custom_vars_expected); | |
| 47 | |
| 48 // There is no ${buggy} in input, so it should remain unchanged. | |
| 49 base::FilePath::StringType custom2_vars(FILE_PATH_LITERAL("//$C/ok")); | |
| 50 base::FilePath::StringType custom2_vars_expected( | |
| 51 FILE_PATH_LITERAL("//$C/ok")); | |
| 52 | |
| 53 path_parser::ReplaceVariableInPathWithValue(buggy, &GetBuggy, &custom2_vars); | |
| 54 ASSERT_EQ(custom2_vars, custom2_vars_expected); | |
| 55 } | |
| 56 | |
| 57 TEST_F(PolicyPathParserTests, CommonExpandPathVariables) { | |
| 58 // No vars whatsoever no substitution should occur. | 30 // No vars whatsoever no substitution should occur. |
| 59 base::FilePath::StringType no_vars(FILE_PATH_LITERAL("//$C/shares")); | 31 base::FilePath::StringType no_vars(FILE_PATH_LITERAL("//$C/shares")); |
| 60 base::FilePath::StringType no_vars_result = | 32 base::FilePath::StringType no_vars_result = |
| 61 path_parser::ExpandPathVariables(no_vars); | 33 path_parser::ExpandPathVariables(no_vars); |
| 62 ASSERT_EQ(no_vars_result, no_vars); | 34 ASSERT_EQ(no_vars_result, no_vars); |
| 63 | 35 |
| 64 // This is unknown variable and shouldn't be substituted. | 36 // This is unknown variable and shouldn't be substituted. |
| 65 base::FilePath::StringType unknown_vars(FILE_PATH_LITERAL("//$C/${buggy}")); | 37 base::FilePath::StringType unknown_vars(FILE_PATH_LITERAL("//$C/${buggy}")); |
| 66 base::FilePath::StringType unknown_vars_result = | 38 base::FilePath::StringType unknown_vars_result = |
| 67 path_parser::ExpandPathVariables(unknown_vars); | 39 path_parser::ExpandPathVariables(unknown_vars); |
| 68 ASSERT_EQ(unknown_vars_result, unknown_vars); | 40 ASSERT_EQ(unknown_vars_result, unknown_vars); |
| 69 | 41 |
| 70 // Trim quotes around, but not inside paths. Test against bug 80211. | 42 // Trim quotes around, but not inside paths. Test against bug 80211. |
| 71 base::FilePath::StringType no_quotes(FILE_PATH_LITERAL("//$C/\"a\"/$path")); | 43 base::FilePath::StringType no_quotes(FILE_PATH_LITERAL("//$C/\"a\"/$path")); |
| 72 base::FilePath::StringType single_quotes( | 44 base::FilePath::StringType single_quotes( |
| 73 FILE_PATH_LITERAL("'//$C/\"a\"/$path'")); | 45 FILE_PATH_LITERAL("'//$C/\"a\"/$path'")); |
| 74 base::FilePath::StringType double_quotes( | 46 base::FilePath::StringType double_quotes( |
| 75 FILE_PATH_LITERAL("\"//$C/\"a\"/$path\"")); | 47 FILE_PATH_LITERAL("\"//$C/\"a\"/$path\"")); |
| 76 base::FilePath::StringType quotes_result = | 48 base::FilePath::StringType quotes_result = |
| 77 path_parser::ExpandPathVariables(single_quotes); | 49 path_parser::ExpandPathVariables(single_quotes); |
| 78 ASSERT_EQ(quotes_result, no_quotes); | 50 ASSERT_EQ(quotes_result, no_quotes); |
| 79 quotes_result = path_parser::ExpandPathVariables(double_quotes); | 51 quotes_result = path_parser::ExpandPathVariables(double_quotes); |
| 80 ASSERT_EQ(quotes_result, no_quotes); | 52 ASSERT_EQ(quotes_result, no_quotes); |
| 81 } | |
| 82 | 53 |
| 83 #if defined(OS_MACOSX) | |
| 84 // http://crbug.com/327520 | |
| 85 #define MAYBE_AllPlatformVariables DISABLED_AllPlatformVariables | |
| 86 #else | |
| 87 #define MAYBE_AllPlatformVariables AllPlatformVariables | |
| 88 #endif | |
| 89 TEST_F(PolicyPathParserTests, MAYBE_AllPlatformVariables) { | |
| 90 // Both should have been substituted. | 54 // Both should have been substituted. |
| 91 base::FilePath::StringType vars( | 55 base::FilePath::StringType vars( |
| 92 FILE_PATH_LITERAL("${user_name}${machine_name}")); | 56 FILE_PATH_LITERAL("${user_name}${machine_name}")); |
| 93 base::FilePath::StringType vars_result = | 57 base::FilePath::StringType vars_result = |
| 94 path_parser::ExpandPathVariables(vars); | 58 path_parser::ExpandPathVariables(vars); |
| 95 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${user_name}")), | 59 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${user_name}")), |
| 96 base::FilePath::StringType::npos); | 60 base::FilePath::StringType::npos); |
| 97 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}")), | 61 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}")), |
| 98 base::FilePath::StringType::npos); | 62 base::FilePath::StringType::npos); |
| 99 | 63 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 FILE_PATH_LITERAL("${program_files}")); | 108 FILE_PATH_LITERAL("${program_files}")); |
| 145 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${windows}"), | 109 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${windows}"), |
| 146 FILE_PATH_LITERAL("${windows}")); | 110 FILE_PATH_LITERAL("${windows}")); |
| 147 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${client_name}"), | 111 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${client_name}"), |
| 148 FILE_PATH_LITERAL("${client_name}")); | 112 FILE_PATH_LITERAL("${client_name}")); |
| 149 } | 113 } |
| 150 | 114 |
| 151 #endif // OS_WIN | 115 #endif // OS_WIN |
| 152 | 116 |
| 153 } // namespace policy | 117 } // namespace policy |
| OLD | NEW |