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

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

Issue 11644057: Move BrowserAction out of Extension (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_ungoop_extension_action
Patch Set: Created 7 years, 12 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
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/extension.h" 15 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_manifest_constants.h" 16 #include "chrome/common/extensions/extension_manifest_constants.h"
17 #include "chrome/common/extensions/manifest_handler.h"
16 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
17 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
20 22
21 using extensions::Extension; 23 using extensions::Extension;
22 24
23 namespace keys = extension_manifest_keys; 25 namespace keys = extension_manifest_keys;
24 26
27 class ExtensionFileUtil : public testing::Test {
Yoyo Zhou 2012/12/21 23:50:59 ExtensionFileUtilTest is a better name.
Devlin 2012/12/27 20:36:46 I thought so too, but wasn't sure I should change
28 protected:
29 virtual void SetUp() OVERRIDE {
Yoyo Zhou 2012/12/21 23:50:59 call base class SetUp
Devlin 2012/12/27 20:36:46 Done.
30 extensions::ManifestHandler::Register(
31 extension_manifest_keys::kBrowserAction,
32 new extensions::BrowserActionHandler);
33 }
34 };
35
25 #if defined(OS_WIN) 36 #if defined(OS_WIN)
26 // http://crbug.com/106381 37 // http://crbug.com/106381
27 #define InstallUninstallGarbageCollect DISABLED_InstallUninstallGarbageCollect 38 #define InstallUninstallGarbageCollect DISABLED_InstallUninstallGarbageCollect
28 #endif 39 #endif
29 TEST(ExtensionFileUtil, InstallUninstallGarbageCollect) { 40 TEST_F(ExtensionFileUtil, InstallUninstallGarbageCollect) {
30 base::ScopedTempDir temp; 41 base::ScopedTempDir temp;
31 ASSERT_TRUE(temp.CreateUniqueTempDir()); 42 ASSERT_TRUE(temp.CreateUniqueTempDir());
32 43
33 // Create a source extension. 44 // Create a source extension.
34 std::string extension_id("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); 45 std::string extension_id("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
35 std::string version("1.0"); 46 std::string version("1.0");
36 FilePath src = temp.path().AppendASCII(extension_id); 47 FilePath src = temp.path().AppendASCII(extension_id);
37 ASSERT_TRUE(file_util::CreateDirectory(src)); 48 ASSERT_TRUE(file_util::CreateDirectory(src));
38 49
39 // Create a extensions tree. 50 // Create a extensions tree.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 ASSERT_TRUE(file_util::DirectoryExists(version_2)); 101 ASSERT_TRUE(file_util::DirectoryExists(version_2));
91 ASSERT_TRUE(file_util::DirectoryExists(version_3)); 102 ASSERT_TRUE(file_util::DirectoryExists(version_3));
92 103
93 // Uninstall. Should remove entire extension subtree. 104 // Uninstall. Should remove entire extension subtree.
94 extension_file_util::UninstallExtension(all_extensions, extension_id); 105 extension_file_util::UninstallExtension(all_extensions, extension_id);
95 ASSERT_FALSE(file_util::DirectoryExists(version_2.DirName())); 106 ASSERT_FALSE(file_util::DirectoryExists(version_2.DirName()));
96 ASSERT_FALSE(file_util::DirectoryExists(version_3.DirName())); 107 ASSERT_FALSE(file_util::DirectoryExists(version_3.DirName()));
97 ASSERT_TRUE(file_util::DirectoryExists(all_extensions)); 108 ASSERT_TRUE(file_util::DirectoryExists(all_extensions));
98 } 109 }
99 110
100 TEST(ExtensionFileUtil, LoadExtensionWithValidLocales) { 111 TEST_F(ExtensionFileUtil, LoadExtensionWithValidLocales) {
101 FilePath install_dir; 112 FilePath install_dir;
102 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 113 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
103 install_dir = install_dir.AppendASCII("extensions") 114 install_dir = install_dir.AppendASCII("extensions")
104 .AppendASCII("good") 115 .AppendASCII("good")
105 .AppendASCII("Extensions") 116 .AppendASCII("Extensions")
106 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 117 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
107 .AppendASCII("1.0.0.0"); 118 .AppendASCII("1.0.0.0");
108 119
109 std::string error; 120 std::string error;
110 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 121 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
111 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 122 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
112 ASSERT_TRUE(extension != NULL); 123 ASSERT_TRUE(extension != NULL);
113 EXPECT_EQ("The first extension that I made.", extension->description()); 124 EXPECT_EQ("The first extension that I made.", extension->description());
114 } 125 }
115 126
116 TEST(ExtensionFileUtil, LoadExtensionWithoutLocalesFolder) { 127 TEST_F(ExtensionFileUtil, LoadExtensionWithoutLocalesFolder) {
117 FilePath install_dir; 128 FilePath install_dir;
118 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 129 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
119 install_dir = install_dir.AppendASCII("extensions") 130 install_dir = install_dir.AppendASCII("extensions")
120 .AppendASCII("good") 131 .AppendASCII("good")
121 .AppendASCII("Extensions") 132 .AppendASCII("Extensions")
122 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") 133 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa")
123 .AppendASCII("1.0"); 134 .AppendASCII("1.0");
124 135
125 std::string error; 136 std::string error;
126 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 137 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
127 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 138 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
128 ASSERT_FALSE(extension == NULL); 139 ASSERT_FALSE(extension == NULL);
129 EXPECT_TRUE(error.empty()); 140 EXPECT_TRUE(error.empty());
130 } 141 }
131 142
132 #if defined(OS_WIN) 143 #if defined(OS_WIN)
133 // http://crbug.com/106381 144 // http://crbug.com/106381
134 #define CheckIllegalFilenamesNoUnderscores \ 145 #define CheckIllegalFilenamesNoUnderscores \
135 DISABLED_CheckIllegalFilenamesNoUnderscores 146 DISABLED_CheckIllegalFilenamesNoUnderscores
136 #endif 147 #endif
137 TEST(ExtensionFileUtil, CheckIllegalFilenamesNoUnderscores) { 148 TEST_F(ExtensionFileUtil, CheckIllegalFilenamesNoUnderscores) {
138 base::ScopedTempDir temp; 149 base::ScopedTempDir temp;
139 ASSERT_TRUE(temp.CreateUniqueTempDir()); 150 ASSERT_TRUE(temp.CreateUniqueTempDir());
140 151
141 FilePath src_path = temp.path().AppendASCII("some_dir"); 152 FilePath src_path = temp.path().AppendASCII("some_dir");
142 ASSERT_TRUE(file_util::CreateDirectory(src_path)); 153 ASSERT_TRUE(file_util::CreateDirectory(src_path));
143 154
144 std::string data = "{ \"name\": { \"message\": \"foobar\" } }"; 155 std::string data = "{ \"name\": { \"message\": \"foobar\" } }";
145 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("some_file.txt"), 156 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("some_file.txt"),
146 data.c_str(), data.length())); 157 data.c_str(), data.length()));
147 std::string error; 158 std::string error;
148 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(), 159 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(),
149 &error)); 160 &error));
150 } 161 }
151 162
152 #if defined(OS_WIN) 163 #if defined(OS_WIN)
153 // http://crbug.com/106381 164 // http://crbug.com/106381
154 #define CheckIllegalFilenamesOnlyReserved \ 165 #define CheckIllegalFilenamesOnlyReserved \
155 DISABLED_CheckIllegalFilenamesOnlyReserved 166 DISABLED_CheckIllegalFilenamesOnlyReserved
156 #endif 167 #endif
157 TEST(ExtensionFileUtil, CheckIllegalFilenamesOnlyReserved) { 168 TEST_F(ExtensionFileUtil, CheckIllegalFilenamesOnlyReserved) {
158 base::ScopedTempDir temp; 169 base::ScopedTempDir temp;
159 ASSERT_TRUE(temp.CreateUniqueTempDir()); 170 ASSERT_TRUE(temp.CreateUniqueTempDir());
160 171
161 FilePath src_path = temp.path().Append(Extension::kLocaleFolder); 172 FilePath src_path = temp.path().Append(Extension::kLocaleFolder);
162 ASSERT_TRUE(file_util::CreateDirectory(src_path)); 173 ASSERT_TRUE(file_util::CreateDirectory(src_path));
163 174
164 std::string error; 175 std::string error;
165 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(), 176 EXPECT_TRUE(extension_file_util::CheckForIllegalFilenames(temp.path(),
166 &error)); 177 &error));
167 } 178 }
168 179
169 #if defined(OS_WIN) 180 #if defined(OS_WIN)
170 // http://crbug.com/106381 181 // http://crbug.com/106381
171 #define CheckIllegalFilenamesReservedAndIllegal \ 182 #define CheckIllegalFilenamesReservedAndIllegal \
172 DISABLED_CheckIllegalFilenamesReservedAndIllegal 183 DISABLED_CheckIllegalFilenamesReservedAndIllegal
173 #endif 184 #endif
174 TEST(ExtensionFileUtil, CheckIllegalFilenamesReservedAndIllegal) { 185 TEST_F(ExtensionFileUtil, CheckIllegalFilenamesReservedAndIllegal) {
175 base::ScopedTempDir temp; 186 base::ScopedTempDir temp;
176 ASSERT_TRUE(temp.CreateUniqueTempDir()); 187 ASSERT_TRUE(temp.CreateUniqueTempDir());
177 188
178 FilePath src_path = temp.path().Append(Extension::kLocaleFolder); 189 FilePath src_path = temp.path().Append(Extension::kLocaleFolder);
179 ASSERT_TRUE(file_util::CreateDirectory(src_path)); 190 ASSERT_TRUE(file_util::CreateDirectory(src_path));
180 191
181 src_path = temp.path().AppendASCII("_some_dir"); 192 src_path = temp.path().AppendASCII("_some_dir");
182 ASSERT_TRUE(file_util::CreateDirectory(src_path)); 193 ASSERT_TRUE(file_util::CreateDirectory(src_path));
183 194
184 std::string error; 195 std::string error;
185 EXPECT_FALSE(extension_file_util::CheckForIllegalFilenames(temp.path(), 196 EXPECT_FALSE(extension_file_util::CheckForIllegalFilenames(temp.path(),
186 &error)); 197 &error));
187 } 198 }
188 199
189 TEST(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnMissingManifest) { 200 TEST_F(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnMissingManifest) {
190 FilePath install_dir; 201 FilePath install_dir;
191 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 202 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
192 install_dir = install_dir.AppendASCII("extensions") 203 install_dir = install_dir.AppendASCII("extensions")
193 .AppendASCII("bad") 204 .AppendASCII("bad")
194 .AppendASCII("Extensions") 205 .AppendASCII("Extensions")
195 .AppendASCII("dddddddddddddddddddddddddddddddd") 206 .AppendASCII("dddddddddddddddddddddddddddddddd")
196 .AppendASCII("1.0"); 207 .AppendASCII("1.0");
197 208
198 std::string error; 209 std::string error;
199 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 210 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
200 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 211 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
201 ASSERT_TRUE(extension == NULL); 212 ASSERT_TRUE(extension == NULL);
202 ASSERT_FALSE(error.empty()); 213 ASSERT_FALSE(error.empty());
203 ASSERT_STREQ("Manifest file is missing or unreadable.", error.c_str()); 214 ASSERT_STREQ("Manifest file is missing or unreadable.", error.c_str());
204 } 215 }
205 216
206 TEST(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnBadManifest) { 217 TEST_F(ExtensionFileUtil, LoadExtensionGivesHelpfullErrorOnBadManifest) {
207 FilePath install_dir; 218 FilePath install_dir;
208 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 219 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
209 install_dir = install_dir.AppendASCII("extensions") 220 install_dir = install_dir.AppendASCII("extensions")
210 .AppendASCII("bad") 221 .AppendASCII("bad")
211 .AppendASCII("Extensions") 222 .AppendASCII("Extensions")
212 .AppendASCII("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") 223 .AppendASCII("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")
213 .AppendASCII("1.0"); 224 .AppendASCII("1.0");
214 225
215 std::string error; 226 std::string error;
216 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 227 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
217 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 228 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
218 ASSERT_TRUE(extension == NULL); 229 ASSERT_TRUE(extension == NULL);
219 ASSERT_FALSE(error.empty()); 230 ASSERT_FALSE(error.empty());
220 ASSERT_STREQ("Manifest is not valid JSON. " 231 ASSERT_STREQ("Manifest is not valid JSON. "
221 "Line: 2, column: 16, Syntax error.", error.c_str()); 232 "Line: 2, column: 16, Syntax error.", error.c_str());
222 } 233 }
223 234
224 TEST(ExtensionFileUtil, FailLoadingNonUTF8Scripts) { 235 TEST_F(ExtensionFileUtil, FailLoadingNonUTF8Scripts) {
225 FilePath install_dir; 236 FilePath install_dir;
226 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 237 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
227 install_dir = install_dir.AppendASCII("extensions") 238 install_dir = install_dir.AppendASCII("extensions")
228 .AppendASCII("bad") 239 .AppendASCII("bad")
229 .AppendASCII("bad_encoding"); 240 .AppendASCII("bad_encoding");
230 241
231 std::string error; 242 std::string error;
232 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( 243 scoped_refptr<Extension> extension(extension_file_util::LoadExtension(
233 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 244 install_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
234 ASSERT_TRUE(extension == NULL); 245 ASSERT_TRUE(extension == NULL);
235 ASSERT_STREQ("Could not load file 'bad_encoding.js' for content script. " 246 ASSERT_STREQ("Could not load file 'bad_encoding.js' for content script. "
236 "It isn't UTF-8 encoded.", error.c_str()); 247 "It isn't UTF-8 encoded.", error.c_str());
237 } 248 }
238 249
239 TEST(ExtensionFileUtil, ExtensionURLToRelativeFilePath) { 250 TEST_F(ExtensionFileUtil, ExtensionURLToRelativeFilePath) {
240 #define URL_PREFIX "chrome-extension://extension-id/" 251 #define URL_PREFIX "chrome-extension://extension-id/"
241 struct TestCase { 252 struct TestCase {
242 const char* url; 253 const char* url;
243 const char* expected_relative_path; 254 const char* expected_relative_path;
244 } test_cases[] = { 255 } test_cases[] = {
245 { URL_PREFIX "simple.html", 256 { URL_PREFIX "simple.html",
246 "simple.html" }, 257 "simple.html" },
247 { URL_PREFIX "directory/to/file.html", 258 { URL_PREFIX "directory/to/file.html",
248 "directory/to/file.html" }, 259 "directory/to/file.html" },
249 { URL_PREFIX "escape%20spaces.html", 260 { URL_PREFIX "escape%20spaces.html",
(...skipping 25 matching lines...) Expand all
275 286
276 FilePath actual_path = 287 FilePath actual_path =
277 extension_file_util::ExtensionURLToRelativeFilePath(url); 288 extension_file_util::ExtensionURLToRelativeFilePath(url);
278 EXPECT_FALSE(actual_path.IsAbsolute()) << 289 EXPECT_FALSE(actual_path.IsAbsolute()) <<
279 " For the path " << actual_path.value(); 290 " For the path " << actual_path.value();
280 EXPECT_EQ(expected_path.value(), actual_path.value()) << 291 EXPECT_EQ(expected_path.value(), actual_path.value()) <<
281 " For the path " << url; 292 " For the path " << url;
282 } 293 }
283 } 294 }
284 295
285 TEST(ExtensionFileUtil, ExtensionResourceURLToFilePath) { 296 TEST_F(ExtensionFileUtil, ExtensionResourceURLToFilePath) {
286 // Setup filesystem for testing. 297 // Setup filesystem for testing.
287 FilePath root_path; 298 FilePath root_path;
288 ASSERT_TRUE(file_util::CreateNewTempDirectory( 299 ASSERT_TRUE(file_util::CreateNewTempDirectory(
289 FILE_PATH_LITERAL(""), &root_path)); 300 FILE_PATH_LITERAL(""), &root_path));
290 ASSERT_TRUE(file_util::AbsolutePath(&root_path)); 301 ASSERT_TRUE(file_util::AbsolutePath(&root_path));
291 302
292 FilePath api_path = root_path.Append(FILE_PATH_LITERAL("apiname")); 303 FilePath api_path = root_path.Append(FILE_PATH_LITERAL("apiname"));
293 ASSERT_TRUE(file_util::CreateDirectory(api_path)); 304 ASSERT_TRUE(file_util::CreateDirectory(api_path));
294 305
295 const char data[] = "Test Data"; 306 const char data[] = "Test Data";
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 manifest_dir, 385 manifest_dir,
375 location, 386 location,
376 extra_flags, 387 extra_flags,
377 error); 388 error);
378 } 389 }
379 390
380 #if defined(OS_WIN) 391 #if defined(OS_WIN)
381 // http://crbug.com/108279 392 // http://crbug.com/108279
382 #define ValidateThemeUTF8 DISABLED_ValidateThemeUTF8 393 #define ValidateThemeUTF8 DISABLED_ValidateThemeUTF8
383 #endif 394 #endif
384 TEST(ExtensionFileUtil, ValidateThemeUTF8) { 395 TEST_F(ExtensionFileUtil, ValidateThemeUTF8) {
385 base::ScopedTempDir temp; 396 base::ScopedTempDir temp;
386 ASSERT_TRUE(temp.CreateUniqueTempDir()); 397 ASSERT_TRUE(temp.CreateUniqueTempDir());
387 398
388 // "aeo" with accents. Use http://0xcc.net/jsescape/ to decode them. 399 // "aeo" with accents. Use http://0xcc.net/jsescape/ to decode them.
389 std::string non_ascii_file = "\xC3\xA0\xC3\xA8\xC3\xB2.png"; 400 std::string non_ascii_file = "\xC3\xA0\xC3\xA8\xC3\xB2.png";
390 FilePath non_ascii_path = temp.path().Append(FilePath::FromUTF8Unsafe( 401 FilePath non_ascii_path = temp.path().Append(FilePath::FromUTF8Unsafe(
391 non_ascii_file)); 402 non_ascii_file));
392 file_util::WriteFile(non_ascii_path, "", 0); 403 file_util::WriteFile(non_ascii_path, "", 0);
393 404
394 std::string kManifest = 405 std::string kManifest =
(...skipping 12 matching lines...) Expand all
407 error; 418 error;
408 EXPECT_EQ(0U, warnings.size()); 419 EXPECT_EQ(0U, warnings.size());
409 } 420 }
410 421
411 #if defined(OS_WIN) 422 #if defined(OS_WIN)
412 // This test hangs on Windows sometimes. http://crbug.com/110279 423 // This test hangs on Windows sometimes. http://crbug.com/110279
413 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist 424 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist
414 #else 425 #else
415 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist 426 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist
416 #endif 427 #endif
417 TEST(ExtensionFileUtil, MAYBE_BackgroundScriptsMustExist) { 428 TEST_F(ExtensionFileUtil, MAYBE_BackgroundScriptsMustExist) {
418 base::ScopedTempDir temp; 429 base::ScopedTempDir temp;
419 ASSERT_TRUE(temp.CreateUniqueTempDir()); 430 ASSERT_TRUE(temp.CreateUniqueTempDir());
420 431
421 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 432 scoped_ptr<DictionaryValue> value(new DictionaryValue());
422 value->SetString("name", "test"); 433 value->SetString("name", "test");
423 value->SetString("version", "1"); 434 value->SetString("version", "1");
424 value->SetInteger("manifest_version", 1); 435 value->SetInteger("manifest_version", 1);
425 436
426 ListValue* scripts = new ListValue(); 437 ListValue* scripts = new ListValue();
427 scripts->Append(Value::CreateStringValue("foo.js")); 438 scripts->Append(Value::CreateStringValue("foo.js"));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 "4GAAeWonDdkQJBANNb8wrqNWFn7DqyQTfELzcRTRnqQ/r1pdeJo6obzbnwGnlqe3t\n" 481 "4GAAeWonDdkQJBANNb8wrqNWFn7DqyQTfELzcRTRnqQ/r1pdeJo6obzbnwGnlqe3t\n"
471 "KhLjtJNIGrQg5iC0OVLWFuvPJs0t3z62A1ckCQQDPq2JZuwTwu5Pl4DJ0r9O1FdqN\n" 482 "KhLjtJNIGrQg5iC0OVLWFuvPJs0t3z62A1ckCQQDPq2JZuwTwu5Pl4DJ0r9O1FdqN\n"
472 "JgqPZyMptokCDQ3khLLGakIu+TqB9YtrzI69rJMSG2Egb+6McaDX+dh3XmR/AkB9t\n" 483 "JgqPZyMptokCDQ3khLLGakIu+TqB9YtrzI69rJMSG2Egb+6McaDX+dh3XmR/AkB9t\n"
473 "xJf6qDnmA2td/tMtTc0NOk8Qdg/fD8xbZ/YfYMnVoYYs9pQoilBaWRePDRNURMLYZ\n" 484 "xJf6qDnmA2td/tMtTc0NOk8Qdg/fD8xbZ/YfYMnVoYYs9pQoilBaWRePDRNURMLYZ\n"
474 "vHAI0Llmw7tj7jv17pAkEAz44uXRpjRKtllUIvi5pUENAHwDz+HvdpGH68jpU3hmb\n" 485 "vHAI0Llmw7tj7jv17pAkEAz44uXRpjRKtllUIvi5pUENAHwDz+HvdpGH68jpU3hmb\n"
475 "uOwrmnQYxaMReFV68Z2w9DcLZn07f7/R9Wn72z89CxwJAFsDoNaDes4h48bX7plct\n" 486 "uOwrmnQYxaMReFV68Z2w9DcLZn07f7/R9Wn72z89CxwJAFsDoNaDes4h48bX7plct\n"
476 "s9ACjmTwcCigZjN2K7AGv7ntCLF3DnV5dK0dTHNaAdD3SbY3jl29Rk2CwiURSX6Ee\n" 487 "s9ACjmTwcCigZjN2K7AGv7ntCLF3DnV5dK0dTHNaAdD3SbY3jl29Rk2CwiURSX6Ee\n"
477 "g==\n" 488 "g==\n"
478 "-----END PRIVATE KEY-----\n"; 489 "-----END PRIVATE KEY-----\n";
479 490
480 TEST(ExtensionFileUtil, FindPrivateKeyFiles) { 491 TEST_F(ExtensionFileUtil, FindPrivateKeyFiles) {
481 base::ScopedTempDir temp; 492 base::ScopedTempDir temp;
482 ASSERT_TRUE(temp.CreateUniqueTempDir()); 493 ASSERT_TRUE(temp.CreateUniqueTempDir());
483 494
484 FilePath src_path = temp.path().AppendASCII("some_dir"); 495 FilePath src_path = temp.path().AppendASCII("some_dir");
485 ASSERT_TRUE(file_util::CreateDirectory(src_path)); 496 ASSERT_TRUE(file_util::CreateDirectory(src_path));
486 497
487 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("a_key.pem"), 498 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("a_key.pem"),
488 private_key, arraysize(private_key))); 499 private_key, arraysize(private_key)));
489 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("second_key.pem"), 500 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("second_key.pem"),
490 private_key, arraysize(private_key))); 501 private_key, arraysize(private_key)));
491 // Shouldn't find a key with a different extension. 502 // Shouldn't find a key with a different extension.
492 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("key.diff_ext"), 503 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("key.diff_ext"),
493 private_key, arraysize(private_key))); 504 private_key, arraysize(private_key)));
494 // Shouldn't find a key that isn't parsable. 505 // Shouldn't find a key that isn't parsable.
495 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("unparsable_key.pem"), 506 ASSERT_TRUE(file_util::WriteFile(src_path.AppendASCII("unparsable_key.pem"),
496 private_key, arraysize(private_key) - 30)); 507 private_key, arraysize(private_key) - 30));
497 std::vector<FilePath> private_keys = 508 std::vector<FilePath> private_keys =
498 extension_file_util::FindPrivateKeyFiles(temp.path()); 509 extension_file_util::FindPrivateKeyFiles(temp.path());
499 EXPECT_EQ(2U, private_keys.size()); 510 EXPECT_EQ(2U, private_keys.size());
500 EXPECT_THAT(private_keys, 511 EXPECT_THAT(private_keys,
501 testing::Contains(src_path.AppendASCII("a_key.pem"))); 512 testing::Contains(src_path.AppendASCII("a_key.pem")));
502 EXPECT_THAT(private_keys, 513 EXPECT_THAT(private_keys,
503 testing::Contains(src_path.AppendASCII("second_key.pem"))); 514 testing::Contains(src_path.AppendASCII("second_key.pem")));
504 } 515 }
505 516
506 TEST(ExtensionFileUtil, WarnOnPrivateKey) { 517 TEST_F(ExtensionFileUtil, WarnOnPrivateKey) {
507 base::ScopedTempDir temp; 518 base::ScopedTempDir temp;
508 ASSERT_TRUE(temp.CreateUniqueTempDir()); 519 ASSERT_TRUE(temp.CreateUniqueTempDir());
509 520
510 FilePath ext_path = temp.path().AppendASCII("ext_root"); 521 FilePath ext_path = temp.path().AppendASCII("ext_root");
511 ASSERT_TRUE(file_util::CreateDirectory(ext_path)); 522 ASSERT_TRUE(file_util::CreateDirectory(ext_path));
512 523
513 const char manifest[] = 524 const char manifest[] =
514 "{\n" 525 "{\n"
515 " \"name\": \"Test Extension\",\n" 526 " \"name\": \"Test Extension\",\n"
516 " \"version\": \"1.0\",\n" 527 " \"version\": \"1.0\",\n"
(...skipping 22 matching lines...) Expand all
539 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY. 550 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY.
540 extension = extension_file_util::LoadExtension( 551 extension = extension_file_util::LoadExtension(
541 ext_path, "the_id", Extension::EXTERNAL_PREF, 552 ext_path, "the_id", Extension::EXTERNAL_PREF,
542 Extension::ERROR_ON_PRIVATE_KEY, &error); 553 Extension::ERROR_ON_PRIVATE_KEY, &error);
543 EXPECT_FALSE(extension.get()); 554 EXPECT_FALSE(extension.get());
544 EXPECT_THAT(error, 555 EXPECT_THAT(error,
545 testing::ContainsRegex( 556 testing::ContainsRegex(
546 "extension includes the key file.*ext_root.a_key.pem")); 557 "extension includes the key file.*ext_root.a_key.pem"));
547 } 558 }
548 559
549 TEST(ExtensionFileUtil, CheckZeroLengthImageFile) { 560 TEST_F(ExtensionFileUtil, CheckZeroLengthImageFile) {
550 FilePath install_dir; 561 FilePath install_dir;
551 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 562 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
552 563
553 // Try to install an extension with a zero-length icon file. 564 // Try to install an extension with a zero-length icon file.
554 FilePath ext_dir = install_dir.AppendASCII("extensions") 565 FilePath ext_dir = install_dir.AppendASCII("extensions")
555 .AppendASCII("bad") 566 .AppendASCII("bad")
556 .AppendASCII("Extensions") 567 .AppendASCII("Extensions")
557 .AppendASCII("ffffffffffffffffffffffffffffffff"); 568 .AppendASCII("ffffffffffffffffffffffffffffffff");
558 569
559 std::string error; 570 std::string error;
(...skipping 24 matching lines...) Expand all
584 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( 595 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension(
585 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error)); 596 ext_dir, Extension::LOAD, Extension::NO_FLAGS, &error));
586 ASSERT_TRUE(extension3 == NULL); 597 ASSERT_TRUE(extension3 == NULL);
587 ASSERT_STREQ("Could not load icon 'icon.png' for page action.", 598 ASSERT_STREQ("Could not load icon 'icon.png' for page action.",
588 error.c_str()); 599 error.c_str());
589 } 600 }
590 601
591 // TODO(aa): More tests as motivation allows. Maybe steal some from 602 // TODO(aa): More tests as motivation allows. Maybe steal some from
592 // ExtensionService? Many of them could probably be tested here without the 603 // ExtensionService? Many of them could probably be tested here without the
593 // MessageLoop shenanigans. 604 // MessageLoop shenanigans.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698