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 15 matching lines...) Expand all Loading... |
26 FilePath::StringType str(in_str); | 26 FilePath::StringType str(in_str); |
27 std::transform(str.begin(), str.end(), str.begin(), tolower); | 27 std::transform(str.begin(), str.end(), str.begin(), tolower); |
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 std::string extension_id; |
| 37 Extension::GenerateId("test", &extension_id); |
| 38 ExtensionResource resource(extension_id, root_path, relative_path); |
37 | 39 |
38 // The path doesn't exist on disk, we will be returned an empty path. | 40 // The path doesn't exist on disk, we will be returned an empty path. |
39 EXPECT_EQ(root_path.value(), resource.extension_root().value()); | 41 EXPECT_EQ(root_path.value(), resource.extension_root().value()); |
40 EXPECT_EQ(relative_path.value(), resource.relative_path().value()); | 42 EXPECT_EQ(relative_path.value(), resource.relative_path().value()); |
41 EXPECT_TRUE(resource.GetFilePath().empty()); | 43 EXPECT_TRUE(resource.GetFilePath().empty()); |
42 } | 44 } |
43 | 45 |
44 TEST(ExtensionResourceTest, CreateWithAllResourcesOnDisk) { | 46 TEST(ExtensionResourceTest, CreateWithAllResourcesOnDisk) { |
45 ScopedTempDir temp; | 47 ScopedTempDir temp; |
46 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 48 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
(...skipping 14 matching lines...) Expand all Loading... |
61 ASSERT_FALSE(locales.empty()); | 63 ASSERT_FALSE(locales.empty()); |
62 for (size_t i = 0; i < locales.size(); i++) { | 64 for (size_t i = 0; i < locales.size(); i++) { |
63 FilePath make_path; | 65 FilePath make_path; |
64 make_path = l10n_path.AppendASCII(locales[i]); | 66 make_path = l10n_path.AppendASCII(locales[i]); |
65 ASSERT_TRUE(file_util::CreateDirectory(make_path)); | 67 ASSERT_TRUE(file_util::CreateDirectory(make_path)); |
66 ASSERT_TRUE(file_util::WriteFile(make_path.AppendASCII(filename), | 68 ASSERT_TRUE(file_util::WriteFile(make_path.AppendASCII(filename), |
67 data.c_str(), data.length())); | 69 data.c_str(), data.length())); |
68 } | 70 } |
69 | 71 |
70 FilePath path; | 72 FilePath path; |
71 ExtensionResource resource(temp.path(), FilePath().AppendASCII(filename)); | 73 std::string extension_id; |
| 74 Extension::GenerateId("test", &extension_id); |
| 75 ExtensionResource resource(extension_id, temp.path(), |
| 76 FilePath().AppendASCII(filename)); |
72 FilePath resolved_path = resource.GetFilePath(); | 77 FilePath resolved_path = resource.GetFilePath(); |
73 | 78 |
74 FilePath expected_path; | 79 FilePath expected_path; |
75 // Expect default path only, since fallback logic is disabled. | 80 // Expect default path only, since fallback logic is disabled. |
76 // See http://crbug.com/27359. | 81 // See http://crbug.com/27359. |
77 expected_path = root_resource; | 82 expected_path = root_resource; |
78 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); | 83 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); |
79 | 84 |
80 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value())); | 85 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value())); |
81 EXPECT_EQ(ToLower(temp.path().value()), | 86 EXPECT_EQ(ToLower(temp.path().value()), |
82 ToLower(resource.extension_root().value())); | 87 ToLower(resource.extension_root().value())); |
83 EXPECT_EQ(ToLower(FilePath().AppendASCII(filename).value()), | 88 EXPECT_EQ(ToLower(FilePath().AppendASCII(filename).value()), |
84 ToLower(resource.relative_path().value())); | 89 ToLower(resource.relative_path().value())); |
85 } | 90 } |
OLD | NEW |