Extensions: Remove the legacy GetMessages/HasMessages
[chromium-blink-merge.git] / chrome / browser / policy / policy_path_parser_unittest.cc
blobb6437a4d3bed91f3fbe5803a756448f50e986ab0
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 "base/files/file_path.h"
6 #include "chrome/browser/policy/policy_path_parser.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace policy {
12 class PolicyPathParserTests : public testing::Test {
13 protected:
14 void CheckForSubstitution(base::FilePath::StringType test_string,
15 base::FilePath::StringType var_name) {
16 base::FilePath::StringType var(test_string);
17 base::FilePath::StringType var_result =
18 path_parser::ExpandPathVariables(var);
19 ASSERT_EQ(var_result.find(var_name), base::FilePath::StringType::npos);
23 // TODO(pastarmovj): Modify test or change the logic after investigating why it
24 // is flaky. Please only redisable after it has had a chance to run for a few
25 // times. See bug http://crbug.com/327520 for context.
26 // TODO(pastarmovj): Disabling on Mac OS X as the test is flaky. See
27 // crbug.com/458590 for details.
28 #if defined(OS_MACOSX)
29 #define MAYBE_AllPlatformVariables DISABLED_AllPlatformVariables
30 #else
31 #define MAYBE_AllPlatformVariables AllPlatformVariables
32 #endif
33 TEST_F(PolicyPathParserTests, MAYBE_AllPlatformVariables) {
34 // No vars whatsoever no substitution should occur.
35 base::FilePath::StringType no_vars(FILE_PATH_LITERAL("//$C/shares"));
36 base::FilePath::StringType no_vars_result =
37 path_parser::ExpandPathVariables(no_vars);
38 ASSERT_EQ(no_vars_result, no_vars);
40 // This is unknown variable and shouldn't be substituted.
41 base::FilePath::StringType unknown_vars(FILE_PATH_LITERAL("//$C/${buggy}"));
42 base::FilePath::StringType unknown_vars_result =
43 path_parser::ExpandPathVariables(unknown_vars);
44 ASSERT_EQ(unknown_vars_result, unknown_vars);
46 // Trim quotes around, but not inside paths. Test against bug 80211.
47 base::FilePath::StringType no_quotes(FILE_PATH_LITERAL("//$C/\"a\"/$path"));
48 base::FilePath::StringType single_quotes(
49 FILE_PATH_LITERAL("'//$C/\"a\"/$path'"));
50 base::FilePath::StringType double_quotes(
51 FILE_PATH_LITERAL("\"//$C/\"a\"/$path\""));
52 base::FilePath::StringType quotes_result =
53 path_parser::ExpandPathVariables(single_quotes);
54 ASSERT_EQ(quotes_result, no_quotes);
55 quotes_result = path_parser::ExpandPathVariables(double_quotes);
56 ASSERT_EQ(quotes_result, no_quotes);
58 // Both should have been substituted.
59 base::FilePath::StringType vars(
60 FILE_PATH_LITERAL("${user_name}${machine_name}"));
61 base::FilePath::StringType vars_result =
62 path_parser::ExpandPathVariables(vars);
63 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${user_name}")),
64 base::FilePath::StringType::npos);
65 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}")),
66 base::FilePath::StringType::npos);
68 // Should substitute only one instance.
69 vars = FILE_PATH_LITERAL("${machine_name}${machine_name}");
70 vars_result = path_parser::ExpandPathVariables(vars);
71 size_t pos = vars_result.find(FILE_PATH_LITERAL("${machine_name}"));
72 ASSERT_NE(pos, base::FilePath::StringType::npos);
73 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}"), pos+1),
74 base::FilePath::StringType::npos);
76 vars =FILE_PATH_LITERAL("${user_name}${machine_name}");
77 vars_result = path_parser::ExpandPathVariables(vars);
78 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${user_name}")),
79 base::FilePath::StringType::npos);
80 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}")),
81 base::FilePath::StringType::npos);
83 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${user_name}"),
84 FILE_PATH_LITERAL("${user_name}"));
85 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${machine_name}"),
86 FILE_PATH_LITERAL("${machine_name}"));
89 #if defined(OS_MACOSX)
91 TEST_F(PolicyPathParserTests, MacVariables) {
92 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${users}"),
93 FILE_PATH_LITERAL("${users}"));
94 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${documents}"),
95 FILE_PATH_LITERAL("${documents}"));
98 #elif defined(OS_WIN)
100 TEST_F(PolicyPathParserTests, WinVariables) {
101 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${documents}"),
102 FILE_PATH_LITERAL("${documents}"));
103 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${local_app_data}"),
104 FILE_PATH_LITERAL("${local_app_data}"));
105 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${roaming_app_data}"),
106 FILE_PATH_LITERAL("${roaming_app_data}"));
107 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${profile}"),
108 FILE_PATH_LITERAL("${profile}"));
109 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${global_app_data}"),
110 FILE_PATH_LITERAL("${global_app_data}"));
111 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${program_files}"),
112 FILE_PATH_LITERAL("${program_files}"));
113 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${windows}"),
114 FILE_PATH_LITERAL("${windows}"));
115 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${client_name}"),
116 FILE_PATH_LITERAL("${client_name}"));
117 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${session_name}"),
118 FILE_PATH_LITERAL("${session_name}"));
121 #endif // OS_WIN
123 } // namespace policy