[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] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5 | #include "chrome/browser/extensions/extension_service_unittest.h" |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 6 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 8 | #include <set> |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | be5a6db | 2012-11-13 14:39:11 | [diff] [blame] | 11 | #include "base/at_exit.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 12 | #include "base/basictypes.h" |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 13 | #include "base/bind.h" |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 14 | #include "base/command_line.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 15 | #include "base/file_util.h" |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 16 | #include "base/files/file_enumerator.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 17 | #include "base/files/scoped_temp_dir.h" |
[email protected] | ffbec69 | 2012-02-26 20:26:42 | [diff] [blame] | 18 | #include "base/json/json_file_value_serializer.h" |
[email protected] | 93d49d7 | 2009-10-23 20:00:20 | [diff] [blame] | 19 | #include "base/json/json_reader.h" |
[email protected] | ffbec69 | 2012-02-26 20:26:42 | [diff] [blame] | 20 | #include "base/json/json_string_value_serializer.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 21 | #include "base/memory/scoped_ptr.h" |
[email protected] | 71cb8aa | 2011-12-29 19:14:00 | [diff] [blame] | 22 | #include "base/memory/weak_ptr.h" |
[email protected] | b19fe57 | 2013-07-18 04:54:26 | [diff] [blame] | 23 | #include "base/message_loop/message_loop.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 24 | #include "base/path_service.h" |
[email protected] | 9eec53fe | 2013-10-30 20:21:17 | [diff] [blame] | 25 | #include "base/prefs/scoped_user_pref_update.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 26 | #include "base/stl_util.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 27 | #include "base/strings/string16.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 28 | #include "base/strings/string_number_conversions.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 29 | #include "base/strings/string_util.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 30 | #include "base/strings/utf_string_conversions.h" |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 31 | #include "base/version.h" |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 32 | #include "chrome/browser/browser_process.h" |
[email protected] | 9ea0cd3 | 2013-07-12 01:50:36 | [diff] [blame] | 33 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 34 | #include "chrome/browser/extensions/app_sync_data.h" |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 35 | #include "chrome/browser/extensions/blacklist.h" |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 36 | #include "chrome/browser/extensions/chrome_app_sorting.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 37 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | eb6c7ef | 2011-12-12 23:12:20 | [diff] [blame] | 38 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 39 | #include "chrome/browser/extensions/default_apps.h" |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 40 | #include "chrome/browser/extensions/extension_creator.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 41 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 42 | #include "chrome/browser/extensions/extension_error_ui.h" |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 43 | #include "chrome/browser/extensions/extension_notification_observer.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_sync_data.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 47 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 48 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 49 | #include "chrome/browser/extensions/external_install_ui.h" |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 50 | #include "chrome/browser/extensions/external_policy_loader.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 51 | #include "chrome/browser/extensions/external_pref_loader.h" |
| 52 | #include "chrome/browser/extensions/external_provider_impl.h" |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 53 | #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 54 | #include "chrome/browser/extensions/install_observer.h" |
| 55 | #include "chrome/browser/extensions/install_tracker.h" |
| 56 | #include "chrome/browser/extensions/install_tracker_factory.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 57 | #include "chrome/browser/extensions/installed_loader.h" |
[email protected] | f0bfe62 | 2012-06-22 01:01:44 | [diff] [blame] | 58 | #include "chrome/browser/extensions/pack_extension_job.h" |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 59 | #include "chrome/browser/extensions/test_blacklist.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 60 | #include "chrome/browser/extensions/test_extension_system.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 61 | #include "chrome/browser/extensions/unpacked_installer.h" |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 62 | #include "chrome/browser/extensions/updater/extension_updater.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 63 | #include "chrome/browser/prefs/browser_prefs.h" |
[email protected] | e90a01f | 2013-11-19 04:22:12 | [diff] [blame] | 64 | #include "chrome/browser/prefs/pref_service_mock_factory.h" |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 65 | #include "chrome/browser/prefs/pref_service_syncable.h" |
[email protected] | 50736a1 | 2013-09-26 08:58:34 | [diff] [blame] | 66 | #include "chrome/browser/sync/profile_sync_service.h" |
| 67 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 68 | #include "chrome/common/chrome_constants.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 69 | #include "chrome/common/chrome_paths.h" |
| 70 | #include "chrome/common/chrome_switches.h" |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 71 | #include "chrome/common/extensions/api/plugins/plugins_handler.h" |
[email protected] | 6884a80 | 2012-08-07 03:55:22 | [diff] [blame] | 72 | #include "chrome/common/extensions/extension_l10n_util.h" |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 73 | #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 74 | #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 75 | #include "chrome/common/extensions/manifest_url_handler.h" |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 76 | #include "chrome/common/pref_names.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 77 | #include "chrome/common/url_constants.h" |
[email protected] | 078c319 | 2013-08-22 08:18:05 | [diff] [blame] | 78 | #include "chrome/test/base/scoped_browser_locale.h" |
[email protected] | a4ff9eae | 2011-08-01 19:58:16 | [diff] [blame] | 79 | #include "chrome/test/base/testing_profile.h" |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 80 | #include "components/user_prefs/pref_registry_syncable.h" |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 81 | #include "content/public/browser/dom_storage_context.h" |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 82 | #include "content/public/browser/gpu_data_manager.h" |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 83 | #include "content/public/browser/indexed_db_context.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 84 | #include "content/public/browser/notification_registrar.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 85 | #include "content/public/browser/notification_service.h" |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 86 | #include "content/public/browser/plugin_service.h" |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 87 | #include "content/public/browser/render_process_host.h" |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 88 | #include "content/public/browser/storage_partition.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 89 | #include "content/public/common/content_constants.h" |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 90 | #include "content/public/test/test_utils.h" |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 91 | #include "extensions/browser/extension_registry.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 92 | #include "extensions/browser/external_provider_interface.h" |
| 93 | #include "extensions/browser/management_policy.h" |
[email protected] | b52f8ca | 2013-11-28 08:25:22 | [diff] [blame] | 94 | #include "extensions/browser/pending_extension_info.h" |
| 95 | #include "extensions/browser/pending_extension_manager.h" |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 96 | #include "extensions/browser/pref_names.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 97 | #include "extensions/browser/test_management_policy.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 98 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 99 | #include "extensions/common/extension.h" |
[email protected] | 22b7b2c | 2013-11-05 22:52:42 | [diff] [blame] | 100 | #include "extensions/common/extension_builder.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 101 | #include "extensions/common/extension_resource.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] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 105 | #include "extensions/common/url_pattern.h" |
[email protected] | 22b7b2c | 2013-11-05 22:52:42 | [diff] [blame] | 106 | #include "extensions/common/value_builder.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 107 | #include "gpu/config/gpu_info.h" |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 108 | #include "grit/browser_resources.h" |
[email protected] | 5b9bc35 | 2012-07-18 13:13:34 | [diff] [blame] | 109 | #include "net/cookies/canonical_cookie.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 110 | #include "net/cookies/cookie_monster.h" |
| 111 | #include "net/cookies/cookie_options.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 112 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 113 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 114 | #include "sync/api/string_ordinal.h" |
[email protected] | 50736a1 | 2013-09-26 08:58:34 | [diff] [blame] | 115 | #include "sync/api/sync_data.h" |
[email protected] | 895a1e5 | 2012-05-15 02:50:12 | [diff] [blame] | 116 | #include "sync/api/sync_error_factory.h" |
| 117 | #include "sync/api/sync_error_factory_mock.h" |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 118 | #include "sync/api/syncable_service.h" |
[email protected] | 1bcf30e | 2012-03-10 01:06:41 | [diff] [blame] | 119 | #include "sync/protocol/app_specifics.pb.h" |
| 120 | #include "sync/protocol/extension_specifics.pb.h" |
| 121 | #include "sync/protocol/sync.pb.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 122 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | f66c110c | 2008-12-05 20:26:29 | [diff] [blame] | 123 | #include "testing/platform_test.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 124 | #include "url/gurl.h" |
[email protected] | 08b1f75f | 2013-05-22 22:02:38 | [diff] [blame] | 125 | #include "webkit/browser/database/database_tracker.h" |
[email protected] | 7660ec9 | 2013-05-30 05:12:39 | [diff] [blame] | 126 | #include "webkit/browser/quota/quota_manager.h" |
[email protected] | 2a9644c | 2013-06-19 06:19:34 | [diff] [blame] | 127 | #include "webkit/common/database/database_identifier.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 128 | |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 129 | #if defined(OS_CHROMEOS) |
| 130 | #include "chrome/browser/chromeos/extensions/install_limiter.h" |
[email protected] | e4854dc | 2013-04-24 00:11:51 | [diff] [blame] | 131 | #include "chrome/browser/chromeos/login/user_manager.h" |
| 132 | #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 133 | #include "chrome/browser/chromeos/settings/device_settings_service.h" |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 134 | #endif |
| 135 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 136 | // The blacklist tests rely on safe browsing. |
| 137 | #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) |
| 138 | #define ENABLE_BLACKLIST_TESTS |
| 139 | #endif |
| 140 | |
[email protected] | aeca23f | 2013-06-21 22:34:41 | [diff] [blame] | 141 | using base::DictionaryValue; |
| 142 | using base::ListValue; |
| 143 | using base::Value; |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 144 | using content::BrowserContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 145 | using content::BrowserThread; |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 146 | using content::DOMStorageContext; |
| 147 | using content::IndexedDBContext; |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 148 | using content::PluginService; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 149 | using extensions::APIPermission; |
| 150 | using extensions::APIPermissionSet; |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 151 | using extensions::AppSorting; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 152 | using extensions::Blacklist; |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 153 | using extensions::CrxInstaller; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 154 | using extensions::Extension; |
[email protected] | 6d77749 | 2012-07-11 17:33:43 | [diff] [blame] | 155 | using extensions::ExtensionCreator; |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 156 | using extensions::ExtensionPrefs; |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 157 | using extensions::ExtensionRegistry; |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 158 | using extensions::ExtensionResource; |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 159 | using extensions::ExtensionSystem; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 160 | using extensions::FakeSafeBrowsingDatabaseManager; |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 161 | using extensions::FeatureSwitch; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 162 | using extensions::Manifest; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 163 | using extensions::PermissionSet; |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 164 | using extensions::TestExtensionSystem; |
[email protected] | e9f541a | 2012-11-19 21:52:31 | [diff] [blame] | 165 | using extensions::URLPatternSet; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 166 | |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 167 | namespace keys = extensions::manifest_keys; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 168 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 169 | namespace { |
| 170 | |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 171 | // Extension ids used during testing. |
[email protected] | 095ccbe4 | 2013-09-26 00:06:42 | [diff] [blame] | 172 | const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 173 | const char good1[] = "hpiknbiabeeppbpihjehijgoemciehgk"; |
| 174 | const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; |
[email protected] | aa5219d | 2013-11-09 19:25:41 | [diff] [blame] | 175 | const char all_zero[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
[email protected] | 095ccbe4 | 2013-09-26 00:06:42 | [diff] [blame] | 176 | const char good2048[] = "nmgjhmhbleinmjpbdhgajfjkbijcmgbh"; |
| 177 | const char good_crx[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 178 | const char hosted_app[] = "kbmnembihfiondgfjekmnmcbddelicoi"; |
| 179 | const char page_action[] = "obcimlgaoabeegjmmpldobjndiealpln"; |
| 180 | const char theme_crx[] = "iamefpfkojoapidjnbafmgkgncegbkad"; |
| 181 | const char theme2_crx[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 182 | const char permissions_crx[] = "eagpmdpfmaekmmcejjbmjoecnejeiiin"; |
| 183 | const char unpacked[] = "cbcdidchbppangcjoddlpdjlenngjldk"; |
| 184 | const char updates_from_webstore[] = "akjooamlhcgeopfifcmlggaebeocgokj"; |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 185 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 186 | struct ExtensionsOrder { |
[email protected] | 198b590 | 2013-06-27 10:36:11 | [diff] [blame] | 187 | bool operator()(const scoped_refptr<const Extension>& a, |
| 188 | const scoped_refptr<const Extension>& b) { |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 189 | return a->name() < b->name(); |
| 190 | } |
| 191 | }; |
| 192 | |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 193 | static std::vector<base::string16> GetErrors() { |
| 194 | const std::vector<base::string16>* errors = |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 195 | ExtensionErrorReporter::GetInstance()->GetErrors(); |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 196 | std::vector<base::string16> ret_val; |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 197 | |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 198 | for (std::vector<base::string16>::const_iterator iter = errors->begin(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 199 | iter != errors->end(); ++iter) { |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 200 | std::string utf8_error = base::UTF16ToUTF8(*iter); |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 201 | if (utf8_error.find(".svn") == std::string::npos) { |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 202 | ret_val.push_back(*iter); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | // The tests rely on the errors being in a certain order, which can vary |
| 207 | // depending on how filesystem iteration works. |
| 208 | std::stable_sort(ret_val.begin(), ret_val.end()); |
| 209 | |
| 210 | return ret_val; |
| 211 | } |
| 212 | |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 213 | static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 214 | int schemes = URLPattern::SCHEME_ALL; |
| 215 | extent->AddPattern(URLPattern(schemes, pattern)); |
| 216 | } |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 217 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 218 | base::FilePath GetTemporaryFile() { |
| 219 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 220 | CHECK(base::CreateTemporaryFile(&temp_file)); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 221 | return temp_file; |
| 222 | } |
| 223 | |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 224 | bool WaitForCountNotificationsCallback(int *count) { |
| 225 | return --(*count) == 0; |
| 226 | } |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 227 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 228 | } // namespace |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 229 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 230 | class MockExtensionProvider : public extensions::ExternalProviderInterface { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 231 | public: |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 232 | MockExtensionProvider( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 233 | VisitorInterface* visitor, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 234 | Manifest::Location location) |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 235 | : location_(location), visitor_(visitor), visit_count_(0) { |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 236 | } |
| 237 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 238 | virtual ~MockExtensionProvider() {} |
| 239 | |
| 240 | void UpdateOrAddExtension(const std::string& id, |
| 241 | const std::string& version, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 242 | const base::FilePath& path) { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 243 | extension_map_[id] = std::make_pair(version, path); |
| 244 | } |
| 245 | |
| 246 | void RemoveExtension(const std::string& id) { |
| 247 | extension_map_.erase(id); |
| 248 | } |
| 249 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 250 | // ExternalProvider implementation: |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 251 | virtual void VisitRegisteredExtension() OVERRIDE { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 252 | visit_count_++; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 253 | for (DataMap::const_iterator i = extension_map_.begin(); |
| 254 | i != extension_map_.end(); ++i) { |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 255 | Version version(i->second.first); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 256 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 257 | visitor_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 258 | i->first, &version, i->second.second, location_, |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 259 | Extension::NO_FLAGS, false); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 260 | } |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 261 | visitor_->OnExternalProviderReady(this); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 262 | } |
| 263 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 264 | virtual bool HasExtension(const std::string& id) const OVERRIDE { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 265 | return extension_map_.find(id) != extension_map_.end(); |
| 266 | } |
| 267 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 268 | virtual bool GetExtensionDetails( |
| 269 | const std::string& id, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 270 | Manifest::Location* location, |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 271 | scoped_ptr<Version>* version) const OVERRIDE { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 272 | DataMap::const_iterator it = extension_map_.find(id); |
| 273 | if (it == extension_map_.end()) |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 274 | return false; |
| 275 | |
| 276 | if (version) |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 277 | version->reset(new Version(it->second.first)); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 278 | |
| 279 | if (location) |
| 280 | *location = location_; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 281 | |
| 282 | return true; |
| 283 | } |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 284 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 285 | virtual bool IsReady() const OVERRIDE { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 286 | return true; |
| 287 | } |
| 288 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 289 | virtual void ServiceShutdown() OVERRIDE { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 290 | } |
| 291 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 292 | int visit_count() const { return visit_count_; } |
| 293 | void set_visit_count(int visit_count) { |
| 294 | visit_count_ = visit_count; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | private: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 298 | typedef std::map< std::string, std::pair<std::string, base::FilePath> > |
| 299 | DataMap; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 300 | DataMap extension_map_; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 301 | Manifest::Location location_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 302 | VisitorInterface* visitor_; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 303 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 304 | // visit_count_ tracks the number of calls to VisitRegisteredExtension(). |
| 305 | // Mutable because it must be incremented on each call to |
| 306 | // VisitRegisteredExtension(), which must be a const method to inherit |
| 307 | // from the class being mocked. |
| 308 | mutable int visit_count_; |
| 309 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 310 | DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider); |
| 311 | }; |
| 312 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 313 | class MockProviderVisitor |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 314 | : public extensions::ExternalProviderInterface::VisitorInterface { |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 315 | public: |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 316 | // The provider will return |fake_base_path| from |
| 317 | // GetBaseCrxFilePath(). User can test the behavior with |
| 318 | // and without an empty path using this parameter. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 319 | explicit MockProviderVisitor(base::FilePath fake_base_path) |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 320 | : ids_found_(0), |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 321 | fake_base_path_(fake_base_path), |
| 322 | expected_creation_flags_(Extension::NO_FLAGS) { |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 323 | profile_.reset(new TestingProfile); |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 324 | } |
| 325 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 326 | MockProviderVisitor(base::FilePath fake_base_path, |
| 327 | int expected_creation_flags) |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 328 | : ids_found_(0), |
| 329 | fake_base_path_(fake_base_path), |
| 330 | expected_creation_flags_(expected_creation_flags) { |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 331 | } |
| 332 | |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 333 | int Visit(const std::string& json_data) { |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 334 | // Give the test json file to the provider for parsing. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 335 | provider_.reset(new extensions::ExternalProviderImpl( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 336 | this, |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 337 | new extensions::ExternalTestingLoader(json_data, fake_base_path_), |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 338 | profile_.get(), |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 339 | Manifest::EXTERNAL_PREF, |
| 340 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 341 | Extension::NO_FLAGS)); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 342 | |
| 343 | // We also parse the file into a dictionary to compare what we get back |
| 344 | // from the provider. |
| 345 | JSONStringValueSerializer serializer(json_data); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 346 | base::Value* json_value = serializer.Deserialize(NULL, NULL); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 347 | |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 348 | if (!json_value || !json_value->IsType(base::Value::TYPE_DICTIONARY)) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 349 | NOTREACHED() << "Unable to deserialize json data"; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 350 | return -1; |
| 351 | } else { |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 352 | base::DictionaryValue* external_extensions = |
| 353 | static_cast<base::DictionaryValue*>(json_value); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 354 | prefs_.reset(external_extensions); |
| 355 | } |
| 356 | |
| 357 | // Reset our counter. |
| 358 | ids_found_ = 0; |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 359 | // Ask the provider to look up all extensions and return them. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 360 | provider_->VisitRegisteredExtension(); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 361 | |
| 362 | return ids_found_; |
| 363 | } |
| 364 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 365 | virtual bool OnExternalExtensionFileFound(const std::string& id, |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 366 | const Version* version, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 367 | const base::FilePath& path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 368 | Manifest::Location unused, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 369 | int creation_flags, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 370 | bool mark_acknowledged) OVERRIDE { |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 371 | EXPECT_EQ(expected_creation_flags_, creation_flags); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 372 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 373 | ++ids_found_; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 374 | base::DictionaryValue* pref; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 375 | // This tests is to make sure that the provider only notifies us of the |
| 376 | // values we gave it. So if the id we doesn't exist in our internal |
| 377 | // dictionary then something is wrong. |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 378 | EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
| 379 | << "Got back ID (" << id.c_str() << ") we weren't expecting"; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 380 | |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 381 | EXPECT_TRUE(path.IsAbsolute()); |
| 382 | if (!fake_base_path_.empty()) |
| 383 | EXPECT_TRUE(fake_base_path_.IsParent(path)); |
| 384 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 385 | if (pref) { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 386 | EXPECT_TRUE(provider_->HasExtension(id)); |
| 387 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 388 | // Ask provider if the extension we got back is registered. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 389 | Manifest::Location location = Manifest::INVALID_LOCATION; |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 390 | scoped_ptr<Version> v1; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 391 | base::FilePath crx_path; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 392 | |
| 393 | EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1)); |
| 394 | EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); |
| 395 | |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 396 | scoped_ptr<Version> v2; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 397 | EXPECT_TRUE(provider_->GetExtensionDetails(id, &location, &v2)); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 398 | EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); |
| 399 | EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 400 | EXPECT_EQ(Manifest::EXTERNAL_PREF, location); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 401 | |
| 402 | // Remove it so we won't count it ever again. |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 403 | prefs_->Remove(id, NULL); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 404 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 405 | return true; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 406 | } |
| 407 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 408 | virtual bool OnExternalExtensionUpdateUrlFound( |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 409 | const std::string& id, const GURL& update_url, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 410 | Manifest::Location location, |
| 411 | int creation_flags, |
| 412 | bool mark_acknowledged) OVERRIDE { |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 413 | ++ids_found_; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 414 | base::DictionaryValue* pref; |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 415 | // This tests is to make sure that the provider only notifies us of the |
| 416 | // values we gave it. So if the id we doesn't exist in our internal |
| 417 | // dictionary then something is wrong. |
| 418 | EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
| 419 | << L"Got back ID (" << id.c_str() << ") we weren't expecting"; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 420 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 421 | |
| 422 | if (pref) { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 423 | EXPECT_TRUE(provider_->HasExtension(id)); |
| 424 | |
| 425 | // External extensions with update URLs do not have versions. |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 426 | scoped_ptr<Version> v1; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 427 | Manifest::Location location1 = Manifest::INVALID_LOCATION; |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 428 | EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 429 | EXPECT_FALSE(v1.get()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 430 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 431 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 432 | // Remove it so we won't count it again. |
| 433 | prefs_->Remove(id, NULL); |
| 434 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 435 | return true; |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 436 | } |
| 437 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 438 | virtual void OnExternalProviderReady( |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 439 | const extensions::ExternalProviderInterface* provider) OVERRIDE { |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 440 | EXPECT_EQ(provider, provider_.get()); |
| 441 | EXPECT_TRUE(provider->IsReady()); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 442 | } |
| 443 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 444 | private: |
| 445 | int ids_found_; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 446 | base::FilePath fake_base_path_; |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 447 | int expected_creation_flags_; |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 448 | scoped_ptr<extensions::ExternalProviderImpl> provider_; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 449 | scoped_ptr<base::DictionaryValue> prefs_; |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 450 | scoped_ptr<TestingProfile> profile_; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 451 | |
| 452 | DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 453 | }; |
| 454 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 455 | ExtensionServiceTestBase::ExtensionServiceInitParams:: |
| 456 | ExtensionServiceInitParams() |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 457 | : autoupdate_enabled(false), is_first_run(true), profile_is_managed(false) { |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 458 | } |
| 459 | |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 460 | // Our message loop may be used in tests which require it to be an IO loop. |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 461 | ExtensionServiceTestBase::ExtensionServiceTestBase() |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 462 | : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
[email protected] | 32e2e9b | 2011-11-18 18:56:45 | [diff] [blame] | 463 | service_(NULL), |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 464 | management_policy_(NULL), |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 465 | expected_extensions_count_(0) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 466 | base::FilePath test_data_dir; |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 467 | if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { |
| 468 | ADD_FAILURE(); |
| 469 | return; |
| 470 | } |
| 471 | data_dir_ = test_data_dir.AppendASCII("extensions"); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 472 | } |
| 473 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 474 | ExtensionServiceTestBase::~ExtensionServiceTestBase() { |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 475 | service_ = NULL; |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 476 | } |
| 477 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 478 | void ExtensionServiceTestBase::InitializeExtensionService( |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 479 | const ExtensionServiceTestBase::ExtensionServiceInitParams& params) { |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 480 | profile_ = CreateTestingProfile(params); |
| 481 | service_ = InitializeExtensionServiceForProfile(params, profile_.get()); |
| 482 | management_policy_ = |
| 483 | ExtensionSystem::Get(profile_.get())->management_policy(); |
| 484 | extensions_install_dir_ = params.extensions_install_dir; |
| 485 | expected_extensions_count_ = 0; |
| 486 | } |
| 487 | |
| 488 | // static |
| 489 | scoped_ptr<TestingProfile> ExtensionServiceTestBase::CreateTestingProfile( |
| 490 | const ExtensionServiceInitParams& params) { |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 491 | TestingProfile::Builder profile_builder; |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 492 | // Create a PrefService that only contains user defined preference values. |
[email protected] | e90a01f | 2013-11-19 04:22:12 | [diff] [blame] | 493 | PrefServiceMockFactory factory; |
[email protected] | a50e38f | 2013-07-22 16:47:00 | [diff] [blame] | 494 | // If pref_file is empty, TestingProfile automatically creates |
| 495 | // TestingPrefServiceSyncable instance. |
| 496 | if (!params.pref_file.empty()) { |
[email protected] | e90a01f | 2013-11-19 04:22:12 | [diff] [blame] | 497 | factory.SetUserPrefsFile(params.pref_file, |
| 498 | base::MessageLoopProxy::current().get()); |
[email protected] | a50e38f | 2013-07-22 16:47:00 | [diff] [blame] | 499 | scoped_refptr<user_prefs::PrefRegistrySyncable> registry( |
| 500 | new user_prefs::PrefRegistrySyncable); |
| 501 | scoped_ptr<PrefServiceSyncable> prefs( |
[email protected] | e90a01f | 2013-11-19 04:22:12 | [diff] [blame] | 502 | factory.CreateSyncable(registry.get())); |
[email protected] | a50e38f | 2013-07-22 16:47:00 | [diff] [blame] | 503 | chrome::RegisterUserProfilePrefs(registry.get()); |
| 504 | profile_builder.SetPrefService(prefs.Pass()); |
| 505 | } |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 506 | |
| 507 | if (params.profile_is_managed) |
| 508 | profile_builder.SetManagedUserId("asdf"); |
| 509 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 510 | profile_builder.SetPath(params.profile_path); |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 511 | return profile_builder.Build(); |
| 512 | } |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 513 | |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 514 | // static |
| 515 | ExtensionService* |
| 516 | ExtensionServiceTestBase::InitializeExtensionServiceForProfile( |
| 517 | const ExtensionServiceInitParams& params, |
| 518 | Profile* profile) { |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 519 | TestExtensionSystem* system = static_cast<TestExtensionSystem*>( |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 520 | ExtensionSystem::Get(profile)); |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 521 | if (!params.is_first_run) { |
| 522 | ExtensionPrefs* prefs = system->CreateExtensionPrefs( |
| 523 | CommandLine::ForCurrentProcess(), |
| 524 | params.extensions_install_dir); |
| 525 | prefs->SetAlertSystemFirstRun(); |
| 526 | } |
| 527 | |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 528 | ExtensionService* service = system->CreateExtensionService( |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 529 | CommandLine::ForCurrentProcess(), |
| 530 | params.extensions_install_dir, |
| 531 | params.autoupdate_enabled); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 532 | |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 533 | service->SetFileTaskRunnerForTesting( |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 534 | base::MessageLoopProxy::current().get()); |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 535 | service->set_extensions_enabled(true); |
| 536 | service->set_show_extensions_prompts(false); |
| 537 | service->set_install_updates_when_idle_for_test(false); |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 538 | |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 539 | // When we start up, we want to make sure there is no external provider, |
| 540 | // since the ExtensionService on Windows will use the Registry as a default |
| 541 | // provider and if there is something already registered there then it will |
| 542 | // interfere with the tests. Those tests that need an external provider |
| 543 | // will register one specifically. |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 544 | service->ClearProvidersForTesting(); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 545 | |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 546 | #if defined(OS_CHROMEOS) |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 547 | extensions::InstallLimiter::Get(profile)->DisableForTest(); |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 548 | #endif |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 549 | return service; |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 550 | } |
| 551 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 552 | void ExtensionServiceTestBase::InitializeInstalledExtensionService( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 553 | const base::FilePath& prefs_file, |
| 554 | const base::FilePath& source_install_dir) { |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 555 | EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 556 | base::FilePath path = temp_dir_.path(); |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 557 | path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 558 | EXPECT_TRUE(base::DeleteFile(path, true)); |
[email protected] | 54124ed0 | 2014-01-07 10:06:58 | [diff] [blame] | 559 | base::File::Error error = base::File::FILE_OK; |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 560 | EXPECT_TRUE(base::CreateDirectoryAndGetError(path, &error)) << error; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 561 | base::FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences")); |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 562 | EXPECT_TRUE(base::CopyFile(prefs_file, temp_prefs)); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 563 | |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 564 | base::FilePath extensions_install_dir = |
| 565 | path.Append(FILE_PATH_LITERAL("Extensions")); |
| 566 | EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); |
| 567 | EXPECT_TRUE( |
| 568 | base::CopyDirectory(source_install_dir, extensions_install_dir, true)); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 569 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 570 | ExtensionServiceInitParams params; |
| 571 | params.profile_path = path; |
| 572 | params.pref_file = temp_prefs; |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 573 | params.extensions_install_dir = extensions_install_dir; |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 574 | InitializeExtensionService(params); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 575 | } |
| 576 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 577 | void ExtensionServiceTestBase::InitializeGoodInstalledExtensionService() { |
| 578 | base::FilePath source_install_dir = data_dir_ |
| 579 | .AppendASCII("good") |
| 580 | .AppendASCII("Extensions"); |
| 581 | base::FilePath pref_path = source_install_dir |
| 582 | .DirName() |
| 583 | .AppendASCII("Preferences"); |
| 584 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 585 | } |
| 586 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 587 | void ExtensionServiceTestBase::InitializeEmptyExtensionService() { |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 588 | InitializeExtensionService(CreateDefaultInitParams()); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 589 | } |
| 590 | |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 591 | void ExtensionServiceTestBase::InitializeProcessManager() { |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 592 | static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 593 | ExtensionSystem::Get(profile_.get()))-> |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 594 | CreateProcessManager(); |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 595 | } |
| 596 | |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 597 | void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 598 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 599 | params.autoupdate_enabled = true; |
| 600 | InitializeExtensionService(params); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 601 | service_->updater()->Start(); |
| 602 | } |
| 603 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 604 | void ExtensionServiceTestBase::InitializeExtensionSyncService() { |
| 605 | extension_sync_service_.reset(new ExtensionSyncService( |
| 606 | profile_.get(), service_->extension_prefs(), service_)); |
| 607 | } |
| 608 | |
| 609 | // static |
| 610 | void ExtensionServiceTestBase::SetUpTestCase() { |
| 611 | ExtensionErrorReporter::Init(false); // no noisy errors |
| 612 | } |
| 613 | |
| 614 | void ExtensionServiceTestBase::SetUp() { |
| 615 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | void ExtensionServiceTestBase::TearDown() { |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 619 | } |
| 620 | |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 621 | ExtensionServiceTestBase::ExtensionServiceInitParams |
| 622 | ExtensionServiceTestBase::CreateDefaultInitParams() { |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 623 | return CreateDefaultInitParamsInTempDir(&temp_dir_); |
| 624 | } |
| 625 | |
| 626 | // static |
| 627 | ExtensionServiceTestBase::ExtensionServiceInitParams |
| 628 | ExtensionServiceTestBase::CreateDefaultInitParamsInTempDir( |
| 629 | base::ScopedTempDir* temp_dir) { |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 630 | ExtensionServiceInitParams params; |
[email protected] | 82ac12c2 | 2013-11-21 13:05:21 | [diff] [blame] | 631 | EXPECT_TRUE(temp_dir->CreateUniqueTempDir()); |
| 632 | base::FilePath path = temp_dir->path(); |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 633 | path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 634 | EXPECT_TRUE(base::DeleteFile(path, true)); |
[email protected] | 54124ed0 | 2014-01-07 10:06:58 | [diff] [blame] | 635 | base::File::Error error = base::File::FILE_OK; |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 636 | EXPECT_TRUE(base::CreateDirectoryAndGetError(path, &error)) << error; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 637 | base::FilePath prefs_filename = |
| 638 | path.Append(FILE_PATH_LITERAL("TestPreferences")); |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 639 | base::FilePath extensions_install_dir = |
| 640 | path.Append(FILE_PATH_LITERAL("Extensions")); |
| 641 | EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 642 | EXPECT_TRUE(base::CreateDirectoryAndGetError(extensions_install_dir, |
| 643 | &error)) << error; |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 644 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 645 | params.profile_path = path; |
| 646 | params.pref_file = prefs_filename; |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 647 | params.extensions_install_dir = extensions_install_dir; |
| 648 | return params; |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 649 | } |
| 650 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 651 | class ExtensionServiceTest |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 652 | : public ExtensionServiceTestBase, public content::NotificationObserver { |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 653 | public: |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 654 | ExtensionServiceTest() |
| 655 | : installed_(NULL), |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 656 | was_update_(false), |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 657 | override_external_install_prompt_( |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 658 | FeatureSwitch::prompt_for_external_extensions(), false) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 659 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 660 | content::NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 661 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 662 | content::NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 663 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 664 | content::NotificationService::AllSources()); |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 665 | } |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 666 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 667 | virtual void Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 668 | const content::NotificationSource& source, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 669 | const content::NotificationDetails& details) OVERRIDE { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 670 | switch (type) { |
| 671 | case chrome::NOTIFICATION_EXTENSION_LOADED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 672 | const Extension* extension = |
| 673 | content::Details<const Extension>(details).ptr(); |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 674 | loaded_.push_back(make_scoped_refptr(extension)); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 675 | // The tests rely on the errors being in a certain order, which can vary |
| 676 | // depending on how filesystem iteration works. |
| 677 | std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder()); |
| 678 | break; |
| 679 | } |
| 680 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 681 | case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 682 | const Extension* e = |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 683 | content::Details<extensions::UnloadedExtensionInfo>( |
| 684 | details)->extension; |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 685 | unloaded_id_ = e->id(); |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 686 | extensions::ExtensionList::iterator i = |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 687 | std::find(loaded_.begin(), loaded_.end(), e); |
| 688 | // TODO(erikkay) fix so this can be an assert. Right now the tests |
| 689 | // are manually calling clear() on loaded_, so this isn't doable. |
| 690 | if (i == loaded_.end()) |
| 691 | return; |
| 692 | loaded_.erase(i); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 693 | break; |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 694 | } |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 695 | case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
| 696 | const extensions::InstalledExtensionInfo* installed_info = |
| 697 | content::Details<const extensions::InstalledExtensionInfo>(details) |
| 698 | .ptr(); |
| 699 | installed_ = installed_info->extension; |
| 700 | was_update_ = installed_info->is_update; |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 701 | old_name_ = installed_info->old_name; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 702 | break; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 703 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 704 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 705 | default: |
| 706 | DCHECK(false); |
[email protected] | 3acbd42 | 2008-12-08 18:25:00 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 710 | void AddMockExternalProvider( |
| 711 | extensions::ExternalProviderInterface* provider) { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 712 | service_->AddProviderForTesting(provider); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 713 | } |
| 714 | |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 715 | void MockSyncStartFlare(bool* was_called, |
| 716 | syncer::ModelType* model_type_passed_in, |
| 717 | syncer::ModelType model_type) { |
| 718 | *was_called = true; |
| 719 | *model_type_passed_in = model_type; |
| 720 | } |
| 721 | |
[email protected] | 9197f3b | 2009-06-02 00:49:27 | [diff] [blame] | 722 | protected: |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 723 | // Paths to some of the fake extensions. |
| 724 | base::FilePath good0_path() { |
| 725 | return data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 726 | .AppendASCII(good0).AppendASCII("1.0.0.0"); |
| 727 | } |
| 728 | |
| 729 | base::FilePath good1_path() { |
| 730 | return data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 731 | .AppendASCII(good1).AppendASCII("2"); |
| 732 | } |
| 733 | |
| 734 | base::FilePath good2_path() { |
| 735 | return data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 736 | .AppendASCII(good2).AppendASCII("1.0"); |
| 737 | } |
| 738 | |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 739 | void TestExternalProvider(MockExtensionProvider* provider, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 740 | Manifest::Location location); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 741 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 742 | void PackCRX(const base::FilePath& dir_path, |
| 743 | const base::FilePath& pem_path, |
| 744 | const base::FilePath& crx_path) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 745 | // Use the existing pem key, if provided. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 746 | base::FilePath pem_output_path; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 747 | if (pem_path.value().empty()) { |
| 748 | pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 749 | } else { |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 750 | ASSERT_TRUE(base::PathExists(pem_path)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 751 | } |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 752 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 753 | ASSERT_TRUE(base::DeleteFile(crx_path, false)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 754 | |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 755 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 756 | ASSERT_TRUE(creator->Run(dir_path, |
| 757 | crx_path, |
| 758 | pem_path, |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 759 | pem_output_path, |
| 760 | ExtensionCreator::kOverwriteCRX)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 761 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 762 | ASSERT_TRUE(base::PathExists(crx_path)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 763 | } |
| 764 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 765 | enum InstallState { |
| 766 | INSTALL_FAILED, |
| 767 | INSTALL_UPDATED, |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 768 | INSTALL_NEW, |
| 769 | INSTALL_WITHOUT_LOAD, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 770 | }; |
| 771 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 772 | const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
| 773 | const base::FilePath& pem_path, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 774 | InstallState install_state, |
| 775 | int creation_flags) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 776 | base::FilePath crx_path; |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 777 | base::ScopedTempDir temp_dir; |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 778 | EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 779 | crx_path = temp_dir.path().AppendASCII("temp.crx"); |
| 780 | |
| 781 | PackCRX(dir_path, pem_path, crx_path); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 782 | return InstallCRX(crx_path, install_state, creation_flags); |
| 783 | } |
| 784 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 785 | const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
| 786 | const base::FilePath& pem_path, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 787 | InstallState install_state) { |
| 788 | return PackAndInstallCRX(dir_path, pem_path, install_state, |
| 789 | Extension::NO_FLAGS); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 790 | } |
| 791 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 792 | const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 793 | InstallState install_state) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 794 | return PackAndInstallCRX(dir_path, base::FilePath(), install_state, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 795 | Extension::NO_FLAGS); |
| 796 | } |
| 797 | |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 798 | // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 799 | // is expected to fail. |
| 800 | // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is |
| 801 | // non-empty, expects that the existing extension's title was |
| 802 | // |expected_old_name|. |
| 803 | const Extension* InstallCRX(const base::FilePath& path, |
| 804 | InstallState install_state, |
| 805 | int creation_flags, |
| 806 | const std::string& expected_old_name) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 807 | InstallCRXInternal(path, creation_flags); |
| 808 | return VerifyCrxInstall(path, install_state, expected_old_name); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 812 | // is expected to fail. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 813 | const Extension* InstallCRX(const base::FilePath& path, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 814 | InstallState install_state, |
| 815 | int creation_flags) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 816 | return InstallCRX(path, install_state, creation_flags, std::string()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 817 | } |
| 818 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 819 | // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 820 | // is expected to fail. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 821 | const Extension* InstallCRX(const base::FilePath& path, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 822 | InstallState install_state) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 823 | return InstallCRX(path, install_state, Extension::NO_FLAGS); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 824 | } |
| 825 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 826 | const Extension* InstallCRXFromWebStore(const base::FilePath& path, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 827 | InstallState install_state) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 828 | InstallCRXInternal(path, Extension::FROM_WEBSTORE); |
| 829 | return VerifyCrxInstall(path, install_state); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 830 | } |
| 831 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 832 | const Extension* InstallCRXWithLocation(const base::FilePath& crx_path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 833 | Manifest::Location install_location, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 834 | InstallState install_state) { |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 835 | EXPECT_TRUE(base::PathExists(crx_path)) |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 836 | << "Path does not exist: "<< crx_path.value().c_str(); |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 837 | // no client (silent install) |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 838 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 839 | installer->set_install_source(install_location); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 840 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 841 | content::WindowedNotificationObserver observer( |
| 842 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 843 | content::NotificationService::AllSources()); |
| 844 | installer->InstallCrx(crx_path); |
| 845 | observer.Wait(); |
| 846 | |
| 847 | return VerifyCrxInstall(crx_path, install_state); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 848 | } |
| 849 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 850 | // Verifies the result of a CRX installation. Used by InstallCRX. Set the |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 851 | // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 852 | // Returns an Extension pointer if the install succeeded, NULL otherwise. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 853 | const Extension* VerifyCrxInstall(const base::FilePath& path, |
| 854 | InstallState install_state) { |
| 855 | return VerifyCrxInstall(path, install_state, std::string()); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 856 | } |
| 857 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 858 | // Verifies the result of a CRX installation. Used by InstallCRX. Set the |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 859 | // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
| 860 | // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is |
| 861 | // non-empty, expects that the existing extension's title was |
| 862 | // |expected_old_name|. |
| 863 | // Returns an Extension pointer if the install succeeded, NULL otherwise. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 864 | const Extension* VerifyCrxInstall(const base::FilePath& path, |
| 865 | InstallState install_state, |
| 866 | const std::string& expected_old_name) { |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 867 | std::vector<base::string16> errors = GetErrors(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 868 | const Extension* extension = NULL; |
| 869 | if (install_state != INSTALL_FAILED) { |
| 870 | if (install_state == INSTALL_NEW) |
| 871 | ++expected_extensions_count_; |
[email protected] | 902f7cd | 2009-05-22 19:02:19 | [diff] [blame] | 872 | |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 873 | EXPECT_TRUE(installed_) << path.value(); |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 874 | // If and only if INSTALL_UPDATED, it should have the is_update flag. |
| 875 | EXPECT_EQ(install_state == INSTALL_UPDATED, was_update_) |
| 876 | << path.value(); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 877 | // If INSTALL_UPDATED, old_name_ should match the given string. |
| 878 | if (install_state == INSTALL_UPDATED && !expected_old_name.empty()) |
| 879 | EXPECT_EQ(expected_old_name, old_name_); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 880 | EXPECT_EQ(0u, errors.size()) << path.value(); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 881 | |
| 882 | if (install_state == INSTALL_WITHOUT_LOAD) { |
| 883 | EXPECT_EQ(0u, loaded_.size()) << path.value(); |
| 884 | } else { |
| 885 | EXPECT_EQ(1u, loaded_.size()) << path.value(); |
[email protected] | b1ac7046 | 2013-08-14 21:33:30 | [diff] [blame] | 886 | size_t actual_extension_count = service_->extensions()->size() + |
| 887 | service_->disabled_extensions()->size(); |
| 888 | EXPECT_EQ(expected_extensions_count_, actual_extension_count) << |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 889 | path.value(); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 890 | extension = loaded_[0].get(); |
| 891 | EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) |
| 892 | << path.value(); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 893 | } |
| 894 | |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 895 | for (std::vector<base::string16>::iterator err = errors.begin(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 896 | err != errors.end(); ++err) { |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 897 | LOG(ERROR) << *err; |
| 898 | } |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 899 | } else { |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 900 | EXPECT_FALSE(installed_) << path.value(); |
[email protected] | 86a27407 | 2009-06-11 02:06:45 | [diff] [blame] | 901 | EXPECT_EQ(0u, loaded_.size()) << path.value(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 902 | EXPECT_EQ(1u, errors.size()) << path.value(); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 903 | } |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 904 | |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 905 | installed_ = NULL; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 906 | was_update_ = false; |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 907 | old_name_ = ""; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 908 | loaded_.clear(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 909 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 910 | return extension; |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 911 | } |
| 912 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 913 | enum UpdateState { |
| 914 | FAILED_SILENTLY, |
| 915 | FAILED, |
| 916 | UPDATED, |
| 917 | INSTALLED, |
| 918 | ENABLED |
| 919 | }; |
| 920 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 921 | void BlackListWebGL() { |
| 922 | static const std::string json_blacklist = |
| 923 | "{\n" |
| 924 | " \"name\": \"gpu blacklist\",\n" |
| 925 | " \"version\": \"1.0\",\n" |
| 926 | " \"entries\": [\n" |
| 927 | " {\n" |
| 928 | " \"id\": 1,\n" |
[email protected] | 3d34657 | 2013-03-22 19:59:55 | [diff] [blame] | 929 | " \"features\": [\"webgl\"]\n" |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 930 | " }\n" |
| 931 | " ]\n" |
| 932 | "}"; |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 933 | gpu::GPUInfo gpu_info; |
[email protected] | 7e34315 | 2012-09-20 21:49:53 | [diff] [blame] | 934 | content::GpuDataManager::GetInstance()->InitializeForTesting( |
| 935 | json_blacklist, gpu_info); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 936 | } |
| 937 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 938 | // Helper method to set up a WindowedNotificationObserver to wait for a |
| 939 | // specific CrxInstaller to finish if we don't know the value of the |
| 940 | // |installer| yet. |
| 941 | static bool IsCrxInstallerDone(extensions::CrxInstaller** installer, |
| 942 | const content::NotificationSource& source, |
| 943 | const content::NotificationDetails& details) { |
| 944 | return content::Source<extensions::CrxInstaller>(source).ptr() == |
| 945 | *installer; |
| 946 | } |
| 947 | |
| 948 | void UpdateExtension(const std::string& id, |
| 949 | const base::FilePath& in_path, |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 950 | UpdateState expected_state) { |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 951 | ASSERT_TRUE(base::PathExists(in_path)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 952 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 953 | // We need to copy this to a temporary location because Update() will delete |
| 954 | // it. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 955 | base::FilePath path = temp_dir_.path(); |
[email protected] | a1295ba2 | 2009-09-02 03:33:39 | [diff] [blame] | 956 | path = path.Append(in_path.BaseName()); |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 957 | ASSERT_TRUE(base::CopyFile(in_path, path)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 958 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 959 | int previous_enabled_extension_count = |
| 960 | service_->extensions()->size(); |
| 961 | int previous_installed_extension_count = |
| 962 | previous_enabled_extension_count + |
| 963 | service_->disabled_extensions()->size(); |
| 964 | |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 965 | extensions::CrxInstaller* installer = NULL; |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 966 | content::WindowedNotificationObserver observer( |
| 967 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 968 | base::Bind(&IsCrxInstallerDone, &installer)); |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 969 | service_->UpdateExtension(id, path, true, GURL(), &installer); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 970 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 971 | if (installer) |
| 972 | observer.Wait(); |
| 973 | else |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 974 | base::RunLoop().RunUntilIdle(); |
[email protected] | f3113e23 | 2010-06-25 01:36:40 | [diff] [blame] | 975 | |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 976 | std::vector<base::string16> errors = GetErrors(); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 977 | int error_count = errors.size(); |
| 978 | int enabled_extension_count = |
| 979 | service_->extensions()->size(); |
| 980 | int installed_extension_count = |
| 981 | enabled_extension_count + service_->disabled_extensions()->size(); |
| 982 | |
| 983 | int expected_error_count = (expected_state == FAILED) ? 1 : 0; |
| 984 | EXPECT_EQ(expected_error_count, error_count) << path.value(); |
| 985 | |
| 986 | if (expected_state <= FAILED) { |
| 987 | EXPECT_EQ(previous_enabled_extension_count, |
| 988 | enabled_extension_count); |
| 989 | EXPECT_EQ(previous_installed_extension_count, |
| 990 | installed_extension_count); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 991 | } else { |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 992 | int expected_installed_extension_count = |
| 993 | (expected_state >= INSTALLED) ? 1 : 0; |
| 994 | int expected_enabled_extension_count = |
| 995 | (expected_state >= ENABLED) ? 1 : 0; |
| 996 | EXPECT_EQ(expected_installed_extension_count, |
| 997 | installed_extension_count); |
| 998 | EXPECT_EQ(expected_enabled_extension_count, |
| 999 | enabled_extension_count); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 1000 | } |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1001 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1002 | // Update() should the temporary input file. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1003 | EXPECT_FALSE(base::PathExists(path)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 1004 | } |
| 1005 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1006 | void TerminateExtension(const std::string& id) { |
| 1007 | const Extension* extension = service_->GetInstalledExtension(id); |
| 1008 | if (!extension) { |
| 1009 | ADD_FAILURE(); |
| 1010 | return; |
| 1011 | } |
| 1012 | service_->TrackTerminatedExtensionForTest(extension); |
| 1013 | } |
| 1014 | |
| 1015 | size_t GetPrefKeyCount() { |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1016 | const base::DictionaryValue* dict = |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 1017 | profile_->GetPrefs()->GetDictionary("extensions.settings"); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1018 | if (!dict) { |
| 1019 | ADD_FAILURE(); |
| 1020 | return 0; |
| 1021 | } |
| 1022 | return dict->size(); |
| 1023 | } |
| 1024 | |
| 1025 | void UninstallExtension(const std::string& id, bool use_helper) { |
| 1026 | // Verify that the extension is installed. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1027 | base::FilePath extension_path = extensions_install_dir_.AppendASCII(id); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1028 | EXPECT_TRUE(base::PathExists(extension_path)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1029 | size_t pref_key_count = GetPrefKeyCount(); |
| 1030 | EXPECT_GT(pref_key_count, 0u); |
| 1031 | ValidateIntegerPref(id, "state", Extension::ENABLED); |
| 1032 | |
| 1033 | // Uninstall it. |
| 1034 | if (use_helper) { |
| 1035 | EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service_, id)); |
| 1036 | } else { |
| 1037 | EXPECT_TRUE(service_->UninstallExtension(id, false, NULL)); |
| 1038 | } |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1039 | --expected_extensions_count_; |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1040 | |
| 1041 | // We should get an unload notification. |
| 1042 | EXPECT_FALSE(unloaded_id_.empty()); |
| 1043 | EXPECT_EQ(id, unloaded_id_); |
| 1044 | |
| 1045 | // Verify uninstalled state. |
| 1046 | size_t new_pref_key_count = GetPrefKeyCount(); |
| 1047 | if (new_pref_key_count == pref_key_count) { |
| 1048 | ValidateIntegerPref(id, "location", |
| 1049 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 1050 | } else { |
| 1051 | EXPECT_EQ(new_pref_key_count, pref_key_count - 1); |
| 1052 | } |
| 1053 | |
| 1054 | // The extension should not be in the service anymore. |
| 1055 | EXPECT_FALSE(service_->GetInstalledExtension(id)); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1056 | base::RunLoop().RunUntilIdle(); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1057 | |
| 1058 | // The directory should be gone. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1059 | EXPECT_FALSE(base::PathExists(extension_path)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | void ValidatePrefKeyCount(size_t count) { |
| 1063 | EXPECT_EQ(count, GetPrefKeyCount()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1064 | } |
| 1065 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1066 | testing::AssertionResult ValidateBooleanPref( |
| 1067 | const std::string& extension_id, |
| 1068 | const std::string& pref_path, |
| 1069 | bool expected_val) { |
| 1070 | std::string msg = "while checking: "; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1071 | msg += extension_id; |
| 1072 | msg += " "; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1073 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1074 | msg += " == "; |
| 1075 | msg += expected_val ? "true" : "false"; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1076 | |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 1077 | PrefService* prefs = profile_->GetPrefs(); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1078 | const base::DictionaryValue* dict = |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 1079 | prefs->GetDictionary("extensions.settings"); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1080 | if (!dict) { |
| 1081 | return testing::AssertionFailure() |
| 1082 | << "extension.settings does not exist " << msg; |
| 1083 | } |
| 1084 | |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1085 | const base::DictionaryValue* pref = NULL; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1086 | if (!dict->GetDictionary(extension_id, &pref)) { |
| 1087 | return testing::AssertionFailure() |
| 1088 | << "extension pref does not exist " << msg; |
| 1089 | } |
| 1090 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1091 | bool val; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1092 | if (!pref->GetBoolean(pref_path, &val)) { |
| 1093 | return testing::AssertionFailure() |
| 1094 | << pref_path << " pref not found " << msg; |
| 1095 | } |
| 1096 | |
| 1097 | return expected_val == val |
| 1098 | ? testing::AssertionSuccess() |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1099 | : testing::AssertionFailure() << "base::Value is incorrect " << msg; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | bool IsPrefExist(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1103 | const std::string& pref_path) { |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1104 | const base::DictionaryValue* dict = |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 1105 | profile_->GetPrefs()->GetDictionary("extensions.settings"); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1106 | if (dict == NULL) return false; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1107 | const base::DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1108 | if (!dict->GetDictionary(extension_id, &pref)) { |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1109 | return false; |
| 1110 | } |
| 1111 | if (pref == NULL) { |
| 1112 | return false; |
| 1113 | } |
| 1114 | bool val; |
| 1115 | if (!pref->GetBoolean(pref_path, &val)) { |
| 1116 | return false; |
| 1117 | } |
| 1118 | return true; |
| 1119 | } |
| 1120 | |
| 1121 | void ValidateIntegerPref(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1122 | const std::string& pref_path, |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1123 | int expected_val) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1124 | std::string msg = " while checking: "; |
| 1125 | msg += extension_id; |
| 1126 | msg += " "; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1127 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1128 | msg += " == "; |
| 1129 | msg += base::IntToString(expected_val); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1130 | |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 1131 | PrefService* prefs = profile_->GetPrefs(); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1132 | const base::DictionaryValue* dict = |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 1133 | prefs->GetDictionary("extensions.settings"); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1134 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1135 | const base::DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1136 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1137 | EXPECT_TRUE(pref != NULL) << msg; |
| 1138 | int val; |
[email protected] | 4c91487e | 2009-10-02 04:11:04 | [diff] [blame] | 1139 | ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1140 | EXPECT_EQ(expected_val, val) << msg; |
| 1141 | } |
| 1142 | |
| 1143 | void ValidateStringPref(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1144 | const std::string& pref_path, |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1145 | const std::string& expected_val) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1146 | std::string msg = " while checking: "; |
| 1147 | msg += extension_id; |
| 1148 | msg += ".manifest."; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1149 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1150 | msg += " == "; |
| 1151 | msg += expected_val; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1152 | |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1153 | const base::DictionaryValue* dict = |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 1154 | profile_->GetPrefs()->GetDictionary("extensions.settings"); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1155 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1156 | const base::DictionaryValue* pref = NULL; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1157 | std::string manifest_path = extension_id + ".manifest"; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1158 | ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1159 | EXPECT_TRUE(pref != NULL) << msg; |
| 1160 | std::string val; |
| 1161 | ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; |
| 1162 | EXPECT_EQ(expected_val, val) << msg; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1163 | } |
| 1164 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1165 | void SetPref(const std::string& extension_id, |
| 1166 | const std::string& pref_path, |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1167 | base::Value* value, |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1168 | const std::string& msg) { |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 1169 | DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1170 | base::DictionaryValue* dict = update.Get(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1171 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1172 | base::DictionaryValue* pref = NULL; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1173 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| 1174 | EXPECT_TRUE(pref != NULL) << msg; |
| 1175 | pref->Set(pref_path, value); |
| 1176 | } |
| 1177 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1178 | void SetPrefInteg(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1179 | const std::string& pref_path, |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1180 | int value) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1181 | std::string msg = " while setting: "; |
| 1182 | msg += extension_id; |
| 1183 | msg += " "; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1184 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1185 | msg += " = "; |
| 1186 | msg += base::IntToString(value); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1187 | |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 1188 | SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | void SetPrefBool(const std::string& extension_id, |
| 1192 | const std::string& pref_path, |
| 1193 | bool value) { |
| 1194 | std::string msg = " while setting: "; |
| 1195 | msg += extension_id + " " + pref_path; |
| 1196 | msg += " = "; |
| 1197 | msg += (value ? "true" : "false"); |
| 1198 | |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 1199 | SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | void ClearPref(const std::string& extension_id, |
| 1203 | const std::string& pref_path) { |
| 1204 | std::string msg = " while clearing: "; |
| 1205 | msg += extension_id + " " + pref_path; |
| 1206 | |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 1207 | DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1208 | base::DictionaryValue* dict = update.Get(); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1209 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1210 | base::DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1211 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1212 | EXPECT_TRUE(pref != NULL) << msg; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1213 | pref->Remove(pref_path, NULL); |
| 1214 | } |
| 1215 | |
| 1216 | void SetPrefStringSet(const std::string& extension_id, |
| 1217 | const std::string& pref_path, |
| 1218 | const std::set<std::string>& value) { |
| 1219 | std::string msg = " while setting: "; |
| 1220 | msg += extension_id + " " + pref_path; |
| 1221 | |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1222 | base::ListValue* list_value = new base::ListValue(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1223 | for (std::set<std::string>::const_iterator iter = value.begin(); |
| 1224 | iter != value.end(); ++iter) |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 1225 | list_value->Append(new base::StringValue(*iter)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1226 | |
| 1227 | SetPref(extension_id, pref_path, list_value, msg); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1228 | } |
| 1229 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1230 | void InitPluginService() { |
| 1231 | #if defined(ENABLE_PLUGINS) |
| 1232 | PluginService::GetInstance()->Init(); |
| 1233 | #endif |
| 1234 | } |
| 1235 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1236 | protected: |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 1237 | extensions::ExtensionList loaded_; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1238 | std::string unloaded_id_; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1239 | const Extension* installed_; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1240 | bool was_update_; |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 1241 | std::string old_name_; |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 1242 | FeatureSwitch::ScopedOverride override_external_install_prompt_; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1243 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1244 | private: |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1245 | // Create a CrxInstaller and install the CRX file. |
| 1246 | // Instead of calling this method yourself, use InstallCRX(), which does extra |
| 1247 | // error checking. |
| 1248 | void InstallCRXInternal(const base::FilePath& crx_path) { |
| 1249 | InstallCRXInternal(crx_path, Extension::NO_FLAGS); |
| 1250 | } |
| 1251 | |
| 1252 | void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags) { |
| 1253 | ASSERT_TRUE(base::PathExists(crx_path)) |
| 1254 | << "Path does not exist: "<< crx_path.value().c_str(); |
| 1255 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); |
| 1256 | installer->set_creation_flags(creation_flags); |
| 1257 | if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) |
| 1258 | installer->set_allow_silent_install(true); |
| 1259 | |
| 1260 | content::WindowedNotificationObserver observer( |
| 1261 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1262 | content::Source<extensions::CrxInstaller>(installer)); |
| 1263 | |
| 1264 | installer->InstallCrx(crx_path); |
| 1265 | |
| 1266 | observer.Wait(); |
| 1267 | } |
| 1268 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1269 | content::NotificationRegistrar registrar_; |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 1270 | }; |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1271 | |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1272 | // Receives notifications from a PackExtensionJob, indicating either that |
| 1273 | // packing succeeded or that there was some error. |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 1274 | class PackExtensionTestClient : public extensions::PackExtensionJob::Client { |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1275 | public: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1276 | PackExtensionTestClient(const base::FilePath& expected_crx_path, |
| 1277 | const base::FilePath& expected_private_key_path); |
| 1278 | virtual void OnPackSuccess(const base::FilePath& crx_path, |
| 1279 | const base::FilePath& private_key_path) OVERRIDE; |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1280 | virtual void OnPackFailure(const std::string& error_message, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 1281 | ExtensionCreator::ErrorType type) OVERRIDE; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1282 | |
| 1283 | private: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1284 | const base::FilePath expected_crx_path_; |
| 1285 | const base::FilePath expected_private_key_path_; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1286 | DISALLOW_COPY_AND_ASSIGN(PackExtensionTestClient); |
| 1287 | }; |
| 1288 | |
| 1289 | PackExtensionTestClient::PackExtensionTestClient( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1290 | const base::FilePath& expected_crx_path, |
| 1291 | const base::FilePath& expected_private_key_path) |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1292 | : expected_crx_path_(expected_crx_path), |
| 1293 | expected_private_key_path_(expected_private_key_path) {} |
| 1294 | |
| 1295 | // If packing succeeded, we make sure that the package names match our |
| 1296 | // expectations. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1297 | void PackExtensionTestClient::OnPackSuccess( |
| 1298 | const base::FilePath& crx_path, |
| 1299 | const base::FilePath& private_key_path) { |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1300 | // We got the notification and processed it; we don't expect any further tasks |
| 1301 | // to be posted to the current thread, so we should stop blocking and continue |
| 1302 | // on with the rest of the test. |
| 1303 | // This call to |Quit()| matches the call to |Run()| in the |
| 1304 | // |PackPunctuatedExtension| test. |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 1305 | base::MessageLoop::current()->Quit(); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1306 | EXPECT_EQ(expected_crx_path_.value(), crx_path.value()); |
| 1307 | EXPECT_EQ(expected_private_key_path_.value(), private_key_path.value()); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1308 | ASSERT_TRUE(base::PathExists(private_key_path)); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | // 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] | 1312 | void PackExtensionTestClient::OnPackFailure(const std::string& error_message, |
| 1313 | ExtensionCreator::ErrorType type) { |
| 1314 | if (type == ExtensionCreator::kCRXExists) |
| 1315 | FAIL() << "Packing should not fail."; |
| 1316 | else |
| 1317 | FAIL() << "Existing CRX should have been overwritten."; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1318 | } |
| 1319 | |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1320 | // Test loading good extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1321 | TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1322 | InitPluginService(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1323 | InitializeGoodInstalledExtensionService(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1324 | service_->Init(); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1325 | |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1326 | uint32 expected_num_extensions = 3u; |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1327 | ASSERT_EQ(expected_num_extensions, loaded_.size()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1328 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 1329 | EXPECT_EQ(std::string(good0), loaded_[0]->id()); |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 1330 | EXPECT_EQ(std::string("My extension 1"), |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1331 | loaded_[0]->name()); |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 1332 | EXPECT_EQ(std::string("The first extension that I made."), |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1333 | loaded_[0]->description()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1334 | EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location()); |
[email protected] | 61b41161 | 2009-11-10 23:17:41 | [diff] [blame] | 1335 | EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)); |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1336 | EXPECT_EQ(expected_num_extensions, service_->extensions()->size()); |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 1337 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1338 | ValidatePrefKeyCount(3); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1339 | ValidateIntegerPref(good0, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1340 | ValidateIntegerPref(good0, "location", Manifest::INTERNAL); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1341 | ValidateIntegerPref(good1, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1342 | ValidateIntegerPref(good1, "location", Manifest::INTERNAL); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1343 | ValidateIntegerPref(good2, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1344 | ValidateIntegerPref(good2, "location", Manifest::INTERNAL); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1345 | |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1346 | URLPatternSet expected_patterns; |
| 1347 | AddPattern(&expected_patterns, "file:///*"); |
| 1348 | AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 1349 | AddPattern(&expected_patterns, "https://*.google.com/*"); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1350 | const Extension* extension = loaded_[0].get(); |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 1351 | const extensions::UserScriptList& scripts = |
| 1352 | extensions::ContentScriptsInfo::GetContentScripts(extension); |
[email protected] | e66de89 | 2009-03-20 20:38:43 | [diff] [blame] | 1353 | ASSERT_EQ(2u, scripts.size()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1354 | EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); |
[email protected] | e66de89 | 2009-03-20 20:38:43 | [diff] [blame] | 1355 | EXPECT_EQ(2u, scripts[0].js_scripts().size()); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 1356 | ExtensionResource resource00(extension->id(), |
| 1357 | scripts[0].js_scripts()[0].extension_root(), |
[email protected] | 9194b3f | 2009-10-20 15:27:21 | [diff] [blame] | 1358 | scripts[0].js_scripts()[0].relative_path()); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 1359 | base::FilePath expected_path = |
| 1360 | base::MakeAbsoluteFilePath(extension->path().AppendASCII("script1.js")); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1361 | EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 1362 | ExtensionResource resource01(extension->id(), |
| 1363 | scripts[0].js_scripts()[1].extension_root(), |
[email protected] | 9194b3f | 2009-10-20 15:27:21 | [diff] [blame] | 1364 | scripts[0].js_scripts()[1].relative_path()); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 1365 | expected_path = |
| 1366 | base::MakeAbsoluteFilePath(extension->path().AppendASCII("script2.js")); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1367 | EXPECT_TRUE(resource01.ComparePathWithDefault(expected_path)); |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1368 | EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(extension)); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1369 | EXPECT_EQ(1u, scripts[1].url_patterns().patterns().size()); |
| 1370 | EXPECT_EQ("http://*.news.com/*", |
| 1371 | scripts[1].url_patterns().begin()->GetAsString()); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 1372 | ExtensionResource resource10(extension->id(), |
| 1373 | scripts[1].js_scripts()[0].extension_root(), |
[email protected] | 9194b3f | 2009-10-20 15:27:21 | [diff] [blame] | 1374 | scripts[1].js_scripts()[0].relative_path()); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1375 | expected_path = |
| 1376 | extension->path().AppendASCII("js_files").AppendASCII("script3.js"); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 1377 | expected_path = base::MakeAbsoluteFilePath(expected_path); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1378 | EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1379 | |
| 1380 | expected_patterns.ClearPatterns(); |
| 1381 | AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 1382 | AddPattern(&expected_patterns, "https://*.google.com/*"); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1383 | EXPECT_EQ(expected_patterns, |
| 1384 | extension->GetActivePermissions()->explicit_hosts()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1385 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1386 | EXPECT_EQ(std::string(good1), loaded_[1]->id()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1387 | EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 1388 | EXPECT_EQ(std::string(), loaded_[1]->description()); |
[email protected] | 81067e0 | 2009-07-27 15:12:09 | [diff] [blame] | 1389 | EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1390 | extensions::BackgroundInfo::GetBackgroundURL(loaded_[1].get())); |
| 1391 | EXPECT_EQ(0u, |
| 1392 | extensions::ContentScriptsInfo::GetContentScripts(loaded_[1].get()) |
| 1393 | .size()); |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1394 | |
[email protected] | b8fb303 | 2011-04-29 18:45:56 | [diff] [blame] | 1395 | // We don't parse the plugins section on Chrome OS. |
| 1396 | #if defined(OS_CHROMEOS) |
[email protected] | 144b6c4 | 2013-06-14 07:30:38 | [diff] [blame] | 1397 | EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(loaded_[1].get())); |
[email protected] | b8fb303 | 2011-04-29 18:45:56 | [diff] [blame] | 1398 | #else |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1399 | ASSERT_TRUE(extensions::PluginInfo::HasPlugins(loaded_[1].get())); |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1400 | const std::vector<extensions::PluginInfo>* plugins = |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1401 | extensions::PluginInfo::GetPlugins(loaded_[1].get()); |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1402 | ASSERT_TRUE(plugins); |
| 1403 | ASSERT_EQ(2u, plugins->size()); |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 1404 | EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1405 | plugins->at(0).path.value()); |
| 1406 | EXPECT_TRUE(plugins->at(0).is_public); |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 1407 | EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1408 | plugins->at(1).path.value()); |
| 1409 | EXPECT_FALSE(plugins->at(1).is_public); |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1410 | #endif |
[email protected] | 18a1235 | 2009-01-31 01:33:28 | [diff] [blame] | 1411 | |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1412 | EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location()); |
[email protected] | b8fb303 | 2011-04-29 18:45:56 | [diff] [blame] | 1413 | |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1414 | int index = expected_num_extensions - 1; |
| 1415 | EXPECT_EQ(std::string(good2), loaded_[index]->id()); |
| 1416 | EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 1417 | EXPECT_EQ(std::string(), loaded_[index]->description()); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1418 | EXPECT_EQ(0u, |
| 1419 | extensions::ContentScriptsInfo::GetContentScripts( |
| 1420 | loaded_[index].get()).size()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1421 | EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1422 | }; |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1423 | |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1424 | // Test loading bad extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1425 | TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1426 | // Initialize the test dir with a bad Preferences/extensions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1427 | base::FilePath source_install_dir = data_dir_ |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1428 | .AppendASCII("bad") |
| 1429 | .AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1430 | base::FilePath pref_path = source_install_dir |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1431 | .DirName() |
| 1432 | .AppendASCII("Preferences"); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1433 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1434 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1435 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1436 | service_->Init(); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1437 | |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1438 | ASSERT_EQ(4u, GetErrors().size()); |
| 1439 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1440 | |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1441 | EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[0]), |
[email protected] | d7b36dc | 2009-10-29 21:47:40 | [diff] [blame] | 1442 | std::string("Could not load extension from '*'. ") + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 1443 | extensions::manifest_errors::kManifestUnreadable)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1444 | base::UTF16ToUTF8(GetErrors()[0]); |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1445 | |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1446 | EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[1]), |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1447 | std::string("Could not load extension from '*'. ") + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 1448 | extensions::manifest_errors::kManifestUnreadable)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1449 | base::UTF16ToUTF8(GetErrors()[1]); |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1450 | |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1451 | EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[2]), |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1452 | std::string("Could not load extension from '*'. ") + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 1453 | extensions::manifest_errors::kMissingFile)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1454 | base::UTF16ToUTF8(GetErrors()[2]); |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1455 | |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1456 | EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[3]), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1457 | std::string("Could not load extension from '*'. ") + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 1458 | extensions::manifest_errors::kManifestUnreadable)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 1459 | base::UTF16ToUTF8(GetErrors()[3]); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1460 | }; |
| 1461 | |
[email protected] | 2f8757c3 | 2012-06-19 19:17:47 | [diff] [blame] | 1462 | // Test that partially deleted extensions are cleaned up during startup |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1463 | // Test loading bad extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1464 | TEST_F(ExtensionServiceTest, CleanupOnStartup) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1465 | InitPluginService(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1466 | InitializeGoodInstalledExtensionService(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1467 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 1468 | // Simulate that one of them got partially deleted by clearing its pref. |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 1469 | { |
| 1470 | DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 1471 | base::DictionaryValue* dict = update.Get(); |
[email protected] | 2f8757c3 | 2012-06-19 19:17:47 | [diff] [blame] | 1472 | ASSERT_TRUE(dict != NULL); |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 1473 | dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); |
| 1474 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1475 | |
| 1476 | service_->Init(); |
[email protected] | 36fc54f | 2013-06-14 02:49:34 | [diff] [blame] | 1477 | // A delayed task to call GarbageCollectExtensions is posted by |
| 1478 | // ExtensionService::Init. As the test won't wait for the delayed task to |
| 1479 | // be called, call it manually instead. |
| 1480 | service_->GarbageCollectExtensions(); |
[email protected] | 1f4728f | 2012-12-05 20:40:05 | [diff] [blame] | 1481 | // Wait for GarbageCollectExtensions task to complete. |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1482 | base::RunLoop().RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1483 | |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 1484 | base::FileEnumerator dirs(extensions_install_dir_, false, |
| 1485 | base::FileEnumerator::DIRECTORIES); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1486 | size_t count = 0; |
| 1487 | while (!dirs.Next().empty()) |
| 1488 | count++; |
| 1489 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1490 | // We should have only gotten two extensions now. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1491 | EXPECT_EQ(2u, count); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1492 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1493 | // And extension1 dir should now be toast. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1494 | base::FilePath extension_dir = extensions_install_dir_ |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 1495 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1496 | ASSERT_FALSE(base::PathExists(extension_dir)); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1497 | } |
| 1498 | |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1499 | // Test that GarbageCollectExtensions deletes the right versions of an |
| 1500 | // extension. |
| 1501 | TEST_F(ExtensionServiceTest, GarbageCollectWithPendingUpdates) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1502 | InitPluginService(); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1503 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1504 | base::FilePath source_install_dir = data_dir_ |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1505 | .AppendASCII("pending_updates") |
| 1506 | .AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1507 | base::FilePath pref_path = source_install_dir |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1508 | .DirName() |
| 1509 | .AppendASCII("Preferences"); |
| 1510 | |
| 1511 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1512 | |
| 1513 | // This is the directory that is going to be deleted, so make sure it actually |
| 1514 | // is there before the garbage collection. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1515 | ASSERT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1516 | "hpiknbiabeeppbpihjehijgoemciehgk/3"))); |
| 1517 | |
| 1518 | service_->GarbageCollectExtensions(); |
[email protected] | 1f4728f | 2012-12-05 20:40:05 | [diff] [blame] | 1519 | // Wait for GarbageCollectExtensions task to complete. |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1520 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1521 | |
| 1522 | // Verify that the pending update for the first extension didn't get |
| 1523 | // deleted. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1524 | EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1525 | "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1526 | EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1527 | "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1528 | EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1529 | "hpiknbiabeeppbpihjehijgoemciehgk/2"))); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1530 | EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1531 | "hpiknbiabeeppbpihjehijgoemciehgk/3"))); |
| 1532 | } |
| 1533 | |
| 1534 | // Test that pending updates are properly handled on startup. |
| 1535 | TEST_F(ExtensionServiceTest, UpdateOnStartup) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1536 | InitPluginService(); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1537 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1538 | base::FilePath source_install_dir = data_dir_ |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1539 | .AppendASCII("pending_updates") |
| 1540 | .AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1541 | base::FilePath pref_path = source_install_dir |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1542 | .DirName() |
| 1543 | .AppendASCII("Preferences"); |
| 1544 | |
| 1545 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1546 | |
| 1547 | // This is the directory that is going to be deleted, so make sure it actually |
| 1548 | // is there before the garbage collection. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1549 | ASSERT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1550 | "hpiknbiabeeppbpihjehijgoemciehgk/3"))); |
| 1551 | |
| 1552 | service_->Init(); |
[email protected] | 36fc54f | 2013-06-14 02:49:34 | [diff] [blame] | 1553 | // A delayed task to call GarbageCollectExtensions is posted by |
| 1554 | // ExtensionService::Init. As the test won't wait for the delayed task to |
| 1555 | // be called, call it manually instead. |
| 1556 | service_->GarbageCollectExtensions(); |
[email protected] | 1f4728f | 2012-12-05 20:40:05 | [diff] [blame] | 1557 | // Wait for GarbageCollectExtensions task to complete. |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1558 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1559 | |
| 1560 | // Verify that the pending update for the first extension got installed. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1561 | EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1562 | "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1563 | EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1564 | "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1565 | EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1566 | "hpiknbiabeeppbpihjehijgoemciehgk/2"))); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1567 | EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1568 | "hpiknbiabeeppbpihjehijgoemciehgk/3"))); |
| 1569 | |
| 1570 | // Make sure update information got deleted. |
| 1571 | ExtensionPrefs* prefs = service_->extension_prefs(); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1572 | EXPECT_FALSE( |
| 1573 | prefs->GetDelayedInstallInfo("bjafgdebaacbbbecmhlhpofkepfkgcpa")); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1574 | } |
| 1575 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1576 | // Test various cases for delayed install because of missing imports. |
| 1577 | TEST_F(ExtensionServiceTest, PendingImports) { |
| 1578 | InitPluginService(); |
| 1579 | |
| 1580 | base::FilePath source_install_dir = data_dir_ |
| 1581 | .AppendASCII("pending_updates_with_imports") |
| 1582 | .AppendASCII("Extensions"); |
| 1583 | base::FilePath pref_path = source_install_dir |
| 1584 | .DirName() |
| 1585 | .AppendASCII("Preferences"); |
| 1586 | |
| 1587 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1588 | |
| 1589 | // Verify there are no pending extensions initially. |
| 1590 | EXPECT_FALSE(service_->pending_extension_manager()->HasPendingExtensions()); |
| 1591 | |
| 1592 | service_->Init(); |
| 1593 | // Wait for GarbageCollectExtensions task to complete. |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1594 | base::RunLoop().RunUntilIdle(); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1595 | |
| 1596 | // These extensions are used by the extensions we test below, they must be |
| 1597 | // installed. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1598 | EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1599 | "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1600 | EXPECT_TRUE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1601 | "hpiknbiabeeppbpihjehijgoemciehgk/2"))); |
| 1602 | |
| 1603 | // Each of these extensions should have been rejected because of dependencies |
| 1604 | // that cannot be satisfied. |
| 1605 | ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1606 | EXPECT_FALSE( |
| 1607 | prefs->GetDelayedInstallInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); |
| 1608 | EXPECT_FALSE( |
| 1609 | prefs->GetInstalledExtensionInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); |
| 1610 | EXPECT_FALSE( |
| 1611 | prefs->GetDelayedInstallInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); |
| 1612 | EXPECT_FALSE( |
| 1613 | prefs->GetInstalledExtensionInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); |
| 1614 | EXPECT_FALSE( |
| 1615 | prefs->GetDelayedInstallInfo("cccccccccccccccccccccccccccccccc")); |
| 1616 | EXPECT_FALSE( |
| 1617 | prefs->GetInstalledExtensionInfo("cccccccccccccccccccccccccccccccc")); |
| 1618 | |
| 1619 | // Make sure the import started for the extension with a dependency. |
| 1620 | EXPECT_TRUE( |
| 1621 | prefs->GetDelayedInstallInfo("behllobkkfkfnphdnhnkndlbkcpglgmj")); |
| 1622 | EXPECT_EQ(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, |
| 1623 | prefs->GetDelayedInstallReason("behllobkkfkfnphdnhnkndlbkcpglgmj")); |
| 1624 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1625 | EXPECT_FALSE(base::PathExists(extensions_install_dir_.AppendASCII( |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1626 | "behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0"))); |
| 1627 | |
| 1628 | EXPECT_TRUE(service_->pending_extension_manager()->HasPendingExtensions()); |
| 1629 | std::string pending_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); |
| 1630 | EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(pending_id)); |
| 1631 | // Remove it because we are not testing the pending extension manager's |
| 1632 | // ability to download and install extensions. |
| 1633 | EXPECT_TRUE(service_->pending_extension_manager()->Remove(pending_id)); |
| 1634 | } |
| 1635 | |
[email protected] | d7eaf57 | 2009-07-01 21:57:00 | [diff] [blame] | 1636 | // Test installing extensions. This test tries to install few extensions using |
| 1637 | // crx files. If you need to change those crx files, feel free to repackage |
| 1638 | // them, throw away the key used and change the id's above. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1639 | TEST_F(ExtensionServiceTest, InstallExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1640 | InitializeEmptyExtensionService(); |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1641 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1642 | // Extensions not enabled. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1643 | set_extensions_enabled(false); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1644 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1645 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1646 | set_extensions_enabled(true); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1647 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1648 | ValidatePrefKeyCount(0); |
| 1649 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1650 | // A simple extension that should install without error. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1651 | path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1652 | InstallCRX(path, INSTALL_NEW); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1653 | // TODO(erikkay): verify the contents of the installed extension. |
| 1654 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1655 | int pref_count = 0; |
| 1656 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1657 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1658 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1659 | |
[email protected] | 902f7cd | 2009-05-22 19:02:19 | [diff] [blame] | 1660 | // An extension with page actions. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1661 | path = data_dir_.AppendASCII("page_action.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1662 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1663 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1664 | ValidateIntegerPref(page_action, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1665 | ValidateIntegerPref(page_action, "location", Manifest::INTERNAL); |
[email protected] | 902f7cd | 2009-05-22 19:02:19 | [diff] [blame] | 1666 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1667 | // Bad signature. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1668 | path = data_dir_.AppendASCII("bad_signature.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1669 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | d7eaf57 | 2009-07-01 21:57:00 | [diff] [blame] | 1670 | ValidatePrefKeyCount(pref_count); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 1671 | |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1672 | // 0-length extension file. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1673 | path = data_dir_.AppendASCII("not_an_extension.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1674 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1675 | ValidatePrefKeyCount(pref_count); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1676 | |
| 1677 | // Bad magic number. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1678 | path = data_dir_.AppendASCII("bad_magic.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1679 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1680 | ValidatePrefKeyCount(pref_count); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1681 | |
[email protected] | 622813ee0 | 2013-08-21 21:00:29 | [diff] [blame] | 1682 | // Packed extensions may have folders or files that have underscores. |
| 1683 | // This will only cause a warning, rather than a fatal error. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1684 | path = data_dir_.AppendASCII("bad_underscore.crx"); |
[email protected] | 622813ee0 | 2013-08-21 21:00:29 | [diff] [blame] | 1685 | InstallCRX(path, INSTALL_NEW); |
| 1686 | ValidatePrefKeyCount(++pref_count); |
[email protected] | 99872e3 | 2009-09-25 22:02:49 | [diff] [blame] | 1687 | |
[email protected] | 5fda9194 | 2013-09-24 06:47:53 | [diff] [blame] | 1688 | // A test for an extension with a 2048-bit public key. |
| 1689 | path = data_dir_.AppendASCII("good2048.crx"); |
| 1690 | InstallCRX(path, INSTALL_NEW); |
| 1691 | ValidatePrefKeyCount(++pref_count); |
| 1692 | ValidateIntegerPref(good2048, "state", Extension::ENABLED); |
| 1693 | ValidateIntegerPref(good2048, "location", Manifest::INTERNAL); |
| 1694 | |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1695 | // TODO(erikkay): add more tests for many of the failure cases. |
| 1696 | // TODO(erikkay): add tests for upgrade cases. |
| 1697 | } |
| 1698 | |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1699 | struct MockInstallObserver : public extensions::InstallObserver { |
| 1700 | MockInstallObserver() { |
| 1701 | } |
| 1702 | |
| 1703 | virtual ~MockInstallObserver() { |
| 1704 | } |
| 1705 | |
| 1706 | virtual void OnBeginExtensionInstall( |
[email protected] | fa517d0 | 2013-11-18 09:33:09 | [diff] [blame] | 1707 | const ExtensionInstallParams& params) OVERRIDE { |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | virtual void OnDownloadProgress(const std::string& extension_id, |
| 1711 | int percent_downloaded) OVERRIDE { |
| 1712 | } |
| 1713 | |
| 1714 | virtual void OnExtensionInstalled(const Extension* extension) OVERRIDE { |
| 1715 | last_extension_installed = extension->id(); |
| 1716 | } |
| 1717 | |
| 1718 | virtual void OnInstallFailure(const std::string& extension_id) OVERRIDE { |
| 1719 | } |
| 1720 | |
| 1721 | virtual void OnExtensionLoaded(const Extension* extension) OVERRIDE { |
| 1722 | } |
| 1723 | |
| 1724 | virtual void OnExtensionUnloaded(const Extension* extension) OVERRIDE { |
| 1725 | } |
| 1726 | |
| 1727 | virtual void OnExtensionUninstalled(const Extension* extension) OVERRIDE { |
| 1728 | last_extension_uninstalled = extension->id(); |
| 1729 | } |
| 1730 | |
| 1731 | virtual void OnAppsReordered() OVERRIDE { |
| 1732 | } |
| 1733 | |
| 1734 | virtual void OnAppInstalledToAppList( |
| 1735 | const std::string& extension_id) OVERRIDE { |
| 1736 | } |
| 1737 | |
| 1738 | virtual void OnShutdown() OVERRIDE { |
| 1739 | } |
| 1740 | |
| 1741 | std::string last_extension_installed; |
| 1742 | std::string last_extension_uninstalled; |
| 1743 | }; |
| 1744 | |
| 1745 | // Test that correct notifications are sent to InstallTracker observers on |
| 1746 | // extension install and uninstall. |
| 1747 | TEST_F(ExtensionServiceTest, InstallObserverNotified) { |
| 1748 | InitializeEmptyExtensionService(); |
| 1749 | |
| 1750 | extensions::InstallTracker* tracker( |
| 1751 | extensions::InstallTrackerFactory::GetForProfile(profile_.get())); |
| 1752 | MockInstallObserver observer; |
| 1753 | tracker->AddObserver(&observer); |
| 1754 | |
| 1755 | // A simple extension that should install without error. |
| 1756 | ASSERT_TRUE(observer.last_extension_installed.empty()); |
| 1757 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1758 | InstallCRX(path, INSTALL_NEW); |
| 1759 | ASSERT_EQ(good_crx, observer.last_extension_installed); |
| 1760 | |
| 1761 | // Uninstall the extension. |
| 1762 | ASSERT_TRUE(observer.last_extension_uninstalled.empty()); |
| 1763 | UninstallExtension(good_crx, false); |
| 1764 | ASSERT_EQ(good_crx, observer.last_extension_uninstalled); |
| 1765 | |
| 1766 | tracker->RemoveObserver(&observer); |
| 1767 | } |
| 1768 | |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1769 | // Tests that flags passed to OnExternalExtensionFileFound() make it to the |
| 1770 | // extension object. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1771 | TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1772 | const char kPrefFromBookmark[] = "from_bookmark"; |
| 1773 | |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1774 | InitializeEmptyExtensionService(); |
| 1775 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1776 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1777 | set_extensions_enabled(true); |
| 1778 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1779 | // Register and install an external extension. |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1780 | Version version("1.0.0.0"); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1781 | content::WindowedNotificationObserver observer( |
| 1782 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1783 | content::NotificationService::AllSources()); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1784 | if (service_->OnExternalExtensionFileFound( |
| 1785 | good_crx, |
| 1786 | &version, |
| 1787 | path, |
| 1788 | Manifest::EXTERNAL_PREF, |
| 1789 | Extension::FROM_BOOKMARK, |
| 1790 | false /* mark_acknowledged */)) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1791 | observer.Wait(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1792 | } |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1793 | |
| 1794 | const Extension* extension = service_->GetExtensionById(good_crx, false); |
| 1795 | ASSERT_TRUE(extension); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1796 | ASSERT_TRUE(extension->from_bookmark()); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1797 | ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1798 | |
| 1799 | // Upgrade to version 2.0, the flag should be preserved. |
| 1800 | path = data_dir_.AppendASCII("good2.crx"); |
| 1801 | UpdateExtension(good_crx, path, ENABLED); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1802 | ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1803 | extension = service_->GetExtensionById(good_crx, false); |
| 1804 | ASSERT_TRUE(extension); |
| 1805 | ASSERT_TRUE(extension->from_bookmark()); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1806 | } |
| 1807 | |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1808 | // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1809 | TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1810 | InitializeEmptyExtensionService(); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1811 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1812 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1813 | set_extensions_enabled(true); |
| 1814 | |
| 1815 | // Install an external extension. |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1816 | Version version("1.0.0.0"); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1817 | content::WindowedNotificationObserver observer( |
| 1818 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1819 | content::NotificationService::AllSources()); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1820 | if (service_->OnExternalExtensionFileFound(good_crx, &version, |
| 1821 | path, Manifest::EXTERNAL_PREF, |
| 1822 | Extension::NO_FLAGS, false)) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1823 | observer.Wait(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1824 | } |
| 1825 | |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1826 | ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1827 | |
| 1828 | // Uninstall it and check that its killbit gets set. |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1829 | UninstallExtension(good_crx, false); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1830 | ValidateIntegerPref(good_crx, "location", |
| 1831 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1832 | |
| 1833 | // Try to re-install it externally. This should fail because of the killbit. |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1834 | service_->OnExternalExtensionFileFound(good_crx, &version, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1835 | path, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1836 | Extension::NO_FLAGS, false); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1837 | base::RunLoop().RunUntilIdle(); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1838 | ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1839 | ValidateIntegerPref(good_crx, "location", |
| 1840 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1841 | |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1842 | version = Version("1.0.0.1"); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1843 | // Repeat the same thing with a newer version of the extension. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1844 | path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1845 | service_->OnExternalExtensionFileFound(good_crx, &version, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1846 | path, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1847 | Extension::NO_FLAGS, false); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1848 | base::RunLoop().RunUntilIdle(); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1849 | ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1850 | ValidateIntegerPref(good_crx, "location", |
| 1851 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1852 | |
| 1853 | // Try adding the same extension from an external update URL. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1854 | ASSERT_FALSE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1855 | good_crx, |
| 1856 | GURL("http:://fake.update/url"), |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 1857 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 1858 | Extension::NO_FLAGS, |
| 1859 | false)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 1860 | |
| 1861 | ASSERT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1862 | } |
| 1863 | |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1864 | // Test that uninstalling an external extension does not crash when |
| 1865 | // the extension could not be loaded. |
| 1866 | // This extension shown in preferences file requires an experimental permission. |
| 1867 | // It could not be loaded without such permission. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1868 | TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1869 | base::FilePath source_install_dir = data_dir_ |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1870 | .AppendASCII("good") |
| 1871 | .AppendASCII("Extensions"); |
| 1872 | // The preference contains an external extension |
| 1873 | // that requires 'experimental' permission. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1874 | base::FilePath pref_path = source_install_dir |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1875 | .DirName() |
| 1876 | .AppendASCII("PreferencesExperimental"); |
| 1877 | |
| 1878 | // Aforementioned extension will not be loaded if |
| 1879 | // there is no '--enable-experimental-extension-apis' command line flag. |
| 1880 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1881 | |
| 1882 | service_->Init(); |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1883 | |
| 1884 | // Check and try to uninstall it. |
| 1885 | // If we don't check whether the extension is loaded before we uninstall it |
| 1886 | // in CheckExternalUninstall, a crash will happen here because we will get or |
| 1887 | // dereference a NULL pointer (extension) inside UninstallExtension. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1888 | MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1889 | service_->OnExternalProviderReady(&provider); |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1890 | } |
| 1891 | |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1892 | // Test that external extensions with incorrect IDs are not installed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1893 | TEST_F(ExtensionServiceTest, FailOnWrongId) { |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1894 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1895 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1896 | set_extensions_enabled(true); |
| 1897 | |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1898 | Version version("1.0.0.0"); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1899 | |
| 1900 | const std::string wrong_id = all_zero; |
| 1901 | const std::string correct_id = good_crx; |
| 1902 | ASSERT_NE(correct_id, wrong_id); |
| 1903 | |
| 1904 | // Install an external extension with an ID from the external |
| 1905 | // source that is not equal to the ID in the extension manifest. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1906 | content::WindowedNotificationObserver observer( |
| 1907 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1908 | content::NotificationService::AllSources()); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1909 | service_->OnExternalExtensionFileFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1910 | wrong_id, &version, path, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1911 | Extension::NO_FLAGS, false); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1912 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1913 | observer.Wait(); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1914 | ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); |
| 1915 | |
| 1916 | // Try again with the right ID. Expect success. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1917 | content::WindowedNotificationObserver observer2( |
| 1918 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1919 | content::NotificationService::AllSources()); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1920 | if (service_->OnExternalExtensionFileFound( |
| 1921 | correct_id, &version, path, Manifest::EXTERNAL_PREF, |
| 1922 | Extension::NO_FLAGS, false)) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1923 | observer2.Wait(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1924 | } |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1925 | ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1926 | } |
| 1927 | |
| 1928 | // Test that external extensions with incorrect versions are not installed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1929 | TEST_F(ExtensionServiceTest, FailOnWrongVersion) { |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1930 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1931 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1932 | set_extensions_enabled(true); |
| 1933 | |
| 1934 | // Install an external extension with a version from the external |
| 1935 | // source that is not equal to the version in the extension manifest. |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1936 | Version wrong_version("1.2.3.4"); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1937 | content::WindowedNotificationObserver observer( |
| 1938 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1939 | content::NotificationService::AllSources()); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1940 | service_->OnExternalExtensionFileFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1941 | good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1942 | Extension::NO_FLAGS, false); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1943 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1944 | observer.Wait(); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1945 | ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); |
| 1946 | |
| 1947 | // Try again with the right version. Expect success. |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 1948 | service_->pending_extension_manager()->Remove(good_crx); |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1949 | Version correct_version("1.0.0.0"); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1950 | content::WindowedNotificationObserver observer2( |
| 1951 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1952 | content::NotificationService::AllSources()); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1953 | if (service_->OnExternalExtensionFileFound( |
| 1954 | good_crx, &correct_version, path, Manifest::EXTERNAL_PREF, |
| 1955 | Extension::NO_FLAGS, false)) { |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 1956 | observer2.Wait(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1957 | } |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1958 | ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1959 | } |
| 1960 | |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1961 | // Install a user script (they get converted automatically to an extension) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1962 | TEST_F(ExtensionServiceTest, InstallUserScript) { |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1963 | // The details of script conversion are tested elsewhere, this just tests |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1964 | // integration with ExtensionService. |
| 1965 | InitializeEmptyExtensionService(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1966 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1967 | base::FilePath path = data_dir_ |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1968 | .AppendASCII("user_script_basic.user.js"); |
| 1969 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1970 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 1971 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1972 | installer->set_allow_silent_install(true); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 1973 | installer->InstallUserScript( |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1974 | path, |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 1975 | GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1976 | |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 1977 | base::RunLoop().RunUntilIdle(); |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 1978 | std::vector<base::string16> errors = GetErrors(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1979 | EXPECT_TRUE(installed_) << "Nothing was installed."; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1980 | EXPECT_FALSE(was_update_) << path.value(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1981 | ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; |
| 1982 | EXPECT_EQ(0u, errors.size()) << "There were errors: " |
| 1983 | << JoinString(errors, ','); |
| 1984 | EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << |
| 1985 | path.value(); |
| 1986 | |
| 1987 | installed_ = NULL; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1988 | was_update_ = false; |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1989 | loaded_.clear(); |
| 1990 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| 1991 | } |
| 1992 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1993 | // Extensions don't install during shutdown. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1994 | TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1995 | InitializeEmptyExtensionService(); |
| 1996 | |
| 1997 | // Simulate shutdown. |
| 1998 | service_->set_browser_terminating_for_test(true); |
| 1999 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2000 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 2001 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service_)); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2002 | installer->set_allow_silent_install(true); |
| 2003 | installer->InstallCrx(path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2004 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2005 | |
| 2006 | EXPECT_FALSE(installed_) << "Extension installed during shutdown."; |
| 2007 | ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown."; |
| 2008 | } |
| 2009 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2010 | // This tests that the granted permissions preferences are correctly set when |
| 2011 | // installing an extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2012 | TEST_F(ExtensionServiceTest, GrantedPermissions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2013 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2014 | base::FilePath path = data_dir_ |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2015 | .AppendASCII("permissions"); |
| 2016 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2017 | base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2018 | path = path.AppendASCII("unknown"); |
| 2019 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2020 | ASSERT_TRUE(base::PathExists(pem_path)); |
| 2021 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2022 | |
| 2023 | ExtensionPrefs* prefs = service_->extension_prefs(); |
| 2024 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2025 | APIPermissionSet expected_api_perms; |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2026 | URLPatternSet expected_host_perms; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2027 | |
| 2028 | // Make sure there aren't any granted permissions before the |
| 2029 | // extension is installed. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2030 | scoped_refptr<PermissionSet> known_perms( |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2031 | prefs->GetGrantedPermissions(permissions_crx)); |
| 2032 | EXPECT_FALSE(known_perms.get()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2033 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2034 | const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2035 | |
| 2036 | EXPECT_EQ(0u, GetErrors().size()); |
| 2037 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2038 | EXPECT_EQ(permissions_crx, extension->id()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2039 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2040 | // Verify that the valid API permissions have been recognized. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2041 | expected_api_perms.insert(APIPermission::kTab); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2042 | |
| 2043 | AddPattern(&expected_host_perms, "http://*.google.com/*"); |
| 2044 | AddPattern(&expected_host_perms, "https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 2045 | AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2046 | AddPattern(&expected_host_perms, "http://www.example.com/*"); |
| 2047 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2048 | known_perms = prefs->GetGrantedPermissions(extension->id()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2049 | EXPECT_TRUE(known_perms.get()); |
| 2050 | EXPECT_FALSE(known_perms->IsEmpty()); |
| 2051 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 2052 | EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 2053 | EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2054 | } |
| 2055 | |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 2056 | |
| 2057 | #if !defined(OS_CHROMEOS) |
| 2058 | // This tests that the granted permissions preferences are correctly set for |
| 2059 | // default apps. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2060 | TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 2061 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2062 | base::FilePath path = data_dir_ |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 2063 | .AppendASCII("permissions"); |
| 2064 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2065 | base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 2066 | path = path.AppendASCII("unknown"); |
| 2067 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2068 | ASSERT_TRUE(base::PathExists(pem_path)); |
| 2069 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 2070 | |
| 2071 | ExtensionPrefs* prefs = service_->extension_prefs(); |
| 2072 | |
| 2073 | APIPermissionSet expected_api_perms; |
| 2074 | URLPatternSet expected_host_perms; |
| 2075 | |
| 2076 | // Make sure there aren't any granted permissions before the |
| 2077 | // extension is installed. |
| 2078 | scoped_refptr<PermissionSet> known_perms( |
| 2079 | prefs->GetGrantedPermissions(permissions_crx)); |
| 2080 | EXPECT_FALSE(known_perms.get()); |
| 2081 | |
| 2082 | const Extension* extension = PackAndInstallCRX( |
| 2083 | path, pem_path, INSTALL_NEW, Extension::WAS_INSTALLED_BY_DEFAULT); |
| 2084 | |
| 2085 | EXPECT_EQ(0u, GetErrors().size()); |
| 2086 | ASSERT_EQ(1u, service_->extensions()->size()); |
| 2087 | EXPECT_EQ(permissions_crx, extension->id()); |
| 2088 | |
| 2089 | // Verify that the valid API permissions have been recognized. |
| 2090 | expected_api_perms.insert(APIPermission::kTab); |
| 2091 | |
| 2092 | known_perms = prefs->GetGrantedPermissions(extension->id()); |
| 2093 | EXPECT_TRUE(known_perms.get()); |
| 2094 | EXPECT_FALSE(known_perms->IsEmpty()); |
| 2095 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 2096 | EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
| 2097 | } |
| 2098 | #endif |
| 2099 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2100 | #if !defined(OS_CHROMEOS) |
| 2101 | // Tests that the granted permissions full_access bit gets set correctly when |
| 2102 | // an extension contains an NPAPI plugin. Don't run this test on Chrome OS |
| 2103 | // since they don't support plugins. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2104 | TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 2105 | InitPluginService(); |
[email protected] | 183d4b8 | 2011-11-11 18:50:26 | [diff] [blame] | 2106 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2107 | InitializeEmptyExtensionService(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2108 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2109 | ASSERT_TRUE(base::PathExists(good1_path())); |
| 2110 | const Extension* extension = PackAndInstallCRX(good1_path(), INSTALL_NEW); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2111 | EXPECT_EQ(0u, GetErrors().size()); |
| 2112 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2113 | ExtensionPrefs* prefs = service_->extension_prefs(); |
| 2114 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2115 | scoped_refptr<PermissionSet> permissions( |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2116 | prefs->GetGrantedPermissions(extension->id())); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2117 | EXPECT_FALSE(permissions->IsEmpty()); |
| 2118 | EXPECT_TRUE(permissions->HasEffectiveFullAccess()); |
| 2119 | EXPECT_FALSE(permissions->apis().empty()); |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2120 | EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2121 | |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2122 | // Full access implies full host access too... |
| 2123 | EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2124 | } |
| 2125 | #endif |
| 2126 | |
| 2127 | // Tests that the extension is disabled when permissions are missing from |
| 2128 | // the extension's granted permissions preferences. (This simulates updating |
| 2129 | // the browser to a version which recognizes more permissions). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2130 | TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2131 | InitializeEmptyExtensionService(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2132 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2133 | base::FilePath path = data_dir_ |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2134 | .AppendASCII("permissions") |
| 2135 | .AppendASCII("unknown"); |
| 2136 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2137 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2138 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2139 | const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2140 | |
| 2141 | EXPECT_EQ(0u, GetErrors().size()); |
| 2142 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2143 | std::string extension_id = extension->id(); |
| 2144 | |
| 2145 | ExtensionPrefs* prefs = service_->extension_prefs(); |
| 2146 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2147 | APIPermissionSet expected_api_permissions; |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2148 | URLPatternSet expected_host_permissions; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2149 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2150 | expected_api_permissions.insert(APIPermission::kTab); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2151 | AddPattern(&expected_host_permissions, "http://*.google.com/*"); |
| 2152 | AddPattern(&expected_host_permissions, "https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 2153 | AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2154 | AddPattern(&expected_host_permissions, "http://www.example.com/*"); |
| 2155 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2156 | std::set<std::string> host_permissions; |
| 2157 | |
| 2158 | // Test that the extension is disabled when an API permission is missing from |
| 2159 | // the extension's granted api permissions preference. (This simulates |
| 2160 | // updating the browser to a version which recognizes a new API permission). |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2161 | SetPref(extension_id, "granted_permissions.api", |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 2162 | new base::ListValue(), "granted_permissions.api"); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2163 | service_->ReloadExtensionsForTest(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2164 | |
| 2165 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 2166 | extension = service_->disabled_extensions()->begin()->get(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2167 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 2168 | ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 2169 | ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2170 | ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 2171 | |
| 2172 | // Now grant and re-enable the extension, making sure the prefs are updated. |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 2173 | service_->GrantPermissionsAndEnableExtension(extension); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2174 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 2175 | ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 2176 | ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2177 | ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 2178 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2179 | scoped_refptr<PermissionSet> current_perms( |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2180 | prefs->GetGrantedPermissions(extension_id)); |
| 2181 | ASSERT_TRUE(current_perms.get()); |
| 2182 | ASSERT_FALSE(current_perms->IsEmpty()); |
| 2183 | ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); |
| 2184 | ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 2185 | ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2186 | |
| 2187 | // Tests that the extension is disabled when a host permission is missing from |
| 2188 | // the extension's granted host permissions preference. (This simulates |
| 2189 | // updating the browser to a version which recognizes additional host |
| 2190 | // permissions). |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2191 | host_permissions.clear(); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2192 | current_perms = NULL; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2193 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2194 | host_permissions.insert("http://*.google.com/*"); |
| 2195 | host_permissions.insert("https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 2196 | host_permissions.insert("http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2197 | |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 2198 | base::ListValue* api_permissions = new base::ListValue(); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2199 | api_permissions->Append( |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 2200 | new base::StringValue("tabs")); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2201 | SetPref(extension_id, "granted_permissions.api", |
| 2202 | api_permissions, "granted_permissions.api"); |
| 2203 | SetPrefStringSet( |
| 2204 | extension_id, "granted_permissions.scriptable_host", host_permissions); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2205 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2206 | service_->ReloadExtensionsForTest(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2207 | |
| 2208 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 2209 | extension = service_->disabled_extensions()->begin()->get(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2210 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 2211 | ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 2212 | ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2213 | ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 2214 | |
| 2215 | // Now grant and re-enable the extension, making sure the prefs are updated. |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 2216 | service_->GrantPermissionsAndEnableExtension(extension); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2217 | |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 2218 | ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2219 | ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 2220 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2221 | current_perms = prefs->GetGrantedPermissions(extension_id); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2222 | ASSERT_TRUE(current_perms.get()); |
| 2223 | ASSERT_FALSE(current_perms->IsEmpty()); |
| 2224 | ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); |
| 2225 | ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 2226 | ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2227 | } |
| 2228 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2229 | // Test Packaging and installing an extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2230 | TEST_F(ExtensionServiceTest, PackExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2231 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2232 | base::FilePath input_directory = data_dir_ |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 2233 | .AppendASCII("good") |
| 2234 | .AppendASCII("Extensions") |
| 2235 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 2236 | .AppendASCII("1.0.0.0"); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2237 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2238 | base::ScopedTempDir temp_dir; |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 2239 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2240 | base::FilePath output_directory = temp_dir.path(); |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 2241 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2242 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 2243 | base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2244 | |
| 2245 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2246 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 2247 | privkey_path, ExtensionCreator::kNoRunFlags)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2248 | ASSERT_TRUE(base::PathExists(crx_path)); |
| 2249 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 2250 | |
| 2251 | // Repeat the run with the pem file gone, and no special flags |
| 2252 | // Should refuse to overwrite the existing crx. |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 2253 | base::DeleteFile(privkey_path, false); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2254 | ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 2255 | privkey_path, ExtensionCreator::kNoRunFlags)); |
| 2256 | |
| 2257 | // OK, now try it with a flag to overwrite existing crx. Should work. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2258 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 2259 | privkey_path, ExtensionCreator::kOverwriteCRX)); |
| 2260 | |
| 2261 | // Repeat the run allowing existing crx, but the existing pem is still |
| 2262 | // an error. Should fail. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2263 | ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 2264 | privkey_path, ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2265 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2266 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2267 | InstallCRX(crx_path, INSTALL_NEW); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 2268 | |
| 2269 | // Try packing with invalid paths. |
| 2270 | creator.reset(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2271 | ASSERT_FALSE( |
| 2272 | creator->Run(base::FilePath(), base::FilePath(), base::FilePath(), |
| 2273 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 2274 | |
| 2275 | // Try packing an empty directory. Should fail because an empty directory is |
| 2276 | // not a valid extension. |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2277 | base::ScopedTempDir temp_dir2; |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 2278 | ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
| 2279 | creator.reset(new ExtensionCreator()); |
| 2280 | ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2281 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 2282 | |
| 2283 | // Try packing with an invalid manifest. |
| 2284 | std::string invalid_manifest_content = "I am not a manifest."; |
| 2285 | ASSERT_TRUE(file_util::WriteFile( |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2286 | temp_dir2.path().Append(extensions::kManifestFilename), |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 2287 | invalid_manifest_content.c_str(), invalid_manifest_content.size())); |
| 2288 | creator.reset(new ExtensionCreator()); |
| 2289 | ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2290 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | c21b5b61 | 2013-07-31 07:49:16 | [diff] [blame] | 2291 | |
| 2292 | // Try packing with a private key that is a valid key, but invalid for the |
| 2293 | // extension. |
| 2294 | base::FilePath bad_private_key_dir = data_dir_.AppendASCII("bad_private_key"); |
| 2295 | crx_path = output_directory.AppendASCII("bad_private_key.crx"); |
| 2296 | privkey_path = data_dir_.AppendASCII("bad_private_key.pem"); |
| 2297 | ASSERT_FALSE(creator->Run(bad_private_key_dir, crx_path, base::FilePath(), |
| 2298 | privkey_path, ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2299 | } |
| 2300 | |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2301 | // Test Packaging and installing an extension whose name contains punctuation. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2302 | TEST_F(ExtensionServiceTest, PackPunctuatedExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2303 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2304 | base::FilePath input_directory = data_dir_ |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2305 | .AppendASCII("good") |
| 2306 | .AppendASCII("Extensions") |
| 2307 | .AppendASCII(good0) |
| 2308 | .AppendASCII("1.0.0.0"); |
| 2309 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2310 | base::ScopedTempDir temp_dir; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2311 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 2312 | |
| 2313 | // Extension names containing punctuation, and the expected names for the |
| 2314 | // packed extensions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2315 | const base::FilePath punctuated_names[] = { |
| 2316 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods")), |
| 2317 | base::FilePath(FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod")), |
| 2318 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname/")). |
[email protected] | d9034ed2 | 2012-02-10 02:04:40 | [diff] [blame] | 2319 | NormalizePathSeparators(), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2320 | }; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2321 | const base::FilePath expected_crx_names[] = { |
| 2322 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods.crx")), |
| 2323 | base::FilePath( |
| 2324 | FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.crx")), |
| 2325 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.crx")), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2326 | }; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2327 | const base::FilePath expected_private_key_names[] = { |
| 2328 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods.pem")), |
| 2329 | base::FilePath( |
| 2330 | FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.pem")), |
| 2331 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.pem")), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2332 | }; |
| 2333 | |
| 2334 | for (size_t i = 0; i < arraysize(punctuated_names); ++i) { |
| 2335 | SCOPED_TRACE(punctuated_names[i].value().c_str()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2336 | base::FilePath output_dir = temp_dir.path().Append(punctuated_names[i]); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2337 | |
| 2338 | // Copy the extension into the output directory, as PackExtensionJob doesn't |
| 2339 | // let us choose where to output the packed extension. |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 2340 | ASSERT_TRUE(base::CopyDirectory(input_directory, output_dir, true)); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2341 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2342 | base::FilePath expected_crx_path = |
| 2343 | temp_dir.path().Append(expected_crx_names[i]); |
| 2344 | base::FilePath expected_private_key_path = |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2345 | temp_dir.path().Append(expected_private_key_names[i]); |
| 2346 | PackExtensionTestClient pack_client(expected_crx_path, |
| 2347 | expected_private_key_path); |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 2348 | scoped_refptr<extensions::PackExtensionJob> packer( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2349 | new extensions::PackExtensionJob(&pack_client, output_dir, |
| 2350 | base::FilePath(), |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 2351 | ExtensionCreator::kOverwriteCRX)); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2352 | packer->Start(); |
| 2353 | |
| 2354 | // The packer will post a notification task to the current thread's message |
| 2355 | // loop when it is finished. We manually run the loop here so that we |
| 2356 | // block and catch the notification; otherwise, the process would exit. |
| 2357 | // This call to |Run()| is matched by a call to |Quit()| in the |
| 2358 | // |PackExtensionTestClient|'s notification handling code. |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 2359 | base::MessageLoop::current()->Run(); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2360 | |
| 2361 | if (HasFatalFailure()) |
| 2362 | return; |
| 2363 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2364 | InstallCRX(expected_crx_path, INSTALL_NEW); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2365 | } |
| 2366 | } |
| 2367 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2368 | TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) { |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2369 | InitializeEmptyExtensionService(); |
| 2370 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2371 | base::ScopedTempDir extension_temp_dir; |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2372 | ASSERT_TRUE(extension_temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2373 | base::FilePath input_directory = extension_temp_dir.path().AppendASCII("ext"); |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 2374 | ASSERT_TRUE(base::CopyDirectory( |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2375 | data_dir_ |
| 2376 | .AppendASCII("good") |
| 2377 | .AppendASCII("Extensions") |
| 2378 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 2379 | .AppendASCII("1.0.0.0"), |
| 2380 | input_directory, |
| 2381 | /*recursive=*/true)); |
| 2382 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2383 | base::ScopedTempDir output_temp_dir; |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2384 | ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2385 | base::FilePath output_directory = output_temp_dir.path(); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2386 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2387 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 2388 | base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2389 | |
| 2390 | // Pack the extension once to get a private key. |
| 2391 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2392 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2393 | privkey_path, ExtensionCreator::kNoRunFlags)) |
| 2394 | << creator->error_message(); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2395 | ASSERT_TRUE(base::PathExists(crx_path)); |
| 2396 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2397 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 2398 | base::DeleteFile(crx_path, false); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2399 | // Move the pem file into the extension. |
[email protected] | 5553d5b | 2013-07-01 23:07:36 | [diff] [blame] | 2400 | base::Move(privkey_path, |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2401 | input_directory.AppendASCII("privkey.pem")); |
| 2402 | |
| 2403 | // This pack should fail because of the contained private key. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2404 | EXPECT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2405 | privkey_path, ExtensionCreator::kNoRunFlags)); |
| 2406 | EXPECT_THAT(creator->error_message(), |
| 2407 | testing::ContainsRegex( |
| 2408 | "extension includes the key file.*privkey.pem")); |
| 2409 | } |
| 2410 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2411 | // Test Packaging and installing an extension using an openssl generated key. |
| 2412 | // The openssl is generated with the following: |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 2413 | // > openssl genrsa -out privkey.pem 1024 |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 2414 | // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 2415 | // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2416 | // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2417 | TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2418 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2419 | base::FilePath input_directory = data_dir_ |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 2420 | .AppendASCII("good") |
| 2421 | .AppendASCII("Extensions") |
| 2422 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 2423 | .AppendASCII("1.0.0.0"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2424 | base::FilePath privkey_path(data_dir_.AppendASCII( |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2425 | "openssl_privkey_asn1.pem")); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2426 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2427 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2428 | base::ScopedTempDir temp_dir; |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 2429 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2430 | base::FilePath output_directory = temp_dir.path(); |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 2431 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2432 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2433 | |
| 2434 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 2435 | ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2436 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2437 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2438 | InstallCRX(crx_path, INSTALL_NEW); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2439 | } |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2440 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2441 | TEST_F(ExtensionServiceTest, InstallTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2442 | InitializeEmptyExtensionService(); |
[email protected] | b1ac7046 | 2013-08-14 21:33:30 | [diff] [blame] | 2443 | service_->Init(); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2444 | |
| 2445 | // A theme. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2446 | base::FilePath path = data_dir_.AppendASCII("theme.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2447 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2448 | int pref_count = 0; |
| 2449 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2450 | ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2451 | ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2452 | |
[email protected] | 6ef635e4 | 2009-07-26 06:16:12 | [diff] [blame] | 2453 | // A theme when extensions are disabled. Themes can be installed, even when |
| 2454 | // extensions are disabled. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2455 | set_extensions_enabled(false); |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2456 | path = data_dir_.AppendASCII("theme2.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2457 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2458 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2459 | ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2460 | ValidateIntegerPref(theme2_crx, "location", Manifest::INTERNAL); |
[email protected] | 494c06e | 2009-07-25 01:06:42 | [diff] [blame] | 2461 | |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2462 | // A theme with extension elements. Themes cannot have extension elements, |
| 2463 | // so any such elements (like content scripts) should be ignored. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2464 | set_extensions_enabled(true); |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2465 | { |
| 2466 | path = data_dir_.AppendASCII("theme_with_extension.crx"); |
| 2467 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2468 | ValidatePrefKeyCount(++pref_count); |
| 2469 | ASSERT_TRUE(extension); |
| 2470 | EXPECT_TRUE(extension->is_theme()); |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 2471 | EXPECT_EQ( |
| 2472 | 0u, |
| 2473 | extensions::ContentScriptsInfo::GetContentScripts(extension).size()); |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2474 | } |
[email protected] | 1219891 | 2009-06-05 03:41:22 | [diff] [blame] | 2475 | |
| 2476 | // A theme with image resources missing (misspelt path). |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2477 | path = data_dir_.AppendASCII("theme_missing_image.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2478 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2479 | ValidatePrefKeyCount(pref_count); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2480 | } |
| 2481 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2482 | TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2483 | // Load. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2484 | InitializeEmptyExtensionService(); |
[email protected] | b1ac7046 | 2013-08-14 21:33:30 | [diff] [blame] | 2485 | service_->Init(); |
| 2486 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2487 | base::FilePath extension_path = data_dir_ |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2488 | .AppendASCII("theme_i18n"); |
| 2489 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2490 | extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2491 | base::RunLoop().RunUntilIdle(); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2492 | EXPECT_EQ(0u, GetErrors().size()); |
| 2493 | ASSERT_EQ(1u, loaded_.size()); |
| 2494 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 2495 | const Extension* theme = service_->extensions()->begin()->get(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2496 | EXPECT_EQ("name", theme->name()); |
| 2497 | EXPECT_EQ("description", theme->description()); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 2498 | |
| 2499 | // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a |
| 2500 | // temporary directory, but it automatically installs to the extension's |
| 2501 | // 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] | 2502 | base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2503 | ASSERT_TRUE(base::PathExists(theme_file)); |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 2504 | ASSERT_TRUE(base::DeleteFile(theme_file, false)); // Not recursive. |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2505 | } |
| 2506 | |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2507 | // Tests that we can change the ID of an unpacked extension by adding a key |
| 2508 | // to its manifest. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2509 | TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) { |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2510 | InitializeEmptyExtensionService(); |
| 2511 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2512 | base::ScopedTempDir temp; |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2513 | ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 2514 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2515 | base::FilePath extension_path = temp.path(); |
| 2516 | base::FilePath manifest_path = |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2517 | extension_path.Append(extensions::kManifestFilename); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2518 | base::FilePath manifest_no_key = data_dir_. |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2519 | AppendASCII("unpacked"). |
| 2520 | AppendASCII("manifest_no_key.json"); |
| 2521 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2522 | base::FilePath manifest_with_key = data_dir_. |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2523 | AppendASCII("unpacked"). |
| 2524 | AppendASCII("manifest_with_key.json"); |
| 2525 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2526 | ASSERT_TRUE(base::PathExists(manifest_no_key)); |
| 2527 | ASSERT_TRUE(base::PathExists(manifest_with_key)); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2528 | |
| 2529 | // Load the unpacked extension with no key. |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 2530 | base::CopyFile(manifest_no_key, manifest_path); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2531 | extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
| 2532 | |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2533 | base::RunLoop().RunUntilIdle(); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2534 | EXPECT_EQ(0u, GetErrors().size()); |
| 2535 | ASSERT_EQ(1u, loaded_.size()); |
| 2536 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 2537 | |
| 2538 | // Add the key to the manifest. |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 2539 | base::CopyFile(manifest_with_key, manifest_path); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2540 | loaded_.clear(); |
| 2541 | |
| 2542 | // Reload the extensions. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2543 | service_->ReloadExtensionsForTest(); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2544 | const Extension* extension = service_->GetExtensionById(unpacked, false); |
| 2545 | EXPECT_EQ(unpacked, extension->id()); |
| 2546 | ASSERT_EQ(1u, loaded_.size()); |
| 2547 | |
| 2548 | // TODO(jstritar): Right now this just makes sure we don't crash and burn, but |
| 2549 | // we should also test that preferences are preserved. |
| 2550 | } |
| 2551 | |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2552 | #if defined(OS_POSIX) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2553 | TEST_F(ExtensionServiceTest, UnpackedExtensionMayContainSymlinkedFiles) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2554 | base::FilePath source_data_dir = data_dir_. |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2555 | AppendASCII("unpacked"). |
| 2556 | AppendASCII("symlinks_allowed"); |
| 2557 | |
| 2558 | // Paths to test data files. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2559 | base::FilePath source_manifest = source_data_dir.AppendASCII("manifest.json"); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2560 | ASSERT_TRUE(base::PathExists(source_manifest)); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2561 | base::FilePath source_icon = source_data_dir.AppendASCII("icon.png"); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2562 | ASSERT_TRUE(base::PathExists(source_icon)); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2563 | |
| 2564 | // Set up the temporary extension directory. |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2565 | base::ScopedTempDir temp; |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2566 | ASSERT_TRUE(temp.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2567 | base::FilePath extension_path = temp.path(); |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2568 | base::FilePath manifest = extension_path.Append( |
| 2569 | extensions::kManifestFilename); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2570 | base::FilePath icon_symlink = extension_path.AppendASCII("icon.png"); |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 2571 | base::CopyFile(source_manifest, manifest); |
[email protected] | b264eab | 2013-11-27 23:22:08 | [diff] [blame] | 2572 | base::CreateSymbolicLink(source_icon, icon_symlink); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2573 | |
| 2574 | // Load extension. |
| 2575 | InitializeEmptyExtensionService(); |
| 2576 | extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2577 | base::RunLoop().RunUntilIdle(); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2578 | |
| 2579 | EXPECT_TRUE(GetErrors().empty()); |
| 2580 | ASSERT_EQ(1u, loaded_.size()); |
| 2581 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 2582 | } |
| 2583 | #endif |
| 2584 | |
[email protected] | 5ccca8ad | 2013-08-19 22:35:34 | [diff] [blame] | 2585 | TEST_F(ExtensionServiceTest, UnpackedExtensionMayNotHaveUnderscore) { |
| 2586 | InitializeEmptyExtensionService(); |
| 2587 | base::FilePath extension_path = data_dir_ |
| 2588 | .AppendASCII("underscore_name"); |
| 2589 | extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
| 2590 | base::RunLoop().RunUntilIdle(); |
| 2591 | EXPECT_EQ(1u, GetErrors().size()); |
| 2592 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 2593 | } |
| 2594 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2595 | TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2596 | InitializeEmptyExtensionService(); |
[email protected] | b1ac7046 | 2013-08-14 21:33:30 | [diff] [blame] | 2597 | service_->Init(); |
| 2598 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2599 | base::FilePath theme_path = data_dir_ |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2600 | .AppendASCII("theme_i18n"); |
| 2601 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2602 | const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2603 | |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2604 | EXPECT_EQ(0u, GetErrors().size()); |
| 2605 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2606 | EXPECT_EQ("name", theme->name()); |
| 2607 | EXPECT_EQ("description", theme->description()); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2608 | } |
| 2609 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2610 | TEST_F(ExtensionServiceTest, InstallApps) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2611 | InitializeEmptyExtensionService(); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2612 | |
| 2613 | // An empty app. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2614 | const Extension* app = PackAndInstallCRX(data_dir_.AppendASCII("app1"), |
| 2615 | INSTALL_NEW); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2616 | int pref_count = 0; |
| 2617 | ValidatePrefKeyCount(++pref_count); |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 2618 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2619 | ValidateIntegerPref(app->id(), "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2620 | ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2621 | |
| 2622 | // Another app with non-overlapping extent. Should succeed. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2623 | PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2624 | ValidatePrefKeyCount(++pref_count); |
| 2625 | |
| 2626 | // A third app whose extent overlaps the first. Should fail. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2627 | PackAndInstallCRX(data_dir_.AppendASCII("app3"), INSTALL_FAILED); |
[email protected] | cd10e28 | 2010-10-26 21:04:51 | [diff] [blame] | 2628 | ValidatePrefKeyCount(pref_count); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2629 | } |
| 2630 | |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2631 | // Tests that file access is OFF by default. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2632 | TEST_F(ExtensionServiceTest, DefaultFileAccess) { |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2633 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2634 | const Extension* extension = |
| 2635 | PackAndInstallCRX(data_dir_ |
| 2636 | .AppendASCII("permissions") |
| 2637 | .AppendASCII("files"), |
| 2638 | INSTALL_NEW); |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2639 | EXPECT_EQ(0u, GetErrors().size()); |
| 2640 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2641 | EXPECT_FALSE(service_->extension_prefs()->AllowFileAccess(extension->id())); |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2642 | } |
| 2643 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2644 | TEST_F(ExtensionServiceTest, UpdateApps) { |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2645 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2646 | base::FilePath extensions_path = data_dir_.AppendASCII("app_update"); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2647 | |
| 2648 | // First install v1 of a hosted app. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2649 | const Extension* extension = |
| 2650 | InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2651 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2652 | std::string id = extension->id(); |
| 2653 | ASSERT_EQ(std::string("1"), extension->version()->GetString()); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2654 | |
| 2655 | // Now try updating to v2. |
| 2656 | UpdateExtension(id, |
| 2657 | extensions_path.AppendASCII("v2.crx"), |
| 2658 | ENABLED); |
| 2659 | ASSERT_EQ(std::string("2"), |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2660 | service_->GetExtensionById(id, false)->version()->GetString()); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2661 | } |
| 2662 | |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2663 | // Verifies that the NTP page and launch ordinals are kept when updating apps. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2664 | TEST_F(ExtensionServiceTest, UpdateAppsRetainOrdinals) { |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2665 | InitializeEmptyExtensionService(); |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 2666 | AppSorting* sorting = service_->extension_prefs()->app_sorting(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2667 | base::FilePath extensions_path = data_dir_.AppendASCII("app_update"); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2668 | |
| 2669 | // First install v1 of a hosted app. |
| 2670 | const Extension* extension = |
| 2671 | InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); |
| 2672 | ASSERT_EQ(1u, service_->extensions()->size()); |
| 2673 | std::string id = extension->id(); |
| 2674 | ASSERT_EQ(std::string("1"), extension->version()->GetString()); |
| 2675 | |
| 2676 | // Modify the ordinals so we can distinguish them from the defaults. |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 2677 | syncer::StringOrdinal new_page_ordinal = |
| 2678 | sorting->GetPageOrdinal(id).CreateAfter(); |
| 2679 | syncer::StringOrdinal new_launch_ordinal = |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2680 | sorting->GetAppLaunchOrdinal(id).CreateBefore(); |
| 2681 | |
| 2682 | sorting->SetPageOrdinal(id, new_page_ordinal); |
| 2683 | sorting->SetAppLaunchOrdinal(id, new_launch_ordinal); |
| 2684 | |
| 2685 | // Now try updating to v2. |
| 2686 | UpdateExtension(id, extensions_path.AppendASCII("v2.crx"), ENABLED); |
| 2687 | ASSERT_EQ(std::string("2"), |
| 2688 | service_->GetExtensionById(id, false)->version()->GetString()); |
| 2689 | |
| 2690 | // Verify that the ordinals match. |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 2691 | ASSERT_TRUE(new_page_ordinal.Equals(sorting->GetPageOrdinal(id))); |
| 2692 | ASSERT_TRUE(new_launch_ordinal.Equals(sorting->GetAppLaunchOrdinal(id))); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2693 | } |
| 2694 | |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2695 | // Ensures that the CWS has properly initialized ordinals. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2696 | TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) { |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2697 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2698 | service_->component_loader()->Add( |
| 2699 | IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store"))); |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2700 | service_->Init(); |
| 2701 | |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 2702 | AppSorting* sorting = service_->extension_prefs()->app_sorting(); |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2703 | EXPECT_TRUE( |
| 2704 | sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid()); |
| 2705 | EXPECT_TRUE( |
| 2706 | sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid()); |
| 2707 | } |
| 2708 | |
[email protected] | fe10c20 | 2013-03-11 23:44:34 | [diff] [blame] | 2709 | TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2710 | InitializeEmptyExtensionService(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2711 | EXPECT_TRUE(service_->extensions()->is_empty()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2712 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2713 | int pref_count = 0; |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2714 | |
| 2715 | // Install app1 with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2716 | const Extension* extension = |
| 2717 | PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2718 | ValidatePrefKeyCount(++pref_count); |
| 2719 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2720 | const std::string id1 = extension->id(); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2721 | EXPECT_TRUE(extension->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2722 | APIPermission::kUnlimitedStorage)); |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2723 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2724 | extensions::AppLaunchInfo::GetFullLaunchURL(extension))); |
| 2725 | const GURL origin1( |
| 2726 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2727 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2728 | IsStorageUnlimited(origin1)); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2729 | |
| 2730 | // Install app2 from the same origin with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2731 | extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2732 | ValidatePrefKeyCount(++pref_count); |
| 2733 | ASSERT_EQ(2u, service_->extensions()->size()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2734 | const std::string id2 = extension->id(); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2735 | EXPECT_TRUE(extension->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2736 | APIPermission::kUnlimitedStorage)); |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2737 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2738 | extensions::AppLaunchInfo::GetFullLaunchURL(extension))); |
| 2739 | const GURL origin2( |
| 2740 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2741 | EXPECT_EQ(origin1, origin2); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2742 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2743 | IsStorageUnlimited(origin2)); |
| 2744 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2745 | |
| 2746 | // Uninstall one of them, unlimited storage should still be granted |
| 2747 | // to the origin. |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2748 | UninstallExtension(id1, false); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2749 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2750 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2751 | IsStorageUnlimited(origin1)); |
| 2752 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2753 | // Uninstall the other, unlimited storage should be revoked. |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2754 | UninstallExtension(id2, false); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2755 | EXPECT_EQ(0u, service_->extensions()->size()); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2756 | EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2757 | IsStorageUnlimited(origin2)); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2758 | } |
| 2759 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2760 | TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2761 | InitializeEmptyExtensionService(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2762 | EXPECT_TRUE(service_->extensions()->is_empty()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2763 | |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2764 | int pref_count = 0; |
| 2765 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2766 | const Extension* extension = |
| 2767 | PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2768 | ValidatePrefKeyCount(++pref_count); |
| 2769 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2770 | EXPECT_TRUE(extension->is_app()); |
| 2771 | const std::string id1 = extension->id(); |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2772 | const GURL origin1( |
| 2773 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2774 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2775 | IsStorageProtected(origin1)); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2776 | |
| 2777 | // App 4 has a different origin (maps.google.com). |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2778 | extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2779 | ValidatePrefKeyCount(++pref_count); |
| 2780 | ASSERT_EQ(2u, service_->extensions()->size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2781 | const std::string id2 = extension->id(); |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2782 | const GURL origin2( |
| 2783 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2784 | ASSERT_NE(origin1, origin2); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2785 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2786 | IsStorageProtected(origin2)); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2787 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2788 | UninstallExtension(id1, false); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2789 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2790 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2791 | UninstallExtension(id2, false); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2792 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2793 | EXPECT_TRUE(service_->extensions()->is_empty()); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2794 | EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2795 | IsStorageProtected(origin1)); |
| 2796 | EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2797 | IsStorageProtected(origin2)); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2798 | } |
| 2799 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2800 | // Test that when an extension version is reinstalled, nothing happens. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2801 | TEST_F(ExtensionServiceTest, Reinstall) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2802 | InitializeEmptyExtensionService(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2803 | |
| 2804 | // A simple extension that should install without error. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2805 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2806 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2807 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2808 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2809 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2810 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2811 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 2812 | // Reinstall the same version, it should overwrite the previous one. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2813 | InstallCRX(path, INSTALL_UPDATED); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2814 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2815 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2816 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2817 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2818 | } |
| 2819 | |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2820 | // Test that we can determine if extensions came from the |
| 2821 | // Chrome web store. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2822 | TEST_F(ExtensionServiceTest, FromWebStore) { |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2823 | InitializeEmptyExtensionService(); |
| 2824 | |
| 2825 | // A simple extension that should install without error. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2826 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2827 | // Not from web store. |
| 2828 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2829 | std::string id = extension->id(); |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2830 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2831 | ValidatePrefKeyCount(1); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2832 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", false)); |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2833 | ASSERT_FALSE(extension->from_webstore()); |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2834 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2835 | // Test install from web store. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2836 | InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store. |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2837 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2838 | ValidatePrefKeyCount(1); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2839 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2840 | |
| 2841 | // Reload so extension gets reinitialized with new value. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2842 | service_->ReloadExtensionsForTest(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2843 | extension = service_->GetExtensionById(id, false); |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2844 | ASSERT_TRUE(extension->from_webstore()); |
[email protected] | 3d72972 | 2011-09-20 02:57:09 | [diff] [blame] | 2845 | |
| 2846 | // Upgrade to version 2.0 |
| 2847 | path = data_dir_.AppendASCII("good2.crx"); |
| 2848 | UpdateExtension(good_crx, path, ENABLED); |
| 2849 | ValidatePrefKeyCount(1); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2850 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2851 | } |
| 2852 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2853 | // Test upgrading a signed extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2854 | TEST_F(ExtensionServiceTest, UpgradeSignedGood) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2855 | InitializeEmptyExtensionService(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2856 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2857 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2858 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2859 | std::string id = extension->id(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2860 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2861 | ASSERT_EQ("1.0.0.0", extension->version()->GetString()); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2862 | ASSERT_EQ(0u, GetErrors().size()); |
| 2863 | |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 2864 | // Upgrade to version 1.0.0.1. |
| 2865 | // Also test that the extension's old and new title are correctly retrieved. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2866 | path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 2867 | InstallCRX(path, INSTALL_UPDATED, Extension::NO_FLAGS, "My extension 1"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2868 | extension = service_->GetExtensionById(id, false); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2869 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2870 | ASSERT_EQ("1.0.0.1", extension->version()->GetString()); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 2871 | ASSERT_EQ("My updated extension 1", extension->name()); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2872 | ASSERT_EQ(0u, GetErrors().size()); |
| 2873 | } |
| 2874 | |
| 2875 | // Test upgrading a signed extension with a bad signature. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2876 | TEST_F(ExtensionServiceTest, UpgradeSignedBad) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2877 | InitializeEmptyExtensionService(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2878 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2879 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2880 | InstallCRX(path, INSTALL_NEW); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2881 | |
| 2882 | // Try upgrading with a bad signature. This should fail during the unpack, |
| 2883 | // because the key will not match the signature. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2884 | path = data_dir_.AppendASCII("bad_signature.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2885 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2886 | } |
| 2887 | |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2888 | // Test a normal update via the UpdateExtension API |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2889 | TEST_F(ExtensionServiceTest, UpdateExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2890 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2891 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2892 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2893 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2894 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2895 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2896 | ASSERT_EQ(good_crx, good->id()); |
| 2897 | |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2898 | path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2899 | UpdateExtension(good_crx, path, ENABLED); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2900 | ASSERT_EQ("1.0.0.1", |
| 2901 | service_->GetExtensionById(good_crx, false)-> |
| 2902 | version()->GetString()); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2903 | } |
| 2904 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2905 | // Extensions should not be updated during browser shutdown. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2906 | TEST_F(ExtensionServiceTest, UpdateExtensionDuringShutdown) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2907 | InitializeEmptyExtensionService(); |
| 2908 | |
| 2909 | // Install an extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2910 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2911 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2912 | ASSERT_EQ(good_crx, good->id()); |
| 2913 | |
| 2914 | // Simulate shutdown. |
| 2915 | service_->set_browser_terminating_for_test(true); |
| 2916 | |
| 2917 | // Update should fail and extension should not be updated. |
| 2918 | path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 2919 | bool updated = service_->UpdateExtension(good_crx, path, true, GURL(), NULL); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2920 | ASSERT_FALSE(updated); |
| 2921 | ASSERT_EQ("1.0.0.0", |
| 2922 | service_->GetExtensionById(good_crx, false)-> |
| 2923 | version()->GetString()); |
| 2924 | } |
| 2925 | |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2926 | // Test updating a not-already-installed extension - this should fail |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2927 | TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2928 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2929 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2930 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2931 | UpdateExtension(good_crx, path, UPDATED); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 2932 | base::RunLoop().RunUntilIdle(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2933 | |
| 2934 | ASSERT_EQ(0u, service_->extensions()->size()); |
| 2935 | ASSERT_FALSE(installed_); |
| 2936 | ASSERT_EQ(0u, loaded_.size()); |
| 2937 | } |
| 2938 | |
| 2939 | // Makes sure you can't downgrade an extension via UpdateExtension |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2940 | TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2941 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2942 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2943 | base::FilePath path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2944 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2945 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2946 | ASSERT_EQ("1.0.0.1", good->VersionString()); |
| 2947 | ASSERT_EQ(good_crx, good->id()); |
| 2948 | |
| 2949 | // Change path from good2.crx -> good.crx |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2950 | path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2951 | UpdateExtension(good_crx, path, FAILED); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2952 | ASSERT_EQ("1.0.0.1", |
| 2953 | service_->GetExtensionById(good_crx, false)-> |
| 2954 | version()->GetString()); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | // Make sure calling update with an identical version does nothing |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2958 | TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2959 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2960 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2961 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2962 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2963 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2964 | ASSERT_EQ(good_crx, good->id()); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2965 | UpdateExtension(good_crx, path, FAILED_SILENTLY); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2966 | } |
| 2967 | |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2968 | // Tests that updating an extension does not clobber old state. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2969 | TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2970 | InitializeEmptyExtensionService(); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2971 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2972 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2973 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2974 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2975 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2976 | ASSERT_EQ(good_crx, good->id()); |
| 2977 | |
| 2978 | // Disable it and allow it to run in incognito. These settings should carry |
| 2979 | // over to the updated version. |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 2980 | service_->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 2981 | extensions::util::SetIsIncognitoEnabled(good->id(), profile_.get(), true); |
[email protected] | c38fd35 | 2012-03-28 04:06:12 | [diff] [blame] | 2982 | service_->extension_prefs()->SetDidExtensionEscalatePermissions(good, true); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2983 | |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2984 | path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2985 | UpdateExtension(good_crx, path, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 2986 | ASSERT_EQ(1u, service_->disabled_extensions()->size());\ |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2987 | const Extension* good2 = service_->GetExtensionById(good_crx, true); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2988 | ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 2989 | EXPECT_TRUE(extensions::util::IsIncognitoEnabled( |
| 2990 | good2->id(), profile_.get())); |
[email protected] | c38fd35 | 2012-03-28 04:06:12 | [diff] [blame] | 2991 | EXPECT_TRUE(service_->extension_prefs()->DidExtensionEscalatePermissions( |
| 2992 | good2->id())); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2993 | } |
| 2994 | |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2995 | // Tests that updating preserves extension location. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2996 | TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2997 | InitializeEmptyExtensionService(); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2998 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2999 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 3000 | |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 3001 | const Extension* good = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3002 | InstallCRXWithLocation(path, Manifest::EXTERNAL_PREF, INSTALL_NEW); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 3003 | |
| 3004 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 3005 | ASSERT_EQ(good_crx, good->id()); |
| 3006 | |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 3007 | path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 3008 | UpdateExtension(good_crx, path, ENABLED); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3009 | const Extension* good2 = service_->GetExtensionById(good_crx, false); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 3010 | ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3011 | EXPECT_EQ(good2->location(), Manifest::EXTERNAL_PREF); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 3012 | } |
| 3013 | |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 3014 | // Makes sure that LOAD extension types can downgrade. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3015 | TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3016 | InitializeEmptyExtensionService(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 3017 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 3018 | base::ScopedTempDir temp; |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 3019 | ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 3020 | |
| 3021 | // We'll write the extension manifest dynamically to a temporary path |
| 3022 | // to make it easier to change the version number. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3023 | base::FilePath extension_path = temp.path(); |
| 3024 | base::FilePath manifest_path = |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 3025 | extension_path.Append(extensions::kManifestFilename); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 3026 | ASSERT_FALSE(base::PathExists(manifest_path)); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 3027 | |
| 3028 | // Start with version 2.0. |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3029 | base::DictionaryValue manifest; |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 3030 | manifest.SetString("version", "2.0"); |
| 3031 | manifest.SetString("name", "LOAD Downgrade Test"); |
[email protected] | b3d5285 | 2011-12-07 01:01:11 | [diff] [blame] | 3032 | manifest.SetInteger("manifest_version", 2); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 3033 | |
| 3034 | JSONFileValueSerializer serializer(manifest_path); |
| 3035 | ASSERT_TRUE(serializer.Serialize(manifest)); |
| 3036 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 3037 | extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3038 | base::RunLoop().RunUntilIdle(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 3039 | |
| 3040 | EXPECT_EQ(0u, GetErrors().size()); |
| 3041 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 3042 | EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 3043 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3044 | EXPECT_EQ("2.0", loaded_[0]->VersionString()); |
| 3045 | |
| 3046 | // Now set the version number to 1.0, reload the extensions and verify that |
| 3047 | // the downgrade was accepted. |
| 3048 | manifest.SetString("version", "1.0"); |
| 3049 | ASSERT_TRUE(serializer.Serialize(manifest)); |
| 3050 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 3051 | extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3052 | base::RunLoop().RunUntilIdle(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 3053 | |
| 3054 | EXPECT_EQ(0u, GetErrors().size()); |
| 3055 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 3056 | EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 3057 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3058 | EXPECT_EQ("1.0", loaded_[0]->VersionString()); |
| 3059 | } |
| 3060 | |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3061 | #if !defined(OS_CHROMEOS) |
| 3062 | // LOAD extensions with plugins require approval. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3063 | TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) { |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3064 | base::FilePath extension_with_plugin_path = good1_path(); |
| 3065 | base::FilePath extension_no_plugin_path = good2_path(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3066 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 3067 | InitPluginService(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3068 | InitializeEmptyExtensionService(); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 3069 | InitializeProcessManager(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3070 | service_->set_show_extensions_prompts(true); |
| 3071 | |
| 3072 | // Start by canceling any install prompts. |
| 3073 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 3074 | switches::kAppsGalleryInstallAutoConfirmForTests, |
| 3075 | "cancel"); |
| 3076 | |
| 3077 | // The extension that has a plugin should not install. |
| 3078 | extensions::UnpackedInstaller::Create(service_)->Load( |
| 3079 | extension_with_plugin_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3080 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3081 | EXPECT_EQ(0u, GetErrors().size()); |
| 3082 | EXPECT_EQ(0u, loaded_.size()); |
| 3083 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3084 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3085 | |
| 3086 | // But the extension with no plugin should since there's no prompt. |
[email protected] | 252873a | 2013-07-19 01:39:48 | [diff] [blame] | 3087 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3088 | extensions::UnpackedInstaller::Create(service_)->Load( |
| 3089 | extension_no_plugin_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3090 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3091 | EXPECT_EQ(0u, GetErrors().size()); |
| 3092 | EXPECT_EQ(1u, loaded_.size()); |
| 3093 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3094 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3095 | EXPECT_TRUE(service_->extensions()->Contains(good2)); |
| 3096 | |
| 3097 | // The plugin extension should install if we accept the dialog. |
| 3098 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 3099 | switches::kAppsGalleryInstallAutoConfirmForTests, |
| 3100 | "accept"); |
| 3101 | |
[email protected] | 252873a | 2013-07-19 01:39:48 | [diff] [blame] | 3102 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3103 | extensions::UnpackedInstaller::Create(service_)->Load( |
| 3104 | extension_with_plugin_path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3105 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3106 | EXPECT_EQ(0u, GetErrors().size()); |
| 3107 | EXPECT_EQ(2u, loaded_.size()); |
| 3108 | EXPECT_EQ(2u, service_->extensions()->size()); |
| 3109 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3110 | EXPECT_TRUE(service_->extensions()->Contains(good1)); |
| 3111 | EXPECT_TRUE(service_->extensions()->Contains(good2)); |
| 3112 | |
| 3113 | // Make sure the granted permissions have been setup. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 3114 | scoped_refptr<PermissionSet> permissions( |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3115 | service_->extension_prefs()->GetGrantedPermissions(good1)); |
| 3116 | EXPECT_FALSE(permissions->IsEmpty()); |
| 3117 | EXPECT_TRUE(permissions->HasEffectiveFullAccess()); |
| 3118 | EXPECT_FALSE(permissions->apis().empty()); |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 3119 | EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3120 | |
| 3121 | // We should be able to reload the extension without getting another prompt. |
| 3122 | loaded_.clear(); |
| 3123 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 3124 | switches::kAppsGalleryInstallAutoConfirmForTests, |
| 3125 | "cancel"); |
| 3126 | |
| 3127 | service_->ReloadExtension(good1); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3128 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3129 | EXPECT_EQ(1u, loaded_.size()); |
| 3130 | EXPECT_EQ(2u, service_->extensions()->size()); |
| 3131 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3132 | } |
[email protected] | 64bbd6c | 2013-11-12 05:05:41 | [diff] [blame] | 3133 | #endif // !defined(OS_CHROMEOS) |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 3134 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 3135 | namespace { |
| 3136 | |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 3137 | bool IsExtension(const Extension* extension) { |
| 3138 | return extension->GetType() == Manifest::TYPE_EXTENSION; |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | } // namespace |
| 3142 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3143 | // Test adding a pending extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3144 | TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3145 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3146 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 3147 | const std::string kFakeId(all_zero); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3148 | const GURL kFakeUpdateURL("http:://fake.update/url"); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3149 | const bool kFakeInstallSilently(true); |
| 3150 | |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 3151 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 3152 | kFakeId, kFakeUpdateURL, &IsExtension, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3153 | kFakeInstallSilently)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3154 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 3155 | const extensions::PendingExtensionInfo* pending_extension_info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 3156 | ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 3157 | GetById(kFakeId))); |
| 3158 | EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); |
| 3159 | EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); |
| 3160 | EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently()); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3161 | } |
| 3162 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3163 | namespace { |
| 3164 | const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 3165 | const char kGoodUpdateURL[] = "http://good.update/url"; |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3166 | const bool kGoodIsFromSync = true; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3167 | const bool kGoodInstallSilently = true; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3168 | } // namespace |
| 3169 | |
| 3170 | // Test updating a pending extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3171 | TEST_F(ExtensionServiceTest, UpdatePendingExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3172 | InitializeEmptyExtensionService(); |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 3173 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 3174 | kGoodId, GURL(kGoodUpdateURL), &IsExtension, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3175 | kGoodInstallSilently)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3176 | EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3177 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3178 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3179 | UpdateExtension(kGoodId, path, ENABLED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3180 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3181 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 3182 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 3183 | const Extension* extension = service_->GetExtensionById(kGoodId, true); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 3184 | ASSERT_TRUE(extension); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3185 | } |
| 3186 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 3187 | namespace { |
| 3188 | |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 3189 | bool IsTheme(const Extension* extension) { |
| 3190 | return extension->is_theme(); |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | } // namespace |
| 3194 | |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 3195 | // Test updating a pending theme. |
[email protected] | 7f2c555 | 2011-12-20 22:53:16 | [diff] [blame] | 3196 | // Disabled due to ASAN failure. http://crbug.com/108320 |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3197 | TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3198 | InitializeEmptyExtensionService(); |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 3199 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3200 | theme_crx, GURL(), &IsTheme, false)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3201 | EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 3202 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3203 | base::FilePath path = data_dir_.AppendASCII("theme.crx"); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 3204 | UpdateExtension(theme_crx, path, ENABLED); |
| 3205 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3206 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 3207 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 3208 | const Extension* extension = service_->GetExtensionById(theme_crx, true); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 3209 | ASSERT_TRUE(extension); |
| 3210 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 3211 | EXPECT_FALSE( |
| 3212 | service_->extension_prefs()->IsExtensionDisabled(extension->id())); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 3213 | EXPECT_TRUE(service_->IsExtensionEnabled(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 3214 | } |
| 3215 | |
[email protected] | d74f92e | 2011-04-18 15:39:23 | [diff] [blame] | 3216 | #if defined(OS_CHROMEOS) |
| 3217 | // Always fails on ChromeOS: http://crbug.com/79737 |
[email protected] | e00ccc9 | 2012-11-01 17:32:30 | [diff] [blame] | 3218 | #define MAYBE_UpdatePendingExternalCrx DISABLED_UpdatePendingExternalCrx |
[email protected] | d74f92e | 2011-04-18 15:39:23 | [diff] [blame] | 3219 | #else |
| 3220 | #define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx |
| 3221 | #endif |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3222 | // Test updating a pending CRX as if the source is an external extension |
| 3223 | // with an update URL. In this case we don't know if the CRX is a theme |
| 3224 | // or not. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3225 | TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3226 | InitializeEmptyExtensionService(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 3227 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 3228 | theme_crx, GURL(), Manifest::EXTERNAL_PREF_DOWNLOAD, Extension::NO_FLAGS, |
| 3229 | false)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3230 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3231 | EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3232 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3233 | base::FilePath path = data_dir_.AppendASCII("theme.crx"); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3234 | UpdateExtension(theme_crx, path, ENABLED); |
| 3235 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3236 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3237 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 3238 | const Extension* extension = service_->GetExtensionById(theme_crx, true); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3239 | ASSERT_TRUE(extension); |
| 3240 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 3241 | EXPECT_FALSE( |
| 3242 | service_->extension_prefs()->IsExtensionDisabled(extension->id())); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 3243 | EXPECT_TRUE(service_->IsExtensionEnabled(extension->id())); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 3244 | EXPECT_FALSE(extensions::util::IsIncognitoEnabled(extension->id(), |
| 3245 | profile_.get())); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3246 | } |
| 3247 | |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3248 | // Test updating a pending CRX as if the source is an external extension |
| 3249 | // with an update URL. The external update should overwrite a sync update, |
| 3250 | // but a sync update should not overwrite a non-sync update. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3251 | TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3252 | InitializeEmptyExtensionService(); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3253 | |
| 3254 | // Add a crx to be installed from the update mechanism. |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 3255 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 3256 | kGoodId, GURL(kGoodUpdateURL), &IsExtension, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3257 | kGoodInstallSilently)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3258 | |
| 3259 | // 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] | 3260 | const extensions::PendingExtensionInfo* pending_extension_info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 3261 | ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 3262 | GetById(kGoodId))); |
| 3263 | EXPECT_TRUE(pending_extension_info->is_from_sync()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3264 | |
| 3265 | // Add a crx to be updated, with the same ID, from a non-sync source. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 3266 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 3267 | kGoodId, GURL(kGoodUpdateURL), Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 3268 | Extension::NO_FLAGS, false)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3269 | |
| 3270 | // Check that there is a pending crx, with is_from_sync set to false. |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 3271 | ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 3272 | GetById(kGoodId))); |
| 3273 | EXPECT_FALSE(pending_extension_info->is_from_sync()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3274 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 3275 | pending_extension_info->install_source()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3276 | |
| 3277 | // Add a crx to be installed from the update mechanism. |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 3278 | EXPECT_FALSE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 3279 | kGoodId, GURL(kGoodUpdateURL), &IsExtension, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3280 | kGoodInstallSilently)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3281 | |
| 3282 | // Check that the external, non-sync update was not overridden. |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 3283 | ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 3284 | GetById(kGoodId))); |
| 3285 | EXPECT_FALSE(pending_extension_info->is_from_sync()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3286 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 3287 | pending_extension_info->install_source()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 3288 | } |
| 3289 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3290 | // Updating a theme should fail if the updater is explicitly told that |
| 3291 | // the CRX is not a theme. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3292 | TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3293 | InitializeEmptyExtensionService(); |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 3294 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3295 | theme_crx, GURL(), &IsExtension, true)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3296 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3297 | EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3298 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3299 | base::FilePath path = data_dir_.AppendASCII("theme.crx"); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3300 | UpdateExtension(theme_crx, path, FAILED_SILENTLY); |
| 3301 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3302 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3303 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 3304 | const Extension* extension = service_->GetExtensionById(theme_crx, true); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3305 | ASSERT_FALSE(extension); |
| 3306 | } |
| 3307 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3308 | // TODO(akalin): Test updating a pending extension non-silently once |
| 3309 | // we can mock out ExtensionInstallUI and inject our version into |
| 3310 | // UpdateExtension(). |
| 3311 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 3312 | // Test updating a pending extension which fails the should-install test. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3313 | TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3314 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3315 | // Add pending extension with a flipped is_theme. |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 3316 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3317 | kGoodId, GURL(kGoodUpdateURL), &IsTheme, kGoodInstallSilently)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3318 | EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3319 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3320 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 3321 | UpdateExtension(kGoodId, path, UPDATED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3322 | |
| 3323 | // TODO(akalin): Figure out how to check that the extensions |
| 3324 | // directory is cleaned up properly in OnExtensionInstalled(). |
| 3325 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3326 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3327 | } |
| 3328 | |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 3329 | // TODO(akalin): Figure out how to test that installs of pending |
| 3330 | // unsyncable extensions are blocked. |
| 3331 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3332 | // Test updating a pending extension for one that is not pending. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3333 | TEST_F(ExtensionServiceTest, UpdatePendingExtensionNotPending) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3334 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3335 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3336 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 3337 | UpdateExtension(kGoodId, path, UPDATED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3338 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3339 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | // Test updating a pending extension for one that is already |
| 3343 | // installed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3344 | TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3345 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3346 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3347 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3348 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3349 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3350 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3351 | EXPECT_FALSE(good->is_theme()); |
| 3352 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3353 | // Use AddExtensionImpl() as AddFrom*() would balk. |
| 3354 | service_->pending_extension_manager()->AddExtensionImpl( |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 3355 | good->id(), extensions::ManifestURL::GetUpdateURL(good), |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 3356 | Version(), &IsExtension, kGoodIsFromSync, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 3357 | kGoodInstallSilently, Manifest::INTERNAL, |
| 3358 | Extension::NO_FLAGS, false); |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3359 | UpdateExtension(good->id(), path, ENABLED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3360 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3361 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 3362 | } |
| 3363 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3364 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3365 | // Tests blacklisting then unblacklisting extensions after the service has been |
| 3366 | // initialized. |
[email protected] | 7d9b4e3 | 2013-10-25 06:11:54 | [diff] [blame] | 3367 | TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3368 | extensions::TestBlacklist test_blacklist; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3369 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3370 | InitializeGoodInstalledExtensionService(); |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3371 | test_blacklist.Attach(service_->blacklist_); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3372 | service_->Init(); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3373 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3374 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
| 3375 | const extensions::ExtensionSet& enabled_extensions = |
| 3376 | registry->enabled_extensions(); |
| 3377 | const extensions::ExtensionSet& blacklisted_extensions = |
| 3378 | registry->blacklisted_extensions(); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3379 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3380 | EXPECT_TRUE(enabled_extensions.Contains(good0) && |
| 3381 | !blacklisted_extensions.Contains(good0)); |
| 3382 | EXPECT_TRUE(enabled_extensions.Contains(good1) && |
| 3383 | !blacklisted_extensions.Contains(good1)); |
| 3384 | EXPECT_TRUE(enabled_extensions.Contains(good2) && |
| 3385 | !blacklisted_extensions.Contains(good2)); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3386 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3387 | EXPECT_FALSE(IsPrefExist(good0, "blacklist")); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3388 | EXPECT_FALSE(IsPrefExist(good1, "blacklist")); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3389 | EXPECT_FALSE(IsPrefExist(good2, "blacklist")); |
| 3390 | EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
| 3391 | |
| 3392 | // Blacklist good0 and good1 (and an invalid extension ID). |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3393 | test_blacklist.SetBlacklistState( |
| 3394 | good0, extensions::BLACKLISTED_MALWARE, true); |
| 3395 | test_blacklist.SetBlacklistState( |
| 3396 | good1, extensions::BLACKLISTED_MALWARE, true); |
| 3397 | test_blacklist.SetBlacklistState( |
| 3398 | "invalid_id", extensions::BLACKLISTED_MALWARE, true); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3399 | base::RunLoop().RunUntilIdle(); |
| 3400 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3401 | EXPECT_TRUE(!enabled_extensions.Contains(good0) && |
| 3402 | blacklisted_extensions.Contains(good0)); |
| 3403 | EXPECT_TRUE(!enabled_extensions.Contains(good1) && |
| 3404 | blacklisted_extensions.Contains(good1)); |
| 3405 | EXPECT_TRUE(enabled_extensions.Contains(good2) && |
| 3406 | !blacklisted_extensions.Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3407 | |
| 3408 | EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); |
| 3409 | EXPECT_TRUE(ValidateBooleanPref(good1, "blacklist", true)); |
| 3410 | EXPECT_FALSE(IsPrefExist(good2, "blacklist")); |
| 3411 | EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
| 3412 | |
| 3413 | // Un-blacklist good1 and blacklist good2. |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3414 | test_blacklist.Clear(false); |
| 3415 | test_blacklist.SetBlacklistState( |
| 3416 | good0, extensions::BLACKLISTED_MALWARE, true); |
| 3417 | test_blacklist.SetBlacklistState( |
| 3418 | good2, extensions::BLACKLISTED_MALWARE, true); |
| 3419 | test_blacklist.SetBlacklistState( |
| 3420 | "invalid_id", extensions::BLACKLISTED_MALWARE, true); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3421 | base::RunLoop().RunUntilIdle(); |
| 3422 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3423 | EXPECT_TRUE(!enabled_extensions.Contains(good0) && |
| 3424 | blacklisted_extensions.Contains(good0)); |
| 3425 | EXPECT_TRUE(enabled_extensions.Contains(good1) && |
| 3426 | !blacklisted_extensions.Contains(good1)); |
| 3427 | EXPECT_TRUE(!enabled_extensions.Contains(good2) && |
| 3428 | blacklisted_extensions.Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3429 | |
| 3430 | EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); |
| 3431 | EXPECT_FALSE(IsPrefExist(good1, "blacklist")); |
| 3432 | EXPECT_TRUE(ValidateBooleanPref(good2, "blacklist", true)); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 3433 | EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3434 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3435 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3436 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3437 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3438 | // Tests trying to install a blacklisted extension. |
[email protected] | e0cbfc4 | 2013-11-07 00:10:10 | [diff] [blame] | 3439 | TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) { |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3440 | scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( |
| 3441 | new FakeSafeBrowsingDatabaseManager(true)); |
| 3442 | Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); |
| 3443 | |
[email protected] | 1747eac0 | 2013-09-23 10:58:42 | [diff] [blame] | 3444 | InitializeEmptyExtensionService(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3445 | service_->Init(); |
[email protected] | 1747eac0 | 2013-09-23 10:58:42 | [diff] [blame] | 3446 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3447 | // After blacklisting good_crx, we cannot install it. |
| 3448 | blacklist_db->SetUnsafe(good_crx).NotifyUpdate(); |
| 3449 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1747eac0 | 2013-09-23 10:58:42 | [diff] [blame] | 3450 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3451 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 3452 | // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't |
| 3453 | // decide to install this silently. Somebody should fix these tests, all |
| 3454 | // 6,000 lines of them. Hah! |
| 3455 | InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3456 | EXPECT_EQ(0u, service_->extensions()->size()); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3457 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3458 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3459 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3460 | #if defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3461 | // Unload blacklisted extension on policy change. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3462 | TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3463 | extensions::TestBlacklist test_blacklist; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3464 | |
| 3465 | // A profile with no extensions installed. |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3466 | InitializeEmptyExtensionService(); |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3467 | test_blacklist.Attach(service_->blacklist_); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3468 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3469 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3470 | |
| 3471 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 3472 | EXPECT_EQ(good_crx, good->id()); |
| 3473 | UpdateExtension(good_crx, path, FAILED_SILENTLY); |
| 3474 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3475 | |
| 3476 | base::ListValue whitelist; |
| 3477 | PrefService* prefs = service_->extension_prefs()->pref_service(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3478 | whitelist.Append(new base::StringValue(good_crx)); |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3479 | prefs->Set(extensions::pref_names::kInstallAllowList, whitelist); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3480 | |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3481 | test_blacklist.SetBlacklistState( |
| 3482 | good_crx, extensions::BLACKLISTED_MALWARE, true); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3483 | base::RunLoop().RunUntilIdle(); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3484 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3485 | // The good_crx is blacklisted and the whitelist doesn't negate it. |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3486 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true)); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3487 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3488 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3489 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3490 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3491 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3492 | // Tests that a blacklisted extension is eventually unloaded on startup, if it |
| 3493 | // wasn't already. |
[email protected] | e0cbfc4 | 2013-11-07 00:10:10 | [diff] [blame] | 3494 | TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3495 | extensions::TestBlacklist test_blacklist; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3496 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3497 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3498 | InitializeGoodInstalledExtensionService(); |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3499 | test_blacklist.Attach(service_->blacklist_); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3500 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3501 | // Blacklist good1 before the service initializes. |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3502 | test_blacklist.SetBlacklistState( |
| 3503 | good1, extensions::BLACKLISTED_MALWARE, false); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3504 | |
| 3505 | // Load extensions. |
| 3506 | service_->Init(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3507 | ASSERT_EQ(3u, loaded_.size()); // hasn't had time to blacklist yet |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3508 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3509 | base::RunLoop().RunUntilIdle(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3510 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3511 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
| 3512 | ASSERT_EQ(1u, registry->blacklisted_extensions().size()); |
| 3513 | ASSERT_EQ(2u, registry->enabled_extensions().size()); |
| 3514 | |
| 3515 | ASSERT_TRUE(registry->enabled_extensions().Contains(good0)); |
| 3516 | ASSERT_TRUE(registry->blacklisted_extensions().Contains(good1)); |
| 3517 | ASSERT_TRUE(registry->enabled_extensions().Contains(good2)); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3518 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3519 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3520 | |
| 3521 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3522 | // Tests extensions blacklisted in prefs on startup; one still blacklisted by |
| 3523 | // safe browsing, the other not. The not-blacklisted one should recover. |
| 3524 | TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3525 | extensions::TestBlacklist test_blacklist; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3526 | |
| 3527 | InitializeGoodInstalledExtensionService(); |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3528 | test_blacklist.Attach(service_->blacklist_); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3529 | service_->extension_prefs()->SetExtensionBlacklisted(good0, true); |
| 3530 | service_->extension_prefs()->SetExtensionBlacklisted(good1, true); |
| 3531 | |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3532 | test_blacklist.SetBlacklistState( |
| 3533 | good1, extensions::BLACKLISTED_MALWARE, false); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3534 | |
| 3535 | service_->Init(); |
| 3536 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3537 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
| 3538 | ASSERT_EQ(2u, registry->blacklisted_extensions().size()); |
| 3539 | ASSERT_EQ(1u, registry->enabled_extensions().size()); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3540 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3541 | ASSERT_TRUE(registry->blacklisted_extensions().Contains(good0)); |
| 3542 | ASSERT_TRUE(registry->blacklisted_extensions().Contains(good1)); |
| 3543 | ASSERT_TRUE(registry->enabled_extensions().Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3544 | |
| 3545 | // Give time for the blacklist to update. |
| 3546 | base::RunLoop().RunUntilIdle(); |
| 3547 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3548 | ASSERT_EQ(1u, registry->blacklisted_extensions().size()); |
| 3549 | ASSERT_EQ(2u, registry->enabled_extensions().size()); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3550 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3551 | ASSERT_TRUE(registry->enabled_extensions().Contains(good0)); |
| 3552 | ASSERT_TRUE(registry->blacklisted_extensions().Contains(good1)); |
| 3553 | ASSERT_TRUE(registry->enabled_extensions().Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3554 | } |
| 3555 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3556 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame^] | 3557 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3558 | // Extension is added to blacklist with BLACKLISTED_POTENTIALLY_UNWANTED state |
| 3559 | // after it is installed. It is then successfully re-enabled by the user. |
| 3560 | TEST_F(ExtensionServiceTest, GreylistedExtensionDisabled) { |
| 3561 | extensions::TestBlacklist test_blacklist; |
| 3562 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3563 | InitializeGoodInstalledExtensionService(); |
| 3564 | test_blacklist.Attach(service_->blacklist_); |
| 3565 | service_->Init(); |
| 3566 | |
| 3567 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
| 3568 | const extensions::ExtensionSet& enabled_extensions = |
| 3569 | registry->enabled_extensions(); |
| 3570 | const extensions::ExtensionSet& disabled_extensions = |
| 3571 | registry->disabled_extensions(); |
| 3572 | |
| 3573 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3574 | EXPECT_TRUE(enabled_extensions.Contains(good1)); |
| 3575 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3576 | |
| 3577 | // Blacklist good0 and good1 (and an invalid extension ID). |
| 3578 | test_blacklist.SetBlacklistState( |
| 3579 | good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); |
| 3580 | test_blacklist.SetBlacklistState( |
| 3581 | good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); |
| 3582 | test_blacklist.SetBlacklistState( |
| 3583 | "invalid_id", extensions::BLACKLISTED_MALWARE, true); |
| 3584 | base::RunLoop().RunUntilIdle(); |
| 3585 | |
| 3586 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3587 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3588 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3589 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3590 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3591 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3592 | |
| 3593 | ValidateIntegerPref( |
| 3594 | good0, "blacklist_state", extensions::BLACKLISTED_CWS_POLICY_VIOLATION); |
| 3595 | ValidateIntegerPref( |
| 3596 | good1, "blacklist_state", extensions::BLACKLISTED_POTENTIALLY_UNWANTED); |
| 3597 | |
| 3598 | // Now user enables good0. |
| 3599 | service_->EnableExtension(good0); |
| 3600 | |
| 3601 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3602 | EXPECT_FALSE(disabled_extensions.Contains(good0)); |
| 3603 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3604 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3605 | |
| 3606 | // Remove extensions from blacklist. |
| 3607 | test_blacklist.SetBlacklistState( |
| 3608 | good0, extensions::NOT_BLACKLISTED, true); |
| 3609 | test_blacklist.SetBlacklistState( |
| 3610 | good1, extensions::NOT_BLACKLISTED, true); |
| 3611 | base::RunLoop().RunUntilIdle(); |
| 3612 | |
| 3613 | // All extensions are enabled. |
| 3614 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3615 | EXPECT_FALSE(disabled_extensions.Contains(good0)); |
| 3616 | EXPECT_TRUE(enabled_extensions.Contains(good1)); |
| 3617 | EXPECT_FALSE(disabled_extensions.Contains(good1)); |
| 3618 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3619 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3620 | } |
| 3621 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3622 | |
| 3623 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3624 | // When extension is removed from greylist, do not re-enable it if it is |
| 3625 | // disabled by user. |
| 3626 | TEST_F(ExtensionServiceTest, GreylistDontEnableManuallyDisabled) { |
| 3627 | extensions::TestBlacklist test_blacklist; |
| 3628 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3629 | InitializeGoodInstalledExtensionService(); |
| 3630 | test_blacklist.Attach(service_->blacklist_); |
| 3631 | service_->Init(); |
| 3632 | |
| 3633 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
| 3634 | const extensions::ExtensionSet& enabled_extensions = |
| 3635 | registry->enabled_extensions(); |
| 3636 | const extensions::ExtensionSet& disabled_extensions = |
| 3637 | registry->disabled_extensions(); |
| 3638 | |
| 3639 | // Manually disable. |
| 3640 | service_->DisableExtension(good0, extensions::Extension::DISABLE_USER_ACTION); |
| 3641 | |
| 3642 | test_blacklist.SetBlacklistState( |
| 3643 | good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); |
| 3644 | test_blacklist.SetBlacklistState( |
| 3645 | good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); |
| 3646 | test_blacklist.SetBlacklistState( |
| 3647 | good2, extensions::BLACKLISTED_SECURITY_VULNERABILITY, true); |
| 3648 | base::RunLoop().RunUntilIdle(); |
| 3649 | |
| 3650 | // All extensions disabled. |
| 3651 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3652 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3653 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3654 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3655 | EXPECT_FALSE(enabled_extensions.Contains(good2)); |
| 3656 | EXPECT_TRUE(disabled_extensions.Contains(good2)); |
| 3657 | |
| 3658 | // Greylisted extension can be enabled. |
| 3659 | service_->EnableExtension(good1); |
| 3660 | EXPECT_TRUE(enabled_extensions.Contains(good1)); |
| 3661 | EXPECT_FALSE(disabled_extensions.Contains(good1)); |
| 3662 | |
| 3663 | // good1 is now manually disabled. |
| 3664 | service_->DisableExtension(good1, extensions::Extension::DISABLE_USER_ACTION); |
| 3665 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3666 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3667 | |
| 3668 | // Remove extensions from blacklist. |
| 3669 | test_blacklist.SetBlacklistState( |
| 3670 | good0, extensions::NOT_BLACKLISTED, true); |
| 3671 | test_blacklist.SetBlacklistState( |
| 3672 | good1, extensions::NOT_BLACKLISTED, true); |
| 3673 | test_blacklist.SetBlacklistState( |
| 3674 | good2, extensions::NOT_BLACKLISTED, true); |
| 3675 | base::RunLoop().RunUntilIdle(); |
| 3676 | |
| 3677 | // good0 and good1 remain disabled. |
| 3678 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3679 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3680 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3681 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3682 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3683 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3684 | } |
| 3685 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3686 | |
| 3687 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3688 | // Blacklisted extension with unknown state are not enabled/disabled. |
| 3689 | TEST_F(ExtensionServiceTest, GreylistUnknownDontChange) { |
| 3690 | extensions::TestBlacklist test_blacklist; |
| 3691 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3692 | InitializeGoodInstalledExtensionService(); |
| 3693 | test_blacklist.Attach(service_->blacklist_); |
| 3694 | service_->Init(); |
| 3695 | |
| 3696 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
| 3697 | const extensions::ExtensionSet& enabled_extensions = |
| 3698 | registry->enabled_extensions(); |
| 3699 | const extensions::ExtensionSet& disabled_extensions = |
| 3700 | registry->disabled_extensions(); |
| 3701 | |
| 3702 | test_blacklist.SetBlacklistState( |
| 3703 | good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); |
| 3704 | test_blacklist.SetBlacklistState( |
| 3705 | good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); |
| 3706 | base::RunLoop().RunUntilIdle(); |
| 3707 | |
| 3708 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3709 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3710 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3711 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3712 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3713 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3714 | |
| 3715 | test_blacklist.SetBlacklistState( |
| 3716 | good0, extensions::NOT_BLACKLISTED, true); |
| 3717 | test_blacklist.SetBlacklistState( |
| 3718 | good1, extensions::BLACKLISTED_UNKNOWN, true); |
| 3719 | test_blacklist.SetBlacklistState( |
| 3720 | good2, extensions::BLACKLISTED_UNKNOWN, true); |
| 3721 | base::RunLoop().RunUntilIdle(); |
| 3722 | |
| 3723 | // good0 re-enabled, other remain as they were. |
| 3724 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3725 | EXPECT_FALSE(disabled_extensions.Contains(good0)); |
| 3726 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3727 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3728 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3729 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3730 | } |
| 3731 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3732 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3733 | // Will not install extension blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3734 | TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3735 | InitializeEmptyExtensionService(); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3736 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3737 | // Blacklist everything. |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3738 | { |
| 3739 | ListPrefUpdate update(profile_->GetPrefs(), |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3740 | extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3741 | base::ListValue* blacklist = update.Get(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3742 | blacklist->Append(new base::StringValue("*")); |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3743 | } |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3744 | |
| 3745 | // Blacklist prevents us from installing good_crx. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3746 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3747 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3748 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3749 | |
| 3750 | // Now whitelist this particular extension. |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3751 | { |
| 3752 | ListPrefUpdate update(profile_->GetPrefs(), |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3753 | extensions::pref_names::kInstallAllowList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3754 | base::ListValue* whitelist = update.Get(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3755 | whitelist->Append(new base::StringValue(good_crx)); |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3756 | } |
| 3757 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3758 | // Ensure we can now install good_crx. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3759 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3760 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3761 | } |
| 3762 | |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3763 | // Extension blacklisted by policy get unloaded after installing. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3764 | TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3765 | InitializeEmptyExtensionService(); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3766 | |
| 3767 | // Install good_crx. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3768 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3769 | InstallCRX(path, INSTALL_NEW); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3770 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3771 | |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3772 | { // Scope for pref update notification. |
| 3773 | PrefService* prefs = profile_->GetPrefs(); |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3774 | ListPrefUpdate update(prefs, extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3775 | base::ListValue* blacklist = update.Get(); |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3776 | ASSERT_TRUE(blacklist != NULL); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3777 | |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3778 | // Blacklist this extension. |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3779 | blacklist->Append(new base::StringValue(good_crx)); |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3780 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3781 | |
| 3782 | // Extension should not be running now. |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3783 | base::RunLoop().RunUntilIdle(); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3784 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3785 | } |
| 3786 | |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3787 | // Tests that component extensions are not blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3788 | TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3789 | InitializeEmptyExtensionService(); |
| 3790 | |
| 3791 | // Blacklist everything. |
| 3792 | { |
| 3793 | ListPrefUpdate update(profile_->GetPrefs(), |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3794 | extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3795 | base::ListValue* blacklist = update.Get(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3796 | blacklist->Append(new base::StringValue("*")); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | // Install a component extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3800 | base::FilePath path = data_dir_ |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3801 | .AppendASCII("good") |
| 3802 | .AppendASCII("Extensions") |
| 3803 | .AppendASCII(good0) |
| 3804 | .AppendASCII("1.0.0.0"); |
| 3805 | std::string manifest; |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 3806 | ASSERT_TRUE(base::ReadFileToString( |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 3807 | path.Append(extensions::kManifestFilename), &manifest)); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 3808 | service_->component_loader()->Add(manifest, path); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3809 | service_->Init(); |
| 3810 | |
| 3811 | // Extension should be installed despite blacklist. |
| 3812 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3813 | EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3814 | |
| 3815 | // Poke external providers and make sure the extension is still present. |
| 3816 | service_->CheckForExternalUpdates(); |
| 3817 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3818 | EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3819 | |
| 3820 | // Extension should not be uninstalled on blacklist changes. |
| 3821 | { |
| 3822 | ListPrefUpdate update(profile_->GetPrefs(), |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3823 | extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3824 | base::ListValue* blacklist = update.Get(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3825 | blacklist->Append(new base::StringValue(good0)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3826 | } |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3827 | base::RunLoop().RunUntilIdle(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3828 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3829 | EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | // Tests that policy-installed extensions are not blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3833 | TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3834 | InitializeEmptyExtensionService(); |
| 3835 | |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3836 | { |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 3837 | // Blacklist everything. |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3838 | ListPrefUpdate blacklist_update( |
| 3839 | profile_->GetPrefs(), extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3840 | base::ListValue* blacklist = blacklist_update.Get(); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 3841 | blacklist->AppendString("*"); |
| 3842 | |
| 3843 | // Mark good.crx for force-installation. |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3844 | DictionaryPrefUpdate forcelist_update( |
| 3845 | profile_->GetPrefs(), |
| 3846 | extensions::pref_names::kInstallForceList); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 3847 | extensions::ExternalPolicyLoader::AddExtension( |
| 3848 | forcelist_update.Get(), good_crx, "http://example.com/update_url"); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | // Have policy force-install an extension. |
| 3852 | MockExtensionProvider* provider = |
| 3853 | new MockExtensionProvider(service_, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3854 | Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3855 | AddMockExternalProvider(provider); |
| 3856 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 3857 | data_dir_.AppendASCII("good.crx")); |
| 3858 | |
| 3859 | // Reloading extensions should find our externally registered extension |
| 3860 | // and install it. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 3861 | content::WindowedNotificationObserver observer( |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 3862 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 3863 | content::NotificationService::AllSources()); |
| 3864 | service_->CheckForExternalUpdates(); |
| 3865 | observer.Wait(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3866 | |
| 3867 | // Extension should be installed despite blacklist. |
| 3868 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3869 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3870 | |
| 3871 | // Blacklist update should not uninstall the extension. |
| 3872 | { |
| 3873 | ListPrefUpdate update(profile_->GetPrefs(), |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 3874 | extensions::pref_names::kInstallDenyList); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3875 | base::ListValue* blacklist = update.Get(); |
[email protected] | aa15e2e | 2013-08-14 02:13:58 | [diff] [blame] | 3876 | blacklist->Append(new base::StringValue(good0)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3877 | } |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 3878 | base::RunLoop().RunUntilIdle(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3879 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3880 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3881 | } |
| 3882 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3883 | // Tests that extensions cannot be installed if the policy provider prohibits |
| 3884 | // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3885 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3886 | InitializeEmptyExtensionService(); |
| 3887 | |
| 3888 | management_policy_->UnregisterAllProviders(); |
| 3889 | extensions::TestManagementPolicyProvider provider_( |
| 3890 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
| 3891 | management_policy_->RegisterProvider(&provider_); |
| 3892 | |
| 3893 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_FAILED); |
| 3894 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3895 | } |
| 3896 | |
| 3897 | // Tests that extensions cannot be loaded from prefs if the policy provider |
| 3898 | // prohibits it. This functionality is implemented in InstalledLoader::Load(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3899 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3900 | InitializeEmptyExtensionService(); |
| 3901 | |
| 3902 | // Create a fake extension to be loaded as though it were read from prefs. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3903 | base::FilePath path = data_dir_.AppendASCII("management") |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3904 | .AppendASCII("simple_extension"); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3905 | base::DictionaryValue manifest; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3906 | manifest.SetString(keys::kName, "simple_extension"); |
| 3907 | manifest.SetString(keys::kVersion, "1"); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 3908 | // UNPACKED is for extensions loaded from a directory. We use it here, even |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3909 | // though we're testing loading from prefs, so that we don't need to provide |
| 3910 | // an extension key. |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 3911 | extensions::ExtensionInfo extension_info( |
| 3912 | &manifest, std::string(), path, Manifest::UNPACKED); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3913 | |
| 3914 | // Ensure we can load it with no management policy in place. |
| 3915 | management_policy_->UnregisterAllProviders(); |
| 3916 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3917 | extensions::InstalledLoader(service_).Load(extension_info, false); |
| 3918 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3919 | |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 3920 | const Extension* extension = (service_->extensions()->begin())->get(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3921 | EXPECT_TRUE(service_->UninstallExtension(extension->id(), false, NULL)); |
| 3922 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3923 | |
| 3924 | // Ensure we cannot load it if management policy prohibits installation. |
| 3925 | extensions::TestManagementPolicyProvider provider_( |
| 3926 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
| 3927 | management_policy_->RegisterProvider(&provider_); |
| 3928 | |
| 3929 | extensions::InstalledLoader(service_).Load(extension_info, false); |
| 3930 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3931 | } |
| 3932 | |
| 3933 | // Tests disabling an extension when prohibited by the ManagementPolicy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3934 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3935 | InitializeEmptyExtensionService(); |
| 3936 | |
| 3937 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3938 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3939 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3940 | |
| 3941 | management_policy_->UnregisterAllProviders(); |
| 3942 | extensions::TestManagementPolicyProvider provider( |
| 3943 | extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
| 3944 | management_policy_->RegisterProvider(&provider); |
| 3945 | |
| 3946 | // Attempt to disable it. |
| 3947 | service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
| 3948 | |
| 3949 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3950 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3951 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3952 | } |
| 3953 | |
| 3954 | // Tests uninstalling an extension when prohibited by the ManagementPolicy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3955 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3956 | InitializeEmptyExtensionService(); |
| 3957 | |
| 3958 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3959 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3960 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3961 | |
| 3962 | management_policy_->UnregisterAllProviders(); |
| 3963 | extensions::TestManagementPolicyProvider provider( |
| 3964 | extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
| 3965 | management_policy_->RegisterProvider(&provider); |
| 3966 | |
| 3967 | // Attempt to uninstall it. |
| 3968 | EXPECT_FALSE(service_->UninstallExtension(good_crx, false, NULL)); |
| 3969 | |
| 3970 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3971 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3972 | } |
| 3973 | |
| 3974 | // Tests that previously installed extensions that are now prohibited from |
| 3975 | // being installed are removed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3976 | TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3977 | InitializeEmptyExtensionService(); |
| 3978 | |
| 3979 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3980 | InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); |
| 3981 | EXPECT_EQ(2u, service_->extensions()->size()); |
| 3982 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3983 | |
| 3984 | management_policy_->UnregisterAllProviders(); |
| 3985 | extensions::TestManagementPolicyProvider provider( |
| 3986 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
| 3987 | management_policy_->RegisterProvider(&provider); |
| 3988 | |
| 3989 | // Run the policy check. |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3990 | service_->CheckManagementPolicy(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3991 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3992 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3993 | } |
| 3994 | |
| 3995 | // Tests that previously disabled extensions that are now required to be |
| 3996 | // enabled are re-enabled on reinstall. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3997 | TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3998 | InitializeEmptyExtensionService(); |
| 3999 | |
| 4000 | // Install, then disable, an extension. |
| 4001 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 4002 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 4003 | service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
| 4004 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 4005 | |
| 4006 | // Register an ExtensionMnagementPolicy that requires the extension to remain |
| 4007 | // enabled. |
| 4008 | management_policy_->UnregisterAllProviders(); |
| 4009 | extensions::TestManagementPolicyProvider provider( |
| 4010 | extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED); |
| 4011 | management_policy_->RegisterProvider(&provider); |
| 4012 | |
| 4013 | // Reinstall the extension. |
| 4014 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_UPDATED); |
| 4015 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 4016 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 4017 | } |
| 4018 | |
[email protected] | ebc3aec | 2013-10-22 02:39:17 | [diff] [blame] | 4019 | // Flaky on windows; http://crbug.com/309833 |
| 4020 | #if defined(OS_WIN) |
| 4021 | #define MAYBE_ExternalExtensionAutoAcknowledgement DISABLED_ExternalExtensionAutoAcknowledgement |
| 4022 | #else |
| 4023 | #define MAYBE_ExternalExtensionAutoAcknowledgement ExternalExtensionAutoAcknowledgement |
| 4024 | #endif |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4025 | TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) { |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 4026 | InitializeEmptyExtensionService(); |
| 4027 | set_extensions_enabled(true); |
| 4028 | |
| 4029 | { |
| 4030 | // Register and install an external extension. |
| 4031 | MockExtensionProvider* provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4032 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 4033 | AddMockExternalProvider(provider); |
| 4034 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 4035 | data_dir_.AppendASCII("good.crx")); |
| 4036 | } |
| 4037 | { |
| 4038 | // Have policy force-install an extension. |
| 4039 | MockExtensionProvider* provider = |
| 4040 | new MockExtensionProvider(service_, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4041 | Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 4042 | AddMockExternalProvider(provider); |
| 4043 | provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 4044 | data_dir_.AppendASCII("page_action.crx")); |
| 4045 | } |
| 4046 | |
| 4047 | // Providers are set up. Let them run. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4048 | int count = 2; |
| 4049 | content::WindowedNotificationObserver observer( |
| 4050 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 4051 | base::Bind(&WaitForCountNotificationsCallback, &count)); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 4052 | service_->CheckForExternalUpdates(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 4053 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4054 | observer.Wait(); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 4055 | |
| 4056 | ASSERT_EQ(2u, service_->extensions()->size()); |
| 4057 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 4058 | EXPECT_TRUE(service_->GetExtensionById(page_action, false)); |
| 4059 | ExtensionPrefs* prefs = service_->extension_prefs(); |
| 4060 | ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); |
| 4061 | ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); |
| 4062 | } |
| 4063 | |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4064 | #if !defined(OS_CHROMEOS) |
| 4065 | // This tests if default apps are installed correctly. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4066 | TEST_F(ExtensionServiceTest, DefaultAppsInstall) { |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4067 | InitializeEmptyExtensionService(); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4068 | set_extensions_enabled(true); |
| 4069 | |
| 4070 | { |
| 4071 | std::string json_data = |
| 4072 | "{" |
| 4073 | " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {" |
| 4074 | " \"external_crx\": \"good.crx\"," |
| 4075 | " \"external_version\": \"1.0.0.0\"," |
| 4076 | " \"is_bookmark_app\": false" |
| 4077 | " }" |
| 4078 | "}"; |
| 4079 | default_apps::Provider* provider = |
| 4080 | new default_apps::Provider( |
| 4081 | profile_.get(), |
| 4082 | service_, |
| 4083 | new extensions::ExternalTestingLoader(json_data, data_dir_), |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4084 | Manifest::INTERNAL, |
| 4085 | Manifest::INVALID_LOCATION, |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4086 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
| 4087 | |
| 4088 | AddMockExternalProvider(provider); |
| 4089 | } |
| 4090 | |
| 4091 | ASSERT_EQ(0u, service_->extensions()->size()); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4092 | content::WindowedNotificationObserver observer( |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 4093 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4094 | content::NotificationService::AllSources()); |
| 4095 | service_->CheckForExternalUpdates(); |
| 4096 | observer.Wait(); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4097 | |
| 4098 | ASSERT_EQ(1u, service_->extensions()->size()); |
| 4099 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 4100 | const Extension* extension = service_->GetExtensionById(good_crx, false); |
| 4101 | EXPECT_TRUE(extension->from_webstore()); |
| 4102 | EXPECT_TRUE(extension->was_installed_by_default()); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4103 | } |
| 4104 | #endif |
| 4105 | |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4106 | // Tests disabling extensions |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4107 | TEST_F(ExtensionServiceTest, DisableExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4108 | InitializeEmptyExtensionService(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4109 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4110 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4111 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 4112 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 4113 | |
| 4114 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
| 4115 | EXPECT_EQ(1u, registry->enabled_extensions().size()); |
| 4116 | EXPECT_EQ(0u, registry->disabled_extensions().size()); |
| 4117 | EXPECT_EQ(0u, registry->terminated_extensions().size()); |
| 4118 | EXPECT_EQ(0u, registry->blacklisted_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4119 | |
| 4120 | // Disable it. |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 4121 | service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4122 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4123 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 4124 | EXPECT_FALSE(service_->GetExtensionById(good_crx, false)); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 4125 | EXPECT_EQ(0u, registry->enabled_extensions().size()); |
| 4126 | EXPECT_EQ(1u, registry->disabled_extensions().size()); |
| 4127 | EXPECT_EQ(0u, registry->terminated_extensions().size()); |
| 4128 | EXPECT_EQ(0u, registry->blacklisted_extensions().size()); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4129 | } |
| 4130 | |
| 4131 | TEST_F(ExtensionServiceTest, TerminateExtension) { |
| 4132 | InitializeEmptyExtensionService(); |
| 4133 | |
| 4134 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 4135 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
| 4136 | EXPECT_EQ(1u, registry->enabled_extensions().size()); |
| 4137 | EXPECT_EQ(0u, registry->disabled_extensions().size()); |
| 4138 | EXPECT_EQ(0u, registry->terminated_extensions().size()); |
| 4139 | EXPECT_EQ(0u, registry->blacklisted_extensions().size()); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4140 | |
| 4141 | TerminateExtension(good_crx); |
| 4142 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 4143 | EXPECT_EQ(0u, registry->enabled_extensions().size()); |
| 4144 | EXPECT_EQ(0u, registry->disabled_extensions().size()); |
| 4145 | EXPECT_EQ(1u, registry->terminated_extensions().size()); |
| 4146 | EXPECT_EQ(0u, registry->blacklisted_extensions().size()); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4147 | } |
| 4148 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4149 | TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4150 | InitializeEmptyExtensionService(); |
| 4151 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4152 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4153 | TerminateExtension(good_crx); |
| 4154 | EXPECT_TRUE(service_->GetTerminatedExtension(good_crx)); |
| 4155 | |
| 4156 | // Disable it. |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 4157 | service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4158 | |
| 4159 | EXPECT_FALSE(service_->GetTerminatedExtension(good_crx)); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4160 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4161 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 4162 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
| 4163 | EXPECT_EQ(0u, registry->enabled_extensions().size()); |
| 4164 | EXPECT_EQ(1u, registry->disabled_extensions().size()); |
| 4165 | EXPECT_EQ(0u, registry->terminated_extensions().size()); |
| 4166 | EXPECT_EQ(0u, registry->blacklisted_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4167 | } |
| 4168 | |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4169 | // Tests disabling all extensions (simulating --disable-extensions flag). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4170 | TEST_F(ExtensionServiceTest, DisableAllExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4171 | InitializeEmptyExtensionService(); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4172 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4173 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4174 | InstallCRX(path, INSTALL_NEW); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4175 | |
| 4176 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 4177 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 4178 | |
| 4179 | // Disable extensions. |
| 4180 | service_->set_extensions_enabled(false); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4181 | service_->ReloadExtensionsForTest(); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4182 | |
| 4183 | // There shouldn't be extensions in either list. |
| 4184 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 4185 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 4186 | |
| 4187 | // This shouldn't do anything when all extensions are disabled. |
| 4188 | service_->EnableExtension(good_crx); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4189 | service_->ReloadExtensionsForTest(); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4190 | |
| 4191 | // There still shouldn't be extensions in either list. |
| 4192 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 4193 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 4194 | |
| 4195 | // And then re-enable the extensions. |
| 4196 | service_->set_extensions_enabled(true); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4197 | service_->ReloadExtensionsForTest(); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4198 | |
| 4199 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 4200 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 4201 | } |
| 4202 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4203 | // Tests reloading extensions. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4204 | TEST_F(ExtensionServiceTest, ReloadExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4205 | InitializeEmptyExtensionService(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4206 | |
| 4207 | // Simple extension that should install without error. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4208 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 4209 | InstallCRX(path, INSTALL_NEW, |
| 4210 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4211 | const char* extension_id = good_crx; |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 4212 | service_->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4213 | |
| 4214 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 4215 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 4216 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4217 | service_->ReloadExtensionsForTest(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4218 | |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 4219 | // The creation flags should not change when reloading the extension. |
| 4220 | const Extension* extension = service_->GetExtensionById(good_crx, true); |
| 4221 | EXPECT_TRUE(extension->from_webstore()); |
| 4222 | EXPECT_TRUE(extension->was_installed_by_default()); |
| 4223 | EXPECT_FALSE(extension->from_bookmark()); |
| 4224 | |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4225 | // Extension counts shouldn't change. |
| 4226 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 4227 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 4228 | |
| 4229 | service_->EnableExtension(extension_id); |
| 4230 | |
| 4231 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 4232 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 4233 | |
[email protected] | 5a73f90 | 2010-06-30 02:29:41 | [diff] [blame] | 4234 | // Need to clear |loaded_| manually before reloading as the |
| 4235 | // EnableExtension() call above inserted into it and |
| 4236 | // UnloadAllExtensions() doesn't send out notifications. |
| 4237 | loaded_.clear(); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4238 | service_->ReloadExtensionsForTest(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4239 | |
| 4240 | // Extension counts shouldn't change. |
| 4241 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 4242 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 4243 | } |
| 4244 | |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4245 | // Tests reloading an extension. |
| 4246 | TEST_F(ExtensionServiceTest, ReloadExtension) { |
| 4247 | InitializeEmptyExtensionService(); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 4248 | InitializeProcessManager(); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4249 | |
| 4250 | // Simple extension that should install without error. |
| 4251 | const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 4252 | base::FilePath ext = data_dir_ |
| 4253 | .AppendASCII("good") |
| 4254 | .AppendASCII("Extensions") |
| 4255 | .AppendASCII(extension_id) |
| 4256 | .AppendASCII("1.0.0.0"); |
| 4257 | extensions::UnpackedInstaller::Create(service_)->Load(ext); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4258 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4259 | |
| 4260 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 4261 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 4262 | |
| 4263 | service_->ReloadExtension(extension_id); |
| 4264 | |
| 4265 | // Extension should be disabled now, waiting to be reloaded. |
| 4266 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 4267 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 4268 | EXPECT_EQ(Extension::DISABLE_RELOAD, |
| 4269 | service_->extension_prefs()->GetDisableReasons(extension_id)); |
| 4270 | |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 4271 | // Reloading again should not crash. |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4272 | service_->ReloadExtension(extension_id); |
| 4273 | |
| 4274 | // Finish reloading |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4275 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4276 | |
| 4277 | // Extension should be enabled again. |
| 4278 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 4279 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 4280 | } |
| 4281 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4282 | TEST_F(ExtensionServiceTest, UninstallExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4283 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4284 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 4285 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4286 | UninstallExtension(good_crx, false); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 4287 | EXPECT_EQ(0u, service_->extensions()->size()); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4288 | } |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 4289 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4290 | TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4291 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4292 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4293 | TerminateExtension(good_crx); |
| 4294 | UninstallExtension(good_crx, false); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 4295 | } |
| 4296 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 4297 | // Tests the uninstaller helper. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4298 | TEST_F(ExtensionServiceTest, UninstallExtensionHelper) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4299 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4300 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4301 | UninstallExtension(good_crx, true); |
| 4302 | } |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 4303 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4304 | TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4305 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4306 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4307 | TerminateExtension(good_crx); |
| 4308 | UninstallExtension(good_crx, true); |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 4309 | } |
| 4310 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4311 | // An extension disabled because of unsupported requirements should re-enabled |
| 4312 | // if updated to a version with supported requirements as long as there are no |
| 4313 | // other disable reasons. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4314 | TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4315 | InitializeEmptyExtensionService(); |
| 4316 | BlackListWebGL(); |
| 4317 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4318 | base::FilePath path = data_dir_.AppendASCII("requirements"); |
| 4319 | base::FilePath pem_path = data_dir_.AppendASCII("requirements") |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4320 | .AppendASCII("v1_good.pem"); |
| 4321 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 4322 | pem_path, |
| 4323 | INSTALL_NEW); |
| 4324 | std::string id = extension_v1->id(); |
| 4325 | EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 4326 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4327 | base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4328 | |
| 4329 | PackCRX(path.AppendASCII("v2_bad_requirements"), |
| 4330 | pem_path, |
| 4331 | v2_bad_requirements_crx); |
| 4332 | UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4333 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 4334 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4335 | base::FilePath v3_good_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4336 | |
| 4337 | PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); |
| 4338 | UpdateExtension(id, v3_good_crx, ENABLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4339 | EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 4340 | } |
| 4341 | |
| 4342 | // Extensions disabled through user action should stay disabled. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4343 | TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4344 | InitializeEmptyExtensionService(); |
| 4345 | BlackListWebGL(); |
| 4346 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4347 | base::FilePath path = data_dir_.AppendASCII("requirements"); |
| 4348 | base::FilePath pem_path = data_dir_.AppendASCII("requirements") |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4349 | .AppendASCII("v1_good.pem"); |
| 4350 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 4351 | pem_path, |
| 4352 | INSTALL_NEW); |
| 4353 | std::string id = extension_v1->id(); |
| 4354 | service_->DisableExtension(id, Extension::DISABLE_USER_ACTION); |
| 4355 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 4356 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4357 | base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4358 | |
| 4359 | PackCRX(path.AppendASCII("v2_bad_requirements"), |
| 4360 | pem_path, |
| 4361 | v2_bad_requirements_crx); |
| 4362 | UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4363 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 4364 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4365 | base::FilePath v3_good_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4366 | |
| 4367 | PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); |
| 4368 | UpdateExtension(id, v3_good_crx, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4369 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 4370 | } |
| 4371 | |
| 4372 | // The extension should not re-enabled because it was disabled from a |
| 4373 | // permission increase. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4374 | TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4375 | InitializeEmptyExtensionService(); |
| 4376 | BlackListWebGL(); |
| 4377 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4378 | base::FilePath path = data_dir_.AppendASCII("requirements"); |
| 4379 | base::FilePath pem_path = data_dir_.AppendASCII("requirements") |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4380 | .AppendASCII("v1_good.pem"); |
| 4381 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 4382 | pem_path, |
| 4383 | INSTALL_NEW); |
| 4384 | std::string id = extension_v1->id(); |
| 4385 | EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 4386 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4387 | base::FilePath v2_bad_requirements_and_permissions_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4388 | |
| 4389 | PackCRX(path.AppendASCII("v2_bad_requirements_and_permissions"), |
| 4390 | pem_path, |
| 4391 | v2_bad_requirements_and_permissions_crx); |
| 4392 | UpdateExtension(id, v2_bad_requirements_and_permissions_crx, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4393 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 4394 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4395 | base::FilePath v3_bad_permissions_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4396 | |
| 4397 | PackCRX(path.AppendASCII("v3_bad_permissions"), |
| 4398 | pem_path, |
| 4399 | v3_bad_permissions_crx); |
| 4400 | UpdateExtension(id, v3_bad_permissions_crx, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4401 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 4402 | } |
| 4403 | |
| 4404 | // Unpacked extensions are not allowed to be installed if they have unsupported |
| 4405 | // requirements. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4406 | TEST_F(ExtensionServiceTest, UnpackedRequirements) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4407 | InitializeEmptyExtensionService(); |
| 4408 | BlackListWebGL(); |
| 4409 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4410 | base::FilePath path = data_dir_.AppendASCII("requirements") |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4411 | .AppendASCII("v2_bad_requirements"); |
| 4412 | extensions::UnpackedInstaller::Create(service_)->Load(path); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4413 | base::RunLoop().RunUntilIdle(); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4414 | EXPECT_EQ(1u, GetErrors().size()); |
| 4415 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 4416 | } |
| 4417 | |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4418 | class ExtensionCookieCallback { |
| 4419 | public: |
| 4420 | ExtensionCookieCallback() |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 4421 | : result_(false), |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 4422 | weak_factory_(base::MessageLoop::current()) {} |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4423 | |
| 4424 | void SetCookieCallback(bool result) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 4425 | base::MessageLoop::current()->PostTask(FROM_HERE, |
| 4426 | base::Bind(&base::MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4427 | result_ = result; |
| 4428 | } |
| 4429 | |
| 4430 | void GetAllCookiesCallback(const net::CookieList& list) { |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 4431 | base::MessageLoop::current()->PostTask(FROM_HERE, |
| 4432 | base::Bind(&base::MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4433 | list_ = list; |
| 4434 | } |
| 4435 | net::CookieList list_; |
| 4436 | bool result_; |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 4437 | base::WeakPtrFactory<base::MessageLoop> weak_factory_; |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4438 | }; |
| 4439 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4440 | // Verifies extension state is removed upon uninstall. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4441 | TEST_F(ExtensionServiceTest, ClearExtensionData) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4442 | InitializeEmptyExtensionService(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4443 | ExtensionCookieCallback callback; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4444 | |
| 4445 | // Load a test extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4446 | base::FilePath path = data_dir_; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4447 | path = path.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4448 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4449 | ASSERT_TRUE(extension); |
| 4450 | GURL ext_url(extension->url()); |
[email protected] | 2a9644c | 2013-06-19 06:19:34 | [diff] [blame] | 4451 | std::string origin_id = webkit_database::GetIdentifierFromOrigin(ext_url); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4452 | |
| 4453 | // Set a cookie for the extension. |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 4454 | net::CookieMonster* cookie_monster = |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 4455 | profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> |
| 4456 | cookie_store()->GetCookieMonster(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4457 | ASSERT_TRUE(cookie_monster); |
| 4458 | net::CookieOptions options; |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4459 | cookie_monster->SetCookieWithOptionsAsync( |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 4460 | ext_url, "dummy=value", options, |
| 4461 | base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 4462 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4463 | base::RunLoop().RunUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4464 | EXPECT_TRUE(callback.result_); |
| 4465 | |
| 4466 | cookie_monster->GetAllCookiesForURLAsync( |
| 4467 | ext_url, |
| 4468 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4469 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4470 | base::RunLoop().RunUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4471 | EXPECT_EQ(1U, callback.list_.size()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4472 | |
| 4473 | // Open a database. |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 4474 | webkit_database::DatabaseTracker* db_tracker = |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 4475 | BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 4476 | GetDatabaseTracker(); |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 4477 | base::string16 db_name = base::UTF8ToUTF16("db"); |
| 4478 | base::string16 description = base::UTF8ToUTF16("db_description"); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4479 | int64 size; |
[email protected] | 7c5f2ec | 2011-05-26 19:15:26 | [diff] [blame] | 4480 | db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4481 | db_tracker->DatabaseClosed(origin_id, db_name); |
| 4482 | std::vector<webkit_database::OriginInfo> origins; |
| 4483 | db_tracker->GetAllOriginsInfo(&origins); |
| 4484 | EXPECT_EQ(1U, origins.size()); |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 4485 | EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4486 | |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 4487 | // Create local storage. We only simulate this by creating the backing files. |
| 4488 | // Note: This test depends on details of how the dom_storage library |
| 4489 | // stores data in the host file system. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4490 | base::FilePath lso_dir_path = |
| 4491 | profile_->GetPath().AppendASCII("Local Storage"); |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 4492 | base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) |
| 4493 | .AddExtension(FILE_PATH_LITERAL(".localstorage")); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4494 | EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 4495 | EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4496 | EXPECT_TRUE(base::PathExists(lso_file_path)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4497 | |
[email protected] | ab30809 | 2011-08-25 23:37:19 | [diff] [blame] | 4498 | // Create indexed db. Similarly, it is enough to only simulate this by |
| 4499 | // creating the directory on the disk. |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 4500 | IndexedDBContext* idb_context = |
| 4501 | BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 4502 | GetIndexedDBContext(); |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 4503 | idb_context->SetTaskRunnerForTesting( |
[email protected] | 198b590 | 2013-06-27 10:36:11 | [diff] [blame] | 4504 | base::MessageLoop::current()->message_loop_proxy().get()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4505 | base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4506 | EXPECT_TRUE(base::CreateDirectory(idb_path)); |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4507 | EXPECT_TRUE(base::DirectoryExists(idb_path)); |
[email protected] | e1dcf92 | 2010-11-22 19:12:12 | [diff] [blame] | 4508 | |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4509 | // Uninstall the extension. |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 4510 | service_->UninstallExtension(good_crx, false, NULL); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4511 | base::RunLoop().RunUntilIdle(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4512 | |
| 4513 | // Check that the cookie is gone. |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4514 | cookie_monster->GetAllCookiesForURLAsync( |
| 4515 | ext_url, |
| 4516 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4517 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4518 | base::RunLoop().RunUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4519 | EXPECT_EQ(0U, callback.list_.size()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4520 | |
| 4521 | // The database should have vanished as well. |
| 4522 | origins.clear(); |
| 4523 | db_tracker->GetAllOriginsInfo(&origins); |
| 4524 | EXPECT_EQ(0U, origins.size()); |
| 4525 | |
| 4526 | // Check that the LSO file has been removed. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4527 | EXPECT_FALSE(base::PathExists(lso_file_path)); |
[email protected] | e1dcf92 | 2010-11-22 19:12:12 | [diff] [blame] | 4528 | |
| 4529 | // Check if the indexed db has disappeared too. |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4530 | EXPECT_FALSE(base::DirectoryExists(idb_path)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4531 | } |
| 4532 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4533 | // Verifies app state is removed upon uninstall. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4534 | TEST_F(ExtensionServiceTest, ClearAppData) { |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4535 | InitializeEmptyExtensionService(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4536 | ExtensionCookieCallback callback; |
| 4537 | |
| 4538 | int pref_count = 0; |
| 4539 | |
| 4540 | // Install app1 with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4541 | const Extension* extension = |
| 4542 | PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4543 | ValidatePrefKeyCount(++pref_count); |
| 4544 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4545 | const std::string id1 = extension->id(); |
| 4546 | EXPECT_TRUE(extension->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 4547 | APIPermission::kUnlimitedStorage)); |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 4548 | const GURL origin1( |
| 4549 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4550 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 4551 | IsStorageUnlimited(origin1)); |
[email protected] | 2a9644c | 2013-06-19 06:19:34 | [diff] [blame] | 4552 | std::string origin_id = webkit_database::GetIdentifierFromOrigin(origin1); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4553 | |
| 4554 | // Install app2 from the same origin with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4555 | extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4556 | ValidatePrefKeyCount(++pref_count); |
| 4557 | ASSERT_EQ(2u, service_->extensions()->size()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4558 | const std::string id2 = extension->id(); |
| 4559 | EXPECT_TRUE(extension->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 4560 | APIPermission::kUnlimitedStorage)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4561 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 4562 | extensions::AppLaunchInfo::GetFullLaunchURL(extension))); |
| 4563 | const GURL origin2( |
| 4564 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4565 | EXPECT_EQ(origin1, origin2); |
| 4566 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 4567 | IsStorageUnlimited(origin2)); |
| 4568 | |
| 4569 | // Set a cookie for the extension. |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 4570 | net::CookieMonster* cookie_monster = |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 4571 | profile_->GetRequestContext()->GetURLRequestContext()-> |
| 4572 | cookie_store()->GetCookieMonster(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4573 | ASSERT_TRUE(cookie_monster); |
| 4574 | net::CookieOptions options; |
| 4575 | cookie_monster->SetCookieWithOptionsAsync( |
| 4576 | origin1, "dummy=value", options, |
| 4577 | base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 4578 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4579 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4580 | EXPECT_TRUE(callback.result_); |
| 4581 | |
| 4582 | cookie_monster->GetAllCookiesForURLAsync( |
| 4583 | origin1, |
| 4584 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4585 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4586 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4587 | EXPECT_EQ(1U, callback.list_.size()); |
| 4588 | |
| 4589 | // Open a database. |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 4590 | webkit_database::DatabaseTracker* db_tracker = |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 4591 | BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 4592 | GetDatabaseTracker(); |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 4593 | base::string16 db_name = base::UTF8ToUTF16("db"); |
| 4594 | base::string16 description = base::UTF8ToUTF16("db_description"); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4595 | int64 size; |
| 4596 | db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
| 4597 | db_tracker->DatabaseClosed(origin_id, db_name); |
| 4598 | std::vector<webkit_database::OriginInfo> origins; |
| 4599 | db_tracker->GetAllOriginsInfo(&origins); |
| 4600 | EXPECT_EQ(1U, origins.size()); |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 4601 | EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4602 | |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 4603 | // Create local storage. We only simulate this by creating the backing files. |
| 4604 | // Note: This test depends on details of how the dom_storage library |
| 4605 | // stores data in the host file system. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4606 | base::FilePath lso_dir_path = |
| 4607 | profile_->GetPath().AppendASCII("Local Storage"); |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 4608 | base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) |
| 4609 | .AddExtension(FILE_PATH_LITERAL(".localstorage")); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4610 | EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 4611 | EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4612 | EXPECT_TRUE(base::PathExists(lso_file_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4613 | |
| 4614 | // Create indexed db. Similarly, it is enough to only simulate this by |
| 4615 | // creating the directory on the disk. |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 4616 | IndexedDBContext* idb_context = |
| 4617 | BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 4618 | GetIndexedDBContext(); |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 4619 | idb_context->SetTaskRunnerForTesting( |
[email protected] | 198b590 | 2013-06-27 10:36:11 | [diff] [blame] | 4620 | base::MessageLoop::current()->message_loop_proxy().get()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4621 | base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4622 | EXPECT_TRUE(base::CreateDirectory(idb_path)); |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4623 | EXPECT_TRUE(base::DirectoryExists(idb_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4624 | |
| 4625 | // Uninstall one of them, unlimited storage should still be granted |
| 4626 | // to the origin. |
| 4627 | UninstallExtension(id1, false); |
| 4628 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 4629 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 4630 | IsStorageUnlimited(origin1)); |
| 4631 | |
| 4632 | // Check that the cookie is still there. |
| 4633 | cookie_monster->GetAllCookiesForURLAsync( |
| 4634 | origin1, |
| 4635 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4636 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4637 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4638 | EXPECT_EQ(1U, callback.list_.size()); |
| 4639 | |
| 4640 | // Now uninstall the other. Storage should be cleared for the apps. |
| 4641 | UninstallExtension(id2, false); |
| 4642 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 4643 | EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 4644 | IsStorageUnlimited(origin1)); |
| 4645 | |
| 4646 | // Check that the cookie is gone. |
| 4647 | cookie_monster->GetAllCookiesForURLAsync( |
| 4648 | origin1, |
| 4649 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4650 | base::Unretained(&callback))); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4651 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4652 | EXPECT_EQ(0U, callback.list_.size()); |
| 4653 | |
| 4654 | // The database should have vanished as well. |
| 4655 | origins.clear(); |
| 4656 | db_tracker->GetAllOriginsInfo(&origins); |
| 4657 | EXPECT_EQ(0U, origins.size()); |
| 4658 | |
| 4659 | // Check that the LSO file has been removed. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4660 | EXPECT_FALSE(base::PathExists(lso_file_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4661 | |
| 4662 | // Check if the indexed db has disappeared too. |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4663 | EXPECT_FALSE(base::DirectoryExists(idb_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4664 | } |
| 4665 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4666 | // Tests loading single extensions (like --load-extension) |
[email protected] | e3f610b | 2013-05-03 02:22:38 | [diff] [blame] | 4667 | // Flaky crashes. http://crbug.com/231806 |
| 4668 | TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4669 | InitializeEmptyExtensionService(); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 4670 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4671 | base::FilePath ext1 = data_dir_ |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 4672 | .AppendASCII("good") |
| 4673 | .AppendASCII("Extensions") |
[email protected] | 5a2721f6 | 2009-06-13 07:08:20 | [diff] [blame] | 4674 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 4675 | .AppendASCII("1.0.0.0"); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4676 | extensions::UnpackedInstaller::Create(service_)->Load(ext1); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4677 | base::RunLoop().RunUntilIdle(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 4678 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4679 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 4680 | EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4681 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 4682 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 4683 | ValidatePrefKeyCount(1); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4684 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4685 | base::FilePath no_manifest = data_dir_ |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 4686 | .AppendASCII("bad") |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 4687 | // .AppendASCII("Extensions") |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 4688 | .AppendASCII("cccccccccccccccccccccccccccccccc") |
| 4689 | .AppendASCII("1"); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4690 | extensions::UnpackedInstaller::Create(service_)->Load(no_manifest); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4691 | base::RunLoop().RunUntilIdle(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 4692 | EXPECT_EQ(1u, GetErrors().size()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4693 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4694 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4695 | |
| 4696 | // Test uninstall. |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4697 | std::string id = loaded_[0]->id(); |
| 4698 | EXPECT_FALSE(unloaded_id_.length()); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 4699 | service_->UninstallExtension(id, false, NULL); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4700 | base::RunLoop().RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4701 | EXPECT_EQ(id, unloaded_id_); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4702 | ASSERT_EQ(0u, loaded_.size()); |
| 4703 | EXPECT_EQ(0u, service_->extensions()->size()); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 4704 | } |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4705 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4706 | // Tests that we generate IDs when they are not specified in the manifest for |
| 4707 | // --load-extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4708 | TEST_F(ExtensionServiceTest, GenerateID) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4709 | InitializeEmptyExtensionService(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 4710 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4711 | base::FilePath no_id_ext = data_dir_.AppendASCII("no_id"); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4712 | extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4713 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4714 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4715 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 4716 | ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 4717 | EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4718 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 4719 | ValidatePrefKeyCount(1); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4720 | |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 4721 | std::string previous_id = loaded_[0]->id(); |
| 4722 | |
| 4723 | // If we reload the same path, we should get the same extension ID. |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4724 | extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4725 | base::RunLoop().RunUntilIdle(); |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 4726 | ASSERT_EQ(1u, loaded_.size()); |
| 4727 | ASSERT_EQ(previous_id, loaded_[0]->id()); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4728 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4729 | |
[email protected] | 557c7bd | 2013-09-18 21:51:25 | [diff] [blame] | 4730 | TEST_F(ExtensionServiceTest, UnpackedValidatesLocales) { |
| 4731 | InitializeEmptyExtensionService(); |
| 4732 | |
| 4733 | base::FilePath bad_locale = data_dir_.AppendASCII("unpacked"). |
| 4734 | AppendASCII("bad_messages_file"); |
| 4735 | extensions::UnpackedInstaller::Create(service_)->Load(bad_locale); |
| 4736 | base::RunLoop().RunUntilIdle(); |
| 4737 | EXPECT_EQ(1u, GetErrors().size()); |
| 4738 | base::FilePath ms_messages_file = bad_locale.AppendASCII("_locales") |
| 4739 | .AppendASCII("ms") |
| 4740 | .AppendASCII("messages.json"); |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 4741 | EXPECT_THAT(base::UTF16ToUTF8(GetErrors()[0]), testing::AllOf( |
| 4742 | testing::HasSubstr( |
| 4743 | base::UTF16ToUTF8(ms_messages_file.LossyDisplayName())), |
[email protected] | 557c7bd | 2013-09-18 21:51:25 | [diff] [blame] | 4744 | testing::HasSubstr("Dictionary keys must be quoted."))); |
| 4745 | ASSERT_EQ(0u, loaded_.size()); |
| 4746 | } |
| 4747 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4748 | void ExtensionServiceTest::TestExternalProvider( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4749 | MockExtensionProvider* provider, Manifest::Location location) { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4750 | // Verify that starting with no providers loads no extensions. |
| 4751 | service_->Init(); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4752 | ASSERT_EQ(0u, loaded_.size()); |
| 4753 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4754 | provider->set_visit_count(0); |
| 4755 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4756 | // Register a test extension externally using the mock registry provider. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4757 | base::FilePath source_path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4758 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4759 | // Add the extension. |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4760 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4761 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4762 | // Reloading extensions should find our externally registered extension |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4763 | // and install it. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4764 | content::WindowedNotificationObserver observer( |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 4765 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4766 | content::NotificationService::AllSources()); |
| 4767 | service_->CheckForExternalUpdates(); |
| 4768 | observer.Wait(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4769 | |
| 4770 | ASSERT_EQ(0u, GetErrors().size()); |
| 4771 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4772 | ASSERT_EQ(location, loaded_[0]->location()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4773 | ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4774 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4775 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4776 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4777 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4778 | // Reload extensions without changing anything. The extension should be |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4779 | // loaded again. |
| 4780 | loaded_.clear(); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4781 | service_->ReloadExtensionsForTest(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4782 | base::RunLoop().RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4783 | ASSERT_EQ(0u, GetErrors().size()); |
| 4784 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4785 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4786 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4787 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 4788 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4789 | // Now update the extension with a new version. We should get upgraded. |
| 4790 | source_path = source_path.DirName().AppendASCII("good2.crx"); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4791 | provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4792 | |
| 4793 | loaded_.clear(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4794 | content::WindowedNotificationObserver observer_2( |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 4795 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4796 | content::NotificationService::AllSources()); |
| 4797 | service_->CheckForExternalUpdates(); |
| 4798 | observer_2.Wait(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4799 | ASSERT_EQ(0u, GetErrors().size()); |
| 4800 | ASSERT_EQ(1u, loaded_.size()); |
| 4801 | ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4802 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4803 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4804 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4805 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4806 | // Uninstall the extension and reload. Nothing should happen because the |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4807 | // preference should prevent us from reinstalling. |
| 4808 | std::string id = loaded_[0]->id(); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 4809 | bool no_uninstall = |
| 4810 | management_policy_->MustRemainEnabled(loaded_[0].get(), NULL); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 4811 | service_->UninstallExtension(id, false, NULL); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4812 | base::RunLoop().RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4813 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4814 | base::FilePath install_path = extensions_install_dir_.AppendASCII(id); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 4815 | if (no_uninstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 4816 | // Policy controlled extensions should not have been touched by uninstall. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4817 | ASSERT_TRUE(base::PathExists(install_path)); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 4818 | } else { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4819 | // The extension should also be gone from the install directory. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4820 | ASSERT_FALSE(base::PathExists(install_path)); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4821 | loaded_.clear(); |
| 4822 | service_->CheckForExternalUpdates(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4823 | base::RunLoop().RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4824 | ASSERT_EQ(0u, loaded_.size()); |
| 4825 | ValidatePrefKeyCount(1); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 4826 | ValidateIntegerPref(good_crx, "state", |
| 4827 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4828 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4829 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4830 | // Now clear the preference and reinstall. |
| 4831 | SetPrefInteg(good_crx, "state", Extension::ENABLED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4832 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4833 | loaded_.clear(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4834 | content::WindowedNotificationObserver observer( |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 4835 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4836 | content::NotificationService::AllSources()); |
| 4837 | service_->CheckForExternalUpdates(); |
| 4838 | observer.Wait(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4839 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4840 | } |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4841 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4842 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4843 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4844 | |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 4845 | if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 4846 | EXPECT_EQ(2, provider->visit_count()); |
| 4847 | } else { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4848 | // Now test an externally triggered uninstall (deleting the registry key or |
| 4849 | // the pref entry). |
| 4850 | provider->RemoveExtension(good_crx); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4851 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4852 | loaded_.clear(); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 4853 | service_->OnExternalProviderReady(provider); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4854 | base::RunLoop().RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4855 | ASSERT_EQ(0u, loaded_.size()); |
| 4856 | ValidatePrefKeyCount(0); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4857 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4858 | // The extension should also be gone from the install directory. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4859 | ASSERT_FALSE(base::PathExists(install_path)); |
[email protected] | abe7a894 | 2009-06-23 05:14:29 | [diff] [blame] | 4860 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4861 | // Now test the case where user uninstalls and then the extension is removed |
| 4862 | // from the external provider. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4863 | content::WindowedNotificationObserver observer( |
| 4864 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 4865 | content::NotificationService::AllSources()); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 4866 | provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4867 | service_->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4868 | observer.Wait(); |
[email protected] | abe7a894 | 2009-06-23 05:14:29 | [diff] [blame] | 4869 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4870 | ASSERT_EQ(1u, loaded_.size()); |
| 4871 | ASSERT_EQ(0u, GetErrors().size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4872 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4873 | // User uninstalls. |
| 4874 | loaded_.clear(); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 4875 | service_->UninstallExtension(id, false, NULL); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4876 | base::RunLoop().RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4877 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4878 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4879 | // Then remove the extension from the extension provider. |
| 4880 | provider->RemoveExtension(good_crx); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4881 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4882 | // Should still be at 0. |
| 4883 | loaded_.clear(); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4884 | extensions::InstalledLoader(service_).LoadAllExtensions(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4885 | base::RunLoop().RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4886 | ASSERT_EQ(0u, loaded_.size()); |
| 4887 | ValidatePrefKeyCount(1); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4888 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4889 | EXPECT_EQ(5, provider->visit_count()); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4890 | } |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4891 | } |
| 4892 | |
| 4893 | // Tests the external installation feature |
| 4894 | #if defined(OS_WIN) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4895 | TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4896 | // This should all work, even when normal extension installation is disabled. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4897 | InitializeEmptyExtensionService(); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4898 | set_extensions_enabled(false); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4899 | |
| 4900 | // Now add providers. Extension system takes ownership of the objects. |
| 4901 | MockExtensionProvider* reg_provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4902 | new MockExtensionProvider(service_, Manifest::EXTERNAL_REGISTRY); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4903 | AddMockExternalProvider(reg_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4904 | TestExternalProvider(reg_provider, Manifest::EXTERNAL_REGISTRY); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4905 | } |
| 4906 | #endif |
| 4907 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4908 | TEST_F(ExtensionServiceTest, ExternalInstallPref) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4909 | InitializeEmptyExtensionService(); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4910 | |
| 4911 | // Now add providers. Extension system takes ownership of the objects. |
| 4912 | MockExtensionProvider* pref_provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4913 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4914 | |
| 4915 | AddMockExternalProvider(pref_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4916 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4917 | } |
| 4918 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4919 | TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4920 | // This should all work, even when normal extension installation is disabled. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4921 | InitializeEmptyExtensionService(); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4922 | set_extensions_enabled(false); |
[email protected] | 55196e9 | 2010-09-29 15:04:46 | [diff] [blame] | 4923 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4924 | // TODO(skerner): The mock provider is not a good model of a provider |
| 4925 | // that works with update URLs, because it adds file and version info. |
| 4926 | // Extend the mock to work with update URLs. This test checks the |
| 4927 | // behavior that is common to all external extension visitors. The |
| 4928 | // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| 4929 | // what the visitor does results in an extension being downloaded and |
| 4930 | // installed. |
[email protected] | 55196e9 | 2010-09-29 15:04:46 | [diff] [blame] | 4931 | MockExtensionProvider* pref_provider = |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 4932 | new MockExtensionProvider(service_, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4933 | Manifest::EXTERNAL_PREF_DOWNLOAD); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4934 | AddMockExternalProvider(pref_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4935 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF_DOWNLOAD); |
[email protected] | 55196e9 | 2010-09-29 15:04:46 | [diff] [blame] | 4936 | } |
| 4937 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4938 | TEST_F(ExtensionServiceTest, ExternalInstallPolicyUpdateUrl) { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4939 | // This should all work, even when normal extension installation is disabled. |
| 4940 | InitializeEmptyExtensionService(); |
| 4941 | set_extensions_enabled(false); |
| 4942 | |
| 4943 | // TODO(skerner): The mock provider is not a good model of a provider |
| 4944 | // that works with update URLs, because it adds file and version info. |
| 4945 | // Extend the mock to work with update URLs. This test checks the |
| 4946 | // behavior that is common to all external extension visitors. The |
| 4947 | // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| 4948 | // what the visitor does results in an extension being downloaded and |
| 4949 | // installed. |
| 4950 | MockExtensionProvider* pref_provider = |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 4951 | new MockExtensionProvider(service_, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4952 | Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4953 | AddMockExternalProvider(pref_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4954 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4955 | } |
| 4956 | |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4957 | // Tests that external extensions get uninstalled when the external extension |
| 4958 | // providers can't account for them. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4959 | TEST_F(ExtensionServiceTest, ExternalUninstall) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4960 | // Start the extensions service with one external extension already installed. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4961 | base::FilePath source_install_dir = data_dir_ |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4962 | .AppendASCII("good") |
| 4963 | .AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4964 | base::FilePath pref_path = source_install_dir |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4965 | .DirName() |
| 4966 | .AppendASCII("PreferencesExternal"); |
| 4967 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 4968 | // This initializes the extensions service with no ExternalProviders. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4969 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4970 | set_extensions_enabled(false); |
| 4971 | |
| 4972 | service_->Init(); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4973 | |
| 4974 | ASSERT_EQ(0u, GetErrors().size()); |
[email protected] | 1f4728f | 2012-12-05 20:40:05 | [diff] [blame] | 4975 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4976 | |
| 4977 | // Verify that it's not the disabled extensions flag causing it not to load. |
| 4978 | set_extensions_enabled(true); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4979 | service_->ReloadExtensionsForTest(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 4980 | base::RunLoop().RunUntilIdle(); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4981 | |
| 4982 | ASSERT_EQ(0u, GetErrors().size()); |
| 4983 | ASSERT_EQ(0u, loaded_.size()); |
| 4984 | } |
| 4985 | |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4986 | // Test that running multiple update checks simultaneously does not |
| 4987 | // keep the update from succeeding. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4988 | TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4989 | InitializeEmptyExtensionService(); |
| 4990 | |
| 4991 | MockExtensionProvider* provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4992 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4993 | AddMockExternalProvider(provider); |
| 4994 | |
| 4995 | // Verify that starting with no providers loads no extensions. |
| 4996 | service_->Init(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4997 | ASSERT_EQ(0u, loaded_.size()); |
| 4998 | |
| 4999 | // Start two checks for updates. |
| 5000 | provider->set_visit_count(0); |
| 5001 | service_->CheckForExternalUpdates(); |
| 5002 | service_->CheckForExternalUpdates(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5003 | base::RunLoop().RunUntilIdle(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5004 | |
| 5005 | // Two calls should cause two checks for external extensions. |
| 5006 | EXPECT_EQ(2, provider->visit_count()); |
| 5007 | EXPECT_EQ(0u, GetErrors().size()); |
| 5008 | EXPECT_EQ(0u, loaded_.size()); |
| 5009 | |
| 5010 | // Register a test extension externally using the mock registry provider. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5011 | base::FilePath source_path = data_dir_.AppendASCII("good.crx"); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5012 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); |
| 5013 | |
| 5014 | // Two checks for external updates should find the extension, and install it |
| 5015 | // once. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5016 | content::WindowedNotificationObserver observer( |
| 5017 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 5018 | content::NotificationService::AllSources()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5019 | provider->set_visit_count(0); |
| 5020 | service_->CheckForExternalUpdates(); |
| 5021 | service_->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5022 | observer.Wait(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5023 | EXPECT_EQ(2, provider->visit_count()); |
| 5024 | ASSERT_EQ(0u, GetErrors().size()); |
| 5025 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5026 | ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5027 | ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); |
| 5028 | ValidatePrefKeyCount(1); |
| 5029 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5030 | ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5031 | |
| 5032 | provider->RemoveExtension(good_crx); |
| 5033 | provider->set_visit_count(0); |
| 5034 | service_->CheckForExternalUpdates(); |
| 5035 | service_->CheckForExternalUpdates(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5036 | base::RunLoop().RunUntilIdle(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5037 | |
| 5038 | // Two calls should cause two checks for external extensions. |
| 5039 | // Because the external source no longer includes good_crx, |
| 5040 | // good_crx will be uninstalled. So, expect that no extensions |
| 5041 | // are loaded. |
| 5042 | EXPECT_EQ(2, provider->visit_count()); |
| 5043 | EXPECT_EQ(0u, GetErrors().size()); |
| 5044 | EXPECT_EQ(0u, loaded_.size()); |
| 5045 | } |
| 5046 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5047 | TEST_F(ExtensionServiceTest, ExternalPrefProvider) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5048 | InitializeEmptyExtensionService(); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5049 | |
| 5050 | // Test some valid extension records. |
| 5051 | // Set a base path to avoid erroring out on relative paths. |
| 5052 | // Paths starting with // are absolute on every platform we support. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5053 | base::FilePath base_path(FILE_PATH_LITERAL("//base/path")); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5054 | ASSERT_TRUE(base_path.IsAbsolute()); |
| 5055 | MockProviderVisitor visitor(base_path); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5056 | std::string json_data = |
| 5057 | "{" |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5058 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5059 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5060 | " \"external_version\": \"1.0\"" |
| 5061 | " }," |
| 5062 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5063 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5064 | " \"external_version\": \"2.0\"" |
| 5065 | " }," |
| 5066 | " \"cccccccccccccccccccccccccccccccc\": {" |
[email protected] | a424d84c | 2010-09-24 09:31:15 | [diff] [blame] | 5067 | " \"external_update_url\": \"http:\\\\foo.com/update\"" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5068 | " }" |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5069 | "}"; |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5070 | EXPECT_EQ(3, visitor.Visit(json_data)); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5071 | |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5072 | // Simulate an external_extensions.json file that contains seven invalid |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5073 | // records: |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5074 | // - One that is missing the 'external_crx' key. |
| 5075 | // - One that is missing the 'external_version' key. |
| 5076 | // - One that is specifying .. in the path. |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 5077 | // - One that specifies both a file and update URL. |
| 5078 | // - One that specifies no file or update URL. |
| 5079 | // - One that has an update URL that is not well formed. |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5080 | // - One that contains a malformed version. |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 5081 | // - One that has an invalid id. |
| 5082 | // - One that has a non-dictionary value. |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 5083 | // - One that has an integer 'external_version' instead of a string. |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5084 | // The final extension is valid, and we check that it is read to make sure |
| 5085 | // failures don't stop valid records from being read. |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5086 | json_data = |
| 5087 | "{" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5088 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5089 | " \"external_version\": \"1.0\"" |
| 5090 | " }," |
| 5091 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5092 | " \"external_crx\": \"RandomExtension.crx\"" |
| 5093 | " }," |
| 5094 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 5095 | " \"external_crx\": \"..\\\\foo\\\\RandomExtension2.crx\"," |
| 5096 | " \"external_version\": \"2.0\"" |
| 5097 | " }," |
| 5098 | " \"dddddddddddddddddddddddddddddddd\": {" |
| 5099 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5100 | " \"external_version\": \"2.0\"," |
| 5101 | " \"external_update_url\": \"http:\\\\foo.com/update\"" |
| 5102 | " }," |
| 5103 | " \"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\": {" |
| 5104 | " }," |
| 5105 | " \"ffffffffffffffffffffffffffffffff\": {" |
| 5106 | " \"external_update_url\": \"This string is not a valid URL\"" |
| 5107 | " }," |
| 5108 | " \"gggggggggggggggggggggggggggggggg\": {" |
| 5109 | " \"external_crx\": \"RandomExtension3.crx\"," |
| 5110 | " \"external_version\": \"This is not a valid version!\"" |
| 5111 | " }," |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 5112 | " \"This is not a valid id!\": {}," |
| 5113 | " \"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\": true," |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 5114 | " \"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\": {" |
| 5115 | " \"external_crx\": \"RandomExtension4.crx\"," |
| 5116 | " \"external_version\": 1.0" |
| 5117 | " }," |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 5118 | " \"pppppppppppppppppppppppppppppppp\": {" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5119 | " \"external_crx\": \"RandomValidExtension.crx\"," |
| 5120 | " \"external_version\": \"1.0\"" |
| 5121 | " }" |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5122 | "}"; |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 5123 | EXPECT_EQ(1, visitor.Visit(json_data)); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5124 | |
| 5125 | // Check that if a base path is not provided, use of a relative |
| 5126 | // path fails. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5127 | base::FilePath empty; |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5128 | MockProviderVisitor visitor_no_relative_paths(empty); |
| 5129 | |
| 5130 | // Use absolute paths. Expect success. |
| 5131 | json_data = |
| 5132 | "{" |
| 5133 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5134 | " \"external_crx\": \"//RandomExtension1.crx\"," |
| 5135 | " \"external_version\": \"3.0\"" |
| 5136 | " }," |
| 5137 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5138 | " \"external_crx\": \"//path/to/RandomExtension2.crx\"," |
| 5139 | " \"external_version\": \"3.0\"" |
| 5140 | " }" |
| 5141 | "}"; |
| 5142 | EXPECT_EQ(2, visitor_no_relative_paths.Visit(json_data)); |
| 5143 | |
| 5144 | // Use a relative path. Expect that it will error out. |
| 5145 | json_data = |
| 5146 | "{" |
| 5147 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 5148 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5149 | " \"external_version\": \"3.0\"" |
| 5150 | " }" |
| 5151 | "}"; |
| 5152 | EXPECT_EQ(0, visitor_no_relative_paths.Visit(json_data)); |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 5153 | |
| 5154 | // Test supported_locales. |
| 5155 | json_data = |
| 5156 | "{" |
| 5157 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5158 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5159 | " \"external_version\": \"1.0\"," |
| 5160 | " \"supported_locales\": [ \"en\" ]" |
| 5161 | " }," |
| 5162 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5163 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5164 | " \"external_version\": \"2.0\"," |
| 5165 | " \"supported_locales\": [ \"en-GB\" ]" |
| 5166 | " }," |
| 5167 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 5168 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5169 | " \"external_version\": \"3.0\"," |
| 5170 | " \"supported_locales\": [ \"en_US\", \"fr\" ]" |
| 5171 | " }" |
| 5172 | "}"; |
| 5173 | { |
| 5174 | ScopedBrowserLocale guard("en-US"); |
| 5175 | EXPECT_EQ(2, visitor.Visit(json_data)); |
| 5176 | } |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 5177 | |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 5178 | // Test keep_if_present. |
| 5179 | json_data = |
| 5180 | "{" |
| 5181 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5182 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5183 | " \"external_version\": \"1.0\"," |
| 5184 | " \"keep_if_present\": true" |
| 5185 | " }" |
| 5186 | "}"; |
| 5187 | { |
| 5188 | EXPECT_EQ(0, visitor.Visit(json_data)); |
| 5189 | } |
| 5190 | |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 5191 | // Test is_bookmark_app. |
| 5192 | MockProviderVisitor from_bookmark_visitor( |
| 5193 | base_path, Extension::FROM_BOOKMARK); |
| 5194 | json_data = |
| 5195 | "{" |
| 5196 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5197 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5198 | " \"external_version\": \"1.0\"," |
| 5199 | " \"is_bookmark_app\": true" |
| 5200 | " }" |
| 5201 | "}"; |
| 5202 | EXPECT_EQ(1, from_bookmark_visitor.Visit(json_data)); |
[email protected] | 7425d7df | 2012-11-28 14:35:42 | [diff] [blame] | 5203 | |
| 5204 | // Test is_from_webstore. |
| 5205 | MockProviderVisitor from_webstore_visitor( |
| 5206 | base_path, Extension::FROM_WEBSTORE); |
| 5207 | json_data = |
| 5208 | "{" |
| 5209 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5210 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5211 | " \"external_version\": \"1.0\"," |
| 5212 | " \"is_from_webstore\": true" |
| 5213 | " }" |
| 5214 | "}"; |
| 5215 | EXPECT_EQ(1, from_webstore_visitor.Visit(json_data)); |
[email protected] | e18236b | 2009-06-22 21:32:10 | [diff] [blame] | 5216 | } |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5217 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5218 | // Test loading good extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5219 | TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) { |
[email protected] | 6884a80 | 2012-08-07 03:55:22 | [diff] [blame] | 5220 | // Ensure we're testing in "en" and leave global state untouched. |
| 5221 | extension_l10n_util::ScopedLocaleForTest testLocale("en"); |
| 5222 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5223 | // Initialize the test dir with a good Preferences/extensions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5224 | base::FilePath source_install_dir = data_dir_ |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5225 | .AppendASCII("l10n"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5226 | base::FilePath pref_path = source_install_dir.AppendASCII("Preferences"); |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5227 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5228 | |
| 5229 | service_->Init(); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5230 | |
| 5231 | ASSERT_EQ(3u, loaded_.size()); |
| 5232 | |
| 5233 | // This was equal to "sr" on load. |
| 5234 | ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en"); |
| 5235 | |
| 5236 | // These are untouched by re-localization. |
| 5237 | ValidateStringPref(loaded_[1]->id(), keys::kCurrentLocale, "en"); |
| 5238 | EXPECT_FALSE(IsPrefExist(loaded_[1]->id(), keys::kCurrentLocale)); |
| 5239 | |
| 5240 | // This one starts with Serbian name, and gets re-localized into English. |
| 5241 | EXPECT_EQ("My name is simple.", loaded_[0]->name()); |
| 5242 | |
| 5243 | // These are untouched by re-localization. |
| 5244 | EXPECT_EQ("My name is simple.", loaded_[1]->name()); |
| 5245 | EXPECT_EQ("no l10n", loaded_[2]->name()); |
| 5246 | } |
| 5247 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5248 | class ExtensionsReadyRecorder : public content::NotificationObserver { |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5249 | public: |
| 5250 | ExtensionsReadyRecorder() : ready_(false) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 5251 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 5252 | content::NotificationService::AllSources()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5253 | } |
| 5254 | |
| 5255 | void set_ready(bool value) { ready_ = value; } |
| 5256 | bool ready() { return ready_; } |
| 5257 | |
| 5258 | private: |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 5259 | virtual void Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5260 | const content::NotificationSource& source, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 5261 | const content::NotificationDetails& details) OVERRIDE { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 5262 | switch (type) { |
| 5263 | case chrome::NOTIFICATION_EXTENSIONS_READY: |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5264 | ready_ = true; |
| 5265 | break; |
| 5266 | default: |
| 5267 | NOTREACHED(); |
| 5268 | } |
| 5269 | } |
| 5270 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5271 | content::NotificationRegistrar registrar_; |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5272 | bool ready_; |
| 5273 | }; |
| 5274 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5275 | // Test that we get enabled/disabled correctly for all the pref/command-line |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5276 | // combinations. We don't want to derive from the ExtensionServiceTest class |
| 5277 | // for this test, so we use ExtensionServiceTestSimple. |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5278 | // |
| 5279 | // Also tests that we always fire EXTENSIONS_READY, no matter whether we are |
| 5280 | // enabled or not. |
[email protected] | 39fdf520 | 2012-11-14 00:38:17 | [diff] [blame] | 5281 | TEST(ExtensionServiceTestSimple, Enabledness) { |
[email protected] | 5a24d2b | 2012-11-14 20:38:31 | [diff] [blame] | 5282 | // Make sure the PluginService singleton is destroyed at the end of the test. |
[email protected] | 39fdf520 | 2012-11-14 00:38:17 | [diff] [blame] | 5283 | base::ShadowingAtExitManager at_exit_manager; |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 5284 | #if defined(ENABLE_PLUGINS) |
| 5285 | content::PluginService::GetInstance()->Init(); |
| 5286 | content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting(); |
| 5287 | #endif |
[email protected] | 5a24d2b | 2012-11-14 20:38:31 | [diff] [blame] | 5288 | |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 5289 | ExtensionErrorReporter::Init(false); // no noisy errors |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5290 | ExtensionsReadyRecorder recorder; |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 5291 | scoped_ptr<TestingProfile> profile(new TestingProfile()); |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 5292 | content::TestBrowserThreadBundle thread_bundle_; |
[email protected] | e4854dc | 2013-04-24 00:11:51 | [diff] [blame] | 5293 | #if defined OS_CHROMEOS |
| 5294 | chromeos::ScopedTestDeviceSettingsService device_settings_service; |
| 5295 | chromeos::ScopedTestCrosSettings cros_settings; |
| 5296 | scoped_ptr<chromeos::ScopedTestUserManager> user_manager( |
| 5297 | new chromeos::ScopedTestUserManager); |
| 5298 | #endif |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5299 | scoped_ptr<CommandLine> command_line; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5300 | base::FilePath install_dir = profile->GetPath() |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 5301 | .AppendASCII(extensions::kInstallDirectoryName); |
[email protected] | be5a6db | 2012-11-13 14:39:11 | [diff] [blame] | 5302 | |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5303 | // By default, we are enabled. |
[email protected] | 947446b | 2010-10-21 03:36:31 | [diff] [blame] | 5304 | command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5305 | ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5306 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5307 | CreateExtensionService( |
| 5308 | command_line.get(), |
| 5309 | install_dir, |
| 5310 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5311 | EXPECT_TRUE(service->extensions_enabled()); |
| 5312 | service->Init(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5313 | base::RunLoop().RunUntilIdle(); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5314 | EXPECT_TRUE(recorder.ready()); |
[email protected] | e4854dc | 2013-04-24 00:11:51 | [diff] [blame] | 5315 | #if defined OS_CHROMEOS |
| 5316 | user_manager.reset(); |
| 5317 | #endif |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5318 | |
| 5319 | // If either the command line or pref is set, we are disabled. |
| 5320 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 5321 | profile.reset(new TestingProfile()); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5322 | command_line->AppendSwitch(switches::kDisableExtensions); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5323 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5324 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5325 | CreateExtensionService( |
| 5326 | command_line.get(), |
| 5327 | install_dir, |
| 5328 | false); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5329 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5330 | service->Init(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5331 | base::RunLoop().RunUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5332 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5333 | |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5334 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 5335 | profile.reset(new TestingProfile()); |
| 5336 | profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5337 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5338 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5339 | CreateExtensionService( |
| 5340 | command_line.get(), |
| 5341 | install_dir, |
| 5342 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5343 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5344 | service->Init(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5345 | base::RunLoop().RunUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5346 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5347 | |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5348 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 5349 | profile.reset(new TestingProfile()); |
| 5350 | profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
[email protected] | 947446b | 2010-10-21 03:36:31 | [diff] [blame] | 5351 | command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5352 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5353 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5354 | CreateExtensionService( |
| 5355 | command_line.get(), |
| 5356 | install_dir, |
| 5357 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5358 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5359 | service->Init(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5360 | base::RunLoop().RunUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5361 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 7e1951a | 2010-09-30 10:22:20 | [diff] [blame] | 5362 | |
| 5363 | // Explicitly delete all the resources used in this test. |
| 5364 | profile.reset(); |
| 5365 | service = NULL; |
[email protected] | 060d497 | 2012-07-19 17:22:39 | [diff] [blame] | 5366 | // Execute any pending deletion tasks. |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5367 | base::RunLoop().RunUntilIdle(); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5368 | } |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5369 | |
| 5370 | // Test loading extensions that require limited and unlimited storage quotas. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5371 | TEST_F(ExtensionServiceTest, StorageQuota) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5372 | InitializeEmptyExtensionService(); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5373 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5374 | base::FilePath extensions_path = data_dir_ |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5375 | .AppendASCII("storage_quota"); |
| 5376 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5377 | base::FilePath limited_quota_ext = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 5378 | extensions_path.AppendASCII("limited_quota") |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5379 | .AppendASCII("1.0"); |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 5380 | |
| 5381 | // The old permission name for unlimited quota was "unlimited_storage", but |
| 5382 | // we changed it to "unlimitedStorage". This tests both versions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5383 | base::FilePath unlimited_quota_ext = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 5384 | extensions_path.AppendASCII("unlimited_quota") |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5385 | .AppendASCII("1.0"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5386 | base::FilePath unlimited_quota_ext2 = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 5387 | extensions_path.AppendASCII("unlimited_quota") |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 5388 | .AppendASCII("2.0"); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 5389 | extensions::UnpackedInstaller::Create(service_)->Load(limited_quota_ext); |
| 5390 | extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext); |
| 5391 | extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext2); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 5392 | base::RunLoop().RunUntilIdle(); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5393 | |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 5394 | ASSERT_EQ(3u, loaded_.size()); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5395 | EXPECT_TRUE(profile_.get()); |
| 5396 | EXPECT_FALSE(profile_->IsOffTheRecord()); |
[email protected] | 7c5f2ec | 2011-05-26 19:15:26 | [diff] [blame] | 5397 | EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 5398 | loaded_[0]->url())); |
| 5399 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 5400 | loaded_[1]->url())); |
| 5401 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 5402 | loaded_[2]->url())); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5403 | } |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5404 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 5405 | // Tests ComponentLoader::Add(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5406 | TEST_F(ExtensionServiceTest, ComponentExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5407 | InitializeEmptyExtensionService(); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5408 | |
[email protected] | f0b97f1 | 2010-10-11 21:44:35 | [diff] [blame] | 5409 | // Component extensions should work even when extensions are disabled. |
| 5410 | set_extensions_enabled(false); |
| 5411 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5412 | base::FilePath path = data_dir_ |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5413 | .AppendASCII("good") |
| 5414 | .AppendASCII("Extensions") |
| 5415 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 5416 | .AppendASCII("1.0.0.0"); |
| 5417 | |
| 5418 | std::string manifest; |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 5419 | ASSERT_TRUE(base::ReadFileToString( |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 5420 | path.Append(extensions::kManifestFilename), &manifest)); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5421 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 5422 | service_->component_loader()->Add(manifest, path); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5423 | service_->Init(); |
| 5424 | |
| 5425 | // Note that we do not pump messages -- the extension should be loaded |
| 5426 | // immediately. |
| 5427 | |
| 5428 | EXPECT_EQ(0u, GetErrors().size()); |
| 5429 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5430 | EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location()); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5431 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 5432 | |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 5433 | // Component extensions get a prefs entry on first install. |
| 5434 | ValidatePrefKeyCount(1); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5435 | |
| 5436 | // Reload all extensions, and make sure it comes back. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5437 | std::string extension_id = (*service_->extensions()->begin())->id(); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5438 | loaded_.clear(); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 5439 | service_->ReloadExtensionsForTest(); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5440 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5441 | EXPECT_EQ(extension_id, (*service_->extensions()->begin())->id()); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5442 | } |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5443 | |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5444 | namespace { |
[email protected] | fe4b4ca | 2013-09-05 23:30:01 | [diff] [blame] | 5445 | |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 5446 | class TestSyncProcessorStub : public syncer::SyncChangeProcessor { |
| 5447 | virtual syncer::SyncError ProcessSyncChanges( |
| 5448 | const tracked_objects::Location& from_here, |
| 5449 | const syncer::SyncChangeList& change_list) OVERRIDE { |
| 5450 | return syncer::SyncError(); |
| 5451 | } |
| 5452 | |
| 5453 | virtual syncer::SyncDataList GetAllSyncData( |
| 5454 | syncer::ModelType type) const OVERRIDE { |
| 5455 | return syncer::SyncDataList(); |
| 5456 | } |
| 5457 | }; |
| 5458 | |
| 5459 | } // namespace |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5460 | |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5461 | TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledComponent) { |
| 5462 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5463 | InitializeExtensionSyncService(); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5464 | |
| 5465 | bool flare_was_called = false; |
| 5466 | syncer::ModelType triggered_type(syncer::UNSPECIFIED); |
| 5467 | base::WeakPtrFactory<ExtensionServiceTest> factory(this); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5468 | extension_sync_service_->SetSyncStartFlare( |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5469 | base::Bind(&ExtensionServiceTest::MockSyncStartFlare, |
| 5470 | factory.GetWeakPtr(), |
| 5471 | &flare_was_called, // Safe due to WeakPtrFactory scope. |
| 5472 | &triggered_type)); // Safe due to WeakPtrFactory scope. |
| 5473 | |
| 5474 | // Install a component extension. |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5475 | std::string manifest; |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 5476 | ASSERT_TRUE(base::ReadFileToString( |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 5477 | good0_path().Append(extensions::kManifestFilename), &manifest)); |
| 5478 | service_->component_loader()->Add(manifest, good0_path()); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5479 | ASSERT_FALSE(service_->is_ready()); |
| 5480 | service_->Init(); |
| 5481 | ASSERT_TRUE(service_->is_ready()); |
| 5482 | |
| 5483 | // Extensions added before service is_ready() don't trigger sync startup. |
| 5484 | EXPECT_FALSE(flare_was_called); |
| 5485 | ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); |
| 5486 | } |
| 5487 | |
| 5488 | TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledNormal) { |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 5489 | InitializeGoodInstalledExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5490 | InitializeExtensionSyncService(); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5491 | |
| 5492 | bool flare_was_called = false; |
| 5493 | syncer::ModelType triggered_type(syncer::UNSPECIFIED); |
| 5494 | base::WeakPtrFactory<ExtensionServiceTest> factory(this); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5495 | extension_sync_service_->SetSyncStartFlare( |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5496 | base::Bind(&ExtensionServiceTest::MockSyncStartFlare, |
| 5497 | factory.GetWeakPtr(), |
| 5498 | &flare_was_called, // Safe due to WeakPtrFactory scope. |
| 5499 | &triggered_type)); // Safe due to WeakPtrFactory scope. |
| 5500 | |
| 5501 | ASSERT_FALSE(service_->is_ready()); |
| 5502 | service_->Init(); |
[email protected] | 50736a1 | 2013-09-26 08:58:34 | [diff] [blame] | 5503 | ASSERT_EQ(3u, loaded_.size()); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5504 | ASSERT_TRUE(service_->is_ready()); |
| 5505 | |
| 5506 | // Extensions added before service is_ready() don't trigger sync startup. |
| 5507 | EXPECT_FALSE(flare_was_called); |
| 5508 | ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); |
| 5509 | } |
| 5510 | |
| 5511 | TEST_F(ExtensionServiceTest, DeferredSyncStartupOnInstall) { |
| 5512 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5513 | InitializeExtensionSyncService(); |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5514 | service_->Init(); |
| 5515 | ASSERT_TRUE(service_->is_ready()); |
| 5516 | |
| 5517 | bool flare_was_called = false; |
| 5518 | syncer::ModelType triggered_type(syncer::UNSPECIFIED); |
| 5519 | base::WeakPtrFactory<ExtensionServiceTest> factory(this); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5520 | extension_sync_service_->SetSyncStartFlare( |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5521 | base::Bind(&ExtensionServiceTest::MockSyncStartFlare, |
| 5522 | factory.GetWeakPtr(), |
| 5523 | &flare_was_called, // Safe due to WeakPtrFactory scope. |
| 5524 | &triggered_type)); // Safe due to WeakPtrFactory scope. |
| 5525 | |
| 5526 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 5527 | InstallCRX(path, INSTALL_NEW); |
| 5528 | |
| 5529 | EXPECT_TRUE(flare_was_called); |
| 5530 | EXPECT_EQ(syncer::EXTENSIONS, triggered_type); |
| 5531 | |
| 5532 | // Reset. |
| 5533 | flare_was_called = false; |
| 5534 | triggered_type = syncer::UNSPECIFIED; |
| 5535 | |
| 5536 | // Once sync starts, flare should no longer be invoked. |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5537 | extension_sync_service_->MergeDataAndStartSyncing( |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 5538 | syncer::EXTENSIONS, syncer::SyncDataList(), |
| 5539 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5540 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 5541 | path = data_dir_.AppendASCII("page_action.crx"); |
| 5542 | InstallCRX(path, INSTALL_NEW); |
| 5543 | EXPECT_FALSE(flare_was_called); |
| 5544 | ASSERT_EQ(syncer::UNSPECIFIED, triggered_type); |
| 5545 | } |
| 5546 | |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5547 | TEST_F(ExtensionServiceTest, DisableExtensionFromSync) { |
| 5548 | // Start the extensions service with one external extension already installed. |
| 5549 | base::FilePath source_install_dir = data_dir_ |
| 5550 | .AppendASCII("good") |
| 5551 | .AppendASCII("Extensions"); |
| 5552 | base::FilePath pref_path = source_install_dir |
| 5553 | .DirName() |
| 5554 | .AppendASCII("Preferences"); |
| 5555 | |
| 5556 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 5557 | InitializeExtensionSyncService(); |
| 5558 | |
| 5559 | // The user has enabled sync. |
| 5560 | ProfileSyncService* sync_service = |
| 5561 | ProfileSyncServiceFactory::GetForProfile(profile_.get()); |
| 5562 | sync_service->SetSyncSetupCompleted(); |
| 5563 | |
| 5564 | service_->Init(); |
| 5565 | ASSERT_TRUE(service_->is_ready()); |
| 5566 | |
| 5567 | ASSERT_EQ(3u, loaded_.size()); |
| 5568 | |
| 5569 | // We start enabled. |
| 5570 | const Extension* extension = service_->GetExtensionById(good0, true); |
| 5571 | ASSERT_TRUE(extension); |
| 5572 | ASSERT_TRUE(service_->IsExtensionEnabled(good0)); |
| 5573 | extensions::ExtensionSyncData disable_good_crx(*extension, false, false); |
| 5574 | |
| 5575 | // Then sync data arrives telling us to disable |good0|. |
| 5576 | syncer::SyncDataList sync_data; |
| 5577 | sync_data.push_back(disable_good_crx.GetSyncData()); |
| 5578 | extension_sync_service_->MergeDataAndStartSyncing( |
| 5579 | syncer::EXTENSIONS, sync_data, |
| 5580 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5581 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 5582 | ASSERT_FALSE(service_->IsExtensionEnabled(good0)); |
| 5583 | } |
| 5584 | |
| 5585 | TEST_F(ExtensionServiceTest, DontDisableExtensionWithPendingEnableFromSync) { |
| 5586 | // Start the extensions service with one external extension already installed. |
| 5587 | base::FilePath source_install_dir = data_dir_ |
| 5588 | .AppendASCII("good") |
| 5589 | .AppendASCII("Extensions"); |
| 5590 | base::FilePath pref_path = source_install_dir |
| 5591 | .DirName() |
| 5592 | .AppendASCII("Preferences"); |
| 5593 | |
| 5594 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 5595 | InitializeExtensionSyncService(); |
| 5596 | |
| 5597 | // The user has enabled sync. |
| 5598 | ProfileSyncService* sync_service = |
| 5599 | ProfileSyncServiceFactory::GetForProfile(profile_.get()); |
| 5600 | sync_service->SetSyncSetupCompleted(); |
| 5601 | |
| 5602 | service_->Init(); |
| 5603 | ASSERT_TRUE(service_->is_ready()); |
| 5604 | ASSERT_EQ(3u, loaded_.size()); |
| 5605 | |
| 5606 | const Extension* extension = service_->GetExtensionById(good0, true); |
| 5607 | ASSERT_TRUE(service_->IsExtensionEnabled(good0)); |
| 5608 | |
| 5609 | // Disable extension before first sync data arrives. |
| 5610 | service_->DisableExtension(good0, Extension::DISABLE_USER_ACTION); |
| 5611 | ASSERT_FALSE(service_->IsExtensionEnabled(good0)); |
| 5612 | |
| 5613 | // Enable extension - this is now the most recent state. |
| 5614 | service_->EnableExtension(good0); |
| 5615 | ASSERT_TRUE(service_->IsExtensionEnabled(good0)); |
| 5616 | |
| 5617 | // Now sync data comes in that says to disable good0. This should be |
| 5618 | // ignored. |
| 5619 | extensions::ExtensionSyncData disable_good_crx(*extension, false, false); |
| 5620 | syncer::SyncDataList sync_data; |
| 5621 | sync_data.push_back(disable_good_crx.GetSyncData()); |
| 5622 | extension_sync_service_->MergeDataAndStartSyncing( |
| 5623 | syncer::EXTENSIONS, sync_data, |
| 5624 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5625 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
| 5626 | |
| 5627 | // The extension was enabled locally before the sync data arrived, so it |
| 5628 | // should still be enabled now. |
| 5629 | ASSERT_TRUE(service_->IsExtensionEnabled(good0)); |
| 5630 | } |
| 5631 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5632 | TEST_F(ExtensionServiceTest, GetSyncData) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5633 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5634 | InitializeExtensionSyncService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5635 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 5636 | const Extension* extension = service_->GetInstalledExtension(good_crx); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5637 | ASSERT_TRUE(extension); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 5638 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5639 | extension_sync_service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5640 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5641 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5642 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5643 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5644 | syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( |
| 5645 | syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5646 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5647 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5648 | EXPECT_EQ(extension->id(), data.id()); |
| 5649 | EXPECT_FALSE(data.uninstalled()); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5650 | EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 5651 | EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile_.get()), |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 5652 | data.incognito_enabled()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5653 | EXPECT_TRUE(data.version().Equals(*extension->version())); |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 5654 | EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension), |
| 5655 | data.update_url()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5656 | EXPECT_EQ(extension->name(), data.name()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5657 | } |
| 5658 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5659 | TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 5660 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5661 | InitializeExtensionSyncService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5662 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 5663 | TerminateExtension(good_crx); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 5664 | const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 5665 | ASSERT_TRUE(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5666 | |
| 5667 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5668 | extension_sync_service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5669 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5670 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5671 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5672 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5673 | syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( |
| 5674 | syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5675 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5676 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5677 | EXPECT_EQ(extension->id(), data.id()); |
| 5678 | EXPECT_FALSE(data.uninstalled()); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5679 | EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 5680 | EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile_.get()), |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 5681 | data.incognito_enabled()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5682 | EXPECT_TRUE(data.version().Equals(*extension->version())); |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 5683 | EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension), |
| 5684 | data.update_url()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5685 | EXPECT_EQ(extension->name(), data.name()); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 5686 | } |
| 5687 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5688 | TEST_F(ExtensionServiceTest, GetSyncDataFilter) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5689 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5690 | InitializeExtensionSyncService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5691 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 5692 | const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 5693 | ASSERT_TRUE(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5694 | |
| 5695 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5696 | extension_sync_service_->MergeDataAndStartSyncing(syncer::APPS, |
| 5697 | syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5698 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5699 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5700 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5701 | syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( |
| 5702 | syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5703 | ASSERT_EQ(list.size(), 0U); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5704 | } |
| 5705 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5706 | TEST_F(ExtensionServiceTest, GetSyncExtensionDataUserSettings) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5707 | InitializeEmptyExtensionService(); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 5708 | InitializeProcessManager(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5709 | InitializeExtensionSyncService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5710 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 5711 | const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 5712 | ASSERT_TRUE(extension); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5713 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5714 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5715 | extension_sync_service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5716 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5717 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5718 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5719 | |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5720 | { |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5721 | syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( |
| 5722 | syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5723 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5724 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5725 | EXPECT_TRUE(data.enabled()); |
| 5726 | EXPECT_FALSE(data.incognito_enabled()); |
| 5727 | } |
| 5728 | |
| 5729 | service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
| 5730 | { |
| 5731 | syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( |
| 5732 | syncer::EXTENSIONS); |
| 5733 | ASSERT_EQ(list.size(), 1U); |
| 5734 | extensions::ExtensionSyncData data(list[0]); |
| 5735 | EXPECT_FALSE(data.enabled()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5736 | EXPECT_FALSE(data.incognito_enabled()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5737 | } |
| 5738 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 5739 | extensions::util::SetIsIncognitoEnabled(good_crx, profile_.get(), true); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5740 | { |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5741 | syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( |
| 5742 | syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5743 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5744 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5745 | EXPECT_FALSE(data.enabled()); |
| 5746 | EXPECT_TRUE(data.incognito_enabled()); |
| 5747 | } |
| 5748 | |
| 5749 | service_->EnableExtension(good_crx); |
| 5750 | { |
| 5751 | syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( |
| 5752 | syncer::EXTENSIONS); |
| 5753 | ASSERT_EQ(list.size(), 1U); |
| 5754 | extensions::ExtensionSyncData data(list[0]); |
| 5755 | EXPECT_TRUE(data.enabled()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5756 | EXPECT_TRUE(data.incognito_enabled()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5757 | } |
| 5758 | } |
| 5759 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5760 | TEST_F(ExtensionServiceTest, SyncForUninstalledExternalExtension) { |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5761 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5762 | InitializeExtensionSyncService(); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5763 | InstallCRXWithLocation(data_dir_.AppendASCII("good.crx"), |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5764 | Manifest::EXTERNAL_PREF, INSTALL_NEW); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5765 | const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 5766 | ASSERT_TRUE(extension); |
| 5767 | |
| 5768 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5769 | extension_sync_service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5770 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5771 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5772 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5773 | |
| 5774 | UninstallExtension(good_crx, false); |
| 5775 | EXPECT_TRUE(service_->IsExternalExtensionUninstalled(good_crx)); |
| 5776 | |
| 5777 | sync_pb::EntitySpecifics specifics; |
| 5778 | sync_pb::AppSpecifics* app_specifics = specifics.mutable_app(); |
| 5779 | sync_pb::ExtensionSpecifics* extension_specifics = |
| 5780 | app_specifics->mutable_extension(); |
| 5781 | extension_specifics->set_id(good_crx); |
| 5782 | extension_specifics->set_version("1.0"); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5783 | extension_specifics->set_enabled(true); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5784 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5785 | syncer::SyncData sync_data = |
| 5786 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5787 | syncer::SyncChange sync_change(FROM_HERE, |
| 5788 | syncer::SyncChange::ACTION_UPDATE, |
| 5789 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5790 | syncer::SyncChangeList list(1); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5791 | list[0] = sync_change; |
| 5792 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5793 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 5794 | EXPECT_TRUE(service_->IsExternalExtensionUninstalled(good_crx)); |
| 5795 | } |
| 5796 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5797 | TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettings) { |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5798 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5799 | InitializeExtensionSyncService(); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5800 | const Extension* app = |
| 5801 | PackAndInstallCRX(data_dir_.AppendASCII("app"), INSTALL_NEW); |
| 5802 | ASSERT_TRUE(app); |
| 5803 | ASSERT_TRUE(app->is_app()); |
| 5804 | |
| 5805 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5806 | extension_sync_service_->MergeDataAndStartSyncing(syncer::APPS, |
| 5807 | syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5808 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5809 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5810 | |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 5811 | syncer::StringOrdinal initial_ordinal = |
| 5812 | syncer::StringOrdinal::CreateInitialOrdinal(); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5813 | { |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5814 | syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( |
| 5815 | syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5816 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5817 | |
| 5818 | extensions::AppSyncData app_sync_data(list[0]); |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 5819 | EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.app_launch_ordinal())); |
| 5820 | EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5821 | } |
| 5822 | |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 5823 | AppSorting* sorting = service_->extension_prefs()->app_sorting(); |
[email protected] | fb82dcd | 2012-03-21 14:15:46 | [diff] [blame] | 5824 | sorting->SetAppLaunchOrdinal(app->id(), initial_ordinal.CreateAfter()); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5825 | { |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5826 | syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( |
| 5827 | syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5828 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5829 | |
| 5830 | extensions::AppSyncData app_sync_data(list[0]); |
| 5831 | EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 5832 | EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5833 | } |
| 5834 | |
[email protected] | fb82dcd | 2012-03-21 14:15:46 | [diff] [blame] | 5835 | sorting->SetPageOrdinal(app->id(), initial_ordinal.CreateAfter()); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5836 | { |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5837 | syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( |
| 5838 | syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5839 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5840 | |
| 5841 | extensions::AppSyncData app_sync_data(list[0]); |
| 5842 | EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); |
| 5843 | EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.page_ordinal())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5844 | } |
| 5845 | } |
| 5846 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5847 | TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettingsOnExtensionMoved) { |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5848 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5849 | InitializeExtensionSyncService(); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5850 | const size_t kAppCount = 3; |
| 5851 | const Extension* apps[kAppCount]; |
| 5852 | apps[0] = PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
| 5853 | apps[1] = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
| 5854 | apps[2] = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); |
| 5855 | for (size_t i = 0; i < kAppCount; ++i) { |
| 5856 | ASSERT_TRUE(apps[i]); |
| 5857 | ASSERT_TRUE(apps[i]->is_app()); |
| 5858 | } |
| 5859 | |
| 5860 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5861 | extension_sync_service_->MergeDataAndStartSyncing(syncer::APPS, |
| 5862 | syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5863 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5864 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5865 | |
| 5866 | service_->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id()); |
| 5867 | { |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5868 | syncer::SyncDataList list = extension_sync_service_->GetAllSyncData( |
| 5869 | syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5870 | ASSERT_EQ(list.size(), 3U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5871 | |
| 5872 | extensions::AppSyncData data[kAppCount]; |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 5873 | for (size_t i = 0; i < kAppCount; ++i) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5874 | data[i] = extensions::AppSyncData(list[i]); |
| 5875 | } |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5876 | |
| 5877 | // The sync data is not always in the same order our apps were installed in, |
| 5878 | // so we do that sorting here so we can make sure the values are changed as |
| 5879 | // expected. |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 5880 | syncer::StringOrdinal app_launch_ordinals[kAppCount]; |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5881 | for (size_t i = 0; i < kAppCount; ++i) { |
| 5882 | for (size_t j = 0; j < kAppCount; ++j) { |
| 5883 | if (apps[i]->id() == data[j].id()) |
| 5884 | app_launch_ordinals[i] = data[j].app_launch_ordinal(); |
| 5885 | } |
| 5886 | } |
| 5887 | |
| 5888 | EXPECT_TRUE(app_launch_ordinals[1].LessThan(app_launch_ordinals[0])); |
| 5889 | EXPECT_TRUE(app_launch_ordinals[0].LessThan(app_launch_ordinals[2])); |
| 5890 | } |
| 5891 | } |
| 5892 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5893 | TEST_F(ExtensionServiceTest, GetSyncDataList) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5894 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5895 | InitializeExtensionSyncService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5896 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 5897 | InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); |
| 5898 | InstallCRX(data_dir_.AppendASCII("theme.crx"), INSTALL_NEW); |
| 5899 | InstallCRX(data_dir_.AppendASCII("theme2.crx"), INSTALL_NEW); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5900 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5901 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5902 | extension_sync_service_->MergeDataAndStartSyncing( |
| 5903 | syncer::APPS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5904 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5905 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5906 | extension_sync_service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5907 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5908 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5909 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5910 | |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 5911 | service_->DisableExtension(page_action, Extension::DISABLE_USER_ACTION); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 5912 | TerminateExtension(theme2_crx); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5913 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5914 | EXPECT_EQ(0u, extension_sync_service_->GetAllSyncData(syncer::APPS).size()); |
| 5915 | EXPECT_EQ(2u, extension_sync_service_-> |
| 5916 | GetAllSyncData(syncer::EXTENSIONS).size()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5917 | } |
| 5918 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5919 | TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5920 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5921 | InitializeExtensionSyncService(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5922 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5923 | extension_sync_service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5924 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5925 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5926 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5927 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5928 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5929 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5930 | ext_specifics->set_id(good_crx); |
| 5931 | ext_specifics->set_version("1.0"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5932 | syncer::SyncData sync_data = |
| 5933 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5934 | syncer::SyncChange sync_change(FROM_HERE, |
| 5935 | syncer::SyncChange::ACTION_DELETE, |
| 5936 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5937 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5938 | list[0] = sync_change; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5939 | |
| 5940 | // Should do nothing. |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5941 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5942 | EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5943 | |
| 5944 | // Install the extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5945 | base::FilePath extension_path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5946 | InstallCRX(extension_path, INSTALL_NEW); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5947 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 5948 | |
| 5949 | // Should uninstall the extension. |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5950 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5951 | EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); |
| 5952 | |
| 5953 | // Should again do nothing. |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5954 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5955 | EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5956 | } |
| 5957 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5958 | TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) { |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5959 | InitializeEmptyExtensionService(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5960 | InitializeExtensionSyncService(); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5961 | |
| 5962 | // Install the extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5963 | base::FilePath extension_path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5964 | InstallCRX(extension_path, INSTALL_NEW); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5965 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 5966 | |
| 5967 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5968 | sync_pb::AppSpecifics* app_specifics = specifics.mutable_app(); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5969 | sync_pb::ExtensionSpecifics* extension_specifics = |
| 5970 | app_specifics->mutable_extension(); |
| 5971 | extension_specifics->set_id(good_crx); |
| 5972 | extension_specifics->set_version( |
| 5973 | service_->GetInstalledExtension(good_crx)->version()->GetString()); |
| 5974 | |
| 5975 | { |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5976 | extension_specifics->set_enabled(true); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5977 | syncer::SyncData sync_data = |
| 5978 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5979 | syncer::SyncChange sync_change(FROM_HERE, |
| 5980 | syncer::SyncChange::ACTION_DELETE, |
| 5981 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5982 | syncer::SyncChangeList list(1); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5983 | list[0] = sync_change; |
| 5984 | |
| 5985 | // Should do nothing |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 5986 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5987 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 5988 | } |
| 5989 | |
| 5990 | { |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 5991 | extension_specifics->set_enabled(false); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5992 | syncer::SyncData sync_data = |
| 5993 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5994 | syncer::SyncChange sync_change(FROM_HERE, |
| 5995 | syncer::SyncChange::ACTION_UPDATE, |
| 5996 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5997 | syncer::SyncChangeList list(1); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5998 | list[0] = sync_change; |
| 5999 | |
| 6000 | // Should again do nothing. |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6001 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 6002 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 6003 | } |
| 6004 | } |
| 6005 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6006 | TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6007 | InitializeEmptyExtensionService(); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 6008 | InitializeProcessManager(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6009 | InitializeExtensionSyncService(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6010 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6011 | extension_sync_service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 6012 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6013 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 6014 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6015 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 6016 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6017 | EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 6018 | EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6019 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6020 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 6021 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6022 | ext_specifics->set_id(good_crx); |
| 6023 | ext_specifics->set_version( |
| 6024 | service_->GetInstalledExtension(good_crx)->version()->GetString()); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6025 | ext_specifics->set_enabled(false); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6026 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6027 | { |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6028 | syncer::SyncData sync_data = |
| 6029 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 6030 | syncer::SyncChange sync_change(FROM_HERE, |
| 6031 | syncer::SyncChange::ACTION_UPDATE, |
| 6032 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6033 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6034 | list[0] = sync_change; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6035 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6036 | EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 6037 | EXPECT_FALSE( |
| 6038 | extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6039 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6040 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6041 | { |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6042 | ext_specifics->set_enabled(true); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6043 | ext_specifics->set_incognito_enabled(true); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6044 | syncer::SyncData sync_data = |
| 6045 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 6046 | syncer::SyncChange sync_change(FROM_HERE, |
| 6047 | syncer::SyncChange::ACTION_UPDATE, |
| 6048 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6049 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6050 | list[0] = sync_change; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6051 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 60d8d38 | 2013-10-27 02:03:36 | [diff] [blame] | 6052 | EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 6053 | EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6054 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6055 | |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6056 | { |
| 6057 | ext_specifics->set_enabled(false); |
| 6058 | ext_specifics->set_incognito_enabled(true); |
| 6059 | syncer::SyncData sync_data = |
| 6060 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
| 6061 | syncer::SyncChange sync_change(FROM_HERE, |
| 6062 | syncer::SyncChange::ACTION_UPDATE, |
| 6063 | sync_data); |
| 6064 | syncer::SyncChangeList list(1); |
| 6065 | list[0] = sync_change; |
| 6066 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
| 6067 | EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 6068 | EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6069 | } |
| 6070 | |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6071 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
| 6072 | } |
| 6073 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6074 | TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 6075 | InitializeExtensionServiceWithUpdater(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6076 | InitializeExtensionSyncService(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6077 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6078 | extension_sync_service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 6079 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6080 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 6081 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 6082 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 6083 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 6084 | TerminateExtension(good_crx); |
| 6085 | EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 6086 | EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 6087 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6088 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 6089 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6090 | ext_specifics->set_id(good_crx); |
| 6091 | ext_specifics->set_version( |
| 6092 | service_->GetInstalledExtension(good_crx)->version()->GetString()); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6093 | ext_specifics->set_enabled(false); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6094 | ext_specifics->set_incognito_enabled(true); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6095 | syncer::SyncData sync_data = |
| 6096 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 6097 | syncer::SyncChange sync_change(FROM_HERE, |
| 6098 | syncer::SyncChange::ACTION_UPDATE, |
| 6099 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6100 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6101 | list[0] = sync_change; |
| 6102 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6103 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6104 | EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 6105 | EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 6106 | |
| 6107 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
| 6108 | } |
| 6109 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6110 | TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6111 | InitializeExtensionServiceWithUpdater(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6112 | InitializeExtensionSyncService(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6113 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6114 | extension_sync_service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 6115 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6116 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 6117 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6118 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 6119 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6120 | EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 6121 | EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6122 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6123 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 6124 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6125 | ext_specifics->set_id(good_crx); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6126 | ext_specifics->set_enabled(true); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6127 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6128 | { |
| 6129 | ext_specifics->set_version( |
| 6130 | service_->GetInstalledExtension(good_crx)->version()->GetString()); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6131 | syncer::SyncData sync_data = |
| 6132 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 6133 | syncer::SyncChange sync_change(FROM_HERE, |
| 6134 | syncer::SyncChange::ACTION_UPDATE, |
| 6135 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6136 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6137 | list[0] = sync_change; |
| 6138 | |
| 6139 | // Should do nothing if extension version == sync version. |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6140 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6141 | EXPECT_FALSE(service_->updater()->WillCheckSoon()); |
| 6142 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6143 | |
| 6144 | // Should do nothing if extension version > sync version (but see |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6145 | // the TODO in ProcessExtensionSyncData). |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6146 | { |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6147 | ext_specifics->set_version("0.0.0.0"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6148 | syncer::SyncData sync_data = |
| 6149 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 6150 | syncer::SyncChange sync_change(FROM_HERE, |
| 6151 | syncer::SyncChange::ACTION_UPDATE, |
| 6152 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6153 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6154 | list[0] = sync_change; |
| 6155 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6156 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6157 | EXPECT_FALSE(service_->updater()->WillCheckSoon()); |
| 6158 | } |
| 6159 | |
| 6160 | // Should kick off an update if extension version < sync version. |
| 6161 | { |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6162 | ext_specifics->set_version("9.9.9.9"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6163 | syncer::SyncData sync_data = |
| 6164 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 6165 | syncer::SyncChange sync_change(FROM_HERE, |
| 6166 | syncer::SyncChange::ACTION_UPDATE, |
| 6167 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6168 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6169 | list[0] = sync_change; |
| 6170 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6171 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6172 | EXPECT_TRUE(service_->updater()->WillCheckSoon()); |
| 6173 | } |
| 6174 | |
| 6175 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
| 6176 | } |
| 6177 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6178 | TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6179 | InitializeExtensionServiceWithUpdater(); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6180 | InitializeExtensionSyncService(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6181 | TestSyncProcessorStub processor; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6182 | extension_sync_service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 6183 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6184 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 6185 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6186 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6187 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 6188 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6189 | ext_specifics->set_id(good_crx); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6190 | ext_specifics->set_enabled(false); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6191 | ext_specifics->set_incognito_enabled(true); |
| 6192 | ext_specifics->set_update_url("http://www.google.com/"); |
| 6193 | ext_specifics->set_version("1.2.3.4"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6194 | syncer::SyncData sync_data = |
| 6195 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 6196 | syncer::SyncChange sync_change(FROM_HERE, |
| 6197 | syncer::SyncChange::ACTION_UPDATE, |
| 6198 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 6199 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 6200 | list[0] = sync_change; |
| 6201 | |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6202 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 6203 | EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 6204 | EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 6205 | extension_sync_service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6206 | EXPECT_TRUE(service_->updater()->WillCheckSoon()); |
[email protected] | 386db357 | 2013-11-08 12:26:44 | [diff] [blame] | 6207 | EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 6208 | EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile_.get())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6209 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6210 | const extensions::PendingExtensionInfo* info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6211 | EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| 6212 | GetById(good_crx))); |
| 6213 | EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); |
| 6214 | EXPECT_TRUE(info->is_from_sync()); |
| 6215 | EXPECT_TRUE(info->install_silently()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6216 | EXPECT_EQ(Manifest::INTERNAL, info->install_source()); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 6217 | // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. |
| 6218 | } |
| 6219 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6220 | TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6221 | InitializeEmptyExtensionService(); |
| 6222 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6223 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 6224 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6225 | ValidatePrefKeyCount(1u); |
| 6226 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6227 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6228 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6229 | extensions::PendingExtensionManager* pending = |
| 6230 | service_->pending_extension_manager(); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6231 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6232 | |
| 6233 | // Skip install when the location is the same. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6234 | EXPECT_FALSE( |
| 6235 | service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 6236 | kGoodId, GURL(kGoodUpdateURL), Manifest::INTERNAL, |
| 6237 | Extension::NO_FLAGS, false)); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6238 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6239 | |
| 6240 | // Install when the location has higher priority. |
| 6241 | EXPECT_TRUE( |
| 6242 | service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 6243 | kGoodId, GURL(kGoodUpdateURL), Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 6244 | Extension::NO_FLAGS, false)); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6245 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6246 | |
| 6247 | // Try the low priority again. Should be rejected. |
| 6248 | EXPECT_FALSE( |
| 6249 | service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 6250 | kGoodId, GURL(kGoodUpdateURL), Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 6251 | Extension::NO_FLAGS, false)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6252 | // The existing record should still be present in the pending extension |
| 6253 | // manager. |
| 6254 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6255 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6256 | pending->Remove(kGoodId); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6257 | |
| 6258 | // Skip install when the location has the same priority as the installed |
| 6259 | // location. |
| 6260 | EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 6261 | kGoodId, GURL(kGoodUpdateURL), Manifest::INTERNAL, |
| 6262 | Extension::NO_FLAGS, false)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6263 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 6264 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6265 | } |
| 6266 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6267 | TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 6268 | Version older_version("0.1.0.0"); |
| 6269 | Version newer_version("2.0.0.0"); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6270 | |
| 6271 | // We don't want the extension to be installed. A path that doesn't |
| 6272 | // point to a valid CRX ensures this. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6273 | const base::FilePath kInvalidPathToCrx = base::FilePath(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6274 | |
| 6275 | const int kCreationFlags = 0; |
| 6276 | const bool kDontMarkAcknowledged = false; |
| 6277 | |
| 6278 | InitializeEmptyExtensionService(); |
| 6279 | |
| 6280 | // The test below uses install source constants to test that |
| 6281 | // priority is enforced. It assumes a specific ranking of install |
| 6282 | // sources: Registry (EXTERNAL_REGISTRY) overrides external pref |
| 6283 | // (EXTERNAL_PREF), and external pref overrides user install (INTERNAL). |
| 6284 | // The following assertions verify these assumptions: |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6285 | ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, |
| 6286 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
| 6287 | Manifest::EXTERNAL_PREF)); |
| 6288 | ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, |
| 6289 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
| 6290 | Manifest::INTERNAL)); |
| 6291 | ASSERT_EQ(Manifest::EXTERNAL_PREF, |
| 6292 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, |
| 6293 | Manifest::INTERNAL)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6294 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6295 | extensions::PendingExtensionManager* pending = |
| 6296 | service_->pending_extension_manager(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6297 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6298 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6299 | { |
| 6300 | // Simulate an external source adding the extension as INTERNAL. |
| 6301 | content::WindowedNotificationObserver observer( |
| 6302 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6303 | content::NotificationService::AllSources()); |
| 6304 | EXPECT_TRUE( |
| 6305 | service_->OnExternalExtensionFileFound( |
| 6306 | kGoodId, &older_version, kInvalidPathToCrx, |
| 6307 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
| 6308 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6309 | observer.Wait(); |
| 6310 | VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 6311 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6312 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6313 | { |
| 6314 | // Simulate an external source adding the extension as EXTERNAL_PREF. |
| 6315 | content::WindowedNotificationObserver observer( |
| 6316 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6317 | content::NotificationService::AllSources()); |
| 6318 | EXPECT_TRUE( |
| 6319 | service_->OnExternalExtensionFileFound( |
| 6320 | kGoodId, &older_version, kInvalidPathToCrx, |
| 6321 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
| 6322 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6323 | observer.Wait(); |
| 6324 | VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 6325 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6326 | |
| 6327 | // Simulate an external source adding as EXTERNAL_PREF again. |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 6328 | // This is rejected because the version and the location are the same as |
| 6329 | // the previous installation, which is still pending. |
| 6330 | EXPECT_FALSE( |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6331 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6332 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6333 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6334 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6335 | |
| 6336 | // Try INTERNAL again. Should fail. |
| 6337 | EXPECT_FALSE( |
| 6338 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6339 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6340 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6341 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6342 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6343 | { |
| 6344 | // Now the registry adds the extension. |
| 6345 | content::WindowedNotificationObserver observer( |
| 6346 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6347 | content::NotificationService::AllSources()); |
| 6348 | EXPECT_TRUE( |
| 6349 | service_->OnExternalExtensionFileFound(kGoodId, |
| 6350 | &older_version, |
| 6351 | kInvalidPathToCrx, |
| 6352 | Manifest::EXTERNAL_REGISTRY, |
| 6353 | kCreationFlags, |
| 6354 | kDontMarkAcknowledged)); |
| 6355 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6356 | observer.Wait(); |
| 6357 | VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 6358 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6359 | |
| 6360 | // Registry outranks both external pref and internal, so both fail. |
| 6361 | EXPECT_FALSE( |
| 6362 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6363 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6364 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6365 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6366 | |
| 6367 | EXPECT_FALSE( |
| 6368 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6369 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6370 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6371 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6372 | |
| 6373 | pending->Remove(kGoodId); |
| 6374 | |
| 6375 | // Install the extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6376 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6377 | const Extension* ext = InstallCRX(path, INSTALL_NEW); |
| 6378 | ValidatePrefKeyCount(1u); |
| 6379 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6380 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6381 | |
| 6382 | // Now test the logic of OnExternalExtensionFileFound() when the extension |
| 6383 | // being added is already installed. |
| 6384 | |
| 6385 | // Tests assume |older_version| is less than the installed version, and |
| 6386 | // |newer_version| is greater. Verify this: |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6387 | ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); |
| 6388 | ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6389 | |
| 6390 | // An external install for the same location should fail if the version is |
| 6391 | // older, or the same, and succeed if the version is newer. |
| 6392 | |
| 6393 | // Older than the installed version... |
| 6394 | EXPECT_FALSE( |
| 6395 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6396 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6397 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6398 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6399 | |
| 6400 | // Same version as the installed version... |
| 6401 | EXPECT_FALSE( |
| 6402 | service_->OnExternalExtensionFileFound( |
| 6403 | kGoodId, ext->version(), kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6404 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6405 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6406 | |
| 6407 | // Newer than the installed version... |
| 6408 | EXPECT_TRUE( |
| 6409 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6410 | kGoodId, &newer_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6411 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6412 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6413 | |
| 6414 | // An external install for a higher priority install source should succeed |
| 6415 | // if the version is greater. |older_version| is not... |
| 6416 | EXPECT_FALSE( |
| 6417 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6418 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6419 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6420 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6421 | |
| 6422 | // |newer_version| is newer. |
| 6423 | EXPECT_TRUE( |
| 6424 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6425 | kGoodId, &newer_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6426 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6427 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6428 | |
| 6429 | // An external install for an even higher priority install source should |
| 6430 | // succeed if the version is greater. |
| 6431 | EXPECT_TRUE( |
| 6432 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6433 | kGoodId, &newer_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6434 | Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6435 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6436 | |
| 6437 | // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, |
| 6438 | // adding from external pref will now fail. |
| 6439 | EXPECT_FALSE( |
| 6440 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 6441 | kGoodId, &newer_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6442 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6443 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6444 | } |
| 6445 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6446 | TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 6447 | Version kVersion123("1.2.3"); |
| 6448 | Version kVersion124("1.2.4"); |
| 6449 | Version kVersion125("1.2.5"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6450 | const base::FilePath kInvalidPathToCrx = base::FilePath(); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6451 | const int kCreationFlags = 0; |
| 6452 | const bool kDontMarkAcknowledged = false; |
| 6453 | |
| 6454 | InitializeEmptyExtensionService(); |
| 6455 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6456 | extensions::PendingExtensionManager* pending = |
| 6457 | service_->pending_extension_manager(); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6458 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6459 | |
| 6460 | // An external provider starts installing from a local crx. |
| 6461 | EXPECT_TRUE( |
| 6462 | service_->OnExternalExtensionFileFound( |
| 6463 | kGoodId, &kVersion123, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6464 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6465 | const extensions::PendingExtensionInfo* info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6466 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 6467 | EXPECT_TRUE(info->version().IsValid()); |
| 6468 | EXPECT_TRUE(info->version().Equals(kVersion123)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6469 | |
| 6470 | // Adding a newer version overrides the currently pending version. |
| 6471 | EXPECT_TRUE( |
| 6472 | service_->OnExternalExtensionFileFound( |
| 6473 | kGoodId, &kVersion124, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6474 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6475 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 6476 | EXPECT_TRUE(info->version().IsValid()); |
| 6477 | EXPECT_TRUE(info->version().Equals(kVersion124)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6478 | |
| 6479 | // Adding an older version fails. |
| 6480 | EXPECT_FALSE( |
| 6481 | service_->OnExternalExtensionFileFound( |
| 6482 | kGoodId, &kVersion123, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6483 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6484 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 6485 | EXPECT_TRUE(info->version().IsValid()); |
| 6486 | EXPECT_TRUE(info->version().Equals(kVersion124)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6487 | |
| 6488 | // Adding an older version fails even when coming from a higher-priority |
| 6489 | // location. |
| 6490 | EXPECT_FALSE( |
| 6491 | service_->OnExternalExtensionFileFound( |
| 6492 | kGoodId, &kVersion123, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6493 | Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6494 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 6495 | EXPECT_TRUE(info->version().IsValid()); |
| 6496 | EXPECT_TRUE(info->version().Equals(kVersion124)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6497 | |
| 6498 | // Adding the latest version from the webstore overrides a specific version. |
| 6499 | GURL kUpdateUrl("http://example.com/update"); |
| 6500 | EXPECT_TRUE( |
| 6501 | service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 6502 | kGoodId, kUpdateUrl, Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 6503 | Extension::NO_FLAGS, false)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6504 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 6505 | EXPECT_FALSE(info->version().IsValid()); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6506 | } |
| 6507 | |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6508 | // This makes sure we can package and install CRX files that use whitelisted |
| 6509 | // permissions. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6510 | TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6511 | std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; |
| 6512 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 6513 | switches::kWhitelistedExtensionID, test_id); |
| 6514 | |
| 6515 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6516 | base::FilePath path = data_dir_ |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6517 | .AppendASCII("permissions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6518 | base::FilePath pem_path = path |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6519 | .AppendASCII("whitelist.pem"); |
| 6520 | path = path |
| 6521 | .AppendASCII("whitelist"); |
| 6522 | |
| 6523 | const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); |
| 6524 | EXPECT_EQ(0u, GetErrors().size()); |
| 6525 | ASSERT_EQ(1u, service_->extensions()->size()); |
| 6526 | EXPECT_EQ(test_id, extension->id()); |
| 6527 | } |
| 6528 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6529 | // Test that when multiple sources try to install an extension, |
| 6530 | // we consistently choose the right one. To make tests easy to read, |
| 6531 | // methods that fake requests to install crx files in several ways |
| 6532 | // are provided. |
| 6533 | class ExtensionSourcePriorityTest : public ExtensionServiceTest { |
| 6534 | public: |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 6535 | virtual void SetUp() { |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6536 | ExtensionServiceTest::SetUp(); |
| 6537 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6538 | // All tests use a single extension. Put the id and path in member vars |
| 6539 | // that all methods can read. |
| 6540 | crx_id_ = kGoodId; |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 6541 | crx_path_ = data_dir_.AppendASCII("good.crx"); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6542 | } |
| 6543 | |
| 6544 | // Fake an external source adding a URL to fetch an extension from. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6545 | bool AddPendingExternalPrefUrl() { |
| 6546 | return service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 6547 | crx_id_, GURL(), Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 6548 | Extension::NO_FLAGS, false); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6549 | } |
| 6550 | |
| 6551 | // Fake an external file from external_extensions.json. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6552 | bool AddPendingExternalPrefFileInstall() { |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 6553 | Version version("1.0.0.0"); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6554 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6555 | return service_->OnExternalExtensionFileFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6556 | crx_id_, &version, crx_path_, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 6557 | Extension::NO_FLAGS, false); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6558 | } |
| 6559 | |
| 6560 | // Fake a request from sync to install an extension. |
| 6561 | bool AddPendingSyncInstall() { |
| 6562 | return service_->pending_extension_manager()->AddFromSync( |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 6563 | crx_id_, GURL(kGoodUpdateURL), &IsExtension, kGoodInstallSilently); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6564 | } |
| 6565 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6566 | // Fake a policy install. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6567 | bool AddPendingPolicyInstall() { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6568 | // Get path to the CRX with id |kGoodId|. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6569 | return service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 6570 | crx_id_, GURL(), Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 6571 | Extension::NO_FLAGS, false); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6572 | } |
| 6573 | |
| 6574 | // Get the install source of a pending extension. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6575 | Manifest::Location GetPendingLocation() { |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6576 | const extensions::PendingExtensionInfo* info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6577 | EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| 6578 | GetById(crx_id_))); |
| 6579 | return info->install_source(); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6580 | } |
| 6581 | |
| 6582 | // Is an extension pending from a sync request? |
| 6583 | bool GetPendingIsFromSync() { |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6584 | const extensions::PendingExtensionInfo* info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6585 | EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| 6586 | GetById(crx_id_))); |
| 6587 | return info->is_from_sync(); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6588 | } |
| 6589 | |
| 6590 | // Is the CRX id these tests use pending? |
| 6591 | bool IsCrxPending() { |
| 6592 | return service_->pending_extension_manager()->IsIdPending(crx_id_); |
| 6593 | } |
| 6594 | |
| 6595 | // Is an extension installed? |
| 6596 | bool IsCrxInstalled() { |
| 6597 | return (service_->GetExtensionById(crx_id_, true) != NULL); |
| 6598 | } |
| 6599 | |
| 6600 | protected: |
| 6601 | // All tests use a single extension. Making the id and path member |
| 6602 | // vars avoids pasing the same argument to every method. |
| 6603 | std::string crx_id_; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6604 | base::FilePath crx_path_; |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6605 | }; |
| 6606 | |
[email protected] | 3634ebd | 2011-04-20 00:34:12 | [diff] [blame] | 6607 | // Test that a pending request for installation of an external CRX from |
| 6608 | // an update URL overrides a pending request to install the same extension |
| 6609 | // from sync. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6610 | TEST_F(ExtensionSourcePriorityTest, PendingExternalFileOverSync) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6611 | InitializeEmptyExtensionService(); |
| 6612 | |
| 6613 | ASSERT_FALSE(IsCrxInstalled()); |
| 6614 | |
| 6615 | // Install pending extension from sync. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6616 | content::WindowedNotificationObserver observer( |
| 6617 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6618 | content::NotificationService::AllSources()); |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6619 | EXPECT_TRUE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6620 | ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6621 | EXPECT_TRUE(GetPendingIsFromSync()); |
| 6622 | ASSERT_FALSE(IsCrxInstalled()); |
| 6623 | |
| 6624 | // Install pending as external prefs json would. |
| 6625 | AddPendingExternalPrefFileInstall(); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6626 | ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6627 | ASSERT_FALSE(IsCrxInstalled()); |
| 6628 | |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6629 | // Another request from sync should be ignored. |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6630 | EXPECT_FALSE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6631 | ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6632 | ASSERT_FALSE(IsCrxInstalled()); |
| 6633 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6634 | observer.Wait(); |
| 6635 | VerifyCrxInstall(crx_path_, INSTALL_NEW); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6636 | ASSERT_TRUE(IsCrxInstalled()); |
| 6637 | } |
| 6638 | |
| 6639 | // Test that an install of an external CRX from an update overrides |
| 6640 | // an install of the same extension from sync. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6641 | TEST_F(ExtensionSourcePriorityTest, PendingExternalUrlOverSync) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6642 | InitializeEmptyExtensionService(); |
| 6643 | ASSERT_FALSE(IsCrxInstalled()); |
| 6644 | |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6645 | EXPECT_TRUE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6646 | ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6647 | EXPECT_TRUE(GetPendingIsFromSync()); |
| 6648 | ASSERT_FALSE(IsCrxInstalled()); |
| 6649 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6650 | ASSERT_TRUE(AddPendingExternalPrefUrl()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6651 | ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6652 | EXPECT_FALSE(GetPendingIsFromSync()); |
| 6653 | ASSERT_FALSE(IsCrxInstalled()); |
| 6654 | |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6655 | EXPECT_FALSE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6656 | ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6657 | EXPECT_FALSE(GetPendingIsFromSync()); |
| 6658 | ASSERT_FALSE(IsCrxInstalled()); |
| 6659 | } |
| 6660 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6661 | // Test that an external install request stops sync from installing |
| 6662 | // the same extension. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6663 | TEST_F(ExtensionSourcePriorityTest, InstallExternalBlocksSyncRequest) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6664 | InitializeEmptyExtensionService(); |
| 6665 | ASSERT_FALSE(IsCrxInstalled()); |
| 6666 | |
| 6667 | // External prefs starts an install. |
| 6668 | AddPendingExternalPrefFileInstall(); |
| 6669 | |
| 6670 | // Crx installer was made, but has not yet run. |
| 6671 | ASSERT_FALSE(IsCrxInstalled()); |
| 6672 | |
| 6673 | // Before the CRX installer runs, Sync requests that the same extension |
| 6674 | // be installed. Should fail, because an external source is pending. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6675 | content::WindowedNotificationObserver observer( |
| 6676 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6677 | content::NotificationService::AllSources()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6678 | ASSERT_FALSE(AddPendingSyncInstall()); |
| 6679 | |
| 6680 | // Wait for the external source to install. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6681 | observer.Wait(); |
| 6682 | VerifyCrxInstall(crx_path_, INSTALL_NEW); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6683 | ASSERT_TRUE(IsCrxInstalled()); |
| 6684 | |
| 6685 | // Now that the extension is installed, sync request should fail |
| 6686 | // because the extension is already installed. |
| 6687 | ASSERT_FALSE(AddPendingSyncInstall()); |
| 6688 | } |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6689 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6690 | // Test that installing an external extension displays a GlobalError. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6691 | TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 6692 | FeatureSwitch::ScopedOverride prompt( |
| 6693 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6694 | |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6695 | InitializeEmptyExtensionService(); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6696 | MockExtensionProvider* provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6697 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6698 | AddMockExternalProvider(provider); |
| 6699 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6700 | service_->UpdateExternalExtensionAlert(); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6701 | // Should return false, meaning there aren't any extensions that the user |
| 6702 | // needs to know about. |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6703 | EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6704 | |
| 6705 | // This is a normal extension, installed normally. |
| 6706 | // This should NOT trigger an alert. |
| 6707 | set_extensions_enabled(true); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6708 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6709 | InstallCRX(path, INSTALL_NEW); |
| 6710 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6711 | service_->CheckForExternalUpdates(); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 6712 | base::RunLoop().RunUntilIdle(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6713 | EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6714 | |
| 6715 | // A hosted app, installed externally. |
[email protected] | 2c495c4 | 2013-01-04 21:49:54 | [diff] [blame] | 6716 | // This should NOT trigger an alert. |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6717 | provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
| 6718 | data_dir_.AppendASCII("hosted_app.crx")); |
| 6719 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6720 | content::WindowedNotificationObserver observer( |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6721 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6722 | content::NotificationService::AllSources()); |
| 6723 | service_->CheckForExternalUpdates(); |
| 6724 | observer.Wait(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6725 | EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6726 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6727 | // Another normal extension, but installed externally. |
| 6728 | // This SHOULD trigger an alert. |
| 6729 | provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 6730 | data_dir_.AppendASCII("page_action.crx")); |
| 6731 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6732 | content::WindowedNotificationObserver observer2( |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6733 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6734 | content::NotificationService::AllSources()); |
| 6735 | service_->CheckForExternalUpdates(); |
| 6736 | observer2.Wait(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6737 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6738 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6739 | |
| 6740 | // Test that external extensions are initially disabled, and that enabling |
| 6741 | // them clears the prompt. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6742 | TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 6743 | FeatureSwitch::ScopedOverride prompt( |
| 6744 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6745 | |
| 6746 | InitializeEmptyExtensionService(); |
| 6747 | MockExtensionProvider* provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6748 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6749 | AddMockExternalProvider(provider); |
| 6750 | |
| 6751 | provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 6752 | data_dir_.AppendASCII("page_action.crx")); |
| 6753 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6754 | content::WindowedNotificationObserver observer( |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6755 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6756 | content::NotificationService::AllSources()); |
| 6757 | service_->CheckForExternalUpdates(); |
| 6758 | observer.Wait(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6759 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 6760 | EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); |
| 6761 | |
| 6762 | const Extension* extension = |
| 6763 | service_->disabled_extensions()->GetByID(page_action); |
| 6764 | EXPECT_TRUE(extension); |
| 6765 | EXPECT_EQ(page_action, extension->id()); |
| 6766 | |
| 6767 | service_->EnableExtension(page_action); |
| 6768 | EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 6769 | EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); |
| 6770 | } |
| 6771 | |
| 6772 | // Test that installing multiple external extensions works. |
[email protected] | 404d1a2 | 2013-09-20 17:28:07 | [diff] [blame] | 6773 | // Flaky on windows; http://crbug.com/295757 . |
| 6774 | #if defined(OS_WIN) |
| 6775 | #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple |
| 6776 | #else |
| 6777 | #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple |
| 6778 | #endif |
| 6779 | TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 6780 | FeatureSwitch::ScopedOverride prompt( |
| 6781 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6782 | |
| 6783 | InitializeEmptyExtensionService(); |
| 6784 | MockExtensionProvider* provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6785 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6786 | AddMockExternalProvider(provider); |
| 6787 | |
| 6788 | provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 6789 | data_dir_.AppendASCII("page_action.crx")); |
| 6790 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 6791 | data_dir_.AppendASCII("good.crx")); |
| 6792 | provider->UpdateOrAddExtension(theme_crx, "2.0", |
| 6793 | data_dir_.AppendASCII("theme.crx")); |
| 6794 | |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6795 | int count = 3; |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6796 | content::WindowedNotificationObserver observer( |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6797 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6798 | base::Bind(&WaitForCountNotificationsCallback, &count)); |
| 6799 | service_->CheckForExternalUpdates(); |
| 6800 | observer.Wait(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6801 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 6802 | EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); |
| 6803 | EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 6804 | EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx)); |
| 6805 | |
| 6806 | service_->EnableExtension(page_action); |
| 6807 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6808 | EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6809 | service_->EnableExtension(theme_crx); |
| 6810 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6811 | EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6812 | service_->EnableExtension(good_crx); |
| 6813 | EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6814 | EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
| 6815 | } |
| 6816 | |
| 6817 | // Test that there is a bubble for external extensions that update |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 6818 | // from the webstore if the profile is not new. |
| 6819 | TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) { |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6820 | FeatureSwitch::ScopedOverride prompt( |
| 6821 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6822 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 6823 | // This sets up the ExtensionPrefs used by our ExtensionService to be |
| 6824 | // post-first run. |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 6825 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 6826 | params.is_first_run = false; |
| 6827 | InitializeExtensionService(params); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6828 | |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6829 | base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); |
| 6830 | PackCRX(data_dir_.AppendASCII("update_from_webstore"), |
| 6831 | data_dir_.AppendASCII("update_from_webstore.pem"), |
| 6832 | crx_path); |
| 6833 | |
| 6834 | MockExtensionProvider* provider = |
| 6835 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 6836 | AddMockExternalProvider(provider); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6837 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6838 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6839 | content::WindowedNotificationObserver observer( |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6840 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6841 | content::NotificationService::AllSources()); |
| 6842 | service_->CheckForExternalUpdates(); |
| 6843 | observer.Wait(); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6844 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 6845 | EXPECT_TRUE(extensions::HasExternalInstallBubble(service_)); |
| 6846 | EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6847 | } |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6848 | |
| 6849 | // Test that there is no bubble for external extensions if the profile is new. |
| 6850 | TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) { |
| 6851 | FeatureSwitch::ScopedOverride prompt( |
| 6852 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6853 | |
| 6854 | InitializeEmptyExtensionService(); |
| 6855 | |
| 6856 | base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); |
| 6857 | PackCRX(data_dir_.AppendASCII("update_from_webstore"), |
| 6858 | data_dir_.AppendASCII("update_from_webstore.pem"), |
| 6859 | crx_path); |
| 6860 | |
| 6861 | MockExtensionProvider* provider = |
| 6862 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 6863 | AddMockExternalProvider(provider); |
| 6864 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
| 6865 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6866 | content::WindowedNotificationObserver observer( |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6867 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6868 | content::NotificationService::AllSources()); |
| 6869 | service_->CheckForExternalUpdates(); |
| 6870 | observer.Wait(); |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6871 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 6872 | EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
| 6873 | EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
| 6874 | } |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6875 | |
| 6876 | TEST_F(ExtensionServiceTest, InstallBlacklistedExtension) { |
| 6877 | InitializeEmptyExtensionService(); |
| 6878 | |
| 6879 | scoped_refptr<Extension> extension = extensions::ExtensionBuilder() |
| 6880 | .SetManifest(extensions::DictionaryBuilder() |
| 6881 | .Set("name", "extension") |
| 6882 | .Set("version", "1.0") |
| 6883 | .Set("manifest_version", 2).Build()) |
| 6884 | .Build(); |
| 6885 | ASSERT_TRUE(extension.get()); |
| 6886 | const std::string& id = extension->id(); |
| 6887 | |
| 6888 | std::set<std::string> id_set; |
| 6889 | id_set.insert(id); |
| 6890 | extensions::ExtensionNotificationObserver notifications( |
| 6891 | content::NotificationService::AllSources(), id_set); |
| 6892 | |
| 6893 | // Installation should be allowed but the extension should never have been |
| 6894 | // loaded and it should be blacklisted in prefs. |
| 6895 | service_->OnExtensionInstalled( |
| 6896 | extension.get(), |
| 6897 | syncer::StringOrdinal(), |
| 6898 | false /* has requirement errors */, |
[email protected] | 8e289f0b | 2013-12-17 17:49:07 | [diff] [blame] | 6899 | extensions::BLACKLISTED_MALWARE, |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6900 | false /* wait for idle */); |
[email protected] | eedc1c75 | 2013-08-09 18:51:55 | [diff] [blame] | 6901 | base::RunLoop().RunUntilIdle(); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6902 | |
| 6903 | // Extension was installed but not loaded. |
| 6904 | EXPECT_TRUE(notifications.CheckNotifications( |
| 6905 | chrome::NOTIFICATION_EXTENSION_INSTALLED)); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6906 | EXPECT_TRUE(service_->GetInstalledExtension(id)); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 6907 | |
| 6908 | ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
| 6909 | EXPECT_FALSE(registry->enabled_extensions().Contains(id)); |
| 6910 | EXPECT_TRUE(registry->blacklisted_extensions().Contains(id)); |
| 6911 | |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6912 | EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id)); |
| 6913 | EXPECT_TRUE( |
| 6914 | service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id)); |
| 6915 | } |
[email protected] | 59ee99d | 2013-10-11 15:46:16 | [diff] [blame] | 6916 | |
| 6917 | TEST_F(ExtensionServiceTest, ReconcileKnownDisabledNoneDisabled) { |
| 6918 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 6919 | InitializeGoodInstalledExtensionService(); |
| 6920 | |
| 6921 | // Initializing shouldn't disable any extensions if none are known to be |
| 6922 | // disabled. |
| 6923 | service_->Init(); |
| 6924 | |
| 6925 | extensions::ExtensionIdSet expected_extensions; |
| 6926 | expected_extensions.insert(good0); |
| 6927 | expected_extensions.insert(good1); |
| 6928 | expected_extensions.insert(good2); |
| 6929 | |
| 6930 | extensions::ExtensionIdSet expected_disabled_extensions; |
| 6931 | |
| 6932 | EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); |
| 6933 | EXPECT_EQ(expected_disabled_extensions, |
| 6934 | service_->disabled_extensions()->GetIDs()); |
| 6935 | } |
| 6936 | |
| 6937 | TEST_F(ExtensionServiceTest, ReconcileKnownDisabledWithSideEnable) { |
| 6938 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 6939 | InitializeGoodInstalledExtensionService(); |
| 6940 | |
| 6941 | ExtensionPrefs* extension_prefs = service_->extension_prefs(); |
| 6942 | |
| 6943 | // Disable good1. |
| 6944 | extension_prefs->SetExtensionState(good1, Extension::DISABLED); |
| 6945 | |
| 6946 | // Mark both good1 and good2 as "known_disabled" (effectively making good2 |
| 6947 | // look as if it had been side-enabled). |
| 6948 | extensions::ExtensionIdSet known_disabled; |
| 6949 | known_disabled.insert(good1); |
| 6950 | known_disabled.insert(good2); |
| 6951 | extension_prefs->SetKnownDisabled(known_disabled); |
| 6952 | |
| 6953 | // Initialize the service (which should disable good2 since it's known to be |
| 6954 | // disabled). |
| 6955 | service_->Init(); |
| 6956 | |
| 6957 | extensions::ExtensionIdSet expected_extensions; |
| 6958 | expected_extensions.insert(good0); |
| 6959 | |
| 6960 | extensions::ExtensionIdSet expected_disabled_extensions; |
| 6961 | expected_disabled_extensions.insert(good1); |
| 6962 | expected_disabled_extensions.insert(good2); |
| 6963 | |
| 6964 | EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); |
| 6965 | EXPECT_EQ(expected_disabled_extensions, |
| 6966 | service_->disabled_extensions()->GetIDs()); |
| 6967 | |
| 6968 | // Make sure that re-enabling an extension sticks across calls to |
| 6969 | // ReconcileKnownDisabled(). |
| 6970 | service_->EnableExtension(good2); |
| 6971 | service_->ReconcileKnownDisabled(); |
| 6972 | expected_extensions.insert(good2); |
| 6973 | expected_disabled_extensions.erase(good2); |
| 6974 | |
| 6975 | EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); |
| 6976 | EXPECT_EQ(expected_disabled_extensions, |
| 6977 | service_->disabled_extensions()->GetIDs()); |
| 6978 | } |