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

Side by Side Diff: chrome/browser/extensions/extensions_service_unittest.cc

Issue 466053: Fix a crash bug on user script installation (Closed)
Patch Set: Created 11 years 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
« no previous file with comments | « chrome/browser/extensions/crx_installer.cc ('k') | chrome/renderer/user_script_slave.cc » ('j') | 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 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "chrome/browser/extensions/crx_installer.h"
15 #include "chrome/browser/extensions/extension_creator.h" 16 #include "chrome/browser/extensions/extension_creator.h"
16 #include "chrome/browser/extensions/extensions_service.h" 17 #include "chrome/browser/extensions/extensions_service.h"
17 #include "chrome/browser/extensions/external_extension_provider.h" 18 #include "chrome/browser/extensions/external_extension_provider.h"
18 #include "chrome/browser/extensions/external_pref_extension_provider.h" 19 #include "chrome/browser/extensions/external_pref_extension_provider.h"
19 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
21 #include "chrome/common/extensions/url_pattern.h" 22 #include "chrome/common/extensions/url_pattern.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/extensions/extension_error_reporter.h" 25 #include "chrome/common/extensions/extension_error_reporter.h"
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 676
676 // And extension1 dir should now be toast. 677 // And extension1 dir should now be toast.
677 FilePath extension_dir = extensions_install_dir_ 678 FilePath extension_dir = extensions_install_dir_
678 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"); 679 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj");
679 ASSERT_FALSE(file_util::PathExists(extension_dir)); 680 ASSERT_FALSE(file_util::PathExists(extension_dir));
680 } 681 }
681 682
682 // Test installing extensions. This test tries to install few extensions using 683 // Test installing extensions. This test tries to install few extensions using
683 // crx files. If you need to change those crx files, feel free to repackage 684 // crx files. If you need to change those crx files, feel free to repackage
684 // them, throw away the key used and change the id's above. 685 // them, throw away the key used and change the id's above.
685 // TODO(mad): http://crbug.com/26214 686 TEST_F(ExtensionsServiceTest, InstallExtension) {
686 TEST_F(ExtensionsServiceTest, DISABLED_InstallExtension) {
687 InitializeEmptyExtensionsService(); 687 InitializeEmptyExtensionsService();
688 688
689 FilePath extensions_path; 689 FilePath extensions_path;
690 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 690 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
691 extensions_path = extensions_path.AppendASCII("extensions"); 691 extensions_path = extensions_path.AppendASCII("extensions");
692 692
693 // Extensions not enabled. 693 // Extensions not enabled.
694 set_extensions_enabled(false); 694 set_extensions_enabled(false);
695 FilePath path = extensions_path.AppendASCII("good.crx"); 695 FilePath path = extensions_path.AppendASCII("good.crx");
696 InstallExtension(path, false); 696 InstallExtension(path, false);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 // class of validation that we do to the directory structure of the extension. 735 // class of validation that we do to the directory structure of the extension.
736 // We did not used to handle this correctly for installation. 736 // We did not used to handle this correctly for installation.
737 path = extensions_path.AppendASCII("bad_underscore.crx"); 737 path = extensions_path.AppendASCII("bad_underscore.crx");
738 InstallExtension(path, false); 738 InstallExtension(path, false);
739 ValidatePrefKeyCount(pref_count); 739 ValidatePrefKeyCount(pref_count);
740 740
741 // TODO(erikkay): add more tests for many of the failure cases. 741 // TODO(erikkay): add more tests for many of the failure cases.
742 // TODO(erikkay): add tests for upgrade cases. 742 // TODO(erikkay): add tests for upgrade cases.
743 } 743 }
744 744
745 // Install a user script (they get converted automatically to an extension)
746 TEST_F(ExtensionsServiceTest, InstallUserScript) {
747 // The details of script conversion are tested elsewhere, this just tests
748 // integration with ExtensionsService.
749 InitializeEmptyExtensionsService();
750
751 FilePath path;
752 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
753 path = path.AppendASCII("extensions")
754 .AppendASCII("user_script_basic.user.js");
755
756 ASSERT_TRUE(file_util::PathExists(path));
757 CrxInstaller::InstallUserScript(
758 path,
759 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js"),
abarth-chromium 2009/12/06 20:49:16 This doesn't actually touch your web site, right??
760 service_->install_directory(),
761 false, // do not delete source
762 service_,
763 NULL); // install UI
764
765 loop_.RunAllPending();
766 std::vector<std::string> errors = GetErrors();
767 EXPECT_TRUE(installed_) << "Nothing was installed.";
768 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded.";
769 EXPECT_EQ(0u, errors.size()) << "There were errors: "
770 << JoinString(errors, ',');
771 EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) <<
772 path.value();
773
774 installed_ = NULL;
775 loaded_.clear();
776 ExtensionErrorReporter::GetInstance()->ClearErrors();
777 }
778
745 // Test Packaging and installing an extension. 779 // Test Packaging and installing an extension.
746 TEST_F(ExtensionsServiceTest, PackExtension) { 780 TEST_F(ExtensionsServiceTest, PackExtension) {
747 InitializeEmptyExtensionsService(); 781 InitializeEmptyExtensionsService();
748 FilePath extensions_path; 782 FilePath extensions_path;
749 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 783 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
750 extensions_path = extensions_path.AppendASCII("extensions"); 784 extensions_path = extensions_path.AppendASCII("extensions");
751 FilePath input_directory = extensions_path 785 FilePath input_directory = extensions_path
752 .AppendASCII("good") 786 .AppendASCII("good")
753 .AppendASCII("Extensions") 787 .AppendASCII("Extensions")
754 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 788 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 1629
1596 recorder.set_ready(false); 1630 recorder.set_ready(false);
1597 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); 1631 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY));
1598 service = new ExtensionsService(&profile, command_line.get(), 1632 service = new ExtensionsService(&profile, command_line.get(),
1599 profile.GetPrefs(), install_dir, false); 1633 profile.GetPrefs(), install_dir, false);
1600 EXPECT_FALSE(service->extensions_enabled()); 1634 EXPECT_FALSE(service->extensions_enabled());
1601 service->Init(); 1635 service->Init();
1602 loop.RunAllPending(); 1636 loop.RunAllPending();
1603 EXPECT_TRUE(recorder.ready()); 1637 EXPECT_TRUE(recorder.ready());
1604 } 1638 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.cc ('k') | chrome/renderer/user_script_slave.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698