Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Side by Side Diff: extensions/common/extension_resource_unittest.cc

Issue 481433005: Extensions: Move id_util functions to crx_file component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert last patchset. function returns Extension* and can't use an assert. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « extensions/common/extension.cc ('k') | extensions/common/id_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/files/scoped_temp_dir.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "components/crx_file/id_util.h"
10 #include "extensions/common/constants.h" 11 #include "extensions/common/constants.h"
11 #include "extensions/common/extension_paths.h" 12 #include "extensions/common/extension_paths.h"
12 #include "extensions/common/extension_resource.h" 13 #include "extensions/common/extension_resource.h"
13 #include "extensions/common/id_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 16
17 namespace extensions { 17 namespace extensions {
18 18
19 TEST(ExtensionResourceTest, CreateEmptyResource) { 19 TEST(ExtensionResourceTest, CreateEmptyResource) {
20 ExtensionResource resource; 20 ExtensionResource resource;
21 21
22 EXPECT_TRUE(resource.extension_root().empty()); 22 EXPECT_TRUE(resource.extension_root().empty());
23 EXPECT_TRUE(resource.relative_path().empty()); 23 EXPECT_TRUE(resource.relative_path().empty());
24 EXPECT_TRUE(resource.GetFilePath().empty()); 24 EXPECT_TRUE(resource.GetFilePath().empty());
25 } 25 }
26 26
27 const base::FilePath::StringType ToLower( 27 const base::FilePath::StringType ToLower(
28 const base::FilePath::StringType& in_str) { 28 const base::FilePath::StringType& in_str) {
29 base::FilePath::StringType str(in_str); 29 base::FilePath::StringType str(in_str);
30 std::transform(str.begin(), str.end(), str.begin(), tolower); 30 std::transform(str.begin(), str.end(), str.begin(), tolower);
31 return str; 31 return str;
32 } 32 }
33 33
34 TEST(ExtensionResourceTest, CreateWithMissingResourceOnDisk) { 34 TEST(ExtensionResourceTest, CreateWithMissingResourceOnDisk) {
35 base::FilePath root_path; 35 base::FilePath root_path;
36 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &root_path)); 36 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &root_path));
37 base::FilePath relative_path; 37 base::FilePath relative_path;
38 relative_path = relative_path.AppendASCII("cira.js"); 38 relative_path = relative_path.AppendASCII("cira.js");
39 std::string extension_id = id_util::GenerateId("test"); 39 std::string extension_id = crx_file::id_util::GenerateId("test");
40 ExtensionResource resource(extension_id, root_path, relative_path); 40 ExtensionResource resource(extension_id, root_path, relative_path);
41 41
42 // The path doesn't exist on disk, we will be returned an empty path. 42 // The path doesn't exist on disk, we will be returned an empty path.
43 EXPECT_EQ(root_path.value(), resource.extension_root().value()); 43 EXPECT_EQ(root_path.value(), resource.extension_root().value());
44 EXPECT_EQ(relative_path.value(), resource.relative_path().value()); 44 EXPECT_EQ(relative_path.value(), resource.relative_path().value());
45 EXPECT_TRUE(resource.GetFilePath().empty()); 45 EXPECT_TRUE(resource.GetFilePath().empty());
46 } 46 }
47 47
48 TEST(ExtensionResourceTest, ResourcesOutsideOfPath) { 48 TEST(ExtensionResourceTest, ResourcesOutsideOfPath) {
49 base::ScopedTempDir temp; 49 base::ScopedTempDir temp;
50 ASSERT_TRUE(temp.CreateUniqueTempDir()); 50 ASSERT_TRUE(temp.CreateUniqueTempDir());
51 51
52 base::FilePath inner_dir = temp.path().AppendASCII("directory"); 52 base::FilePath inner_dir = temp.path().AppendASCII("directory");
53 ASSERT_TRUE(base::CreateDirectory(inner_dir)); 53 ASSERT_TRUE(base::CreateDirectory(inner_dir));
54 base::FilePath sub_dir = inner_dir.AppendASCII("subdir"); 54 base::FilePath sub_dir = inner_dir.AppendASCII("subdir");
55 ASSERT_TRUE(base::CreateDirectory(sub_dir)); 55 ASSERT_TRUE(base::CreateDirectory(sub_dir));
56 base::FilePath inner_file = inner_dir.AppendASCII("inner"); 56 base::FilePath inner_file = inner_dir.AppendASCII("inner");
57 base::FilePath outer_file = temp.path().AppendASCII("outer"); 57 base::FilePath outer_file = temp.path().AppendASCII("outer");
58 ASSERT_TRUE(base::WriteFile(outer_file, "X", 1)); 58 ASSERT_TRUE(base::WriteFile(outer_file, "X", 1));
59 ASSERT_TRUE(base::WriteFile(inner_file, "X", 1)); 59 ASSERT_TRUE(base::WriteFile(inner_file, "X", 1));
60 std::string extension_id = id_util::GenerateId("test"); 60 std::string extension_id = crx_file::id_util::GenerateId("test");
61 61
62 #if defined(OS_POSIX) 62 #if defined(OS_POSIX)
63 base::FilePath symlink_file = inner_dir.AppendASCII("symlink"); 63 base::FilePath symlink_file = inner_dir.AppendASCII("symlink");
64 base::CreateSymbolicLink( 64 base::CreateSymbolicLink(
65 base::FilePath().AppendASCII("..").AppendASCII("outer"), 65 base::FilePath().AppendASCII("..").AppendASCII("outer"),
66 symlink_file); 66 symlink_file);
67 #endif 67 #endif
68 68
69 // A non-packing extension should be able to access the file within the 69 // A non-packing extension should be able to access the file within the
70 // directory. 70 // directory.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 ASSERT_FALSE(locales.empty()); 136 ASSERT_FALSE(locales.empty());
137 for (size_t i = 0; i < locales.size(); i++) { 137 for (size_t i = 0; i < locales.size(); i++) {
138 base::FilePath make_path; 138 base::FilePath make_path;
139 make_path = l10n_path.AppendASCII(locales[i]); 139 make_path = l10n_path.AppendASCII(locales[i]);
140 ASSERT_TRUE(base::CreateDirectory(make_path)); 140 ASSERT_TRUE(base::CreateDirectory(make_path));
141 ASSERT_TRUE(base::WriteFile(make_path.AppendASCII(filename), 141 ASSERT_TRUE(base::WriteFile(make_path.AppendASCII(filename),
142 data.c_str(), data.length())); 142 data.c_str(), data.length()));
143 } 143 }
144 144
145 base::FilePath path; 145 base::FilePath path;
146 std::string extension_id = id_util::GenerateId("test"); 146 std::string extension_id = crx_file::id_util::GenerateId("test");
147 ExtensionResource resource(extension_id, temp.path(), 147 ExtensionResource resource(extension_id, temp.path(),
148 base::FilePath().AppendASCII(filename)); 148 base::FilePath().AppendASCII(filename));
149 base::FilePath resolved_path = resource.GetFilePath(); 149 base::FilePath resolved_path = resource.GetFilePath();
150 150
151 base::FilePath expected_path; 151 base::FilePath expected_path;
152 // Expect default path only, since fallback logic is disabled. 152 // Expect default path only, since fallback logic is disabled.
153 // See http://crbug.com/27359. 153 // See http://crbug.com/27359.
154 expected_path = base::MakeAbsoluteFilePath(root_resource); 154 expected_path = base::MakeAbsoluteFilePath(root_resource);
155 ASSERT_FALSE(expected_path.empty()); 155 ASSERT_FALSE(expected_path.empty());
156 156
157 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value())); 157 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value()));
158 EXPECT_EQ(ToLower(temp.path().value()), 158 EXPECT_EQ(ToLower(temp.path().value()),
159 ToLower(resource.extension_root().value())); 159 ToLower(resource.extension_root().value()));
160 EXPECT_EQ(ToLower(base::FilePath().AppendASCII(filename).value()), 160 EXPECT_EQ(ToLower(base::FilePath().AppendASCII(filename).value()),
161 ToLower(resource.relative_path().value())); 161 ToLower(resource.relative_path().value()));
162 } 162 }
163 163
164 } // namespace extensions 164 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/extension.cc ('k') | extensions/common/id_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698