| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 return str; | 28 return str; |
| 29 } | 29 } |
| 30 | 30 |
| 31 TEST(ExtensionResourceTest, CreateWithMissingResourceOnDisk) { | 31 TEST(ExtensionResourceTest, CreateWithMissingResourceOnDisk) { |
| 32 FilePath root_path; | 32 FilePath root_path; |
| 33 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &root_path)); | 33 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &root_path)); |
| 34 FilePath relative_path; | 34 FilePath relative_path; |
| 35 relative_path = relative_path.AppendASCII("cira.js"); | 35 relative_path = relative_path.AppendASCII("cira.js"); |
| 36 ExtensionResource resource(root_path, relative_path); | 36 ExtensionResource resource(root_path, relative_path); |
| 37 | 37 |
| 38 // The path doesn't exist on disk, we will be returned an empty path. |
| 38 EXPECT_EQ(root_path.value(), resource.extension_root().value()); | 39 EXPECT_EQ(root_path.value(), resource.extension_root().value()); |
| 39 EXPECT_EQ(relative_path.value(), resource.relative_path().value()); | 40 EXPECT_EQ(relative_path.value(), resource.relative_path().value()); |
| 40 EXPECT_EQ(ToLower(root_path.Append(relative_path).value()), | 41 EXPECT_TRUE(resource.GetFilePath().empty()); |
| 41 ToLower(resource.GetFilePath().value())); | |
| 42 | |
| 43 EXPECT_FALSE(resource.GetFilePath().empty()); | |
| 44 } | 42 } |
| 45 | 43 |
| 46 TEST(ExtensionResourceTest, CreateWithAllResourcesOnDisk) { | 44 TEST(ExtensionResourceTest, CreateWithAllResourcesOnDisk) { |
| 47 ScopedTempDir temp; | 45 ScopedTempDir temp; |
| 48 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 46 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 49 | 47 |
| 50 // Create resource in the extension root. | 48 // Create resource in the extension root. |
| 51 const char* filename = "res.ico"; | 49 const char* filename = "res.ico"; |
| 52 FilePath root_resource = temp.path().AppendASCII(filename); | 50 FilePath root_resource = temp.path().AppendASCII(filename); |
| 53 std::string data = "some foo"; | 51 std::string data = "some foo"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 69 data.c_str(), data.length())); | 67 data.c_str(), data.length())); |
| 70 } | 68 } |
| 71 | 69 |
| 72 FilePath path; | 70 FilePath path; |
| 73 ExtensionResource resource(temp.path(), FilePath().AppendASCII(filename)); | 71 ExtensionResource resource(temp.path(), FilePath().AppendASCII(filename)); |
| 74 FilePath resolved_path = resource.GetFilePath(); | 72 FilePath resolved_path = resource.GetFilePath(); |
| 75 | 73 |
| 76 ASSERT_FALSE(locales.empty()); | 74 ASSERT_FALSE(locales.empty()); |
| 77 FilePath expected_path; | 75 FilePath expected_path; |
| 78 expected_path = l10n_path.AppendASCII(locales[0]).AppendASCII(filename); | 76 expected_path = l10n_path.AppendASCII(locales[0]).AppendASCII(filename); |
| 77 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); |
| 79 | 78 |
| 80 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value())); | 79 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value())); |
| 81 EXPECT_EQ(ToLower(temp.path().value()), | 80 EXPECT_EQ(ToLower(temp.path().value()), |
| 82 ToLower(resource.extension_root().value())); | 81 ToLower(resource.extension_root().value())); |
| 83 EXPECT_EQ(ToLower(FilePath().AppendASCII(filename).value()), | 82 EXPECT_EQ(ToLower(FilePath().AppendASCII(filename).value()), |
| 84 ToLower(resource.relative_path().value())); | 83 ToLower(resource.relative_path().value())); |
| 85 } | 84 } |
| OLD | NEW |