| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // Extension ids used during testing. | 36 // Extension ids used during testing. |
| 37 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 37 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 38 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; | 38 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; |
| 39 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; | 39 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 40 const char* const good1 = "hpiknbiabeeppbpihjehijgoemciehgk"; | 40 const char* const good1 = "hpiknbiabeeppbpihjehijgoemciehgk"; |
| 41 const char* const good2 = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; | 41 const char* const good2 = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; |
| 42 const char* const good_crx = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 42 const char* const good_crx = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 43 const char* const page_action = "kemkhnabegjkabakmlcaafgikalipenj"; | 43 const char* const page_action = "obcimlgaoabeegjmmpldobjndiealpln"; |
| 44 const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad"; | 44 const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad"; |
| 45 const char* const theme2_crx = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 45 const char* const theme2_crx = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 46 | 46 |
| 47 struct ExtensionsOrder { | 47 struct ExtensionsOrder { |
| 48 bool operator()(const Extension* a, const Extension* b) { | 48 bool operator()(const Extension* a, const Extension* b) { |
| 49 return a->name() < b->name(); | 49 return a->name() < b->name(); |
| 50 } | 50 } |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 static std::vector<std::string> GetErrors() { | 53 static std::vector<std::string> GetErrors() { |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 count++; | 645 count++; |
| 646 | 646 |
| 647 // We should have only gotten two extensions now. | 647 // We should have only gotten two extensions now. |
| 648 EXPECT_EQ(2u, count); | 648 EXPECT_EQ(2u, count); |
| 649 | 649 |
| 650 // And extension1 dir should now be toast. | 650 // And extension1 dir should now be toast. |
| 651 vers = vers.DirName(); | 651 vers = vers.DirName(); |
| 652 ASSERT_FALSE(file_util::PathExists(vers)); | 652 ASSERT_FALSE(file_util::PathExists(vers)); |
| 653 } | 653 } |
| 654 | 654 |
| 655 // Test installing extensions. | 655 // Test installing extensions. This test tries to install few extensions using |
| 656 // crx files. If you need to change those crx files, feel free to repackage |
| 657 // them, throw away the key used and change the id's above. |
| 656 TEST_F(ExtensionsServiceTest, InstallExtension) { | 658 TEST_F(ExtensionsServiceTest, InstallExtension) { |
| 657 InitializeEmptyExtensionsService(); | 659 InitializeEmptyExtensionsService(); |
| 658 | 660 |
| 659 FilePath extensions_path; | 661 FilePath extensions_path; |
| 660 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 662 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 661 extensions_path = extensions_path.AppendASCII("extensions"); | 663 extensions_path = extensions_path.AppendASCII("extensions"); |
| 662 | 664 |
| 663 // Extensions not enabled. | 665 // Extensions not enabled. |
| 664 SetExtensionsEnabled(false); | 666 SetExtensionsEnabled(false); |
| 665 FilePath path = extensions_path.AppendASCII("good.crx"); | 667 FilePath path = extensions_path.AppendASCII("good.crx"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 681 // An extension with page actions. | 683 // An extension with page actions. |
| 682 path = extensions_path.AppendASCII("page_action.crx"); | 684 path = extensions_path.AppendASCII("page_action.crx"); |
| 683 InstallExtension(path, true); | 685 InstallExtension(path, true); |
| 684 ValidatePrefKeyCount(++pref_count); | 686 ValidatePrefKeyCount(++pref_count); |
| 685 ValidatePref(page_action, L"state", Extension::ENABLED); | 687 ValidatePref(page_action, L"state", Extension::ENABLED); |
| 686 ValidatePref(page_action, L"location", Extension::INTERNAL); | 688 ValidatePref(page_action, L"location", Extension::INTERNAL); |
| 687 | 689 |
| 688 // Bad signature. | 690 // Bad signature. |
| 689 path = extensions_path.AppendASCII("bad_signature.crx"); | 691 path = extensions_path.AppendASCII("bad_signature.crx"); |
| 690 InstallExtension(path, false); | 692 InstallExtension(path, false); |
| 693 ValidatePrefKeyCount(pref_count); |
| 691 | 694 |
| 692 // 0-length extension file. | 695 // 0-length extension file. |
| 693 path = extensions_path.AppendASCII("not_an_extension.crx"); | 696 path = extensions_path.AppendASCII("not_an_extension.crx"); |
| 694 InstallExtension(path, false); | 697 InstallExtension(path, false); |
| 695 ValidatePrefKeyCount(pref_count); | 698 ValidatePrefKeyCount(pref_count); |
| 696 | 699 |
| 697 // Bad magic number. | 700 // Bad magic number. |
| 698 path = extensions_path.AppendASCII("bad_magic.crx"); | 701 path = extensions_path.AppendASCII("bad_magic.crx"); |
| 699 InstallExtension(path, false); | 702 InstallExtension(path, false); |
| 700 ValidatePrefKeyCount(pref_count); | 703 ValidatePrefKeyCount(pref_count); |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1415 profile.GetPrefs()->SetBoolean(prefs::kEnableExtensions, true); | 1418 profile.GetPrefs()->SetBoolean(prefs::kEnableExtensions, true); |
| 1416 service = new ExtensionsService(&profile, command_line.get(), | 1419 service = new ExtensionsService(&profile, command_line.get(), |
| 1417 profile.GetPrefs(), install_dir, &loop, &loop); | 1420 profile.GetPrefs(), install_dir, &loop, &loop); |
| 1418 EXPECT_TRUE(service->extensions_enabled()); | 1421 EXPECT_TRUE(service->extensions_enabled()); |
| 1419 | 1422 |
| 1420 command_line.reset(new CommandLine(L"")); | 1423 command_line.reset(new CommandLine(L"")); |
| 1421 service = new ExtensionsService(&profile, command_line.get(), | 1424 service = new ExtensionsService(&profile, command_line.get(), |
| 1422 profile.GetPrefs(), install_dir, &loop, &loop); | 1425 profile.GetPrefs(), install_dir, &loop, &loop); |
| 1423 EXPECT_TRUE(service->extensions_enabled()); | 1426 EXPECT_TRUE(service->extensions_enabled()); |
| 1424 } | 1427 } |
| OLD | NEW |