1 // Copyright 2014 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. 4 5 #include "chrome/browser/extensions/path_util.h" 6 7 #include "base/files/file_path.h" 8 #include "base/files/file_util.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 using base::FilePath; 12 13 namespace extensions { 14 15 // Basic unittest for path_util::PrettifyPath in 16 // chrome/browser/extensions/path_util.cc. 17 // For legacy reasons, it's tested more in 18 // FileSystemApiTest.FileSystemApiGetDisplayPathPrettify. 19 TEST(ExtensionPathUtilTest, BasicPrettifyPathTest) { 20 const FilePath::CharType kHomeShortcut[] = FILE_PATH_LITERAL("~"); 21 22 // Test prettifying empty path. 23 FilePath unprettified; 24 FilePath prettified = path_util::PrettifyPath(unprettified); 25 EXPECT_EQ(unprettified, prettified); 26 27 // Test home directory ("~"). 28 unprettified = base::GetHomeDir(); 29 prettified = path_util::PrettifyPath(unprettified); 30 EXPECT_NE(unprettified, prettified); 31 EXPECT_EQ(FilePath(kHomeShortcut), prettified); 32 33 // Test with one layer ("~/foo"). 34 unprettified = unprettified.AppendASCII("foo"); 35 prettified = path_util::PrettifyPath(unprettified); 36 EXPECT_NE(unprettified, prettified); 37 EXPECT_EQ(FilePath(kHomeShortcut).AppendASCII("foo"), prettified); 38 39 // Test with two layers ("~/foo/bar"). 40 unprettified = unprettified.AppendASCII("bar"); 41 prettified = path_util::PrettifyPath(unprettified); 42 EXPECT_NE(unprettified, prettified); 43 EXPECT_EQ( 44 FilePath(kHomeShortcut).AppendASCII("foo").AppendASCII("bar"), 45 prettified); 46 } 47 48 } // namespace extensions 49