diff options
author | pastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-25 13:21:33 +0000 |
---|---|---|
committer | pastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-25 13:21:33 +0000 |
commit | f51a7d903bf74513618ab8bf5b392af540227dbe (patch) | |
tree | c141c66ee6237f7b12a3bda37417bc30d298b270 /chrome/browser/policy/policy_path_parser_unittest.cc | |
parent | 2b4bab327076ffb54ccaae6264cf62d8eb0f5194 (diff) | |
download | chromium_src-f51a7d903bf74513618ab8bf5b392af540227dbe.zip chromium_src-f51a7d903bf74513618ab8bf5b392af540227dbe.tar.gz chromium_src-f51a7d903bf74513618ab8bf5b392af540227dbe.tar.bz2 |
Added TranslateVariablesInPolicy to the policy toolkit.
This function was implemented for mac and win in the chrome_main_xxx files because it was used only by the UserDataDir policy until now. However we need this in the DownloadDirectory policy too so I extracted in in a more
global way in the policy::path_parser namespace.
BUG=None
TEST=unit_tests:PolicyPathParser.*
Review URL: http://codereview.chromium.org/6469081
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76045 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/policy/policy_path_parser_unittest.cc')
-rw-r--r-- | chrome/browser/policy/policy_path_parser_unittest.cc | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/chrome/browser/policy/policy_path_parser_unittest.cc b/chrome/browser/policy/policy_path_parser_unittest.cc new file mode 100644 index 0000000..49e49cc --- /dev/null +++ b/chrome/browser/policy/policy_path_parser_unittest.cc @@ -0,0 +1,93 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <base/file_path.h> +#include <chrome/browser/policy/policy_path_parser.h> + +#include "testing/gtest/include/gtest/gtest.h" + +namespace policy { + +class PolicyPathParserTests : public testing::Test { + protected: + void CheckForSubstitution(FilePath::StringType test_string, + FilePath::StringType var_name) { + FilePath::StringType var(test_string); + FilePath::StringType var_result = + path_parser::ExpandPathVariables(var); + ASSERT_EQ(var_result.find(var_name), FilePath::StringType::npos); + } +}; + +TEST_F(PolicyPathParserTests, AllPlatformVariables) { + // No vars whatsoever no substitution should occur. + FilePath::StringType no_vars(FILE_PATH_LITERAL("//$C/shares")); + FilePath::StringType no_vars_result = + path_parser::ExpandPathVariables(no_vars); + ASSERT_EQ(no_vars_result, no_vars); + + // This is unknown variable and shouldn't be substituted. + FilePath::StringType unknown_vars(FILE_PATH_LITERAL("//$C/${buggy}")); + FilePath::StringType unknown_vars_result = + path_parser::ExpandPathVariables(unknown_vars); + ASSERT_EQ(unknown_vars_result, unknown_vars); + + // Both should have been substituted. + FilePath::StringType vars(FILE_PATH_LITERAL("${user_name}${machine_name}")); + FilePath::StringType vars_result = path_parser::ExpandPathVariables(vars); + ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${user_name}")), + FilePath::StringType::npos); + ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}")), + FilePath::StringType::npos); + + // Should substitute only one instance. + vars = FILE_PATH_LITERAL("${machine_name}${machine_name}"); + vars_result = path_parser::ExpandPathVariables(vars); + size_t pos = vars_result.find(FILE_PATH_LITERAL("${machine_name}")); + ASSERT_NE(pos, FilePath::StringType::npos); + ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}"), pos+1), + FilePath::StringType::npos); + + vars =FILE_PATH_LITERAL("${user_name}${machine_name}"); + vars_result = path_parser::ExpandPathVariables(vars); + ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${user_name}")), + FilePath::StringType::npos); + ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}")), + FilePath::StringType::npos); + + CheckForSubstitution(FILE_PATH_LITERAL("//$C/${user_name}"), + FILE_PATH_LITERAL("${user_name}")); + CheckForSubstitution(FILE_PATH_LITERAL("//$C/${machine_name}"), + FILE_PATH_LITERAL("${machine_name}")); +} + +#if defined(OS_MACOSX) + +TEST_F(PolicyPathParserTests, MacVariables) { + CheckForSubstitution(FILE_PATH_LITERAL("//$C/${users}"), + FILE_PATH_LITERAL("${users}")); + CheckForSubstitution(FILE_PATH_LITERAL("//$C/${documents}"), + FILE_PATH_LITERAL("${documents}")); +} + +#elif defined(OS_WIN) + +TEST_F(PolicyPathParserTests, WinVariables) { + CheckForSubstitution(FILE_PATH_LITERAL("//$C/${documents}"), + FILE_PATH_LITERAL("${documents}")); + CheckForSubstitution(FILE_PATH_LITERAL("//$C/${local_app_data}"), + FILE_PATH_LITERAL("${local_app_data}")); + CheckForSubstitution(FILE_PATH_LITERAL("//$C/${profile}"), + FILE_PATH_LITERAL("${profile}")); + CheckForSubstitution(FILE_PATH_LITERAL("//$C/${global_app_data}"), + FILE_PATH_LITERAL("${global_app_data}")); + CheckForSubstitution(FILE_PATH_LITERAL("//$C/${program_files}"), + FILE_PATH_LITERAL("${program_files}")); + CheckForSubstitution(FILE_PATH_LITERAL("//$C/${windows}"), + FILE_PATH_LITERAL("${windows}")); +} + +#endif // OS_WIN + +} // namespace policy |