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 "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" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 304 |
305 std::string error; | 305 std::string error; |
306 std::vector<extensions::InstallWarning> warnings; | 306 std::vector<extensions::InstallWarning> warnings; |
307 scoped_refptr<Extension> extension = LoadExtensionManifest( | 307 scoped_refptr<Extension> extension = LoadExtensionManifest( |
308 value.get(), temp.path(), Manifest::UNPACKED, 0, &error); | 308 value.get(), temp.path(), Manifest::UNPACKED, 0, &error); |
309 ASSERT_TRUE(extension.get()) << error; | 309 ASSERT_TRUE(extension.get()) << error; |
310 | 310 |
311 EXPECT_FALSE(extension_file_util::ValidateExtension( | 311 EXPECT_FALSE(extension_file_util::ValidateExtension( |
312 extension.get(), &error, &warnings)); | 312 extension.get(), &error, &warnings)); |
313 EXPECT_EQ(l10n_util::GetStringFUTF8( | 313 EXPECT_EQ(l10n_util::GetStringFUTF8( |
314 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")), | 314 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, |
| 315 base::ASCIIToUTF16("foo.js")), |
315 error); | 316 error); |
316 EXPECT_EQ(0U, warnings.size()); | 317 EXPECT_EQ(0U, warnings.size()); |
317 | 318 |
318 scripts->Clear(); | 319 scripts->Clear(); |
319 scripts->Append(new base::StringValue("http://google.com/foo.js")); | 320 scripts->Append(new base::StringValue("http://google.com/foo.js")); |
320 | 321 |
321 extension = LoadExtensionManifest(value.get(), temp.path(), | 322 extension = LoadExtensionManifest(value.get(), temp.path(), |
322 Manifest::UNPACKED, 0, &error); | 323 Manifest::UNPACKED, 0, &error); |
323 ASSERT_TRUE(extension.get()) << error; | 324 ASSERT_TRUE(extension.get()) << error; |
324 | 325 |
325 warnings.clear(); | 326 warnings.clear(); |
326 EXPECT_FALSE(extension_file_util::ValidateExtension( | 327 EXPECT_FALSE(extension_file_util::ValidateExtension( |
327 extension.get(), &error, &warnings)); | 328 extension.get(), &error, &warnings)); |
328 EXPECT_EQ(l10n_util::GetStringFUTF8( | 329 EXPECT_EQ(l10n_util::GetStringFUTF8( |
329 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, | 330 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, |
330 ASCIIToUTF16("http://google.com/foo.js")), | 331 base::ASCIIToUTF16("http://google.com/foo.js")), |
331 error); | 332 error); |
332 EXPECT_EQ(0U, warnings.size()); | 333 EXPECT_EQ(0U, warnings.size()); |
333 } | 334 } |
334 | 335 |
335 // Private key, generated by Chrome specifically for this test, and | 336 // Private key, generated by Chrome specifically for this test, and |
336 // never used elsewhere. | 337 // never used elsewhere. |
337 const char private_key[] = | 338 const char private_key[] = |
338 "-----BEGIN PRIVATE KEY-----\n" | 339 "-----BEGIN PRIVATE KEY-----\n" |
339 "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKt02SR0FYaYy6fpW\n" | 340 "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKt02SR0FYaYy6fpW\n" |
340 "MAA+kU1BgK3d+OmmWfdr+JATIjhRkyeSF4lTd/71JQsyKqPzYkQPi3EeROWM+goTv\n" | 341 "MAA+kU1BgK3d+OmmWfdr+JATIjhRkyeSF4lTd/71JQsyKqPzYkQPi3EeROWM+goTv\n" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( | 459 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( |
459 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); | 460 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); |
460 EXPECT_TRUE(extension3.get() == NULL); | 461 EXPECT_TRUE(extension3.get() == NULL); |
461 EXPECT_STREQ("Could not load icon 'icon.png' for page action.", | 462 EXPECT_STREQ("Could not load icon 'icon.png' for page action.", |
462 error.c_str()); | 463 error.c_str()); |
463 } | 464 } |
464 | 465 |
465 // TODO(aa): More tests as motivation allows. Maybe steal some from | 466 // TODO(aa): More tests as motivation allows. Maybe steal some from |
466 // ExtensionService? Many of them could probably be tested here without the | 467 // ExtensionService? Many of them could probably be tested here without the |
467 // MessageLoop shenanigans. | 468 // MessageLoop shenanigans. |
OLD | NEW |