OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "base/at_exit.h" |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "base/file_util.h" | 15 #include "base/file_util.h" |
15 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
16 #include "base/json/json_value_serializer.h" | 17 #include "base/json/json_value_serializer.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
19 #include "base/path_service.h" | 20 #include "base/path_service.h" |
20 #include "base/scoped_temp_dir.h" | 21 #include "base/scoped_temp_dir.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include "chrome/common/extensions/extension_constants.h" | 54 #include "chrome/common/extensions/extension_constants.h" |
54 #include "chrome/common/extensions/extension_resource.h" | 55 #include "chrome/common/extensions/extension_resource.h" |
55 #include "chrome/common/extensions/url_pattern.h" | 56 #include "chrome/common/extensions/url_pattern.h" |
56 #include "chrome/common/pref_names.h" | 57 #include "chrome/common/pref_names.h" |
57 #include "chrome/common/url_constants.h" | 58 #include "chrome/common/url_constants.h" |
58 #include "chrome/test/base/testing_profile.h" | 59 #include "chrome/test/base/testing_profile.h" |
59 #include "content/browser/appcache/chrome_appcache_service.h" | 60 #include "content/browser/appcache/chrome_appcache_service.h" |
60 #include "content/browser/file_system/browser_file_system_helper.h" | 61 #include "content/browser/file_system/browser_file_system_helper.h" |
61 #include "content/browser/in_process_webkit/dom_storage_context.h" | 62 #include "content/browser/in_process_webkit/dom_storage_context.h" |
62 #include "content/browser/in_process_webkit/webkit_context.h" | 63 #include "content/browser/in_process_webkit/webkit_context.h" |
| 64 #include "content/browser/plugin_service.h" |
63 #include "content/public/browser/notification_registrar.h" | 65 #include "content/public/browser/notification_registrar.h" |
64 #include "content/public/browser/notification_service.h" | 66 #include "content/public/browser/notification_service.h" |
65 #include "content/test/test_browser_thread.h" | 67 #include "content/test/test_browser_thread.h" |
66 #include "googleurl/src/gurl.h" | 68 #include "googleurl/src/gurl.h" |
67 #include "net/base/cookie_monster.h" | 69 #include "net/base/cookie_monster.h" |
68 #include "net/base/cookie_options.h" | 70 #include "net/base/cookie_options.h" |
69 #include "net/url_request/url_request_context.h" | 71 #include "net/url_request/url_request_context.h" |
70 #include "net/url_request/url_request_context_getter.h" | 72 #include "net/url_request/url_request_context_getter.h" |
71 #include "testing/gtest/include/gtest/gtest.h" | 73 #include "testing/gtest/include/gtest/gtest.h" |
72 #include "testing/platform_test.h" | 74 #include "testing/platform_test.h" |
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 ASSERT_TRUE(file_util::PathExists(private_key_path)); | 977 ASSERT_TRUE(file_util::PathExists(private_key_path)); |
976 } | 978 } |
977 | 979 |
978 // The tests are designed so that we never expect to see a packing error. | 980 // The tests are designed so that we never expect to see a packing error. |
979 void PackExtensionTestClient::OnPackFailure(const std::string& error_message) { | 981 void PackExtensionTestClient::OnPackFailure(const std::string& error_message) { |
980 FAIL() << "Packing should not fail."; | 982 FAIL() << "Packing should not fail."; |
981 } | 983 } |
982 | 984 |
983 // Test loading good extensions from the profile directory. | 985 // Test loading good extensions from the profile directory. |
984 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { | 986 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { |
| 987 base::ShadowingAtExitManager at_exit_manager; |
| 988 PluginService::GetInstance()->Init(); |
| 989 |
985 // Initialize the test dir with a good Preferences/extensions. | 990 // Initialize the test dir with a good Preferences/extensions. |
986 FilePath source_install_dir = data_dir_ | 991 FilePath source_install_dir = data_dir_ |
987 .AppendASCII("good") | 992 .AppendASCII("good") |
988 .AppendASCII("Extensions"); | 993 .AppendASCII("Extensions"); |
989 FilePath pref_path = source_install_dir | 994 FilePath pref_path = source_install_dir |
990 .DirName() | 995 .DirName() |
991 .AppendASCII("Preferences"); | 996 .AppendASCII("Preferences"); |
992 InitializeInstalledExtensionService(pref_path, source_install_dir); | 997 InitializeInstalledExtensionService(pref_path, source_install_dir); |
993 | 998 |
994 service_->Init(); | 999 service_->Init(); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 extension_manifest_errors::kMissingFile)) << GetErrors()[2]; | 1117 extension_manifest_errors::kMissingFile)) << GetErrors()[2]; |
1113 | 1118 |
1114 EXPECT_TRUE(MatchPattern(GetErrors()[3], | 1119 EXPECT_TRUE(MatchPattern(GetErrors()[3], |
1115 std::string("Could not load extension from '*'. ") + | 1120 std::string("Could not load extension from '*'. ") + |
1116 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[3]; | 1121 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[3]; |
1117 }; | 1122 }; |
1118 | 1123 |
1119 // Test that partially deleted extensions are cleaned up during startup | 1124 // Test that partially deleted extensions are cleaned up during startup |
1120 // Test loading bad extensions from the profile directory. | 1125 // Test loading bad extensions from the profile directory. |
1121 TEST_F(ExtensionServiceTest, CleanupOnStartup) { | 1126 TEST_F(ExtensionServiceTest, CleanupOnStartup) { |
| 1127 base::ShadowingAtExitManager at_exit_manager; |
| 1128 PluginService::GetInstance()->Init(); |
| 1129 |
1122 FilePath source_install_dir = data_dir_ | 1130 FilePath source_install_dir = data_dir_ |
1123 .AppendASCII("good") | 1131 .AppendASCII("good") |
1124 .AppendASCII("Extensions"); | 1132 .AppendASCII("Extensions"); |
1125 FilePath pref_path = source_install_dir | 1133 FilePath pref_path = source_install_dir |
1126 .DirName() | 1134 .DirName() |
1127 .AppendASCII("Preferences"); | 1135 .AppendASCII("Preferences"); |
1128 | 1136 |
1129 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1137 InitializeInstalledExtensionService(pref_path, source_install_dir); |
1130 | 1138 |
1131 // Simulate that one of them got partially deleted by clearing its pref. | 1139 // Simulate that one of them got partially deleted by clearing its pref. |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 EXPECT_EQ(expected_api_perms, known_perms->apis()); | 1453 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
1446 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); | 1454 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
1447 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); | 1455 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
1448 } | 1456 } |
1449 | 1457 |
1450 #if !defined(OS_CHROMEOS) | 1458 #if !defined(OS_CHROMEOS) |
1451 // Tests that the granted permissions full_access bit gets set correctly when | 1459 // Tests that the granted permissions full_access bit gets set correctly when |
1452 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS | 1460 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS |
1453 // since they don't support plugins. | 1461 // since they don't support plugins. |
1454 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { | 1462 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { |
| 1463 base::ShadowingAtExitManager at_exit_manager; |
| 1464 PluginService::GetInstance()->Init(); |
| 1465 |
1455 InitializeEmptyExtensionService(); | 1466 InitializeEmptyExtensionService(); |
1456 | 1467 |
1457 FilePath path = data_dir_ | 1468 FilePath path = data_dir_ |
1458 .AppendASCII("good") | 1469 .AppendASCII("good") |
1459 .AppendASCII("Extensions") | 1470 .AppendASCII("Extensions") |
1460 .AppendASCII(good1) | 1471 .AppendASCII(good1) |
1461 .AppendASCII("2"); | 1472 .AppendASCII("2"); |
1462 | 1473 |
1463 ASSERT_TRUE(file_util::PathExists(path)); | 1474 ASSERT_TRUE(file_util::PathExists(path)); |
1464 PackAndInstallCrx(path, true); | 1475 PackAndInstallCrx(path, true); |
(...skipping 2861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4326 ASSERT_FALSE(AddPendingSyncInstall()); | 4337 ASSERT_FALSE(AddPendingSyncInstall()); |
4327 | 4338 |
4328 // Wait for the external source to install. | 4339 // Wait for the external source to install. |
4329 WaitForCrxInstall(crx_path_, true); | 4340 WaitForCrxInstall(crx_path_, true); |
4330 ASSERT_TRUE(IsCrxInstalled()); | 4341 ASSERT_TRUE(IsCrxInstalled()); |
4331 | 4342 |
4332 // Now that the extension is installed, sync request should fail | 4343 // Now that the extension is installed, sync request should fail |
4333 // because the extension is already installed. | 4344 // because the extension is already installed. |
4334 ASSERT_FALSE(AddPendingSyncInstall()); | 4345 ASSERT_FALSE(AddPendingSyncInstall()); |
4335 } | 4346 } |
OLD | NEW |