| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 9 #include "base/scoped_temp_dir.h" | |
| 10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 12 #include "chrome/common/extensions/extension_l10n_util.h" | 12 #include "chrome/common/extensions/extension_l10n_util.h" |
| 13 #include "chrome/common/extensions/extension_resource.h" | 13 #include "chrome/common/extensions/extension_resource.h" |
| 14 #include "chrome/common/extensions/extension_test_util.h" | 14 #include "chrome/common/extensions/extension_test_util.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 | 17 |
| 18 TEST(ExtensionResourceTest, CreateEmptyResource) { | 18 TEST(ExtensionResourceTest, CreateEmptyResource) { |
| 19 ExtensionResource resource; | 19 ExtensionResource resource; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 37 std::string extension_id = extension_test_util::MakeId("test"); | 37 std::string extension_id = extension_test_util::MakeId("test"); |
| 38 ExtensionResource resource(extension_id, root_path, relative_path); | 38 ExtensionResource resource(extension_id, root_path, relative_path); |
| 39 | 39 |
| 40 // 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. |
| 41 EXPECT_EQ(root_path.value(), resource.extension_root().value()); | 41 EXPECT_EQ(root_path.value(), resource.extension_root().value()); |
| 42 EXPECT_EQ(relative_path.value(), resource.relative_path().value()); | 42 EXPECT_EQ(relative_path.value(), resource.relative_path().value()); |
| 43 EXPECT_TRUE(resource.GetFilePath().empty()); | 43 EXPECT_TRUE(resource.GetFilePath().empty()); |
| 44 } | 44 } |
| 45 | 45 |
| 46 TEST(ExtensionResourceTest, ResourcesOutsideOfPath) { | 46 TEST(ExtensionResourceTest, ResourcesOutsideOfPath) { |
| 47 ScopedTempDir temp; | 47 base::ScopedTempDir temp; |
| 48 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 48 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 49 | 49 |
| 50 FilePath inner_dir = temp.path().AppendASCII("directory"); | 50 FilePath inner_dir = temp.path().AppendASCII("directory"); |
| 51 ASSERT_TRUE(file_util::CreateDirectory(inner_dir)); | 51 ASSERT_TRUE(file_util::CreateDirectory(inner_dir)); |
| 52 FilePath inner_file = inner_dir.AppendASCII("inner"); | 52 FilePath inner_file = inner_dir.AppendASCII("inner"); |
| 53 FilePath outer_file = temp.path().AppendASCII("outer"); | 53 FilePath outer_file = temp.path().AppendASCII("outer"); |
| 54 ASSERT_TRUE(file_util::WriteFile(outer_file, "X", 1)); | 54 ASSERT_TRUE(file_util::WriteFile(outer_file, "X", 1)); |
| 55 ASSERT_TRUE(file_util::WriteFile(inner_file, "X", 1)); | 55 ASSERT_TRUE(file_util::WriteFile(inner_file, "X", 1)); |
| 56 std::string extension_id = extension_test_util::MakeId("test"); | 56 std::string extension_id = extension_test_util::MakeId("test"); |
| 57 | 57 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 r6.set_follow_symlinks_anywhere(); | 99 r6.set_follow_symlinks_anywhere(); |
| 100 EXPECT_FALSE(r6.GetFilePath().empty()); | 100 EXPECT_FALSE(r6.GetFilePath().empty()); |
| 101 #endif | 101 #endif |
| 102 } | 102 } |
| 103 | 103 |
| 104 // crbug.com/108721. Disabled on Windows due to crashing on Vista. | 104 // crbug.com/108721. Disabled on Windows due to crashing on Vista. |
| 105 #if defined(OS_WIN) | 105 #if defined(OS_WIN) |
| 106 #define CreateWithAllResourcesOnDisk DISABLED_CreateWithAllResourcesOnDisk | 106 #define CreateWithAllResourcesOnDisk DISABLED_CreateWithAllResourcesOnDisk |
| 107 #endif | 107 #endif |
| 108 TEST(ExtensionResourceTest, CreateWithAllResourcesOnDisk) { | 108 TEST(ExtensionResourceTest, CreateWithAllResourcesOnDisk) { |
| 109 ScopedTempDir temp; | 109 base::ScopedTempDir temp; |
| 110 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 110 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 111 | 111 |
| 112 // Create resource in the extension root. | 112 // Create resource in the extension root. |
| 113 const char* filename = "res.ico"; | 113 const char* filename = "res.ico"; |
| 114 FilePath root_resource = temp.path().AppendASCII(filename); | 114 FilePath root_resource = temp.path().AppendASCII(filename); |
| 115 std::string data = "some foo"; | 115 std::string data = "some foo"; |
| 116 ASSERT_TRUE(file_util::WriteFile(root_resource, data.c_str(), data.length())); | 116 ASSERT_TRUE(file_util::WriteFile(root_resource, data.c_str(), data.length())); |
| 117 | 117 |
| 118 // Create l10n resources (for current locale and its parents). | 118 // Create l10n resources (for current locale and its parents). |
| 119 FilePath l10n_path = temp.path().Append(extensions::Extension::kLocaleFolder); | 119 FilePath l10n_path = temp.path().Append(extensions::Extension::kLocaleFolder); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 141 // See http://crbug.com/27359. | 141 // See http://crbug.com/27359. |
| 142 expected_path = root_resource; | 142 expected_path = root_resource; |
| 143 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); | 143 ASSERT_TRUE(file_util::AbsolutePath(&expected_path)); |
| 144 | 144 |
| 145 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value())); | 145 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value())); |
| 146 EXPECT_EQ(ToLower(temp.path().value()), | 146 EXPECT_EQ(ToLower(temp.path().value()), |
| 147 ToLower(resource.extension_root().value())); | 147 ToLower(resource.extension_root().value())); |
| 148 EXPECT_EQ(ToLower(FilePath().AppendASCII(filename).value()), | 148 EXPECT_EQ(ToLower(FilePath().AppendASCII(filename).value()), |
| 149 ToLower(resource.relative_path().value())); | 149 ToLower(resource.relative_path().value())); |
| 150 } | 150 } |
| OLD | NEW |