[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 5 | #include <algorithm> |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 6 | #include <set> |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
[email protected] | be5a6db | 2012-11-13 14:39:11 | [diff] [blame] | 9 | #include "base/at_exit.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 10 | #include "base/basictypes.h" |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 11 | #include "base/bind.h" |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 13 | #include "base/file_util.h" |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 14 | #include "base/files/file_enumerator.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 15 | #include "base/files/scoped_temp_dir.h" |
[email protected] | ffbec69 | 2012-02-26 20:26:42 | [diff] [blame] | 16 | #include "base/json/json_file_value_serializer.h" |
[email protected] | 93d49d7 | 2009-10-23 20:00:20 | [diff] [blame] | 17 | #include "base/json/json_reader.h" |
[email protected] | ffbec69 | 2012-02-26 20:26:42 | [diff] [blame] | 18 | #include "base/json/json_string_value_serializer.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 19 | #include "base/memory/scoped_ptr.h" |
[email protected] | 71cb8aa | 2011-12-29 19:14:00 | [diff] [blame] | 20 | #include "base/memory/weak_ptr.h" |
[email protected] | b19fe57 | 2013-07-18 04:54:26 | [diff] [blame] | 21 | #include "base/message_loop/message_loop.h" |
[email protected] | 9eec53fe | 2013-10-30 20:21:17 | [diff] [blame] | 22 | #include "base/prefs/scoped_user_pref_update.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 23 | #include "base/stl_util.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 24 | #include "base/strings/string16.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 25 | #include "base/strings/string_number_conversions.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 26 | #include "base/strings/string_util.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 27 | #include "base/strings/utf_string_conversions.h" |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 28 | #include "base/version.h" |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 29 | #include "chrome/browser/browser_process.h" |
[email protected] | 9ea0cd3 | 2013-07-12 01:50:36 | [diff] [blame] | 30 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 31 | #include "chrome/browser/extensions/app_sync_data.h" |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 32 | #include "chrome/browser/extensions/blacklist.h" |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 33 | #include "chrome/browser/extensions/chrome_app_sorting.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 34 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | eb6c7ef | 2011-12-12 23:12:20 | [diff] [blame] | 35 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 36 | #include "chrome/browser/extensions/default_apps.h" |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 37 | #include "chrome/browser/extensions/extension_creator.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 38 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 39 | #include "chrome/browser/extensions/extension_error_ui.h" |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 40 | #include "chrome/browser/extensions/extension_notification_observer.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 41 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 42 | #include "chrome/browser/extensions/extension_service_test_base.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 43 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_sync_data.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_sync_service.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 47 | #include "chrome/browser/extensions/external_install_error.h" |
| 48 | #include "chrome/browser/extensions/external_install_manager.h" |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 49 | #include "chrome/browser/extensions/external_policy_loader.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 50 | #include "chrome/browser/extensions/external_pref_loader.h" |
| 51 | #include "chrome/browser/extensions/external_provider_impl.h" |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 52 | #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 53 | #include "chrome/browser/extensions/installed_loader.h" |
[email protected] | f0bfe62 | 2012-06-22 01:01:44 | [diff] [blame] | 54 | #include "chrome/browser/extensions/pack_extension_job.h" |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 55 | #include "chrome/browser/extensions/pending_extension_info.h" |
| 56 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 57 | #include "chrome/browser/extensions/test_blacklist.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 58 | #include "chrome/browser/extensions/test_extension_system.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 59 | #include "chrome/browser/extensions/unpacked_installer.h" |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 60 | #include "chrome/browser/extensions/updater/extension_updater.h" |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 61 | #include "chrome/browser/prefs/pref_service_syncable.h" |
[email protected] | 343a0d87 | 2014-08-05 11:44:18 | [diff] [blame] | 62 | #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 63 | #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
[email protected] | 50736a1 | 2013-09-26 08:58:34 | [diff] [blame] | 64 | #include "chrome/browser/sync/profile_sync_service.h" |
| 65 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 66 | #include "chrome/common/chrome_constants.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 67 | #include "chrome/common/chrome_switches.h" |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 68 | #include "chrome/common/extensions/api/plugins/plugins_handler.h" |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 69 | #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 70 | #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 71 | #include "chrome/common/extensions/manifest_url_handler.h" |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 72 | #include "chrome/common/pref_names.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 73 | #include "chrome/common/url_constants.h" |
[email protected] | 078c319 | 2013-08-22 08:18:05 | [diff] [blame] | 74 | #include "chrome/test/base/scoped_browser_locale.h" |
[email protected] | a4ff9eae | 2011-08-01 19:58:16 | [diff] [blame] | 75 | #include "chrome/test/base/testing_profile.h" |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 76 | #include "components/crx_file/id_util.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 77 | #include "components/pref_registry/pref_registry_syncable.h" |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 78 | #include "content/public/browser/dom_storage_context.h" |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 79 | #include "content/public/browser/gpu_data_manager.h" |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 80 | #include "content/public/browser/indexed_db_context.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 81 | #include "content/public/browser/notification_registrar.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 82 | #include "content/public/browser/notification_service.h" |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 83 | #include "content/public/browser/plugin_service.h" |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 84 | #include "content/public/browser/render_process_host.h" |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 85 | #include "content/public/browser/storage_partition.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 86 | #include "content/public/common/content_constants.h" |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 87 | #include "content/public/test/test_utils.h" |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 88 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 89 | #include "extensions/browser/extension_system.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 90 | #include "extensions/browser/external_provider_interface.h" |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 91 | #include "extensions/browser/install_flag.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 92 | #include "extensions/browser/management_policy.h" |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 93 | #include "extensions/browser/pref_names.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 94 | #include "extensions/browser/test_management_policy.h" |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 95 | #include "extensions/browser/uninstall_reason.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 96 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 97 | #include "extensions/common/extension.h" |
[email protected] | 22b7b2c | 2013-11-05 22:52:42 | [diff] [blame] | 98 | #include "extensions/common/extension_builder.h" |
[email protected] | 6668e5d | 2014-04-08 23:32:52 | [diff] [blame] | 99 | #include "extensions/common/extension_l10n_util.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 100 | #include "extensions/common/extension_resource.h" |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 101 | #include "extensions/common/feature_switch.h" |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 102 | #include "extensions/common/manifest_constants.h" |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 103 | #include "extensions/common/manifest_handlers/background_info.h" |
[email protected] | 5a55f3f | 2013-10-29 01:08:29 | [diff] [blame] | 104 | #include "extensions/common/permissions/permission_set.h" |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 105 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | a612eb3 | 2014-03-31 22:09:17 | [diff] [blame] | 106 | #include "extensions/common/switches.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 107 | #include "extensions/common/url_pattern.h" |
[email protected] | 22b7b2c | 2013-11-05 22:52:42 | [diff] [blame] | 108 | #include "extensions/common/value_builder.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 109 | #include "gpu/config/gpu_info.h" |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 110 | #include "grit/browser_resources.h" |
[email protected] | 5b9bc35 | 2012-07-18 13:13:34 | [diff] [blame] | 111 | #include "net/cookies/canonical_cookie.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 112 | #include "net/cookies/cookie_monster.h" |
| 113 | #include "net/cookies/cookie_options.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 114 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 115 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 116 | #include "sync/api/fake_sync_change_processor.h" |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 117 | #include "sync/api/string_ordinal.h" |
[email protected] | 50736a1 | 2013-09-26 08:58:34 | [diff] [blame] | 118 | #include "sync/api/sync_data.h" |
[email protected] | 895a1e5 | 2012-05-15 02:50:12 | [diff] [blame] | 119 | #include "sync/api/sync_error_factory.h" |
| 120 | #include "sync/api/sync_error_factory_mock.h" |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 121 | #include "sync/api/syncable_service.h" |
[email protected] | 1bcf30e | 2012-03-10 01:06:41 | [diff] [blame] | 122 | #include "sync/protocol/app_specifics.pb.h" |
| 123 | #include "sync/protocol/extension_specifics.pb.h" |
| 124 | #include "sync/protocol/sync.pb.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 125 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | f66c110c | 2008-12-05 20:26:29 | [diff] [blame] | 126 | #include "testing/platform_test.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 127 | #include "url/gurl.h" |
[email protected] | 08b1f75f | 2013-05-22 22:02:38 | [diff] [blame] | 128 | #include "webkit/browser/database/database_tracker.h" |
[email protected] | 7660ec9 | 2013-05-30 05:12:39 | [diff] [blame] | 129 | #include "webkit/browser/quota/quota_manager.h" |
[email protected] | 2a9644c | 2013-06-19 06:19:34 | [diff] [blame] | 130 | #include "webkit/common/database/database_identifier.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 131 | |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 132 | #if defined(OS_CHROMEOS) |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 133 | #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" |
[email protected] | e4854dc | 2013-04-24 00:11:51 | [diff] [blame] | 134 | #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 135 | #include "chrome/browser/chromeos/settings/device_settings_service.h" |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 136 | #endif |
| 137 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 138 | // The blacklist tests rely on safe browsing. |
| 139 | #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) |
| 140 | #define ENABLE_BLACKLIST_TESTS |
| 141 | #endif |
| 142 | |
[email protected] | aeca23f | 2013-06-21 22:34:41 | [diff] [blame] | 143 | using base::DictionaryValue; |
| 144 | using base::ListValue; |
| 145 | using base::Value; |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 146 | using content::BrowserContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 147 | using content::BrowserThread; |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 148 | using content::DOMStorageContext; |
| 149 | using content::IndexedDBContext; |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 150 | using content::PluginService; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 151 | using extensions::APIPermission; |
| 152 | using extensions::APIPermissionSet; |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 153 | using extensions::AppSorting; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 154 | using extensions::Blacklist; |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 155 | using extensions::CrxInstaller; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 156 | using extensions::Extension; |
[email protected] | 6d77749 | 2012-07-11 17:33:43 | [diff] [blame] | 157 | using extensions::ExtensionCreator; |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 158 | using extensions::ExtensionPrefs; |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 159 | using extensions::ExtensionRegistry; |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 160 | using extensions::ExtensionResource; |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 161 | using extensions::ExtensionSystem; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 162 | using extensions::FakeSafeBrowsingDatabaseManager; |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 163 | using extensions::FeatureSwitch; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 164 | using extensions::Manifest; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 165 | using extensions::PermissionSet; |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 166 | using extensions::TestExtensionSystem; |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 167 | using extensions::UnloadedExtensionInfo; |
[email protected] | e9f541a | 2012-11-19 21:52:31 | [diff] [blame] | 168 | using extensions::URLPatternSet; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 169 | |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 170 | namespace keys = extensions::manifest_keys; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 171 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 172 | namespace { |
| 173 | |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 174 | // Extension ids used during testing. |
[email protected] | 095ccbe4 | 2013-09-26 00:06:42 | [diff] [blame] | 175 | const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 176 | const char good1[] = "hpiknbiabeeppbpihjehijgoemciehgk"; |
| 177 | const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; |
[email protected] | aa5219d | 2013-11-09 19:25:41 | [diff] [blame] | 178 | const char all_zero[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
[email protected] | 095ccbe4 | 2013-09-26 00:06:42 | [diff] [blame] | 179 | const char good2048[] = "nmgjhmhbleinmjpbdhgajfjkbijcmgbh"; |
| 180 | const char good_crx[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 181 | const char hosted_app[] = "kbmnembihfiondgfjekmnmcbddelicoi"; |
| 182 | const char page_action[] = "obcimlgaoabeegjmmpldobjndiealpln"; |
| 183 | const char theme_crx[] = "iamefpfkojoapidjnbafmgkgncegbkad"; |
| 184 | const char theme2_crx[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 185 | const char permissions_crx[] = "eagpmdpfmaekmmcejjbmjoecnejeiiin"; |
| 186 | const char unpacked[] = "cbcdidchbppangcjoddlpdjlenngjldk"; |
| 187 | const char updates_from_webstore[] = "akjooamlhcgeopfifcmlggaebeocgokj"; |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 188 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 189 | struct ExtensionsOrder { |
[email protected] | 198b590 | 2013-06-27 10:36:11 | [diff] [blame] | 190 | bool operator()(const scoped_refptr<const Extension>& a, |
| 191 | const scoped_refptr<const Extension>& b) { |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 192 | return a->name() < b->name(); |
| 193 | } |
| 194 | }; |
| 195 | |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 196 | static std::vector<base::string16> GetErrors() { |
| 197 | const std::vector<base::string16>* errors = |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 198 | ExtensionErrorReporter::GetInstance()->GetErrors(); |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 199 | std::vector<base::string16> ret_val; |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 200 | |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 201 | for (std::vector<base::string16>::const_iterator iter = errors->begin(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 202 | iter != errors->end(); ++iter) { |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 203 | std::string utf8_error = base::UTF16ToUTF8(*iter); |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 204 | if (utf8_error.find(".svn") == std::string::npos) { |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 205 | ret_val.push_back(*iter); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | // The tests rely on the errors being in a certain order, which can vary |
| 210 | // depending on how filesystem iteration works. |
| 211 | std::stable_sort(ret_val.begin(), ret_val.end()); |
| 212 | |
| 213 | return ret_val; |
| 214 | } |
| 215 | |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 216 | static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 217 | int schemes = URLPattern::SCHEME_ALL; |
| 218 | extent->AddPattern(URLPattern(schemes, pattern)); |
| 219 | } |
| 220 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 221 | base::FilePath GetTemporaryFile() { |
| 222 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 223 | CHECK(base::CreateTemporaryFile(&temp_file)); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 224 | return temp_file; |
| 225 | } |
| 226 | |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 227 | bool WaitForCountNotificationsCallback(int *count) { |
| 228 | return --(*count) == 0; |
| 229 | } |
| 230 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 231 | } // namespace |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 232 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 233 | class MockExtensionProvider : public extensions::ExternalProviderInterface { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 234 | public: |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 235 | MockExtensionProvider( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 236 | VisitorInterface* visitor, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 237 | Manifest::Location location) |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 238 | : location_(location), visitor_(visitor), visit_count_(0) { |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 239 | } |
| 240 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 241 | virtual ~MockExtensionProvider() {} |
| 242 | |
| 243 | void UpdateOrAddExtension(const std::string& id, |
| 244 | const std::string& version, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 245 | const base::FilePath& path) { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 246 | extension_map_[id] = std::make_pair(version, path); |
| 247 | } |
| 248 | |
| 249 | void RemoveExtension(const std::string& id) { |
| 250 | extension_map_.erase(id); |
| 251 | } |
| 252 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 253 | // ExternalProvider implementation: |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 254 | virtual void VisitRegisteredExtension() OVERRIDE { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 255 | visit_count_++; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 256 | for (DataMap::const_iterator i = extension_map_.begin(); |
| 257 | i != extension_map_.end(); ++i) { |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 258 | Version version(i->second.first); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 259 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 260 | visitor_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 261 | i->first, &version, i->second.second, location_, |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 262 | Extension::NO_FLAGS, false); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 263 | } |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 264 | visitor_->OnExternalProviderReady(this); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 267 | virtual bool HasExtension(const std::string& id) const OVERRIDE { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 268 | return extension_map_.find(id) != extension_map_.end(); |
| 269 | } |
| 270 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 271 | virtual bool GetExtensionDetails( |
| 272 | const std::string& id, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 273 | Manifest::Location* location, |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 274 | scoped_ptr<Version>* version) const OVERRIDE { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 275 | DataMap::const_iterator it = extension_map_.find(id); |
| 276 | if (it == extension_map_.end()) |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 277 | return false; |
| 278 | |
| 279 | if (version) |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 280 | version->reset(new Version(it->second.first)); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 281 | |
| 282 | if (location) |
| 283 | *location = location_; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 284 | |
| 285 | return true; |
| 286 | } |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 287 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 288 | virtual bool IsReady() const OVERRIDE { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 289 | return true; |
| 290 | } |
| 291 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 292 | virtual void ServiceShutdown() OVERRIDE { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 293 | } |
| 294 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 295 | int visit_count() const { return visit_count_; } |
| 296 | void set_visit_count(int visit_count) { |
| 297 | visit_count_ = visit_count; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | private: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 301 | typedef std::map< std::string, std::pair<std::string, base::FilePath> > |
| 302 | DataMap; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 303 | DataMap extension_map_; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 304 | Manifest::Location location_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 305 | VisitorInterface* visitor_; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 306 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 307 | // visit_count_ tracks the number of calls to VisitRegisteredExtension(). |
| 308 | // Mutable because it must be incremented on each call to |
| 309 | // VisitRegisteredExtension(), which must be a const method to inherit |
| 310 | // from the class being mocked. |
| 311 | mutable int visit_count_; |
| 312 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 313 | DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider); |
| 314 | }; |
| 315 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 316 | class MockProviderVisitor |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 317 | : public extensions::ExternalProviderInterface::VisitorInterface { |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 318 | public: |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 319 | // The provider will return |fake_base_path| from |
| 320 | // GetBaseCrxFilePath(). User can test the behavior with |
| 321 | // and without an empty path using this parameter. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 322 | explicit MockProviderVisitor(base::FilePath fake_base_path) |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 323 | : ids_found_(0), |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 324 | fake_base_path_(fake_base_path), |
| 325 | expected_creation_flags_(Extension::NO_FLAGS) { |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 326 | profile_.reset(new TestingProfile); |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 327 | } |
| 328 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 329 | MockProviderVisitor(base::FilePath fake_base_path, |
| 330 | int expected_creation_flags) |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 331 | : ids_found_(0), |
| 332 | fake_base_path_(fake_base_path), |
| 333 | expected_creation_flags_(expected_creation_flags) { |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 336 | int Visit(const std::string& json_data) { |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 337 | // Give the test json file to the provider for parsing. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 338 | provider_.reset(new extensions::ExternalProviderImpl( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 339 | this, |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 340 | new extensions::ExternalTestingLoader(json_data, fake_base_path_), |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 341 | profile_.get(), |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 342 | Manifest::EXTERNAL_PREF, |
| 343 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 344 | Extension::NO_FLAGS)); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 345 | |
| 346 | // We also parse the file into a dictionary to compare what we get back |
| 347 | // from the provider. |
| 348 | JSONStringValueSerializer serializer(json_data); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 349 | base::Value* json_value = serializer.Deserialize(NULL, NULL); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 350 | |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 351 | if (!json_value || !json_value->IsType(base::Value::TYPE_DICTIONARY)) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 352 | NOTREACHED() << "Unable to deserialize json data"; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 353 | return -1; |
| 354 | } else { |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 355 | base::DictionaryValue* external_extensions = |
| 356 | static_cast<base::DictionaryValue*>(json_value); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 357 | prefs_.reset(external_extensions); |
| 358 | } |
| 359 | |
| 360 | // Reset our counter. |
| 361 | ids_found_ = 0; |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 362 | // Ask the provider to look up all extensions and return them. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 363 | provider_->VisitRegisteredExtension(); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 364 | |
| 365 | return ids_found_; |
| 366 | } |
| 367 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 368 | virtual bool OnExternalExtensionFileFound(const std::string& id, |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 369 | const Version* version, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 370 | const base::FilePath& path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 371 | Manifest::Location unused, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 372 | int creation_flags, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 373 | bool mark_acknowledged) OVERRIDE { |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 374 | EXPECT_EQ(expected_creation_flags_, creation_flags); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 375 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 376 | ++ids_found_; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 377 | base::DictionaryValue* pref; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 378 | // This tests is to make sure that the provider only notifies us of the |
| 379 | // values we gave it. So if the id we doesn't exist in our internal |
| 380 | // dictionary then something is wrong. |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 381 | EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
| 382 | << "Got back ID (" << id.c_str() << ") we weren't expecting"; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 383 | |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 384 | EXPECT_TRUE(path.IsAbsolute()); |
| 385 | if (!fake_base_path_.empty()) |
| 386 | EXPECT_TRUE(fake_base_path_.IsParent(path)); |
| 387 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 388 | if (pref) { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 389 | EXPECT_TRUE(provider_->HasExtension(id)); |
| 390 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 391 | // Ask provider if the extension we got back is registered. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 392 | Manifest::Location location = Manifest::INVALID_LOCATION; |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 393 | scoped_ptr<Version> v1; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 394 | base::FilePath crx_path; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 395 | |
| 396 | EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1)); |
| 397 | EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); |
| 398 | |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 399 | scoped_ptr<Version> v2; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 400 | EXPECT_TRUE(provider_->GetExtensionDetails(id, &location, &v2)); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 401 | EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); |
| 402 | EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 403 | EXPECT_EQ(Manifest::EXTERNAL_PREF, location); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 404 | |
| 405 | // Remove it so we won't count it ever again. |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 406 | prefs_->Remove(id, NULL); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 407 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 408 | return true; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 409 | } |
| 410 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 411 | virtual bool OnExternalExtensionUpdateUrlFound( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 412 | const std::string& id, |
| 413 | const std::string& install_parameter, |
| 414 | const GURL& update_url, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 415 | Manifest::Location location, |
| 416 | int creation_flags, |
| 417 | bool mark_acknowledged) OVERRIDE { |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 418 | ++ids_found_; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 419 | base::DictionaryValue* pref; |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 420 | // This tests is to make sure that the provider only notifies us of the |
| 421 | // values we gave it. So if the id we doesn't exist in our internal |
| 422 | // dictionary then something is wrong. |
| 423 | EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
| 424 | << L"Got back ID (" << id.c_str() << ") we weren't expecting"; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 425 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 426 | |
| 427 | if (pref) { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 428 | EXPECT_TRUE(provider_->HasExtension(id)); |
| 429 | |
| 430 | // External extensions with update URLs do not have versions. |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 431 | scoped_ptr<Version> v1; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 432 | Manifest::Location location1 = Manifest::INVALID_LOCATION; |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 433 | EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 434 | EXPECT_FALSE(v1.get()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 435 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 436 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 437 | std::string parsed_install_parameter; |
| 438 | pref->GetString("install_parameter", &parsed_install_parameter); |
| 439 | EXPECT_EQ(parsed_install_parameter, install_parameter); |
| 440 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 441 | // Remove it so we won't count it again. |
| 442 | prefs_->Remove(id, NULL); |
| 443 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 444 | return true; |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 445 | } |
| 446 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 447 | virtual void OnExternalProviderReady( |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 448 | const extensions::ExternalProviderInterface* provider) OVERRIDE { |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 449 | EXPECT_EQ(provider, provider_.get()); |
| 450 | EXPECT_TRUE(provider->IsReady()); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 451 | } |
| 452 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 453 | private: |
| 454 | int ids_found_; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 455 | base::FilePath fake_base_path_; |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 456 | int expected_creation_flags_; |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 457 | scoped_ptr<extensions::ExternalProviderImpl> provider_; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 458 | scoped_ptr<base::DictionaryValue> prefs_; |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 459 | scoped_ptr<TestingProfile> profile_; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 460 | |
| 461 | DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 462 | }; |
| 463 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 464 | class ExtensionServiceTest : public extensions::ExtensionServiceTestBase, |
| 465 | public content::NotificationObserver { |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 466 | public: |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 467 | ExtensionServiceTest() |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 468 | : unloaded_reason_(UnloadedExtensionInfo::REASON_UNDEFINED), |
| 469 | installed_(NULL), |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 470 | was_update_(false), |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 471 | override_external_install_prompt_( |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 472 | FeatureSwitch::prompt_for_external_extensions(), |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 473 | false), |
| 474 | expected_extensions_count_(0) { |
[email protected] | fdc7619 | 2014-04-20 21:54:41 | [diff] [blame] | 475 | registrar_.Add(this, |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 476 | extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 477 | content::NotificationService::AllSources()); |
[email protected] | 0403d4e | 2014-05-23 07:56:36 | [diff] [blame] | 478 | registrar_.Add(this, |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 479 | extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 480 | content::NotificationService::AllSources()); |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 481 | registrar_.Add( |
| 482 | this, |
| 483 | extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| 484 | content::NotificationService::AllSources()); |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 485 | } |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 486 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 487 | virtual void Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 488 | const content::NotificationSource& source, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 489 | const content::NotificationDetails& details) OVERRIDE { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 490 | switch (type) { |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 491 | case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 492 | const Extension* extension = |
| 493 | content::Details<const Extension>(details).ptr(); |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 494 | loaded_.push_back(make_scoped_refptr(extension)); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 495 | // The tests rely on the errors being in a certain order, which can vary |
| 496 | // depending on how filesystem iteration works. |
| 497 | std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder()); |
| 498 | break; |
| 499 | } |
| 500 | |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 501 | case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 502 | UnloadedExtensionInfo* unloaded_info = |
| 503 | content::Details<UnloadedExtensionInfo>(details).ptr(); |
| 504 | const Extension* e = unloaded_info->extension; |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 505 | unloaded_id_ = e->id(); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 506 | unloaded_reason_ = unloaded_info->reason; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 507 | extensions::ExtensionList::iterator i = |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 508 | std::find(loaded_.begin(), loaded_.end(), e); |
| 509 | // TODO(erikkay) fix so this can be an assert. Right now the tests |
| 510 | // are manually calling clear() on loaded_, so this isn't doable. |
| 511 | if (i == loaded_.end()) |
| 512 | return; |
| 513 | loaded_.erase(i); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 514 | break; |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 515 | } |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 516 | case extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: { |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 517 | const extensions::InstalledExtensionInfo* installed_info = |
| 518 | content::Details<const extensions::InstalledExtensionInfo>(details) |
| 519 | .ptr(); |
| 520 | installed_ = installed_info->extension; |
| 521 | was_update_ = installed_info->is_update; |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 522 | old_name_ = installed_info->old_name; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 523 | break; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 524 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 525 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 526 | default: |
| 527 | DCHECK(false); |
[email protected] | 3acbd42 | 2008-12-08 18:25:00 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 531 | void AddMockExternalProvider( |
| 532 | extensions::ExternalProviderInterface* provider) { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 533 | service()->AddProviderForTesting(provider); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 534 | } |
| 535 | |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 536 | void MockSyncStartFlare(bool* was_called, |
| 537 | syncer::ModelType* model_type_passed_in, |
| 538 | syncer::ModelType model_type) { |
| 539 | *was_called = true; |
| 540 | *model_type_passed_in = model_type; |
| 541 | } |
| 542 | |
[email protected] | 9197f3b | 2009-06-02 00:49:27 | [diff] [blame] | 543 | protected: |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 544 | // Paths to some of the fake extensions. |
| 545 | base::FilePath good0_path() { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 546 | return data_dir() |
| 547 | .AppendASCII("good") |
| 548 | .AppendASCII("Extensions") |
| 549 | .AppendASCII(good0) |
| 550 | .AppendASCII("1.0.0.0"); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | base::FilePath good1_path() { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 554 | return data_dir() |
| 555 | .AppendASCII("good") |
| 556 | .AppendASCII("Extensions") |
| 557 | .AppendASCII(good1) |
| 558 | .AppendASCII("2"); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | base::FilePath good2_path() { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 562 | return data_dir() |
| 563 | .AppendASCII("good") |
| 564 | .AppendASCII("Extensions") |
| 565 | .AppendASCII(good2) |
| 566 | .AppendASCII("1.0"); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 567 | } |
| 568 | |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 569 | void TestExternalProvider(MockExtensionProvider* provider, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 570 | Manifest::Location location); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 571 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 572 | void PackCRX(const base::FilePath& dir_path, |
| 573 | const base::FilePath& pem_path, |
| 574 | const base::FilePath& crx_path) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 575 | // Use the existing pem key, if provided. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 576 | base::FilePath pem_output_path; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 577 | if (pem_path.value().empty()) { |
| 578 | pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 579 | } else { |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 580 | ASSERT_TRUE(base::PathExists(pem_path)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 581 | } |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 582 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 583 | ASSERT_TRUE(base::DeleteFile(crx_path, false)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 584 | |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 585 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 586 | ASSERT_TRUE(creator->Run(dir_path, |
| 587 | crx_path, |
| 588 | pem_path, |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 589 | pem_output_path, |
| 590 | ExtensionCreator::kOverwriteCRX)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 591 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 592 | ASSERT_TRUE(base::PathExists(crx_path)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 593 | } |
| 594 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 595 | enum InstallState { |
| 596 | INSTALL_FAILED, |
| 597 | INSTALL_UPDATED, |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 598 | INSTALL_NEW, |
| 599 | INSTALL_WITHOUT_LOAD, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 600 | }; |
| 601 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 602 | const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
| 603 | const base::FilePath& pem_path, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 604 | InstallState install_state, |
| 605 | int creation_flags) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 606 | base::FilePath crx_path; |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 607 | base::ScopedTempDir temp_dir; |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 608 | EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 609 | crx_path = temp_dir.path().AppendASCII("temp.crx"); |
| 610 | |
| 611 | PackCRX(dir_path, pem_path, crx_path); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 612 | return InstallCRX(crx_path, install_state, creation_flags); |
| 613 | } |
| 614 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 615 | const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
| 616 | const base::FilePath& pem_path, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 617 | InstallState install_state) { |
| 618 | return PackAndInstallCRX(dir_path, pem_path, install_state, |
| 619 | Extension::NO_FLAGS); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 620 | } |
| 621 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 622 | const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 623 | InstallState install_state) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 624 | return PackAndInstallCRX(dir_path, base::FilePath(), install_state, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 625 | Extension::NO_FLAGS); |
| 626 | } |
| 627 | |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 628 | // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 629 | // is expected to fail. |
| 630 | // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is |
| 631 | // non-empty, expects that the existing extension's title was |
| 632 | // |expected_old_name|. |
| 633 | const Extension* InstallCRX(const base::FilePath& path, |
| 634 | InstallState install_state, |
| 635 | int creation_flags, |
| 636 | const std::string& expected_old_name) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 637 | InstallCRXInternal(path, creation_flags); |
| 638 | return VerifyCrxInstall(path, install_state, expected_old_name); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 642 | // is expected to fail. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 643 | const Extension* InstallCRX(const base::FilePath& path, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 644 | InstallState install_state, |
| 645 | int creation_flags) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 646 | return InstallCRX(path, install_state, creation_flags, std::string()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 647 | } |
| 648 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 649 | // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 650 | // is expected to fail. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 651 | const Extension* InstallCRX(const base::FilePath& path, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 652 | InstallState install_state) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 653 | return InstallCRX(path, install_state, Extension::NO_FLAGS); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 654 | } |
| 655 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 656 | const Extension* InstallCRXFromWebStore(const base::FilePath& path, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 657 | InstallState install_state) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 658 | InstallCRXInternal(path, Extension::FROM_WEBSTORE); |
| 659 | return VerifyCrxInstall(path, install_state); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 660 | } |
| 661 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 662 | const Extension* InstallCRXWithLocation(const base::FilePath& crx_path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 663 | Manifest::Location install_location, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 664 | InstallState install_state) { |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 665 | EXPECT_TRUE(base::PathExists(crx_path)) |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 666 | << "Path does not exist: "<< crx_path.value().c_str(); |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 667 | // no client (silent install) |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 668 | scoped_refptr<CrxInstaller> installer( |
| 669 | CrxInstaller::CreateSilent(service())); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 670 | installer->set_install_source(install_location); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 671 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 672 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 673 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 674 | content::NotificationService::AllSources()); |
| 675 | installer->InstallCrx(crx_path); |
| 676 | observer.Wait(); |
| 677 | |
| 678 | return VerifyCrxInstall(crx_path, install_state); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 679 | } |
| 680 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 681 | // Verifies the result of a CRX installation. Used by InstallCRX. Set the |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 682 | // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 683 | // Returns an Extension pointer if the install succeeded, NULL otherwise. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 684 | const Extension* VerifyCrxInstall(const base::FilePath& path, |
| 685 | InstallState install_state) { |
| 686 | return VerifyCrxInstall(path, install_state, std::string()); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 687 | } |
| 688 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 689 | // Verifies the result of a CRX installation. Used by InstallCRX. Set the |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 690 | // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
| 691 | // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is |
| 692 | // non-empty, expects that the existing extension's title was |
| 693 | // |expected_old_name|. |
| 694 | // Returns an Extension pointer if the install succeeded, NULL otherwise. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 695 | const Extension* VerifyCrxInstall(const base::FilePath& path, |
| 696 | InstallState install_state, |
| 697 | const std::string& expected_old_name) { |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 698 | std::vector<base::string16> errors = GetErrors(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 699 | const Extension* extension = NULL; |
| 700 | if (install_state != INSTALL_FAILED) { |
| 701 | if (install_state == INSTALL_NEW) |
| 702 | ++expected_extensions_count_; |
[email protected] | 902f7cd | 2009-05-22 19:02:19 | [diff] [blame] | 703 | |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 704 | EXPECT_TRUE(installed_) << path.value(); |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 705 | // If and only if INSTALL_UPDATED, it should have the is_update flag. |
| 706 | EXPECT_EQ(install_state == INSTALL_UPDATED, was_update_) |
| 707 | << path.value(); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 708 | // If INSTALL_UPDATED, old_name_ should match the given string. |
| 709 | if (install_state == INSTALL_UPDATED && !expected_old_name.empty()) |
| 710 | EXPECT_EQ(expected_old_name, old_name_); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 711 | EXPECT_EQ(0u, errors.size()) << path.value(); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 712 | |
| 713 | if (install_state == INSTALL_WITHOUT_LOAD) { |
| 714 | EXPECT_EQ(0u, loaded_.size()) << path.value(); |
| 715 | } else { |
| 716 | EXPECT_EQ(1u, loaded_.size()) << path.value(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 717 | size_t actual_extension_count = |
| 718 | registry()->enabled_extensions().size() + |
| 719 | registry()->disabled_extensions().size(); |
[email protected] | b1ac7046 | 2013-08-14 21:33:30 | [diff] [blame] | 720 | EXPECT_EQ(expected_extensions_count_, actual_extension_count) << |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 721 | path.value(); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 722 | extension = loaded_[0].get(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 723 | EXPECT_TRUE(service()->GetExtensionById(extension->id(), false)) |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 724 | << path.value(); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 725 | } |
| 726 | |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 727 | for (std::vector<base::string16>::iterator err = errors.begin(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 728 | err != errors.end(); ++err) { |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 729 | LOG(ERROR) << *err; |
| 730 | } |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 731 | } else { |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 732 | EXPECT_FALSE(installed_) << path.value(); |
[email protected] | 86a27407 | 2009-06-11 02:06:45 | [diff] [blame] | 733 | EXPECT_EQ(0u, loaded_.size()) << path.value(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 734 | EXPECT_EQ(1u, errors.size()) << path.value(); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 735 | } |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 736 | |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 737 | installed_ = NULL; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 738 | was_update_ = false; |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 739 | old_name_ = ""; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 740 | loaded_.clear(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 741 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 742 | return extension; |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 743 | } |
| 744 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 745 | enum UpdateState { |
| 746 | FAILED_SILENTLY, |
| 747 | FAILED, |
| 748 | UPDATED, |
| 749 | INSTALLED, |
[email protected] | 343a0d87 | 2014-08-05 11:44:18 | [diff] [blame] | 750 | DISABLED, |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 751 | ENABLED |
| 752 | }; |
| 753 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 754 | void BlackListWebGL() { |
| 755 | static const std::string json_blacklist = |
| 756 | "{\n" |
| 757 | " \"name\": \"gpu blacklist\",\n" |
| 758 | " \"version\": \"1.0\",\n" |
| 759 | " \"entries\": [\n" |
| 760 | " {\n" |
| 761 | " \"id\": 1,\n" |
[email protected] | 3d34657 | 2013-03-22 19:59:55 | [diff] [blame] | 762 | " \"features\": [\"webgl\"]\n" |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 763 | " }\n" |
| 764 | " ]\n" |
| 765 | "}"; |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 766 | gpu::GPUInfo gpu_info; |
[email protected] | 7e34315 | 2012-09-20 21:49:53 | [diff] [blame] | 767 | content::GpuDataManager::GetInstance()->InitializeForTesting( |
| 768 | json_blacklist, gpu_info); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 769 | } |
| 770 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 771 | // Helper method to set up a WindowedNotificationObserver to wait for a |
| 772 | // specific CrxInstaller to finish if we don't know the value of the |
| 773 | // |installer| yet. |
| 774 | static bool IsCrxInstallerDone(extensions::CrxInstaller** installer, |
| 775 | const content::NotificationSource& source, |
| 776 | const content::NotificationDetails& details) { |
| 777 | return content::Source<extensions::CrxInstaller>(source).ptr() == |
| 778 | *installer; |
| 779 | } |
| 780 | |
[email protected] | 343a0d87 | 2014-08-05 11:44:18 | [diff] [blame] | 781 | void PackCRXAndUpdateExtension(const std::string& id, |
| 782 | const base::FilePath& dir_path, |
| 783 | const base::FilePath& pem_path, |
| 784 | UpdateState expected_state) { |
| 785 | base::ScopedTempDir temp_dir; |
| 786 | EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 787 | base::FilePath crx_path = temp_dir.path().AppendASCII("temp.crx"); |
| 788 | |
| 789 | PackCRX(dir_path, pem_path, crx_path); |
| 790 | UpdateExtension(id, crx_path, expected_state); |
| 791 | } |
| 792 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 793 | void UpdateExtension(const std::string& id, |
| 794 | const base::FilePath& in_path, |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 795 | UpdateState expected_state) { |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 796 | ASSERT_TRUE(base::PathExists(in_path)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 797 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 798 | // We need to copy this to a temporary location because Update() will delete |
| 799 | // it. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 800 | base::FilePath path = temp_dir().path(); |
[email protected] | a1295ba2 | 2009-09-02 03:33:39 | [diff] [blame] | 801 | path = path.Append(in_path.BaseName()); |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 802 | ASSERT_TRUE(base::CopyFile(in_path, path)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 803 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 804 | int previous_enabled_extension_count = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 805 | registry()->enabled_extensions().size(); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 806 | int previous_installed_extension_count = |
| 807 | previous_enabled_extension_count + |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 808 | registry()->disabled_extensions().size(); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 809 | |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 810 | extensions::CrxInstaller* installer = NULL; |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 811 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 812 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 813 | base::Bind(&IsCrxInstallerDone, &installer)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 814 | service()->UpdateExtension(id, path, true, &installer); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 815 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 816 | if (installer) |
| 817 | observer.Wait(); |
| 818 | else |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 819 | base::RunLoop().RunUntilIdle(); |
[email protected] | f3113e23 | 2010-06-25 01:36:40 | [diff] [blame] | 820 | |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 821 | std::vector<base::string16> errors = GetErrors(); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 822 | int error_count = errors.size(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 823 | int enabled_extension_count = registry()->enabled_extensions().size(); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 824 | int installed_extension_count = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 825 | enabled_extension_count + registry()->disabled_extensions().size(); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 826 | |
| 827 | int expected_error_count = (expected_state == FAILED) ? 1 : 0; |
| 828 | EXPECT_EQ(expected_error_count, error_count) << path.value(); |
| 829 | |
| 830 | if (expected_state <= FAILED) { |
| 831 | EXPECT_EQ(previous_enabled_extension_count, |
| 832 | enabled_extension_count); |
| 833 | EXPECT_EQ(previous_installed_extension_count, |
| 834 | installed_extension_count); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 835 | } else { |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 836 | int expected_installed_extension_count = |
| 837 | (expected_state >= INSTALLED) ? 1 : 0; |
| 838 | int expected_enabled_extension_count = |
| 839 | (expected_state >= ENABLED) ? 1 : 0; |
| 840 | EXPECT_EQ(expected_installed_extension_count, |
| 841 | installed_extension_count); |
| 842 | EXPECT_EQ(expected_enabled_extension_count, |
| 843 | enabled_extension_count); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 844 | } |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 845 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 846 | // Update() should the temporary input file. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 847 | EXPECT_FALSE(base::PathExists(path)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 848 | } |
| 849 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 850 | void TerminateExtension(const std::string& id) { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 851 | const Extension* extension = service()->GetInstalledExtension(id); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 852 | if (!extension) { |
| 853 | ADD_FAILURE(); |
| 854 | return; |
| 855 | } |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 856 | service()->TrackTerminatedExtensionForTest(extension); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | size_t GetPrefKeyCount() { |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 860 | const base::DictionaryValue* dict = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 861 | profile()->GetPrefs()->GetDictionary("extensions.settings"); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 862 | if (!dict) { |
| 863 | ADD_FAILURE(); |
| 864 | return 0; |
| 865 | } |
| 866 | return dict->size(); |
| 867 | } |
| 868 | |
| 869 | void UninstallExtension(const std::string& id, bool use_helper) { |
| 870 | // Verify that the extension is installed. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 871 | base::FilePath extension_path = extensions_install_dir().AppendASCII(id); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 872 | EXPECT_TRUE(base::PathExists(extension_path)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 873 | size_t pref_key_count = GetPrefKeyCount(); |
| 874 | EXPECT_GT(pref_key_count, 0u); |
| 875 | ValidateIntegerPref(id, "state", Extension::ENABLED); |
| 876 | |
| 877 | // Uninstall it. |
| 878 | if (use_helper) { |
[email protected] | cc2f55c | 2014-07-08 02:19:04 | [diff] [blame] | 879 | EXPECT_TRUE(ExtensionService::UninstallExtensionHelper( |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 880 | service(), id, extensions::UNINSTALL_REASON_FOR_TESTING)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 881 | } else { |
[email protected] | cc2f55c | 2014-07-08 02:19:04 | [diff] [blame] | 882 | EXPECT_TRUE(service()->UninstallExtension( |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 883 | id, |
| 884 | extensions::UNINSTALL_REASON_FOR_TESTING, |
| 885 | base::Bind(&base::DoNothing), |
| 886 | NULL)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 887 | } |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 888 | --expected_extensions_count_; |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 889 | |
| 890 | // We should get an unload notification. |
| 891 | EXPECT_FALSE(unloaded_id_.empty()); |
| 892 | EXPECT_EQ(id, unloaded_id_); |
| 893 | |
| 894 | // Verify uninstalled state. |
| 895 | size_t new_pref_key_count = GetPrefKeyCount(); |
| 896 | if (new_pref_key_count == pref_key_count) { |
| 897 | ValidateIntegerPref(id, "location", |
| 898 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 899 | } else { |
| 900 | EXPECT_EQ(new_pref_key_count, pref_key_count - 1); |
| 901 | } |
| 902 | |
| 903 | // The extension should not be in the service anymore. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 904 | EXPECT_FALSE(service()->GetInstalledExtension(id)); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 905 | base::RunLoop().RunUntilIdle(); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 906 | |
| 907 | // The directory should be gone. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 908 | EXPECT_FALSE(base::PathExists(extension_path)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | void ValidatePrefKeyCount(size_t count) { |
| 912 | EXPECT_EQ(count, GetPrefKeyCount()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 913 | } |
| 914 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 915 | testing::AssertionResult ValidateBooleanPref( |
| 916 | const std::string& extension_id, |
| 917 | const std::string& pref_path, |
| 918 | bool expected_val) { |
| 919 | std::string msg = "while checking: "; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 920 | msg += extension_id; |
| 921 | msg += " "; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 922 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 923 | msg += " == "; |
| 924 | msg += expected_val ? "true" : "false"; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 925 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 926 | PrefService* prefs = profile()->GetPrefs(); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 927 | const base::DictionaryValue* dict = |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 928 | prefs->GetDictionary("extensions.settings"); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 929 | if (!dict) { |
| 930 | return testing::AssertionFailure() |
| 931 | << "extension.settings does not exist " << msg; |
| 932 | } |
| 933 | |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 934 | const base::DictionaryValue* pref = NULL; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 935 | if (!dict->GetDictionary(extension_id, &pref)) { |
| 936 | return testing::AssertionFailure() |
| 937 | << "extension pref does not exist " << msg; |
| 938 | } |
| 939 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 940 | bool val; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 941 | if (!pref->GetBoolean(pref_path, &val)) { |
| 942 | return testing::AssertionFailure() |
| 943 | << pref_path << " pref not found " << msg; |
| 944 | } |
| 945 | |
| 946 | return expected_val == val |
| 947 | ? testing::AssertionSuccess() |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 948 | : testing::AssertionFailure() << "base::Value is incorrect " << msg; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | bool IsPrefExist(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 952 | const std::string& pref_path) { |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 953 | const base::DictionaryValue* dict = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 954 | profile()->GetPrefs()->GetDictionary("extensions.settings"); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 955 | if (dict == NULL) return false; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 956 | const base::DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 957 | if (!dict->GetDictionary(extension_id, &pref)) { |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 958 | return false; |
| 959 | } |
| 960 | if (pref == NULL) { |
| 961 | return false; |
| 962 | } |
| 963 | bool val; |
| 964 | if (!pref->GetBoolean(pref_path, &val)) { |
| 965 | return false; |
| 966 | } |
| 967 | return true; |
| 968 | } |
| 969 | |
| 970 | void ValidateIntegerPref(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 971 | const std::string& pref_path, |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 972 | int expected_val) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 973 | std::string msg = " while checking: "; |
| 974 | msg += extension_id; |
| 975 | msg += " "; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 976 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 977 | msg += " == "; |
| 978 | msg += base::IntToString(expected_val); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 979 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 980 | PrefService* prefs = profile()->GetPrefs(); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 981 | const base::DictionaryValue* dict = |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 982 | prefs->GetDictionary("extensions.settings"); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 983 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 984 | const base::DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 985 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 986 | EXPECT_TRUE(pref != NULL) << msg; |
| 987 | int val; |
[email protected] | 4c91487e | 2009-10-02 04:11:04 | [diff] [blame] | 988 | ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 989 | EXPECT_EQ(expected_val, val) << msg; |
| 990 | } |
| 991 | |
| 992 | void ValidateStringPref(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 993 | const std::string& pref_path, |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 994 | const std::string& expected_val) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 995 | std::string msg = " while checking: "; |
| 996 | msg += extension_id; |
| 997 | msg += ".manifest."; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 998 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 999 | msg += " == "; |
| 1000 | msg += expected_val; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1001 | |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1002 | const base::DictionaryValue* dict = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1003 | profile()->GetPrefs()->GetDictionary("extensions.settings"); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1004 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1005 | const base::DictionaryValue* pref = NULL; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1006 | std::string manifest_path = extension_id + ".manifest"; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1007 | ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1008 | EXPECT_TRUE(pref != NULL) << msg; |
| 1009 | std::string val; |
| 1010 | ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; |
| 1011 | EXPECT_EQ(expected_val, val) << msg; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1012 | } |
| 1013 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1014 | void SetPref(const std::string& extension_id, |
| 1015 | const std::string& pref_path, |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1016 | base::Value* value, |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1017 | const std::string& msg) { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1018 | DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings"); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1019 | base::DictionaryValue* dict = update.Get(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1020 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1021 | base::DictionaryValue* pref = NULL; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1022 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| 1023 | EXPECT_TRUE(pref != NULL) << msg; |
| 1024 | pref->Set(pref_path, value); |
| 1025 | } |
| 1026 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1027 | void SetPrefInteg(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1028 | const std::string& pref_path, |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1029 | int value) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1030 | std::string msg = " while setting: "; |
| 1031 | msg += extension_id; |
| 1032 | msg += " "; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1033 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1034 | msg += " = "; |
| 1035 | msg += base::IntToString(value); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1036 | |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 1037 | SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | void SetPrefBool(const std::string& extension_id, |
| 1041 | const std::string& pref_path, |
| 1042 | bool value) { |
| 1043 | std::string msg = " while setting: "; |
| 1044 | msg += extension_id + " " + pref_path; |
| 1045 | msg += " = "; |
| 1046 | msg += (value ? "true" : "false"); |
| 1047 | |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 1048 | SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | void ClearPref(const std::string& extension_id, |
| 1052 | const std::string& pref_path) { |
| 1053 | std::string msg = " while clearing: "; |
| 1054 | msg += extension_id + " " + pref_path; |
| 1055 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1056 | DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings"); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1057 | base::DictionaryValue* dict = update.Get(); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1058 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1059 | base::DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1060 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1061 | EXPECT_TRUE(pref != NULL) << msg; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1062 | pref->Remove(pref_path, NULL); |
| 1063 | } |
| 1064 | |
| 1065 | void SetPrefStringSet(const std::string& extension_id, |
| 1066 | const std::string& pref_path, |
| 1067 | const std::set<std::string>& value) { |
| 1068 | std::string msg = " while setting: "; |
| 1069 | msg += extension_id + " " + pref_path; |
| 1070 | |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1071 | base::ListValue* list_value = new base::ListValue(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1072 | for (std::set<std::string>::const_iterator iter = value.begin(); |
| 1073 | iter != value.end(); ++iter) |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 1074 | list_value->Append(new base::StringValue(*iter)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1075 | |
| 1076 | SetPref(extension_id, pref_path, list_value, msg); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1077 | } |
| 1078 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1079 | void InitPluginService() { |
| 1080 | #if defined(ENABLE_PLUGINS) |
| 1081 | PluginService::GetInstance()->Init(); |
| 1082 | #endif |
| 1083 | } |
| 1084 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1085 | void InitializeExtensionSyncService() { |
| 1086 | extension_sync_service_.reset(new ExtensionSyncService( |
| 1087 | profile(), ExtensionPrefs::Get(browser_context()), service())); |
| 1088 | } |
| 1089 | |
| 1090 | extensions::ManagementPolicy* GetManagementPolicy() { |
| 1091 | return ExtensionSystem::Get(browser_context())->management_policy(); |
| 1092 | } |
| 1093 | |
| 1094 | ExtensionSyncService* extension_sync_service() { |
| 1095 | return extension_sync_service_.get(); |
| 1096 | } |
| 1097 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1098 | protected: |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1099 | scoped_ptr<ExtensionSyncService> extension_sync_service_; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 1100 | extensions::ExtensionList loaded_; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1101 | std::string unloaded_id_; |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 1102 | UnloadedExtensionInfo::Reason unloaded_reason_; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1103 | const Extension* installed_; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1104 | bool was_update_; |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 1105 | std::string old_name_; |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 1106 | FeatureSwitch::ScopedOverride override_external_install_prompt_; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1107 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1108 | private: |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1109 | // Create a CrxInstaller and install the CRX file. |
| 1110 | // Instead of calling this method yourself, use InstallCRX(), which does extra |
| 1111 | // error checking. |
| 1112 | void InstallCRXInternal(const base::FilePath& crx_path) { |
| 1113 | InstallCRXInternal(crx_path, Extension::NO_FLAGS); |
| 1114 | } |
| 1115 | |
| 1116 | void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags) { |
| 1117 | ASSERT_TRUE(base::PathExists(crx_path)) |
| 1118 | << "Path does not exist: "<< crx_path.value().c_str(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1119 | scoped_refptr<CrxInstaller> installer( |
| 1120 | CrxInstaller::CreateSilent(service())); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1121 | installer->set_creation_flags(creation_flags); |
| 1122 | if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) |
| 1123 | installer->set_allow_silent_install(true); |
| 1124 | |
| 1125 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1126 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1127 | content::Source<extensions::CrxInstaller>(installer)); |
| 1128 | |
| 1129 | installer->InstallCrx(crx_path); |
| 1130 | |
| 1131 | observer.Wait(); |
| 1132 | } |
| 1133 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1134 | size_t expected_extensions_count_; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1135 | content::NotificationRegistrar registrar_; |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 1136 | }; |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1137 | |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1138 | // Receives notifications from a PackExtensionJob, indicating either that |
| 1139 | // packing succeeded or that there was some error. |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 1140 | class PackExtensionTestClient : public extensions::PackExtensionJob::Client { |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1141 | public: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1142 | PackExtensionTestClient(const base::FilePath& expected_crx_path, |
| 1143 | const base::FilePath& expected_private_key_path); |
| 1144 | virtual void OnPackSuccess(const base::FilePath& crx_path, |
| 1145 | const base::FilePath& private_key_path) OVERRIDE; |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1146 | virtual void OnPackFailure(const std::string& error_message, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 1147 | ExtensionCreator::ErrorType type) OVERRIDE; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1148 | |
| 1149 | private: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1150 | const base::FilePath expected_crx_path_; |
| 1151 | const base::FilePath expected_private_key_path_; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1152 | DISALLOW_COPY_AND_ASSIGN(PackExtensionTestClient); |
| 1153 | }; |
| 1154 | |
| 1155 | PackExtensionTestClient::PackExtensionTestClient( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1156 | const base::FilePath& expected_crx_path, |
| 1157 | const base::FilePath& expected_private_key_path) |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1158 | : expected_crx_path_(expected_crx_path), |
| 1159 | expected_private_key_path_(expected_private_key_path) {} |
| 1160 | |
| 1161 | // If packing succeeded, we make sure that the package names match our |
| 1162 | // expectations. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1163 | void PackExtensionTestClient::OnPackSuccess( |
| 1164 | const base::FilePath& crx_path, |
| 1165 | const base::FilePath& private_key_path) { |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1166 | // We got the notification and processed it; we don't expect any further tasks |
| 1167 | // to be posted to the current thread, so we should stop blocking and continue |
| 1168 | // on with the rest of the test. |
| 1169 | // This call to |Quit()| matches the call to |Run()| in the |
| 1170 | // |PackPunctuatedExtension| test. |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 1171 | base::MessageLoop::current()->Quit(); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1172 | EXPECT_EQ(expected_crx_path_.value(), crx_path.value()); |
| 1173 | EXPECT_EQ(expected_private_key_path_.value(), private_key_path.value()); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1174 | ASSERT_TRUE(base::PathExists(private_key_path)); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | // The tests are designed so that we never expect to see a packing error. |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1178 | void PackExtensionTestClient::OnPackFailure(const std::string& error_message, |
| 1179 | ExtensionCreator::ErrorType type) { |
| 1180 | if (type == ExtensionCreator::kCRXExists) |
| 1181 | FAIL() << "Packing should not fail."; |
| 1182 | else |
| 1183 | FAIL() << "Existing CRX should have been overwritten."; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1184 | } |
| 1185 | |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1186 | // Test loading good extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1187 | TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1188 | InitPluginService(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1189 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1190 | service()->Init(); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1191 | |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1192 | uint32 expected_num_extensions = 3u; |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1193 | ASSERT_EQ(expected_num_extensions, loaded_.size()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1194 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 1195 | EXPECT_EQ(std::string(good0), loaded_[0]->id()); |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 1196 | EXPECT_EQ(std::string("My extension 1"), |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1197 | loaded_[0]->name()); |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 1198 | EXPECT_EQ(std::string("The first extension that I made."), |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1199 | loaded_[0]->description()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1200 | EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1201 | EXPECT_TRUE(service()->GetExtensionById(loaded_[0]->id(), false)); |
| 1202 | EXPECT_EQ(expected_num_extensions, registry()->enabled_extensions().size()); |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 1203 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1204 | ValidatePrefKeyCount(3); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1205 | ValidateIntegerPref(good0, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1206 | ValidateIntegerPref(good0, "location", Manifest::INTERNAL); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1207 | ValidateIntegerPref(good1, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1208 | ValidateIntegerPref(good1, "location", Manifest::INTERNAL); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1209 | ValidateIntegerPref(good2, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1210 | ValidateIntegerPref(good2, "location", Manifest::INTERNAL); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1211 | |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1212 | URLPatternSet expected_patterns; |
| 1213 | AddPattern(&expected_patterns, "file:///*"); |
| 1214 | AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 1215 | AddPattern(&expected_patterns, "https://*.google.com/*"); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1216 | const Extension* extension = loaded_[0].get(); |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 1217 | const extensions::UserScriptList& scripts = |
| 1218 | extensions::ContentScriptsInfo::GetContentScripts(extension); |
[email protected] | e66de89 | 2009-03-20 20:38:43 | [diff] [blame] | 1219 | ASSERT_EQ(2u, scripts.size()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1220 | EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); |
[email protected] | e66de89 | 2009-03-20 20:38:43 | [diff] [blame] | 1221 | EXPECT_EQ(2u, scripts[0].js_scripts().size()); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 1222 | ExtensionResource resource00(extension->id(), |
| 1223 | scripts[0].js_scripts()[0].extension_root(), |
[email protected] | 9194b3f | 2009-10-20 15:27:21 | [diff] [blame] | 1224 | scripts[0].js_scripts()[0].relative_path()); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 1225 | base::FilePath expected_path = |
| 1226 | base::MakeAbsoluteFilePath(extension->path().AppendASCII("script1.js")); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1227 | EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 1228 | ExtensionResource resource01(extension->id(), |
| 1229 | scripts[0].js_scripts()[1].extension_root(), |
[email protected] | 9194b3f | 2009-10-20 15:27:21 | [diff] [blame] | 1230 | scripts[0].js_scripts()[1].relative_path()); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 1231 | expected_path = |
| 1232 | base::MakeAbsoluteFilePath(extension->path().AppendASCII("script2.js")); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1233 | EXPECT_TRUE(resource01.ComparePathWithDefault(expected_path)); |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1234 | EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(extension)); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1235 | EXPECT_EQ(1u, scripts[1].url_patterns().patterns().size()); |
| 1236 | EXPECT_EQ("http://*.news.com/*", |
| 1237 | scripts[1].url_patterns().begin()->GetAsString()); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 1238 | ExtensionResource resource10(extension->id(), |
| 1239 | scripts[1].js_scripts()[0].extension_root(), |
[email protected] | 9194b3f | 2009-10-20 15:27:21 | [diff] [blame] | 1240 | scripts[1].js_scripts()[0].relative_path()); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1241 | expected_path = |
| 1242 | extension->path().AppendASCII("js_files").AppendASCII("script3.js"); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 1243 | expected_path = base::MakeAbsoluteFilePath(expected_path); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1244 | EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1245 | |
| 1246 | expected_patterns.ClearPatterns(); |
| 1247 | AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 1248 | AddPattern(&expected_patterns, "https://*.google.com/*"); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 1249 | EXPECT_EQ( |
| 1250 | expected_patterns, |
| 1251 | extension->permissions_data()->active_permissions()->explicit_hosts()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1252 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1253 | EXPECT_EQ(std::string(good1), loaded_[1]->id()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1254 | EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 1255 | EXPECT_EQ(std::string(), loaded_[1]->description()); |
[email protected] | 81067e0 | 2009-07-27 15:12:09 | [diff] [blame] | 1256 | EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1257 | extensions::BackgroundInfo::GetBackgroundURL(loaded_[1].get())); |
| 1258 | EXPECT_EQ(0u, |
| 1259 | extensions::ContentScriptsInfo::GetContentScripts(loaded_[1].get()) |
| 1260 | .size()); |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1261 | |
[email protected] | b8fb303 | 2011-04-29 18:45:56 | [diff] [blame] | 1262 | // We don't parse the plugins section on Chrome OS. |
| 1263 | #if defined(OS_CHROMEOS) |
[email protected] | 144b6c4 | 2013-06-14 07:30:38 | [diff] [blame] | 1264 | EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(loaded_[1].get())); |
[email protected] | b8fb303 | 2011-04-29 18:45:56 | [diff] [blame] | 1265 | #else |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1266 | ASSERT_TRUE(extensions::PluginInfo::HasPlugins(loaded_[1].get())); |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1267 | const std::vector<extensions::PluginInfo>* plugins = |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1268 | extensions::PluginInfo::GetPlugins(loaded_[1].get()); |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1269 | ASSERT_TRUE(plugins); |
| 1270 | ASSERT_EQ(2u, plugins->size()); |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 1271 | EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1272 | plugins->at(0).path.value()); |
| 1273 | EXPECT_TRUE(plugins->at(0).is_public); |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 1274 | EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1275 | plugins->at(1).path.value()); |
| 1276 | EXPECT_FALSE(plugins->at(1).is_public); |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1277 | #endif |
[email protected] | 18a1235 | 2009-01-31 01:33:28 | [diff] [blame] | 1278 | |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1279 | EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location()); |
[email protected] | b8fb303 | 2011-04-29 18:45:56 | [diff] [blame] | 1280 | |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1281 | int index = expected_num_extensions - 1; |
| 1282 | EXPECT_EQ(std::string(good2), loaded_[index]->id()); |
| 1283 | EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 1284 | EXPECT_EQ(std::string(), loaded_[index]->description()); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1285 | EXPECT_EQ(0u, |
| 1286 | extensions::ContentScriptsInfo::GetContentScripts( |
| 1287 | loaded_[index].get()).size()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1288 | EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1289 | }; |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1290 | |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1291 | // Test loading bad extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1292 | TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1293 | // Initialize the test dir with a bad Preferences/extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1294 | base::FilePath source_install_dir = |
| 1295 | data_dir().AppendASCII("bad").AppendASCII("Extensions"); |
[email protected] | e96a060 | 2014-02-15 08:27:42 | [diff] [blame] | 1296 | base::FilePath pref_path = |
| 1297 | source_install_dir.DirName().Append(chrome::kPreferencesFilename); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1298 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1299 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1300 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1301 | service()->Init(); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1302 | |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1303 | ASSERT_EQ(4u, GetErrors().size()); |
| 1304 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1305 | |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1306 | EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[0]), |
[email protected] | d7b36dc | 2009-10-29 21:47:40 | [diff] [blame] | 1307 | std::string("Could not load extension from '*'. ") + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 1308 | extensions::manifest_errors::kManifestUnreadable)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1309 | base::UTF16ToUTF8(GetErrors()[0]); |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1310 | |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1311 | EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[1]), |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1312 | std::string("Could not load extension from '*'. ") + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 1313 | extensions::manifest_errors::kManifestUnreadable)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1314 | base::UTF16ToUTF8(GetErrors()[1]); |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1315 | |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1316 | EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[2]), |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1317 | std::string("Could not load extension from '*'. ") + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 1318 | extensions::manifest_errors::kMissingFile)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1319 | base::UTF16ToUTF8(GetErrors()[2]); |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1320 | |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1321 | EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[3]), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1322 | std::string("Could not load extension from '*'. ") + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 1323 | extensions::manifest_errors::kManifestUnreadable)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1324 | base::UTF16ToUTF8(GetErrors()[3]); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1325 | }; |
| 1326 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1327 | // Test various cases for delayed install because of missing imports. |
| 1328 | TEST_F(ExtensionServiceTest, PendingImports) { |
| 1329 | InitPluginService(); |
| 1330 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1331 | base::FilePath source_install_dir = |
| 1332 | data_dir().AppendASCII("pending_updates_with_imports").AppendASCII( |
| 1333 | "Extensions"); |
[email protected] | e96a060 | 2014-02-15 08:27:42 | [diff] [blame] | 1334 | base::FilePath pref_path = |
| 1335 | source_install_dir.DirName().Append(chrome::kPreferencesFilename); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1336 | |
| 1337 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1338 | |
| 1339 | // Verify there are no pending extensions initially. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1340 | EXPECT_FALSE(service()->pending_extension_manager()->HasPendingExtensions()); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1341 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1342 | service()->Init(); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1343 | // Wait for GarbageCollectExtensions task to complete. |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1344 | base::RunLoop().RunUntilIdle(); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1345 | |
| 1346 | // These extensions are used by the extensions we test below, they must be |
| 1347 | // installed. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1348 | EXPECT_TRUE(base::PathExists(extensions_install_dir().AppendASCII( |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1349 | "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1350 | EXPECT_TRUE(base::PathExists(extensions_install_dir().AppendASCII( |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1351 | "hpiknbiabeeppbpihjehijgoemciehgk/2"))); |
| 1352 | |
| 1353 | // Each of these extensions should have been rejected because of dependencies |
| 1354 | // that cannot be satisfied. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1355 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1356 | EXPECT_FALSE( |
| 1357 | prefs->GetDelayedInstallInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); |
| 1358 | EXPECT_FALSE( |
| 1359 | prefs->GetInstalledExtensionInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); |
| 1360 | EXPECT_FALSE( |
| 1361 | prefs->GetDelayedInstallInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); |
| 1362 | EXPECT_FALSE( |
| 1363 | prefs->GetInstalledExtensionInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); |
| 1364 | EXPECT_FALSE( |
| 1365 | prefs->GetDelayedInstallInfo("cccccccccccccccccccccccccccccccc")); |
| 1366 | EXPECT_FALSE( |
| 1367 | prefs->GetInstalledExtensionInfo("cccccccccccccccccccccccccccccccc")); |
| 1368 | |
| 1369 | // Make sure the import started for the extension with a dependency. |
| 1370 | EXPECT_TRUE( |
| 1371 | prefs->GetDelayedInstallInfo("behllobkkfkfnphdnhnkndlbkcpglgmj")); |
| 1372 | EXPECT_EQ(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, |
| 1373 | prefs->GetDelayedInstallReason("behllobkkfkfnphdnhnkndlbkcpglgmj")); |
| 1374 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1375 | EXPECT_FALSE(base::PathExists(extensions_install_dir().AppendASCII( |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1376 | "behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0"))); |
| 1377 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1378 | EXPECT_TRUE(service()->pending_extension_manager()->HasPendingExtensions()); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1379 | std::string pending_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1380 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(pending_id)); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1381 | // Remove it because we are not testing the pending extension manager's |
| 1382 | // ability to download and install extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1383 | EXPECT_TRUE(service()->pending_extension_manager()->Remove(pending_id)); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1384 | } |
| 1385 | |
[email protected] | d7eaf57 | 2009-07-01 21:57:00 | [diff] [blame] | 1386 | // Test installing extensions. This test tries to install few extensions using |
| 1387 | // crx files. If you need to change those crx files, feel free to repackage |
| 1388 | // them, throw away the key used and change the id's above. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1389 | TEST_F(ExtensionServiceTest, InstallExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1390 | InitializeEmptyExtensionService(); |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1391 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1392 | // Extensions not enabled. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1393 | service()->set_extensions_enabled(false); |
| 1394 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1395 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1396 | service()->set_extensions_enabled(true); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1397 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1398 | ValidatePrefKeyCount(0); |
| 1399 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1400 | // A simple extension that should install without error. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1401 | path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1402 | InstallCRX(path, INSTALL_NEW); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1403 | // TODO(erikkay): verify the contents of the installed extension. |
| 1404 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1405 | int pref_count = 0; |
| 1406 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1407 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1408 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1409 | |
[email protected] | 902f7cd | 2009-05-22 19:02:19 | [diff] [blame] | 1410 | // An extension with page actions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1411 | path = data_dir().AppendASCII("page_action.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1412 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1413 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1414 | ValidateIntegerPref(page_action, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1415 | ValidateIntegerPref(page_action, "location", Manifest::INTERNAL); |
[email protected] | 902f7cd | 2009-05-22 19:02:19 | [diff] [blame] | 1416 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1417 | // Bad signature. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1418 | path = data_dir().AppendASCII("bad_signature.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1419 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | d7eaf57 | 2009-07-01 21:57:00 | [diff] [blame] | 1420 | ValidatePrefKeyCount(pref_count); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 1421 | |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1422 | // 0-length extension file. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1423 | path = data_dir().AppendASCII("not_an_extension.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1424 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1425 | ValidatePrefKeyCount(pref_count); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1426 | |
| 1427 | // Bad magic number. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1428 | path = data_dir().AppendASCII("bad_magic.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1429 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1430 | ValidatePrefKeyCount(pref_count); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1431 | |
[email protected] | 622813ee0 | 2013-08-21 21:00:29 | [diff] [blame] | 1432 | // Packed extensions may have folders or files that have underscores. |
| 1433 | // This will only cause a warning, rather than a fatal error. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1434 | path = data_dir().AppendASCII("bad_underscore.crx"); |
[email protected] | 622813ee0 | 2013-08-21 21:00:29 | [diff] [blame] | 1435 | InstallCRX(path, INSTALL_NEW); |
| 1436 | ValidatePrefKeyCount(++pref_count); |
[email protected] | 99872e3 | 2009-09-25 22:02:49 | [diff] [blame] | 1437 | |
[email protected] | 5fda9194 | 2013-09-24 06:47:53 | [diff] [blame] | 1438 | // A test for an extension with a 2048-bit public key. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1439 | path = data_dir().AppendASCII("good2048.crx"); |
[email protected] | 5fda9194 | 2013-09-24 06:47:53 | [diff] [blame] | 1440 | InstallCRX(path, INSTALL_NEW); |
| 1441 | ValidatePrefKeyCount(++pref_count); |
| 1442 | ValidateIntegerPref(good2048, "state", Extension::ENABLED); |
| 1443 | ValidateIntegerPref(good2048, "location", Manifest::INTERNAL); |
| 1444 | |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1445 | // TODO(erikkay): add more tests for many of the failure cases. |
| 1446 | // TODO(erikkay): add tests for upgrade cases. |
| 1447 | } |
| 1448 | |
[email protected] | b8e45df | 2014-06-11 19:32:36 | [diff] [blame] | 1449 | struct MockExtensionRegistryObserver |
| 1450 | : public extensions::ExtensionRegistryObserver { |
| 1451 | virtual void OnExtensionWillBeInstalled( |
| 1452 | content::BrowserContext* browser_context, |
| 1453 | const Extension* extension, |
| 1454 | bool is_update, |
| 1455 | bool from_ephemeral, |
| 1456 | const std::string& old_name) OVERRIDE { |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1457 | last_extension_installed = extension->id(); |
| 1458 | } |
| 1459 | |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 1460 | virtual void OnExtensionUninstalled( |
| 1461 | content::BrowserContext* browser_context, |
| 1462 | const Extension* extension, |
| 1463 | extensions::UninstallReason reason) OVERRIDE { |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1464 | last_extension_uninstalled = extension->id(); |
| 1465 | } |
| 1466 | |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1467 | std::string last_extension_installed; |
| 1468 | std::string last_extension_uninstalled; |
| 1469 | }; |
| 1470 | |
[email protected] | b8e45df | 2014-06-11 19:32:36 | [diff] [blame] | 1471 | // Test that correct notifications are sent to ExtensionRegistryObserver on |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1472 | // extension install and uninstall. |
| 1473 | TEST_F(ExtensionServiceTest, InstallObserverNotified) { |
| 1474 | InitializeEmptyExtensionService(); |
| 1475 | |
[email protected] | b8e45df | 2014-06-11 19:32:36 | [diff] [blame] | 1476 | extensions::ExtensionRegistry* registry( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1477 | extensions::ExtensionRegistry::Get(profile())); |
[email protected] | b8e45df | 2014-06-11 19:32:36 | [diff] [blame] | 1478 | MockExtensionRegistryObserver observer; |
| 1479 | registry->AddObserver(&observer); |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1480 | |
| 1481 | // A simple extension that should install without error. |
| 1482 | ASSERT_TRUE(observer.last_extension_installed.empty()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1483 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1484 | InstallCRX(path, INSTALL_NEW); |
| 1485 | ASSERT_EQ(good_crx, observer.last_extension_installed); |
| 1486 | |
| 1487 | // Uninstall the extension. |
| 1488 | ASSERT_TRUE(observer.last_extension_uninstalled.empty()); |
| 1489 | UninstallExtension(good_crx, false); |
| 1490 | ASSERT_EQ(good_crx, observer.last_extension_uninstalled); |
| 1491 | |
[email protected] | b8e45df | 2014-06-11 19:32:36 | [diff] [blame] | 1492 | registry->RemoveObserver(&observer); |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1493 | } |
| 1494 | |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1495 | // Tests that flags passed to OnExternalExtensionFileFound() make it to the |
| 1496 | // extension object. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1497 | TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1498 | const char kPrefFromBookmark[] = "from_bookmark"; |
| 1499 | |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1500 | InitializeEmptyExtensionService(); |
| 1501 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1502 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1503 | service()->set_extensions_enabled(true); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1504 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1505 | // Register and install an external extension. |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1506 | Version version("1.0.0.0"); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1507 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1508 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1509 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1510 | if (service()->OnExternalExtensionFileFound(good_crx, |
| 1511 | &version, |
| 1512 | path, |
| 1513 | Manifest::EXTERNAL_PREF, |
| 1514 | Extension::FROM_BOOKMARK, |
| 1515 | false /* mark_acknowledged */)) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1516 | observer.Wait(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1517 | } |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1518 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1519 | const Extension* extension = service()->GetExtensionById(good_crx, false); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1520 | ASSERT_TRUE(extension); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1521 | ASSERT_TRUE(extension->from_bookmark()); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1522 | ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1523 | |
| 1524 | // Upgrade to version 2.0, the flag should be preserved. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1525 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1526 | UpdateExtension(good_crx, path, ENABLED); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1527 | ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1528 | extension = service()->GetExtensionById(good_crx, false); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1529 | ASSERT_TRUE(extension); |
| 1530 | ASSERT_TRUE(extension->from_bookmark()); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1531 | } |
| 1532 | |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1533 | // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1534 | TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1535 | InitializeEmptyExtensionService(); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1536 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1537 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1538 | service()->set_extensions_enabled(true); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1539 | |
| 1540 | // Install an external extension. |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1541 | Version version("1.0.0.0"); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1542 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1543 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1544 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1545 | if (service()->OnExternalExtensionFileFound(good_crx, |
| 1546 | &version, |
| 1547 | path, |
| 1548 | Manifest::EXTERNAL_PREF, |
| 1549 | Extension::NO_FLAGS, |
| 1550 | false)) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1551 | observer.Wait(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1552 | } |
| 1553 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1554 | ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1555 | |
| 1556 | // Uninstall it and check that its killbit gets set. |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1557 | UninstallExtension(good_crx, false); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1558 | ValidateIntegerPref(good_crx, "location", |
| 1559 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1560 | |
| 1561 | // Try to re-install it externally. This should fail because of the killbit. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1562 | service()->OnExternalExtensionFileFound(good_crx, |
| 1563 | &version, |
| 1564 | path, |
| 1565 | Manifest::EXTERNAL_PREF, |
| 1566 | Extension::NO_FLAGS, |
| 1567 | false); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1568 | base::RunLoop().RunUntilIdle(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1569 | ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1570 | ValidateIntegerPref(good_crx, "location", |
| 1571 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1572 | |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1573 | version = Version("1.0.0.1"); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1574 | // Repeat the same thing with a newer version of the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1575 | path = data_dir().AppendASCII("good2.crx"); |
| 1576 | service()->OnExternalExtensionFileFound(good_crx, |
| 1577 | &version, |
| 1578 | path, |
| 1579 | Manifest::EXTERNAL_PREF, |
| 1580 | Extension::NO_FLAGS, |
| 1581 | false); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1582 | base::RunLoop().RunUntilIdle(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1583 | ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1584 | ValidateIntegerPref(good_crx, "location", |
| 1585 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1586 | |
| 1587 | // Try adding the same extension from an external update URL. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1588 | ASSERT_FALSE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1589 | good_crx, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1590 | std::string(), |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1591 | GURL("http:://fake.update/url"), |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 1592 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 1593 | Extension::NO_FLAGS, |
| 1594 | false)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 1595 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1596 | ASSERT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx)); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1597 | } |
| 1598 | |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1599 | // Test that uninstalling an external extension does not crash when |
| 1600 | // the extension could not be loaded. |
| 1601 | // This extension shown in preferences file requires an experimental permission. |
| 1602 | // It could not be loaded without such permission. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1603 | TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1604 | base::FilePath source_install_dir = |
| 1605 | data_dir().AppendASCII("good").AppendASCII("Extensions"); |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1606 | // The preference contains an external extension |
| 1607 | // that requires 'experimental' permission. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1608 | base::FilePath pref_path = source_install_dir |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1609 | .DirName() |
| 1610 | .AppendASCII("PreferencesExperimental"); |
| 1611 | |
| 1612 | // Aforementioned extension will not be loaded if |
| 1613 | // there is no '--enable-experimental-extension-apis' command line flag. |
| 1614 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1615 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1616 | service()->Init(); |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1617 | |
| 1618 | // Check and try to uninstall it. |
| 1619 | // If we don't check whether the extension is loaded before we uninstall it |
| 1620 | // in CheckExternalUninstall, a crash will happen here because we will get or |
| 1621 | // dereference a NULL pointer (extension) inside UninstallExtension. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1622 | MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1623 | service()->OnExternalProviderReady(&provider); |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1624 | } |
| 1625 | |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1626 | // Test that external extensions with incorrect IDs are not installed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1627 | TEST_F(ExtensionServiceTest, FailOnWrongId) { |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1628 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1629 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1630 | service()->set_extensions_enabled(true); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1631 | |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1632 | Version version("1.0.0.0"); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1633 | |
| 1634 | const std::string wrong_id = all_zero; |
| 1635 | const std::string correct_id = good_crx; |
| 1636 | ASSERT_NE(correct_id, wrong_id); |
| 1637 | |
| 1638 | // Install an external extension with an ID from the external |
| 1639 | // source that is not equal to the ID in the extension manifest. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1640 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1641 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1642 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1643 | service()->OnExternalExtensionFileFound(wrong_id, |
| 1644 | &version, |
| 1645 | path, |
| 1646 | Manifest::EXTERNAL_PREF, |
| 1647 | Extension::NO_FLAGS, |
| 1648 | false); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1649 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1650 | observer.Wait(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1651 | ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1652 | |
| 1653 | // Try again with the right ID. Expect success. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1654 | content::WindowedNotificationObserver observer2( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1655 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1656 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1657 | if (service()->OnExternalExtensionFileFound(correct_id, |
| 1658 | &version, |
| 1659 | path, |
| 1660 | Manifest::EXTERNAL_PREF, |
| 1661 | Extension::NO_FLAGS, |
| 1662 | false)) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1663 | observer2.Wait(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1664 | } |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1665 | ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | // Test that external extensions with incorrect versions are not installed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1669 | TEST_F(ExtensionServiceTest, FailOnWrongVersion) { |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1670 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1671 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1672 | service()->set_extensions_enabled(true); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1673 | |
| 1674 | // Install an external extension with a version from the external |
| 1675 | // source that is not equal to the version in the extension manifest. |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1676 | Version wrong_version("1.2.3.4"); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1677 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1678 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1679 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1680 | service()->OnExternalExtensionFileFound(good_crx, |
| 1681 | &wrong_version, |
| 1682 | path, |
| 1683 | Manifest::EXTERNAL_PREF, |
| 1684 | Extension::NO_FLAGS, |
| 1685 | false); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1686 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1687 | observer.Wait(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1688 | ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1689 | |
| 1690 | // Try again with the right version. Expect success. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1691 | service()->pending_extension_manager()->Remove(good_crx); |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1692 | Version correct_version("1.0.0.0"); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1693 | content::WindowedNotificationObserver observer2( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 1694 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1695 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1696 | if (service()->OnExternalExtensionFileFound(good_crx, |
| 1697 | &correct_version, |
| 1698 | path, |
| 1699 | Manifest::EXTERNAL_PREF, |
| 1700 | Extension::NO_FLAGS, |
| 1701 | false)) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1702 | observer2.Wait(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1703 | } |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1704 | ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1705 | } |
| 1706 | |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1707 | // Install a user script (they get converted automatically to an extension) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1708 | TEST_F(ExtensionServiceTest, InstallUserScript) { |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1709 | // The details of script conversion are tested elsewhere, this just tests |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1710 | // integration with ExtensionService. |
| 1711 | InitializeEmptyExtensionService(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1712 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1713 | base::FilePath path = data_dir().AppendASCII("user_script_basic.user.js"); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1714 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1715 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1716 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service())); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1717 | installer->set_allow_silent_install(true); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 1718 | installer->InstallUserScript( |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1719 | path, |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 1720 | GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1721 | |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1722 | base::RunLoop().RunUntilIdle(); |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 1723 | std::vector<base::string16> errors = GetErrors(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1724 | EXPECT_TRUE(installed_) << "Nothing was installed."; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1725 | EXPECT_FALSE(was_update_) << path.value(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1726 | ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; |
| 1727 | EXPECT_EQ(0u, errors.size()) << "There were errors: " |
| 1728 | << JoinString(errors, ','); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1729 | EXPECT_TRUE(service()->GetExtensionById(loaded_[0]->id(), false)) |
| 1730 | << path.value(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1731 | |
| 1732 | installed_ = NULL; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1733 | was_update_ = false; |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1734 | loaded_.clear(); |
| 1735 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| 1736 | } |
| 1737 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1738 | // Extensions don't install during shutdown. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1739 | TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1740 | InitializeEmptyExtensionService(); |
| 1741 | |
| 1742 | // Simulate shutdown. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1743 | service()->set_browser_terminating_for_test(true); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1744 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1745 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1746 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service())); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1747 | installer->set_allow_silent_install(true); |
| 1748 | installer->InstallCrx(path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1749 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1750 | |
| 1751 | EXPECT_FALSE(installed_) << "Extension installed during shutdown."; |
| 1752 | ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown."; |
| 1753 | } |
| 1754 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1755 | // This tests that the granted permissions preferences are correctly set when |
| 1756 | // installing an extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1757 | TEST_F(ExtensionServiceTest, GrantedPermissions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1758 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1759 | base::FilePath path = data_dir().AppendASCII("permissions"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1760 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1761 | base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1762 | path = path.AppendASCII("unknown"); |
| 1763 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1764 | ASSERT_TRUE(base::PathExists(pem_path)); |
| 1765 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1766 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1767 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1768 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1769 | APIPermissionSet expected_api_perms; |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 1770 | URLPatternSet expected_host_perms; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1771 | |
| 1772 | // Make sure there aren't any granted permissions before the |
| 1773 | // extension is installed. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1774 | scoped_refptr<PermissionSet> known_perms( |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1775 | prefs->GetGrantedPermissions(permissions_crx)); |
| 1776 | EXPECT_FALSE(known_perms.get()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1777 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1778 | const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1779 | |
| 1780 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1781 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1782 | EXPECT_EQ(permissions_crx, extension->id()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1783 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1784 | // Verify that the valid API permissions have been recognized. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1785 | expected_api_perms.insert(APIPermission::kTab); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1786 | |
| 1787 | AddPattern(&expected_host_perms, "http://*.google.com/*"); |
| 1788 | AddPattern(&expected_host_perms, "https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 1789 | AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1790 | AddPattern(&expected_host_perms, "http://www.example.com/*"); |
| 1791 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1792 | known_perms = prefs->GetGrantedPermissions(extension->id()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1793 | EXPECT_TRUE(known_perms.get()); |
| 1794 | EXPECT_FALSE(known_perms->IsEmpty()); |
| 1795 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1796 | EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1797 | EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1798 | } |
| 1799 | |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1800 | |
| 1801 | #if !defined(OS_CHROMEOS) |
| 1802 | // This tests that the granted permissions preferences are correctly set for |
| 1803 | // default apps. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1804 | TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1805 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1806 | base::FilePath path = data_dir().AppendASCII("permissions"); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1807 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1808 | base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1809 | path = path.AppendASCII("unknown"); |
| 1810 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1811 | ASSERT_TRUE(base::PathExists(pem_path)); |
| 1812 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1813 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1814 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1815 | |
| 1816 | APIPermissionSet expected_api_perms; |
| 1817 | URLPatternSet expected_host_perms; |
| 1818 | |
| 1819 | // Make sure there aren't any granted permissions before the |
| 1820 | // extension is installed. |
| 1821 | scoped_refptr<PermissionSet> known_perms( |
| 1822 | prefs->GetGrantedPermissions(permissions_crx)); |
| 1823 | EXPECT_FALSE(known_perms.get()); |
| 1824 | |
| 1825 | const Extension* extension = PackAndInstallCRX( |
| 1826 | path, pem_path, INSTALL_NEW, Extension::WAS_INSTALLED_BY_DEFAULT); |
| 1827 | |
| 1828 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1829 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1830 | EXPECT_EQ(permissions_crx, extension->id()); |
| 1831 | |
| 1832 | // Verify that the valid API permissions have been recognized. |
| 1833 | expected_api_perms.insert(APIPermission::kTab); |
| 1834 | |
| 1835 | known_perms = prefs->GetGrantedPermissions(extension->id()); |
| 1836 | EXPECT_TRUE(known_perms.get()); |
| 1837 | EXPECT_FALSE(known_perms->IsEmpty()); |
| 1838 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1839 | EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
| 1840 | } |
| 1841 | #endif |
| 1842 | |
[email protected] | 77724b60 | 2014-05-14 11:36:12 | [diff] [blame] | 1843 | #if !defined(OS_POSIX) || defined(OS_MACOSX) |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1844 | // Tests that the granted permissions full_access bit gets set correctly when |
[email protected] | 77724b60 | 2014-05-14 11:36:12 | [diff] [blame] | 1845 | // an extension contains an NPAPI plugin. |
| 1846 | // Only run this on platforms that support NPAPI plugins. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1847 | TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1848 | InitPluginService(); |
[email protected] | 183d4b8 | 2011-11-11 18:50:26 | [diff] [blame] | 1849 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1850 | InitializeEmptyExtensionService(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1851 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1852 | ASSERT_TRUE(base::PathExists(good1_path())); |
| 1853 | const Extension* extension = PackAndInstallCRX(good1_path(), INSTALL_NEW); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1854 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1855 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 1856 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1857 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1858 | scoped_refptr<PermissionSet> permissions( |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1859 | prefs->GetGrantedPermissions(extension->id())); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1860 | EXPECT_FALSE(permissions->IsEmpty()); |
| 1861 | EXPECT_TRUE(permissions->HasEffectiveFullAccess()); |
| 1862 | EXPECT_FALSE(permissions->apis().empty()); |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1863 | EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1864 | |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1865 | // Full access implies full host access too... |
| 1866 | EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1867 | } |
| 1868 | #endif |
| 1869 | |
| 1870 | // Tests that the extension is disabled when permissions are missing from |
| 1871 | // the extension's granted permissions preferences. (This simulates updating |
| 1872 | // the browser to a version which recognizes more permissions). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1873 | TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1874 | InitializeEmptyExtensionService(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1875 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1876 | base::FilePath path = |
| 1877 | data_dir().AppendASCII("permissions").AppendASCII("unknown"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1878 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1879 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1880 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1881 | const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1882 | |
| 1883 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1884 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1885 | std::string extension_id = extension->id(); |
| 1886 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1887 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1888 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1889 | APIPermissionSet expected_api_permissions; |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 1890 | URLPatternSet expected_host_permissions; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1891 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1892 | expected_api_permissions.insert(APIPermission::kTab); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1893 | AddPattern(&expected_host_permissions, "http://*.google.com/*"); |
| 1894 | AddPattern(&expected_host_permissions, "https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 1895 | AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1896 | AddPattern(&expected_host_permissions, "http://www.example.com/*"); |
| 1897 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1898 | std::set<std::string> host_permissions; |
| 1899 | |
| 1900 | // Test that the extension is disabled when an API permission is missing from |
| 1901 | // the extension's granted api permissions preference. (This simulates |
| 1902 | // updating the browser to a version which recognizes a new API permission). |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1903 | SetPref(extension_id, "granted_permissions.api", |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1904 | new base::ListValue(), "granted_permissions.api"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1905 | service()->ReloadExtensionsForTest(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1906 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1907 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 1908 | extension = registry()->disabled_extensions().begin()->get(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1909 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1910 | ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1911 | ASSERT_FALSE(service()->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1912 | ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1913 | |
| 1914 | // Now grant and re-enable the extension, making sure the prefs are updated. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1915 | service()->GrantPermissionsAndEnableExtension(extension); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1916 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1917 | ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1918 | ASSERT_TRUE(service()->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1919 | ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1920 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1921 | scoped_refptr<PermissionSet> current_perms( |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1922 | prefs->GetGrantedPermissions(extension_id)); |
| 1923 | ASSERT_TRUE(current_perms.get()); |
| 1924 | ASSERT_FALSE(current_perms->IsEmpty()); |
| 1925 | ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); |
| 1926 | ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1927 | ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1928 | |
| 1929 | // Tests that the extension is disabled when a host permission is missing from |
| 1930 | // the extension's granted host permissions preference. (This simulates |
| 1931 | // updating the browser to a version which recognizes additional host |
| 1932 | // permissions). |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1933 | host_permissions.clear(); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1934 | current_perms = NULL; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1935 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1936 | host_permissions.insert("http://*.google.com/*"); |
| 1937 | host_permissions.insert("https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 1938 | host_permissions.insert("http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1939 | |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1940 | base::ListValue* api_permissions = new base::ListValue(); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1941 | api_permissions->Append( |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 1942 | new base::StringValue("tabs")); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1943 | SetPref(extension_id, "granted_permissions.api", |
| 1944 | api_permissions, "granted_permissions.api"); |
| 1945 | SetPrefStringSet( |
| 1946 | extension_id, "granted_permissions.scriptable_host", host_permissions); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1947 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1948 | service()->ReloadExtensionsForTest(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1949 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1950 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 1951 | extension = registry()->disabled_extensions().begin()->get(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1952 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1953 | ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1954 | ASSERT_FALSE(service()->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1955 | ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1956 | |
| 1957 | // Now grant and re-enable the extension, making sure the prefs are updated. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1958 | service()->GrantPermissionsAndEnableExtension(extension); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1959 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1960 | ASSERT_TRUE(service()->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1961 | ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1962 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1963 | current_perms = prefs->GetGrantedPermissions(extension_id); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1964 | ASSERT_TRUE(current_perms.get()); |
| 1965 | ASSERT_FALSE(current_perms->IsEmpty()); |
| 1966 | ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); |
| 1967 | ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1968 | ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1969 | } |
| 1970 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1971 | // Test Packaging and installing an extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1972 | TEST_F(ExtensionServiceTest, PackExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1973 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1974 | base::FilePath input_directory = |
| 1975 | data_dir() |
| 1976 | .AppendASCII("good") |
| 1977 | .AppendASCII("Extensions") |
| 1978 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 1979 | .AppendASCII("1.0.0.0"); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1980 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 1981 | base::ScopedTempDir temp_dir; |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 1982 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1983 | base::FilePath output_directory = temp_dir.path(); |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 1984 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1985 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 1986 | base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1987 | |
| 1988 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1989 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1990 | privkey_path, ExtensionCreator::kNoRunFlags)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1991 | ASSERT_TRUE(base::PathExists(crx_path)); |
| 1992 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1993 | |
| 1994 | // Repeat the run with the pem file gone, and no special flags |
| 1995 | // Should refuse to overwrite the existing crx. |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 1996 | base::DeleteFile(privkey_path, false); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1997 | ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1998 | privkey_path, ExtensionCreator::kNoRunFlags)); |
| 1999 | |
| 2000 | // OK, now try it with a flag to overwrite existing crx. Should work. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2001 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 2002 | privkey_path, ExtensionCreator::kOverwriteCRX)); |
| 2003 | |
| 2004 | // Repeat the run allowing existing crx, but the existing pem is still |
| 2005 | // an error. Should fail. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2006 | ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 2007 | privkey_path, ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2008 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2009 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2010 | InstallCRX(crx_path, INSTALL_NEW); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 2011 | |
| 2012 | // Try packing with invalid paths. |
| 2013 | creator.reset(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2014 | ASSERT_FALSE( |
| 2015 | creator->Run(base::FilePath(), base::FilePath(), base::FilePath(), |
| 2016 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 2017 | |
| 2018 | // Try packing an empty directory. Should fail because an empty directory is |
| 2019 | // not a valid extension. |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2020 | base::ScopedTempDir temp_dir2; |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 2021 | ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
| 2022 | creator.reset(new ExtensionCreator()); |
| 2023 | ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2024 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 2025 | |
| 2026 | // Try packing with an invalid manifest. |
| 2027 | std::string invalid_manifest_content = "I am not a manifest."; |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 2028 | ASSERT_TRUE(base::WriteFile( |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2029 | temp_dir2.path().Append(extensions::kManifestFilename), |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 2030 | invalid_manifest_content.c_str(), invalid_manifest_content.size())); |
| 2031 | creator.reset(new ExtensionCreator()); |
| 2032 | ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2033 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | c21b5b61 | 2013-07-31 07:49:16 | [diff] [blame] | 2034 | |
| 2035 | // Try packing with a private key that is a valid key, but invalid for the |
| 2036 | // extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2037 | base::FilePath bad_private_key_dir = |
| 2038 | data_dir().AppendASCII("bad_private_key"); |
[email protected] | c21b5b61 | 2013-07-31 07:49:16 | [diff] [blame] | 2039 | crx_path = output_directory.AppendASCII("bad_private_key.crx"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2040 | privkey_path = data_dir().AppendASCII("bad_private_key.pem"); |
[email protected] | c21b5b61 | 2013-07-31 07:49:16 | [diff] [blame] | 2041 | ASSERT_FALSE(creator->Run(bad_private_key_dir, crx_path, base::FilePath(), |
| 2042 | privkey_path, ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2043 | } |
| 2044 | |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2045 | // Test Packaging and installing an extension whose name contains punctuation. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2046 | TEST_F(ExtensionServiceTest, PackPunctuatedExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2047 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2048 | base::FilePath input_directory = data_dir() |
| 2049 | .AppendASCII("good") |
| 2050 | .AppendASCII("Extensions") |
| 2051 | .AppendASCII(good0) |
| 2052 | .AppendASCII("1.0.0.0"); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2053 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2054 | base::ScopedTempDir temp_dir; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2055 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 2056 | |
| 2057 | // Extension names containing punctuation, and the expected names for the |
| 2058 | // packed extensions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2059 | const base::FilePath punctuated_names[] = { |
| 2060 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods")), |
| 2061 | base::FilePath(FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod")), |
| 2062 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname/")). |
[email protected] | d9034ed2 | 2012-02-10 02:04:40 | [diff] [blame] | 2063 | NormalizePathSeparators(), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2064 | }; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2065 | const base::FilePath expected_crx_names[] = { |
| 2066 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods.crx")), |
| 2067 | base::FilePath( |
| 2068 | FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.crx")), |
| 2069 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.crx")), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2070 | }; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2071 | const base::FilePath expected_private_key_names[] = { |
| 2072 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods.pem")), |
| 2073 | base::FilePath( |
| 2074 | FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.pem")), |
| 2075 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.pem")), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2076 | }; |
| 2077 | |
| 2078 | for (size_t i = 0; i < arraysize(punctuated_names); ++i) { |
| 2079 | SCOPED_TRACE(punctuated_names[i].value().c_str()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2080 | base::FilePath output_dir = temp_dir.path().Append(punctuated_names[i]); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2081 | |
| 2082 | // Copy the extension into the output directory, as PackExtensionJob doesn't |
| 2083 | // let us choose where to output the packed extension. |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 2084 | ASSERT_TRUE(base::CopyDirectory(input_directory, output_dir, true)); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2085 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2086 | base::FilePath expected_crx_path = |
| 2087 | temp_dir.path().Append(expected_crx_names[i]); |
| 2088 | base::FilePath expected_private_key_path = |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2089 | temp_dir.path().Append(expected_private_key_names[i]); |
| 2090 | PackExtensionTestClient pack_client(expected_crx_path, |
| 2091 | expected_private_key_path); |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 2092 | scoped_refptr<extensions::PackExtensionJob> packer( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2093 | new extensions::PackExtensionJob(&pack_client, output_dir, |
| 2094 | base::FilePath(), |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 2095 | ExtensionCreator::kOverwriteCRX)); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2096 | packer->Start(); |
| 2097 | |
| 2098 | // The packer will post a notification task to the current thread's message |
| 2099 | // loop when it is finished. We manually run the loop here so that we |
| 2100 | // block and catch the notification; otherwise, the process would exit. |
| 2101 | // This call to |Run()| is matched by a call to |Quit()| in the |
| 2102 | // |PackExtensionTestClient|'s notification handling code. |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 2103 | base::MessageLoop::current()->Run(); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2104 | |
| 2105 | if (HasFatalFailure()) |
| 2106 | return; |
| 2107 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2108 | InstallCRX(expected_crx_path, INSTALL_NEW); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2109 | } |
| 2110 | } |
| 2111 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2112 | TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) { |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2113 | InitializeEmptyExtensionService(); |
| 2114 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2115 | base::ScopedTempDir extension_temp_dir; |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2116 | ASSERT_TRUE(extension_temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2117 | base::FilePath input_directory = extension_temp_dir.path().AppendASCII("ext"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2118 | ASSERT_TRUE( |
| 2119 | base::CopyDirectory(data_dir() |
| 2120 | .AppendASCII("good") |
| 2121 | .AppendASCII("Extensions") |
| 2122 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 2123 | .AppendASCII("1.0.0.0"), |
| 2124 | input_directory, |
| 2125 | /*recursive=*/true)); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2126 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2127 | base::ScopedTempDir output_temp_dir; |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2128 | ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2129 | base::FilePath output_directory = output_temp_dir.path(); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2130 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2131 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 2132 | base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2133 | |
| 2134 | // Pack the extension once to get a private key. |
| 2135 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2136 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2137 | privkey_path, ExtensionCreator::kNoRunFlags)) |
| 2138 | << creator->error_message(); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2139 | ASSERT_TRUE(base::PathExists(crx_path)); |
| 2140 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2141 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 2142 | base::DeleteFile(crx_path, false); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2143 | // Move the pem file into the extension. |
[email protected] | 5553d5b | 2013-07-01 23:07:36 | [diff] [blame] | 2144 | base::Move(privkey_path, |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2145 | input_directory.AppendASCII("privkey.pem")); |
| 2146 | |
| 2147 | // This pack should fail because of the contained private key. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2148 | EXPECT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2149 | privkey_path, ExtensionCreator::kNoRunFlags)); |
| 2150 | EXPECT_THAT(creator->error_message(), |
| 2151 | testing::ContainsRegex( |
| 2152 | "extension includes the key file.*privkey.pem")); |
| 2153 | } |
| 2154 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2155 | // Test Packaging and installing an extension using an openssl generated key. |
| 2156 | // The openssl is generated with the following: |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 2157 | // > openssl genrsa -out privkey.pem 1024 |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 2158 | // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 2159 | // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2160 | // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2161 | TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2162 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2163 | base::FilePath input_directory = |
| 2164 | data_dir() |
| 2165 | .AppendASCII("good") |
| 2166 | .AppendASCII("Extensions") |
| 2167 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 2168 | .AppendASCII("1.0.0.0"); |
| 2169 | base::FilePath privkey_path( |
| 2170 | data_dir().AppendASCII("openssl_privkey_asn1.pem")); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2171 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2172 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2173 | base::ScopedTempDir temp_dir; |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 2174 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2175 | base::FilePath output_directory = temp_dir.path(); |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 2176 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2177 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2178 | |
| 2179 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 2180 | ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2181 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2182 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2183 | InstallCRX(crx_path, INSTALL_NEW); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2184 | } |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2185 | |
[email protected] | 8706592 | 2014-05-28 14:50:37 | [diff] [blame] | 2186 | #if defined(THREAD_SANITIZER) |
| 2187 | // Flaky under Tsan. http://crbug.com/377702 |
| 2188 | #define MAYBE_InstallTheme DISABLED_InstallTheme |
| 2189 | #else |
| 2190 | #define MAYBE_InstallTheme InstallTheme |
| 2191 | #endif |
| 2192 | |
| 2193 | TEST_F(ExtensionServiceTest, MAYBE_InstallTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2194 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2195 | service()->Init(); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2196 | |
| 2197 | // A theme. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2198 | base::FilePath path = data_dir().AppendASCII("theme.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2199 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2200 | int pref_count = 0; |
| 2201 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2202 | ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2203 | ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2204 | |
[email protected] | 6ef635e4 | 2009-07-26 06:16:12 | [diff] [blame] | 2205 | // A theme when extensions are disabled. Themes can be installed, even when |
| 2206 | // extensions are disabled. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2207 | service()->set_extensions_enabled(false); |
| 2208 | path = data_dir().AppendASCII("theme2.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2209 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2210 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2211 | ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2212 | ValidateIntegerPref(theme2_crx, "location", Manifest::INTERNAL); |
[email protected] | 494c06e | 2009-07-25 01:06:42 | [diff] [blame] | 2213 | |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2214 | // A theme with extension elements. Themes cannot have extension elements, |
| 2215 | // so any such elements (like content scripts) should be ignored. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2216 | service()->set_extensions_enabled(true); |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2217 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2218 | path = data_dir().AppendASCII("theme_with_extension.crx"); |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2219 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2220 | ValidatePrefKeyCount(++pref_count); |
| 2221 | ASSERT_TRUE(extension); |
| 2222 | EXPECT_TRUE(extension->is_theme()); |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 2223 | EXPECT_EQ( |
| 2224 | 0u, |
| 2225 | extensions::ContentScriptsInfo::GetContentScripts(extension).size()); |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2226 | } |
[email protected] | 1219891 | 2009-06-05 03:41:22 | [diff] [blame] | 2227 | |
| 2228 | // A theme with image resources missing (misspelt path). |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2229 | path = data_dir().AppendASCII("theme_missing_image.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2230 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2231 | ValidatePrefKeyCount(pref_count); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2232 | } |
| 2233 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2234 | TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2235 | // Load. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2236 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2237 | service()->Init(); |
[email protected] | b1ac7046 | 2013-08-14 21:33:30 | [diff] [blame] | 2238 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2239 | base::FilePath extension_path = data_dir().AppendASCII("theme_i18n"); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2240 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2241 | extensions::UnpackedInstaller::Create(service())->Load(extension_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2242 | base::RunLoop().RunUntilIdle(); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2243 | EXPECT_EQ(0u, GetErrors().size()); |
| 2244 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2245 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 2246 | const Extension* theme = registry()->enabled_extensions().begin()->get(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2247 | EXPECT_EQ("name", theme->name()); |
| 2248 | EXPECT_EQ("description", theme->description()); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 2249 | |
| 2250 | // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a |
| 2251 | // temporary directory, but it automatically installs to the extension's |
| 2252 | // directory, and we don't want to copy the whole extension for a unittest. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2253 | base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2254 | ASSERT_TRUE(base::PathExists(theme_file)); |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 2255 | ASSERT_TRUE(base::DeleteFile(theme_file, false)); // Not recursive. |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2256 | } |
| 2257 | |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2258 | // Tests that we can change the ID of an unpacked extension by adding a key |
| 2259 | // to its manifest. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2260 | TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) { |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2261 | InitializeEmptyExtensionService(); |
| 2262 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2263 | base::ScopedTempDir temp; |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2264 | ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 2265 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2266 | base::FilePath extension_path = temp.path(); |
| 2267 | base::FilePath manifest_path = |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2268 | extension_path.Append(extensions::kManifestFilename); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2269 | base::FilePath manifest_no_key = |
| 2270 | data_dir().AppendASCII("unpacked").AppendASCII("manifest_no_key.json"); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2271 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2272 | base::FilePath manifest_with_key = |
| 2273 | data_dir().AppendASCII("unpacked").AppendASCII("manifest_with_key.json"); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2274 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2275 | ASSERT_TRUE(base::PathExists(manifest_no_key)); |
| 2276 | ASSERT_TRUE(base::PathExists(manifest_with_key)); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2277 | |
| 2278 | // Load the unpacked extension with no key. |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 2279 | base::CopyFile(manifest_no_key, manifest_path); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2280 | extensions::UnpackedInstaller::Create(service())->Load(extension_path); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2281 | |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2282 | base::RunLoop().RunUntilIdle(); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2283 | EXPECT_EQ(0u, GetErrors().size()); |
| 2284 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2285 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2286 | |
| 2287 | // Add the key to the manifest. |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 2288 | base::CopyFile(manifest_with_key, manifest_path); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2289 | loaded_.clear(); |
| 2290 | |
| 2291 | // Reload the extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2292 | service()->ReloadExtensionsForTest(); |
| 2293 | const Extension* extension = service()->GetExtensionById(unpacked, false); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2294 | EXPECT_EQ(unpacked, extension->id()); |
| 2295 | ASSERT_EQ(1u, loaded_.size()); |
| 2296 | |
| 2297 | // TODO(jstritar): Right now this just makes sure we don't crash and burn, but |
| 2298 | // we should also test that preferences are preserved. |
| 2299 | } |
| 2300 | |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2301 | #if defined(OS_POSIX) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2302 | TEST_F(ExtensionServiceTest, UnpackedExtensionMayContainSymlinkedFiles) { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2303 | base::FilePath source_data_dir = |
| 2304 | data_dir().AppendASCII("unpacked").AppendASCII("symlinks_allowed"); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2305 | |
| 2306 | // Paths to test data files. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2307 | base::FilePath source_manifest = source_data_dir.AppendASCII("manifest.json"); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2308 | ASSERT_TRUE(base::PathExists(source_manifest)); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2309 | base::FilePath source_icon = source_data_dir.AppendASCII("icon.png"); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2310 | ASSERT_TRUE(base::PathExists(source_icon)); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2311 | |
| 2312 | // Set up the temporary extension directory. |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2313 | base::ScopedTempDir temp; |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2314 | ASSERT_TRUE(temp.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2315 | base::FilePath extension_path = temp.path(); |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2316 | base::FilePath manifest = extension_path.Append( |
| 2317 | extensions::kManifestFilename); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2318 | base::FilePath icon_symlink = extension_path.AppendASCII("icon.png"); |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 2319 | base::CopyFile(source_manifest, manifest); |
[email protected] | b264eab | 2013-11-27 23:22:08 | [diff] [blame] | 2320 | base::CreateSymbolicLink(source_icon, icon_symlink); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2321 | |
| 2322 | // Load extension. |
| 2323 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2324 | extensions::UnpackedInstaller::Create(service())->Load(extension_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2325 | base::RunLoop().RunUntilIdle(); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2326 | |
| 2327 | EXPECT_TRUE(GetErrors().empty()); |
| 2328 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2329 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2330 | } |
| 2331 | #endif |
| 2332 | |
[email protected] | 5ccca8ad | 2013-08-19 22:35:34 | [diff] [blame] | 2333 | TEST_F(ExtensionServiceTest, UnpackedExtensionMayNotHaveUnderscore) { |
| 2334 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2335 | base::FilePath extension_path = data_dir().AppendASCII("underscore_name"); |
| 2336 | extensions::UnpackedInstaller::Create(service())->Load(extension_path); |
[email protected] | 5ccca8ad | 2013-08-19 22:35:34 | [diff] [blame] | 2337 | base::RunLoop().RunUntilIdle(); |
| 2338 | EXPECT_EQ(1u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2339 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 5ccca8ad | 2013-08-19 22:35:34 | [diff] [blame] | 2340 | } |
| 2341 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2342 | TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2343 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2344 | service()->Init(); |
[email protected] | b1ac7046 | 2013-08-14 21:33:30 | [diff] [blame] | 2345 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2346 | base::FilePath theme_path = data_dir().AppendASCII("theme_i18n"); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2347 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2348 | const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2349 | |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2350 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2351 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2352 | EXPECT_EQ("name", theme->name()); |
| 2353 | EXPECT_EQ("description", theme->description()); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2354 | } |
| 2355 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2356 | TEST_F(ExtensionServiceTest, InstallApps) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2357 | InitializeEmptyExtensionService(); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2358 | |
| 2359 | // An empty app. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2360 | const Extension* app = |
| 2361 | PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2362 | int pref_count = 0; |
| 2363 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2364 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2365 | ValidateIntegerPref(app->id(), "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2366 | ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2367 | |
| 2368 | // Another app with non-overlapping extent. Should succeed. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2369 | PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2370 | ValidatePrefKeyCount(++pref_count); |
| 2371 | |
| 2372 | // A third app whose extent overlaps the first. Should fail. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2373 | PackAndInstallCRX(data_dir().AppendASCII("app3"), INSTALL_FAILED); |
[email protected] | cd10e28 | 2010-10-26 21:04:51 | [diff] [blame] | 2374 | ValidatePrefKeyCount(pref_count); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2375 | } |
| 2376 | |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2377 | // Tests that file access is OFF by default. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2378 | TEST_F(ExtensionServiceTest, DefaultFileAccess) { |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2379 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2380 | const Extension* extension = PackAndInstallCRX( |
| 2381 | data_dir().AppendASCII("permissions").AppendASCII("files"), INSTALL_NEW); |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2382 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2383 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 2384 | EXPECT_FALSE( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2385 | ExtensionPrefs::Get(profile())->AllowFileAccess(extension->id())); |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2386 | } |
| 2387 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2388 | TEST_F(ExtensionServiceTest, UpdateApps) { |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2389 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2390 | base::FilePath extensions_path = data_dir().AppendASCII("app_update"); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2391 | |
| 2392 | // First install v1 of a hosted app. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2393 | const Extension* extension = |
| 2394 | InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2395 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2396 | std::string id = extension->id(); |
| 2397 | ASSERT_EQ(std::string("1"), extension->version()->GetString()); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2398 | |
| 2399 | // Now try updating to v2. |
| 2400 | UpdateExtension(id, |
| 2401 | extensions_path.AppendASCII("v2.crx"), |
| 2402 | ENABLED); |
| 2403 | ASSERT_EQ(std::string("2"), |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2404 | service()->GetExtensionById(id, false)->version()->GetString()); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2405 | } |
| 2406 | |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2407 | // Verifies that the NTP page and launch ordinals are kept when updating apps. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2408 | TEST_F(ExtensionServiceTest, UpdateAppsRetainOrdinals) { |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2409 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2410 | AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting(); |
| 2411 | base::FilePath extensions_path = data_dir().AppendASCII("app_update"); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2412 | |
| 2413 | // First install v1 of a hosted app. |
| 2414 | const Extension* extension = |
| 2415 | InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2416 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2417 | std::string id = extension->id(); |
| 2418 | ASSERT_EQ(std::string("1"), extension->version()->GetString()); |
| 2419 | |
| 2420 | // Modify the ordinals so we can distinguish them from the defaults. |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 2421 | syncer::StringOrdinal new_page_ordinal = |
| 2422 | sorting->GetPageOrdinal(id).CreateAfter(); |
| 2423 | syncer::StringOrdinal new_launch_ordinal = |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2424 | sorting->GetAppLaunchOrdinal(id).CreateBefore(); |
| 2425 | |
| 2426 | sorting->SetPageOrdinal(id, new_page_ordinal); |
| 2427 | sorting->SetAppLaunchOrdinal(id, new_launch_ordinal); |
| 2428 | |
| 2429 | // Now try updating to v2. |
| 2430 | UpdateExtension(id, extensions_path.AppendASCII("v2.crx"), ENABLED); |
| 2431 | ASSERT_EQ(std::string("2"), |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2432 | service()->GetExtensionById(id, false)->version()->GetString()); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2433 | |
| 2434 | // Verify that the ordinals match. |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 2435 | ASSERT_TRUE(new_page_ordinal.Equals(sorting->GetPageOrdinal(id))); |
| 2436 | ASSERT_TRUE(new_launch_ordinal.Equals(sorting->GetAppLaunchOrdinal(id))); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2437 | } |
| 2438 | |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2439 | // Ensures that the CWS has properly initialized ordinals. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2440 | TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) { |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2441 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2442 | service()->component_loader()->Add( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2443 | IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store"))); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2444 | service()->Init(); |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2445 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2446 | AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting(); |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2447 | EXPECT_TRUE( |
| 2448 | sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid()); |
| 2449 | EXPECT_TRUE( |
| 2450 | sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid()); |
| 2451 | } |
| 2452 | |
[email protected] | fe10c20 | 2013-03-11 23:44:34 | [diff] [blame] | 2453 | TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2454 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2455 | EXPECT_TRUE(registry()->enabled_extensions().is_empty()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2456 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2457 | int pref_count = 0; |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2458 | |
| 2459 | // Install app1 with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2460 | const Extension* extension = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2461 | PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2462 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2463 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2464 | const std::string id1 = extension->id(); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 2465 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2466 | APIPermission::kUnlimitedStorage)); |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2467 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2468 | extensions::AppLaunchInfo::GetFullLaunchURL(extension))); |
| 2469 | const GURL origin1( |
| 2470 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2471 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 2472 | origin1)); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2473 | |
| 2474 | // Install app2 from the same origin with unlimited storage. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2475 | extension = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2476 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2477 | ASSERT_EQ(2u, registry()->enabled_extensions().size()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2478 | const std::string id2 = extension->id(); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 2479 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2480 | APIPermission::kUnlimitedStorage)); |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2481 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2482 | extensions::AppLaunchInfo::GetFullLaunchURL(extension))); |
| 2483 | const GURL origin2( |
| 2484 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2485 | EXPECT_EQ(origin1, origin2); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2486 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 2487 | origin2)); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2488 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2489 | // Uninstall one of them, unlimited storage should still be granted |
| 2490 | // to the origin. |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2491 | UninstallExtension(id1, false); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2492 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 2493 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 2494 | origin1)); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2495 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2496 | // Uninstall the other, unlimited storage should be revoked. |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2497 | UninstallExtension(id2, false); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2498 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 2499 | EXPECT_FALSE( |
| 2500 | profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 2501 | origin2)); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2502 | } |
| 2503 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2504 | TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2505 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2506 | EXPECT_TRUE(registry()->enabled_extensions().is_empty()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2507 | |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2508 | int pref_count = 0; |
| 2509 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2510 | const Extension* extension = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2511 | PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2512 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2513 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2514 | EXPECT_TRUE(extension->is_app()); |
| 2515 | const std::string id1 = extension->id(); |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2516 | const GURL origin1( |
| 2517 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2518 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected( |
| 2519 | origin1)); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2520 | |
| 2521 | // App 4 has a different origin (maps.google.com). |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2522 | extension = PackAndInstallCRX(data_dir().AppendASCII("app4"), INSTALL_NEW); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2523 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2524 | ASSERT_EQ(2u, registry()->enabled_extensions().size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2525 | const std::string id2 = extension->id(); |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2526 | const GURL origin2( |
| 2527 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2528 | ASSERT_NE(origin1, origin2); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2529 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected( |
| 2530 | origin2)); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2531 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2532 | UninstallExtension(id1, false); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2533 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2534 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2535 | UninstallExtension(id2, false); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2536 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2537 | EXPECT_TRUE(registry()->enabled_extensions().is_empty()); |
| 2538 | EXPECT_FALSE( |
| 2539 | profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected( |
| 2540 | origin1)); |
| 2541 | EXPECT_FALSE( |
| 2542 | profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected( |
| 2543 | origin2)); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2544 | } |
| 2545 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2546 | // Test that when an extension version is reinstalled, nothing happens. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2547 | TEST_F(ExtensionServiceTest, Reinstall) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2548 | InitializeEmptyExtensionService(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2549 | |
| 2550 | // A simple extension that should install without error. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2551 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2552 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2553 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2554 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2555 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2556 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2557 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 2558 | // Reinstall the same version, it should overwrite the previous one. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2559 | InstallCRX(path, INSTALL_UPDATED); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2560 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2561 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2562 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2563 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2564 | } |
| 2565 | |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2566 | // Test that we can determine if extensions came from the |
| 2567 | // Chrome web store. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2568 | TEST_F(ExtensionServiceTest, FromWebStore) { |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2569 | InitializeEmptyExtensionService(); |
| 2570 | |
| 2571 | // A simple extension that should install without error. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2572 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2573 | // Not from web store. |
| 2574 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2575 | std::string id = extension->id(); |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2576 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2577 | ValidatePrefKeyCount(1); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2578 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", false)); |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2579 | ASSERT_FALSE(extension->from_webstore()); |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2580 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2581 | // Test install from web store. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2582 | InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store. |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2583 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2584 | ValidatePrefKeyCount(1); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2585 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2586 | |
| 2587 | // Reload so extension gets reinitialized with new value. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2588 | service()->ReloadExtensionsForTest(); |
| 2589 | extension = service()->GetExtensionById(id, false); |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2590 | ASSERT_TRUE(extension->from_webstore()); |
[email protected] | 3d72972 | 2011-09-20 02:57:09 | [diff] [blame] | 2591 | |
| 2592 | // Upgrade to version 2.0 |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2593 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | 3d72972 | 2011-09-20 02:57:09 | [diff] [blame] | 2594 | UpdateExtension(good_crx, path, ENABLED); |
| 2595 | ValidatePrefKeyCount(1); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2596 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2597 | } |
| 2598 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2599 | // Test upgrading a signed extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2600 | TEST_F(ExtensionServiceTest, UpgradeSignedGood) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2601 | InitializeEmptyExtensionService(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2602 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2603 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2604 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2605 | std::string id = extension->id(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2606 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2607 | ASSERT_EQ("1.0.0.0", extension->version()->GetString()); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2608 | ASSERT_EQ(0u, GetErrors().size()); |
| 2609 | |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 2610 | // Upgrade to version 1.0.0.1. |
| 2611 | // Also test that the extension's old and new title are correctly retrieved. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2612 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 2613 | InstallCRX(path, INSTALL_UPDATED, Extension::NO_FLAGS, "My extension 1"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2614 | extension = service()->GetExtensionById(id, false); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2615 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2616 | ASSERT_EQ("1.0.0.1", extension->version()->GetString()); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 2617 | ASSERT_EQ("My updated extension 1", extension->name()); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2618 | ASSERT_EQ(0u, GetErrors().size()); |
| 2619 | } |
| 2620 | |
| 2621 | // Test upgrading a signed extension with a bad signature. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2622 | TEST_F(ExtensionServiceTest, UpgradeSignedBad) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2623 | InitializeEmptyExtensionService(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2624 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2625 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2626 | InstallCRX(path, INSTALL_NEW); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2627 | |
| 2628 | // Try upgrading with a bad signature. This should fail during the unpack, |
| 2629 | // because the key will not match the signature. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2630 | path = data_dir().AppendASCII("bad_signature.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2631 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2632 | } |
| 2633 | |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2634 | // Test a normal update via the UpdateExtension API |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2635 | TEST_F(ExtensionServiceTest, UpdateExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2636 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2637 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2638 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2639 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2640 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2641 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2642 | ASSERT_EQ(good_crx, good->id()); |
| 2643 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2644 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2645 | UpdateExtension(good_crx, path, ENABLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2646 | ASSERT_EQ( |
| 2647 | "1.0.0.1", |
| 2648 | service()->GetExtensionById(good_crx, false)->version()->GetString()); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2649 | } |
| 2650 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2651 | // Extensions should not be updated during browser shutdown. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2652 | TEST_F(ExtensionServiceTest, UpdateExtensionDuringShutdown) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2653 | InitializeEmptyExtensionService(); |
| 2654 | |
| 2655 | // Install an extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2656 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2657 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2658 | ASSERT_EQ(good_crx, good->id()); |
| 2659 | |
| 2660 | // Simulate shutdown. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2661 | service()->set_browser_terminating_for_test(true); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2662 | |
| 2663 | // Update should fail and extension should not be updated. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2664 | path = data_dir().AppendASCII("good2.crx"); |
| 2665 | bool updated = service()->UpdateExtension(good_crx, path, true, NULL); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2666 | ASSERT_FALSE(updated); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2667 | ASSERT_EQ( |
| 2668 | "1.0.0.0", |
| 2669 | service()->GetExtensionById(good_crx, false)->version()->GetString()); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2670 | } |
| 2671 | |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2672 | // Test updating a not-already-installed extension - this should fail |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2673 | TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2674 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2675 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2676 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2677 | UpdateExtension(good_crx, path, UPDATED); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2678 | base::RunLoop().RunUntilIdle(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2679 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2680 | ASSERT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2681 | ASSERT_FALSE(installed_); |
| 2682 | ASSERT_EQ(0u, loaded_.size()); |
| 2683 | } |
| 2684 | |
| 2685 | // Makes sure you can't downgrade an extension via UpdateExtension |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2686 | TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2687 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2688 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2689 | base::FilePath path = data_dir().AppendASCII("good2.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2690 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2691 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2692 | ASSERT_EQ("1.0.0.1", good->VersionString()); |
| 2693 | ASSERT_EQ(good_crx, good->id()); |
| 2694 | |
| 2695 | // Change path from good2.crx -> good.crx |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2696 | path = data_dir().AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2697 | UpdateExtension(good_crx, path, FAILED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2698 | ASSERT_EQ( |
| 2699 | "1.0.0.1", |
| 2700 | service()->GetExtensionById(good_crx, false)->version()->GetString()); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | // Make sure calling update with an identical version does nothing |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2704 | TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2705 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2706 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2707 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2708 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2709 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2710 | ASSERT_EQ(good_crx, good->id()); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2711 | UpdateExtension(good_crx, path, FAILED_SILENTLY); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2712 | } |
| 2713 | |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2714 | // Tests that updating an extension does not clobber old state. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2715 | TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2716 | InitializeEmptyExtensionService(); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2717 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2718 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2719 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2720 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2721 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2722 | ASSERT_EQ(good_crx, good->id()); |
| 2723 | |
| 2724 | // Disable it and allow it to run in incognito. These settings should carry |
| 2725 | // over to the updated version. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2726 | service()->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION); |
| 2727 | extensions::util::SetIsIncognitoEnabled(good->id(), profile(), true); |
| 2728 | ExtensionPrefs::Get(profile()) |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 2729 | ->SetDidExtensionEscalatePermissions(good, true); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2730 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2731 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2732 | UpdateExtension(good_crx, path, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2733 | ASSERT_EQ(1u, registry()->disabled_extensions().size()); |
| 2734 | const Extension* good2 = service()->GetExtensionById(good_crx, true); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2735 | ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2736 | EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good2->id(), profile())); |
| 2737 | EXPECT_TRUE(ExtensionPrefs::Get(profile()) |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 2738 | ->DidExtensionEscalatePermissions(good2->id())); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2739 | } |
| 2740 | |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2741 | // Tests that updating preserves extension location. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2742 | TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2743 | InitializeEmptyExtensionService(); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2744 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2745 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2746 | |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 2747 | const Extension* good = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2748 | InstallCRXWithLocation(path, Manifest::EXTERNAL_PREF, INSTALL_NEW); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2749 | |
| 2750 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2751 | ASSERT_EQ(good_crx, good->id()); |
| 2752 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2753 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2754 | UpdateExtension(good_crx, path, ENABLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2755 | const Extension* good2 = service()->GetExtensionById(good_crx, false); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2756 | ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2757 | EXPECT_EQ(good2->location(), Manifest::EXTERNAL_PREF); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2758 | } |
| 2759 | |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2760 | // Makes sure that LOAD extension types can downgrade. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2761 | TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2762 | InitializeEmptyExtensionService(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2763 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2764 | base::ScopedTempDir temp; |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2765 | ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 2766 | |
| 2767 | // We'll write the extension manifest dynamically to a temporary path |
| 2768 | // to make it easier to change the version number. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2769 | base::FilePath extension_path = temp.path(); |
| 2770 | base::FilePath manifest_path = |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2771 | extension_path.Append(extensions::kManifestFilename); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2772 | ASSERT_FALSE(base::PathExists(manifest_path)); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2773 | |
| 2774 | // Start with version 2.0. |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 2775 | base::DictionaryValue manifest; |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2776 | manifest.SetString("version", "2.0"); |
| 2777 | manifest.SetString("name", "LOAD Downgrade Test"); |
[email protected] | b3d5285 | 2011-12-07 01:01:11 | [diff] [blame] | 2778 | manifest.SetInteger("manifest_version", 2); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2779 | |
| 2780 | JSONFileValueSerializer serializer(manifest_path); |
| 2781 | ASSERT_TRUE(serializer.Serialize(manifest)); |
| 2782 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2783 | extensions::UnpackedInstaller::Create(service())->Load(extension_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2784 | base::RunLoop().RunUntilIdle(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2785 | |
| 2786 | EXPECT_EQ(0u, GetErrors().size()); |
| 2787 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 2788 | EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2789 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2790 | EXPECT_EQ("2.0", loaded_[0]->VersionString()); |
| 2791 | |
| 2792 | // Now set the version number to 1.0, reload the extensions and verify that |
| 2793 | // the downgrade was accepted. |
| 2794 | manifest.SetString("version", "1.0"); |
| 2795 | ASSERT_TRUE(serializer.Serialize(manifest)); |
| 2796 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2797 | extensions::UnpackedInstaller::Create(service())->Load(extension_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2798 | base::RunLoop().RunUntilIdle(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2799 | |
| 2800 | EXPECT_EQ(0u, GetErrors().size()); |
| 2801 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 2802 | EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2803 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2804 | EXPECT_EQ("1.0", loaded_[0]->VersionString()); |
| 2805 | } |
| 2806 | |
[email protected] | 77724b60 | 2014-05-14 11:36:12 | [diff] [blame] | 2807 | #if !defined(OS_POSIX) || defined(OS_MACOSX) |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2808 | // LOAD extensions with plugins require approval. |
[email protected] | 77724b60 | 2014-05-14 11:36:12 | [diff] [blame] | 2809 | // Only run this on platforms that support NPAPI plugins. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2810 | TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) { |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2811 | base::FilePath extension_with_plugin_path = good1_path(); |
| 2812 | base::FilePath extension_no_plugin_path = good2_path(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2813 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 2814 | InitPluginService(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2815 | InitializeEmptyExtensionService(); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 2816 | InitializeProcessManager(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2817 | service()->set_show_extensions_prompts(true); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2818 | |
| 2819 | // Start by canceling any install prompts. |
[email protected] | 2a74d6f6 | 2014-07-24 11:53:47 | [diff] [blame] | 2820 | ExtensionInstallPrompt::g_auto_confirm_for_tests = |
| 2821 | ExtensionInstallPrompt::CANCEL; |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2822 | |
| 2823 | // The extension that has a plugin should not install. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2824 | extensions::UnpackedInstaller::Create(service()) |
| 2825 | ->Load(extension_with_plugin_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2826 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2827 | EXPECT_EQ(0u, GetErrors().size()); |
| 2828 | EXPECT_EQ(0u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2829 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 2830 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2831 | |
| 2832 | // But the extension with no plugin should since there's no prompt. |
[email protected] | 252873a | 2013-07-19 01:39:48 | [diff] [blame] | 2833 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2834 | extensions::UnpackedInstaller::Create(service()) |
| 2835 | ->Load(extension_no_plugin_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2836 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2837 | EXPECT_EQ(0u, GetErrors().size()); |
| 2838 | EXPECT_EQ(1u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2839 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 2840 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 2841 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good2)); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2842 | |
| 2843 | // The plugin extension should install if we accept the dialog. |
[email protected] | 2a74d6f6 | 2014-07-24 11:53:47 | [diff] [blame] | 2844 | ExtensionInstallPrompt::g_auto_confirm_for_tests = |
| 2845 | ExtensionInstallPrompt::ACCEPT; |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2846 | |
[email protected] | 252873a | 2013-07-19 01:39:48 | [diff] [blame] | 2847 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2848 | extensions::UnpackedInstaller::Create(service()) |
| 2849 | ->Load(extension_with_plugin_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2850 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2851 | EXPECT_EQ(0u, GetErrors().size()); |
| 2852 | EXPECT_EQ(2u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2853 | EXPECT_EQ(2u, registry()->enabled_extensions().size()); |
| 2854 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 2855 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good1)); |
| 2856 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good2)); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2857 | |
| 2858 | // Make sure the granted permissions have been setup. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2859 | scoped_refptr<PermissionSet> permissions( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2860 | ExtensionPrefs::Get(profile())->GetGrantedPermissions(good1)); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2861 | EXPECT_FALSE(permissions->IsEmpty()); |
| 2862 | EXPECT_TRUE(permissions->HasEffectiveFullAccess()); |
| 2863 | EXPECT_FALSE(permissions->apis().empty()); |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2864 | EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2865 | |
| 2866 | // We should be able to reload the extension without getting another prompt. |
| 2867 | loaded_.clear(); |
[email protected] | 2a74d6f6 | 2014-07-24 11:53:47 | [diff] [blame] | 2868 | ExtensionInstallPrompt::g_auto_confirm_for_tests = |
| 2869 | ExtensionInstallPrompt::CANCEL; |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2870 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2871 | service()->ReloadExtension(good1); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2872 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2873 | EXPECT_EQ(1u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2874 | EXPECT_EQ(2u, registry()->enabled_extensions().size()); |
| 2875 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2876 | } |
[email protected] | 77724b60 | 2014-05-14 11:36:12 | [diff] [blame] | 2877 | #endif // !defined(OS_POSIX) || defined(OS_MACOSX) |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2878 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2879 | namespace { |
| 2880 | |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 2881 | bool IsExtension(const Extension* extension) { |
| 2882 | return extension->GetType() == Manifest::TYPE_EXTENSION; |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2883 | } |
| 2884 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 2885 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 2886 | std::set<std::string> StringSet(const std::string& s) { |
| 2887 | std::set<std::string> set; |
| 2888 | set.insert(s); |
| 2889 | return set; |
| 2890 | } |
| 2891 | std::set<std::string> StringSet(const std::string& s1, const std::string& s2) { |
| 2892 | std::set<std::string> set = StringSet(s1); |
| 2893 | set.insert(s2); |
| 2894 | return set; |
| 2895 | } |
| 2896 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 2897 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2898 | } // namespace |
| 2899 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2900 | // Test adding a pending extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2901 | TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2902 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2903 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 2904 | const std::string kFakeId(all_zero); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2905 | const GURL kFakeUpdateURL("http:://fake.update/url"); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2906 | const bool kFakeInstallSilently(true); |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 2907 | const bool kFakeRemoteInstall(false); |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2908 | const bool kFakeInstalledByCustodian(false); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2909 | |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 2910 | EXPECT_TRUE( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2911 | service()->pending_extension_manager()->AddFromSync( |
| 2912 | kFakeId, |
| 2913 | kFakeUpdateURL, |
| 2914 | &IsExtension, |
| 2915 | kFakeInstallSilently, |
| 2916 | kFakeRemoteInstall, |
| 2917 | kFakeInstalledByCustodian)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2918 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 2919 | const extensions::PendingExtensionInfo* pending_extension_info; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2920 | ASSERT_TRUE((pending_extension_info = |
| 2921 | service()->pending_extension_manager()->GetById(kFakeId))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2922 | EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); |
| 2923 | EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); |
| 2924 | EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently()); |
[email protected] | 24b5fd4 | 2014-05-17 01:14:18 | [diff] [blame] | 2925 | // Use |
| 2926 | // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()) |
| 2927 | // instead of |
| 2928 | // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install()) |
| 2929 | // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is |
| 2930 | // turned into an error with -Werror=conversion-null: |
| 2931 | // converting 'false' to pointer type for argument 1 of |
| 2932 | // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' |
| 2933 | // https://code.google.com/p/googletest/issues/detail?id=458 |
| 2934 | EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2935 | } |
| 2936 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2937 | namespace { |
| 2938 | const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 2939 | const char kGoodUpdateURL[] = "http://good.update/url"; |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2940 | const bool kGoodIsFromSync = true; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2941 | const bool kGoodInstallSilently = true; |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 2942 | const bool kGoodRemoteInstall = false; |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2943 | const bool kGoodInstalledByCustodian = false; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2944 | } // namespace |
| 2945 | |
| 2946 | // Test updating a pending extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2947 | TEST_F(ExtensionServiceTest, UpdatePendingExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2948 | InitializeEmptyExtensionService(); |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 2949 | EXPECT_TRUE( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2950 | service()->pending_extension_manager()->AddFromSync( |
| 2951 | kGoodId, |
| 2952 | GURL(kGoodUpdateURL), |
| 2953 | &IsExtension, |
| 2954 | kGoodInstallSilently, |
| 2955 | kGoodRemoteInstall, |
| 2956 | kGoodInstalledByCustodian)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2957 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2958 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2959 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2960 | UpdateExtension(kGoodId, path, ENABLED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2961 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2962 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2963 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2964 | const Extension* extension = service()->GetExtensionById(kGoodId, true); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2965 | ASSERT_TRUE(extension); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2966 | } |
| 2967 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2968 | namespace { |
| 2969 | |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 2970 | bool IsTheme(const Extension* extension) { |
| 2971 | return extension->is_theme(); |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | } // namespace |
| 2975 | |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2976 | // Test updating a pending theme. |
[email protected] | 7f2c555 | 2011-12-20 22:53:16 | [diff] [blame] | 2977 | // Disabled due to ASAN failure. http://crbug.com/108320 |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2978 | TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2979 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2980 | EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2981 | theme_crx, GURL(), &IsTheme, false, false, false)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2982 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2983 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2984 | base::FilePath path = data_dir().AppendASCII("theme.crx"); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2985 | UpdateExtension(theme_crx, path, ENABLED); |
| 2986 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2987 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2988 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2989 | const Extension* extension = service()->GetExtensionById(theme_crx, true); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2990 | ASSERT_TRUE(extension); |
| 2991 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2992 | EXPECT_FALSE( |
| 2993 | ExtensionPrefs::Get(profile())->IsExtensionDisabled(extension->id())); |
| 2994 | EXPECT_TRUE(service()->IsExtensionEnabled(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2995 | } |
| 2996 | |
[email protected] | d74f92e | 2011-04-18 15:39:23 | [diff] [blame] | 2997 | #if defined(OS_CHROMEOS) |
| 2998 | // Always fails on ChromeOS: http://crbug.com/79737 |
[email protected] | e00ccc9 | 2012-11-01 17:32:30 | [diff] [blame] | 2999 | #define MAYBE_UpdatePendingExternalCrx DISABLED_UpdatePendingExternalCrx |
[email protected] | d74f92e | 2011-04-18 15:39:23 | [diff] [blame] | 3000 | #else |
| 3001 | #define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx |
| 3002 | #endif |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3003 | // Test updating a pending CRX as if the source is an external extension |
| 3004 | // with an update URL. In this case we don't know if the CRX is a theme |
| 3005 | // or not. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3006 | TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3007 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3008 | EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 3009 | theme_crx, |
| 3010 | std::string(), |
| 3011 | GURL(), |
| 3012 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 3013 | Extension::NO_FLAGS, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 3014 | false)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3015 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3016 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3017 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3018 | base::FilePath path = data_dir().AppendASCII("theme.crx"); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3019 | UpdateExtension(theme_crx, path, ENABLED); |
| 3020 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3021 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3022 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3023 | const Extension* extension = service()->GetExtensionById(theme_crx, true); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3024 | ASSERT_TRUE(extension); |
| 3025 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3026 | EXPECT_FALSE( |
| 3027 | ExtensionPrefs::Get(profile())->IsExtensionDisabled(extension->id())); |
| 3028 | EXPECT_TRUE(service()->IsExtensionEnabled(extension->id())); |
| 3029 | EXPECT_FALSE( |
| 3030 | extensions::util::IsIncognitoEnabled(extension->id(), profile())); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3031 | } |
| 3032 | |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3033 | // Test updating a pending CRX as if the source is an external extension |
| 3034 | // with an update URL. The external update should overwrite a sync update, |
| 3035 | // but a sync update should not overwrite a non-sync update. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3036 | TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3037 | InitializeEmptyExtensionService(); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3038 | |
| 3039 | // Add a crx to be installed from the update mechanism. |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 3040 | EXPECT_TRUE( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 3041 | service()->pending_extension_manager()->AddFromSync( |
| 3042 | kGoodId, |
| 3043 | GURL(kGoodUpdateURL), |
| 3044 | &IsExtension, |
| 3045 | kGoodInstallSilently, |
| 3046 | kGoodRemoteInstall, |
| 3047 | kGoodInstalledByCustodian)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3048 | |
| 3049 | // Check that there is a pending crx, with is_from_sync set to true. |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 3050 | const extensions::PendingExtensionInfo* pending_extension_info; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3051 | ASSERT_TRUE((pending_extension_info = |
| 3052 | service()->pending_extension_manager()->GetById(kGoodId))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 3053 | EXPECT_TRUE(pending_extension_info->is_from_sync()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3054 | |
| 3055 | // Add a crx to be updated, with the same ID, from a non-sync source. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3056 | EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 3057 | kGoodId, |
| 3058 | std::string(), |
| 3059 | GURL(kGoodUpdateURL), |
| 3060 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 3061 | Extension::NO_FLAGS, |
| 3062 | false)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3063 | |
| 3064 | // Check that there is a pending crx, with is_from_sync set to false. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3065 | ASSERT_TRUE((pending_extension_info = |
| 3066 | service()->pending_extension_manager()->GetById(kGoodId))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 3067 | EXPECT_FALSE(pending_extension_info->is_from_sync()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3068 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 3069 | pending_extension_info->install_source()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3070 | |
| 3071 | // Add a crx to be installed from the update mechanism. |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 3072 | EXPECT_FALSE( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 3073 | service()->pending_extension_manager()->AddFromSync( |
| 3074 | kGoodId, |
| 3075 | GURL(kGoodUpdateURL), |
| 3076 | &IsExtension, |
| 3077 | kGoodInstallSilently, |
| 3078 | kGoodRemoteInstall, |
| 3079 | kGoodInstalledByCustodian)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3080 | |
| 3081 | // Check that the external, non-sync update was not overridden. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3082 | ASSERT_TRUE((pending_extension_info = |
| 3083 | service()->pending_extension_manager()->GetById(kGoodId))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 3084 | EXPECT_FALSE(pending_extension_info->is_from_sync()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3085 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 3086 | pending_extension_info->install_source()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3087 | } |
| 3088 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3089 | // Updating a theme should fail if the updater is explicitly told that |
| 3090 | // the CRX is not a theme. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3091 | TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3092 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3093 | EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 3094 | theme_crx, GURL(), &IsExtension, true, false, false)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3095 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3096 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3097 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3098 | base::FilePath path = data_dir().AppendASCII("theme.crx"); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3099 | UpdateExtension(theme_crx, path, FAILED_SILENTLY); |
| 3100 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3101 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3102 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3103 | const Extension* extension = service()->GetExtensionById(theme_crx, true); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3104 | ASSERT_FALSE(extension); |
| 3105 | } |
| 3106 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3107 | // TODO(akalin): Test updating a pending extension non-silently once |
| 3108 | // we can mock out ExtensionInstallUI and inject our version into |
| 3109 | // UpdateExtension(). |
| 3110 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 3111 | // Test updating a pending extension which fails the should-install test. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3112 | TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3113 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3114 | // Add pending extension with a flipped is_theme. |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 3115 | EXPECT_TRUE( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 3116 | service()->pending_extension_manager()->AddFromSync( |
| 3117 | kGoodId, |
| 3118 | GURL(kGoodUpdateURL), |
| 3119 | &IsTheme, |
| 3120 | kGoodInstallSilently, |
| 3121 | kGoodRemoteInstall, |
| 3122 | kGoodInstalledByCustodian)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3123 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3124 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3125 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 3126 | UpdateExtension(kGoodId, path, UPDATED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3127 | |
| 3128 | // TODO(akalin): Figure out how to check that the extensions |
| 3129 | // directory is cleaned up properly in OnExtensionInstalled(). |
| 3130 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3131 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3132 | } |
| 3133 | |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 3134 | // TODO(akalin): Figure out how to test that installs of pending |
| 3135 | // unsyncable extensions are blocked. |
| 3136 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3137 | // Test updating a pending extension for one that is not pending. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3138 | TEST_F(ExtensionServiceTest, UpdatePendingExtensionNotPending) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3139 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3140 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3141 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 3142 | UpdateExtension(kGoodId, path, UPDATED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3143 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3144 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | // Test updating a pending extension for one that is already |
| 3148 | // installed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3149 | TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3150 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3151 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3152 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3153 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3154 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3155 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3156 | EXPECT_FALSE(good->is_theme()); |
| 3157 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3158 | // Use AddExtensionImpl() as AddFrom*() would balk. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3159 | service()->pending_extension_manager()->AddExtensionImpl( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 3160 | good->id(), |
| 3161 | std::string(), |
| 3162 | extensions::ManifestURL::GetUpdateURL(good), |
| 3163 | Version(), |
| 3164 | &IsExtension, |
| 3165 | kGoodIsFromSync, |
| 3166 | kGoodInstallSilently, |
| 3167 | Manifest::INTERNAL, |
| 3168 | Extension::NO_FLAGS, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 3169 | false, |
| 3170 | kGoodRemoteInstall); |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3171 | UpdateExtension(good->id(), path, ENABLED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3172 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3173 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 3174 | } |
| 3175 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3176 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3177 | // Tests blacklisting then unblacklisting extensions after the service has been |
| 3178 | // initialized. |
[email protected] | 7d9b4e3 | 2013-10-25 06:11:54 | [diff] [blame] | 3179 | TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3180 | extensions::TestBlacklist test_blacklist; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3181 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3182 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3183 | test_blacklist.Attach(service()->blacklist_); |
| 3184 | service()->Init(); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3185 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3186 | const extensions::ExtensionSet& enabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3187 | registry()->enabled_extensions(); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3188 | const extensions::ExtensionSet& blacklisted_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3189 | registry()->blacklisted_extensions(); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3190 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3191 | EXPECT_TRUE(enabled_extensions.Contains(good0) && |
| 3192 | !blacklisted_extensions.Contains(good0)); |
| 3193 | EXPECT_TRUE(enabled_extensions.Contains(good1) && |
| 3194 | !blacklisted_extensions.Contains(good1)); |
| 3195 | EXPECT_TRUE(enabled_extensions.Contains(good2) && |
| 3196 | !blacklisted_extensions.Contains(good2)); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3197 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3198 | EXPECT_FALSE(IsPrefExist(good0, "blacklist")); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3199 | EXPECT_FALSE(IsPrefExist(good1, "blacklist")); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3200 | EXPECT_FALSE(IsPrefExist(good2, "blacklist")); |
| 3201 | EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
| 3202 | |
| 3203 | // Blacklist good0 and good1 (and an invalid extension ID). |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3204 | test_blacklist.SetBlacklistState( |
| 3205 | good0, extensions::BLACKLISTED_MALWARE, true); |
| 3206 | test_blacklist.SetBlacklistState( |
| 3207 | good1, extensions::BLACKLISTED_MALWARE, true); |
| 3208 | test_blacklist.SetBlacklistState( |
| 3209 | "invalid_id", extensions::BLACKLISTED_MALWARE, true); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3210 | base::RunLoop().RunUntilIdle(); |
| 3211 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3212 | EXPECT_TRUE(!enabled_extensions.Contains(good0) && |
| 3213 | blacklisted_extensions.Contains(good0)); |
| 3214 | EXPECT_TRUE(!enabled_extensions.Contains(good1) && |
| 3215 | blacklisted_extensions.Contains(good1)); |
| 3216 | EXPECT_TRUE(enabled_extensions.Contains(good2) && |
| 3217 | !blacklisted_extensions.Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3218 | |
| 3219 | EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); |
| 3220 | EXPECT_TRUE(ValidateBooleanPref(good1, "blacklist", true)); |
| 3221 | EXPECT_FALSE(IsPrefExist(good2, "blacklist")); |
| 3222 | EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
| 3223 | |
| 3224 | // Un-blacklist good1 and blacklist good2. |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3225 | test_blacklist.Clear(false); |
| 3226 | test_blacklist.SetBlacklistState( |
| 3227 | good0, extensions::BLACKLISTED_MALWARE, true); |
| 3228 | test_blacklist.SetBlacklistState( |
| 3229 | good2, extensions::BLACKLISTED_MALWARE, true); |
| 3230 | test_blacklist.SetBlacklistState( |
| 3231 | "invalid_id", extensions::BLACKLISTED_MALWARE, true); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3232 | base::RunLoop().RunUntilIdle(); |
| 3233 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3234 | EXPECT_TRUE(!enabled_extensions.Contains(good0) && |
| 3235 | blacklisted_extensions.Contains(good0)); |
| 3236 | EXPECT_TRUE(enabled_extensions.Contains(good1) && |
| 3237 | !blacklisted_extensions.Contains(good1)); |
| 3238 | EXPECT_TRUE(!enabled_extensions.Contains(good2) && |
| 3239 | blacklisted_extensions.Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3240 | |
| 3241 | EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); |
| 3242 | EXPECT_FALSE(IsPrefExist(good1, "blacklist")); |
| 3243 | EXPECT_TRUE(ValidateBooleanPref(good2, "blacklist", true)); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 3244 | EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3245 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3246 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3247 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3248 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3249 | // Tests trying to install a blacklisted extension. |
[email protected] | e0cbfc4 | 2013-11-07 00:10:10 | [diff] [blame] | 3250 | TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) { |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3251 | scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( |
| 3252 | new FakeSafeBrowsingDatabaseManager(true)); |
| 3253 | Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); |
| 3254 | |
[email protected] | 1747eac0 | 2013-09-23 10:58:42 | [diff] [blame] | 3255 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3256 | service()->Init(); |
[email protected] | 1747eac0 | 2013-09-23 10:58:42 | [diff] [blame] | 3257 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3258 | // After blacklisting good_crx, we cannot install it. |
| 3259 | blacklist_db->SetUnsafe(good_crx).NotifyUpdate(); |
| 3260 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1747eac0 | 2013-09-23 10:58:42 | [diff] [blame] | 3261 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3262 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 3263 | // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't |
| 3264 | // decide to install this silently. Somebody should fix these tests, all |
| 3265 | // 6,000 lines of them. Hah! |
| 3266 | InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3267 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3268 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3269 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3270 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3271 | #if defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3272 | // Unload blacklisted extension on policy change. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3273 | TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3274 | extensions::TestBlacklist test_blacklist; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3275 | |
| 3276 | // A profile with no extensions installed. |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3277 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3278 | test_blacklist.Attach(service()->blacklist_); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3279 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3280 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3281 | |
| 3282 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 3283 | EXPECT_EQ(good_crx, good->id()); |
| 3284 | UpdateExtension(good_crx, path, FAILED_SILENTLY); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3285 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3286 | |
| 3287 | base::ListValue whitelist; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3288 | PrefService* prefs = ExtensionPrefs::Get(profile())->pref_service(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3289 | whitelist.Append(new base::StringValue(good_crx)); |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3290 | prefs->Set(extensions::pref_names::kInstallAllowList, whitelist); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3291 | |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3292 | test_blacklist.SetBlacklistState( |
| 3293 | good_crx, extensions::BLACKLISTED_MALWARE, true); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3294 | base::RunLoop().RunUntilIdle(); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3295 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3296 | // The good_crx is blacklisted and the whitelist doesn't negate it. |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3297 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3298 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3299 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3300 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3301 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3302 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3303 | // Tests that a blacklisted extension is eventually unloaded on startup, if it |
| 3304 | // wasn't already. |
[email protected] | e0cbfc4 | 2013-11-07 00:10:10 | [diff] [blame] | 3305 | TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3306 | extensions::TestBlacklist test_blacklist; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3307 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3308 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3309 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3310 | test_blacklist.Attach(service()->blacklist_); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3311 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3312 | // Blacklist good1 before the service initializes. |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3313 | test_blacklist.SetBlacklistState( |
| 3314 | good1, extensions::BLACKLISTED_MALWARE, false); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3315 | |
| 3316 | // Load extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3317 | service()->Init(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3318 | ASSERT_EQ(3u, loaded_.size()); // hasn't had time to blacklist yet |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3319 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3320 | base::RunLoop().RunUntilIdle(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3321 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3322 | ASSERT_EQ(1u, registry()->blacklisted_extensions().size()); |
| 3323 | ASSERT_EQ(2u, registry()->enabled_extensions().size()); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3324 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3325 | ASSERT_TRUE(registry()->enabled_extensions().Contains(good0)); |
| 3326 | ASSERT_TRUE(registry()->blacklisted_extensions().Contains(good1)); |
| 3327 | ASSERT_TRUE(registry()->enabled_extensions().Contains(good2)); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3328 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3329 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3330 | |
| 3331 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3332 | // Tests extensions blacklisted in prefs on startup; one still blacklisted by |
| 3333 | // safe browsing, the other not. The not-blacklisted one should recover. |
| 3334 | TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3335 | extensions::TestBlacklist test_blacklist; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3336 | |
| 3337 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3338 | test_blacklist.Attach(service()->blacklist_); |
| 3339 | ExtensionPrefs::Get(profile())->SetExtensionBlacklisted(good0, true); |
| 3340 | ExtensionPrefs::Get(profile())->SetExtensionBlacklisted(good1, true); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3341 | |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3342 | test_blacklist.SetBlacklistState( |
| 3343 | good1, extensions::BLACKLISTED_MALWARE, false); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3344 | |
[email protected] | 27e52832 | 2014-05-27 20:54:30 | [diff] [blame] | 3345 | // Extension service hasn't loaded yet, but IsExtensionEnabled reads out of |
| 3346 | // prefs. Ensure it takes into account the blacklist state (crbug.com/373842). |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3347 | EXPECT_FALSE(service()->IsExtensionEnabled(good0)); |
| 3348 | EXPECT_FALSE(service()->IsExtensionEnabled(good1)); |
| 3349 | EXPECT_TRUE(service()->IsExtensionEnabled(good2)); |
[email protected] | 27e52832 | 2014-05-27 20:54:30 | [diff] [blame] | 3350 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3351 | service()->Init(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3352 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3353 | EXPECT_EQ(2u, registry()->blacklisted_extensions().size()); |
| 3354 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3355 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3356 | EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good0)); |
| 3357 | EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good1)); |
| 3358 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3359 | |
| 3360 | // Give time for the blacklist to update. |
| 3361 | base::RunLoop().RunUntilIdle(); |
| 3362 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3363 | EXPECT_EQ(1u, registry()->blacklisted_extensions().size()); |
| 3364 | EXPECT_EQ(2u, registry()->enabled_extensions().size()); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3365 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3366 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good0)); |
| 3367 | EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good1)); |
| 3368 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3369 | } |
| 3370 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3371 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3372 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3373 | // Extension is added to blacklist with BLACKLISTED_POTENTIALLY_UNWANTED state |
| 3374 | // after it is installed. It is then successfully re-enabled by the user. |
| 3375 | TEST_F(ExtensionServiceTest, GreylistedExtensionDisabled) { |
| 3376 | extensions::TestBlacklist test_blacklist; |
| 3377 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3378 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3379 | test_blacklist.Attach(service()->blacklist_); |
| 3380 | service()->Init(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3381 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3382 | const extensions::ExtensionSet& enabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3383 | registry()->enabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3384 | const extensions::ExtensionSet& disabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3385 | registry()->disabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3386 | |
| 3387 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3388 | EXPECT_TRUE(enabled_extensions.Contains(good1)); |
| 3389 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3390 | |
| 3391 | // Blacklist good0 and good1 (and an invalid extension ID). |
| 3392 | test_blacklist.SetBlacklistState( |
| 3393 | good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); |
| 3394 | test_blacklist.SetBlacklistState( |
| 3395 | good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); |
| 3396 | test_blacklist.SetBlacklistState( |
| 3397 | "invalid_id", extensions::BLACKLISTED_MALWARE, true); |
| 3398 | base::RunLoop().RunUntilIdle(); |
| 3399 | |
| 3400 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3401 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3402 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3403 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3404 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3405 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3406 | |
| 3407 | ValidateIntegerPref( |
| 3408 | good0, "blacklist_state", extensions::BLACKLISTED_CWS_POLICY_VIOLATION); |
| 3409 | ValidateIntegerPref( |
| 3410 | good1, "blacklist_state", extensions::BLACKLISTED_POTENTIALLY_UNWANTED); |
| 3411 | |
| 3412 | // Now user enables good0. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3413 | service()->EnableExtension(good0); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3414 | |
| 3415 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3416 | EXPECT_FALSE(disabled_extensions.Contains(good0)); |
| 3417 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3418 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3419 | |
| 3420 | // Remove extensions from blacklist. |
| 3421 | test_blacklist.SetBlacklistState( |
| 3422 | good0, extensions::NOT_BLACKLISTED, true); |
| 3423 | test_blacklist.SetBlacklistState( |
| 3424 | good1, extensions::NOT_BLACKLISTED, true); |
| 3425 | base::RunLoop().RunUntilIdle(); |
| 3426 | |
| 3427 | // All extensions are enabled. |
| 3428 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3429 | EXPECT_FALSE(disabled_extensions.Contains(good0)); |
| 3430 | EXPECT_TRUE(enabled_extensions.Contains(good1)); |
| 3431 | EXPECT_FALSE(disabled_extensions.Contains(good1)); |
| 3432 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3433 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3434 | } |
| 3435 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3436 | |
| 3437 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3438 | // When extension is removed from greylist, do not re-enable it if it is |
| 3439 | // disabled by user. |
| 3440 | TEST_F(ExtensionServiceTest, GreylistDontEnableManuallyDisabled) { |
| 3441 | extensions::TestBlacklist test_blacklist; |
| 3442 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3443 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3444 | test_blacklist.Attach(service()->blacklist_); |
| 3445 | service()->Init(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3446 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3447 | const extensions::ExtensionSet& enabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3448 | registry()->enabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3449 | const extensions::ExtensionSet& disabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3450 | registry()->disabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3451 | |
| 3452 | // Manually disable. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3453 | service()->DisableExtension(good0, |
| 3454 | extensions::Extension::DISABLE_USER_ACTION); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3455 | |
| 3456 | test_blacklist.SetBlacklistState( |
| 3457 | good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); |
| 3458 | test_blacklist.SetBlacklistState( |
| 3459 | good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); |
| 3460 | test_blacklist.SetBlacklistState( |
| 3461 | good2, extensions::BLACKLISTED_SECURITY_VULNERABILITY, true); |
| 3462 | base::RunLoop().RunUntilIdle(); |
| 3463 | |
| 3464 | // All extensions disabled. |
| 3465 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3466 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3467 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3468 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3469 | EXPECT_FALSE(enabled_extensions.Contains(good2)); |
| 3470 | EXPECT_TRUE(disabled_extensions.Contains(good2)); |
| 3471 | |
| 3472 | // Greylisted extension can be enabled. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3473 | service()->EnableExtension(good1); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3474 | EXPECT_TRUE(enabled_extensions.Contains(good1)); |
| 3475 | EXPECT_FALSE(disabled_extensions.Contains(good1)); |
| 3476 | |
| 3477 | // good1 is now manually disabled. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3478 | service()->DisableExtension(good1, |
| 3479 | extensions::Extension::DISABLE_USER_ACTION); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3480 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3481 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3482 | |
| 3483 | // Remove extensions from blacklist. |
| 3484 | test_blacklist.SetBlacklistState( |
| 3485 | good0, extensions::NOT_BLACKLISTED, true); |
| 3486 | test_blacklist.SetBlacklistState( |
| 3487 | good1, extensions::NOT_BLACKLISTED, true); |
| 3488 | test_blacklist.SetBlacklistState( |
| 3489 | good2, extensions::NOT_BLACKLISTED, true); |
| 3490 | base::RunLoop().RunUntilIdle(); |
| 3491 | |
| 3492 | // good0 and good1 remain disabled. |
| 3493 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3494 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3495 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3496 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3497 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3498 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3499 | } |
| 3500 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3501 | |
| 3502 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3503 | // Blacklisted extension with unknown state are not enabled/disabled. |
| 3504 | TEST_F(ExtensionServiceTest, GreylistUnknownDontChange) { |
| 3505 | extensions::TestBlacklist test_blacklist; |
| 3506 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3507 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3508 | test_blacklist.Attach(service()->blacklist_); |
| 3509 | service()->Init(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3510 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3511 | const extensions::ExtensionSet& enabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3512 | registry()->enabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3513 | const extensions::ExtensionSet& disabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3514 | registry()->disabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3515 | |
| 3516 | test_blacklist.SetBlacklistState( |
| 3517 | good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); |
| 3518 | test_blacklist.SetBlacklistState( |
| 3519 | good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); |
| 3520 | base::RunLoop().RunUntilIdle(); |
| 3521 | |
| 3522 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3523 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3524 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3525 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3526 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3527 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3528 | |
| 3529 | test_blacklist.SetBlacklistState( |
| 3530 | good0, extensions::NOT_BLACKLISTED, true); |
| 3531 | test_blacklist.SetBlacklistState( |
| 3532 | good1, extensions::BLACKLISTED_UNKNOWN, true); |
| 3533 | test_blacklist.SetBlacklistState( |
| 3534 | good2, extensions::BLACKLISTED_UNKNOWN, true); |
| 3535 | base::RunLoop().RunUntilIdle(); |
| 3536 | |
| 3537 | // good0 re-enabled, other remain as they were. |
| 3538 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3539 | EXPECT_FALSE(disabled_extensions.Contains(good0)); |
| 3540 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3541 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3542 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3543 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3544 | } |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3545 | |
| 3546 | // Tests that blacklisted extensions cannot be reloaded, both those loaded |
| 3547 | // before and after extension service startup. |
| 3548 | TEST_F(ExtensionServiceTest, ReloadBlacklistedExtension) { |
| 3549 | extensions::TestBlacklist test_blacklist; |
| 3550 | |
| 3551 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3552 | test_blacklist.Attach(service()->blacklist_); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3553 | |
| 3554 | test_blacklist.SetBlacklistState( |
| 3555 | good1, extensions::BLACKLISTED_MALWARE, false); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3556 | service()->Init(); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3557 | test_blacklist.SetBlacklistState( |
| 3558 | good2, extensions::BLACKLISTED_MALWARE, false); |
| 3559 | base::RunLoop().RunUntilIdle(); |
| 3560 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3561 | EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs()); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3562 | EXPECT_EQ(StringSet(good1, good2), |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3563 | registry()->blacklisted_extensions().GetIDs()); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3564 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3565 | service()->ReloadExtension(good1); |
| 3566 | service()->ReloadExtension(good2); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3567 | base::RunLoop().RunUntilIdle(); |
| 3568 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3569 | EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs()); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3570 | EXPECT_EQ(StringSet(good1, good2), |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3571 | registry()->blacklisted_extensions().GetIDs()); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3572 | } |
| 3573 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3574 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3575 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3576 | // Will not install extension blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3577 | TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3578 | InitializeEmptyExtensionService(); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3579 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3580 | // Blacklist everything. |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3581 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3582 | ListPrefUpdate update(profile()->GetPrefs(), |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3583 | extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3584 | base::ListValue* blacklist = update.Get(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3585 | blacklist->Append(new base::StringValue("*")); |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3586 | } |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3587 | |
| 3588 | // Blacklist prevents us from installing good_crx. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3589 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3590 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3591 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3592 | |
| 3593 | // Now whitelist this particular extension. |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3594 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3595 | ListPrefUpdate update(profile()->GetPrefs(), |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3596 | extensions::pref_names::kInstallAllowList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3597 | base::ListValue* whitelist = update.Get(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3598 | whitelist->Append(new base::StringValue(good_crx)); |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3599 | } |
| 3600 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3601 | // Ensure we can now install good_crx. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3602 | InstallCRX(path, INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3603 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3604 | } |
| 3605 | |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3606 | // Extension blacklisted by policy get unloaded after installing. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3607 | TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3608 | InitializeEmptyExtensionService(); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3609 | |
| 3610 | // Install good_crx. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3611 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3612 | InstallCRX(path, INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3613 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3614 | |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3615 | { // Scope for pref update notification. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3616 | PrefService* prefs = profile()->GetPrefs(); |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3617 | ListPrefUpdate update(prefs, extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3618 | base::ListValue* blacklist = update.Get(); |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3619 | ASSERT_TRUE(blacklist != NULL); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3620 | |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3621 | // Blacklist this extension. |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3622 | blacklist->Append(new base::StringValue(good_crx)); |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3623 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3624 | |
| 3625 | // Extension should not be running now. |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3626 | base::RunLoop().RunUntilIdle(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3627 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3628 | } |
| 3629 | |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3630 | // Tests that component extensions are not blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3631 | TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3632 | InitializeEmptyExtensionService(); |
| 3633 | |
| 3634 | // Blacklist everything. |
| 3635 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3636 | ListPrefUpdate update(profile()->GetPrefs(), |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3637 | extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3638 | base::ListValue* blacklist = update.Get(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3639 | blacklist->Append(new base::StringValue("*")); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | // Install a component extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3643 | base::FilePath path = data_dir() |
| 3644 | .AppendASCII("good") |
| 3645 | .AppendASCII("Extensions") |
| 3646 | .AppendASCII(good0) |
| 3647 | .AppendASCII("1.0.0.0"); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3648 | std::string manifest; |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 3649 | ASSERT_TRUE(base::ReadFileToString( |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 3650 | path.Append(extensions::kManifestFilename), &manifest)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3651 | service()->component_loader()->Add(manifest, path); |
| 3652 | service()->Init(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3653 | |
| 3654 | // Extension should be installed despite blacklist. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3655 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 3656 | EXPECT_TRUE(service()->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3657 | |
| 3658 | // Poke external providers and make sure the extension is still present. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3659 | service()->CheckForExternalUpdates(); |
| 3660 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 3661 | EXPECT_TRUE(service()->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3662 | |
| 3663 | // Extension should not be uninstalled on blacklist changes. |
| 3664 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3665 | ListPrefUpdate update(profile()->GetPrefs(), |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3666 | extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3667 | base::ListValue* blacklist = update.Get(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3668 | blacklist->Append(new base::StringValue(good0)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3669 | } |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3670 | base::RunLoop().RunUntilIdle(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3671 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 3672 | EXPECT_TRUE(service()->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | // Tests that policy-installed extensions are not blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3676 | TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3677 | InitializeEmptyExtensionService(); |
| 3678 | |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3679 | { |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 3680 | // Blacklist everything. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3681 | ListPrefUpdate blacklist_update(profile()->GetPrefs(), |
| 3682 | extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3683 | base::ListValue* blacklist = blacklist_update.Get(); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 3684 | blacklist->AppendString("*"); |
| 3685 | |
| 3686 | // Mark good.crx for force-installation. |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3687 | DictionaryPrefUpdate forcelist_update( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3688 | profile()->GetPrefs(), extensions::pref_names::kInstallForceList); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 3689 | extensions::ExternalPolicyLoader::AddExtension( |
| 3690 | forcelist_update.Get(), good_crx, "http://example.com/update_url"); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3691 | } |
| 3692 | |
| 3693 | // Have policy force-install an extension. |
| 3694 | MockExtensionProvider* provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3695 | new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3696 | AddMockExternalProvider(provider); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3697 | provider->UpdateOrAddExtension( |
| 3698 | good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx")); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3699 | |
| 3700 | // Reloading extensions should find our externally registered extension |
| 3701 | // and install it. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 3702 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 3703 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 3704 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3705 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 3706 | observer.Wait(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3707 | |
| 3708 | // Extension should be installed despite blacklist. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3709 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 3710 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3711 | |
| 3712 | // Blacklist update should not uninstall the extension. |
| 3713 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3714 | ListPrefUpdate update(profile()->GetPrefs(), |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3715 | extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3716 | base::ListValue* blacklist = update.Get(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3717 | blacklist->Append(new base::StringValue(good0)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3718 | } |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3719 | base::RunLoop().RunUntilIdle(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3720 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 3721 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3722 | } |
| 3723 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3724 | // Tests that extensions cannot be installed if the policy provider prohibits |
| 3725 | // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3726 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3727 | InitializeEmptyExtensionService(); |
| 3728 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3729 | GetManagementPolicy()->UnregisterAllProviders(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3730 | extensions::TestManagementPolicyProvider provider_( |
| 3731 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3732 | GetManagementPolicy()->RegisterProvider(&provider_); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3733 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3734 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_FAILED); |
| 3735 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | // Tests that extensions cannot be loaded from prefs if the policy provider |
| 3739 | // prohibits it. This functionality is implemented in InstalledLoader::Load(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3740 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3741 | InitializeEmptyExtensionService(); |
| 3742 | |
| 3743 | // Create a fake extension to be loaded as though it were read from prefs. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3744 | base::FilePath path = |
| 3745 | data_dir().AppendASCII("management").AppendASCII("simple_extension"); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3746 | base::DictionaryValue manifest; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3747 | manifest.SetString(keys::kName, "simple_extension"); |
| 3748 | manifest.SetString(keys::kVersion, "1"); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 3749 | // UNPACKED is for extensions loaded from a directory. We use it here, even |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3750 | // though we're testing loading from prefs, so that we don't need to provide |
| 3751 | // an extension key. |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 3752 | extensions::ExtensionInfo extension_info( |
| 3753 | &manifest, std::string(), path, Manifest::UNPACKED); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3754 | |
| 3755 | // Ensure we can load it with no management policy in place. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3756 | GetManagementPolicy()->UnregisterAllProviders(); |
| 3757 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 3758 | extensions::InstalledLoader(service()).Load(extension_info, false); |
| 3759 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3760 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3761 | const Extension* extension = |
| 3762 | (registry()->enabled_extensions().begin())->get(); |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 3763 | EXPECT_TRUE( |
| 3764 | service()->UninstallExtension(extension->id(), |
| 3765 | extensions::UNINSTALL_REASON_FOR_TESTING, |
| 3766 | base::Bind(&base::DoNothing), |
| 3767 | NULL)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3768 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3769 | |
| 3770 | // Ensure we cannot load it if management policy prohibits installation. |
| 3771 | extensions::TestManagementPolicyProvider provider_( |
| 3772 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3773 | GetManagementPolicy()->RegisterProvider(&provider_); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3774 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3775 | extensions::InstalledLoader(service()).Load(extension_info, false); |
| 3776 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | // Tests disabling an extension when prohibited by the ManagementPolicy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3780 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3781 | InitializeEmptyExtensionService(); |
| 3782 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3783 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 3784 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3785 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3786 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3787 | GetManagementPolicy()->UnregisterAllProviders(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3788 | extensions::TestManagementPolicyProvider provider( |
| 3789 | extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3790 | GetManagementPolicy()->RegisterProvider(&provider); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3791 | |
| 3792 | // Attempt to disable it. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3793 | service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3794 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3795 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3796 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
| 3797 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | // Tests uninstalling an extension when prohibited by the ManagementPolicy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3801 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3802 | InitializeEmptyExtensionService(); |
| 3803 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3804 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 3805 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3806 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3807 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3808 | GetManagementPolicy()->UnregisterAllProviders(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3809 | extensions::TestManagementPolicyProvider provider( |
| 3810 | extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3811 | GetManagementPolicy()->RegisterProvider(&provider); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3812 | |
| 3813 | // Attempt to uninstall it. |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 3814 | EXPECT_FALSE( |
| 3815 | service()->UninstallExtension(good_crx, |
| 3816 | extensions::UNINSTALL_REASON_FOR_TESTING, |
| 3817 | base::Bind(&base::DoNothing), |
| 3818 | NULL)); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3819 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3820 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3821 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | // Tests that previously installed extensions that are now prohibited from |
| 3825 | // being installed are removed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3826 | TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3827 | InitializeEmptyExtensionService(); |
| 3828 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3829 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 3830 | InstallCRX(data_dir().AppendASCII("page_action.crx"), INSTALL_NEW); |
| 3831 | EXPECT_EQ(2u, registry()->enabled_extensions().size()); |
| 3832 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3833 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3834 | GetManagementPolicy()->UnregisterAllProviders(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3835 | extensions::TestManagementPolicyProvider provider( |
| 3836 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3837 | GetManagementPolicy()->RegisterProvider(&provider); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3838 | |
| 3839 | // Run the policy check. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3840 | service()->CheckManagementPolicy(); |
| 3841 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 3842 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | // Tests that previously disabled extensions that are now required to be |
| 3846 | // enabled are re-enabled on reinstall. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3847 | TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3848 | InitializeEmptyExtensionService(); |
| 3849 | |
| 3850 | // Install, then disable, an extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3851 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 3852 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3853 | service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
| 3854 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3855 | |
| 3856 | // Register an ExtensionMnagementPolicy that requires the extension to remain |
| 3857 | // enabled. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3858 | GetManagementPolicy()->UnregisterAllProviders(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3859 | extensions::TestManagementPolicyProvider provider( |
| 3860 | extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3861 | GetManagementPolicy()->RegisterProvider(&provider); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3862 | |
| 3863 | // Reinstall the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3864 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_UPDATED); |
| 3865 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3866 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3867 | } |
| 3868 | |
[email protected] | ebc3aec | 2013-10-22 02:39:17 | [diff] [blame] | 3869 | // Flaky on windows; http://crbug.com/309833 |
| 3870 | #if defined(OS_WIN) |
| 3871 | #define MAYBE_ExternalExtensionAutoAcknowledgement DISABLED_ExternalExtensionAutoAcknowledgement |
| 3872 | #else |
| 3873 | #define MAYBE_ExternalExtensionAutoAcknowledgement ExternalExtensionAutoAcknowledgement |
| 3874 | #endif |
[email protected] | 893642c | 2014-02-03 06:53:13 | [diff] [blame] | 3875 | TEST_F(ExtensionServiceTest, MAYBE_ExternalExtensionAutoAcknowledgement) { |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3876 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3877 | service()->set_extensions_enabled(true); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3878 | |
| 3879 | { |
| 3880 | // Register and install an external extension. |
| 3881 | MockExtensionProvider* provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3882 | new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3883 | AddMockExternalProvider(provider); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3884 | provider->UpdateOrAddExtension( |
| 3885 | good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx")); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3886 | } |
| 3887 | { |
| 3888 | // Have policy force-install an extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3889 | MockExtensionProvider* provider = new MockExtensionProvider( |
| 3890 | service(), Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3891 | AddMockExternalProvider(provider); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3892 | provider->UpdateOrAddExtension( |
| 3893 | page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | // Providers are set up. Let them run. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 3897 | int count = 2; |
| 3898 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 3899 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 3900 | base::Bind(&WaitForCountNotificationsCallback, &count)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3901 | service()->CheckForExternalUpdates(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 3902 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 3903 | observer.Wait(); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3904 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3905 | ASSERT_EQ(2u, registry()->enabled_extensions().size()); |
| 3906 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
| 3907 | EXPECT_TRUE(service()->GetExtensionById(page_action, false)); |
| 3908 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3909 | ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); |
| 3910 | ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); |
| 3911 | } |
| 3912 | |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 3913 | #if !defined(OS_CHROMEOS) |
| 3914 | // This tests if default apps are installed correctly. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3915 | TEST_F(ExtensionServiceTest, DefaultAppsInstall) { |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 3916 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3917 | service()->set_extensions_enabled(true); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 3918 | |
| 3919 | { |
| 3920 | std::string json_data = |
| 3921 | "{" |
| 3922 | " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {" |
| 3923 | " \"external_crx\": \"good.crx\"," |
| 3924 | " \"external_version\": \"1.0.0.0\"," |
| 3925 | " \"is_bookmark_app\": false" |
| 3926 | " }" |
| 3927 | "}"; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3928 | default_apps::Provider* provider = new default_apps::Provider( |
| 3929 | profile(), |
| 3930 | service(), |
| 3931 | new extensions::ExternalTestingLoader(json_data, data_dir()), |
| 3932 | Manifest::INTERNAL, |
| 3933 | Manifest::INVALID_LOCATION, |
| 3934 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 3935 | |
| 3936 | AddMockExternalProvider(provider); |
| 3937 | } |
| 3938 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3939 | ASSERT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 3940 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 3941 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 3942 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3943 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 3944 | observer.Wait(); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 3945 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3946 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 3947 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
| 3948 | const Extension* extension = service()->GetExtensionById(good_crx, false); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 3949 | EXPECT_TRUE(extension->from_webstore()); |
| 3950 | EXPECT_TRUE(extension->was_installed_by_default()); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 3951 | } |
| 3952 | #endif |
| 3953 | |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3954 | // Tests disabling extensions |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3955 | TEST_F(ExtensionServiceTest, DisableExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3956 | InitializeEmptyExtensionService(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3957 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3958 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 3959 | EXPECT_TRUE(service()->GetExtensionById(good_crx, true)); |
| 3960 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3961 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3962 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3963 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 3964 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 3965 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3966 | |
| 3967 | // Disable it. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3968 | service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3969 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3970 | EXPECT_TRUE(service()->GetExtensionById(good_crx, true)); |
| 3971 | EXPECT_FALSE(service()->GetExtensionById(good_crx, false)); |
| 3972 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 3973 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 3974 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 3975 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | TEST_F(ExtensionServiceTest, TerminateExtension) { |
| 3979 | InitializeEmptyExtensionService(); |
| 3980 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3981 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 3982 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3983 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 3984 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 3985 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 3986 | |
| 3987 | TerminateExtension(good_crx); |
| 3988 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3989 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 3990 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 3991 | EXPECT_EQ(1u, registry()->terminated_extensions().size()); |
| 3992 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3993 | } |
| 3994 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3995 | TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3996 | InitializeEmptyExtensionService(); |
| 3997 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3998 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3999 | TerminateExtension(good_crx); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4000 | EXPECT_TRUE(registry()->GetExtensionById( |
[email protected] | e066da3 | 2014-03-26 18:27:35 | [diff] [blame] | 4001 | good_crx, extensions::ExtensionRegistry::TERMINATED)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4002 | |
| 4003 | // Disable it. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4004 | service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4005 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4006 | EXPECT_FALSE(registry()->GetExtensionById( |
[email protected] | e066da3 | 2014-03-26 18:27:35 | [diff] [blame] | 4007 | good_crx, extensions::ExtensionRegistry::TERMINATED)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4008 | EXPECT_TRUE(service()->GetExtensionById(good_crx, true)); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4009 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4010 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4011 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 4012 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 4013 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4014 | } |
| 4015 | |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4016 | // Tests disabling all extensions (simulating --disable-extensions flag). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4017 | TEST_F(ExtensionServiceTest, DisableAllExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4018 | InitializeEmptyExtensionService(); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4019 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4020 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4021 | InstallCRX(path, INSTALL_NEW); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4022 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4023 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4024 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4025 | |
| 4026 | // Disable extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4027 | service()->set_extensions_enabled(false); |
| 4028 | service()->ReloadExtensionsForTest(); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4029 | |
| 4030 | // There shouldn't be extensions in either list. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4031 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4032 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4033 | |
| 4034 | // This shouldn't do anything when all extensions are disabled. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4035 | service()->EnableExtension(good_crx); |
| 4036 | service()->ReloadExtensionsForTest(); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4037 | |
| 4038 | // There still shouldn't be extensions in either list. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4039 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4040 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4041 | |
| 4042 | // And then re-enable the extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4043 | service()->set_extensions_enabled(true); |
| 4044 | service()->ReloadExtensionsForTest(); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4045 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4046 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4047 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4048 | } |
| 4049 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4050 | // Tests reloading extensions. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4051 | TEST_F(ExtensionServiceTest, ReloadExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4052 | InitializeEmptyExtensionService(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4053 | |
| 4054 | // Simple extension that should install without error. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4055 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 4056 | InstallCRX(path, INSTALL_NEW, |
| 4057 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4058 | const char* extension_id = good_crx; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4059 | service()->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4060 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4061 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4062 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4063 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4064 | service()->ReloadExtensionsForTest(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4065 | |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 4066 | // The creation flags should not change when reloading the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4067 | const Extension* extension = service()->GetExtensionById(good_crx, true); |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 4068 | EXPECT_TRUE(extension->from_webstore()); |
| 4069 | EXPECT_TRUE(extension->was_installed_by_default()); |
| 4070 | EXPECT_FALSE(extension->from_bookmark()); |
| 4071 | |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4072 | // Extension counts shouldn't change. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4073 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4074 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4075 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4076 | service()->EnableExtension(extension_id); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4077 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4078 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4079 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4080 | |
[email protected] | 5a73f90 | 2010-06-30 02:29:41 | [diff] [blame] | 4081 | // Need to clear |loaded_| manually before reloading as the |
| 4082 | // EnableExtension() call above inserted into it and |
| 4083 | // UnloadAllExtensions() doesn't send out notifications. |
| 4084 | loaded_.clear(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4085 | service()->ReloadExtensionsForTest(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4086 | |
| 4087 | // Extension counts shouldn't change. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4088 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4089 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4090 | } |
| 4091 | |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4092 | // Tests reloading an extension. |
| 4093 | TEST_F(ExtensionServiceTest, ReloadExtension) { |
| 4094 | InitializeEmptyExtensionService(); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 4095 | InitializeProcessManager(); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4096 | |
| 4097 | // Simple extension that should install without error. |
| 4098 | const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4099 | base::FilePath ext = data_dir() |
| 4100 | .AppendASCII("good") |
| 4101 | .AppendASCII("Extensions") |
| 4102 | .AppendASCII(extension_id) |
| 4103 | .AppendASCII("1.0.0.0"); |
| 4104 | extensions::UnpackedInstaller::Create(service())->Load(ext); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4105 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4106 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4107 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4108 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4109 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4110 | service()->ReloadExtension(extension_id); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4111 | |
| 4112 | // Extension should be disabled now, waiting to be reloaded. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4113 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4114 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 4115 | EXPECT_EQ(Extension::DISABLE_RELOAD, |
| 4116 | ExtensionPrefs::Get(profile())->GetDisableReasons(extension_id)); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4117 | |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 4118 | // Reloading again should not crash. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4119 | service()->ReloadExtension(extension_id); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4120 | |
| 4121 | // Finish reloading |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4122 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4123 | |
| 4124 | // Extension should be enabled again. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4125 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4126 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4127 | } |
| 4128 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4129 | TEST_F(ExtensionServiceTest, UninstallExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4130 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4131 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 4132 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4133 | UninstallExtension(good_crx, false); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4134 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 4135 | EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4136 | } |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 4137 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4138 | TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4139 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4140 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4141 | TerminateExtension(good_crx); |
| 4142 | UninstallExtension(good_crx, false); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 4143 | EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 4144 | } |
| 4145 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 4146 | // Tests the uninstaller helper. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4147 | TEST_F(ExtensionServiceTest, UninstallExtensionHelper) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4148 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4149 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4150 | UninstallExtension(good_crx, true); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 4151 | EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4152 | } |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 4153 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4154 | TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4155 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4156 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4157 | TerminateExtension(good_crx); |
| 4158 | UninstallExtension(good_crx, true); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 4159 | EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_); |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 4160 | } |
| 4161 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4162 | // An extension disabled because of unsupported requirements should re-enabled |
| 4163 | // if updated to a version with supported requirements as long as there are no |
| 4164 | // other disable reasons. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4165 | TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4166 | InitializeEmptyExtensionService(); |
| 4167 | BlackListWebGL(); |
| 4168 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4169 | base::FilePath path = data_dir().AppendASCII("requirements"); |
| 4170 | base::FilePath pem_path = |
| 4171 | data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem"); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4172 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 4173 | pem_path, |
| 4174 | INSTALL_NEW); |
| 4175 | std::string id = extension_v1->id(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4176 | EXPECT_TRUE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4177 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4178 | base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4179 | |
| 4180 | PackCRX(path.AppendASCII("v2_bad_requirements"), |
| 4181 | pem_path, |
| 4182 | v2_bad_requirements_crx); |
| 4183 | UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4184 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4185 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4186 | base::FilePath v3_good_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4187 | |
| 4188 | PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); |
| 4189 | UpdateExtension(id, v3_good_crx, ENABLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4190 | EXPECT_TRUE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | // Extensions disabled through user action should stay disabled. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4194 | TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4195 | InitializeEmptyExtensionService(); |
| 4196 | BlackListWebGL(); |
| 4197 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4198 | base::FilePath path = data_dir().AppendASCII("requirements"); |
| 4199 | base::FilePath pem_path = |
| 4200 | data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem"); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4201 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 4202 | pem_path, |
| 4203 | INSTALL_NEW); |
| 4204 | std::string id = extension_v1->id(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4205 | service()->DisableExtension(id, Extension::DISABLE_USER_ACTION); |
| 4206 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4207 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4208 | base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4209 | |
| 4210 | PackCRX(path.AppendASCII("v2_bad_requirements"), |
| 4211 | pem_path, |
| 4212 | v2_bad_requirements_crx); |
| 4213 | UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4214 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4215 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4216 | base::FilePath v3_good_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4217 | |
| 4218 | PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); |
| 4219 | UpdateExtension(id, v3_good_crx, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4220 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | // The extension should not re-enabled because it was disabled from a |
| 4224 | // permission increase. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4225 | TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4226 | InitializeEmptyExtensionService(); |
| 4227 | BlackListWebGL(); |
| 4228 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4229 | base::FilePath path = data_dir().AppendASCII("requirements"); |
| 4230 | base::FilePath pem_path = |
| 4231 | data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem"); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4232 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 4233 | pem_path, |
| 4234 | INSTALL_NEW); |
| 4235 | std::string id = extension_v1->id(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4236 | EXPECT_TRUE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4237 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4238 | base::FilePath v2_bad_requirements_and_permissions_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4239 | |
| 4240 | PackCRX(path.AppendASCII("v2_bad_requirements_and_permissions"), |
| 4241 | pem_path, |
| 4242 | v2_bad_requirements_and_permissions_crx); |
| 4243 | UpdateExtension(id, v2_bad_requirements_and_permissions_crx, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4244 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4245 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4246 | base::FilePath v3_bad_permissions_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4247 | |
| 4248 | PackCRX(path.AppendASCII("v3_bad_permissions"), |
| 4249 | pem_path, |
| 4250 | v3_bad_permissions_crx); |
| 4251 | UpdateExtension(id, v3_bad_permissions_crx, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4252 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | // Unpacked extensions are not allowed to be installed if they have unsupported |
| 4256 | // requirements. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4257 | TEST_F(ExtensionServiceTest, UnpackedRequirements) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4258 | InitializeEmptyExtensionService(); |
| 4259 | BlackListWebGL(); |
| 4260 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4261 | base::FilePath path = |
| 4262 | data_dir().AppendASCII("requirements").AppendASCII("v2_bad_requirements"); |
| 4263 | extensions::UnpackedInstaller::Create(service())->Load(path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4264 | base::RunLoop().RunUntilIdle(); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4265 | EXPECT_EQ(1u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4266 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4267 | } |
| 4268 | |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4269 | class ExtensionCookieCallback { |
| 4270 | public: |
| 4271 | ExtensionCookieCallback() |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 4272 | : result_(false), |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 4273 | weak_factory_(base::MessageLoop::current()) {} |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4274 | |
| 4275 | void SetCookieCallback(bool result) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 4276 | base::MessageLoop::current()->PostTask(FROM_HERE, |
| 4277 | base::Bind(&base::MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4278 | result_ = result; |
| 4279 | } |
| 4280 | |
| 4281 | void GetAllCookiesCallback(const net::CookieList& list) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 4282 | base::MessageLoop::current()->PostTask(FROM_HERE, |
| 4283 | base::Bind(&base::MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4284 | list_ = list; |
| 4285 | } |
| 4286 | net::CookieList list_; |
| 4287 | bool result_; |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 4288 | base::WeakPtrFactory<base::MessageLoop> weak_factory_; |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4289 | }; |
| 4290 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4291 | // Verifies extension state is removed upon uninstall. |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 4292 | TEST_F(ExtensionServiceTest, ClearExtensionData) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4293 | InitializeEmptyExtensionService(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4294 | ExtensionCookieCallback callback; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4295 | |
| 4296 | // Load a test extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4297 | base::FilePath path = data_dir(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4298 | path = path.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4299 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4300 | ASSERT_TRUE(extension); |
| 4301 | GURL ext_url(extension->url()); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 4302 | std::string origin_id = storage::GetIdentifierFromOrigin(ext_url); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4303 | |
| 4304 | // Set a cookie for the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4305 | net::CookieMonster* cookie_monster = profile() |
| 4306 | ->GetRequestContextForExtensions() |
| 4307 | ->GetURLRequestContext() |
| 4308 | ->cookie_store() |
| 4309 | ->GetCookieMonster(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4310 | ASSERT_TRUE(cookie_monster); |
| 4311 | net::CookieOptions options; |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4312 | cookie_monster->SetCookieWithOptionsAsync( |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 4313 | ext_url, "dummy=value", options, |
| 4314 | base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 4315 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4316 | base::RunLoop().RunUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4317 | EXPECT_TRUE(callback.result_); |
| 4318 | |
| 4319 | cookie_monster->GetAllCookiesForURLAsync( |
| 4320 | ext_url, |
| 4321 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4322 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4323 | base::RunLoop().RunUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4324 | EXPECT_EQ(1U, callback.list_.size()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4325 | |
| 4326 | // Open a database. |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 4327 | storage::DatabaseTracker* db_tracker = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4328 | BrowserContext::GetDefaultStoragePartition(profile()) |
| 4329 | ->GetDatabaseTracker(); |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 4330 | base::string16 db_name = base::UTF8ToUTF16("db"); |
| 4331 | base::string16 description = base::UTF8ToUTF16("db_description"); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4332 | int64 size; |
[email protected] | 7c5f2ec | 2011-05-26 19:15:26 | [diff] [blame] | 4333 | db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4334 | db_tracker->DatabaseClosed(origin_id, db_name); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 4335 | std::vector<storage::OriginInfo> origins; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4336 | db_tracker->GetAllOriginsInfo(&origins); |
| 4337 | EXPECT_EQ(1U, origins.size()); |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 4338 | EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4339 | |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 4340 | // Create local storage. We only simulate this by creating the backing files. |
| 4341 | // Note: This test depends on details of how the dom_storage library |
| 4342 | // stores data in the host file system. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4343 | base::FilePath lso_dir_path = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4344 | profile()->GetPath().AppendASCII("Local Storage"); |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 4345 | base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) |
| 4346 | .AddExtension(FILE_PATH_LITERAL(".localstorage")); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4347 | EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 4348 | EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4349 | EXPECT_TRUE(base::PathExists(lso_file_path)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4350 | |
[email protected] | ab30809 | 2011-08-25 23:37:19 | [diff] [blame] | 4351 | // Create indexed db. Similarly, it is enough to only simulate this by |
| 4352 | // creating the directory on the disk. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4353 | IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition( |
| 4354 | profile())->GetIndexedDBContext(); |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 4355 | idb_context->SetTaskRunnerForTesting( |
[email protected] | 198b590 | 2013-06-27 10:36:11 | [diff] [blame] | 4356 | base::MessageLoop::current()->message_loop_proxy().get()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4357 | base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4358 | EXPECT_TRUE(base::CreateDirectory(idb_path)); |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4359 | EXPECT_TRUE(base::DirectoryExists(idb_path)); |
[email protected] | e1dcf92 | 2010-11-22 19:12:12 | [diff] [blame] | 4360 | |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4361 | // Uninstall the extension. |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 4362 | base::RunLoop run_loop; |
| 4363 | ASSERT_TRUE( |
| 4364 | service()->UninstallExtension(good_crx, |
| 4365 | extensions::UNINSTALL_REASON_FOR_TESTING, |
| 4366 | run_loop.QuitClosure(), |
| 4367 | NULL)); |
| 4368 | // The data deletion happens on the IO thread. |
| 4369 | run_loop.Run(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4370 | |
| 4371 | // Check that the cookie is gone. |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4372 | cookie_monster->GetAllCookiesForURLAsync( |
| 4373 | ext_url, |
| 4374 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4375 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4376 | base::RunLoop().RunUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4377 | EXPECT_EQ(0U, callback.list_.size()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4378 | |
| 4379 | // The database should have vanished as well. |
| 4380 | origins.clear(); |
| 4381 | db_tracker->GetAllOriginsInfo(&origins); |
| 4382 | EXPECT_EQ(0U, origins.size()); |
| 4383 | |
| 4384 | // Check that the LSO file has been removed. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4385 | EXPECT_FALSE(base::PathExists(lso_file_path)); |
[email protected] | e1dcf92 | 2010-11-22 19:12:12 | [diff] [blame] | 4386 | |
| 4387 | // Check if the indexed db has disappeared too. |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4388 | EXPECT_FALSE(base::DirectoryExists(idb_path)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4389 | } |
| 4390 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4391 | // Verifies app state is removed upon uninstall. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4392 | TEST_F(ExtensionServiceTest, ClearAppData) { |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4393 | InitializeEmptyExtensionService(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4394 | ExtensionCookieCallback callback; |
| 4395 | |
| 4396 | int pref_count = 0; |
| 4397 | |
| 4398 | // Install app1 with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4399 | const Extension* extension = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4400 | PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4401 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4402 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4403 | const std::string id1 = extension->id(); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 4404 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 4405 | APIPermission::kUnlimitedStorage)); |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 4406 | const GURL origin1( |
| 4407 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4408 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 4409 | origin1)); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 4410 | std::string origin_id = storage::GetIdentifierFromOrigin(origin1); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4411 | |
| 4412 | // Install app2 from the same origin with unlimited storage. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4413 | extension = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4414 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4415 | ASSERT_EQ(2u, registry()->enabled_extensions().size()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4416 | const std::string id2 = extension->id(); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 4417 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 4418 | APIPermission::kUnlimitedStorage)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4419 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 4420 | extensions::AppLaunchInfo::GetFullLaunchURL(extension))); |
| 4421 | const GURL origin2( |
| 4422 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4423 | EXPECT_EQ(origin1, origin2); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4424 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 4425 | origin2)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4426 | |
| 4427 | // Set a cookie for the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4428 | net::CookieMonster* cookie_monster = profile() |
| 4429 | ->GetRequestContext() |
| 4430 | ->GetURLRequestContext() |
| 4431 | ->cookie_store() |
| 4432 | ->GetCookieMonster(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4433 | ASSERT_TRUE(cookie_monster); |
| 4434 | net::CookieOptions options; |
| 4435 | cookie_monster->SetCookieWithOptionsAsync( |
| 4436 | origin1, "dummy=value", options, |
| 4437 | base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 4438 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4439 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4440 | EXPECT_TRUE(callback.result_); |
| 4441 | |
| 4442 | cookie_monster->GetAllCookiesForURLAsync( |
| 4443 | origin1, |
| 4444 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4445 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4446 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4447 | EXPECT_EQ(1U, callback.list_.size()); |
| 4448 | |
| 4449 | // Open a database. |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 4450 | storage::DatabaseTracker* db_tracker = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4451 | BrowserContext::GetDefaultStoragePartition(profile()) |
| 4452 | ->GetDatabaseTracker(); |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 4453 | base::string16 db_name = base::UTF8ToUTF16("db"); |
| 4454 | base::string16 description = base::UTF8ToUTF16("db_description"); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4455 | int64 size; |
| 4456 | db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
| 4457 | db_tracker->DatabaseClosed(origin_id, db_name); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame^] | 4458 | std::vector<storage::OriginInfo> origins; |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4459 | db_tracker->GetAllOriginsInfo(&origins); |
| 4460 | EXPECT_EQ(1U, origins.size()); |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 4461 | EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4462 | |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 4463 | // Create local storage. We only simulate this by creating the backing files. |
| 4464 | // Note: This test depends on details of how the dom_storage library |
| 4465 | // stores data in the host file system. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4466 | base::FilePath lso_dir_path = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4467 | profile()->GetPath().AppendASCII("Local Storage"); |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 4468 | base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) |
| 4469 | .AddExtension(FILE_PATH_LITERAL(".localstorage")); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4470 | EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 4471 | EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4472 | EXPECT_TRUE(base::PathExists(lso_file_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4473 | |
| 4474 | // Create indexed db. Similarly, it is enough to only simulate this by |
| 4475 | // creating the directory on the disk. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4476 | IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition( |
| 4477 | profile())->GetIndexedDBContext(); |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 4478 | idb_context->SetTaskRunnerForTesting( |
[email protected] | 198b590 | 2013-06-27 10:36:11 | [diff] [blame] | 4479 | base::MessageLoop::current()->message_loop_proxy().get()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4480 | base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4481 | EXPECT_TRUE(base::CreateDirectory(idb_path)); |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4482 | EXPECT_TRUE(base::DirectoryExists(idb_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4483 | |
| 4484 | // Uninstall one of them, unlimited storage should still be granted |
| 4485 | // to the origin. |
| 4486 | UninstallExtension(id1, false); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4487 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4488 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 4489 | origin1)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4490 | |
| 4491 | // Check that the cookie is still there. |
| 4492 | cookie_monster->GetAllCookiesForURLAsync( |
| 4493 | origin1, |
| 4494 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4495 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4496 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4497 | EXPECT_EQ(1U, callback.list_.size()); |
| 4498 | |
| 4499 | // Now uninstall the other. Storage should be cleared for the apps. |
| 4500 | UninstallExtension(id2, false); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4501 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4502 | EXPECT_FALSE( |
| 4503 | profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 4504 | origin1)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4505 | |
| 4506 | // Check that the cookie is gone. |
| 4507 | cookie_monster->GetAllCookiesForURLAsync( |
| 4508 | origin1, |
| 4509 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4510 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4511 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4512 | EXPECT_EQ(0U, callback.list_.size()); |
| 4513 | |
| 4514 | // The database should have vanished as well. |
| 4515 | origins.clear(); |
| 4516 | db_tracker->GetAllOriginsInfo(&origins); |
| 4517 | EXPECT_EQ(0U, origins.size()); |
| 4518 | |
| 4519 | // Check that the LSO file has been removed. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4520 | EXPECT_FALSE(base::PathExists(lso_file_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4521 | |
| 4522 | // Check if the indexed db has disappeared too. |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4523 | EXPECT_FALSE(base::DirectoryExists(idb_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4524 | } |
| 4525 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4526 | // Tests loading single extensions (like --load-extension) |
[email protected] | e3f610b | 2013-05-03 02:22:38 | [diff] [blame] | 4527 | // Flaky crashes. http://crbug.com/231806 |
| 4528 | TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4529 | InitializeEmptyExtensionService(); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 4530 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4531 | base::FilePath ext1 = data_dir() |
| 4532 | .AppendASCII("good") |
| 4533 | .AppendASCII("Extensions") |
| 4534 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 4535 | .AppendASCII("1.0.0.0"); |
| 4536 | extensions::UnpackedInstaller::Create(service())->Load(ext1); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4537 | base::RunLoop().RunUntilIdle(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 4538 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4539 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 4540 | EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4541 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 4542 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 4543 | ValidatePrefKeyCount(1); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4544 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4545 | base::FilePath no_manifest = |
| 4546 | data_dir() |
| 4547 | .AppendASCII("bad") |
| 4548 | // .AppendASCII("Extensions") |
| 4549 | .AppendASCII("cccccccccccccccccccccccccccccccc") |
| 4550 | .AppendASCII("1"); |
| 4551 | extensions::UnpackedInstaller::Create(service())->Load(no_manifest); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4552 | base::RunLoop().RunUntilIdle(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 4553 | EXPECT_EQ(1u, GetErrors().size()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4554 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4555 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4556 | |
| 4557 | // Test uninstall. |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4558 | std::string id = loaded_[0]->id(); |
| 4559 | EXPECT_FALSE(unloaded_id_.length()); |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 4560 | service()->UninstallExtension(id, |
| 4561 | extensions::UNINSTALL_REASON_FOR_TESTING, |
| 4562 | base::Bind(&base::DoNothing), |
| 4563 | NULL); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4564 | base::RunLoop().RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4565 | EXPECT_EQ(id, unloaded_id_); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4566 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4567 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 4568 | } |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4569 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4570 | // Tests that we generate IDs when they are not specified in the manifest for |
| 4571 | // --load-extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4572 | TEST_F(ExtensionServiceTest, GenerateID) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4573 | InitializeEmptyExtensionService(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 4574 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4575 | base::FilePath no_id_ext = data_dir().AppendASCII("no_id"); |
| 4576 | extensions::UnpackedInstaller::Create(service())->Load(no_id_ext); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4577 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4578 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4579 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 4580 | ASSERT_TRUE(crx_file::id_util::IdIsValid(loaded_[0]->id())); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 4581 | EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4582 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 4583 | ValidatePrefKeyCount(1); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4584 | |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 4585 | std::string previous_id = loaded_[0]->id(); |
| 4586 | |
| 4587 | // If we reload the same path, we should get the same extension ID. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4588 | extensions::UnpackedInstaller::Create(service())->Load(no_id_ext); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4589 | base::RunLoop().RunUntilIdle(); |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 4590 | ASSERT_EQ(1u, loaded_.size()); |
| 4591 | ASSERT_EQ(previous_id, loaded_[0]->id()); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4592 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4593 | |
[email protected] | 557c7bd | 2013-09-18 21:51:25 | [diff] [blame] | 4594 | TEST_F(ExtensionServiceTest, UnpackedValidatesLocales) { |
| 4595 | InitializeEmptyExtensionService(); |
| 4596 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4597 | base::FilePath bad_locale = |
| 4598 | data_dir().AppendASCII("unpacked").AppendASCII("bad_messages_file"); |
| 4599 | extensions::UnpackedInstaller::Create(service())->Load(bad_locale); |
[email protected] | 557c7bd | 2013-09-18 21:51:25 | [diff] [blame] | 4600 | base::RunLoop().RunUntilIdle(); |
| 4601 | EXPECT_EQ(1u, GetErrors().size()); |
| 4602 | base::FilePath ms_messages_file = bad_locale.AppendASCII("_locales") |
| 4603 | .AppendASCII("ms") |
| 4604 | .AppendASCII("messages.json"); |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 4605 | EXPECT_THAT(base::UTF16ToUTF8(GetErrors()[0]), testing::AllOf( |
| 4606 | testing::HasSubstr( |
| 4607 | base::UTF16ToUTF8(ms_messages_file.LossyDisplayName())), |
[email protected] | 557c7bd | 2013-09-18 21:51:25 | [diff] [blame] | 4608 | testing::HasSubstr("Dictionary keys must be quoted."))); |
| 4609 | ASSERT_EQ(0u, loaded_.size()); |
| 4610 | } |
| 4611 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4612 | void ExtensionServiceTest::TestExternalProvider( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4613 | MockExtensionProvider* provider, Manifest::Location location) { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4614 | // Verify that starting with no providers loads no extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4615 | service()->Init(); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4616 | ASSERT_EQ(0u, loaded_.size()); |
| 4617 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4618 | provider->set_visit_count(0); |
| 4619 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4620 | // Register a test extension externally using the mock registry provider. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4621 | base::FilePath source_path = data_dir().AppendASCII("good.crx"); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4622 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4623 | // Add the extension. |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4624 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4625 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4626 | // Reloading extensions should find our externally registered extension |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4627 | // and install it. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4628 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 4629 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4630 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4631 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4632 | observer.Wait(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4633 | |
| 4634 | ASSERT_EQ(0u, GetErrors().size()); |
| 4635 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4636 | ASSERT_EQ(location, loaded_[0]->location()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4637 | ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4638 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4639 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4640 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4641 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4642 | // Reload extensions without changing anything. The extension should be |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4643 | // loaded again. |
| 4644 | loaded_.clear(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4645 | service()->ReloadExtensionsForTest(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4646 | base::RunLoop().RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4647 | ASSERT_EQ(0u, GetErrors().size()); |
| 4648 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4649 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4650 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4651 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 4652 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4653 | // Now update the extension with a new version. We should get upgraded. |
| 4654 | source_path = source_path.DirName().AppendASCII("good2.crx"); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4655 | provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4656 | |
| 4657 | loaded_.clear(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4658 | content::WindowedNotificationObserver observer_2( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 4659 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4660 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4661 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4662 | observer_2.Wait(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4663 | ASSERT_EQ(0u, GetErrors().size()); |
| 4664 | ASSERT_EQ(1u, loaded_.size()); |
| 4665 | ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4666 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4667 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4668 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4669 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4670 | // Uninstall the extension and reload. Nothing should happen because the |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4671 | // preference should prevent us from reinstalling. |
| 4672 | std::string id = loaded_[0]->id(); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 4673 | bool no_uninstall = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4674 | GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL); |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 4675 | service()->UninstallExtension(id, |
| 4676 | extensions::UNINSTALL_REASON_FOR_TESTING, |
| 4677 | base::Bind(&base::DoNothing), |
| 4678 | NULL); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4679 | base::RunLoop().RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4680 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4681 | base::FilePath install_path = extensions_install_dir().AppendASCII(id); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 4682 | if (no_uninstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 4683 | // Policy controlled extensions should not have been touched by uninstall. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4684 | ASSERT_TRUE(base::PathExists(install_path)); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 4685 | } else { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4686 | // The extension should also be gone from the install directory. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4687 | ASSERT_FALSE(base::PathExists(install_path)); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4688 | loaded_.clear(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4689 | service()->CheckForExternalUpdates(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4690 | base::RunLoop().RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4691 | ASSERT_EQ(0u, loaded_.size()); |
| 4692 | ValidatePrefKeyCount(1); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 4693 | ValidateIntegerPref(good_crx, "state", |
| 4694 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4695 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4696 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4697 | // Now clear the preference and reinstall. |
| 4698 | SetPrefInteg(good_crx, "state", Extension::ENABLED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4699 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4700 | loaded_.clear(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4701 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 4702 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4703 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4704 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4705 | observer.Wait(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4706 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4707 | } |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4708 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4709 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4710 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4711 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4712 | if (GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL)) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 4713 | EXPECT_EQ(2, provider->visit_count()); |
| 4714 | } else { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4715 | // Now test an externally triggered uninstall (deleting the registry key or |
| 4716 | // the pref entry). |
| 4717 | provider->RemoveExtension(good_crx); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4718 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4719 | loaded_.clear(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4720 | service()->OnExternalProviderReady(provider); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4721 | base::RunLoop().RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4722 | ASSERT_EQ(0u, loaded_.size()); |
| 4723 | ValidatePrefKeyCount(0); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4724 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4725 | // The extension should also be gone from the install directory. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4726 | ASSERT_FALSE(base::PathExists(install_path)); |
[email protected] | abe7a894 | 2009-06-23 05:14:29 | [diff] [blame] | 4727 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4728 | // Now test the case where user uninstalls and then the extension is removed |
| 4729 | // from the external provider. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4730 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 4731 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4732 | content::NotificationService::AllSources()); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 4733 | provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4734 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4735 | observer.Wait(); |
[email protected] | abe7a894 | 2009-06-23 05:14:29 | [diff] [blame] | 4736 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4737 | ASSERT_EQ(1u, loaded_.size()); |
| 4738 | ASSERT_EQ(0u, GetErrors().size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4739 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4740 | // User uninstalls. |
| 4741 | loaded_.clear(); |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 4742 | service()->UninstallExtension(id, |
| 4743 | extensions::UNINSTALL_REASON_FOR_TESTING, |
| 4744 | base::Bind(&base::DoNothing), |
| 4745 | NULL); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4746 | base::RunLoop().RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4747 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4748 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4749 | // Then remove the extension from the extension provider. |
| 4750 | provider->RemoveExtension(good_crx); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4751 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4752 | // Should still be at 0. |
| 4753 | loaded_.clear(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4754 | extensions::InstalledLoader(service()).LoadAllExtensions(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4755 | base::RunLoop().RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4756 | ASSERT_EQ(0u, loaded_.size()); |
| 4757 | ValidatePrefKeyCount(1); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4758 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4759 | EXPECT_EQ(5, provider->visit_count()); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4760 | } |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4761 | } |
| 4762 | |
| 4763 | // Tests the external installation feature |
| 4764 | #if defined(OS_WIN) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4765 | TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4766 | // This should all work, even when normal extension installation is disabled. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4767 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4768 | service()->set_extensions_enabled(false); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4769 | |
| 4770 | // Now add providers. Extension system takes ownership of the objects. |
| 4771 | MockExtensionProvider* reg_provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4772 | new MockExtensionProvider(service(), Manifest::EXTERNAL_REGISTRY); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4773 | AddMockExternalProvider(reg_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4774 | TestExternalProvider(reg_provider, Manifest::EXTERNAL_REGISTRY); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4775 | } |
| 4776 | #endif |
| 4777 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4778 | TEST_F(ExtensionServiceTest, ExternalInstallPref) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4779 | InitializeEmptyExtensionService(); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4780 | |
| 4781 | // Now add providers. Extension system takes ownership of the objects. |
| 4782 | MockExtensionProvider* pref_provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4783 | new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4784 | |
| 4785 | AddMockExternalProvider(pref_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4786 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4787 | } |
| 4788 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4789 | TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4790 | // This should all work, even when normal extension installation is disabled. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4791 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4792 | service()->set_extensions_enabled(false); |
[email protected] | 55196e9 | 2010-09-29 15:04:46 | [diff] [blame] | 4793 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4794 | // TODO(skerner): The mock provider is not a good model of a provider |
| 4795 | // that works with update URLs, because it adds file and version info. |
| 4796 | // Extend the mock to work with update URLs. This test checks the |
| 4797 | // behavior that is common to all external extension visitors. The |
| 4798 | // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| 4799 | // what the visitor does results in an extension being downloaded and |
| 4800 | // installed. |
[email protected] | 55196e9 | 2010-09-29 15:04:46 | [diff] [blame] | 4801 | MockExtensionProvider* pref_provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4802 | new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF_DOWNLOAD); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4803 | AddMockExternalProvider(pref_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4804 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF_DOWNLOAD); |
[email protected] | 55196e9 | 2010-09-29 15:04:46 | [diff] [blame] | 4805 | } |
| 4806 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4807 | TEST_F(ExtensionServiceTest, ExternalInstallPolicyUpdateUrl) { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4808 | // This should all work, even when normal extension installation is disabled. |
| 4809 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4810 | service()->set_extensions_enabled(false); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4811 | |
| 4812 | // TODO(skerner): The mock provider is not a good model of a provider |
| 4813 | // that works with update URLs, because it adds file and version info. |
| 4814 | // Extend the mock to work with update URLs. This test checks the |
| 4815 | // behavior that is common to all external extension visitors. The |
| 4816 | // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| 4817 | // what the visitor does results in an extension being downloaded and |
| 4818 | // installed. |
| 4819 | MockExtensionProvider* pref_provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4820 | new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4821 | AddMockExternalProvider(pref_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4822 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4823 | } |
| 4824 | |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4825 | // Tests that external extensions get uninstalled when the external extension |
| 4826 | // providers can't account for them. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4827 | TEST_F(ExtensionServiceTest, ExternalUninstall) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4828 | // Start the extensions service with one external extension already installed. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4829 | base::FilePath source_install_dir = |
| 4830 | data_dir().AppendASCII("good").AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4831 | base::FilePath pref_path = source_install_dir |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4832 | .DirName() |
| 4833 | .AppendASCII("PreferencesExternal"); |
| 4834 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 4835 | // This initializes the extensions service with no ExternalProviders. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4836 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4837 | service()->set_extensions_enabled(false); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4838 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4839 | service()->Init(); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4840 | |
| 4841 | ASSERT_EQ(0u, GetErrors().size()); |
[email protected] | 1f4728f | 2012-12-05 20:40:05 | [diff] [blame] | 4842 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4843 | |
| 4844 | // Verify that it's not the disabled extensions flag causing it not to load. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4845 | service()->set_extensions_enabled(true); |
| 4846 | service()->ReloadExtensionsForTest(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4847 | base::RunLoop().RunUntilIdle(); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4848 | |
| 4849 | ASSERT_EQ(0u, GetErrors().size()); |
| 4850 | ASSERT_EQ(0u, loaded_.size()); |
| 4851 | } |
| 4852 | |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4853 | // Test that running multiple update checks simultaneously does not |
| 4854 | // keep the update from succeeding. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4855 | TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4856 | InitializeEmptyExtensionService(); |
| 4857 | |
| 4858 | MockExtensionProvider* provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4859 | new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4860 | AddMockExternalProvider(provider); |
| 4861 | |
| 4862 | // Verify that starting with no providers loads no extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4863 | service()->Init(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4864 | ASSERT_EQ(0u, loaded_.size()); |
| 4865 | |
| 4866 | // Start two checks for updates. |
| 4867 | provider->set_visit_count(0); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4868 | service()->CheckForExternalUpdates(); |
| 4869 | service()->CheckForExternalUpdates(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4870 | base::RunLoop().RunUntilIdle(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4871 | |
| 4872 | // Two calls should cause two checks for external extensions. |
| 4873 | EXPECT_EQ(2, provider->visit_count()); |
| 4874 | EXPECT_EQ(0u, GetErrors().size()); |
| 4875 | EXPECT_EQ(0u, loaded_.size()); |
| 4876 | |
| 4877 | // Register a test extension externally using the mock registry provider. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4878 | base::FilePath source_path = data_dir().AppendASCII("good.crx"); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4879 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); |
| 4880 | |
| 4881 | // Two checks for external updates should find the extension, and install it |
| 4882 | // once. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4883 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 4884 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4885 | content::NotificationService::AllSources()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4886 | provider->set_visit_count(0); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4887 | service()->CheckForExternalUpdates(); |
| 4888 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4889 | observer.Wait(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4890 | EXPECT_EQ(2, provider->visit_count()); |
| 4891 | ASSERT_EQ(0u, GetErrors().size()); |
| 4892 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4893 | ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4894 | ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); |
| 4895 | ValidatePrefKeyCount(1); |
| 4896 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4897 | ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4898 | |
| 4899 | provider->RemoveExtension(good_crx); |
| 4900 | provider->set_visit_count(0); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4901 | service()->CheckForExternalUpdates(); |
| 4902 | service()->CheckForExternalUpdates(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4903 | base::RunLoop().RunUntilIdle(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4904 | |
| 4905 | // Two calls should cause two checks for external extensions. |
| 4906 | // Because the external source no longer includes good_crx, |
| 4907 | // good_crx will be uninstalled. So, expect that no extensions |
| 4908 | // are loaded. |
| 4909 | EXPECT_EQ(2, provider->visit_count()); |
| 4910 | EXPECT_EQ(0u, GetErrors().size()); |
| 4911 | EXPECT_EQ(0u, loaded_.size()); |
| 4912 | } |
| 4913 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4914 | TEST_F(ExtensionServiceTest, ExternalPrefProvider) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4915 | InitializeEmptyExtensionService(); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4916 | |
| 4917 | // Test some valid extension records. |
| 4918 | // Set a base path to avoid erroring out on relative paths. |
| 4919 | // Paths starting with // are absolute on every platform we support. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4920 | base::FilePath base_path(FILE_PATH_LITERAL("//base/path")); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4921 | ASSERT_TRUE(base_path.IsAbsolute()); |
| 4922 | MockProviderVisitor visitor(base_path); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4923 | std::string json_data = |
| 4924 | "{" |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4925 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4926 | " \"external_crx\": \"RandomExtension.crx\"," |
| 4927 | " \"external_version\": \"1.0\"" |
| 4928 | " }," |
| 4929 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 4930 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 4931 | " \"external_version\": \"2.0\"" |
| 4932 | " }," |
| 4933 | " \"cccccccccccccccccccccccccccccccc\": {" |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 4934 | " \"external_update_url\": \"http:\\\\foo.com/update\"," |
| 4935 | " \"install_parameter\": \"id\"" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4936 | " }" |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4937 | "}"; |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4938 | EXPECT_EQ(3, visitor.Visit(json_data)); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4939 | |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4940 | // Simulate an external_extensions.json file that contains seven invalid |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4941 | // records: |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4942 | // - One that is missing the 'external_crx' key. |
| 4943 | // - One that is missing the 'external_version' key. |
| 4944 | // - One that is specifying .. in the path. |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 4945 | // - One that specifies both a file and update URL. |
| 4946 | // - One that specifies no file or update URL. |
| 4947 | // - One that has an update URL that is not well formed. |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4948 | // - One that contains a malformed version. |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 4949 | // - One that has an invalid id. |
| 4950 | // - One that has a non-dictionary value. |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 4951 | // - One that has an integer 'external_version' instead of a string. |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4952 | // The final extension is valid, and we check that it is read to make sure |
| 4953 | // failures don't stop valid records from being read. |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4954 | json_data = |
| 4955 | "{" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4956 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 4957 | " \"external_version\": \"1.0\"" |
| 4958 | " }," |
| 4959 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 4960 | " \"external_crx\": \"RandomExtension.crx\"" |
| 4961 | " }," |
| 4962 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 4963 | " \"external_crx\": \"..\\\\foo\\\\RandomExtension2.crx\"," |
| 4964 | " \"external_version\": \"2.0\"" |
| 4965 | " }," |
| 4966 | " \"dddddddddddddddddddddddddddddddd\": {" |
| 4967 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 4968 | " \"external_version\": \"2.0\"," |
| 4969 | " \"external_update_url\": \"http:\\\\foo.com/update\"" |
| 4970 | " }," |
| 4971 | " \"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\": {" |
| 4972 | " }," |
| 4973 | " \"ffffffffffffffffffffffffffffffff\": {" |
| 4974 | " \"external_update_url\": \"This string is not a valid URL\"" |
| 4975 | " }," |
| 4976 | " \"gggggggggggggggggggggggggggggggg\": {" |
| 4977 | " \"external_crx\": \"RandomExtension3.crx\"," |
| 4978 | " \"external_version\": \"This is not a valid version!\"" |
| 4979 | " }," |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 4980 | " \"This is not a valid id!\": {}," |
| 4981 | " \"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\": true," |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 4982 | " \"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\": {" |
| 4983 | " \"external_crx\": \"RandomExtension4.crx\"," |
| 4984 | " \"external_version\": 1.0" |
| 4985 | " }," |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 4986 | " \"pppppppppppppppppppppppppppppppp\": {" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4987 | " \"external_crx\": \"RandomValidExtension.crx\"," |
| 4988 | " \"external_version\": \"1.0\"" |
| 4989 | " }" |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4990 | "}"; |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 4991 | EXPECT_EQ(1, visitor.Visit(json_data)); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4992 | |
| 4993 | // Check that if a base path is not provided, use of a relative |
| 4994 | // path fails. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4995 | base::FilePath empty; |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4996 | MockProviderVisitor visitor_no_relative_paths(empty); |
| 4997 | |
| 4998 | // Use absolute paths. Expect success. |
| 4999 | json_data = |
| 5000 | "{" |
| 5001 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5002 | " \"external_crx\": \"//RandomExtension1.crx\"," |
| 5003 | " \"external_version\": \"3.0\"" |
| 5004 | " }," |
| 5005 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5006 | " \"external_crx\": \"//path/to/RandomExtension2.crx\"," |
| 5007 | " \"external_version\": \"3.0\"" |
| 5008 | " }" |
| 5009 | "}"; |
| 5010 | EXPECT_EQ(2, visitor_no_relative_paths.Visit(json_data)); |
| 5011 | |
| 5012 | // Use a relative path. Expect that it will error out. |
| 5013 | json_data = |
| 5014 | "{" |
| 5015 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 5016 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5017 | " \"external_version\": \"3.0\"" |
| 5018 | " }" |
| 5019 | "}"; |
| 5020 | EXPECT_EQ(0, visitor_no_relative_paths.Visit(json_data)); |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 5021 | |
| 5022 | // Test supported_locales. |
| 5023 | json_data = |
| 5024 | "{" |
| 5025 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5026 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5027 | " \"external_version\": \"1.0\"," |
| 5028 | " \"supported_locales\": [ \"en\" ]" |
| 5029 | " }," |
| 5030 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5031 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5032 | " \"external_version\": \"2.0\"," |
| 5033 | " \"supported_locales\": [ \"en-GB\" ]" |
| 5034 | " }," |
| 5035 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 5036 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5037 | " \"external_version\": \"3.0\"," |
| 5038 | " \"supported_locales\": [ \"en_US\", \"fr\" ]" |
| 5039 | " }" |
| 5040 | "}"; |
| 5041 | { |
| 5042 | ScopedBrowserLocale guard("en-US"); |
| 5043 | EXPECT_EQ(2, visitor.Visit(json_data)); |
| 5044 | } |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 5045 | |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 5046 | // Test keep_if_present. |
| 5047 | json_data = |
| 5048 | "{" |
| 5049 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5050 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5051 | " \"external_version\": \"1.0\"," |
| 5052 | " \"keep_if_present\": true" |
| 5053 | " }" |
| 5054 | "}"; |
| 5055 | { |
| 5056 | EXPECT_EQ(0, visitor.Visit(json_data)); |
| 5057 | } |
| 5058 | |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 5059 | // Test is_bookmark_app. |
| 5060 | MockProviderVisitor from_bookmark_visitor( |
| 5061 | base_path, Extension::FROM_BOOKMARK); |
| 5062 | json_data = |
| 5063 | "{" |
| 5064 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5065 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5066 | " \"external_version\": \"1.0\"," |
| 5067 | " \"is_bookmark_app\": true" |
| 5068 | " }" |
| 5069 | "}"; |
| 5070 | EXPECT_EQ(1, from_bookmark_visitor.Visit(json_data)); |
[email protected] | 7425d7df | 2012-11-28 14:35:42 | [diff] [blame] | 5071 | |
| 5072 | // Test is_from_webstore. |
| 5073 | MockProviderVisitor from_webstore_visitor( |
| 5074 | base_path, Extension::FROM_WEBSTORE); |
| 5075 | json_data = |
| 5076 | "{" |
| 5077 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5078 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5079 | " \"external_version\": \"1.0\"," |
| 5080 | " \"is_from_webstore\": true" |
| 5081 | " }" |
| 5082 | "}"; |
| 5083 | EXPECT_EQ(1, from_webstore_visitor.Visit(json_data)); |
[email protected] | bf9fd5ae | 2014-04-09 22:50:06 | [diff] [blame] | 5084 | |
| 5085 | // Test was_installed_by_eom. |
| 5086 | MockProviderVisitor was_installed_by_eom_visitor( |
| 5087 | base_path, Extension::WAS_INSTALLED_BY_OEM); |
| 5088 | json_data = |
| 5089 | "{" |
| 5090 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5091 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5092 | " \"external_version\": \"1.0\"," |
| 5093 | " \"was_installed_by_oem\": true" |
| 5094 | " }" |
| 5095 | "}"; |
| 5096 | EXPECT_EQ(1, was_installed_by_eom_visitor.Visit(json_data)); |
[email protected] | e18236b | 2009-06-22 21:32:10 | [diff] [blame] | 5097 | } |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5098 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5099 | // Test loading good extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5100 | TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) { |
[email protected] | 6884a80 | 2012-08-07 03:55:22 | [diff] [blame] | 5101 | // Ensure we're testing in "en" and leave global state untouched. |
| 5102 | extension_l10n_util::ScopedLocaleForTest testLocale("en"); |
| 5103 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5104 | // Initialize the test dir with a good Preferences/extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5105 | base::FilePath source_install_dir = data_dir().AppendASCII("l10n"); |
[email protected] | e96a060 | 2014-02-15 08:27:42 | [diff] [blame] | 5106 | base::FilePath pref_path = |
| 5107 | source_install_dir.Append(chrome::kPreferencesFilename); |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5108 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5109 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5110 | service()->Init(); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5111 | |
| 5112 | ASSERT_EQ(3u, loaded_.size()); |
| 5113 | |
| 5114 | // This was equal to "sr" on load. |
| 5115 | ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en"); |
| 5116 | |
| 5117 | // These are untouched by re-localization. |
| 5118 | ValidateStringPref(loaded_[1]->id(), keys::kCurrentLocale, "en"); |
| 5119 | EXPECT_FALSE(IsPrefExist(loaded_[1]->id(), keys::kCurrentLocale)); |
| 5120 | |
| 5121 | // This one starts with Serbian name, and gets re-localized into English. |
| 5122 | EXPECT_EQ("My name is simple.", loaded_[0]->name()); |
| 5123 | |
| 5124 | // These are untouched by re-localization. |
| 5125 | EXPECT_EQ("My name is simple.", loaded_[1]->name()); |
| 5126 | EXPECT_EQ("no l10n", loaded_[2]->name()); |
| 5127 | } |
| 5128 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5129 | class ExtensionsReadyRecorder : public content::NotificationObserver { |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5130 | public: |
| 5131 | ExtensionsReadyRecorder() : ready_(false) { |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 5132 | registrar_.Add(this, |
| 5133 | extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 5134 | content::NotificationService::AllSources()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5135 | } |
| 5136 | |
| 5137 | void set_ready(bool value) { ready_ = value; } |
| 5138 | bool ready() { return ready_; } |
| 5139 | |
| 5140 | private: |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 5141 | virtual void Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5142 | const content::NotificationSource& source, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 5143 | const content::NotificationDetails& details) OVERRIDE { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 5144 | switch (type) { |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 5145 | case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5146 | ready_ = true; |
| 5147 | break; |
| 5148 | default: |
| 5149 | NOTREACHED(); |
| 5150 | } |
| 5151 | } |
| 5152 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5153 | content::NotificationRegistrar registrar_; |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5154 | bool ready_; |
| 5155 | }; |
| 5156 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5157 | // Test that we get enabled/disabled correctly for all the pref/command-line |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5158 | // combinations. We don't want to derive from the ExtensionServiceTest class |
| 5159 | // for this test, so we use ExtensionServiceTestSimple. |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5160 | // |
| 5161 | // Also tests that we always fire EXTENSIONS_READY, no matter whether we are |
| 5162 | // enabled or not. |
[email protected] | 39fdf520 | 2012-11-14 00:38:17 | [diff] [blame] | 5163 | TEST(ExtensionServiceTestSimple, Enabledness) { |
[email protected] | 5a24d2b | 2012-11-14 20:38:31 | [diff] [blame] | 5164 | // Make sure the PluginService singleton is destroyed at the end of the test. |
[email protected] | 39fdf520 | 2012-11-14 00:38:17 | [diff] [blame] | 5165 | base::ShadowingAtExitManager at_exit_manager; |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 5166 | #if defined(ENABLE_PLUGINS) |
| 5167 | content::PluginService::GetInstance()->Init(); |
| 5168 | content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting(); |
| 5169 | #endif |
[email protected] | 5a24d2b | 2012-11-14 20:38:31 | [diff] [blame] | 5170 | |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 5171 | ExtensionErrorReporter::Init(false); // no noisy errors |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5172 | ExtensionsReadyRecorder recorder; |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 5173 | scoped_ptr<TestingProfile> profile(new TestingProfile()); |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 5174 | content::TestBrowserThreadBundle thread_bundle_; |
[email protected] | e4854dc | 2013-04-24 00:11:51 | [diff] [blame] | 5175 | #if defined OS_CHROMEOS |
| 5176 | chromeos::ScopedTestDeviceSettingsService device_settings_service; |
| 5177 | chromeos::ScopedTestCrosSettings cros_settings; |
| 5178 | scoped_ptr<chromeos::ScopedTestUserManager> user_manager( |
| 5179 | new chromeos::ScopedTestUserManager); |
| 5180 | #endif |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5181 | scoped_ptr<CommandLine> command_line; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5182 | base::FilePath install_dir = profile->GetPath() |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 5183 | .AppendASCII(extensions::kInstallDirectoryName); |
[email protected] | be5a6db | 2012-11-13 14:39:11 | [diff] [blame] | 5184 | |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5185 | // By default, we are enabled. |
[email protected] | 947446b | 2010-10-21 03:36:31 | [diff] [blame] | 5186 | command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5187 | ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5188 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5189 | CreateExtensionService( |
| 5190 | command_line.get(), |
| 5191 | install_dir, |
| 5192 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5193 | EXPECT_TRUE(service->extensions_enabled()); |
| 5194 | service->Init(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5195 | base::RunLoop().RunUntilIdle(); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5196 | EXPECT_TRUE(recorder.ready()); |
[email protected] | e4854dc | 2013-04-24 00:11:51 | [diff] [blame] | 5197 | #if defined OS_CHROMEOS |
| 5198 | user_manager.reset(); |
| 5199 | #endif |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5200 | |
| 5201 | // If either the command line or pref is set, we are disabled. |
| 5202 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 5203 | profile.reset(new TestingProfile()); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5204 | command_line->AppendSwitch(switches::kDisableExtensions); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5205 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5206 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5207 | CreateExtensionService( |
| 5208 | command_line.get(), |
| 5209 | install_dir, |
| 5210 | false); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5211 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5212 | service->Init(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5213 | base::RunLoop().RunUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5214 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5215 | |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5216 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 5217 | profile.reset(new TestingProfile()); |
| 5218 | profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5219 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5220 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5221 | CreateExtensionService( |
| 5222 | command_line.get(), |
| 5223 | install_dir, |
| 5224 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5225 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5226 | service->Init(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5227 | base::RunLoop().RunUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5228 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5229 | |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5230 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 5231 | profile.reset(new TestingProfile()); |
| 5232 | profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
[email protected] | 947446b | 2010-10-21 03:36:31 | [diff] [blame] | 5233 | command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5234 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5235 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5236 | CreateExtensionService( |
| 5237 | command_line.get(), |
| 5238 | install_dir, |
| 5239 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5240 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5241 | service->Init(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5242 | base::RunLoop().RunUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5243 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 7e1951a | 2010-09-30 10:22:20 | [diff] [blame] | 5244 | |
| 5245 | // Explicitly delete all the resources used in this test. |
| 5246 | profile.reset(); |
| 5247 | service = NULL; |
[email protected] | 060d497 | 2012-07-19 17:22:39 | [diff] [blame] | 5248 | // Execute any pending deletion tasks. |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5249 | base::RunLoop().RunUntilIdle(); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5250 | } |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5251 | |
| 5252 | // Test loading extensions that require limited and unlimited storage quotas. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5253 | TEST_F(ExtensionServiceTest, StorageQuota) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5254 | InitializeEmptyExtensionService(); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5255 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5256 | base::FilePath extensions_path = data_dir().AppendASCII("storage_quota"); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5257 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5258 | base::FilePath limited_quota_ext = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 5259 | extensions_path.AppendASCII("limited_quota") |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5260 | .AppendASCII("1.0"); |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 5261 | |
| 5262 | // The old permission name for unlimited quota was "unlimited_storage", but |
| 5263 | // we changed it to "unlimitedStorage". This tests both versions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5264 | base::FilePath unlimited_quota_ext = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 5265 | extensions_path.AppendASCII("unlimited_quota") |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5266 | .AppendASCII("1.0"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5267 | base::FilePath unlimited_quota_ext2 = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 5268 | extensions_path.AppendASCII("unlimited_quota") |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 5269 | .AppendASCII("2.0"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5270 | extensions::UnpackedInstaller::Create(service())->Load(limited_quota_ext); |
| 5271 | extensions::UnpackedInstaller::Create(service())->Load(unlimited_quota_ext); |
| 5272 | extensions::UnpackedInstaller::Create(service())->Load(unlimited_quota_ext2); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5273 | base::RunLoop().RunUntilIdle(); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5274 | |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 5275 | ASSERT_EQ(3u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5276 | EXPECT_TRUE(profile()); |
| 5277 | EXPECT_FALSE(profile()->IsOffTheRecord()); |
| 5278 | EXPECT_FALSE( |
| 5279 | profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 5280 | loaded_[0]->url())); |
| 5281 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
[email protected] | 7c5f2ec | 2011-05-26 19:15:26 | [diff] [blame] | 5282 | loaded_[1]->url())); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5283 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
[email protected] | 7c5f2ec | 2011-05-26 19:15:26 | [diff] [blame] | 5284 | loaded_[2]->url())); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5285 | } |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5286 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 5287 | // Tests ComponentLoader::Add(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5288 | TEST_F(ExtensionServiceTest, ComponentExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5289 | InitializeEmptyExtensionService(); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5290 | |
[email protected] | f0b97f1 | 2010-10-11 21:44:35 | [diff] [blame] | 5291 | // Component extensions should work even when extensions are disabled. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5292 | service()->set_extensions_enabled(false); |
[email protected] | f0b97f1 | 2010-10-11 21:44:35 | [diff] [blame] | 5293 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5294 | base::FilePath path = data_dir() |
| 5295 | .AppendASCII("good") |
| 5296 | .AppendASCII("Extensions") |
| 5297 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 5298 | .AppendASCII("1.0.0.0"); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5299 | |
| 5300 | std::string manifest; |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 5301 | ASSERT_TRUE(base::ReadFileToString( |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 5302 | path.Append(extensions::kManifestFilename), &manifest)); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5303 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5304 | service()->component_loader()->Add(manifest, path); |
| 5305 | service()->Init(); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5306 | |
| 5307 | // Note that we do not pump messages -- the extension should be loaded |
| 5308 | // immediately. |
| 5309 | |
| 5310 | EXPECT_EQ(0u, GetErrors().size()); |
| 5311 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5312 | EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5313 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5314 | |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 5315 | // Component extensions get a prefs entry on first install. |
| 5316 | ValidatePrefKeyCount(1); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5317 | |
| 5318 | // Reload all extensions, and make sure it comes back. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5319 | std::string extension_id = (*registry()->enabled_extensions().begin())->id(); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5320 | loaded_.clear(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5321 | service()->ReloadExtensionsForTest(); |
| 5322 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 5323 | EXPECT_EQ(extension_id, (*registry()->enabled_extensions().begin())->id()); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5324 | } |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5325 | |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5326 | TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledComponent) { |
| 5327 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5328 | InitializeExtensionSyncService(); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5329 | |
| 5330 | bool flare_was_called = false; |
| 5331 | syncer::ModelType triggered_type(syncer::UNSPECIFIED); |
| 5332 | base::WeakPtrFactory<ExtensionServiceTest> factory(this); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5333 | extension_sync_service()->SetSyncStartFlare( |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5334 | base::Bind(&ExtensionServiceTest::MockSyncStartFlare, |
| 5335 | factory.GetWeakPtr(), |
| 5336 | &flare_was_called, // Safe due to WeakPtrFactory scope. |
| 5337 | &triggered_type)); // Safe due to WeakPtrFactory scope. |
| 5338 | |
| 5339 | // Install a component extension. |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5340 | std::string manifest; |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 5341 | ASSERT_TRUE(base::ReadFileToString( |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 5342 | good0_path().Append(extensions::kManifestFilename), &manifest)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5343 | service()->component_loader()->Add(manifest, good0_path()); |
| 5344 | ASSERT_FALSE(service()->is_ready()); |
| 5345 | service()->Init(); |
| 5346 | ASSERT_TRUE(service()->is_ready()); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5347 | |
| 5348 | // Extensions added before service is_ready() don't trigger sync startup. |
| 5349 | EXPECT_FALSE(flare_was_called); |
| 5350 | ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); |
| 5351 | } |
| 5352 | |
| 5353 | TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledNormal) { |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 5354 | InitializeGoodInstalledExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5355 | InitializeExtensionSyncService(); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5356 | |
| 5357 | bool flare_was_called = false; |
| 5358 | syncer::ModelType triggered_type(syncer::UNSPECIFIED); |
| 5359 | base::WeakPtrFactory<ExtensionServiceTest> factory(this); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5360 | extension_sync_service()->SetSyncStartFlare( |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5361 | base::Bind(&ExtensionServiceTest::MockSyncStartFlare, |
| 5362 | factory.GetWeakPtr(), |
| 5363 | &flare_was_called, // Safe due to WeakPtrFactory scope. |
| 5364 | &triggered_type)); // Safe due to WeakPtrFactory scope. |
| 5365 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5366 | ASSERT_FALSE(service()->is_ready()); |
| 5367 | service()->Init(); |
[email protected] | 50736a1 | 2013-09-26 08:58:34 | [diff] [blame] | 5368 | ASSERT_EQ(3u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5369 | ASSERT_TRUE(service()->is_ready()); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5370 | |
| 5371 | // Extensions added before service is_ready() don't trigger sync startup. |
| 5372 | EXPECT_FALSE(flare_was_called); |
| 5373 | ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); |
| 5374 | } |
| 5375 | |
| 5376 | TEST_F(ExtensionServiceTest, DeferredSyncStartupOnInstall) { |
| 5377 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5378 | InitializeExtensionSyncService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5379 | service()->Init(); |
| 5380 | ASSERT_TRUE(service()->is_ready()); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5381 | |
| 5382 | bool flare_was_called = false; |
| 5383 | syncer::ModelType triggered_type(syncer::UNSPECIFIED); |
| 5384 | base::WeakPtrFactory<ExtensionServiceTest> factory(this); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5385 | extension_sync_service()->SetSyncStartFlare( |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5386 | base::Bind(&ExtensionServiceTest::MockSyncStartFlare, |
| 5387 | factory.GetWeakPtr(), |
| 5388 | &flare_was_called, // Safe due to WeakPtrFactory scope. |
| 5389 | &triggered_type)); // Safe due to WeakPtrFactory scope. |
| 5390 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5391 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5392 | InstallCRX(path, INSTALL_NEW); |
| 5393 | |
| 5394 | EXPECT_TRUE(flare_was_called); |
| 5395 | EXPECT_EQ(syncer::EXTENSIONS, triggered_type); |
| 5396 | |
| 5397 | // Reset. |
| 5398 | flare_was_called = false; |
| 5399 | triggered_type = syncer::UNSPECIFIED; |
| 5400 | |
| 5401 | // Once sync starts, flare should no longer be invoked. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5402 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5403 | syncer::EXTENSIONS, |
| 5404 | syncer::SyncDataList(), |
| 5405 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5406 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5407 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5408 | path = data_dir().AppendASCII("page_action.crx"); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5409 | InstallCRX(path, INSTALL_NEW); |
| 5410 | EXPECT_FALSE(flare_was_called); |
| 5411 | ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); |
| 5412 | } |
| 5413 | |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5414 | TEST_F(ExtensionServiceTest, DisableExtensionFromSync) { |
| 5415 | // Start the extensions service with one external extension already installed. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5416 | base::FilePath source_install_dir = |
| 5417 | data_dir().AppendASCII("good").AppendASCII("Extensions"); |
[email protected] | e96a060 | 2014-02-15 08:27:42 | [diff] [blame] | 5418 | base::FilePath pref_path = |
| 5419 | source_install_dir.DirName().Append(chrome::kPreferencesFilename); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5420 | |
| 5421 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 5422 | InitializeExtensionSyncService(); |
| 5423 | |
| 5424 | // The user has enabled sync. |
| 5425 | ProfileSyncService* sync_service = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5426 | ProfileSyncServiceFactory::GetForProfile(profile()); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5427 | sync_service->SetSyncSetupCompleted(); |
| 5428 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5429 | service()->Init(); |
| 5430 | ASSERT_TRUE(service()->is_ready()); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5431 | |
| 5432 | ASSERT_EQ(3u, loaded_.size()); |
| 5433 | |
| 5434 | // We start enabled. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5435 | const Extension* extension = service()->GetExtensionById(good0, true); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5436 | ASSERT_TRUE(extension); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5437 | ASSERT_TRUE(service()->IsExtensionEnabled(good0)); |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 5438 | extensions::ExtensionSyncData disable_good_crx( |
| 5439 | *extension, false, false, false); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5440 | |
| 5441 | // Then sync data arrives telling us to disable |good0|. |
| 5442 | syncer::SyncDataList sync_data; |
| 5443 | sync_data.push_back(disable_good_crx.GetSyncData()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5444 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5445 | syncer::EXTENSIONS, |
| 5446 | sync_data, |
| 5447 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5448 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5449 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5450 | ASSERT_FALSE(service()->IsExtensionEnabled(good0)); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | TEST_F(ExtensionServiceTest, DontDisableExtensionWithPendingEnableFromSync) { |
| 5454 | // Start the extensions service with one external extension already installed. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5455 | base::FilePath source_install_dir = |
| 5456 | data_dir().AppendASCII("good").AppendASCII("Extensions"); |
[email protected] | e96a060 | 2014-02-15 08:27:42 | [diff] [blame] | 5457 | base::FilePath pref_path = |
| 5458 | source_install_dir.DirName().Append(chrome::kPreferencesFilename); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5459 | |
| 5460 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 5461 | InitializeExtensionSyncService(); |
| 5462 | |
| 5463 | // The user has enabled sync. |
| 5464 | ProfileSyncService* sync_service = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5465 | ProfileSyncServiceFactory::GetForProfile(profile()); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5466 | sync_service->SetSyncSetupCompleted(); |
| 5467 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5468 | service()->Init(); |
| 5469 | ASSERT_TRUE(service()->is_ready()); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5470 | ASSERT_EQ(3u, loaded_.size()); |
| 5471 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5472 | const Extension* extension = service()->GetExtensionById(good0, true); |
| 5473 | ASSERT_TRUE(service()->IsExtensionEnabled(good0)); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5474 | |
| 5475 | // Disable extension before first sync data arrives. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5476 | service()->DisableExtension(good0, Extension::DISABLE_USER_ACTION); |
| 5477 | ASSERT_FALSE(service()->IsExtensionEnabled(good0)); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5478 | |
| 5479 | // Enable extension - this is now the most recent state. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5480 | service()->EnableExtension(good0); |
| 5481 | ASSERT_TRUE(service()->IsExtensionEnabled(good0)); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5482 | |
| 5483 | // Now sync data comes in that says to disable good0. This should be |
| 5484 | // ignored. |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 5485 | extensions::ExtensionSyncData disable_good_crx( |
| 5486 | *extension, false, false, false); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5487 | syncer::SyncDataList sync_data; |
| 5488 | sync_data.push_back(disable_good_crx.GetSyncData()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5489 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5490 | syncer::EXTENSIONS, |
| 5491 | sync_data, |
| 5492 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5493 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5494 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 5495 | |
| 5496 | // The extension was enabled locally before the sync data arrived, so it |
| 5497 | // should still be enabled now. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5498 | ASSERT_TRUE(service()->IsExtensionEnabled(good0)); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5499 | } |
| 5500 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5501 | TEST_F(ExtensionServiceTest, GetSyncData) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5502 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5503 | InitializeExtensionSyncService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5504 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 5505 | const Extension* extension = service()->GetInstalledExtension(good_crx); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5506 | ASSERT_TRUE(extension); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 5507 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5508 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5509 | syncer::EXTENSIONS, |
| 5510 | syncer::SyncDataList(), |
| 5511 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5512 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5513 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5514 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5515 | syncer::SyncDataList list = |
| 5516 | extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5517 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5518 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5519 | EXPECT_EQ(extension->id(), data.id()); |
| 5520 | EXPECT_FALSE(data.uninstalled()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5521 | EXPECT_EQ(service()->IsExtensionEnabled(good_crx), data.enabled()); |
| 5522 | EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile()), |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 5523 | data.incognito_enabled()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5524 | EXPECT_TRUE(data.version().Equals(*extension->version())); |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 5525 | EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension), |
| 5526 | data.update_url()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5527 | EXPECT_EQ(extension->name(), data.name()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5528 | } |
| 5529 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5530 | TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 5531 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5532 | InitializeExtensionSyncService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5533 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 5534 | TerminateExtension(good_crx); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5535 | const Extension* extension = service()->GetInstalledExtension(good_crx); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 5536 | ASSERT_TRUE(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5537 | |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5538 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5539 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5540 | syncer::EXTENSIONS, |
| 5541 | syncer::SyncDataList(), |
| 5542 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5543 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5544 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5545 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5546 | syncer::SyncDataList list = |
| 5547 | extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5548 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5549 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5550 | EXPECT_EQ(extension->id(), data.id()); |
| 5551 | EXPECT_FALSE(data.uninstalled()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5552 | EXPECT_EQ(service()->IsExtensionEnabled(good_crx), data.enabled()); |
| 5553 | EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile()), |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 5554 | data.incognito_enabled()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5555 | EXPECT_TRUE(data.version().Equals(*extension->version())); |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 5556 | EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension), |
| 5557 | data.update_url()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5558 | EXPECT_EQ(extension->name(), data.name()); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 5559 | } |
| 5560 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5561 | TEST_F(ExtensionServiceTest, GetSyncDataFilter) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5562 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5563 | InitializeExtensionSyncService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5564 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 5565 | const Extension* extension = service()->GetInstalledExtension(good_crx); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 5566 | ASSERT_TRUE(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5567 | |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5568 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5569 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5570 | syncer::APPS, |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5571 | syncer::SyncDataList(), |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5572 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5573 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5574 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5575 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5576 | syncer::SyncDataList list = |
| 5577 | extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5578 | ASSERT_EQ(list.size(), 0U); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5579 | } |
| 5580 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5581 | TEST_F(ExtensionServiceTest, GetSyncExtensionDataUserSettings) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5582 | InitializeEmptyExtensionService(); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 5583 | InitializeProcessManager(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5584 | InitializeExtensionSyncService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5585 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 5586 | const Extension* extension = service()->GetInstalledExtension(good_crx); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 5587 | ASSERT_TRUE(extension); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5588 | |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5589 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5590 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5591 | syncer::EXTENSIONS, |
| 5592 | syncer::SyncDataList(), |
| 5593 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5594 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5595 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5596 | |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5597 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5598 | syncer::SyncDataList list = |
| 5599 | extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5600 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5601 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5602 | EXPECT_TRUE(data.enabled()); |
| 5603 | EXPECT_FALSE(data.incognito_enabled()); |
| 5604 | } |
| 5605 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5606 | service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5607 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5608 | syncer::SyncDataList list = |
| 5609 | extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5610 | ASSERT_EQ(list.size(), 1U); |
| 5611 | extensions::ExtensionSyncData data(list[0]); |
| 5612 | EXPECT_FALSE(data.enabled()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5613 | EXPECT_FALSE(data.incognito_enabled()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5614 | } |
| 5615 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5616 | extensions::util::SetIsIncognitoEnabled(good_crx, profile(), true); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5617 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5618 | syncer::SyncDataList list = |
| 5619 | extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5620 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5621 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5622 | EXPECT_FALSE(data.enabled()); |
| 5623 | EXPECT_TRUE(data.incognito_enabled()); |
| 5624 | } |
| 5625 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5626 | service()->EnableExtension(good_crx); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5627 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5628 | syncer::SyncDataList list = |
| 5629 | extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5630 | ASSERT_EQ(list.size(), 1U); |
| 5631 | extensions::ExtensionSyncData data(list[0]); |
| 5632 | EXPECT_TRUE(data.enabled()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5633 | EXPECT_TRUE(data.incognito_enabled()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5634 | } |
| 5635 | } |
| 5636 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5637 | TEST_F(ExtensionServiceTest, SyncForUninstalledExternalExtension) { |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5638 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5639 | InitializeExtensionSyncService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5640 | InstallCRXWithLocation( |
| 5641 | data_dir().AppendASCII("good.crx"), Manifest::EXTERNAL_PREF, INSTALL_NEW); |
| 5642 | const Extension* extension = service()->GetInstalledExtension(good_crx); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5643 | ASSERT_TRUE(extension); |
| 5644 | |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5645 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5646 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5647 | syncer::EXTENSIONS, |
| 5648 | syncer::SyncDataList(), |
| 5649 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5650 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5651 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5652 | |
| 5653 | UninstallExtension(good_crx, false); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5654 | EXPECT_TRUE( |
| 5655 | ExtensionPrefs::Get(profile())->IsExternalExtensionUninstalled(good_crx)); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5656 | |
| 5657 | sync_pb::EntitySpecifics specifics; |
| 5658 | sync_pb::AppSpecifics* app_specifics = specifics.mutable_app(); |
| 5659 | sync_pb::ExtensionSpecifics* extension_specifics = |
| 5660 | app_specifics->mutable_extension(); |
| 5661 | extension_specifics->set_id(good_crx); |
| 5662 | extension_specifics->set_version("1.0"); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5663 | extension_specifics->set_enabled(true); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5664 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5665 | syncer::SyncData sync_data = |
| 5666 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5667 | syncer::SyncChange sync_change(FROM_HERE, |
| 5668 | syncer::SyncChange::ACTION_UPDATE, |
| 5669 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5670 | syncer::SyncChangeList list(1); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5671 | list[0] = sync_change; |
| 5672 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5673 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 5674 | EXPECT_TRUE( |
| 5675 | ExtensionPrefs::Get(profile())->IsExternalExtensionUninstalled(good_crx)); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5676 | } |
| 5677 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5678 | TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettings) { |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5679 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5680 | InitializeExtensionSyncService(); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5681 | const Extension* app = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5682 | PackAndInstallCRX(data_dir().AppendASCII("app"), INSTALL_NEW); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5683 | ASSERT_TRUE(app); |
| 5684 | ASSERT_TRUE(app->is_app()); |
| 5685 | |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5686 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5687 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5688 | syncer::APPS, |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5689 | syncer::SyncDataList(), |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5690 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5691 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5692 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5693 | |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 5694 | syncer::StringOrdinal initial_ordinal = |
| 5695 | syncer::StringOrdinal::CreateInitialOrdinal(); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5696 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5697 | syncer::SyncDataList list = |
| 5698 | extension_sync_service()->GetAllSyncData(syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5699 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5700 | |
| 5701 | extensions::AppSyncData app_sync_data(list[0]); |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 5702 | EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.app_launch_ordinal())); |
| 5703 | EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5704 | } |
| 5705 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5706 | AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting(); |
[email protected] | fb82dcd | 2012-03-21 14:15:46 | [diff] [blame] | 5707 | sorting->SetAppLaunchOrdinal(app->id(), initial_ordinal.CreateAfter()); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5708 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5709 | syncer::SyncDataList list = |
| 5710 | extension_sync_service()->GetAllSyncData(syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5711 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5712 | |
| 5713 | extensions::AppSyncData app_sync_data(list[0]); |
| 5714 | EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 5715 | EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5716 | } |
| 5717 | |
[email protected] | fb82dcd | 2012-03-21 14:15:46 | [diff] [blame] | 5718 | sorting->SetPageOrdinal(app->id(), initial_ordinal.CreateAfter()); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5719 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5720 | syncer::SyncDataList list = |
| 5721 | extension_sync_service()->GetAllSyncData(syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5722 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5723 | |
| 5724 | extensions::AppSyncData app_sync_data(list[0]); |
| 5725 | EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); |
| 5726 | EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.page_ordinal())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5727 | } |
| 5728 | } |
| 5729 | |
[email protected] | 74c5ea1 | 2014-03-19 23:14:39 | [diff] [blame] | 5730 | // TODO (rdevlin.cronin): The OnExtensionMoved() method has been removed from |
| 5731 | // ExtensionService, so this test probably needs a new home. Unfortunately, it |
| 5732 | // relies pretty heavily on things like InitializeExtension[Sync]Service() and |
| 5733 | // PackAndInstallCRX(). When we clean up a bit more, this should move out. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5734 | TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettingsOnExtensionMoved) { |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5735 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5736 | InitializeExtensionSyncService(); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5737 | const size_t kAppCount = 3; |
| 5738 | const Extension* apps[kAppCount]; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5739 | apps[0] = PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW); |
| 5740 | apps[1] = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW); |
| 5741 | apps[2] = PackAndInstallCRX(data_dir().AppendASCII("app4"), INSTALL_NEW); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5742 | for (size_t i = 0; i < kAppCount; ++i) { |
| 5743 | ASSERT_TRUE(apps[i]); |
| 5744 | ASSERT_TRUE(apps[i]->is_app()); |
| 5745 | } |
| 5746 | |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5747 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5748 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5749 | syncer::APPS, |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5750 | syncer::SyncDataList(), |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5751 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5752 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5753 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5754 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5755 | ExtensionPrefs::Get(service()->GetBrowserContext()) |
[email protected] | 74c5ea1 | 2014-03-19 23:14:39 | [diff] [blame] | 5756 | ->app_sorting() |
| 5757 | ->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id()); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5758 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5759 | syncer::SyncDataList list = |
| 5760 | extension_sync_service()->GetAllSyncData(syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5761 | ASSERT_EQ(list.size(), 3U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5762 | |
| 5763 | extensions::AppSyncData data[kAppCount]; |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 5764 | for (size_t i = 0; i < kAppCount; ++i) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5765 | data[i] = extensions::AppSyncData(list[i]); |
| 5766 | } |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5767 | |
| 5768 | // The sync data is not always in the same order our apps were installed in, |
| 5769 | // so we do that sorting here so we can make sure the values are changed as |
| 5770 | // expected. |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 5771 | syncer::StringOrdinal app_launch_ordinals[kAppCount]; |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5772 | for (size_t i = 0; i < kAppCount; ++i) { |
| 5773 | for (size_t j = 0; j < kAppCount; ++j) { |
| 5774 | if (apps[i]->id() == data[j].id()) |
| 5775 | app_launch_ordinals[i] = data[j].app_launch_ordinal(); |
| 5776 | } |
| 5777 | } |
| 5778 | |
| 5779 | EXPECT_TRUE(app_launch_ordinals[1].LessThan(app_launch_ordinals[0])); |
| 5780 | EXPECT_TRUE(app_launch_ordinals[0].LessThan(app_launch_ordinals[2])); |
| 5781 | } |
| 5782 | } |
| 5783 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5784 | TEST_F(ExtensionServiceTest, GetSyncDataList) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5785 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5786 | InitializeExtensionSyncService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5787 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 5788 | InstallCRX(data_dir().AppendASCII("page_action.crx"), INSTALL_NEW); |
| 5789 | InstallCRX(data_dir().AppendASCII("theme.crx"), INSTALL_NEW); |
| 5790 | InstallCRX(data_dir().AppendASCII("theme2.crx"), INSTALL_NEW); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5791 | |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5792 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5793 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5794 | syncer::APPS, |
| 5795 | syncer::SyncDataList(), |
| 5796 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5797 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5798 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5799 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5800 | syncer::EXTENSIONS, |
| 5801 | syncer::SyncDataList(), |
| 5802 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5803 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5804 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5805 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5806 | service()->DisableExtension(page_action, Extension::DISABLE_USER_ACTION); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 5807 | TerminateExtension(theme2_crx); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5808 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5809 | EXPECT_EQ(0u, extension_sync_service()->GetAllSyncData(syncer::APPS).size()); |
| 5810 | EXPECT_EQ( |
| 5811 | 2u, extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS).size()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5812 | } |
| 5813 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5814 | TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5815 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5816 | InitializeExtensionSyncService(); |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5817 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5818 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5819 | syncer::EXTENSIONS, |
| 5820 | syncer::SyncDataList(), |
| 5821 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5822 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5823 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5824 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5825 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5826 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5827 | ext_specifics->set_id(good_crx); |
| 5828 | ext_specifics->set_version("1.0"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5829 | syncer::SyncData sync_data = |
| 5830 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5831 | syncer::SyncChange sync_change(FROM_HERE, |
| 5832 | syncer::SyncChange::ACTION_DELETE, |
| 5833 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5834 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5835 | list[0] = sync_change; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5836 | |
| 5837 | // Should do nothing. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5838 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 5839 | EXPECT_FALSE(service()->GetExtensionById(good_crx, true)); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5840 | |
| 5841 | // Install the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5842 | base::FilePath extension_path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5843 | InstallCRX(extension_path, INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5844 | EXPECT_TRUE(service()->GetExtensionById(good_crx, true)); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5845 | |
| 5846 | // Should uninstall the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5847 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 5848 | EXPECT_FALSE(service()->GetExtensionById(good_crx, true)); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5849 | |
| 5850 | // Should again do nothing. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5851 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 5852 | EXPECT_FALSE(service()->GetExtensionById(good_crx, true)); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5853 | } |
| 5854 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5855 | TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) { |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5856 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5857 | InitializeExtensionSyncService(); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5858 | |
| 5859 | // Install the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5860 | base::FilePath extension_path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5861 | InstallCRX(extension_path, INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5862 | EXPECT_TRUE(service()->GetExtensionById(good_crx, true)); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5863 | |
| 5864 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5865 | sync_pb::AppSpecifics* app_specifics = specifics.mutable_app(); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5866 | sync_pb::ExtensionSpecifics* extension_specifics = |
| 5867 | app_specifics->mutable_extension(); |
| 5868 | extension_specifics->set_id(good_crx); |
| 5869 | extension_specifics->set_version( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5870 | service()->GetInstalledExtension(good_crx)->version()->GetString()); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5871 | |
| 5872 | { |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5873 | extension_specifics->set_enabled(true); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5874 | syncer::SyncData sync_data = |
| 5875 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5876 | syncer::SyncChange sync_change(FROM_HERE, |
| 5877 | syncer::SyncChange::ACTION_DELETE, |
| 5878 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5879 | syncer::SyncChangeList list(1); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5880 | list[0] = sync_change; |
| 5881 | |
| 5882 | // Should do nothing |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5883 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 5884 | EXPECT_TRUE(service()->GetExtensionById(good_crx, true)); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5885 | } |
| 5886 | |
| 5887 | { |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5888 | extension_specifics->set_enabled(false); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5889 | syncer::SyncData sync_data = |
| 5890 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5891 | syncer::SyncChange sync_change(FROM_HERE, |
| 5892 | syncer::SyncChange::ACTION_UPDATE, |
| 5893 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5894 | syncer::SyncChangeList list(1); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5895 | list[0] = sync_change; |
| 5896 | |
| 5897 | // Should again do nothing. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5898 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 5899 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5900 | } |
| 5901 | } |
| 5902 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5903 | TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5904 | InitializeEmptyExtensionService(); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 5905 | InitializeProcessManager(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5906 | InitializeExtensionSyncService(); |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5907 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5908 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5909 | syncer::EXTENSIONS, |
| 5910 | syncer::SyncDataList(), |
| 5911 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5912 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5913 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5914 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5915 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 5916 | EXPECT_TRUE(service()->IsExtensionEnabled(good_crx)); |
| 5917 | EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5918 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5919 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5920 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5921 | ext_specifics->set_id(good_crx); |
| 5922 | ext_specifics->set_version( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5923 | service()->GetInstalledExtension(good_crx)->version()->GetString()); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5924 | ext_specifics->set_enabled(false); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5925 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5926 | { |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5927 | syncer::SyncData sync_data = |
| 5928 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5929 | syncer::SyncChange sync_change(FROM_HERE, |
| 5930 | syncer::SyncChange::ACTION_UPDATE, |
| 5931 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5932 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5933 | list[0] = sync_change; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5934 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 5935 | EXPECT_FALSE(service()->IsExtensionEnabled(good_crx)); |
| 5936 | EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5937 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5938 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5939 | { |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5940 | ext_specifics->set_enabled(true); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5941 | ext_specifics->set_incognito_enabled(true); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5942 | syncer::SyncData sync_data = |
| 5943 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5944 | syncer::SyncChange sync_change(FROM_HERE, |
| 5945 | syncer::SyncChange::ACTION_UPDATE, |
| 5946 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5947 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5948 | list[0] = sync_change; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5949 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 5950 | EXPECT_TRUE(service()->IsExtensionEnabled(good_crx)); |
| 5951 | EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5952 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5953 | |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5954 | { |
| 5955 | ext_specifics->set_enabled(false); |
| 5956 | ext_specifics->set_incognito_enabled(true); |
| 5957 | syncer::SyncData sync_data = |
| 5958 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
| 5959 | syncer::SyncChange sync_change(FROM_HERE, |
| 5960 | syncer::SyncChange::ACTION_UPDATE, |
| 5961 | sync_data); |
| 5962 | syncer::SyncChangeList list(1); |
| 5963 | list[0] = sync_change; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5964 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 5965 | EXPECT_FALSE(service()->IsExtensionEnabled(good_crx)); |
| 5966 | EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile())); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5967 | } |
| 5968 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5969 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx)); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5970 | } |
| 5971 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5972 | TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 5973 | InitializeExtensionServiceWithUpdater(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5974 | InitializeExtensionSyncService(); |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5975 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5976 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 5977 | syncer::EXTENSIONS, |
| 5978 | syncer::SyncDataList(), |
| 5979 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 5980 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5981 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 5982 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5983 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 5984 | TerminateExtension(good_crx); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5985 | EXPECT_TRUE(service()->IsExtensionEnabled(good_crx)); |
| 5986 | EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile())); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 5987 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5988 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5989 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5990 | ext_specifics->set_id(good_crx); |
| 5991 | ext_specifics->set_version( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5992 | service()->GetInstalledExtension(good_crx)->version()->GetString()); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5993 | ext_specifics->set_enabled(false); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5994 | ext_specifics->set_incognito_enabled(true); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5995 | syncer::SyncData sync_data = |
| 5996 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5997 | syncer::SyncChange sync_change(FROM_HERE, |
| 5998 | syncer::SyncChange::ACTION_UPDATE, |
| 5999 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6000 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6001 | list[0] = sync_change; |
| 6002 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6003 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 6004 | EXPECT_FALSE(service()->IsExtensionEnabled(good_crx)); |
| 6005 | EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile())); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 6006 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6007 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 6008 | } |
| 6009 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6010 | TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6011 | InitializeExtensionServiceWithUpdater(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6012 | InitializeExtensionSyncService(); |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 6013 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6014 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 6015 | syncer::EXTENSIONS, |
| 6016 | syncer::SyncDataList(), |
| 6017 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 6018 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6019 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6020 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6021 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 6022 | EXPECT_TRUE(service()->IsExtensionEnabled(good_crx)); |
| 6023 | EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6024 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6025 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 6026 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6027 | ext_specifics->set_id(good_crx); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6028 | ext_specifics->set_enabled(true); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6029 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6030 | { |
| 6031 | ext_specifics->set_version( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6032 | service()->GetInstalledExtension(good_crx)->version()->GetString()); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6033 | syncer::SyncData sync_data = |
| 6034 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 6035 | syncer::SyncChange sync_change(FROM_HERE, |
| 6036 | syncer::SyncChange::ACTION_UPDATE, |
| 6037 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6038 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6039 | list[0] = sync_change; |
| 6040 | |
| 6041 | // Should do nothing if extension version == sync version. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6042 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 6043 | EXPECT_FALSE(service()->updater()->WillCheckSoon()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6044 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6045 | |
| 6046 | // Should do nothing if extension version > sync version (but see |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6047 | // the TODO in ProcessExtensionSyncData). |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6048 | { |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6049 | ext_specifics->set_version("0.0.0.0"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6050 | syncer::SyncData sync_data = |
| 6051 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 6052 | syncer::SyncChange sync_change(FROM_HERE, |
| 6053 | syncer::SyncChange::ACTION_UPDATE, |
| 6054 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6055 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6056 | list[0] = sync_change; |
| 6057 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6058 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 6059 | EXPECT_FALSE(service()->updater()->WillCheckSoon()); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6060 | } |
| 6061 | |
| 6062 | // Should kick off an update if extension version < sync version. |
| 6063 | { |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6064 | ext_specifics->set_version("9.9.9.9"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6065 | syncer::SyncData sync_data = |
| 6066 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 6067 | syncer::SyncChange sync_change(FROM_HERE, |
| 6068 | syncer::SyncChange::ACTION_UPDATE, |
| 6069 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6070 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6071 | list[0] = sync_change; |
| 6072 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6073 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 6074 | EXPECT_TRUE(service()->updater()->WillCheckSoon()); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6075 | } |
| 6076 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6077 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx)); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6078 | } |
| 6079 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6080 | TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6081 | InitializeExtensionServiceWithUpdater(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6082 | InitializeExtensionSyncService(); |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 6083 | syncer::FakeSyncChangeProcessor processor; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6084 | extension_sync_service()->MergeDataAndStartSyncing( |
[email protected] | d0b2352 | 2014-02-19 02:15:25 | [diff] [blame] | 6085 | syncer::EXTENSIONS, |
| 6086 | syncer::SyncDataList(), |
| 6087 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 6088 | new syncer::FakeSyncChangeProcessor), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6089 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6090 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6091 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 6092 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6093 | ext_specifics->set_id(good_crx); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6094 | ext_specifics->set_enabled(false); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6095 | ext_specifics->set_incognito_enabled(true); |
| 6096 | ext_specifics->set_update_url("http://www.google.com/"); |
| 6097 | ext_specifics->set_version("1.2.3.4"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6098 | syncer::SyncData sync_data = |
| 6099 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 6100 | syncer::SyncChange sync_change(FROM_HERE, |
| 6101 | syncer::SyncChange::ACTION_UPDATE, |
| 6102 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6103 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6104 | list[0] = sync_change; |
| 6105 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6106 | EXPECT_TRUE(service()->IsExtensionEnabled(good_crx)); |
| 6107 | EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile())); |
| 6108 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 6109 | EXPECT_TRUE(service()->updater()->WillCheckSoon()); |
| 6110 | EXPECT_FALSE(service()->IsExtensionEnabled(good_crx)); |
| 6111 | EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6112 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6113 | const extensions::PendingExtensionInfo* info; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6114 | EXPECT_TRUE( |
| 6115 | (info = service()->pending_extension_manager()->GetById(good_crx))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6116 | EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); |
| 6117 | EXPECT_TRUE(info->is_from_sync()); |
| 6118 | EXPECT_TRUE(info->install_silently()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6119 | EXPECT_EQ(Manifest::INTERNAL, info->install_source()); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6120 | // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. |
| 6121 | } |
| 6122 | |
[email protected] | 343a0d87 | 2014-08-05 11:44:18 | [diff] [blame] | 6123 | TEST_F(ExtensionServiceTest, SupervisedUser_InstallOnlyAllowedByCustodian) { |
| 6124 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 6125 | params.profile_is_supervised = true; |
| 6126 | InitializeExtensionService(params); |
| 6127 | |
| 6128 | SupervisedUserService* supervised_user_service = |
| 6129 | SupervisedUserServiceFactory::GetForProfile(profile()); |
| 6130 | GetManagementPolicy()->RegisterProvider(supervised_user_service); |
| 6131 | |
| 6132 | base::FilePath path1 = data_dir().AppendASCII("good.crx"); |
| 6133 | base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); |
| 6134 | const Extension* extensions[] = { |
| 6135 | InstallCRX(path1, INSTALL_FAILED), |
| 6136 | InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) |
| 6137 | }; |
| 6138 | |
| 6139 | // Only the extension with the "installed by custodian" flag should have been |
| 6140 | // installed and enabled. |
| 6141 | EXPECT_FALSE(extensions[0]); |
| 6142 | ASSERT_TRUE(extensions[1]); |
| 6143 | EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id())); |
| 6144 | } |
| 6145 | |
| 6146 | TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithoutPermissionIncrease) { |
| 6147 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 6148 | params.profile_is_supervised = true; |
| 6149 | InitializeExtensionService(params); |
| 6150 | |
| 6151 | SupervisedUserService* supervised_user_service = |
| 6152 | SupervisedUserServiceFactory::GetForProfile(profile()); |
| 6153 | GetManagementPolicy()->RegisterProvider(supervised_user_service); |
| 6154 | |
| 6155 | base::FilePath base_path = data_dir().AppendASCII("autoupdate"); |
| 6156 | base::FilePath pem_path = base_path.AppendASCII("key.pem"); |
| 6157 | |
| 6158 | base::FilePath path = base_path.AppendASCII("v1"); |
| 6159 | const Extension* extension = |
| 6160 | PackAndInstallCRX(path, pem_path, INSTALL_NEW, |
| 6161 | Extension::WAS_INSTALLED_BY_CUSTODIAN); |
| 6162 | // The extension must now be installed and enabled. |
| 6163 | ASSERT_TRUE(extension); |
| 6164 | ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); |
| 6165 | |
| 6166 | // Save the id, as the extension object will be destroyed during updating. |
| 6167 | std::string id = extension->id(); |
| 6168 | |
| 6169 | std::string old_version = extension->VersionString(); |
| 6170 | |
| 6171 | // Update to a new version. |
| 6172 | path = base_path.AppendASCII("v2"); |
| 6173 | PackCRXAndUpdateExtension(id, path, pem_path, ENABLED); |
| 6174 | |
| 6175 | // The extension should still be there and enabled. |
| 6176 | extension = registry()->enabled_extensions().GetByID(id); |
| 6177 | ASSERT_TRUE(extension); |
| 6178 | // The version should have changed. |
| 6179 | EXPECT_NE(extension->VersionString(), old_version); |
| 6180 | } |
| 6181 | |
| 6182 | TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) { |
| 6183 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 6184 | params.profile_is_supervised = true; |
| 6185 | InitializeExtensionService(params); |
| 6186 | |
| 6187 | SupervisedUserService* supervised_user_service = |
| 6188 | SupervisedUserServiceFactory::GetForProfile(profile()); |
| 6189 | GetManagementPolicy()->RegisterProvider(supervised_user_service); |
| 6190 | |
| 6191 | base::FilePath base_path = data_dir().AppendASCII("permissions_increase"); |
| 6192 | base::FilePath pem_path = base_path.AppendASCII("permissions.pem"); |
| 6193 | |
| 6194 | base::FilePath path = base_path.AppendASCII("v1"); |
| 6195 | const Extension* extension = |
| 6196 | PackAndInstallCRX(path, pem_path, INSTALL_NEW, |
| 6197 | Extension::WAS_INSTALLED_BY_CUSTODIAN); |
| 6198 | // The extension must now be installed and enabled. |
| 6199 | ASSERT_TRUE(extension); |
| 6200 | ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); |
| 6201 | |
| 6202 | // Save the id, as the extension object will be destroyed during updating. |
| 6203 | std::string id = extension->id(); |
| 6204 | |
| 6205 | std::string old_version = extension->VersionString(); |
| 6206 | |
| 6207 | // Update to a new version with increased permissions. |
| 6208 | path = base_path.AppendASCII("v2"); |
| 6209 | PackCRXAndUpdateExtension(id, path, pem_path, DISABLED); |
| 6210 | |
| 6211 | // The extension should still be there, but disabled. |
| 6212 | EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 6213 | extension = registry()->disabled_extensions().GetByID(id); |
| 6214 | ASSERT_TRUE(extension); |
| 6215 | // The version should have changed. |
| 6216 | EXPECT_NE(extension->VersionString(), old_version); |
| 6217 | } |
| 6218 | |
| 6219 | TEST_F(ExtensionServiceTest, |
| 6220 | SupervisedUser_SyncUninstallByCustodianSkipsPolicy) { |
[email protected] | 6ef6001 | 2014-07-22 19:08:12 | [diff] [blame] | 6221 | InitializeEmptyExtensionService(); |
| 6222 | InitializeExtensionSyncService(); |
| 6223 | extension_sync_service()->MergeDataAndStartSyncing( |
| 6224 | syncer::EXTENSIONS, |
| 6225 | syncer::SyncDataList(), |
| 6226 | scoped_ptr<syncer::SyncChangeProcessor>( |
| 6227 | new syncer::FakeSyncChangeProcessor), |
| 6228 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 6229 | |
| 6230 | // Install two extensions. |
| 6231 | base::FilePath path1 = data_dir().AppendASCII("good.crx"); |
| 6232 | base::FilePath path2 = data_dir().AppendASCII("good2048.crx"); |
[email protected] | 343a0d87 | 2014-08-05 11:44:18 | [diff] [blame] | 6233 | const Extension* extensions[] = { |
[email protected] | 6ef6001 | 2014-07-22 19:08:12 | [diff] [blame] | 6234 | InstallCRX(path1, INSTALL_NEW), |
| 6235 | InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN) |
| 6236 | }; |
| 6237 | |
| 6238 | // Add a policy provider that will disallow any changes. |
| 6239 | extensions::TestManagementPolicyProvider provider( |
| 6240 | extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
| 6241 | GetManagementPolicy()->RegisterProvider(&provider); |
| 6242 | |
| 6243 | // Create a sync deletion for each extension. |
| 6244 | syncer::SyncChangeList change_list; |
[email protected] | 343a0d87 | 2014-08-05 11:44:18 | [diff] [blame] | 6245 | for (size_t i = 0; i < arraysize(extensions); i++) { |
[email protected] | 6ef6001 | 2014-07-22 19:08:12 | [diff] [blame] | 6246 | const std::string& id = extensions[i]->id(); |
| 6247 | sync_pb::EntitySpecifics specifics; |
| 6248 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
| 6249 | ext_specifics->set_id(id); |
| 6250 | ext_specifics->set_version("1.0"); |
| 6251 | ext_specifics->set_installed_by_custodian( |
| 6252 | extensions[i]->was_installed_by_custodian()); |
| 6253 | syncer::SyncData sync_data = |
| 6254 | syncer::SyncData::CreateLocalData(id, "Name", specifics); |
| 6255 | change_list.push_back(syncer::SyncChange(FROM_HERE, |
| 6256 | syncer::SyncChange::ACTION_DELETE, |
| 6257 | sync_data)); |
| 6258 | } |
| 6259 | |
| 6260 | // Save the extension ids, as uninstalling destroys the Extension instance. |
[email protected] | 343a0d87 | 2014-08-05 11:44:18 | [diff] [blame] | 6261 | std::string extension_ids[] = { |
[email protected] | 6ef6001 | 2014-07-22 19:08:12 | [diff] [blame] | 6262 | extensions[0]->id(), |
| 6263 | extensions[1]->id() |
| 6264 | }; |
| 6265 | |
| 6266 | // Now apply the uninstallations. |
| 6267 | extension_sync_service()->ProcessSyncChanges(FROM_HERE, change_list); |
| 6268 | |
| 6269 | // Uninstalling the extension without installed_by_custodian should have been |
[email protected] | 343a0d87 | 2014-08-05 11:44:18 | [diff] [blame] | 6270 | // blocked by policy, so it should still be there. |
| 6271 | EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_ids[0])); |
[email protected] | 6ef6001 | 2014-07-22 19:08:12 | [diff] [blame] | 6272 | |
| 6273 | // But installed_by_custodian should result in bypassing the policy check. |
[email protected] | 343a0d87 | 2014-08-05 11:44:18 | [diff] [blame] | 6274 | EXPECT_FALSE( |
| 6275 | registry()->GenerateInstalledExtensionsSet()->Contains(extension_ids[1])); |
[email protected] | 6ef6001 | 2014-07-22 19:08:12 | [diff] [blame] | 6276 | } |
| 6277 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6278 | TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6279 | InitializeEmptyExtensionService(); |
| 6280 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6281 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 6282 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6283 | ValidatePrefKeyCount(1u); |
| 6284 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6285 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6286 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6287 | extensions::PendingExtensionManager* pending = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6288 | service()->pending_extension_manager(); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6289 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6290 | |
| 6291 | // Skip install when the location is the same. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6292 | EXPECT_FALSE( |
| 6293 | service()->OnExternalExtensionUpdateUrlFound(kGoodId, |
| 6294 | std::string(), |
| 6295 | GURL(kGoodUpdateURL), |
| 6296 | Manifest::INTERNAL, |
| 6297 | Extension::NO_FLAGS, |
| 6298 | false)); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6299 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6300 | |
| 6301 | // Install when the location has higher priority. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6302 | EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 6303 | kGoodId, |
| 6304 | std::string(), |
| 6305 | GURL(kGoodUpdateURL), |
| 6306 | Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 6307 | Extension::NO_FLAGS, |
| 6308 | false)); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6309 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6310 | |
| 6311 | // Try the low priority again. Should be rejected. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6312 | EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 6313 | kGoodId, |
| 6314 | std::string(), |
| 6315 | GURL(kGoodUpdateURL), |
| 6316 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 6317 | Extension::NO_FLAGS, |
| 6318 | false)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6319 | // The existing record should still be present in the pending extension |
| 6320 | // manager. |
| 6321 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6322 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6323 | pending->Remove(kGoodId); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6324 | |
| 6325 | // Skip install when the location has the same priority as the installed |
| 6326 | // location. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6327 | EXPECT_FALSE( |
| 6328 | service()->OnExternalExtensionUpdateUrlFound(kGoodId, |
| 6329 | std::string(), |
| 6330 | GURL(kGoodUpdateURL), |
| 6331 | Manifest::INTERNAL, |
| 6332 | Extension::NO_FLAGS, |
| 6333 | false)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6334 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6335 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6336 | } |
| 6337 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6338 | TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 6339 | Version older_version("0.1.0.0"); |
| 6340 | Version newer_version("2.0.0.0"); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6341 | |
| 6342 | // We don't want the extension to be installed. A path that doesn't |
| 6343 | // point to a valid CRX ensures this. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6344 | const base::FilePath kInvalidPathToCrx = base::FilePath(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6345 | |
| 6346 | const int kCreationFlags = 0; |
| 6347 | const bool kDontMarkAcknowledged = false; |
| 6348 | |
| 6349 | InitializeEmptyExtensionService(); |
| 6350 | |
| 6351 | // The test below uses install source constants to test that |
| 6352 | // priority is enforced. It assumes a specific ranking of install |
| 6353 | // sources: Registry (EXTERNAL_REGISTRY) overrides external pref |
| 6354 | // (EXTERNAL_PREF), and external pref overrides user install (INTERNAL). |
| 6355 | // The following assertions verify these assumptions: |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6356 | ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, |
| 6357 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
| 6358 | Manifest::EXTERNAL_PREF)); |
| 6359 | ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, |
| 6360 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
| 6361 | Manifest::INTERNAL)); |
| 6362 | ASSERT_EQ(Manifest::EXTERNAL_PREF, |
| 6363 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, |
| 6364 | Manifest::INTERNAL)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6365 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6366 | extensions::PendingExtensionManager* pending = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6367 | service()->pending_extension_manager(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6368 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6369 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6370 | { |
| 6371 | // Simulate an external source adding the extension as INTERNAL. |
| 6372 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6373 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6374 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6375 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6376 | &older_version, |
| 6377 | kInvalidPathToCrx, |
| 6378 | Manifest::INTERNAL, |
| 6379 | kCreationFlags, |
| 6380 | kDontMarkAcknowledged)); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6381 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6382 | observer.Wait(); |
| 6383 | VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 6384 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6385 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6386 | { |
| 6387 | // Simulate an external source adding the extension as EXTERNAL_PREF. |
| 6388 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6389 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6390 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6391 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6392 | &older_version, |
| 6393 | kInvalidPathToCrx, |
| 6394 | Manifest::EXTERNAL_PREF, |
| 6395 | kCreationFlags, |
| 6396 | kDontMarkAcknowledged)); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6397 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6398 | observer.Wait(); |
| 6399 | VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 6400 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6401 | |
| 6402 | // Simulate an external source adding as EXTERNAL_PREF again. |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 6403 | // This is rejected because the version and the location are the same as |
| 6404 | // the previous installation, which is still pending. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6405 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6406 | &older_version, |
| 6407 | kInvalidPathToCrx, |
| 6408 | Manifest::EXTERNAL_PREF, |
| 6409 | kCreationFlags, |
| 6410 | kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6411 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6412 | |
| 6413 | // Try INTERNAL again. Should fail. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6414 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6415 | &older_version, |
| 6416 | kInvalidPathToCrx, |
| 6417 | Manifest::INTERNAL, |
| 6418 | kCreationFlags, |
| 6419 | kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6420 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6421 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6422 | { |
| 6423 | // Now the registry adds the extension. |
| 6424 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6425 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6426 | content::NotificationService::AllSources()); |
| 6427 | EXPECT_TRUE( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6428 | service()->OnExternalExtensionFileFound(kGoodId, |
| 6429 | &older_version, |
| 6430 | kInvalidPathToCrx, |
| 6431 | Manifest::EXTERNAL_REGISTRY, |
| 6432 | kCreationFlags, |
| 6433 | kDontMarkAcknowledged)); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6434 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6435 | observer.Wait(); |
| 6436 | VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 6437 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6438 | |
| 6439 | // Registry outranks both external pref and internal, so both fail. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6440 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6441 | &older_version, |
| 6442 | kInvalidPathToCrx, |
| 6443 | Manifest::EXTERNAL_PREF, |
| 6444 | kCreationFlags, |
| 6445 | kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6446 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6447 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6448 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6449 | &older_version, |
| 6450 | kInvalidPathToCrx, |
| 6451 | Manifest::INTERNAL, |
| 6452 | kCreationFlags, |
| 6453 | kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6454 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6455 | |
| 6456 | pending->Remove(kGoodId); |
| 6457 | |
| 6458 | // Install the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6459 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6460 | const Extension* ext = InstallCRX(path, INSTALL_NEW); |
| 6461 | ValidatePrefKeyCount(1u); |
| 6462 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6463 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6464 | |
| 6465 | // Now test the logic of OnExternalExtensionFileFound() when the extension |
| 6466 | // being added is already installed. |
| 6467 | |
| 6468 | // Tests assume |older_version| is less than the installed version, and |
| 6469 | // |newer_version| is greater. Verify this: |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6470 | ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); |
| 6471 | ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6472 | |
| 6473 | // An external install for the same location should fail if the version is |
| 6474 | // older, or the same, and succeed if the version is newer. |
| 6475 | |
| 6476 | // Older than the installed version... |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6477 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6478 | &older_version, |
| 6479 | kInvalidPathToCrx, |
| 6480 | Manifest::INTERNAL, |
| 6481 | kCreationFlags, |
| 6482 | kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6483 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6484 | |
| 6485 | // Same version as the installed version... |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6486 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6487 | ext->version(), |
| 6488 | kInvalidPathToCrx, |
| 6489 | Manifest::INTERNAL, |
| 6490 | kCreationFlags, |
| 6491 | kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6492 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6493 | |
| 6494 | // Newer than the installed version... |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6495 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6496 | &newer_version, |
| 6497 | kInvalidPathToCrx, |
| 6498 | Manifest::INTERNAL, |
| 6499 | kCreationFlags, |
| 6500 | kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6501 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6502 | |
| 6503 | // An external install for a higher priority install source should succeed |
| 6504 | // if the version is greater. |older_version| is not... |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6505 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6506 | &older_version, |
| 6507 | kInvalidPathToCrx, |
| 6508 | Manifest::EXTERNAL_PREF, |
| 6509 | kCreationFlags, |
| 6510 | kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6511 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6512 | |
| 6513 | // |newer_version| is newer. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6514 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6515 | &newer_version, |
| 6516 | kInvalidPathToCrx, |
| 6517 | Manifest::EXTERNAL_PREF, |
| 6518 | kCreationFlags, |
| 6519 | kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6520 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6521 | |
| 6522 | // An external install for an even higher priority install source should |
| 6523 | // succeed if the version is greater. |
| 6524 | EXPECT_TRUE( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6525 | service()->OnExternalExtensionFileFound(kGoodId, |
| 6526 | &newer_version, |
| 6527 | kInvalidPathToCrx, |
| 6528 | Manifest::EXTERNAL_REGISTRY, |
| 6529 | kCreationFlags, |
| 6530 | kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6531 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6532 | |
| 6533 | // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, |
| 6534 | // adding from external pref will now fail. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6535 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6536 | &newer_version, |
| 6537 | kInvalidPathToCrx, |
| 6538 | Manifest::EXTERNAL_PREF, |
| 6539 | kCreationFlags, |
| 6540 | kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6541 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6542 | } |
| 6543 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6544 | TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 6545 | Version kVersion123("1.2.3"); |
| 6546 | Version kVersion124("1.2.4"); |
| 6547 | Version kVersion125("1.2.5"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6548 | const base::FilePath kInvalidPathToCrx = base::FilePath(); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6549 | const int kCreationFlags = 0; |
| 6550 | const bool kDontMarkAcknowledged = false; |
| 6551 | |
| 6552 | InitializeEmptyExtensionService(); |
| 6553 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6554 | extensions::PendingExtensionManager* pending = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6555 | service()->pending_extension_manager(); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6556 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6557 | |
| 6558 | // An external provider starts installing from a local crx. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6559 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6560 | &kVersion123, |
| 6561 | kInvalidPathToCrx, |
| 6562 | Manifest::EXTERNAL_PREF, |
| 6563 | kCreationFlags, |
| 6564 | kDontMarkAcknowledged)); |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6565 | const extensions::PendingExtensionInfo* info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6566 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 6567 | EXPECT_TRUE(info->version().IsValid()); |
| 6568 | EXPECT_TRUE(info->version().Equals(kVersion123)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6569 | |
| 6570 | // Adding a newer version overrides the currently pending version. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6571 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6572 | &kVersion124, |
| 6573 | kInvalidPathToCrx, |
| 6574 | Manifest::EXTERNAL_PREF, |
| 6575 | kCreationFlags, |
| 6576 | kDontMarkAcknowledged)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6577 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 6578 | EXPECT_TRUE(info->version().IsValid()); |
| 6579 | EXPECT_TRUE(info->version().Equals(kVersion124)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6580 | |
| 6581 | // Adding an older version fails. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6582 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId, |
| 6583 | &kVersion123, |
| 6584 | kInvalidPathToCrx, |
| 6585 | Manifest::EXTERNAL_PREF, |
| 6586 | kCreationFlags, |
| 6587 | kDontMarkAcknowledged)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6588 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 6589 | EXPECT_TRUE(info->version().IsValid()); |
| 6590 | EXPECT_TRUE(info->version().Equals(kVersion124)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6591 | |
| 6592 | // Adding an older version fails even when coming from a higher-priority |
| 6593 | // location. |
| 6594 | EXPECT_FALSE( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6595 | service()->OnExternalExtensionFileFound(kGoodId, |
| 6596 | &kVersion123, |
| 6597 | kInvalidPathToCrx, |
| 6598 | Manifest::EXTERNAL_REGISTRY, |
| 6599 | kCreationFlags, |
| 6600 | kDontMarkAcknowledged)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6601 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 6602 | EXPECT_TRUE(info->version().IsValid()); |
| 6603 | EXPECT_TRUE(info->version().Equals(kVersion124)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6604 | |
| 6605 | // Adding the latest version from the webstore overrides a specific version. |
| 6606 | GURL kUpdateUrl("http://example.com/update"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6607 | EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 6608 | kGoodId, |
| 6609 | std::string(), |
| 6610 | kUpdateUrl, |
| 6611 | Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 6612 | Extension::NO_FLAGS, |
| 6613 | false)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6614 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 6615 | EXPECT_FALSE(info->version().IsValid()); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6616 | } |
| 6617 | |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6618 | // This makes sure we can package and install CRX files that use whitelisted |
| 6619 | // permissions. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6620 | TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6621 | std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; |
| 6622 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
[email protected] | a612eb3 | 2014-03-31 22:09:17 | [diff] [blame] | 6623 | extensions::switches::kWhitelistedExtensionID, test_id); |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6624 | |
| 6625 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6626 | base::FilePath path = data_dir().AppendASCII("permissions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6627 | base::FilePath pem_path = path |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6628 | .AppendASCII("whitelist.pem"); |
| 6629 | path = path |
| 6630 | .AppendASCII("whitelist"); |
| 6631 | |
| 6632 | const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); |
| 6633 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6634 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6635 | EXPECT_EQ(test_id, extension->id()); |
| 6636 | } |
| 6637 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6638 | // Test that when multiple sources try to install an extension, |
| 6639 | // we consistently choose the right one. To make tests easy to read, |
| 6640 | // methods that fake requests to install crx files in several ways |
| 6641 | // are provided. |
| 6642 | class ExtensionSourcePriorityTest : public ExtensionServiceTest { |
| 6643 | public: |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 6644 | virtual void SetUp() { |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6645 | ExtensionServiceTest::SetUp(); |
| 6646 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6647 | // All tests use a single extension. Put the id and path in member vars |
| 6648 | // that all methods can read. |
| 6649 | crx_id_ = kGoodId; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6650 | crx_path_ = data_dir().AppendASCII("good.crx"); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6651 | } |
| 6652 | |
| 6653 | // Fake an external source adding a URL to fetch an extension from. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6654 | bool AddPendingExternalPrefUrl() { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6655 | return service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 6656 | crx_id_, |
| 6657 | std::string(), |
| 6658 | GURL(), |
| 6659 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 6660 | Extension::NO_FLAGS, |
| 6661 | false); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6662 | } |
| 6663 | |
| 6664 | // Fake an external file from external_extensions.json. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6665 | bool AddPendingExternalPrefFileInstall() { |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 6666 | Version version("1.0.0.0"); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6667 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6668 | return service()->OnExternalExtensionFileFound(crx_id_, |
| 6669 | &version, |
| 6670 | crx_path_, |
| 6671 | Manifest::EXTERNAL_PREF, |
| 6672 | Extension::NO_FLAGS, |
| 6673 | false); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6674 | } |
| 6675 | |
| 6676 | // Fake a request from sync to install an extension. |
| 6677 | bool AddPendingSyncInstall() { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6678 | return service()->pending_extension_manager()->AddFromSync( |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 6679 | crx_id_, |
| 6680 | GURL(kGoodUpdateURL), |
| 6681 | &IsExtension, |
| 6682 | kGoodInstallSilently, |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 6683 | kGoodRemoteInstall, |
| 6684 | kGoodInstalledByCustodian); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6685 | } |
| 6686 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6687 | // Fake a policy install. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6688 | bool AddPendingPolicyInstall() { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6689 | // Get path to the CRX with id |kGoodId|. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6690 | return service()->OnExternalExtensionUpdateUrlFound( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 6691 | crx_id_, |
| 6692 | std::string(), |
| 6693 | GURL(), |
| 6694 | Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 6695 | Extension::NO_FLAGS, |
| 6696 | false); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6697 | } |
| 6698 | |
| 6699 | // Get the install source of a pending extension. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6700 | Manifest::Location GetPendingLocation() { |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6701 | const extensions::PendingExtensionInfo* info; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6702 | EXPECT_TRUE( |
| 6703 | (info = service()->pending_extension_manager()->GetById(crx_id_))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6704 | return info->install_source(); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6705 | } |
| 6706 | |
| 6707 | // Is an extension pending from a sync request? |
| 6708 | bool GetPendingIsFromSync() { |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6709 | const extensions::PendingExtensionInfo* info; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6710 | EXPECT_TRUE( |
| 6711 | (info = service()->pending_extension_manager()->GetById(crx_id_))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6712 | return info->is_from_sync(); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6713 | } |
| 6714 | |
| 6715 | // Is the CRX id these tests use pending? |
| 6716 | bool IsCrxPending() { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6717 | return service()->pending_extension_manager()->IsIdPending(crx_id_); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6718 | } |
| 6719 | |
| 6720 | // Is an extension installed? |
| 6721 | bool IsCrxInstalled() { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6722 | return (service()->GetExtensionById(crx_id_, true) != NULL); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6723 | } |
| 6724 | |
| 6725 | protected: |
| 6726 | // All tests use a single extension. Making the id and path member |
| 6727 | // vars avoids pasing the same argument to every method. |
| 6728 | std::string crx_id_; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6729 | base::FilePath crx_path_; |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6730 | }; |
| 6731 | |
[email protected] | 3634ebd | 2011-04-20 00:34:12 | [diff] [blame] | 6732 | // Test that a pending request for installation of an external CRX from |
| 6733 | // an update URL overrides a pending request to install the same extension |
| 6734 | // from sync. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6735 | TEST_F(ExtensionSourcePriorityTest, PendingExternalFileOverSync) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6736 | InitializeEmptyExtensionService(); |
| 6737 | |
| 6738 | ASSERT_FALSE(IsCrxInstalled()); |
| 6739 | |
| 6740 | // Install pending extension from sync. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6741 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6742 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6743 | content::NotificationService::AllSources()); |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6744 | EXPECT_TRUE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6745 | ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6746 | EXPECT_TRUE(GetPendingIsFromSync()); |
| 6747 | ASSERT_FALSE(IsCrxInstalled()); |
| 6748 | |
| 6749 | // Install pending as external prefs json would. |
| 6750 | AddPendingExternalPrefFileInstall(); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6751 | ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6752 | ASSERT_FALSE(IsCrxInstalled()); |
| 6753 | |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6754 | // Another request from sync should be ignored. |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6755 | EXPECT_FALSE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6756 | ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6757 | ASSERT_FALSE(IsCrxInstalled()); |
| 6758 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6759 | observer.Wait(); |
| 6760 | VerifyCrxInstall(crx_path_, INSTALL_NEW); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6761 | ASSERT_TRUE(IsCrxInstalled()); |
| 6762 | } |
| 6763 | |
| 6764 | // Test that an install of an external CRX from an update overrides |
| 6765 | // an install of the same extension from sync. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6766 | TEST_F(ExtensionSourcePriorityTest, PendingExternalUrlOverSync) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6767 | InitializeEmptyExtensionService(); |
| 6768 | ASSERT_FALSE(IsCrxInstalled()); |
| 6769 | |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6770 | EXPECT_TRUE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6771 | ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6772 | EXPECT_TRUE(GetPendingIsFromSync()); |
| 6773 | ASSERT_FALSE(IsCrxInstalled()); |
| 6774 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6775 | ASSERT_TRUE(AddPendingExternalPrefUrl()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6776 | ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6777 | EXPECT_FALSE(GetPendingIsFromSync()); |
| 6778 | ASSERT_FALSE(IsCrxInstalled()); |
| 6779 | |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6780 | EXPECT_FALSE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6781 | ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6782 | EXPECT_FALSE(GetPendingIsFromSync()); |
| 6783 | ASSERT_FALSE(IsCrxInstalled()); |
| 6784 | } |
| 6785 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6786 | // Test that an external install request stops sync from installing |
| 6787 | // the same extension. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6788 | TEST_F(ExtensionSourcePriorityTest, InstallExternalBlocksSyncRequest) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6789 | InitializeEmptyExtensionService(); |
| 6790 | ASSERT_FALSE(IsCrxInstalled()); |
| 6791 | |
| 6792 | // External prefs starts an install. |
| 6793 | AddPendingExternalPrefFileInstall(); |
| 6794 | |
| 6795 | // Crx installer was made, but has not yet run. |
| 6796 | ASSERT_FALSE(IsCrxInstalled()); |
| 6797 | |
| 6798 | // Before the CRX installer runs, Sync requests that the same extension |
| 6799 | // be installed. Should fail, because an external source is pending. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6800 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6801 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6802 | content::NotificationService::AllSources()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6803 | ASSERT_FALSE(AddPendingSyncInstall()); |
| 6804 | |
| 6805 | // Wait for the external source to install. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6806 | observer.Wait(); |
| 6807 | VerifyCrxInstall(crx_path_, INSTALL_NEW); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6808 | ASSERT_TRUE(IsCrxInstalled()); |
| 6809 | |
| 6810 | // Now that the extension is installed, sync request should fail |
| 6811 | // because the extension is already installed. |
| 6812 | ASSERT_FALSE(AddPendingSyncInstall()); |
| 6813 | } |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6814 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6815 | // Test that installing an external extension displays a GlobalError. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6816 | TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 6817 | FeatureSwitch::ScopedOverride prompt( |
| 6818 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6819 | |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6820 | InitializeEmptyExtensionService(); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6821 | MockExtensionProvider* provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6822 | new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6823 | AddMockExternalProvider(provider); |
| 6824 | |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 6825 | service()->external_install_manager()->UpdateExternalExtensionAlert(); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6826 | // Should return false, meaning there aren't any extensions that the user |
| 6827 | // needs to know about. |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6828 | EXPECT_FALSE( |
| 6829 | service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6830 | |
| 6831 | // This is a normal extension, installed normally. |
| 6832 | // This should NOT trigger an alert. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6833 | service()->set_extensions_enabled(true); |
| 6834 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6835 | InstallCRX(path, INSTALL_NEW); |
| 6836 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6837 | service()->CheckForExternalUpdates(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 6838 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6839 | EXPECT_FALSE( |
| 6840 | service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6841 | |
| 6842 | // A hosted app, installed externally. |
[email protected] | 2c495c4 | 2013-01-04 21:49:54 | [diff] [blame] | 6843 | // This should NOT trigger an alert. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6844 | provider->UpdateOrAddExtension( |
| 6845 | hosted_app, "1.0.0.0", data_dir().AppendASCII("hosted_app.crx")); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6846 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6847 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6848 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6849 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6850 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6851 | observer.Wait(); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6852 | EXPECT_FALSE( |
| 6853 | service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6854 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6855 | // Another normal extension, but installed externally. |
| 6856 | // This SHOULD trigger an alert. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6857 | provider->UpdateOrAddExtension( |
| 6858 | page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6859 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6860 | content::WindowedNotificationObserver observer2( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6861 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6862 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6863 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6864 | observer2.Wait(); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6865 | EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6866 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6867 | |
| 6868 | // Test that external extensions are initially disabled, and that enabling |
| 6869 | // them clears the prompt. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6870 | TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 6871 | FeatureSwitch::ScopedOverride prompt( |
| 6872 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6873 | |
| 6874 | InitializeEmptyExtensionService(); |
| 6875 | MockExtensionProvider* provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6876 | new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6877 | AddMockExternalProvider(provider); |
| 6878 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6879 | provider->UpdateOrAddExtension( |
| 6880 | page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6881 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6882 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6883 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6884 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6885 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6886 | observer.Wait(); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6887 | EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6888 | EXPECT_FALSE(service()->IsExtensionEnabled(page_action)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6889 | |
| 6890 | const Extension* extension = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6891 | registry()->disabled_extensions().GetByID(page_action); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6892 | EXPECT_TRUE(extension); |
| 6893 | EXPECT_EQ(page_action, extension->id()); |
| 6894 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6895 | service()->EnableExtension(page_action); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6896 | EXPECT_FALSE( |
| 6897 | service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6898 | EXPECT_TRUE(service()->IsExtensionEnabled(page_action)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6899 | } |
| 6900 | |
| 6901 | // Test that installing multiple external extensions works. |
[email protected] | 404d1a2 | 2013-09-20 17:28:07 | [diff] [blame] | 6902 | // Flaky on windows; http://crbug.com/295757 . |
| 6903 | #if defined(OS_WIN) |
| 6904 | #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple |
| 6905 | #else |
| 6906 | #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple |
| 6907 | #endif |
| 6908 | TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 6909 | FeatureSwitch::ScopedOverride prompt( |
| 6910 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6911 | |
| 6912 | InitializeEmptyExtensionService(); |
| 6913 | MockExtensionProvider* provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6914 | new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6915 | AddMockExternalProvider(provider); |
| 6916 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6917 | provider->UpdateOrAddExtension( |
| 6918 | page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); |
| 6919 | provider->UpdateOrAddExtension( |
| 6920 | good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx")); |
| 6921 | provider->UpdateOrAddExtension( |
| 6922 | theme_crx, "2.0", data_dir().AppendASCII("theme.crx")); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6923 | |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6924 | int count = 3; |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6925 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6926 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6927 | base::Bind(&WaitForCountNotificationsCallback, &count)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6928 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6929 | observer.Wait(); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6930 | EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6931 | EXPECT_FALSE(service()->IsExtensionEnabled(page_action)); |
| 6932 | EXPECT_FALSE(service()->IsExtensionEnabled(good_crx)); |
| 6933 | EXPECT_FALSE(service()->IsExtensionEnabled(theme_crx)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6934 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6935 | service()->EnableExtension(page_action); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6936 | EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 6937 | EXPECT_FALSE(service() |
| 6938 | ->external_install_manager() |
| 6939 | ->HasExternalInstallBubbleForTesting()); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6940 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6941 | service()->EnableExtension(theme_crx); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6942 | EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 6943 | EXPECT_FALSE(service() |
| 6944 | ->external_install_manager() |
| 6945 | ->HasExternalInstallBubbleForTesting()); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6946 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6947 | service()->EnableExtension(good_crx); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6948 | EXPECT_FALSE( |
| 6949 | service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 6950 | EXPECT_FALSE(service() |
| 6951 | ->external_install_manager() |
| 6952 | ->HasExternalInstallBubbleForTesting()); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6953 | } |
| 6954 | |
| 6955 | // Test that there is a bubble for external extensions that update |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 6956 | // from the webstore if the profile is not new. |
| 6957 | TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) { |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6958 | FeatureSwitch::ScopedOverride prompt( |
| 6959 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6960 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 6961 | // This sets up the ExtensionPrefs used by our ExtensionService to be |
| 6962 | // post-first run. |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 6963 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 6964 | params.is_first_run = false; |
| 6965 | InitializeExtensionService(params); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6966 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6967 | base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx"); |
| 6968 | PackCRX(data_dir().AppendASCII("update_from_webstore"), |
| 6969 | data_dir().AppendASCII("update_from_webstore.pem"), |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6970 | crx_path); |
| 6971 | |
| 6972 | MockExtensionProvider* provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6973 | new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6974 | AddMockExternalProvider(provider); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6975 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6976 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6977 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6978 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6979 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6980 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6981 | observer.Wait(); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6982 | EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 6983 | EXPECT_TRUE(service() |
| 6984 | ->external_install_manager() |
| 6985 | ->HasExternalInstallBubbleForTesting()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6986 | EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6987 | } |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6988 | |
| 6989 | // Test that there is no bubble for external extensions if the profile is new. |
| 6990 | TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) { |
| 6991 | FeatureSwitch::ScopedOverride prompt( |
| 6992 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6993 | |
| 6994 | InitializeEmptyExtensionService(); |
| 6995 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6996 | base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx"); |
| 6997 | PackCRX(data_dir().AppendASCII("update_from_webstore"), |
| 6998 | data_dir().AppendASCII("update_from_webstore.pem"), |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6999 | crx_path); |
| 7000 | |
| 7001 | MockExtensionProvider* provider = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7002 | new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF); |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 7003 | AddMockExternalProvider(provider); |
| 7004 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
| 7005 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 7006 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 7007 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 7008 | content::NotificationService::AllSources()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7009 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 7010 | observer.Wait(); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 7011 | EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError()); |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 7012 | EXPECT_FALSE(service() |
| 7013 | ->external_install_manager() |
| 7014 | ->HasExternalInstallBubbleForTesting()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7015 | EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore)); |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 7016 | } |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 7017 | |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 7018 | // Test that clicking to remove the extension on an external install warning |
| 7019 | // uninstalls the extension. |
| 7020 | TEST_F(ExtensionServiceTest, ExternalInstallClickToRemove) { |
| 7021 | FeatureSwitch::ScopedOverride prompt( |
| 7022 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 7023 | |
| 7024 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 7025 | params.is_first_run = false; |
| 7026 | InitializeExtensionService(params); |
| 7027 | |
| 7028 | base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx"); |
| 7029 | PackCRX(data_dir().AppendASCII("update_from_webstore"), |
| 7030 | data_dir().AppendASCII("update_from_webstore.pem"), |
| 7031 | crx_path); |
| 7032 | |
| 7033 | MockExtensionProvider* provider = |
| 7034 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 7035 | AddMockExternalProvider(provider); |
| 7036 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
| 7037 | |
| 7038 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 7039 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 7040 | content::NotificationService::AllSources()); |
| 7041 | service_->CheckForExternalUpdates(); |
| 7042 | observer.Wait(); |
| 7043 | EXPECT_TRUE(service_->external_install_manager()->HasExternalInstallError()); |
| 7044 | |
| 7045 | // We check both enabled and disabled, since these are "eventually exclusive" |
| 7046 | // sets. |
| 7047 | EXPECT_TRUE(registry()->disabled_extensions().GetByID(updates_from_webstore)); |
| 7048 | EXPECT_FALSE(registry()->enabled_extensions().GetByID(updates_from_webstore)); |
| 7049 | |
| 7050 | // Click the negative response. |
| 7051 | service_->external_install_manager()->error_for_testing()->InstallUIAbort( |
| 7052 | true); |
| 7053 | // The Extension should be uninstalled. |
| 7054 | EXPECT_FALSE(registry()->GetExtensionById(updates_from_webstore, |
| 7055 | ExtensionRegistry::EVERYTHING)); |
| 7056 | // The error should be removed. |
| 7057 | EXPECT_FALSE(service_->external_install_manager()->HasExternalInstallError()); |
| 7058 | } |
| 7059 | |
| 7060 | // Test that clicking to keep the extension on an external install warning |
| 7061 | // re-enables the extension. |
| 7062 | TEST_F(ExtensionServiceTest, ExternalInstallClickToKeep) { |
| 7063 | FeatureSwitch::ScopedOverride prompt( |
| 7064 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 7065 | |
| 7066 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 7067 | params.is_first_run = false; |
| 7068 | InitializeExtensionService(params); |
| 7069 | |
| 7070 | base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx"); |
| 7071 | PackCRX(data_dir().AppendASCII("update_from_webstore"), |
| 7072 | data_dir().AppendASCII("update_from_webstore.pem"), |
| 7073 | crx_path); |
| 7074 | |
| 7075 | MockExtensionProvider* provider = |
| 7076 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 7077 | AddMockExternalProvider(provider); |
| 7078 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
| 7079 | |
| 7080 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 7081 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 7082 | content::NotificationService::AllSources()); |
| 7083 | service_->CheckForExternalUpdates(); |
| 7084 | observer.Wait(); |
| 7085 | EXPECT_TRUE(service_->external_install_manager()->HasExternalInstallError()); |
| 7086 | |
| 7087 | // We check both enabled and disabled, since these are "eventually exclusive" |
| 7088 | // sets. |
| 7089 | EXPECT_TRUE(registry()->disabled_extensions().GetByID(updates_from_webstore)); |
| 7090 | EXPECT_FALSE(registry()->enabled_extensions().GetByID(updates_from_webstore)); |
| 7091 | |
| 7092 | // Accept the extension. |
| 7093 | service_->external_install_manager()->error_for_testing()->InstallUIProceed(); |
| 7094 | |
| 7095 | // It should be enabled again. |
| 7096 | EXPECT_TRUE(registry()->enabled_extensions().GetByID(updates_from_webstore)); |
| 7097 | EXPECT_FALSE( |
| 7098 | registry()->disabled_extensions().GetByID(updates_from_webstore)); |
| 7099 | |
| 7100 | // The error should be removed. |
| 7101 | EXPECT_FALSE(service_->external_install_manager()->HasExternalInstallError()); |
| 7102 | } |
| 7103 | |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 7104 | TEST_F(ExtensionServiceTest, InstallBlacklistedExtension) { |
| 7105 | InitializeEmptyExtensionService(); |
| 7106 | |
| 7107 | scoped_refptr<Extension> extension = extensions::ExtensionBuilder() |
| 7108 | .SetManifest(extensions::DictionaryBuilder() |
| 7109 | .Set("name", "extension") |
| 7110 | .Set("version", "1.0") |
| 7111 | .Set("manifest_version", 2).Build()) |
| 7112 | .Build(); |
| 7113 | ASSERT_TRUE(extension.get()); |
| 7114 | const std::string& id = extension->id(); |
| 7115 | |
| 7116 | std::set<std::string> id_set; |
| 7117 | id_set.insert(id); |
| 7118 | extensions::ExtensionNotificationObserver notifications( |
| 7119 | content::NotificationService::AllSources(), id_set); |
| 7120 | |
| 7121 | // Installation should be allowed but the extension should never have been |
| 7122 | // loaded and it should be blacklisted in prefs. |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 7123 | service()->OnExtensionInstalled( |
| 7124 | extension.get(), |
| 7125 | syncer::StringOrdinal(), |
| 7126 | (extensions::kInstallFlagIsBlacklistedForMalware | |
| 7127 | extensions::kInstallFlagInstallImmediately)); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 7128 | base::RunLoop().RunUntilIdle(); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 7129 | |
| 7130 | // Extension was installed but not loaded. |
| 7131 | EXPECT_TRUE(notifications.CheckNotifications( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 7132 | extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7133 | EXPECT_TRUE(service()->GetInstalledExtension(id)); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 7134 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7135 | EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 7136 | EXPECT_TRUE(registry()->blacklisted_extensions().Contains(id)); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 7137 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7138 | EXPECT_TRUE(ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(id)); |
| 7139 | EXPECT_TRUE( |
| 7140 | ExtensionPrefs::Get(profile())->IsBlacklistedExtensionAcknowledged(id)); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 7141 | } |
[email protected] | 59ee99d | 2013-10-11 15:46:16 | [diff] [blame] | 7142 | |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 7143 | // Tests a profile being destroyed correctly disables extensions. |
| 7144 | TEST_F(ExtensionServiceTest, DestroyingProfileClearsExtensions) { |
| 7145 | InitializeEmptyExtensionService(); |
| 7146 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7147 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 7148 | EXPECT_NE(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7149 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 7150 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 7151 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 7152 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 7153 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7154 | service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 7155 | content::Source<Profile>(profile()), |
| 7156 | content::NotificationService::NoDetails()); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 7157 | EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7158 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 7159 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 7160 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 7161 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 7162 | } |