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

Side by Side Diff: chrome/browser/policy/policy_path_parser_unittest.cc

Issue 214233003: Refactorise the policy_path_parser framework (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes the review comments Created 6 years, 8 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
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 #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 #if defined(OS_MACOSX) 23 namespace path_parser {
24 // http://crbug.com/327520 24
25 #define MAYBE_AllPlatformVariables DISABLED_AllPlatformVariables 25 // The test needs access to a routine that is not exposed via the public header.
26 #else 26 void ReplaceVariableInPathWithValue(
27 #define MAYBE_AllPlatformVariables AllPlatformVariables 27 const base::FilePath::StringType& variable,
28 #endif 28 const policy::path_parser::internal::GetValueFuncPtr& value_func_ptr,
29 TEST_F(PolicyPathParserTests, MAYBE_AllPlatformVariables) { 29 base::FilePath::StringType* path);
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) {
30 // No vars whatsoever no substitution should occur. 58 // No vars whatsoever no substitution should occur.
31 base::FilePath::StringType no_vars(FILE_PATH_LITERAL("//$C/shares")); 59 base::FilePath::StringType no_vars(FILE_PATH_LITERAL("//$C/shares"));
32 base::FilePath::StringType no_vars_result = 60 base::FilePath::StringType no_vars_result =
33 path_parser::ExpandPathVariables(no_vars); 61 path_parser::ExpandPathVariables(no_vars);
34 ASSERT_EQ(no_vars_result, no_vars); 62 ASSERT_EQ(no_vars_result, no_vars);
35 63
36 // This is unknown variable and shouldn't be substituted. 64 // This is unknown variable and shouldn't be substituted.
37 base::FilePath::StringType unknown_vars(FILE_PATH_LITERAL("//$C/${buggy}")); 65 base::FilePath::StringType unknown_vars(FILE_PATH_LITERAL("//$C/${buggy}"));
38 base::FilePath::StringType unknown_vars_result = 66 base::FilePath::StringType unknown_vars_result =
39 path_parser::ExpandPathVariables(unknown_vars); 67 path_parser::ExpandPathVariables(unknown_vars);
40 ASSERT_EQ(unknown_vars_result, unknown_vars); 68 ASSERT_EQ(unknown_vars_result, unknown_vars);
41 69
42 // Trim quotes around, but not inside paths. Test against bug 80211. 70 // Trim quotes around, but not inside paths. Test against bug 80211.
43 base::FilePath::StringType no_quotes(FILE_PATH_LITERAL("//$C/\"a\"/$path")); 71 base::FilePath::StringType no_quotes(FILE_PATH_LITERAL("//$C/\"a\"/$path"));
44 base::FilePath::StringType single_quotes( 72 base::FilePath::StringType single_quotes(
45 FILE_PATH_LITERAL("'//$C/\"a\"/$path'")); 73 FILE_PATH_LITERAL("'//$C/\"a\"/$path'"));
46 base::FilePath::StringType double_quotes( 74 base::FilePath::StringType double_quotes(
47 FILE_PATH_LITERAL("\"//$C/\"a\"/$path\"")); 75 FILE_PATH_LITERAL("\"//$C/\"a\"/$path\""));
48 base::FilePath::StringType quotes_result = 76 base::FilePath::StringType quotes_result =
49 path_parser::ExpandPathVariables(single_quotes); 77 path_parser::ExpandPathVariables(single_quotes);
50 ASSERT_EQ(quotes_result, no_quotes); 78 ASSERT_EQ(quotes_result, no_quotes);
51 quotes_result = path_parser::ExpandPathVariables(double_quotes); 79 quotes_result = path_parser::ExpandPathVariables(double_quotes);
52 ASSERT_EQ(quotes_result, no_quotes); 80 ASSERT_EQ(quotes_result, no_quotes);
81 }
53 82
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) {
54 // Both should have been substituted. 90 // Both should have been substituted.
55 base::FilePath::StringType vars( 91 base::FilePath::StringType vars(
56 FILE_PATH_LITERAL("${user_name}${machine_name}")); 92 FILE_PATH_LITERAL("${user_name}${machine_name}"));
57 base::FilePath::StringType vars_result = 93 base::FilePath::StringType vars_result =
58 path_parser::ExpandPathVariables(vars); 94 path_parser::ExpandPathVariables(vars);
59 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${user_name}")), 95 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${user_name}")),
60 base::FilePath::StringType::npos); 96 base::FilePath::StringType::npos);
61 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}")), 97 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}")),
62 base::FilePath::StringType::npos); 98 base::FilePath::StringType::npos);
63 99
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 FILE_PATH_LITERAL("${program_files}")); 144 FILE_PATH_LITERAL("${program_files}"));
109 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${windows}"), 145 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${windows}"),
110 FILE_PATH_LITERAL("${windows}")); 146 FILE_PATH_LITERAL("${windows}"));
111 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${client_name}"), 147 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${client_name}"),
112 FILE_PATH_LITERAL("${client_name}")); 148 FILE_PATH_LITERAL("${client_name}"));
113 } 149 }
114 150
115 #endif // OS_WIN 151 #endif // OS_WIN
116 152
117 } // namespace policy 153 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698