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

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

Issue 12578008: Move CrxFile, FileReader, ExtensionResource to src/extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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
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 "chrome/common/extensions/extension_file_util.h" 5 #include "chrome/common/extensions/extension_file_util.h"
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/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h " 14 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h "
15 #include "chrome/common/extensions/api/extension_action/page_action_handler.h" 15 #include "chrome/common/extensions/api/extension_action/page_action_handler.h"
16 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" 16 #include "chrome/common/extensions/api/i18n/default_locale_handler.h"
17 #include "chrome/common/extensions/api/icons/icons_handler.h" 17 #include "chrome/common/extensions/api/icons/icons_handler.h"
18 #include "chrome/common/extensions/background_info.h" 18 #include "chrome/common/extensions/background_info.h"
19 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_manifest_constants.h" 20 #include "chrome/common/extensions/extension_manifest_constants.h"
21 #include "chrome/common/extensions/manifest.h" 21 #include "chrome/common/extensions/manifest.h"
22 #include "chrome/common/extensions/manifest_handler.h" 22 #include "chrome/common/extensions/manifest_handler.h"
23 #include "extensions/common/constants.h"
23 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
24 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
27 28
28 using extensions::Extension; 29 using extensions::Extension;
29 using extensions::Manifest; 30 using extensions::Manifest;
30 31
31 namespace keys = extension_manifest_keys; 32 namespace keys = extension_manifest_keys;
32 33
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 std::string error; 166 std::string error;
166 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(), 167 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(),
167 &error)); 168 &error));
168 } 169 }
169 170
170 TEST_F(ExtensionFileUtilTest, CheckIllegalFilenamesOnlyReserved) { 171 TEST_F(ExtensionFileUtilTest, CheckIllegalFilenamesOnlyReserved) {
171 base::ScopedTempDir temp; 172 base::ScopedTempDir temp;
172 ASSERT_TRUE(temp.CreateUniqueTempDir()); 173 ASSERT_TRUE(temp.CreateUniqueTempDir());
173 174
174 const base::FilePath::CharType* folders[] = 175 const base::FilePath::CharType* folders[] =
175 { Extension::kLocaleFolder, Extension::kPlatformSpecificFolder }; 176 { extensions::kLocaleFolder, extensions::kPlatformSpecificFolder };
176 177
177 for (size_t i = 0; i < arraysize(folders); i++) { 178 for (size_t i = 0; i < arraysize(folders); i++) {
178 base::FilePath src_path = temp.path().Append(folders[i]); 179 base::FilePath src_path = temp.path().Append(folders[i]);
179 ASSERT_TRUE(file_util::CreateDirectory(src_path)); 180 ASSERT_TRUE(file_util::CreateDirectory(src_path));
180 } 181 }
181 182
182 std::string error; 183 std::string error;
183 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(), 184 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(),
184 &error)); 185 &error));
185 } 186 }
186 187
187 TEST_F(ExtensionFileUtilTest, CheckIllegalFilenamesReservedAndIllegal) { 188 TEST_F(ExtensionFileUtilTest, CheckIllegalFilenamesReservedAndIllegal) {
188 base::ScopedTempDir temp; 189 base::ScopedTempDir temp;
189 ASSERT_TRUE(temp.CreateUniqueTempDir()); 190 ASSERT_TRUE(temp.CreateUniqueTempDir());
190 191
191 base::FilePath src_path = temp.path().Append(Extension::kLocaleFolder); 192 base::FilePath src_path = temp.path().Append(extensions::kLocaleFolder);
192 ASSERT_TRUE(file_util::CreateDirectory(src_path)); 193 ASSERT_TRUE(file_util::CreateDirectory(src_path));
193 194
194 src_path = temp.path().AppendASCII("_some_dir"); 195 src_path = temp.path().AppendASCII("_some_dir");
195 ASSERT_TRUE(file_util::CreateDirectory(src_path)); 196 ASSERT_TRUE(file_util::CreateDirectory(src_path));
196 197
197 std::string error; 198 std::string error;
198 EXPECT_FALSE(extension_file_util::CheckForIllegalFilenames(temp.path(), 199 EXPECT_FALSE(extension_file_util::CheckForIllegalFilenames(temp.path(),
199 &error)); 200 &error));
200 } 201 }
201 202
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( 591 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension(
591 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); 592 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error));
592 EXPECT_TRUE(extension3 == NULL); 593 EXPECT_TRUE(extension3 == NULL);
593 EXPECT_STREQ("Could not load icon 'icon.png' for page action.", 594 EXPECT_STREQ("Could not load icon 'icon.png' for page action.",
594 error.c_str()); 595 error.c_str());
595 } 596 }
596 597
597 // TODO(aa): More tests as motivation allows. Maybe steal some from 598 // TODO(aa): More tests as motivation allows. Maybe steal some from
598 // ExtensionService? Many of them could probably be tested here without the 599 // ExtensionService? Many of them could probably be tested here without the
599 // MessageLoop shenanigans. 600 // MessageLoop shenanigans.
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_file_util.cc ('k') | chrome/common/extensions/extension_l10n_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698