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

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

Issue 316013: Loading local resources uses improved fallback algorithm.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | « chrome/common/extensions/extension_resource.cc ('k') | no next file » | 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) 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"
11 #include "chrome/browser/extensions/extension_l10n_util.h"
11 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
12 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_resource.h" 14 #include "chrome/common/extensions/extension_resource.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 TEST(ExtensionResourceTest, CreateEmptyResource) { 17 TEST(ExtensionResourceTest, CreateEmptyResource) {
17 ExtensionResource resource; 18 ExtensionResource resource;
18 19
19 EXPECT_TRUE(resource.extension_root().empty()); 20 EXPECT_TRUE(resource.extension_root().empty());
20 EXPECT_TRUE(resource.relative_path().empty()); 21 EXPECT_TRUE(resource.relative_path().empty());
(...skipping 14 matching lines...) Expand all
35 ExtensionResource resource(root_path, relative_path); 36 ExtensionResource resource(root_path, relative_path);
36 37
37 EXPECT_EQ(root_path.value(), resource.extension_root().value()); 38 EXPECT_EQ(root_path.value(), resource.extension_root().value());
38 EXPECT_EQ(relative_path.value(), resource.relative_path().value()); 39 EXPECT_EQ(relative_path.value(), resource.relative_path().value());
39 EXPECT_EQ(ToLower(root_path.Append(relative_path).value()), 40 EXPECT_EQ(ToLower(root_path.Append(relative_path).value()),
40 ToLower(resource.GetFilePath().value())); 41 ToLower(resource.GetFilePath().value()));
41 42
42 EXPECT_FALSE(resource.GetFilePath().empty()); 43 EXPECT_FALSE(resource.GetFilePath().empty());
43 } 44 }
44 45
45 TEST(ExtensionResourceTest, CreateWithBothResourcesOnDisk) { 46 TEST(ExtensionResourceTest, CreateWithAllResourcesOnDisk) {
46 ScopedTempDir temp; 47 ScopedTempDir temp;
47 ASSERT_TRUE(temp.CreateUniqueTempDir()); 48 ASSERT_TRUE(temp.CreateUniqueTempDir());
48 49
50 // Create resource in the extension root.
49 const char* filename = "res.ico"; 51 const char* filename = "res.ico";
50 FilePath root_resource = temp.path().AppendASCII(filename); 52 FilePath root_resource = temp.path().AppendASCII(filename);
51 std::string data = "some foo"; 53 std::string data = "some foo";
52 ASSERT_TRUE(file_util::WriteFile(root_resource.AppendASCII(filename), 54 ASSERT_TRUE(file_util::WriteFile(root_resource.AppendASCII(filename),
53 data.c_str(), data.length())); 55 data.c_str(), data.length()));
54 56
57 // Create l10n resources (for current locale and its parents).
55 FilePath l10n_path = temp.path().AppendASCII(Extension::kLocaleFolder); 58 FilePath l10n_path = temp.path().AppendASCII(Extension::kLocaleFolder);
56 ASSERT_TRUE(file_util::CreateDirectory(l10n_path)); 59 ASSERT_TRUE(file_util::CreateDirectory(l10n_path));
57 60
58 static std::string current_locale = l10n_util::GetApplicationLocale(L""); 61 std::vector<std::string> locales;
59 std::replace(current_locale.begin(), current_locale.end(), '-', '_'); 62 extension_l10n_util::GetParentLocales(l10n_util::GetApplicationLocale(L""),
60 l10n_path = l10n_path.AppendASCII(current_locale); 63 &locales);
61 ASSERT_TRUE(file_util::CreateDirectory(l10n_path)); 64 for (size_t i = 0; i < locales.size(); i++) {
62 65 FilePath make_path;
63 ASSERT_TRUE(file_util::WriteFile(l10n_path.AppendASCII(filename), 66 make_path = l10n_path.AppendASCII(locales[i]);
64 data.c_str(), data.length())); 67 ASSERT_TRUE(file_util::CreateDirectory(make_path));
68 ASSERT_TRUE(file_util::WriteFile(make_path.AppendASCII(filename),
69 data.c_str(), data.length()));
70 }
65 71
66 FilePath path; 72 FilePath path;
67 ExtensionResource resource(temp.path(), FilePath().AppendASCII(filename)); 73 ExtensionResource resource(temp.path(), FilePath().AppendASCII(filename));
68 FilePath resolved_path = resource.GetFilePath(); 74 FilePath resolved_path = resource.GetFilePath();
69 75
70 EXPECT_EQ(ToLower(l10n_path.AppendASCII(filename).value()), 76 ASSERT_FALSE(locales.empty());
71 ToLower(resolved_path.value())); 77 FilePath expected_path;
78 expected_path = l10n_path.AppendASCII(locales[0]).AppendASCII(filename);
79
80 EXPECT_EQ(ToLower(expected_path.value()), ToLower(resolved_path.value()));
72 EXPECT_EQ(ToLower(temp.path().value()), 81 EXPECT_EQ(ToLower(temp.path().value()),
73 ToLower(resource.extension_root().value())); 82 ToLower(resource.extension_root().value()));
74 EXPECT_EQ(ToLower(FilePath().AppendASCII(filename).value()), 83 EXPECT_EQ(ToLower(FilePath().AppendASCII(filename).value()),
75 ToLower(resource.relative_path().value())); 84 ToLower(resource.relative_path().value()));
76 } 85 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_resource.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698