[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 | |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 5 | #include "chrome/browser/extensions/extension_service.h" |
| 6 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 9 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 10 | #include <algorithm> |
treib | 9afc621 | 2015-10-30 18:49:58 | [diff] [blame] | 11 | #include <map> |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 12 | #include <memory> |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 13 | #include <set> |
treib | 9afc621 | 2015-10-30 18:49:58 | [diff] [blame] | 14 | #include <string> |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 15 | #include <utility> |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
[email protected] | be5a6db | 2012-11-13 14:39:11 | [diff] [blame] | 18 | #include "base/at_exit.h" |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 19 | #include "base/bind.h" |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 20 | #include "base/command_line.h" |
[email protected] | 25a4c1c | 2013-06-08 04:53:36 | [diff] [blame] | 21 | #include "base/files/file_enumerator.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 22 | #include "base/files/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 23 | #include "base/files/scoped_temp_dir.h" |
[email protected] | ffbec69 | 2012-02-26 20:26:42 | [diff] [blame] | 24 | #include "base/json/json_file_value_serializer.h" |
[email protected] | 93d49d7 | 2009-10-23 20:00:20 | [diff] [blame] | 25 | #include "base/json/json_reader.h" |
[email protected] | ffbec69 | 2012-02-26 20:26:42 | [diff] [blame] | 26 | #include "base/json/json_string_value_serializer.h" |
skyostil | f221b7de | 2015-06-11 20:36:32 | [diff] [blame] | 27 | #include "base/location.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 28 | #include "base/macros.h" |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 29 | #include "base/memory/ptr_util.h" |
fdoray | cb32419d | 2016-06-23 15:52:55 | [diff] [blame] | 30 | #include "base/run_loop.h" |
skyostil | f221b7de | 2015-06-11 20:36:32 | [diff] [blame] | 31 | #include "base/single_thread_task_runner.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 32 | #include "base/stl_util.h" |
brettw | d97eede | 2015-07-06 22:09:00 | [diff] [blame] | 33 | #include "base/strings/pattern.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 34 | #include "base/strings/string16.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 35 | #include "base/strings/string_number_conversions.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 36 | #include "base/strings/string_util.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 37 | #include "base/strings/utf_string_conversions.h" |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 38 | #include "base/values.h" |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 39 | #include "base/version.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 40 | #include "build/build_config.h" |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 41 | #include "chrome/browser/browser_process.h" |
[email protected] | 9ea0cd3 | 2013-07-12 01:50:36 | [diff] [blame] | 42 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 43 | #include "chrome/browser/extensions/blacklist.h" |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 44 | #include "chrome/browser/extensions/chrome_app_sorting.h" |
rdevlin.cronin | f87d15f | 2017-01-26 22:57:19 | [diff] [blame] | 45 | #include "chrome/browser/extensions/chrome_test_extension_loader.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 46 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | eb6c7ef | 2011-12-12 23:12:20 | [diff] [blame] | 47 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 48 | #include "chrome/browser/extensions/default_apps.h" |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 49 | #include "chrome/browser/extensions/extension_creator.h" |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 50 | #include "chrome/browser/extensions/extension_error_ui.h" |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 51 | #include "chrome/browser/extensions/extension_management_test_util.h" |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 52 | #include "chrome/browser/extensions/extension_service_test_base.h" |
treib | 9afc621 | 2015-10-30 18:49:58 | [diff] [blame] | 53 | #include "chrome/browser/extensions/extension_service_test_with_install.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 54 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 55 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 56 | #include "chrome/browser/extensions/external_install_error.h" |
| 57 | #include "chrome/browser/extensions/external_install_manager.h" |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 58 | #include "chrome/browser/extensions/external_policy_loader.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 59 | #include "chrome/browser/extensions/external_pref_loader.h" |
| 60 | #include "chrome/browser/extensions/external_provider_impl.h" |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 61 | #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 62 | #include "chrome/browser/extensions/installed_loader.h" |
Devlin Cronin | 9722a72 | 2017-12-16 03:35:10 | [diff] [blame] | 63 | #include "chrome/browser/extensions/load_error_reporter.h" |
[email protected] | f0bfe62 | 2012-06-22 01:01:44 | [diff] [blame] | 64 | #include "chrome/browser/extensions/pack_extension_job.h" |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 65 | #include "chrome/browser/extensions/pending_extension_info.h" |
| 66 | #include "chrome/browser/extensions/pending_extension_manager.h" |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 67 | #include "chrome/browser/extensions/permissions_updater.h" |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 68 | #include "chrome/browser/extensions/test_blacklist.h" |
Devlin Cronin | a7baea2 | 2017-12-12 14:43:05 | [diff] [blame] | 69 | #include "chrome/browser/extensions/test_extension_dir.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 70 | #include "chrome/browser/extensions/test_extension_system.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 71 | #include "chrome/browser/extensions/unpacked_installer.h" |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 72 | #include "chrome/browser/extensions/updater/extension_updater.h" |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 73 | #include "chrome/browser/policy/profile_policy_connector.h" |
| 74 | #include "chrome/browser/policy/profile_policy_connector_factory.h" |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 75 | #include "chrome/browser/ui/global_error/global_error.h" |
| 76 | #include "chrome/browser/ui/global_error/global_error_service.h" |
| 77 | #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 78 | #include "chrome/common/chrome_constants.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 79 | #include "chrome/common/chrome_switches.h" |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 80 | #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 81 | #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 82 | #include "chrome/common/pref_names.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 83 | #include "chrome/common/url_constants.h" |
thestig | 4a9b0ef | 2016-08-29 08:22:12 | [diff] [blame] | 84 | #include "chrome/grit/browser_resources.h" |
| 85 | #include "chrome/grit/generated_resources.h" |
[email protected] | 078c319 | 2013-08-22 08:18:05 | [diff] [blame] | 86 | #include "chrome/test/base/scoped_browser_locale.h" |
[email protected] | a4ff9eae | 2011-08-01 19:58:16 | [diff] [blame] | 87 | #include "chrome/test/base/testing_profile.h" |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 88 | #include "components/crx_file/id_util.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 89 | #include "components/pref_registry/pref_registry_syncable.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 90 | #include "components/prefs/scoped_user_pref_update.h" |
skym | 7160384 | 2016-10-10 18:17:31 | [diff] [blame] | 91 | #include "components/sync/model/string_ordinal.h" |
maxbogue | ea16ff41 | 2016-10-28 16:35:29 | [diff] [blame] | 92 | #include "components/sync_preferences/pref_service_syncable.h" |
| 93 | #include "components/sync_preferences/testing_pref_service_syncable.h" |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 94 | #include "content/public/browser/dom_storage_context.h" |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 95 | #include "content/public/browser/gpu_data_manager.h" |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 96 | #include "content/public/browser/indexed_db_context.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 97 | #include "content/public/browser/notification_service.h" |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 98 | #include "content/public/browser/plugin_service.h" |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 99 | #include "content/public/browser/render_process_host.h" |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 100 | #include "content/public/browser/storage_partition.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 101 | #include "content/public/common/content_constants.h" |
skyostil | 0becb33 | 2015-04-27 17:59:37 | [diff] [blame] | 102 | #include "content/public/test/test_browser_thread_bundle.h" |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 103 | #include "content/public/test/test_utils.h" |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 104 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 105 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 106 | #include "extensions/browser/extension_system.h" |
karandeepb | 810e3340 | 2017-04-05 23:41:22 | [diff] [blame] | 107 | #include "extensions/browser/extension_util.h" |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 108 | #include "extensions/browser/external_install_info.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 109 | #include "extensions/browser/external_provider_interface.h" |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 110 | #include "extensions/browser/install_flag.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 111 | #include "extensions/browser/management_policy.h" |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 112 | #include "extensions/browser/mock_external_provider.h" |
limasdf | e1d046f | 2015-10-29 00:48:00 | [diff] [blame] | 113 | #include "extensions/browser/test_extension_registry_observer.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 114 | #include "extensions/browser/test_management_policy.h" |
[email protected] | e43c61f | 2014-07-20 21:46:34 | [diff] [blame] | 115 | #include "extensions/browser/uninstall_reason.h" |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 116 | #include "extensions/common/disable_reason.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 117 | #include "extensions/common/extension.h" |
[email protected] | 22b7b2c | 2013-11-05 22:52:42 | [diff] [blame] | 118 | #include "extensions/common/extension_builder.h" |
[email protected] | 6668e5d | 2014-04-08 23:32:52 | [diff] [blame] | 119 | #include "extensions/common/extension_l10n_util.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 120 | #include "extensions/common/extension_resource.h" |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 121 | #include "extensions/common/file_util.h" |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 122 | #include "extensions/common/manifest_constants.h" |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 123 | #include "extensions/common/manifest_handlers/background_info.h" |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 124 | #include "extensions/common/manifest_handlers/permissions_parser.h" |
rockot | d554614 | 2014-10-15 00:29:08 | [diff] [blame] | 125 | #include "extensions/common/manifest_url_handlers.h" |
[email protected] | 5a55f3f | 2013-10-29 01:08:29 | [diff] [blame] | 126 | #include "extensions/common/permissions/permission_set.h" |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 127 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | a612eb3 | 2014-03-31 22:09:17 | [diff] [blame] | 128 | #include "extensions/common/switches.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 129 | #include "extensions/common/url_pattern.h" |
[email protected] | 22b7b2c | 2013-11-05 22:52:42 | [diff] [blame] | 130 | #include "extensions/common/value_builder.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 131 | #include "net/cookies/cookie_options.h" |
mmenke | e28c9aa | 2016-01-20 23:54:04 | [diff] [blame] | 132 | #include "net/cookies/cookie_store.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 133 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 134 | #include "net/url_request/url_request_context_getter.h" |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 135 | #include "ppapi/features/features.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 136 | #include "storage/browser/database/database_tracker.h" |
| 137 | #include "storage/browser/quota/quota_manager.h" |
pilgrim | 1633055 | 2014-09-10 01:32:22 | [diff] [blame] | 138 | #include "storage/common/database/database_identifier.h" |
treib | 9afc621 | 2015-10-30 18:49:58 | [diff] [blame] | 139 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 140 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | f66c110c | 2008-12-05 20:26:29 | [diff] [blame] | 141 | #include "testing/platform_test.h" |
fatalerr | 2443c2df | 2014-10-31 19:14:35 | [diff] [blame] | 142 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 143 | #include "url/gurl.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 144 | |
nparker | 333f169b | 2015-04-18 13:33:07 | [diff] [blame] | 145 | // The blacklist tests rely on the safe-browsing database. |
| 146 | #if defined(SAFE_BROWSING_DB_LOCAL) |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 147 | #define ENABLE_BLACKLIST_TESTS |
| 148 | #endif |
| 149 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 150 | using content::BrowserContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 151 | using content::BrowserThread; |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 152 | using content::DOMStorageContext; |
| 153 | using content::IndexedDBContext; |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 154 | using content::PluginService; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 155 | using extensions::APIPermission; |
| 156 | using extensions::APIPermissionSet; |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 157 | using extensions::AppSorting; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 158 | using extensions::Blacklist; |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 159 | using extensions::CrxInstaller; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 160 | using extensions::Extension; |
Devlin Cronin | 05b047d | 2017-08-22 21:53:55 | [diff] [blame] | 161 | using extensions::ExtensionBuilder; |
[email protected] | 6d77749 | 2012-07-11 17:33:43 | [diff] [blame] | 162 | using extensions::ExtensionCreator; |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 163 | using extensions::ExtensionPrefs; |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 164 | using extensions::ExtensionRegistry; |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 165 | using extensions::ExtensionResource; |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 166 | using extensions::ExtensionSystem; |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 167 | using extensions::ExternalInstallError; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 168 | using extensions::ExternalInstallInfoFile; |
| 169 | using extensions::ExternalInstallInfoUpdateUrl; |
| 170 | using extensions::ExternalProviderInterface; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 171 | using extensions::FakeSafeBrowsingDatabaseManager; |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 172 | using extensions::FeatureSwitch; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 173 | using extensions::Manifest; |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 174 | using extensions::MockExternalProvider; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 175 | using extensions::PermissionSet; |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 176 | using extensions::TestExtensionSystem; |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 177 | using extensions::UnloadedExtensionReason; |
[email protected] | e9f541a | 2012-11-19 21:52:31 | [diff] [blame] | 178 | using extensions::URLPatternSet; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 179 | |
[email protected] | 6bf9061 | 2013-08-15 00:36:27 | [diff] [blame] | 180 | namespace keys = extensions::manifest_keys; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 181 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 182 | namespace { |
| 183 | |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 184 | // Extension ids used during testing. |
[email protected] | 095ccbe4 | 2013-09-26 00:06:42 | [diff] [blame] | 185 | const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 186 | const char good1[] = "hpiknbiabeeppbpihjehijgoemciehgk"; |
| 187 | const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; |
[email protected] | aa5219d | 2013-11-09 19:25:41 | [diff] [blame] | 188 | const char all_zero[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
[email protected] | 095ccbe4 | 2013-09-26 00:06:42 | [diff] [blame] | 189 | const char good2048[] = "nmgjhmhbleinmjpbdhgajfjkbijcmgbh"; |
| 190 | const char good_crx[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 191 | const char minimal_platform_app_crx[] = "jjeoclcdfjddkdjokiejckgcildcflpp"; |
[email protected] | 095ccbe4 | 2013-09-26 00:06:42 | [diff] [blame] | 192 | const char hosted_app[] = "kbmnembihfiondgfjekmnmcbddelicoi"; |
| 193 | const char page_action[] = "obcimlgaoabeegjmmpldobjndiealpln"; |
| 194 | const char theme_crx[] = "iamefpfkojoapidjnbafmgkgncegbkad"; |
| 195 | const char theme2_crx[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 196 | const char permissions_crx[] = "eagpmdpfmaekmmcejjbmjoecnejeiiin"; |
[email protected] | 095ccbe4 | 2013-09-26 00:06:42 | [diff] [blame] | 197 | const char updates_from_webstore[] = "akjooamlhcgeopfifcmlggaebeocgokj"; |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 198 | const char updates_from_webstore2[] = "oolblhbomdbcpmafphaodhjfcgbihcdg"; |
| 199 | const char updates_from_webstore3[] = "bmfoocgfinpmkmlbjhcbofejhkhlbchk"; |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 200 | const char permissions_blocklist[] = "noffkehfcaggllbcojjbopcmlhcnhcdn"; |
Takumi Fujimoto | 43c8c00f | 2017-07-26 22:48:56 | [diff] [blame] | 201 | const char cast_stable[] = "boadgeojelhgndaghljhdicfkmllpafd"; |
| 202 | const char cast_beta[] = "dliochdbjfkdbacpmhlcpmleaejidimm"; |
Tatsuhisa Yamaguchi | 5ed1aece3 | 2017-10-26 10:18:56 | [diff] [blame] | 203 | const char zip_unpacker[] = "oedeeodfidgoollimchfdnbmhcpnklnd"; |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 204 | |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 205 | struct BubbleErrorsTestData { |
| 206 | BubbleErrorsTestData(const std::string& id, |
| 207 | const std::string& version, |
| 208 | const base::FilePath& crx_path, |
| 209 | size_t expected_bubble_error_count) |
| 210 | : id(id), |
| 211 | version(version), |
| 212 | crx_path(crx_path), |
| 213 | expected_bubble_error_count(expected_bubble_error_count) {} |
| 214 | std::string id; |
| 215 | std::string version; |
| 216 | base::FilePath crx_path; |
| 217 | size_t expected_bubble_error_count; |
| 218 | bool expect_has_shown_bubble_view; |
| 219 | }; |
| 220 | |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 221 | static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 222 | int schemes = URLPattern::SCHEME_ALL; |
| 223 | extent->AddPattern(URLPattern(schemes, pattern)); |
| 224 | } |
| 225 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 226 | base::FilePath GetTemporaryFile() { |
| 227 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 228 | CHECK(base::CreateTemporaryFile(&temp_file)); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 229 | return temp_file; |
| 230 | } |
| 231 | |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 232 | bool WaitForCountNotificationsCallback(int *count) { |
| 233 | return --(*count) == 0; |
| 234 | } |
| 235 | |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 236 | bool HasExternalInstallErrors(ExtensionService* service) { |
| 237 | return !service->external_install_manager()->GetErrorsForTesting().empty(); |
| 238 | } |
| 239 | |
| 240 | bool HasExternalInstallBubble(ExtensionService* service) { |
| 241 | std::vector<ExternalInstallError*> errors = |
| 242 | service->external_install_manager()->GetErrorsForTesting(); |
| 243 | auto found = std::find_if( |
| 244 | errors.begin(), errors.end(), |
| 245 | [](const ExternalInstallError* error) { |
| 246 | return error->alert_type() == ExternalInstallError::BUBBLE_ALERT; |
| 247 | }); |
| 248 | return found != errors.end(); |
| 249 | } |
| 250 | |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 251 | size_t GetExternalInstallBubbleCount(ExtensionService* service) { |
| 252 | size_t bubble_count = 0u; |
| 253 | std::vector<ExternalInstallError*> errors = |
| 254 | service->external_install_manager()->GetErrorsForTesting(); |
vmpstr | ae72b08 | 2016-07-25 21:55:47 | [diff] [blame] | 255 | for (auto* error : errors) |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 256 | bubble_count += error->alert_type() == ExternalInstallError::BUBBLE_ALERT; |
| 257 | return bubble_count; |
| 258 | } |
| 259 | |
mtomasz | 622f70d2 | 2017-01-27 03:36:26 | [diff] [blame] | 260 | scoped_refptr<Extension> CreateExtension(const base::string16& name, |
| 261 | const base::FilePath& path, |
| 262 | Manifest::Location location) { |
| 263 | base::DictionaryValue manifest; |
| 264 | manifest.SetString(extensions::manifest_keys::kVersion, "1.0.0.0"); |
| 265 | manifest.SetString(extensions::manifest_keys::kName, name); |
| 266 | std::string error; |
| 267 | scoped_refptr<Extension> extension = |
| 268 | Extension::Create(path, location, manifest, Extension::NO_FLAGS, &error); |
| 269 | EXPECT_TRUE(extension.get() != nullptr) << error; |
| 270 | return extension; |
| 271 | } |
| 272 | |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 273 | std::unique_ptr<ExternalInstallInfoFile> CreateExternalExtension( |
| 274 | const extensions::ExtensionId& extension_id, |
| 275 | const std::string& version_str, |
| 276 | const base::FilePath& path, |
| 277 | Manifest::Location location, |
| 278 | Extension::InitFromValueFlags flags) { |
| 279 | return base::MakeUnique<ExternalInstallInfoFile>( |
Devlin Cronin | d4c2a8f3 | 2017-09-29 17:08:30 | [diff] [blame] | 280 | extension_id, base::Version(version_str), path, location, flags, false, |
| 281 | false); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 282 | } |
| 283 | |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 284 | // Helper function to persist the passed directories and file paths in |
| 285 | // |extension_dir|. Also, writes a generic manifest file. |
| 286 | void PersistExtensionWithPaths( |
| 287 | const base::FilePath& extension_dir, |
| 288 | const std::vector<base::FilePath>& directory_paths, |
| 289 | const std::vector<base::FilePath>& file_paths) { |
| 290 | for (const auto& directory : directory_paths) |
| 291 | EXPECT_TRUE(base::CreateDirectory(directory)); |
| 292 | |
| 293 | std::string data = "file_data"; |
| 294 | for (const auto& file : file_paths) { |
| 295 | EXPECT_EQ(static_cast<int>(data.size()), |
| 296 | base::WriteFile(file, data.c_str(), data.size())); |
| 297 | } |
| 298 | |
| 299 | std::unique_ptr<base::DictionaryValue> manifest = |
| 300 | extensions::DictionaryBuilder() |
| 301 | .Set(keys::kName, "Test extension") |
| 302 | .Set(keys::kVersion, "1.0") |
| 303 | .Set(keys::kManifestVersion, 2) |
| 304 | .Build(); |
| 305 | |
| 306 | // Persist manifest file. |
| 307 | base::FilePath manifest_path = |
| 308 | extension_dir.Append(extensions::kManifestFilename); |
| 309 | JSONFileValueSerializer(manifest_path).Serialize(*manifest); |
| 310 | EXPECT_TRUE(base::PathExists(manifest_path)); |
| 311 | } |
| 312 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 313 | } // namespace |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 314 | |
Istiaque Ahmed | 2a59ae0 | 2017-08-24 04:43:26 | [diff] [blame] | 315 | namespace extensions { |
| 316 | |
| 317 | // A simplified version of ExternalPrefLoader that loads the dictionary |
| 318 | // from json data specified in a string. |
| 319 | class ExternalTestingLoader : public ExternalLoader { |
| 320 | public: |
| 321 | ExternalTestingLoader(const std::string& json_data, |
| 322 | const base::FilePath& fake_base_path) |
| 323 | : fake_base_path_(fake_base_path) { |
| 324 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 325 | JSONStringValueDeserializer deserializer(json_data); |
| 326 | base::FilePath fake_json_path = fake_base_path.AppendASCII("fake.json"); |
| 327 | testing_prefs_ = ExternalPrefLoader::ExtractExtensionPrefs(&deserializer, |
| 328 | fake_json_path); |
| 329 | } |
| 330 | |
| 331 | // ExternalLoader: |
| 332 | const base::FilePath GetBaseCrxFilePath() override { return fake_base_path_; } |
| 333 | |
| 334 | void StartLoading() override { |
| 335 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Istiaque Ahmed | ef99c8ea | 2017-09-06 21:19:57 | [diff] [blame] | 336 | LoadFinished(testing_prefs_->CreateDeepCopy()); |
Istiaque Ahmed | 2a59ae0 | 2017-08-24 04:43:26 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | private: |
| 340 | friend class base::RefCountedThreadSafe<ExternalLoader>; |
| 341 | |
| 342 | ~ExternalTestingLoader() override {} |
| 343 | |
| 344 | base::FilePath fake_base_path_; |
| 345 | std::unique_ptr<base::DictionaryValue> testing_prefs_; |
| 346 | |
| 347 | DISALLOW_COPY_AND_ASSIGN(ExternalTestingLoader); |
| 348 | }; |
| 349 | |
| 350 | } // namespace extensions |
| 351 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 352 | class MockProviderVisitor |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 353 | : public extensions::ExternalProviderInterface::VisitorInterface { |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 354 | public: |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 355 | // The provider will return |fake_base_path| from |
| 356 | // GetBaseCrxFilePath(). User can test the behavior with |
| 357 | // and without an empty path using this parameter. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 358 | explicit MockProviderVisitor(base::FilePath fake_base_path) |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 359 | : ids_found_(0), |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 360 | fake_base_path_(fake_base_path), |
| 361 | expected_creation_flags_(Extension::NO_FLAGS) { |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 362 | profile_.reset(new TestingProfile); |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 363 | } |
| 364 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 365 | MockProviderVisitor(base::FilePath fake_base_path, |
| 366 | int expected_creation_flags) |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 367 | : ids_found_(0), |
| 368 | fake_base_path_(fake_base_path), |
| 369 | expected_creation_flags_(expected_creation_flags) { |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 370 | profile_.reset(new TestingProfile); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 371 | } |
| 372 | |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 373 | int Visit(const std::string& json_data) { |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 374 | return Visit(json_data, Manifest::EXTERNAL_PREF, |
| 375 | Manifest::EXTERNAL_PREF_DOWNLOAD); |
| 376 | } |
| 377 | |
| 378 | int Visit(const std::string& json_data, |
| 379 | Manifest::Location crx_location, |
| 380 | Manifest::Location download_location) { |
| 381 | crx_location_ = crx_location; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 382 | // Give the test json file to the provider for parsing. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 383 | provider_.reset(new extensions::ExternalProviderImpl( |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 384 | this, new extensions::ExternalTestingLoader(json_data, fake_base_path_), |
| 385 | profile_.get(), crx_location, download_location, Extension::NO_FLAGS)); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 386 | |
| 387 | // We also parse the file into a dictionary to compare what we get back |
| 388 | // from the provider. |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 389 | prefs_ = GetDictionaryFromJSON(json_data); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 390 | |
| 391 | // Reset our counter. |
| 392 | ids_found_ = 0; |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 393 | // Ask the provider to look up all extensions and return them. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 394 | provider_->VisitRegisteredExtension(); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 395 | |
| 396 | return ids_found_; |
| 397 | } |
| 398 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 399 | bool OnExternalExtensionFileFound( |
| 400 | const ExternalInstallInfoFile& info) override { |
| 401 | EXPECT_EQ(expected_creation_flags_, info.creation_flags); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 402 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 403 | ++ids_found_; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 404 | base::DictionaryValue* pref; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 405 | // This tests is to make sure that the provider only notifies us of the |
| 406 | // values we gave it. So if the id we doesn't exist in our internal |
| 407 | // dictionary then something is wrong. |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 408 | EXPECT_TRUE(prefs_->GetDictionary(info.extension_id, &pref)) |
| 409 | << "Got back ID (" << info.extension_id.c_str() |
| 410 | << ") we weren't expecting"; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 411 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 412 | EXPECT_TRUE(info.path.IsAbsolute()); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 413 | if (!fake_base_path_.empty()) |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 414 | EXPECT_TRUE(fake_base_path_.IsParent(info.path)); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 415 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 416 | if (pref) { |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 417 | EXPECT_TRUE(provider_->HasExtension(info.extension_id)); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 418 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 419 | // Ask provider if the extension we got back is registered. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 420 | Manifest::Location location = Manifest::INVALID_LOCATION; |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 421 | std::unique_ptr<base::Version> v1; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 422 | base::FilePath crx_path; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 423 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 424 | EXPECT_TRUE(provider_->GetExtensionDetails(info.extension_id, NULL, &v1)); |
Devlin Cronin | d4c2a8f3 | 2017-09-29 17:08:30 | [diff] [blame] | 425 | EXPECT_EQ(info.version.GetString(), v1->GetString()); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 426 | |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 427 | std::unique_ptr<base::Version> v2; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 428 | EXPECT_TRUE( |
| 429 | provider_->GetExtensionDetails(info.extension_id, &location, &v2)); |
Devlin Cronin | d4c2a8f3 | 2017-09-29 17:08:30 | [diff] [blame] | 430 | EXPECT_EQ(info.version.GetString(), v1->GetString()); |
| 431 | EXPECT_EQ(info.version.GetString(), v2->GetString()); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 432 | EXPECT_EQ(crx_location_, location); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 433 | |
| 434 | // Remove it so we won't count it ever again. |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 435 | prefs_->Remove(info.extension_id, NULL); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 436 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 437 | return true; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 438 | } |
| 439 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 440 | bool OnExternalExtensionUpdateUrlFound( |
| 441 | const ExternalInstallInfoUpdateUrl& info, |
| 442 | bool is_initial_load) override { |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 443 | ++ids_found_; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 444 | base::DictionaryValue* pref; |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 445 | // This tests is to make sure that the provider only notifies us of the |
| 446 | // values we gave it. So if the id we doesn't exist in our internal |
| 447 | // dictionary then something is wrong. |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 448 | EXPECT_TRUE(prefs_->GetDictionary(info.extension_id, &pref)) |
| 449 | << L"Got back ID (" << info.extension_id.c_str() |
| 450 | << ") we weren't expecting"; |
| 451 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, info.download_location); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 452 | |
| 453 | if (pref) { |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 454 | EXPECT_TRUE(provider_->HasExtension(info.extension_id)); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 455 | |
| 456 | // External extensions with update URLs do not have versions. |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 457 | std::unique_ptr<base::Version> v1; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 458 | Manifest::Location location1 = Manifest::INVALID_LOCATION; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 459 | EXPECT_TRUE( |
| 460 | provider_->GetExtensionDetails(info.extension_id, &location1, &v1)); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 461 | EXPECT_FALSE(v1.get()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 462 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 463 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 464 | std::string parsed_install_parameter; |
| 465 | pref->GetString("install_parameter", &parsed_install_parameter); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 466 | EXPECT_EQ(parsed_install_parameter, info.install_parameter); |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 467 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 468 | // Remove it so we won't count it again. |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 469 | prefs_->Remove(info.extension_id, NULL); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 470 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 471 | return true; |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 472 | } |
| 473 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 474 | void OnExternalProviderUpdateComplete( |
| 475 | const ExternalProviderInterface* provider, |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 476 | const std::vector<ExternalInstallInfoUpdateUrl>& update_url_extensions, |
| 477 | const std::vector<ExternalInstallInfoFile>& file_extensions, |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 478 | const std::set<std::string>& removed_extensions) override { |
| 479 | ADD_FAILURE() << "MockProviderVisitor does not provide incremental updates," |
| 480 | " use MockUpdateProviderVisitor instead."; |
| 481 | } |
| 482 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 483 | void OnExternalProviderReady( |
mostynb | a15bee1 | 2014-10-04 00:40:32 | [diff] [blame] | 484 | const extensions::ExternalProviderInterface* provider) override { |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 485 | EXPECT_EQ(provider, provider_.get()); |
| 486 | EXPECT_TRUE(provider->IsReady()); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 487 | } |
| 488 | |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 489 | Profile* profile() { return profile_.get(); } |
| 490 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 491 | protected: |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 492 | std::unique_ptr<extensions::ExternalProviderImpl> provider_; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 493 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 494 | std::unique_ptr<base::DictionaryValue> GetDictionaryFromJSON( |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 495 | const std::string& json_data) { |
| 496 | // We also parse the file into a dictionary to compare what we get back |
| 497 | // from the provider. |
| 498 | JSONStringValueDeserializer deserializer(json_data); |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 499 | std::unique_ptr<base::Value> json_value = |
| 500 | deserializer.Deserialize(NULL, NULL); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 501 | |
jdoerrie | 1f536b2 | 2017-10-23 17:15:11 | [diff] [blame] | 502 | if (!json_value || !json_value->is_dict()) { |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 503 | ADD_FAILURE() << "Unable to deserialize json data"; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 504 | return std::unique_ptr<base::DictionaryValue>(); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 505 | } else { |
| 506 | return base::DictionaryValue::From(std::move(json_value)); |
| 507 | } |
| 508 | } |
| 509 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 510 | private: |
| 511 | int ids_found_; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 512 | base::FilePath fake_base_path_; |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 513 | int expected_creation_flags_; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 514 | Manifest::Location crx_location_; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 515 | std::unique_ptr<base::DictionaryValue> prefs_; |
| 516 | std::unique_ptr<TestingProfile> profile_; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 517 | |
| 518 | DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 519 | }; |
| 520 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 521 | // Mock provider that can simulate incremental update like |
| 522 | // ExternalRegistryLoader. |
| 523 | class MockUpdateProviderVisitor : public MockProviderVisitor { |
| 524 | public: |
| 525 | // The provider will return |fake_base_path| from |
| 526 | // GetBaseCrxFilePath(). User can test the behavior with |
| 527 | // and without an empty path using this parameter. |
| 528 | explicit MockUpdateProviderVisitor(base::FilePath fake_base_path) |
| 529 | : MockProviderVisitor(fake_base_path) {} |
| 530 | |
| 531 | void VisitDueToUpdate(const std::string& json_data) { |
| 532 | update_url_extension_ids_.clear(); |
| 533 | file_extension_ids_.clear(); |
| 534 | removed_extension_ids_.clear(); |
| 535 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 536 | std::unique_ptr<base::DictionaryValue> new_prefs = |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 537 | GetDictionaryFromJSON(json_data); |
| 538 | if (!new_prefs) |
| 539 | return; |
Istiaque Ahmed | a7431b3 | 2017-08-20 18:33:37 | [diff] [blame] | 540 | provider_->UpdatePrefs(std::move(new_prefs)); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | void OnExternalProviderUpdateComplete( |
| 544 | const ExternalProviderInterface* provider, |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 545 | const std::vector<ExternalInstallInfoUpdateUrl>& update_url_extensions, |
| 546 | const std::vector<ExternalInstallInfoFile>& file_extensions, |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 547 | const std::set<std::string>& removed_extensions) override { |
lazyboy | 4aeef20 | 2016-09-07 21:28:59 | [diff] [blame] | 548 | for (const auto& extension_info : update_url_extensions) |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 549 | update_url_extension_ids_.insert(extension_info.extension_id); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 550 | EXPECT_EQ(update_url_extension_ids_.size(), update_url_extensions.size()); |
| 551 | |
lazyboy | 4aeef20 | 2016-09-07 21:28:59 | [diff] [blame] | 552 | for (const auto& extension_info : file_extensions) |
Devlin Cronin | 19f70b6a | 2017-10-01 04:14:05 | [diff] [blame] | 553 | file_extension_ids_.insert(extension_info.extension_id); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 554 | EXPECT_EQ(file_extension_ids_.size(), file_extensions.size()); |
| 555 | |
| 556 | for (const auto& extension_id : removed_extensions) |
| 557 | removed_extension_ids_.insert(extension_id); |
| 558 | } |
| 559 | |
| 560 | size_t GetUpdateURLExtensionCount() { |
| 561 | return update_url_extension_ids_.size(); |
| 562 | } |
| 563 | size_t GetFileExtensionCount() { return file_extension_ids_.size(); } |
| 564 | size_t GetRemovedExtensionCount() { return removed_extension_ids_.size(); } |
| 565 | |
| 566 | bool HasSeenUpdateWithUpdateUrl(const std::string& extension_id) { |
| 567 | return update_url_extension_ids_.count(extension_id) > 0u; |
| 568 | } |
| 569 | bool HasSeenUpdateWithFile(const std::string& extension_id) { |
| 570 | return file_extension_ids_.count(extension_id) > 0u; |
| 571 | } |
| 572 | bool HasSeenRemoval(const std::string& extension_id) { |
| 573 | return removed_extension_ids_.count(extension_id) > 0u; |
| 574 | } |
| 575 | |
| 576 | private: |
| 577 | std::set<std::string> update_url_extension_ids_; |
| 578 | std::set<std::string> file_extension_ids_; |
| 579 | std::set<std::string> removed_extension_ids_; |
| 580 | |
| 581 | DISALLOW_COPY_AND_ASSIGN(MockUpdateProviderVisitor); |
| 582 | }; |
| 583 | |
treib | 9afc621 | 2015-10-30 18:49:58 | [diff] [blame] | 584 | class ExtensionServiceTest |
| 585 | : public extensions::ExtensionServiceTestWithInstall { |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 586 | public: |
Gabriel Charette | 4a7f5ac | 2017-06-14 21:54:07 | [diff] [blame] | 587 | ExtensionServiceTest() = default; |
wkorman | a08d7c0 | 2015-11-17 21:43:38 | [diff] [blame] | 588 | |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 589 | MockExternalProvider* AddMockExternalProvider(Manifest::Location location) { |
| 590 | auto provider = base::MakeUnique<MockExternalProvider>(service(), location); |
| 591 | MockExternalProvider* provider_ptr = provider.get(); |
| 592 | service()->AddProviderForTesting(std::move(provider)); |
| 593 | return provider_ptr; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 594 | } |
| 595 | |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 596 | // Checks for external extensions and waits for one to complete installing. |
| 597 | void WaitForExternalExtensionInstalled() { |
| 598 | content::WindowedNotificationObserver observer( |
| 599 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
| 600 | content::NotificationService::AllSources()); |
| 601 | service()->CheckForExternalUpdates(); |
| 602 | observer.Wait(); |
| 603 | } |
| 604 | |
[email protected] | 9197f3b | 2009-06-02 00:49:27 | [diff] [blame] | 605 | protected: |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 606 | void TestExternalProvider(MockExternalProvider* provider, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 607 | Manifest::Location location); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 608 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 609 | // Grants all optional permissions stated in manifest to active permission |
| 610 | // set for extension |id|. |
| 611 | void GrantAllOptionalPermissions(const std::string& id) { |
| 612 | const Extension* extension = service()->GetInstalledExtension(id); |
rdevlin.cronin | d630c30 | 2015-09-30 20:19:33 | [diff] [blame] | 613 | const PermissionSet& all_optional_permissions = |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 614 | extensions::PermissionsParser::GetOptionalPermissions(extension); |
| 615 | extensions::PermissionsUpdater perms_updater(profile()); |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 616 | perms_updater.AddPermissions(extension, all_optional_permissions); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 617 | } |
| 618 | |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 619 | testing::AssertionResult IsBlocked(const std::string& id) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 620 | std::unique_ptr<extensions::ExtensionSet> all_unblocked_extensions = |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 621 | registry()->GenerateInstalledExtensionsSet( |
| 622 | ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::BLOCKED); |
rdevlin.cronin | 165732a4 | 2016-07-18 22:25:08 | [diff] [blame] | 623 | if (all_unblocked_extensions->Contains(id)) |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 624 | return testing::AssertionFailure() << id << " is still unblocked!"; |
| 625 | if (!registry()->blocked_extensions().Contains(id)) |
| 626 | return testing::AssertionFailure() << id << " is not blocked!"; |
| 627 | return testing::AssertionSuccess(); |
| 628 | } |
| 629 | |
| 630 | // Helper method to test that an extension moves through being blocked and |
| 631 | // unblocked as appropriate for its type. |
| 632 | void AssertExtensionBlocksAndUnblocks( |
| 633 | bool should_block, const std::string extension_id) { |
| 634 | // Assume we start in an unblocked state. |
| 635 | EXPECT_FALSE(IsBlocked(extension_id)); |
| 636 | |
| 637 | // Block the extensions. |
| 638 | service()->BlockAllExtensions(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 639 | content::RunAllTasksUntilIdle(); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 640 | |
| 641 | if (should_block) |
| 642 | ASSERT_TRUE(IsBlocked(extension_id)); |
| 643 | else |
| 644 | ASSERT_FALSE(IsBlocked(extension_id)); |
| 645 | |
| 646 | service()->UnblockAllExtensions(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 647 | content::RunAllTasksUntilIdle(); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 648 | |
| 649 | ASSERT_FALSE(IsBlocked(extension_id)); |
| 650 | } |
| 651 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 652 | bool IsPrefExist(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 653 | const std::string& pref_path) { |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 654 | const base::DictionaryValue* dict = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 655 | profile()->GetPrefs()->GetDictionary("extensions.settings"); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 656 | if (dict == NULL) return false; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 657 | const base::DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 658 | if (!dict->GetDictionary(extension_id, &pref)) { |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 659 | return false; |
| 660 | } |
| 661 | if (pref == NULL) { |
| 662 | return false; |
| 663 | } |
| 664 | bool val; |
| 665 | if (!pref->GetBoolean(pref_path, &val)) { |
| 666 | return false; |
| 667 | } |
| 668 | return true; |
| 669 | } |
| 670 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 671 | void SetPref(const std::string& extension_id, |
| 672 | const std::string& pref_path, |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 673 | std::unique_ptr<base::Value> value, |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 674 | const std::string& msg) { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 675 | DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings"); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 676 | base::DictionaryValue* dict = update.Get(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 677 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 678 | base::DictionaryValue* pref = NULL; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 679 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| 680 | EXPECT_TRUE(pref != NULL) << msg; |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 681 | pref->Set(pref_path, std::move(value)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 682 | } |
| 683 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 684 | void SetPrefInteg(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 685 | const std::string& pref_path, |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 686 | int value) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 687 | std::string msg = " while setting: "; |
| 688 | msg += extension_id; |
| 689 | msg += " "; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 690 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 691 | msg += " = "; |
| 692 | msg += base::IntToString(value); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 693 | |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 694 | SetPref(extension_id, pref_path, base::MakeUnique<base::Value>(value), msg); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | void SetPrefBool(const std::string& extension_id, |
| 698 | const std::string& pref_path, |
| 699 | bool value) { |
| 700 | std::string msg = " while setting: "; |
| 701 | msg += extension_id + " " + pref_path; |
| 702 | msg += " = "; |
| 703 | msg += (value ? "true" : "false"); |
| 704 | |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 705 | SetPref(extension_id, pref_path, base::MakeUnique<base::Value>(value), msg); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | void ClearPref(const std::string& extension_id, |
| 709 | const std::string& pref_path) { |
| 710 | std::string msg = " while clearing: "; |
| 711 | msg += extension_id + " " + pref_path; |
| 712 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 713 | DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings"); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 714 | base::DictionaryValue* dict = update.Get(); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 715 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 716 | base::DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 717 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 718 | EXPECT_TRUE(pref != NULL) << msg; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 719 | pref->Remove(pref_path, NULL); |
| 720 | } |
| 721 | |
| 722 | void SetPrefStringSet(const std::string& extension_id, |
| 723 | const std::string& pref_path, |
| 724 | const std::set<std::string>& value) { |
| 725 | std::string msg = " while setting: "; |
| 726 | msg += extension_id + " " + pref_path; |
| 727 | |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 728 | auto list_value = base::MakeUnique<base::ListValue>(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 729 | for (std::set<std::string>::const_iterator iter = value.begin(); |
| 730 | iter != value.end(); ++iter) |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 731 | list_value->AppendString(*iter); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 732 | |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 733 | SetPref(extension_id, pref_path, std::move(list_value), msg); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 734 | } |
| 735 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 736 | void InitPluginService() { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 737 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 738 | PluginService::GetInstance()->Init(); |
| 739 | #endif |
| 740 | } |
| 741 | |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 742 | void InitializeEmptyExtensionServiceWithTestingPrefs() { |
| 743 | ExtensionServiceTestBase::ExtensionServiceInitParams params = |
| 744 | CreateDefaultInitParams(); |
| 745 | params.pref_file = base::FilePath(); |
| 746 | InitializeExtensionService(params); |
| 747 | } |
| 748 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 749 | extensions::ManagementPolicy* GetManagementPolicy() { |
| 750 | return ExtensionSystem::Get(browser_context())->management_policy(); |
| 751 | } |
| 752 | |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 753 | ExternalInstallError* GetError(const std::string& extension_id) { |
| 754 | std::vector<ExternalInstallError*> errors = |
| 755 | service_->external_install_manager()->GetErrorsForTesting(); |
| 756 | auto found = std::find_if( |
| 757 | errors.begin(), errors.end(), |
| 758 | [&extension_id](const ExternalInstallError* error) { |
| 759 | return error->extension_id() == extension_id; |
| 760 | }); |
| 761 | return found == errors.end() ? nullptr : *found; |
| 762 | } |
| 763 | |
sdefresne | 50c1e52 | 2015-09-18 09:47:51 | [diff] [blame] | 764 | typedef extensions::ExtensionManagementPrefUpdater< |
maxbogue | ea16ff41 | 2016-10-28 16:35:29 | [diff] [blame] | 765 | sync_preferences::TestingPrefServiceSyncable> |
| 766 | ManagementPrefUpdater; |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 767 | }; |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 768 | |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 769 | // Receives notifications from a PackExtensionJob, indicating either that |
| 770 | // packing succeeded or that there was some error. |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 771 | class PackExtensionTestClient : public extensions::PackExtensionJob::Client { |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 772 | public: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 773 | PackExtensionTestClient(const base::FilePath& expected_crx_path, |
| 774 | const base::FilePath& expected_private_key_path); |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 775 | void OnPackSuccess(const base::FilePath& crx_path, |
| 776 | const base::FilePath& private_key_path) override; |
| 777 | void OnPackFailure(const std::string& error_message, |
| 778 | ExtensionCreator::ErrorType type) override; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 779 | |
| 780 | private: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 781 | const base::FilePath expected_crx_path_; |
| 782 | const base::FilePath expected_private_key_path_; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 783 | DISALLOW_COPY_AND_ASSIGN(PackExtensionTestClient); |
| 784 | }; |
| 785 | |
| 786 | PackExtensionTestClient::PackExtensionTestClient( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 787 | const base::FilePath& expected_crx_path, |
| 788 | const base::FilePath& expected_private_key_path) |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 789 | : expected_crx_path_(expected_crx_path), |
| 790 | expected_private_key_path_(expected_private_key_path) {} |
| 791 | |
| 792 | // If packing succeeded, we make sure that the package names match our |
| 793 | // expectations. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 794 | void PackExtensionTestClient::OnPackSuccess( |
| 795 | const base::FilePath& crx_path, |
| 796 | const base::FilePath& private_key_path) { |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 797 | // We got the notification and processed it; we don't expect any further tasks |
| 798 | // to be posted to the current thread, so we should stop blocking and continue |
| 799 | // on with the rest of the test. |
| 800 | // This call to |Quit()| matches the call to |Run()| in the |
| 801 | // |PackPunctuatedExtension| test. |
Gabriel Charette | 53a9ef81 | 2017-07-26 12:36:23 | [diff] [blame] | 802 | base::RunLoop::QuitCurrentWhenIdleDeprecated(); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 803 | EXPECT_EQ(expected_crx_path_.value(), crx_path.value()); |
| 804 | EXPECT_EQ(expected_private_key_path_.value(), private_key_path.value()); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 805 | ASSERT_TRUE(base::PathExists(private_key_path)); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | // 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] | 809 | void PackExtensionTestClient::OnPackFailure(const std::string& error_message, |
| 810 | ExtensionCreator::ErrorType type) { |
| 811 | if (type == ExtensionCreator::kCRXExists) |
| 812 | FAIL() << "Packing should not fail."; |
| 813 | else |
| 814 | FAIL() << "Existing CRX should have been overwritten."; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 815 | } |
| 816 | |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 817 | // Test loading good extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 818 | TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 819 | InitPluginService(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 820 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 821 | service()->Init(); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 822 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 823 | uint32_t expected_num_extensions = 3u; |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 824 | ASSERT_EQ(expected_num_extensions, loaded_.size()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 825 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 826 | EXPECT_EQ(std::string(good0), loaded_[0]->id()); |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 827 | EXPECT_EQ(std::string("My extension 1"), |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 828 | loaded_[0]->name()); |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 829 | EXPECT_EQ(std::string("The first extension that I made."), |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 830 | loaded_[0]->description()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 831 | EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 832 | EXPECT_TRUE(service()->GetExtensionById(loaded_[0]->id(), false)); |
| 833 | EXPECT_EQ(expected_num_extensions, registry()->enabled_extensions().size()); |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 834 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 835 | ValidatePrefKeyCount(3); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 836 | ValidateIntegerPref(good0, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 837 | ValidateIntegerPref(good0, "location", Manifest::INTERNAL); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 838 | ValidateIntegerPref(good1, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 839 | ValidateIntegerPref(good1, "location", Manifest::INTERNAL); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 840 | ValidateIntegerPref(good2, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 841 | ValidateIntegerPref(good2, "location", Manifest::INTERNAL); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 842 | |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 843 | URLPatternSet expected_patterns; |
| 844 | AddPattern(&expected_patterns, "file:///*"); |
| 845 | AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 846 | AddPattern(&expected_patterns, "https://*.google.com/*"); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 847 | const Extension* extension = loaded_[0].get(); |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 848 | const extensions::UserScriptList& scripts = |
| 849 | extensions::ContentScriptsInfo::GetContentScripts(extension); |
[email protected] | e66de89 | 2009-03-20 20:38:43 | [diff] [blame] | 850 | ASSERT_EQ(2u, scripts.size()); |
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 851 | EXPECT_EQ(expected_patterns, scripts[0]->url_patterns()); |
| 852 | EXPECT_EQ(2u, scripts[0]->js_scripts().size()); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 853 | ExtensionResource resource00(extension->id(), |
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 854 | scripts[0]->js_scripts()[0]->extension_root(), |
| 855 | scripts[0]->js_scripts()[0]->relative_path()); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 856 | base::FilePath expected_path = |
| 857 | base::MakeAbsoluteFilePath(extension->path().AppendASCII("script1.js")); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 858 | EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 859 | ExtensionResource resource01(extension->id(), |
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 860 | scripts[0]->js_scripts()[1]->extension_root(), |
| 861 | scripts[0]->js_scripts()[1]->relative_path()); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 862 | expected_path = |
| 863 | base::MakeAbsoluteFilePath(extension->path().AppendASCII("script2.js")); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 864 | EXPECT_TRUE(resource01.ComparePathWithDefault(expected_path)); |
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 865 | EXPECT_EQ(1u, scripts[1]->url_patterns().patterns().size()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 866 | EXPECT_EQ("http://*.news.com/*", |
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 867 | scripts[1]->url_patterns().begin()->GetAsString()); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 868 | ExtensionResource resource10(extension->id(), |
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 869 | scripts[1]->js_scripts()[0]->extension_root(), |
| 870 | scripts[1]->js_scripts()[0]->relative_path()); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 871 | expected_path = |
| 872 | extension->path().AppendASCII("js_files").AppendASCII("script3.js"); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 873 | expected_path = base::MakeAbsoluteFilePath(expected_path); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 874 | EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 875 | |
| 876 | expected_patterns.ClearPatterns(); |
| 877 | AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 878 | AddPattern(&expected_patterns, "https://*.google.com/*"); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 879 | EXPECT_EQ( |
| 880 | expected_patterns, |
rdevlin.cronin | d630c30 | 2015-09-30 20:19:33 | [diff] [blame] | 881 | extension->permissions_data()->active_permissions().explicit_hosts()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 882 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 883 | EXPECT_EQ(std::string(good1), loaded_[1]->id()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 884 | EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 885 | EXPECT_EQ(std::string(), loaded_[1]->description()); |
[email protected] | 81067e0 | 2009-07-27 15:12:09 | [diff] [blame] | 886 | EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 887 | extensions::BackgroundInfo::GetBackgroundURL(loaded_[1].get())); |
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 888 | EXPECT_TRUE( |
| 889 | extensions::ContentScriptsInfo::GetContentScripts(loaded_[1].get()) |
| 890 | .empty()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 891 | EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location()); |
[email protected] | b8fb303 | 2011-04-29 18:45:56 | [diff] [blame] | 892 | |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 893 | int index = expected_num_extensions - 1; |
| 894 | EXPECT_EQ(std::string(good2), loaded_[index]->id()); |
| 895 | EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 896 | EXPECT_EQ(std::string(), loaded_[index]->description()); |
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 897 | EXPECT_TRUE( |
| 898 | extensions::ContentScriptsInfo::GetContentScripts(loaded_[index].get()) |
| 899 | .empty()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 900 | EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); |
thestig | 4b36dd3 | 2014-10-31 20:30:19 | [diff] [blame] | 901 | } |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 902 | |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 903 | // Test loading bad extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 904 | TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 905 | // Initialize the test dir with a bad Preferences/extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 906 | base::FilePath source_install_dir = |
| 907 | data_dir().AppendASCII("bad").AppendASCII("Extensions"); |
[email protected] | e96a060 | 2014-02-15 08:27:42 | [diff] [blame] | 908 | base::FilePath pref_path = |
| 909 | source_install_dir.DirName().Append(chrome::kPreferencesFilename); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 910 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 911 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 912 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 913 | service()->Init(); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 914 | |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 915 | ASSERT_EQ(4u, GetErrors().size()); |
| 916 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 917 | |
brettw | d97eede | 2015-07-06 22:09:00 | [diff] [blame] | 918 | EXPECT_TRUE(base::MatchPattern(base::UTF16ToUTF8(GetErrors()[0]), |
fatalerr | 2443c2df | 2014-10-31 19:14:35 | [diff] [blame] | 919 | l10n_util::GetStringUTF8(IDS_EXTENSIONS_LOAD_ERROR_MESSAGE) + " *. " + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 920 | extensions::manifest_errors::kManifestUnreadable)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 921 | base::UTF16ToUTF8(GetErrors()[0]); |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 922 | |
brettw | d97eede | 2015-07-06 22:09:00 | [diff] [blame] | 923 | EXPECT_TRUE(base::MatchPattern(base::UTF16ToUTF8(GetErrors()[1]), |
fatalerr | 2443c2df | 2014-10-31 19:14:35 | [diff] [blame] | 924 | l10n_util::GetStringUTF8(IDS_EXTENSIONS_LOAD_ERROR_MESSAGE) + " *. " + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 925 | extensions::manifest_errors::kManifestUnreadable)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 926 | base::UTF16ToUTF8(GetErrors()[1]); |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 927 | |
brettw | d97eede | 2015-07-06 22:09:00 | [diff] [blame] | 928 | EXPECT_TRUE(base::MatchPattern(base::UTF16ToUTF8(GetErrors()[2]), |
fatalerr | 2443c2df | 2014-10-31 19:14:35 | [diff] [blame] | 929 | l10n_util::GetStringUTF8(IDS_EXTENSIONS_LOAD_ERROR_MESSAGE) + " *. " + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 930 | extensions::manifest_errors::kMissingFile)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 931 | base::UTF16ToUTF8(GetErrors()[2]); |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 932 | |
brettw | d97eede | 2015-07-06 22:09:00 | [diff] [blame] | 933 | EXPECT_TRUE(base::MatchPattern(base::UTF16ToUTF8(GetErrors()[3]), |
fatalerr | 2443c2df | 2014-10-31 19:14:35 | [diff] [blame] | 934 | l10n_util::GetStringUTF8(IDS_EXTENSIONS_LOAD_ERROR_MESSAGE) + " *. " + |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 935 | extensions::manifest_errors::kManifestUnreadable)) << |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 936 | base::UTF16ToUTF8(GetErrors()[3]); |
thestig | 4b36dd3 | 2014-10-31 20:30:19 | [diff] [blame] | 937 | } |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 938 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 939 | // Test various cases for delayed install because of missing imports. |
| 940 | TEST_F(ExtensionServiceTest, PendingImports) { |
| 941 | InitPluginService(); |
| 942 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 943 | base::FilePath source_install_dir = |
| 944 | data_dir().AppendASCII("pending_updates_with_imports").AppendASCII( |
| 945 | "Extensions"); |
[email protected] | e96a060 | 2014-02-15 08:27:42 | [diff] [blame] | 946 | base::FilePath pref_path = |
| 947 | source_install_dir.DirName().Append(chrome::kPreferencesFilename); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 948 | |
| 949 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 950 | |
| 951 | // Verify there are no pending extensions initially. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 952 | EXPECT_FALSE(service()->pending_extension_manager()->HasPendingExtensions()); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 953 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 954 | service()->Init(); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 955 | // Wait for GarbageCollectExtensions task to complete. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 956 | content::RunAllTasksUntilIdle(); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 957 | |
| 958 | // These extensions are used by the extensions we test below, they must be |
| 959 | // installed. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 960 | EXPECT_TRUE(base::PathExists(extensions_install_dir().AppendASCII( |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 961 | "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 962 | EXPECT_TRUE(base::PathExists(extensions_install_dir().AppendASCII( |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 963 | "hpiknbiabeeppbpihjehijgoemciehgk/2"))); |
| 964 | |
| 965 | // Each of these extensions should have been rejected because of dependencies |
| 966 | // that cannot be satisfied. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 967 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 968 | EXPECT_FALSE( |
| 969 | prefs->GetDelayedInstallInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); |
| 970 | EXPECT_FALSE( |
| 971 | prefs->GetInstalledExtensionInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); |
| 972 | EXPECT_FALSE( |
| 973 | prefs->GetDelayedInstallInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); |
| 974 | EXPECT_FALSE( |
| 975 | prefs->GetInstalledExtensionInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); |
| 976 | EXPECT_FALSE( |
| 977 | prefs->GetDelayedInstallInfo("cccccccccccccccccccccccccccccccc")); |
| 978 | EXPECT_FALSE( |
| 979 | prefs->GetInstalledExtensionInfo("cccccccccccccccccccccccccccccccc")); |
| 980 | |
| 981 | // Make sure the import started for the extension with a dependency. |
| 982 | EXPECT_TRUE( |
| 983 | prefs->GetDelayedInstallInfo("behllobkkfkfnphdnhnkndlbkcpglgmj")); |
| 984 | EXPECT_EQ(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, |
| 985 | prefs->GetDelayedInstallReason("behllobkkfkfnphdnhnkndlbkcpglgmj")); |
| 986 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 987 | EXPECT_FALSE(base::PathExists(extensions_install_dir().AppendASCII( |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 988 | "behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0"))); |
| 989 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 990 | EXPECT_TRUE(service()->pending_extension_manager()->HasPendingExtensions()); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 991 | std::string pending_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 992 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(pending_id)); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 993 | // Remove it because we are not testing the pending extension manager's |
| 994 | // ability to download and install extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 995 | EXPECT_TRUE(service()->pending_extension_manager()->Remove(pending_id)); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 996 | } |
| 997 | |
rdevlin.cronin | 7217be5 | 2017-03-24 20:47:05 | [diff] [blame] | 998 | // Tests that installation fails with extensions disabled. |
| 999 | TEST_F(ExtensionServiceTest, InstallExtensionsWithExtensionsDisabled) { |
| 1000 | InitializeExtensionServiceWithExtensionsDisabled(); |
| 1001 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1002 | InstallCRX(path, INSTALL_FAILED); |
| 1003 | } |
| 1004 | |
[email protected] | d7eaf57 | 2009-07-01 21:57:00 | [diff] [blame] | 1005 | // Test installing extensions. This test tries to install few extensions using |
| 1006 | // crx files. If you need to change those crx files, feel free to repackage |
| 1007 | // them, throw away the key used and change the id's above. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1008 | TEST_F(ExtensionServiceTest, InstallExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1009 | InitializeEmptyExtensionService(); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1010 | ValidatePrefKeyCount(0); |
| 1011 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1012 | // A simple extension that should install without error. |
rdevlin.cronin | 7217be5 | 2017-03-24 20:47:05 | [diff] [blame] | 1013 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1014 | InstallCRX(path, INSTALL_NEW); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1015 | // TODO(erikkay): verify the contents of the installed extension. |
| 1016 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1017 | int pref_count = 0; |
| 1018 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1019 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1020 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1021 | |
[email protected] | 902f7cd | 2009-05-22 19:02:19 | [diff] [blame] | 1022 | // An extension with page actions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1023 | path = data_dir().AppendASCII("page_action.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1024 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1025 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1026 | ValidateIntegerPref(page_action, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1027 | ValidateIntegerPref(page_action, "location", Manifest::INTERNAL); |
[email protected] | 902f7cd | 2009-05-22 19:02:19 | [diff] [blame] | 1028 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1029 | // Bad signature. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1030 | path = data_dir().AppendASCII("bad_signature.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1031 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | d7eaf57 | 2009-07-01 21:57:00 | [diff] [blame] | 1032 | ValidatePrefKeyCount(pref_count); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 1033 | |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1034 | // 0-length extension file. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1035 | path = data_dir().AppendASCII("not_an_extension.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1036 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1037 | ValidatePrefKeyCount(pref_count); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1038 | |
| 1039 | // Bad magic number. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1040 | path = data_dir().AppendASCII("bad_magic.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1041 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1042 | ValidatePrefKeyCount(pref_count); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1043 | |
[email protected] | 622813ee0 | 2013-08-21 21:00:29 | [diff] [blame] | 1044 | // Packed extensions may have folders or files that have underscores. |
| 1045 | // This will only cause a warning, rather than a fatal error. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1046 | path = data_dir().AppendASCII("bad_underscore.crx"); |
[email protected] | 622813ee0 | 2013-08-21 21:00:29 | [diff] [blame] | 1047 | InstallCRX(path, INSTALL_NEW); |
| 1048 | ValidatePrefKeyCount(++pref_count); |
[email protected] | 99872e3 | 2009-09-25 22:02:49 | [diff] [blame] | 1049 | |
[email protected] | 5fda9194 | 2013-09-24 06:47:53 | [diff] [blame] | 1050 | // A test for an extension with a 2048-bit public key. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1051 | path = data_dir().AppendASCII("good2048.crx"); |
[email protected] | 5fda9194 | 2013-09-24 06:47:53 | [diff] [blame] | 1052 | InstallCRX(path, INSTALL_NEW); |
| 1053 | ValidatePrefKeyCount(++pref_count); |
| 1054 | ValidateIntegerPref(good2048, "state", Extension::ENABLED); |
| 1055 | ValidateIntegerPref(good2048, "location", Manifest::INTERNAL); |
| 1056 | |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1057 | // TODO(erikkay): add more tests for many of the failure cases. |
| 1058 | // TODO(erikkay): add tests for upgrade cases. |
| 1059 | } |
| 1060 | |
[email protected] | b8e45df | 2014-06-11 19:32:36 | [diff] [blame] | 1061 | struct MockExtensionRegistryObserver |
| 1062 | : public extensions::ExtensionRegistryObserver { |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 1063 | void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
| 1064 | const Extension* extension, |
| 1065 | bool is_update, |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 1066 | const std::string& old_name) override { |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1067 | last_extension_installed = extension->id(); |
| 1068 | } |
| 1069 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 1070 | void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 1071 | const Extension* extension, |
| 1072 | extensions::UninstallReason reason) override { |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1073 | last_extension_uninstalled = extension->id(); |
| 1074 | } |
| 1075 | |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1076 | std::string last_extension_installed; |
| 1077 | std::string last_extension_uninstalled; |
| 1078 | }; |
| 1079 | |
[email protected] | b8e45df | 2014-06-11 19:32:36 | [diff] [blame] | 1080 | // Test that correct notifications are sent to ExtensionRegistryObserver on |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1081 | // extension install and uninstall. |
| 1082 | TEST_F(ExtensionServiceTest, InstallObserverNotified) { |
| 1083 | InitializeEmptyExtensionService(); |
| 1084 | |
[email protected] | b8e45df | 2014-06-11 19:32:36 | [diff] [blame] | 1085 | extensions::ExtensionRegistry* registry( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1086 | extensions::ExtensionRegistry::Get(profile())); |
[email protected] | b8e45df | 2014-06-11 19:32:36 | [diff] [blame] | 1087 | MockExtensionRegistryObserver observer; |
| 1088 | registry->AddObserver(&observer); |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1089 | |
| 1090 | // A simple extension that should install without error. |
| 1091 | ASSERT_TRUE(observer.last_extension_installed.empty()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1092 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1093 | InstallCRX(path, INSTALL_NEW); |
| 1094 | ASSERT_EQ(good_crx, observer.last_extension_installed); |
| 1095 | |
| 1096 | // Uninstall the extension. |
| 1097 | ASSERT_TRUE(observer.last_extension_uninstalled.empty()); |
Devlin Cronin | 6fd1cd6 | 2017-12-05 19:13:57 | [diff] [blame] | 1098 | UninstallExtension(good_crx); |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1099 | ASSERT_EQ(good_crx, observer.last_extension_uninstalled); |
| 1100 | |
[email protected] | b8e45df | 2014-06-11 19:32:36 | [diff] [blame] | 1101 | registry->RemoveObserver(&observer); |
[email protected] | 0d55b9a | 2013-07-19 10:40:26 | [diff] [blame] | 1102 | } |
| 1103 | |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1104 | // Tests that flags passed to OnExternalExtensionFileFound() make it to the |
| 1105 | // extension object. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1106 | TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1107 | const char kPrefFromBookmark[] = "from_bookmark"; |
| 1108 | |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1109 | InitializeEmptyExtensionService(); |
| 1110 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1111 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1112 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1113 | // Register and install an external extension. |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1114 | std::string version_str = "1.0.0.0"; |
| 1115 | std::unique_ptr<ExternalInstallInfoFile> info = CreateExternalExtension( |
| 1116 | good_crx, version_str, path, Manifest::EXTERNAL_PREF, |
| 1117 | Extension::FROM_BOOKMARK); |
| 1118 | MockExternalProvider* provider = |
| 1119 | AddMockExternalProvider(Manifest::EXTERNAL_POLICY_DOWNLOAD); |
| 1120 | provider->UpdateOrAddExtension(std::move(info)); |
| 1121 | WaitForExternalExtensionInstalled(); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1122 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1123 | const Extension* extension = service()->GetExtensionById(good_crx, false); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1124 | ASSERT_TRUE(extension); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1125 | ASSERT_TRUE(extension->from_bookmark()); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1126 | ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1127 | |
| 1128 | // Upgrade to version 2.0, the flag should be preserved. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1129 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1130 | UpdateExtension(good_crx, path, ENABLED); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 1131 | ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1132 | extension = service()->GetExtensionById(good_crx, false); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1133 | ASSERT_TRUE(extension); |
| 1134 | ASSERT_TRUE(extension->from_bookmark()); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 1135 | } |
| 1136 | |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1137 | // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1138 | TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1139 | InitializeEmptyExtensionService(); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1140 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1141 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1142 | |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1143 | std::string version_str = "1.0.0.0"; |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1144 | // Install an external extension. |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1145 | std::unique_ptr<ExternalInstallInfoFile> info = |
| 1146 | CreateExternalExtension(good_crx, version_str, path, |
| 1147 | Manifest::EXTERNAL_PREF, Extension::NO_FLAGS); |
| 1148 | MockExternalProvider* provider = |
| 1149 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
| 1150 | provider->UpdateOrAddExtension(std::move(info)); |
| 1151 | WaitForExternalExtensionInstalled(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 1152 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1153 | ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1154 | |
| 1155 | // Uninstall it and check that its killbit gets set. |
Devlin Cronin | 6fd1cd6 | 2017-12-05 19:13:57 | [diff] [blame] | 1156 | UninstallExtension(good_crx); |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 1157 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1158 | EXPECT_TRUE(prefs->IsExternalExtensionUninstalled(good_crx)); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1159 | |
| 1160 | // Try to re-install it externally. This should fail because of the killbit. |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1161 | info = CreateExternalExtension(good_crx, version_str, path, |
| 1162 | Manifest::EXTERNAL_PREF, Extension::NO_FLAGS); |
| 1163 | provider->UpdateOrAddExtension(std::move(info)); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 1164 | content::RunAllTasksUntilIdle(); |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 1165 | ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); |
| 1166 | EXPECT_TRUE(prefs->IsExternalExtensionUninstalled(good_crx)); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1167 | |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1168 | std::string newer_version = "1.0.0.1"; |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1169 | // Repeat the same thing with a newer version of the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1170 | path = data_dir().AppendASCII("good2.crx"); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1171 | info = CreateExternalExtension(good_crx, newer_version, path, |
| 1172 | Manifest::EXTERNAL_PREF, Extension::NO_FLAGS); |
| 1173 | provider->UpdateOrAddExtension(std::move(info)); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 1174 | content::RunAllTasksUntilIdle(); |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 1175 | ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); |
| 1176 | EXPECT_TRUE(prefs->IsExternalExtensionUninstalled(good_crx)); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1177 | |
| 1178 | // Try adding the same extension from an external update URL. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1179 | ASSERT_FALSE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1180 | good_crx, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1181 | std::string(), |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1182 | GURL("http:://fake.update/url"), |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 1183 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 1184 | Extension::NO_FLAGS, |
| 1185 | false)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 1186 | |
emaxx | 6699afb68 | 2016-10-10 21:22:13 | [diff] [blame] | 1187 | // Installation of the same extension through the policy should be successful. |
| 1188 | ASSERT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
| 1189 | good_crx, |
| 1190 | std::string(), |
| 1191 | GURL("http:://fake.update/url"), |
| 1192 | Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 1193 | Extension::NO_FLAGS, |
| 1194 | false)); |
| 1195 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(good_crx)); |
| 1196 | EXPECT_TRUE(service()->pending_extension_manager()->Remove(good_crx)); |
| 1197 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1198 | ASSERT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx)); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1199 | } |
| 1200 | |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1201 | // Test that uninstalling an external extension does not crash when |
| 1202 | // the extension could not be loaded. |
| 1203 | // This extension shown in preferences file requires an experimental permission. |
| 1204 | // It could not be loaded without such permission. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1205 | TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1206 | base::FilePath source_install_dir = |
| 1207 | data_dir().AppendASCII("good").AppendASCII("Extensions"); |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1208 | // The preference contains an external extension |
| 1209 | // that requires 'experimental' permission. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1210 | base::FilePath pref_path = source_install_dir |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1211 | .DirName() |
| 1212 | .AppendASCII("PreferencesExperimental"); |
| 1213 | |
| 1214 | // Aforementioned extension will not be loaded if |
| 1215 | // there is no '--enable-experimental-extension-apis' command line flag. |
| 1216 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1217 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1218 | service()->Init(); |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1219 | |
| 1220 | // Check and try to uninstall it. |
| 1221 | // If we don't check whether the extension is loaded before we uninstall it |
| 1222 | // in CheckExternalUninstall, a crash will happen here because we will get or |
| 1223 | // dereference a NULL pointer (extension) inside UninstallExtension. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 1224 | MockExternalProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1225 | service()->OnExternalProviderReady(&provider); |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1226 | } |
| 1227 | |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1228 | // Test that external extensions with incorrect IDs are not installed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1229 | TEST_F(ExtensionServiceTest, FailOnWrongId) { |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1230 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1231 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1232 | |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1233 | std::string version_str = "1.0.0.0"; |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1234 | |
| 1235 | const std::string wrong_id = all_zero; |
| 1236 | const std::string correct_id = good_crx; |
| 1237 | ASSERT_NE(correct_id, wrong_id); |
| 1238 | |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1239 | MockExternalProvider* provider = |
| 1240 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
| 1241 | |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1242 | // Install an external extension with an ID from the external |
| 1243 | // source that is not equal to the ID in the extension manifest. |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1244 | std::unique_ptr<ExternalInstallInfoFile> info = |
| 1245 | CreateExternalExtension(wrong_id, version_str, path, |
| 1246 | Manifest::EXTERNAL_PREF, Extension::NO_FLAGS); |
| 1247 | provider->UpdateOrAddExtension(std::move(info)); |
| 1248 | WaitForExternalExtensionInstalled(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1249 | ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1250 | |
| 1251 | // Try again with the right ID. Expect success. |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1252 | info = CreateExternalExtension(correct_id, version_str, path, |
| 1253 | Manifest::EXTERNAL_PREF, Extension::NO_FLAGS); |
| 1254 | provider->UpdateOrAddExtension(std::move(info)); |
| 1255 | WaitForExternalExtensionInstalled(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1256 | ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | // Test that external extensions with incorrect versions are not installed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1260 | TEST_F(ExtensionServiceTest, FailOnWrongVersion) { |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1261 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1262 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1263 | MockExternalProvider* provider = |
| 1264 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1265 | |
| 1266 | // Install an external extension with a version from the external |
| 1267 | // source that is not equal to the version in the extension manifest. |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1268 | std::string wrong_version_str = "1.2.3.4"; |
| 1269 | std::unique_ptr<ExternalInstallInfoFile> wrong_info = |
| 1270 | CreateExternalExtension(good_crx, wrong_version_str, path, |
| 1271 | Manifest::EXTERNAL_PREF, Extension::NO_FLAGS); |
| 1272 | provider->UpdateOrAddExtension(std::move(wrong_info)); |
| 1273 | WaitForExternalExtensionInstalled(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1274 | ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1275 | |
| 1276 | // Try again with the right version. Expect success. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1277 | service()->pending_extension_manager()->Remove(good_crx); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 1278 | std::unique_ptr<ExternalInstallInfoFile> correct_info = |
| 1279 | CreateExternalExtension(good_crx, "1.0.0.0", path, |
| 1280 | Manifest::EXTERNAL_PREF, Extension::NO_FLAGS); |
| 1281 | provider->UpdateOrAddExtension(std::move(correct_info)); |
| 1282 | WaitForExternalExtensionInstalled(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1283 | ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1284 | } |
| 1285 | |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1286 | // Install a user script (they get converted automatically to an extension) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1287 | TEST_F(ExtensionServiceTest, InstallUserScript) { |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1288 | // The details of script conversion are tested elsewhere, this just tests |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1289 | // integration with ExtensionService. |
| 1290 | InitializeEmptyExtensionService(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1291 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1292 | base::FilePath path = data_dir().AppendASCII("user_script_basic.user.js"); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1293 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1294 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1295 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service())); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1296 | installer->set_allow_silent_install(true); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 1297 | installer->InstallUserScript( |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1298 | path, |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 1299 | GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1300 | |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 1301 | content::RunAllTasksUntilIdle(); |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 1302 | std::vector<base::string16> errors = GetErrors(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1303 | EXPECT_TRUE(installed_) << "Nothing was installed."; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1304 | EXPECT_FALSE(was_update_) << path.value(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1305 | ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; |
brettw | d94a2214 | 2015-07-15 05:19:26 | [diff] [blame] | 1306 | EXPECT_EQ(0u, errors.size()) |
| 1307 | << "There were errors: " |
| 1308 | << base::JoinString(errors, base::ASCIIToUTF16(",")); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1309 | EXPECT_TRUE(service()->GetExtensionById(loaded_[0]->id(), false)) |
| 1310 | << path.value(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1311 | |
| 1312 | installed_ = NULL; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1313 | was_update_ = false; |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1314 | loaded_.clear(); |
Devlin Cronin | 9722a72 | 2017-12-16 03:35:10 | [diff] [blame] | 1315 | extensions::LoadErrorReporter::GetInstance()->ClearErrors(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1316 | } |
| 1317 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1318 | // Extensions don't install during shutdown. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1319 | TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1320 | InitializeEmptyExtensionService(); |
| 1321 | |
| 1322 | // Simulate shutdown. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1323 | service()->set_browser_terminating_for_test(true); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1324 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1325 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 1326 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service())); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1327 | installer->set_allow_silent_install(true); |
| 1328 | installer->InstallCrx(path); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 1329 | content::RunAllTasksUntilIdle(); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1330 | |
| 1331 | EXPECT_FALSE(installed_) << "Extension installed during shutdown."; |
| 1332 | ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown."; |
| 1333 | } |
| 1334 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1335 | // This tests that the granted permissions preferences are correctly set when |
| 1336 | // installing an extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1337 | TEST_F(ExtensionServiceTest, GrantedPermissions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1338 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1339 | base::FilePath path = data_dir().AppendASCII("permissions"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1340 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1341 | base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1342 | path = path.AppendASCII("unknown"); |
| 1343 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1344 | ASSERT_TRUE(base::PathExists(pem_path)); |
| 1345 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1346 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1347 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1348 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1349 | APIPermissionSet expected_api_perms; |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 1350 | URLPatternSet expected_host_perms; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1351 | |
| 1352 | // Make sure there aren't any granted permissions before the |
| 1353 | // extension is installed. |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 1354 | EXPECT_FALSE(prefs->GetGrantedPermissions(permissions_crx).get()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1355 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1356 | const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1357 | |
| 1358 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1359 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1360 | EXPECT_EQ(permissions_crx, extension->id()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1361 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1362 | // Verify that the valid API permissions have been recognized. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1363 | expected_api_perms.insert(APIPermission::kTab); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1364 | |
| 1365 | AddPattern(&expected_host_perms, "http://*.google.com/*"); |
| 1366 | AddPattern(&expected_host_perms, "https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 1367 | AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1368 | AddPattern(&expected_host_perms, "http://www.example.com/*"); |
| 1369 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 1370 | std::unique_ptr<const PermissionSet> known_perms = |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 1371 | prefs->GetGrantedPermissions(extension->id()); |
treib | fef128d | 2016-06-02 09:14:51 | [diff] [blame] | 1372 | ASSERT_TRUE(known_perms.get()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1373 | EXPECT_FALSE(known_perms->IsEmpty()); |
| 1374 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1375 | EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1376 | } |
| 1377 | |
treib | fef128d | 2016-06-02 09:14:51 | [diff] [blame] | 1378 | // This tests that the granted permissions preferences are correctly set when |
| 1379 | // updating an extension, and the extension is disabled in case of a permission |
| 1380 | // escalation. |
| 1381 | TEST_F(ExtensionServiceTest, GrantedPermissionsOnUpdate) { |
| 1382 | InitializeEmptyExtensionService(); |
| 1383 | const base::FilePath base_path = data_dir().AppendASCII("permissions"); |
| 1384 | |
| 1385 | const base::FilePath pem_path = base_path.AppendASCII("update.pem"); |
| 1386 | const base::FilePath path1 = base_path.AppendASCII("update_1"); |
| 1387 | const base::FilePath path2 = base_path.AppendASCII("update_2"); |
| 1388 | const base::FilePath path3 = base_path.AppendASCII("update_3"); |
| 1389 | const base::FilePath path4 = base_path.AppendASCII("update_4"); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1390 | const base::FilePath path5 = base_path.AppendASCII("update_5"); |
treib | fef128d | 2016-06-02 09:14:51 | [diff] [blame] | 1391 | |
| 1392 | ASSERT_TRUE(base::PathExists(pem_path)); |
| 1393 | ASSERT_TRUE(base::PathExists(path1)); |
| 1394 | ASSERT_TRUE(base::PathExists(path2)); |
| 1395 | ASSERT_TRUE(base::PathExists(path3)); |
| 1396 | ASSERT_TRUE(base::PathExists(path4)); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1397 | ASSERT_TRUE(base::PathExists(path5)); |
treib | fef128d | 2016-06-02 09:14:51 | [diff] [blame] | 1398 | |
| 1399 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1400 | |
| 1401 | // Install version 1, which has the kHistory permission. |
| 1402 | const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); |
| 1403 | const std::string id = extension->id(); |
| 1404 | |
| 1405 | EXPECT_EQ(0u, GetErrors().size()); |
| 1406 | ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1407 | |
| 1408 | // Verify that the history permission has been recognized. |
| 1409 | APIPermissionSet expected_api_perms; |
| 1410 | expected_api_perms.insert(APIPermission::kHistory); |
| 1411 | { |
| 1412 | std::unique_ptr<const PermissionSet> known_perms = |
| 1413 | prefs->GetGrantedPermissions(id); |
| 1414 | ASSERT_TRUE(known_perms.get()); |
| 1415 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1416 | } |
| 1417 | |
| 1418 | // Update to version 2 that adds the kTopSites permission, which has a |
| 1419 | // separate message, but is implied by kHistory. The extension should remain |
| 1420 | // enabled. |
| 1421 | PackCRXAndUpdateExtension(id, path2, pem_path, ENABLED); |
| 1422 | extension = service()->GetInstalledExtension(id); |
| 1423 | ASSERT_TRUE(extension); |
| 1424 | EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1425 | |
| 1426 | // The extra permission should have been granted automatically. |
| 1427 | expected_api_perms.insert(APIPermission::kTopSites); |
| 1428 | { |
| 1429 | std::unique_ptr<const PermissionSet> known_perms = |
| 1430 | prefs->GetGrantedPermissions(id); |
| 1431 | ASSERT_TRUE(known_perms.get()); |
| 1432 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1433 | } |
| 1434 | |
| 1435 | // Update to version 3 that adds the kStorage permission, which does not have |
| 1436 | // a message. The extension should remain enabled. |
| 1437 | PackCRXAndUpdateExtension(id, path3, pem_path, ENABLED); |
| 1438 | extension = service()->GetInstalledExtension(id); |
| 1439 | ASSERT_TRUE(extension); |
| 1440 | EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1441 | |
| 1442 | // The extra permission should have been granted automatically. |
| 1443 | expected_api_perms.insert(APIPermission::kStorage); |
| 1444 | { |
| 1445 | std::unique_ptr<const PermissionSet> known_perms = |
| 1446 | prefs->GetGrantedPermissions(id); |
| 1447 | ASSERT_TRUE(known_perms.get()); |
| 1448 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1449 | } |
| 1450 | |
| 1451 | // Update to version 4 that adds the kNotifications permission, which has a |
| 1452 | // message and hence is considered a permission increase. Now the extension |
| 1453 | // should get disabled. |
| 1454 | PackCRXAndUpdateExtension(id, path4, pem_path, DISABLED); |
| 1455 | extension = service()->GetInstalledExtension(id); |
| 1456 | ASSERT_TRUE(extension); |
| 1457 | EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 1458 | |
| 1459 | // No new permissions should have been granted. |
| 1460 | { |
| 1461 | std::unique_ptr<const PermissionSet> known_perms = |
| 1462 | prefs->GetGrantedPermissions(id); |
| 1463 | ASSERT_TRUE(known_perms.get()); |
| 1464 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1465 | } |
| 1466 | } |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1467 | |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1468 | TEST_F(ExtensionServiceTest, ReenableWithAllPermissionsGranted) { |
| 1469 | InitializeEmptyExtensionService(); |
| 1470 | const base::FilePath base_path = data_dir().AppendASCII("permissions"); |
| 1471 | |
| 1472 | const base::FilePath pem_path = base_path.AppendASCII("update.pem"); |
| 1473 | const base::FilePath path1 = base_path.AppendASCII("update_1"); |
| 1474 | const base::FilePath path4 = base_path.AppendASCII("update_4"); |
| 1475 | const base::FilePath path5 = base_path.AppendASCII("update_5"); |
| 1476 | |
| 1477 | ASSERT_TRUE(base::PathExists(pem_path)); |
| 1478 | ASSERT_TRUE(base::PathExists(path1)); |
| 1479 | ASSERT_TRUE(base::PathExists(path4)); |
| 1480 | ASSERT_TRUE(base::PathExists(path5)); |
| 1481 | |
| 1482 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1483 | |
| 1484 | // Install version 1, which has the kHistory permission. |
| 1485 | const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); |
| 1486 | const std::string id = extension->id(); |
| 1487 | |
| 1488 | EXPECT_EQ(0u, GetErrors().size()); |
| 1489 | ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1490 | |
| 1491 | // Update to version 4 that adds the kNotifications permission, which has a |
| 1492 | // message and hence is considered a permission increase. The extension |
| 1493 | // should get disabled due to a permissions increase. |
| 1494 | PackCRXAndUpdateExtension(id, path4, pem_path, DISABLED); |
| 1495 | extension = service()->GetInstalledExtension(id); |
| 1496 | ASSERT_TRUE(extension); |
| 1497 | EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1498 | EXPECT_TRUE(prefs->HasDisableReason( |
| 1499 | id, extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE)); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1500 | |
| 1501 | // Update to version 5 that removes the kNotifications permission again. |
| 1502 | // The extension should get re-enabled. |
| 1503 | PackCRXAndUpdateExtension(id, path5, pem_path, ENABLED); |
| 1504 | extension = service()->GetInstalledExtension(id); |
| 1505 | ASSERT_TRUE(extension); |
| 1506 | EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1507 | } |
| 1508 | |
| 1509 | TEST_F(ExtensionServiceTest, ReenableWithAllPermissionsGrantedOnStartup) { |
| 1510 | InitializeEmptyExtensionService(); |
| 1511 | const base::FilePath base_path = data_dir().AppendASCII("permissions"); |
| 1512 | |
| 1513 | const base::FilePath pem_path = base_path.AppendASCII("update.pem"); |
| 1514 | const base::FilePath path1 = base_path.AppendASCII("update_1"); |
| 1515 | |
| 1516 | ASSERT_TRUE(base::PathExists(pem_path)); |
| 1517 | ASSERT_TRUE(base::PathExists(path1)); |
| 1518 | |
| 1519 | // Install an extension which has the kHistory permission. |
| 1520 | const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); |
| 1521 | const std::string id = extension->id(); |
| 1522 | |
| 1523 | EXPECT_EQ(0u, GetErrors().size()); |
| 1524 | ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1525 | |
| 1526 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1527 | |
| 1528 | // Disable the extension due to a supposed permission increase, but retain its |
| 1529 | // granted permissions. |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1530 | service()->DisableExtension( |
| 1531 | id, extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1532 | EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1533 | EXPECT_TRUE(prefs->HasDisableReason( |
| 1534 | id, extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE)); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1535 | |
| 1536 | // Simulate a Chrome restart. Since the extension has all required |
| 1537 | // permissions, it should get re-enabled. |
| 1538 | service()->ReloadExtensionsForTest(); |
| 1539 | EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1540 | EXPECT_FALSE(prefs->HasDisableReason( |
| 1541 | id, extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE)); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | TEST_F(ExtensionServiceTest, |
| 1545 | DontReenableWithAllPermissionsGrantedButOtherReason) { |
| 1546 | InitializeEmptyExtensionService(); |
| 1547 | const base::FilePath base_path = data_dir().AppendASCII("permissions"); |
| 1548 | |
| 1549 | const base::FilePath pem_path = base_path.AppendASCII("update.pem"); |
| 1550 | const base::FilePath path1 = base_path.AppendASCII("update_1"); |
| 1551 | const base::FilePath path4 = base_path.AppendASCII("update_4"); |
| 1552 | const base::FilePath path5 = base_path.AppendASCII("update_5"); |
| 1553 | |
| 1554 | ASSERT_TRUE(base::PathExists(pem_path)); |
| 1555 | ASSERT_TRUE(base::PathExists(path1)); |
| 1556 | ASSERT_TRUE(base::PathExists(path4)); |
| 1557 | ASSERT_TRUE(base::PathExists(path5)); |
| 1558 | |
| 1559 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1560 | |
| 1561 | // Install version 1, which has the kHistory permission. |
| 1562 | const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); |
| 1563 | const std::string id = extension->id(); |
| 1564 | |
| 1565 | EXPECT_EQ(0u, GetErrors().size()); |
| 1566 | ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1567 | |
| 1568 | // Disable the extension. |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1569 | service()->DisableExtension(id, |
| 1570 | extensions::disable_reason::DISABLE_USER_ACTION); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1571 | EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1572 | EXPECT_TRUE(prefs->HasDisableReason( |
| 1573 | id, extensions::disable_reason::DISABLE_USER_ACTION)); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1574 | |
| 1575 | // Update to version 4 that adds the kNotifications permission, which has a |
| 1576 | // message and hence is considered a permission increase. The extension |
| 1577 | // should get disabled due to a permissions increase. |
| 1578 | PackCRXAndUpdateExtension(id, path4, pem_path, DISABLED); |
| 1579 | extension = service()->GetInstalledExtension(id); |
| 1580 | ASSERT_TRUE(extension); |
| 1581 | EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1582 | EXPECT_TRUE(prefs->HasDisableReason( |
| 1583 | id, extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE)); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1584 | // The USER_ACTION reason should also still be there. |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1585 | EXPECT_TRUE(prefs->HasDisableReason( |
| 1586 | id, extensions::disable_reason::DISABLE_USER_ACTION)); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1587 | |
| 1588 | // Update to version 5 that removes the kNotifications permission again. |
| 1589 | // The PERMISSIONS_INCREASE should be removed, but the extension should stay |
| 1590 | // disabled since USER_ACTION is still there. |
| 1591 | PackCRXAndUpdateExtension(id, path5, pem_path, DISABLED); |
| 1592 | extension = service()->GetInstalledExtension(id); |
| 1593 | ASSERT_TRUE(extension); |
| 1594 | EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1595 | EXPECT_EQ(extensions::disable_reason::DISABLE_USER_ACTION, |
| 1596 | prefs->GetDisableReasons(id)); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | TEST_F(ExtensionServiceTest, |
| 1600 | DontReenableWithAllPermissionsGrantedOnStartupButOtherReason) { |
| 1601 | InitializeEmptyExtensionService(); |
| 1602 | const base::FilePath base_path = data_dir().AppendASCII("permissions"); |
| 1603 | |
| 1604 | const base::FilePath pem_path = base_path.AppendASCII("update.pem"); |
| 1605 | const base::FilePath path1 = base_path.AppendASCII("update_1"); |
| 1606 | |
| 1607 | ASSERT_TRUE(base::PathExists(pem_path)); |
| 1608 | ASSERT_TRUE(base::PathExists(path1)); |
| 1609 | |
| 1610 | // Install an extension which has the kHistory permission. |
| 1611 | const Extension* extension = PackAndInstallCRX(path1, pem_path, INSTALL_NEW); |
| 1612 | const std::string id = extension->id(); |
| 1613 | |
| 1614 | EXPECT_EQ(0u, GetErrors().size()); |
| 1615 | ASSERT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 1616 | |
| 1617 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 1618 | |
| 1619 | // Disable the extension due to a supposed permission increase, but retain its |
| 1620 | // granted permissions. |
| 1621 | service()->DisableExtension( |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1622 | id, extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE | |
| 1623 | extensions::disable_reason::DISABLE_USER_ACTION); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1624 | EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1625 | EXPECT_TRUE(prefs->HasDisableReason( |
| 1626 | id, extensions::disable_reason::DISABLE_PERMISSIONS_INCREASE)); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1627 | |
| 1628 | // Simulate a Chrome restart. Since the extension has all required |
| 1629 | // permissions, the DISABLE_PERMISSIONS_INCREASE should get removed, but it |
| 1630 | // should stay disabled due to the remaining DISABLE_USER_ACTION reason. |
| 1631 | service()->ReloadExtensionsForTest(); |
| 1632 | EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 1633 | EXPECT_EQ(extensions::disable_reason::DISABLE_USER_ACTION, |
| 1634 | prefs->GetDisableReasons(id)); |
treib | 6e51bca | 2016-06-15 10:26:03 | [diff] [blame] | 1635 | } |
| 1636 | |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1637 | #if !defined(OS_CHROMEOS) |
| 1638 | // This tests that the granted permissions preferences are correctly set for |
| 1639 | // default apps. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1640 | TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1641 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1642 | base::FilePath path = data_dir().AppendASCII("permissions"); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1643 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1644 | base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1645 | path = path.AppendASCII("unknown"); |
| 1646 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1647 | ASSERT_TRUE(base::PathExists(pem_path)); |
| 1648 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1649 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1650 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1651 | |
| 1652 | APIPermissionSet expected_api_perms; |
| 1653 | URLPatternSet expected_host_perms; |
| 1654 | |
| 1655 | // Make sure there aren't any granted permissions before the |
| 1656 | // extension is installed. |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 1657 | EXPECT_FALSE(prefs->GetGrantedPermissions(permissions_crx).get()); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1658 | |
| 1659 | const Extension* extension = PackAndInstallCRX( |
catmullings | 22bc237 | 2016-11-02 19:59:35 | [diff] [blame] | 1660 | path, pem_path, INSTALL_NEW, Extension::WAS_INSTALLED_BY_DEFAULT, |
| 1661 | Manifest::Location::INTERNAL); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1662 | |
| 1663 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1664 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1665 | EXPECT_EQ(permissions_crx, extension->id()); |
| 1666 | |
| 1667 | // Verify that the valid API permissions have been recognized. |
| 1668 | expected_api_perms.insert(APIPermission::kTab); |
| 1669 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 1670 | std::unique_ptr<const PermissionSet> known_perms = |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 1671 | prefs->GetGrantedPermissions(extension->id()); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1672 | EXPECT_TRUE(known_perms.get()); |
| 1673 | EXPECT_FALSE(known_perms->IsEmpty()); |
| 1674 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1675 | } |
| 1676 | #endif |
| 1677 | |
| 1678 | // Tests that the extension is disabled when permissions are missing from |
| 1679 | // the extension's granted permissions preferences. (This simulates updating |
| 1680 | // the browser to a version which recognizes more permissions). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1681 | TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1682 | InitializeEmptyExtensionService(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1683 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1684 | base::FilePath path = |
| 1685 | data_dir().AppendASCII("permissions").AppendASCII("unknown"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1686 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1687 | ASSERT_TRUE(base::PathExists(path)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1688 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1689 | const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1690 | |
| 1691 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1692 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1693 | std::string extension_id = extension->id(); |
| 1694 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1695 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1696 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1697 | APIPermissionSet expected_api_permissions; |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 1698 | URLPatternSet expected_host_permissions; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1699 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1700 | expected_api_permissions.insert(APIPermission::kTab); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1701 | AddPattern(&expected_host_permissions, "http://*.google.com/*"); |
| 1702 | AddPattern(&expected_host_permissions, "https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 1703 | AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1704 | AddPattern(&expected_host_permissions, "http://www.example.com/*"); |
| 1705 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1706 | std::set<std::string> host_permissions; |
| 1707 | |
| 1708 | // Test that the extension is disabled when an API permission is missing from |
| 1709 | // the extension's granted api permissions preference. (This simulates |
| 1710 | // updating the browser to a version which recognizes a new API permission). |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1711 | SetPref(extension_id, "granted_permissions.api", |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 1712 | base::MakeUnique<base::ListValue>(), "granted_permissions.api"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1713 | service()->ReloadExtensionsForTest(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1714 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1715 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 1716 | extension = registry()->disabled_extensions().begin()->get(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1717 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1718 | ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1719 | ASSERT_FALSE(service()->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1720 | ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1721 | |
| 1722 | // Now grant and re-enable the extension, making sure the prefs are updated. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1723 | service()->GrantPermissionsAndEnableExtension(extension); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1724 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1725 | ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1726 | ASSERT_TRUE(service()->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1727 | ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1728 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 1729 | std::unique_ptr<const PermissionSet> current_perms = |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 1730 | prefs->GetGrantedPermissions(extension_id); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1731 | ASSERT_TRUE(current_perms.get()); |
| 1732 | ASSERT_FALSE(current_perms->IsEmpty()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1733 | ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1734 | ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1735 | |
| 1736 | // Tests that the extension is disabled when a host permission is missing from |
| 1737 | // the extension's granted host permissions preference. (This simulates |
| 1738 | // updating the browser to a version which recognizes additional host |
| 1739 | // permissions). |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1740 | host_permissions.clear(); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1741 | current_perms = NULL; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1742 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1743 | host_permissions.insert("http://*.google.com/*"); |
| 1744 | host_permissions.insert("https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 1745 | host_permissions.insert("http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1746 | |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 1747 | auto api_permissions = base::MakeUnique<base::ListValue>(); |
dcheng | d9ea6386 | 2016-06-03 02:27:18 | [diff] [blame] | 1748 | api_permissions->AppendString("tabs"); |
vabr | 9984ea6 | 2017-04-10 11:33:49 | [diff] [blame] | 1749 | SetPref(extension_id, "granted_permissions.api", std::move(api_permissions), |
| 1750 | "granted_permissions.api"); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1751 | SetPrefStringSet( |
| 1752 | extension_id, "granted_permissions.scriptable_host", host_permissions); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1753 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1754 | service()->ReloadExtensionsForTest(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1755 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1756 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 1757 | extension = registry()->disabled_extensions().begin()->get(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1758 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1759 | ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1760 | ASSERT_FALSE(service()->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1761 | ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1762 | |
| 1763 | // Now grant and re-enable the extension, making sure the prefs are updated. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1764 | service()->GrantPermissionsAndEnableExtension(extension); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1765 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1766 | ASSERT_TRUE(service()->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1767 | ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1768 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1769 | current_perms = prefs->GetGrantedPermissions(extension_id); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1770 | ASSERT_TRUE(current_perms.get()); |
| 1771 | ASSERT_FALSE(current_perms->IsEmpty()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1772 | ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1773 | ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1774 | } |
| 1775 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1776 | // Test Packaging and installing an extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1777 | TEST_F(ExtensionServiceTest, PackExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1778 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1779 | base::FilePath input_directory = |
| 1780 | data_dir() |
| 1781 | .AppendASCII("good") |
| 1782 | .AppendASCII("Extensions") |
| 1783 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 1784 | .AppendASCII("1.0.0.0"); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1785 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 1786 | base::ScopedTempDir temp_dir; |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 1787 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 1788 | base::FilePath output_directory = temp_dir.GetPath(); |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 1789 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1790 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 1791 | base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1792 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 1793 | std::unique_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1794 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1795 | privkey_path, ExtensionCreator::kNoRunFlags)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1796 | ASSERT_TRUE(base::PathExists(crx_path)); |
| 1797 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1798 | |
| 1799 | // Repeat the run with the pem file gone, and no special flags |
| 1800 | // Should refuse to overwrite the existing crx. |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 1801 | base::DeleteFile(privkey_path, false); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1802 | ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1803 | privkey_path, ExtensionCreator::kNoRunFlags)); |
| 1804 | |
| 1805 | // OK, now try it with a flag to overwrite existing crx. Should work. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1806 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1807 | privkey_path, ExtensionCreator::kOverwriteCRX)); |
| 1808 | |
| 1809 | // Repeat the run allowing existing crx, but the existing pem is still |
| 1810 | // an error. Should fail. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1811 | ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1812 | privkey_path, ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1813 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1814 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1815 | InstallCRX(crx_path, INSTALL_NEW); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 1816 | |
| 1817 | // Try packing with invalid paths. |
| 1818 | creator.reset(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1819 | ASSERT_FALSE( |
| 1820 | creator->Run(base::FilePath(), base::FilePath(), base::FilePath(), |
| 1821 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 1822 | |
| 1823 | // Try packing an empty directory. Should fail because an empty directory is |
| 1824 | // not a valid extension. |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 1825 | base::ScopedTempDir temp_dir2; |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 1826 | ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
| 1827 | creator.reset(new ExtensionCreator()); |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 1828 | ASSERT_FALSE(creator->Run(temp_dir2.GetPath(), crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1829 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 1830 | |
| 1831 | // Try packing with an invalid manifest. |
| 1832 | std::string invalid_manifest_content = "I am not a manifest."; |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 1833 | ASSERT_EQ( |
| 1834 | static_cast<int>(invalid_manifest_content.size()), |
| 1835 | base::WriteFile(temp_dir2.GetPath().Append(extensions::kManifestFilename), |
| 1836 | invalid_manifest_content.c_str(), |
| 1837 | invalid_manifest_content.size())); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 1838 | creator.reset(new ExtensionCreator()); |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 1839 | ASSERT_FALSE(creator->Run(temp_dir2.GetPath(), crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1840 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | c21b5b61 | 2013-07-31 07:49:16 | [diff] [blame] | 1841 | |
| 1842 | // Try packing with a private key that is a valid key, but invalid for the |
| 1843 | // extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1844 | base::FilePath bad_private_key_dir = |
| 1845 | data_dir().AppendASCII("bad_private_key"); |
[email protected] | c21b5b61 | 2013-07-31 07:49:16 | [diff] [blame] | 1846 | crx_path = output_directory.AppendASCII("bad_private_key.crx"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1847 | privkey_path = data_dir().AppendASCII("bad_private_key.pem"); |
[email protected] | c21b5b61 | 2013-07-31 07:49:16 | [diff] [blame] | 1848 | ASSERT_FALSE(creator->Run(bad_private_key_dir, crx_path, base::FilePath(), |
| 1849 | privkey_path, ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1850 | } |
| 1851 | |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1852 | // Test Packaging and installing an extension whose name contains punctuation. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1853 | TEST_F(ExtensionServiceTest, PackPunctuatedExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1854 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1855 | base::FilePath input_directory = data_dir() |
| 1856 | .AppendASCII("good") |
| 1857 | .AppendASCII("Extensions") |
| 1858 | .AppendASCII(good0) |
| 1859 | .AppendASCII("1.0.0.0"); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1860 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 1861 | base::ScopedTempDir temp_dir; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1862 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1863 | |
| 1864 | // Extension names containing punctuation, and the expected names for the |
| 1865 | // packed extensions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1866 | const base::FilePath punctuated_names[] = { |
| 1867 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods")), |
| 1868 | base::FilePath(FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod")), |
| 1869 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname/")). |
[email protected] | d9034ed2 | 2012-02-10 02:04:40 | [diff] [blame] | 1870 | NormalizePathSeparators(), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1871 | }; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1872 | const base::FilePath expected_crx_names[] = { |
| 1873 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods.crx")), |
| 1874 | base::FilePath( |
| 1875 | FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.crx")), |
| 1876 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.crx")), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1877 | }; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1878 | const base::FilePath expected_private_key_names[] = { |
| 1879 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods.pem")), |
| 1880 | base::FilePath( |
| 1881 | FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.pem")), |
| 1882 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.pem")), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1883 | }; |
| 1884 | |
| 1885 | for (size_t i = 0; i < arraysize(punctuated_names); ++i) { |
| 1886 | SCOPED_TRACE(punctuated_names[i].value().c_str()); |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 1887 | base::FilePath output_dir = temp_dir.GetPath().Append(punctuated_names[i]); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1888 | |
| 1889 | // Copy the extension into the output directory, as PackExtensionJob doesn't |
| 1890 | // let us choose where to output the packed extension. |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 1891 | ASSERT_TRUE(base::CopyDirectory(input_directory, output_dir, true)); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1892 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1893 | base::FilePath expected_crx_path = |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 1894 | temp_dir.GetPath().Append(expected_crx_names[i]); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1895 | base::FilePath expected_private_key_path = |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 1896 | temp_dir.GetPath().Append(expected_private_key_names[i]); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1897 | PackExtensionTestClient pack_client(expected_crx_path, |
| 1898 | expected_private_key_path); |
Istiaque Ahmed | 6a06cc9 | 2017-08-12 00:31:33 | [diff] [blame] | 1899 | { |
| 1900 | extensions::PackExtensionJob packer(&pack_client, output_dir, |
| 1901 | base::FilePath(), |
| 1902 | ExtensionCreator::kOverwriteCRX); |
| 1903 | packer.Start(); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1904 | |
Istiaque Ahmed | 6a06cc9 | 2017-08-12 00:31:33 | [diff] [blame] | 1905 | // The packer will post a notification task to the current thread's |
| 1906 | // message loop when it is finished. We manually run the loop here so |
| 1907 | // that we block and catch the notification; otherwise, the process would |
| 1908 | // exit. |
| 1909 | // This call to |Run()| is matched by a call to |Quit()| in the |
| 1910 | // |PackExtensionTestClient|'s notification handling code. |
| 1911 | base::RunLoop().Run(); |
| 1912 | } |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1913 | |
| 1914 | if (HasFatalFailure()) |
| 1915 | return; |
| 1916 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1917 | InstallCRX(expected_crx_path, INSTALL_NEW); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1921 | TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) { |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 1922 | InitializeEmptyExtensionService(); |
| 1923 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 1924 | base::ScopedTempDir extension_temp_dir; |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 1925 | ASSERT_TRUE(extension_temp_dir.CreateUniqueTempDir()); |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 1926 | base::FilePath input_directory = |
| 1927 | extension_temp_dir.GetPath().AppendASCII("ext"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1928 | ASSERT_TRUE( |
| 1929 | base::CopyDirectory(data_dir() |
| 1930 | .AppendASCII("good") |
| 1931 | .AppendASCII("Extensions") |
| 1932 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 1933 | .AppendASCII("1.0.0.0"), |
| 1934 | input_directory, |
| 1935 | /*recursive=*/true)); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 1936 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 1937 | base::ScopedTempDir output_temp_dir; |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 1938 | ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir()); |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 1939 | base::FilePath output_directory = output_temp_dir.GetPath(); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 1940 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1941 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 1942 | base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 1943 | |
| 1944 | // Pack the extension once to get a private key. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 1945 | std::unique_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1946 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 1947 | privkey_path, ExtensionCreator::kNoRunFlags)) |
| 1948 | << creator->error_message(); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1949 | ASSERT_TRUE(base::PathExists(crx_path)); |
| 1950 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 1951 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 1952 | base::DeleteFile(crx_path, false); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 1953 | // Move the pem file into the extension. |
[email protected] | 5553d5b | 2013-07-01 23:07:36 | [diff] [blame] | 1954 | base::Move(privkey_path, |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 1955 | input_directory.AppendASCII("privkey.pem")); |
| 1956 | |
| 1957 | // This pack should fail because of the contained private key. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1958 | EXPECT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 1959 | privkey_path, ExtensionCreator::kNoRunFlags)); |
| 1960 | EXPECT_THAT(creator->error_message(), |
| 1961 | testing::ContainsRegex( |
| 1962 | "extension includes the key file.*privkey.pem")); |
| 1963 | } |
| 1964 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1965 | // Test Packaging and installing an extension using an openssl generated key. |
| 1966 | // The openssl is generated with the following: |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1967 | // > openssl genrsa -out privkey.pem 1024 |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 1968 | // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1969 | // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1970 | // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1971 | TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1972 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 1973 | base::FilePath input_directory = |
| 1974 | data_dir() |
| 1975 | .AppendASCII("good") |
| 1976 | .AppendASCII("Extensions") |
| 1977 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 1978 | .AppendASCII("1.0.0.0"); |
| 1979 | base::FilePath privkey_path( |
| 1980 | data_dir().AppendASCII("openssl_privkey_asn1.pem")); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 1981 | ASSERT_TRUE(base::PathExists(privkey_path)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1982 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 1983 | base::ScopedTempDir temp_dir; |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 1984 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 1985 | base::FilePath output_directory = temp_dir.GetPath(); |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 1986 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1987 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1988 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 1989 | std::unique_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1990 | ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1991 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1992 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1993 | InstallCRX(crx_path, INSTALL_NEW); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1994 | } |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1995 | |
rdevlin.cronin | 7217be5 | 2017-03-24 20:47:05 | [diff] [blame] | 1996 | TEST_F(ExtensionServiceTest, TestInstallThemeWithExtensionsDisabled) { |
| 1997 | // Themes can be installed, even when extensions are disabled. |
| 1998 | InitializeExtensionServiceWithExtensionsDisabled(); |
| 1999 | base::FilePath path = data_dir().AppendASCII("theme.crx"); |
| 2000 | InstallCRX(path, INSTALL_NEW); |
| 2001 | ValidatePrefKeyCount(1); |
| 2002 | ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); |
| 2003 | ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL); |
| 2004 | } |
| 2005 | |
[email protected] | 8706592 | 2014-05-28 14:50:37 | [diff] [blame] | 2006 | #if defined(THREAD_SANITIZER) |
| 2007 | // Flaky under Tsan. http://crbug.com/377702 |
| 2008 | #define MAYBE_InstallTheme DISABLED_InstallTheme |
| 2009 | #else |
| 2010 | #define MAYBE_InstallTheme InstallTheme |
| 2011 | #endif |
| 2012 | |
| 2013 | TEST_F(ExtensionServiceTest, MAYBE_InstallTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2014 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2015 | service()->Init(); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2016 | |
| 2017 | // A theme. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2018 | base::FilePath path = data_dir().AppendASCII("theme.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2019 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2020 | int pref_count = 0; |
| 2021 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2022 | ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2023 | ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2024 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2025 | path = data_dir().AppendASCII("theme2.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2026 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2027 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2028 | ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2029 | ValidateIntegerPref(theme2_crx, "location", Manifest::INTERNAL); |
[email protected] | 494c06e | 2009-07-25 01:06:42 | [diff] [blame] | 2030 | |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2031 | // A theme with extension elements. Themes cannot have extension elements, |
| 2032 | // so any such elements (like content scripts) should be ignored. |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2033 | { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2034 | path = data_dir().AppendASCII("theme_with_extension.crx"); |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2035 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2036 | ValidatePrefKeyCount(++pref_count); |
| 2037 | ASSERT_TRUE(extension); |
| 2038 | EXPECT_TRUE(extension->is_theme()); |
lazyboy | 12c77d7 | 2016-08-19 20:06:09 | [diff] [blame] | 2039 | EXPECT_TRUE( |
| 2040 | extensions::ContentScriptsInfo::GetContentScripts(extension).empty()); |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2041 | } |
[email protected] | 1219891 | 2009-06-05 03:41:22 | [diff] [blame] | 2042 | |
| 2043 | // A theme with image resources missing (misspelt path). |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2044 | path = data_dir().AppendASCII("theme_missing_image.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2045 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2046 | ValidatePrefKeyCount(pref_count); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2047 | } |
| 2048 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2049 | TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2050 | // Load. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2051 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2052 | service()->Init(); |
[email protected] | b1ac7046 | 2013-08-14 21:33:30 | [diff] [blame] | 2053 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2054 | base::FilePath extension_path = data_dir().AppendASCII("theme_i18n"); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2055 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2056 | extensions::UnpackedInstaller::Create(service())->Load(extension_path); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 2057 | content::RunAllTasksUntilIdle(); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2058 | EXPECT_EQ(0u, GetErrors().size()); |
| 2059 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2060 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 2061 | const Extension* theme = registry()->enabled_extensions().begin()->get(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2062 | EXPECT_EQ("name", theme->name()); |
| 2063 | EXPECT_EQ("description", theme->description()); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 2064 | |
estade | b8867dff | 2016-11-03 17:33:33 | [diff] [blame] | 2065 | // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 2066 | // temporary directory, but it automatically installs to the extension's |
| 2067 | // directory, and we don't want to copy the whole extension for a unittest. |
estade | b8867dff | 2016-11-03 17:33:33 | [diff] [blame] | 2068 | base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2069 | ASSERT_TRUE(base::PathExists(theme_file)); |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 2070 | ASSERT_TRUE(base::DeleteFile(theme_file, false)); // Not recursive. |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2071 | } |
| 2072 | |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2073 | #if defined(OS_POSIX) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2074 | TEST_F(ExtensionServiceTest, UnpackedExtensionMayContainSymlinkedFiles) { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2075 | base::FilePath source_data_dir = |
| 2076 | data_dir().AppendASCII("unpacked").AppendASCII("symlinks_allowed"); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2077 | |
| 2078 | // Paths to test data files. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2079 | base::FilePath source_manifest = source_data_dir.AppendASCII("manifest.json"); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2080 | ASSERT_TRUE(base::PathExists(source_manifest)); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2081 | base::FilePath source_icon = source_data_dir.AppendASCII("icon.png"); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2082 | ASSERT_TRUE(base::PathExists(source_icon)); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2083 | |
| 2084 | // Set up the temporary extension directory. |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2085 | base::ScopedTempDir temp; |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2086 | ASSERT_TRUE(temp.CreateUniqueTempDir()); |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 2087 | base::FilePath extension_path = temp.GetPath(); |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2088 | base::FilePath manifest = extension_path.Append( |
| 2089 | extensions::kManifestFilename); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2090 | base::FilePath icon_symlink = extension_path.AppendASCII("icon.png"); |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 2091 | base::CopyFile(source_manifest, manifest); |
[email protected] | b264eab | 2013-11-27 23:22:08 | [diff] [blame] | 2092 | base::CreateSymbolicLink(source_icon, icon_symlink); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2093 | |
| 2094 | // Load extension. |
| 2095 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2096 | extensions::UnpackedInstaller::Create(service())->Load(extension_path); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 2097 | content::RunAllTasksUntilIdle(); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2098 | |
| 2099 | EXPECT_TRUE(GetErrors().empty()); |
| 2100 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2101 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2102 | } |
| 2103 | #endif |
| 2104 | |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2105 | // Tests than an unpacked extension with an empty kMetadataFolder loads |
| 2106 | // successfully. |
| 2107 | TEST_F(ExtensionServiceTest, UnpackedExtensionWithEmptyMetadataFolder) { |
Catherine Mullings | f5f1a133 | 2017-08-04 18:29:19 | [diff] [blame] | 2108 | InitializeEmptyExtensionService(); |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2109 | base::ScopedTempDir temp_dir; |
| 2110 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 2111 | base::FilePath extension_dir = base::MakeAbsoluteFilePath(temp_dir.GetPath()); |
| 2112 | base::FilePath metadata_dir = |
| 2113 | extension_dir.Append(extensions::kMetadataFolder); |
| 2114 | PersistExtensionWithPaths(extension_dir, {metadata_dir}, {}); |
| 2115 | EXPECT_TRUE(base::DirectoryExists(metadata_dir)); |
| 2116 | |
| 2117 | extensions::UnpackedInstaller::Create(service())->Load(extension_dir); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 2118 | content::RunAllTasksUntilIdle(); |
Catherine Mullings | f5f1a133 | 2017-08-04 18:29:19 | [diff] [blame] | 2119 | EXPECT_EQ(0u, GetErrors().size()); |
| 2120 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2121 | |
| 2122 | // The kMetadataFolder should have been deleted since it did not contain |
| 2123 | // any non-reserved filenames. |
| 2124 | EXPECT_FALSE(base::DirectoryExists(metadata_dir)); |
Catherine Mullings | f5f1a133 | 2017-08-04 18:29:19 | [diff] [blame] | 2125 | } |
| 2126 | |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2127 | // Tests that an unpacked extension with only reserved filenames in the |
| 2128 | // kMetadataFolder loads successfully. |
| 2129 | TEST_F(ExtensionServiceTest, UnpackedExtensionWithReservedMetadataFiles) { |
Karan Bhatia | 4617866 | 2017-09-11 21:50:45 | [diff] [blame] | 2130 | InitializeEmptyExtensionService(); |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2131 | base::ScopedTempDir temp_dir; |
| 2132 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 2133 | base::FilePath extension_dir = base::MakeAbsoluteFilePath(temp_dir.GetPath()); |
| 2134 | base::FilePath metadata_dir = |
| 2135 | extension_dir.Append(extensions::kMetadataFolder); |
| 2136 | PersistExtensionWithPaths( |
| 2137 | extension_dir, {metadata_dir}, |
| 2138 | extensions::file_util::GetReservedMetadataFilePaths(extension_dir)); |
| 2139 | EXPECT_TRUE(base::DirectoryExists(metadata_dir)); |
| 2140 | |
| 2141 | extensions::UnpackedInstaller::Create(service())->Load(extension_dir); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 2142 | content::RunAllTasksUntilIdle(); |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2143 | EXPECT_EQ(0u, GetErrors().size()); |
| 2144 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 2145 | |
| 2146 | // The kMetadataFolder should have been deleted since it did not contain |
| 2147 | // any non-reserved filenames. |
| 2148 | EXPECT_FALSE(base::DirectoryExists(metadata_dir)); |
| 2149 | } |
| 2150 | |
| 2151 | // Tests that an unpacked extension with non-reserved files in the |
| 2152 | // kMetadataFolder fails to load. |
| 2153 | TEST_F(ExtensionServiceTest, UnpackedExtensionWithUserMetadataFiles) { |
| 2154 | InitializeEmptyExtensionService(); |
| 2155 | base::ScopedTempDir temp_dir; |
| 2156 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 2157 | base::FilePath extension_dir = base::MakeAbsoluteFilePath(temp_dir.GetPath()); |
| 2158 | base::FilePath metadata_dir = |
| 2159 | extension_dir.Append(extensions::kMetadataFolder); |
| 2160 | base::FilePath non_reserved_file = |
| 2161 | metadata_dir.Append(FILE_PATH_LITERAL("a.txt")); |
| 2162 | PersistExtensionWithPaths( |
| 2163 | extension_dir, {metadata_dir}, |
| 2164 | {extensions::file_util::GetVerifiedContentsPath(extension_dir), |
| 2165 | non_reserved_file}); |
| 2166 | EXPECT_TRUE(base::PathExists(non_reserved_file)); |
| 2167 | |
| 2168 | extensions::UnpackedInstaller::Create(service())->Load(extension_dir); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 2169 | content::RunAllTasksUntilIdle(); |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2170 | ASSERT_EQ(1u, GetErrors().size()); |
| 2171 | |
| 2172 | // Format expected error string. |
| 2173 | std::string expected("Failed to load extension from: "); |
| 2174 | expected.append(extension_dir.MaybeAsASCII()) |
| 2175 | .append( |
| 2176 | ". Cannot load extension with file or directory name _metadata. " |
| 2177 | "Filenames starting with \"_\" are reserved for use by the system."); |
| 2178 | |
| 2179 | EXPECT_EQ(base::UTF8ToUTF16(expected), GetErrors()[0]); |
| 2180 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 2181 | |
| 2182 | // Non-reserved filepaths inside the kMetadataFolder should not have been |
| 2183 | // deleted. |
| 2184 | EXPECT_TRUE(base::PathExists(non_reserved_file)); |
| 2185 | } |
| 2186 | |
| 2187 | // Tests than an unpacked extension with an empty kMetadataFolder and a folder |
| 2188 | // beginning with "_" fails to load. |
| 2189 | TEST_F(ExtensionServiceTest, |
| 2190 | UnpackedExtensionWithEmptyMetadataAndUnderscoreFolders) { |
| 2191 | InitializeEmptyExtensionService(); |
| 2192 | base::ScopedTempDir temp_dir; |
| 2193 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 2194 | base::FilePath extension_dir = base::MakeAbsoluteFilePath(temp_dir.GetPath()); |
| 2195 | base::FilePath metadata_dir = |
| 2196 | extension_dir.Append(extensions::kMetadataFolder); |
| 2197 | PersistExtensionWithPaths( |
| 2198 | extension_dir, |
| 2199 | {metadata_dir, extension_dir.Append(FILE_PATH_LITERAL("_badfolder"))}, |
| 2200 | {}); |
| 2201 | |
| 2202 | extensions::UnpackedInstaller::Create(service())->Load(extension_dir); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 2203 | content::RunAllTasksUntilIdle(); |
Catherine Mullings | f5f1a133 | 2017-08-04 18:29:19 | [diff] [blame] | 2204 | EXPECT_EQ(1u, GetErrors().size()); |
| 2205 | |
| 2206 | // Format expected error string. |
| 2207 | std::string expected("Failed to load extension from: "); |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2208 | expected.append(extension_dir.MaybeAsASCII()) |
Catherine Mullings | f5f1a133 | 2017-08-04 18:29:19 | [diff] [blame] | 2209 | .append( |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2210 | ". Cannot load extension with file or directory name _badfolder. " |
| 2211 | "Filenames starting with \"_\" are reserved for use by the system."); |
Catherine Mullings | f5f1a133 | 2017-08-04 18:29:19 | [diff] [blame] | 2212 | |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2213 | EXPECT_EQ(base::UTF8ToUTF16(expected), GetErrors()[0]); |
Catherine Mullings | f5f1a133 | 2017-08-04 18:29:19 | [diff] [blame] | 2214 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2215 | |
| 2216 | // The kMetadataFolder should have been deleted since it did not contain any |
| 2217 | // non-reserved filenames. |
| 2218 | EXPECT_FALSE(base::DirectoryExists(metadata_dir)); |
Catherine Mullings | f5f1a133 | 2017-08-04 18:29:19 | [diff] [blame] | 2219 | } |
| 2220 | |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2221 | // Tests that an unpacked extension with an arbitrary folder beginning with an |
| 2222 | // underscore can't load. |
[email protected] | 5ccca8ad | 2013-08-19 22:35:34 | [diff] [blame] | 2223 | TEST_F(ExtensionServiceTest, UnpackedExtensionMayNotHaveUnderscore) { |
| 2224 | InitializeEmptyExtensionService(); |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2225 | base::ScopedTempDir temp_dir; |
| 2226 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 2227 | base::FilePath extension_dir = base::MakeAbsoluteFilePath(temp_dir.GetPath()); |
| 2228 | base::FilePath underscore_folder = |
| 2229 | extension_dir.Append(FILE_PATH_LITERAL("_badfolder")); |
| 2230 | PersistExtensionWithPaths( |
| 2231 | extension_dir, {underscore_folder}, |
| 2232 | {underscore_folder.Append(FILE_PATH_LITERAL("a.js"))}); |
| 2233 | EXPECT_TRUE(base::DirectoryExists(underscore_folder)); |
| 2234 | |
| 2235 | extensions::UnpackedInstaller::Create(service())->Load(extension_dir); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 2236 | content::RunAllTasksUntilIdle(); |
[email protected] | 5ccca8ad | 2013-08-19 22:35:34 | [diff] [blame] | 2237 | EXPECT_EQ(1u, GetErrors().size()); |
Catherine Mullings | f5f1a133 | 2017-08-04 18:29:19 | [diff] [blame] | 2238 | |
| 2239 | // Format expected error string. |
| 2240 | std::string expected("Failed to load extension from: "); |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2241 | expected.append(extension_dir.MaybeAsASCII()) |
Catherine Mullings | f5f1a133 | 2017-08-04 18:29:19 | [diff] [blame] | 2242 | .append( |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2243 | ". Cannot load extension with file or directory name _badfolder. " |
| 2244 | "Filenames starting with \"_\" are reserved for use by the system."); |
Catherine Mullings | f5f1a133 | 2017-08-04 18:29:19 | [diff] [blame] | 2245 | |
Karan Bhatia | fe12281a | 2017-09-16 02:38:18 | [diff] [blame] | 2246 | EXPECT_EQ(base::UTF8ToUTF16(expected), GetErrors()[0]); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2247 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 5ccca8ad | 2013-08-19 22:35:34 | [diff] [blame] | 2248 | } |
| 2249 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2250 | TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2251 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2252 | service()->Init(); |
[email protected] | b1ac7046 | 2013-08-14 21:33:30 | [diff] [blame] | 2253 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2254 | base::FilePath theme_path = data_dir().AppendASCII("theme_i18n"); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2255 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2256 | const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2257 | |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2258 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2259 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2260 | EXPECT_EQ("name", theme->name()); |
| 2261 | EXPECT_EQ("description", theme->description()); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2262 | } |
| 2263 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2264 | TEST_F(ExtensionServiceTest, InstallApps) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2265 | InitializeEmptyExtensionService(); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2266 | |
| 2267 | // An empty app. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2268 | const Extension* app = |
| 2269 | PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2270 | int pref_count = 0; |
| 2271 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2272 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2273 | ValidateIntegerPref(app->id(), "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2274 | ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2275 | |
| 2276 | // Another app with non-overlapping extent. Should succeed. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2277 | PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2278 | ValidatePrefKeyCount(++pref_count); |
| 2279 | |
| 2280 | // A third app whose extent overlaps the first. Should fail. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2281 | PackAndInstallCRX(data_dir().AppendASCII("app3"), INSTALL_FAILED); |
[email protected] | cd10e28 | 2010-10-26 21:04:51 | [diff] [blame] | 2282 | ValidatePrefKeyCount(pref_count); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2283 | } |
| 2284 | |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2285 | // Tests that file access is OFF by default. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2286 | TEST_F(ExtensionServiceTest, DefaultFileAccess) { |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2287 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2288 | const Extension* extension = PackAndInstallCRX( |
| 2289 | data_dir().AppendASCII("permissions").AppendASCII("files"), INSTALL_NEW); |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2290 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2291 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 2292 | EXPECT_FALSE( |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2293 | ExtensionPrefs::Get(profile())->AllowFileAccess(extension->id())); |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2294 | } |
| 2295 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2296 | TEST_F(ExtensionServiceTest, UpdateApps) { |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2297 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2298 | base::FilePath extensions_path = data_dir().AppendASCII("app_update"); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2299 | |
| 2300 | // First install v1 of a hosted app. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2301 | const Extension* extension = |
| 2302 | InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2303 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2304 | std::string id = extension->id(); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 2305 | ASSERT_EQ(std::string("1"), extension->version().GetString()); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2306 | |
| 2307 | // Now try updating to v2. |
| 2308 | UpdateExtension(id, |
| 2309 | extensions_path.AppendASCII("v2.crx"), |
| 2310 | ENABLED); |
| 2311 | ASSERT_EQ(std::string("2"), |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 2312 | service()->GetExtensionById(id, false)->version().GetString()); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2313 | } |
| 2314 | |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2315 | // Verifies that the NTP page and launch ordinals are kept when updating apps. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2316 | TEST_F(ExtensionServiceTest, UpdateAppsRetainOrdinals) { |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2317 | InitializeEmptyExtensionService(); |
deepak.m1 | 4ba69e6 | 2015-11-17 05:42:12 | [diff] [blame] | 2318 | AppSorting* sorting = ExtensionSystem::Get(profile())->app_sorting(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2319 | base::FilePath extensions_path = data_dir().AppendASCII("app_update"); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2320 | |
| 2321 | // First install v1 of a hosted app. |
| 2322 | const Extension* extension = |
| 2323 | InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2324 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2325 | std::string id = extension->id(); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 2326 | ASSERT_EQ(std::string("1"), extension->version().GetString()); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2327 | |
| 2328 | // Modify the ordinals so we can distinguish them from the defaults. |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 2329 | syncer::StringOrdinal new_page_ordinal = |
| 2330 | sorting->GetPageOrdinal(id).CreateAfter(); |
| 2331 | syncer::StringOrdinal new_launch_ordinal = |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2332 | sorting->GetAppLaunchOrdinal(id).CreateBefore(); |
| 2333 | |
| 2334 | sorting->SetPageOrdinal(id, new_page_ordinal); |
| 2335 | sorting->SetAppLaunchOrdinal(id, new_launch_ordinal); |
| 2336 | |
| 2337 | // Now try updating to v2. |
| 2338 | UpdateExtension(id, extensions_path.AppendASCII("v2.crx"), ENABLED); |
| 2339 | ASSERT_EQ(std::string("2"), |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 2340 | service()->GetExtensionById(id, false)->version().GetString()); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2341 | |
| 2342 | // Verify that the ordinals match. |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 2343 | ASSERT_TRUE(new_page_ordinal.Equals(sorting->GetPageOrdinal(id))); |
| 2344 | ASSERT_TRUE(new_launch_ordinal.Equals(sorting->GetAppLaunchOrdinal(id))); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2345 | } |
| 2346 | |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2347 | // Ensures that the CWS has properly initialized ordinals. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2348 | TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) { |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2349 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2350 | service()->component_loader()->Add( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2351 | IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store"))); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2352 | service()->Init(); |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2353 | |
deepak.m1 | 4ba69e6 | 2015-11-17 05:42:12 | [diff] [blame] | 2354 | AppSorting* sorting = ExtensionSystem::Get(profile())->app_sorting(); |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2355 | EXPECT_TRUE( |
hanxi | a3182da | 2014-09-02 22:51:19 | [diff] [blame] | 2356 | sorting->GetPageOrdinal(extensions::kWebStoreAppId).IsValid()); |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2357 | EXPECT_TRUE( |
hanxi | a3182da | 2014-09-02 22:51:19 | [diff] [blame] | 2358 | sorting->GetAppLaunchOrdinal(extensions::kWebStoreAppId).IsValid()); |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2359 | } |
| 2360 | |
[email protected] | fe10c20 | 2013-03-11 23:44:34 | [diff] [blame] | 2361 | TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2362 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2363 | EXPECT_TRUE(registry()->enabled_extensions().is_empty()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2364 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2365 | int pref_count = 0; |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2366 | |
| 2367 | // Install app1 with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2368 | const Extension* extension = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2369 | PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2370 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2371 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2372 | const std::string id1 = extension->id(); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 2373 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2374 | APIPermission::kUnlimitedStorage)); |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2375 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2376 | extensions::AppLaunchInfo::GetFullLaunchURL(extension))); |
| 2377 | const GURL origin1( |
| 2378 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2379 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 2380 | origin1)); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2381 | |
| 2382 | // Install app2 from the same origin with unlimited storage. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2383 | extension = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2384 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2385 | ASSERT_EQ(2u, registry()->enabled_extensions().size()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2386 | const std::string id2 = extension->id(); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 2387 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2388 | APIPermission::kUnlimitedStorage)); |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2389 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2390 | extensions::AppLaunchInfo::GetFullLaunchURL(extension))); |
| 2391 | const GURL origin2( |
| 2392 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2393 | EXPECT_EQ(origin1, origin2); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2394 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 2395 | origin2)); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2396 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2397 | // Uninstall one of them, unlimited storage should still be granted |
| 2398 | // to the origin. |
Devlin Cronin | 6fd1cd6 | 2017-12-05 19:13:57 | [diff] [blame] | 2399 | UninstallExtension(id1); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2400 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 2401 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 2402 | origin1)); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2403 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2404 | // Uninstall the other, unlimited storage should be revoked. |
Devlin Cronin | 6fd1cd6 | 2017-12-05 19:13:57 | [diff] [blame] | 2405 | UninstallExtension(id2); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2406 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 2407 | EXPECT_FALSE( |
| 2408 | profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 2409 | origin2)); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2410 | } |
| 2411 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2412 | TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2413 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2414 | EXPECT_TRUE(registry()->enabled_extensions().is_empty()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2415 | |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2416 | int pref_count = 0; |
| 2417 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2418 | const Extension* extension = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2419 | PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2420 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2421 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2422 | EXPECT_TRUE(extension->is_app()); |
| 2423 | const std::string id1 = extension->id(); |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2424 | const GURL origin1( |
| 2425 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2426 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected( |
| 2427 | origin1)); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2428 | |
| 2429 | // App 4 has a different origin (maps.google.com). |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2430 | extension = PackAndInstallCRX(data_dir().AppendASCII("app4"), INSTALL_NEW); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2431 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2432 | ASSERT_EQ(2u, registry()->enabled_extensions().size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2433 | const std::string id2 = extension->id(); |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 2434 | const GURL origin2( |
| 2435 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2436 | ASSERT_NE(origin1, origin2); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2437 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected( |
| 2438 | origin2)); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2439 | |
Devlin Cronin | 6fd1cd6 | 2017-12-05 19:13:57 | [diff] [blame] | 2440 | UninstallExtension(id1); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2441 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2442 | |
Devlin Cronin | 6fd1cd6 | 2017-12-05 19:13:57 | [diff] [blame] | 2443 | UninstallExtension(id2); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2444 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2445 | EXPECT_TRUE(registry()->enabled_extensions().is_empty()); |
| 2446 | EXPECT_FALSE( |
| 2447 | profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected( |
| 2448 | origin1)); |
| 2449 | EXPECT_FALSE( |
| 2450 | profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected( |
| 2451 | origin2)); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2452 | } |
| 2453 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2454 | // Test that when an extension version is reinstalled, nothing happens. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2455 | TEST_F(ExtensionServiceTest, Reinstall) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2456 | InitializeEmptyExtensionService(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2457 | |
| 2458 | // A simple extension that should install without error. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2459 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2460 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2461 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2462 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2463 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2464 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2465 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 2466 | // Reinstall the same version, it should overwrite the previous one. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2467 | InstallCRX(path, INSTALL_UPDATED); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2468 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2469 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2470 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2471 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2472 | } |
| 2473 | |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2474 | // Test that we can determine if extensions came from the |
| 2475 | // Chrome web store. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2476 | TEST_F(ExtensionServiceTest, FromWebStore) { |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2477 | InitializeEmptyExtensionService(); |
| 2478 | |
| 2479 | // A simple extension that should install without error. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2480 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2481 | // Not from web store. |
| 2482 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2483 | std::string id = extension->id(); |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2484 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2485 | ValidatePrefKeyCount(1); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2486 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", false)); |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2487 | ASSERT_FALSE(extension->from_webstore()); |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2488 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2489 | // Test install from web store. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2490 | InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store. |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2491 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2492 | ValidatePrefKeyCount(1); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2493 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2494 | |
| 2495 | // Reload so extension gets reinitialized with new value. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2496 | service()->ReloadExtensionsForTest(); |
| 2497 | extension = service()->GetExtensionById(id, false); |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 2498 | ASSERT_TRUE(extension->from_webstore()); |
[email protected] | 3d72972 | 2011-09-20 02:57:09 | [diff] [blame] | 2499 | |
| 2500 | // Upgrade to version 2.0 |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2501 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | 3d72972 | 2011-09-20 02:57:09 | [diff] [blame] | 2502 | UpdateExtension(good_crx, path, ENABLED); |
| 2503 | ValidatePrefKeyCount(1); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2504 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true)); |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2505 | } |
| 2506 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2507 | // Test upgrading a signed extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2508 | TEST_F(ExtensionServiceTest, UpgradeSignedGood) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2509 | InitializeEmptyExtensionService(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2510 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2511 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2512 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2513 | std::string id = extension->id(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2514 | |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 2515 | ASSERT_EQ("1.0.0.0", extension->version().GetString()); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2516 | ASSERT_EQ(0u, GetErrors().size()); |
| 2517 | |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 2518 | // Upgrade to version 1.0.0.1. |
| 2519 | // Also test that the extension's old and new title are correctly retrieved. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2520 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 2521 | InstallCRX(path, INSTALL_UPDATED, Extension::NO_FLAGS, "My extension 1"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2522 | extension = service()->GetExtensionById(id, false); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2523 | |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 2524 | ASSERT_EQ("1.0.0.1", extension->version().GetString()); |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 2525 | ASSERT_EQ("My updated extension 1", extension->name()); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2526 | ASSERT_EQ(0u, GetErrors().size()); |
| 2527 | } |
| 2528 | |
| 2529 | // Test upgrading a signed extension with a bad signature. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2530 | TEST_F(ExtensionServiceTest, UpgradeSignedBad) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2531 | InitializeEmptyExtensionService(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2532 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2533 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2534 | InstallCRX(path, INSTALL_NEW); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2535 | |
| 2536 | // Try upgrading with a bad signature. This should fail during the unpack, |
| 2537 | // because the key will not match the signature. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2538 | path = data_dir().AppendASCII("bad_signature.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2539 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2540 | } |
| 2541 | |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2542 | // Test a normal update via the UpdateExtension API |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2543 | TEST_F(ExtensionServiceTest, UpdateExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2544 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2545 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2546 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2547 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2548 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2549 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2550 | ASSERT_EQ(good_crx, good->id()); |
| 2551 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2552 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2553 | UpdateExtension(good_crx, path, ENABLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2554 | ASSERT_EQ( |
| 2555 | "1.0.0.1", |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 2556 | service()->GetExtensionById(good_crx, false)->version().GetString()); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2557 | } |
| 2558 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2559 | // Extensions should not be updated during browser shutdown. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2560 | TEST_F(ExtensionServiceTest, UpdateExtensionDuringShutdown) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2561 | InitializeEmptyExtensionService(); |
| 2562 | |
| 2563 | // Install an extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2564 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2565 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2566 | ASSERT_EQ(good_crx, good->id()); |
| 2567 | |
| 2568 | // Simulate shutdown. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2569 | service()->set_browser_terminating_for_test(true); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2570 | |
| 2571 | // Update should fail and extension should not be updated. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2572 | path = data_dir().AppendASCII("good2.crx"); |
ginkage | 553af320 | 2015-02-04 12:39:09 | [diff] [blame] | 2573 | bool updated = service()->UpdateExtension( |
| 2574 | extensions::CRXFileInfo(good_crx, path), true, NULL); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2575 | ASSERT_FALSE(updated); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2576 | ASSERT_EQ( |
| 2577 | "1.0.0.0", |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 2578 | service()->GetExtensionById(good_crx, false)->version().GetString()); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2579 | } |
| 2580 | |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2581 | // Test updating a not-already-installed extension - this should fail |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2582 | TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2583 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2584 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2585 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2586 | UpdateExtension(good_crx, path, UPDATED); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 2587 | content::RunAllTasksUntilIdle(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2588 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2589 | ASSERT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2590 | ASSERT_FALSE(installed_); |
| 2591 | ASSERT_EQ(0u, loaded_.size()); |
| 2592 | } |
| 2593 | |
| 2594 | // Makes sure you can't downgrade an extension via UpdateExtension |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2595 | TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2596 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2597 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2598 | base::FilePath path = data_dir().AppendASCII("good2.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2599 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2600 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2601 | ASSERT_EQ("1.0.0.1", good->VersionString()); |
| 2602 | ASSERT_EQ(good_crx, good->id()); |
| 2603 | |
| 2604 | // Change path from good2.crx -> good.crx |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2605 | path = data_dir().AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2606 | UpdateExtension(good_crx, path, FAILED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2607 | ASSERT_EQ( |
| 2608 | "1.0.0.1", |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 2609 | service()->GetExtensionById(good_crx, false)->version().GetString()); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | // Make sure calling update with an identical version does nothing |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2613 | TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2614 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2615 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2616 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2617 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2618 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2619 | ASSERT_EQ(good_crx, good->id()); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2620 | UpdateExtension(good_crx, path, FAILED_SILENTLY); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2621 | } |
| 2622 | |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2623 | // Tests that updating an extension does not clobber old state. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2624 | TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2625 | InitializeEmptyExtensionService(); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2626 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2627 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2628 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2629 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2630 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2631 | ASSERT_EQ(good_crx, good->id()); |
| 2632 | |
| 2633 | // Disable it and allow it to run in incognito. These settings should carry |
| 2634 | // over to the updated version. |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 2635 | service()->DisableExtension(good->id(), |
| 2636 | extensions::disable_reason::DISABLE_USER_ACTION); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2637 | extensions::util::SetIsIncognitoEnabled(good->id(), profile(), true); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2638 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2639 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2640 | UpdateExtension(good_crx, path, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2641 | ASSERT_EQ(1u, registry()->disabled_extensions().size()); |
| 2642 | const Extension* good2 = service()->GetExtensionById(good_crx, true); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 2643 | ASSERT_EQ("1.0.0.1", good2->version().GetString()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2644 | EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good2->id(), profile())); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 2645 | EXPECT_EQ(extensions::disable_reason::DISABLE_USER_ACTION, |
treib | aac30ec | 2015-06-10 09:18:09 | [diff] [blame] | 2646 | ExtensionPrefs::Get(profile())->GetDisableReasons(good2->id())); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2647 | } |
| 2648 | |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2649 | // Tests that updating preserves extension location. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2650 | TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2651 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2652 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2653 | |
catmullings | 22bc237 | 2016-11-02 19:59:35 | [diff] [blame] | 2654 | const Extension* good = InstallCRX(path, Manifest::EXTERNAL_PREF, INSTALL_NEW, |
| 2655 | Extension::NO_FLAGS); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2656 | |
| 2657 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2658 | ASSERT_EQ(good_crx, good->id()); |
| 2659 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2660 | path = data_dir().AppendASCII("good2.crx"); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2661 | UpdateExtension(good_crx, path, ENABLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2662 | const Extension* good2 = service()->GetExtensionById(good_crx, false); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 2663 | ASSERT_EQ("1.0.0.1", good2->version().GetString()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2664 | EXPECT_EQ(good2->location(), Manifest::EXTERNAL_PREF); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2665 | } |
| 2666 | |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2667 | // Makes sure that LOAD extension types can downgrade. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2668 | TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2669 | InitializeEmptyExtensionService(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2670 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2671 | base::ScopedTempDir temp; |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2672 | ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 2673 | |
| 2674 | // We'll write the extension manifest dynamically to a temporary path |
| 2675 | // to make it easier to change the version number. |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 2676 | base::FilePath extension_path = temp.GetPath(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2677 | base::FilePath manifest_path = |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2678 | extension_path.Append(extensions::kManifestFilename); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 2679 | ASSERT_FALSE(base::PathExists(manifest_path)); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2680 | |
| 2681 | // Start with version 2.0. |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 2682 | base::DictionaryValue manifest; |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2683 | manifest.SetString("version", "2.0"); |
| 2684 | manifest.SetString("name", "LOAD Downgrade Test"); |
[email protected] | b3d5285 | 2011-12-07 01:01:11 | [diff] [blame] | 2685 | manifest.SetInteger("manifest_version", 2); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2686 | |
| 2687 | JSONFileValueSerializer serializer(manifest_path); |
| 2688 | ASSERT_TRUE(serializer.Serialize(manifest)); |
| 2689 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2690 | extensions::UnpackedInstaller::Create(service())->Load(extension_path); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 2691 | content::RunAllTasksUntilIdle(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2692 | |
| 2693 | EXPECT_EQ(0u, GetErrors().size()); |
| 2694 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 2695 | EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2696 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2697 | EXPECT_EQ("2.0", loaded_[0]->VersionString()); |
| 2698 | |
| 2699 | // Now set the version number to 1.0, reload the extensions and verify that |
| 2700 | // the downgrade was accepted. |
| 2701 | manifest.SetString("version", "1.0"); |
| 2702 | ASSERT_TRUE(serializer.Serialize(manifest)); |
| 2703 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2704 | extensions::UnpackedInstaller::Create(service())->Load(extension_path); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 2705 | content::RunAllTasksUntilIdle(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2706 | |
| 2707 | EXPECT_EQ(0u, GetErrors().size()); |
| 2708 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 2709 | EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2710 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2711 | EXPECT_EQ("1.0", loaded_[0]->VersionString()); |
| 2712 | } |
| 2713 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2714 | namespace { |
| 2715 | |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 2716 | bool IsExtension(const Extension* extension) { |
| 2717 | return extension->GetType() == Manifest::TYPE_EXTENSION; |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2718 | } |
| 2719 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 2720 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 2721 | std::set<std::string> StringSet(const std::string& s) { |
| 2722 | std::set<std::string> set; |
| 2723 | set.insert(s); |
| 2724 | return set; |
| 2725 | } |
| 2726 | std::set<std::string> StringSet(const std::string& s1, const std::string& s2) { |
| 2727 | std::set<std::string> set = StringSet(s1); |
| 2728 | set.insert(s2); |
| 2729 | return set; |
| 2730 | } |
| 2731 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 2732 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2733 | } // namespace |
| 2734 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2735 | // Test adding a pending extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2736 | TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2737 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2738 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 2739 | const std::string kFakeId(all_zero); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2740 | const GURL kFakeUpdateURL("http:://fake.update/url"); |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 2741 | const bool kFakeRemoteInstall(false); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2742 | |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 2743 | EXPECT_TRUE( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2744 | service()->pending_extension_manager()->AddFromSync( |
| 2745 | kFakeId, |
| 2746 | kFakeUpdateURL, |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 2747 | base::Version(), |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2748 | &IsExtension, |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 2749 | kFakeRemoteInstall)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2750 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 2751 | const extensions::PendingExtensionInfo* pending_extension_info; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2752 | ASSERT_TRUE((pending_extension_info = |
| 2753 | service()->pending_extension_manager()->GetById(kFakeId))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2754 | EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); |
| 2755 | EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); |
[email protected] | 24b5fd4 | 2014-05-17 01:14:18 | [diff] [blame] | 2756 | // Use |
| 2757 | // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()) |
| 2758 | // instead of |
| 2759 | // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install()) |
| 2760 | // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is |
| 2761 | // turned into an error with -Werror=conversion-null: |
| 2762 | // converting 'false' to pointer type for argument 1 of |
| 2763 | // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' |
| 2764 | // https://code.google.com/p/googletest/issues/detail?id=458 |
| 2765 | EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2766 | } |
| 2767 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2768 | namespace { |
| 2769 | const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 2770 | const char kGoodUpdateURL[] = "http://good.update/url"; |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 2771 | const char kGoodVersion[] = "1"; |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2772 | const bool kGoodIsFromSync = true; |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 2773 | const bool kGoodRemoteInstall = false; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2774 | } // namespace |
| 2775 | |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 2776 | // Test installing a pending extension (this goes through |
| 2777 | // ExtensionService::UpdateExtension). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2778 | TEST_F(ExtensionServiceTest, UpdatePendingExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2779 | InitializeEmptyExtensionService(); |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 2780 | EXPECT_TRUE( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2781 | service()->pending_extension_manager()->AddFromSync( |
| 2782 | kGoodId, |
| 2783 | GURL(kGoodUpdateURL), |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 2784 | base::Version(kGoodVersion), |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2785 | &IsExtension, |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 2786 | kGoodRemoteInstall)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2787 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2788 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2789 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2790 | UpdateExtension(kGoodId, path, ENABLED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2791 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2792 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2793 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2794 | const Extension* extension = service()->GetExtensionById(kGoodId, true); |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 2795 | EXPECT_TRUE(extension); |
| 2796 | } |
| 2797 | |
| 2798 | TEST_F(ExtensionServiceTest, UpdatePendingExtensionWrongVersion) { |
| 2799 | InitializeEmptyExtensionService(); |
| 2800 | base::Version other_version("0.1"); |
| 2801 | ASSERT_TRUE(other_version.IsValid()); |
robpercival | dcd8b10 | 2016-01-25 19:39:00 | [diff] [blame] | 2802 | ASSERT_NE(other_version, base::Version(kGoodVersion)); |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 2803 | EXPECT_TRUE( |
| 2804 | service()->pending_extension_manager()->AddFromSync( |
| 2805 | kGoodId, |
| 2806 | GURL(kGoodUpdateURL), |
| 2807 | other_version, |
| 2808 | &IsExtension, |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 2809 | kGoodRemoteInstall)); |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 2810 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
| 2811 | |
| 2812 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 2813 | // After installation, the extension should be disabled, because it's missing |
| 2814 | // permissions. |
| 2815 | UpdateExtension(kGoodId, path, DISABLED); |
| 2816 | |
| 2817 | EXPECT_TRUE( |
| 2818 | ExtensionPrefs::Get(profile())->DidExtensionEscalatePermissions(kGoodId)); |
| 2819 | |
| 2820 | // It should still have been installed though. |
| 2821 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
| 2822 | |
| 2823 | const Extension* extension = service()->GetExtensionById(kGoodId, true); |
| 2824 | EXPECT_TRUE(extension); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2825 | } |
| 2826 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2827 | namespace { |
| 2828 | |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 2829 | bool IsTheme(const Extension* extension) { |
| 2830 | return extension->is_theme(); |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | } // namespace |
| 2834 | |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2835 | // Test updating a pending theme. |
rdevlin.cronin | aa55dfc | 2017-03-23 15:03:04 | [diff] [blame] | 2836 | TEST_F(ExtensionServiceTest, UpdatePendingTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2837 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2838 | EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 2839 | theme_crx, GURL(), base::Version(), &IsTheme, false)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2840 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2841 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2842 | base::FilePath path = data_dir().AppendASCII("theme.crx"); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2843 | UpdateExtension(theme_crx, path, ENABLED); |
| 2844 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2845 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2846 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2847 | const Extension* extension = service()->GetExtensionById(theme_crx, true); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2848 | ASSERT_TRUE(extension); |
| 2849 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2850 | EXPECT_FALSE( |
| 2851 | ExtensionPrefs::Get(profile())->IsExtensionDisabled(extension->id())); |
| 2852 | EXPECT_TRUE(service()->IsExtensionEnabled(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2853 | } |
| 2854 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2855 | // Test updating a pending CRX as if the source is an external extension |
| 2856 | // with an update URL. In this case we don't know if the CRX is a theme |
| 2857 | // or not. |
rdevlin.cronin | 1428ea0 | 2017-03-22 21:15:32 | [diff] [blame] | 2858 | TEST_F(ExtensionServiceTest, UpdatePendingExternalCrx) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2859 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2860 | EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 2861 | theme_crx, |
| 2862 | std::string(), |
| 2863 | GURL(), |
| 2864 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 2865 | Extension::NO_FLAGS, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 2866 | false)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2867 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2868 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2869 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2870 | base::FilePath path = data_dir().AppendASCII("theme.crx"); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2871 | UpdateExtension(theme_crx, path, ENABLED); |
| 2872 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2873 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2874 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2875 | const Extension* extension = service()->GetExtensionById(theme_crx, true); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2876 | ASSERT_TRUE(extension); |
| 2877 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2878 | EXPECT_FALSE( |
| 2879 | ExtensionPrefs::Get(profile())->IsExtensionDisabled(extension->id())); |
| 2880 | EXPECT_TRUE(service()->IsExtensionEnabled(extension->id())); |
| 2881 | EXPECT_FALSE( |
| 2882 | extensions::util::IsIncognitoEnabled(extension->id(), profile())); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2883 | } |
| 2884 | |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2885 | // Test updating a pending CRX as if the source is an external extension |
| 2886 | // with an update URL. The external update should overwrite a sync update, |
| 2887 | // but a sync update should not overwrite a non-sync update. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2888 | TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2889 | InitializeEmptyExtensionService(); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2890 | |
| 2891 | // Add a crx to be installed from the update mechanism. |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 2892 | EXPECT_TRUE( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2893 | service()->pending_extension_manager()->AddFromSync( |
| 2894 | kGoodId, |
| 2895 | GURL(kGoodUpdateURL), |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 2896 | base::Version(), |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2897 | &IsExtension, |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 2898 | kGoodRemoteInstall)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2899 | |
| 2900 | // 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] | 2901 | const extensions::PendingExtensionInfo* pending_extension_info; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2902 | ASSERT_TRUE((pending_extension_info = |
| 2903 | service()->pending_extension_manager()->GetById(kGoodId))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2904 | EXPECT_TRUE(pending_extension_info->is_from_sync()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2905 | |
| 2906 | // Add a crx to be updated, with the same ID, from a non-sync source. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2907 | EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 2908 | kGoodId, |
| 2909 | std::string(), |
| 2910 | GURL(kGoodUpdateURL), |
| 2911 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 2912 | Extension::NO_FLAGS, |
| 2913 | false)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2914 | |
| 2915 | // Check that there is a pending crx, with is_from_sync set to false. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2916 | ASSERT_TRUE((pending_extension_info = |
| 2917 | service()->pending_extension_manager()->GetById(kGoodId))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2918 | EXPECT_FALSE(pending_extension_info->is_from_sync()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2919 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2920 | pending_extension_info->install_source()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2921 | |
| 2922 | // Add a crx to be installed from the update mechanism. |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 2923 | EXPECT_FALSE( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2924 | service()->pending_extension_manager()->AddFromSync( |
| 2925 | kGoodId, |
| 2926 | GURL(kGoodUpdateURL), |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 2927 | base::Version(), |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2928 | &IsExtension, |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 2929 | kGoodRemoteInstall)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2930 | |
| 2931 | // Check that the external, non-sync update was not overridden. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2932 | ASSERT_TRUE((pending_extension_info = |
| 2933 | service()->pending_extension_manager()->GetById(kGoodId))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2934 | EXPECT_FALSE(pending_extension_info->is_from_sync()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2935 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2936 | pending_extension_info->install_source()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2937 | } |
| 2938 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2939 | // Updating a theme should fail if the updater is explicitly told that |
| 2940 | // the CRX is not a theme. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2941 | TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2942 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2943 | EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 2944 | theme_crx, GURL(), base::Version(), &IsExtension, false)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2945 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2946 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2947 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2948 | base::FilePath path = data_dir().AppendASCII("theme.crx"); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2949 | UpdateExtension(theme_crx, path, FAILED_SILENTLY); |
| 2950 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2951 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2952 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2953 | const Extension* extension = service()->GetExtensionById(theme_crx, true); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2954 | ASSERT_FALSE(extension); |
| 2955 | } |
| 2956 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2957 | // TODO(akalin): Test updating a pending extension non-silently once |
| 2958 | // we can mock out ExtensionInstallUI and inject our version into |
| 2959 | // UpdateExtension(). |
| 2960 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2961 | // Test updating a pending extension which fails the should-install test. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2962 | TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2963 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2964 | // Add pending extension with a flipped is_theme. |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 2965 | EXPECT_TRUE( |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2966 | service()->pending_extension_manager()->AddFromSync( |
| 2967 | kGoodId, |
| 2968 | GURL(kGoodUpdateURL), |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 2969 | base::Version(), |
[email protected] | 6338fa3 | 2014-07-16 21:41:59 | [diff] [blame] | 2970 | &IsTheme, |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 2971 | kGoodRemoteInstall)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2972 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2973 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2974 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2975 | UpdateExtension(kGoodId, path, UPDATED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2976 | |
| 2977 | // TODO(akalin): Figure out how to check that the extensions |
| 2978 | // directory is cleaned up properly in OnExtensionInstalled(). |
| 2979 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2980 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2981 | } |
| 2982 | |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2983 | // TODO(akalin): Figure out how to test that installs of pending |
| 2984 | // unsyncable extensions are blocked. |
| 2985 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2986 | // Test updating a pending extension for one that is not pending. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2987 | TEST_F(ExtensionServiceTest, UpdatePendingExtensionNotPending) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2988 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2989 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2990 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2991 | UpdateExtension(kGoodId, path, UPDATED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2992 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 2993 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | // Test updating a pending extension for one that is already |
| 2997 | // installed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2998 | TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2999 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3000 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3001 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3002 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3003 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3004 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 3005 | EXPECT_FALSE(good->is_theme()); |
| 3006 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3007 | // Use AddExtensionImpl() as AddFrom*() would balk. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3008 | service()->pending_extension_manager()->AddExtensionImpl( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 3009 | good->id(), |
| 3010 | std::string(), |
| 3011 | extensions::ManifestURL::GetUpdateURL(good), |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 3012 | base::Version(), |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 3013 | &IsExtension, |
| 3014 | kGoodIsFromSync, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 3015 | Manifest::INTERNAL, |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 3016 | Extension::NO_FLAGS, |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 3017 | false, |
| 3018 | kGoodRemoteInstall); |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3019 | UpdateExtension(good->id(), path, ENABLED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3020 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3021 | EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 3022 | } |
| 3023 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3024 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3025 | // Tests blacklisting then unblacklisting extensions after the service has been |
| 3026 | // initialized. |
[email protected] | 7d9b4e3 | 2013-10-25 06:11:54 | [diff] [blame] | 3027 | TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3028 | extensions::TestBlacklist test_blacklist; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3029 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3030 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3031 | test_blacklist.Attach(service()->blacklist_); |
| 3032 | service()->Init(); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3033 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3034 | const extensions::ExtensionSet& enabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3035 | registry()->enabled_extensions(); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3036 | const extensions::ExtensionSet& blacklisted_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3037 | registry()->blacklisted_extensions(); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3038 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3039 | EXPECT_TRUE(enabled_extensions.Contains(good0) && |
| 3040 | !blacklisted_extensions.Contains(good0)); |
| 3041 | EXPECT_TRUE(enabled_extensions.Contains(good1) && |
| 3042 | !blacklisted_extensions.Contains(good1)); |
| 3043 | EXPECT_TRUE(enabled_extensions.Contains(good2) && |
| 3044 | !blacklisted_extensions.Contains(good2)); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3045 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3046 | EXPECT_FALSE(IsPrefExist(good0, "blacklist")); |
[email protected] | e636c81 | 2013-09-23 05:51:08 | [diff] [blame] | 3047 | EXPECT_FALSE(IsPrefExist(good1, "blacklist")); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3048 | EXPECT_FALSE(IsPrefExist(good2, "blacklist")); |
| 3049 | EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
| 3050 | |
| 3051 | // Blacklist good0 and good1 (and an invalid extension ID). |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3052 | test_blacklist.SetBlacklistState( |
| 3053 | good0, extensions::BLACKLISTED_MALWARE, true); |
| 3054 | test_blacklist.SetBlacklistState( |
| 3055 | good1, extensions::BLACKLISTED_MALWARE, true); |
| 3056 | test_blacklist.SetBlacklistState( |
| 3057 | "invalid_id", extensions::BLACKLISTED_MALWARE, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3058 | content::RunAllTasksUntilIdle(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3059 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3060 | EXPECT_TRUE(!enabled_extensions.Contains(good0) && |
| 3061 | blacklisted_extensions.Contains(good0)); |
| 3062 | EXPECT_TRUE(!enabled_extensions.Contains(good1) && |
| 3063 | blacklisted_extensions.Contains(good1)); |
| 3064 | EXPECT_TRUE(enabled_extensions.Contains(good2) && |
| 3065 | !blacklisted_extensions.Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3066 | |
| 3067 | EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); |
| 3068 | EXPECT_TRUE(ValidateBooleanPref(good1, "blacklist", true)); |
| 3069 | EXPECT_FALSE(IsPrefExist(good2, "blacklist")); |
| 3070 | EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
| 3071 | |
| 3072 | // Un-blacklist good1 and blacklist good2. |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3073 | test_blacklist.Clear(false); |
| 3074 | test_blacklist.SetBlacklistState( |
| 3075 | good0, extensions::BLACKLISTED_MALWARE, true); |
| 3076 | test_blacklist.SetBlacklistState( |
| 3077 | good2, extensions::BLACKLISTED_MALWARE, true); |
| 3078 | test_blacklist.SetBlacklistState( |
| 3079 | "invalid_id", extensions::BLACKLISTED_MALWARE, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3080 | content::RunAllTasksUntilIdle(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3081 | |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3082 | EXPECT_TRUE(!enabled_extensions.Contains(good0) && |
| 3083 | blacklisted_extensions.Contains(good0)); |
| 3084 | EXPECT_TRUE(enabled_extensions.Contains(good1) && |
| 3085 | !blacklisted_extensions.Contains(good1)); |
| 3086 | EXPECT_TRUE(!enabled_extensions.Contains(good2) && |
| 3087 | blacklisted_extensions.Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3088 | |
| 3089 | EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); |
| 3090 | EXPECT_FALSE(IsPrefExist(good1, "blacklist")); |
| 3091 | EXPECT_TRUE(ValidateBooleanPref(good2, "blacklist", true)); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 3092 | EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3093 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3094 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3095 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3096 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3097 | // Tests trying to install a blacklisted extension. |
[email protected] | e0cbfc4 | 2013-11-07 00:10:10 | [diff] [blame] | 3098 | TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) { |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3099 | scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( |
| 3100 | new FakeSafeBrowsingDatabaseManager(true)); |
| 3101 | Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); |
| 3102 | |
[email protected] | 1747eac0 | 2013-09-23 10:58:42 | [diff] [blame] | 3103 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3104 | service()->Init(); |
[email protected] | 1747eac0 | 2013-09-23 10:58:42 | [diff] [blame] | 3105 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3106 | // After blacklisting good_crx, we cannot install it. |
| 3107 | blacklist_db->SetUnsafe(good_crx).NotifyUpdate(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3108 | content::RunAllTasksUntilIdle(); |
[email protected] | 1747eac0 | 2013-09-23 10:58:42 | [diff] [blame] | 3109 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3110 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 3111 | // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't |
| 3112 | // decide to install this silently. Somebody should fix these tests, all |
| 3113 | // 6,000 lines of them. Hah! |
| 3114 | InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3115 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3116 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3117 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3118 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3119 | #if defined(ENABLE_BLACKLIST_TESTS) |
atuchin | 6dc7c44 | 2016-07-20 07:04:34 | [diff] [blame] | 3120 | // Tests that previously blacklisted extension will be enabled if it is removed |
| 3121 | // from the blacklist. Also checks that all blacklisted preferences will be |
| 3122 | // cleared in that case. |
| 3123 | TEST_F(ExtensionServiceTest, RemoveExtensionFromBlacklist) { |
| 3124 | extensions::TestBlacklist test_blacklist; |
| 3125 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3126 | InitializeGoodInstalledExtensionService(); |
| 3127 | test_blacklist.Attach(service()->blacklist_); |
| 3128 | service()->Init(); |
| 3129 | |
| 3130 | ASSERT_TRUE(registry()->enabled_extensions().Contains(good0)); |
| 3131 | extensions::TestExtensionRegistryObserver observer( |
| 3132 | extensions::ExtensionRegistry::Get(profile()), good0); |
| 3133 | |
| 3134 | // Add the extension to the blacklist. |
| 3135 | test_blacklist.SetBlacklistState(good0, extensions::BLACKLISTED_MALWARE, |
| 3136 | true); |
| 3137 | observer.WaitForExtensionUnloaded(); |
| 3138 | |
| 3139 | // The extension should be disabled, both "blacklist" and "blacklist_state" |
| 3140 | // prefs should be set. |
vmpstr | ae72b08 | 2016-07-25 21:55:47 | [diff] [blame] | 3141 | auto* prefs = ExtensionPrefs::Get(profile()); |
atuchin | 6dc7c44 | 2016-07-20 07:04:34 | [diff] [blame] | 3142 | EXPECT_FALSE(registry()->enabled_extensions().Contains(good0)); |
| 3143 | EXPECT_TRUE(prefs->IsExtensionBlacklisted(good0)); |
| 3144 | EXPECT_EQ(extensions::BLACKLISTED_MALWARE, |
| 3145 | prefs->GetExtensionBlacklistState(good0)); |
| 3146 | |
| 3147 | // Remove the extension from the blacklist. |
| 3148 | test_blacklist.SetBlacklistState(good0, extensions::NOT_BLACKLISTED, true); |
| 3149 | observer.WaitForExtensionLoaded()->id(); |
| 3150 | |
| 3151 | // The extension should be enabled, both "blacklist" and "blacklist_state" |
| 3152 | // should be cleared. |
| 3153 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good0)); |
| 3154 | EXPECT_FALSE(prefs->IsExtensionBlacklisted(good0)); |
| 3155 | EXPECT_EQ(extensions::NOT_BLACKLISTED, |
| 3156 | prefs->GetExtensionBlacklistState(good0)); |
| 3157 | } |
| 3158 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3159 | |
| 3160 | #if defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3161 | // Unload blacklisted extension on policy change. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3162 | TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3163 | extensions::TestBlacklist test_blacklist; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3164 | |
| 3165 | // A profile with no extensions installed. |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 3166 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3167 | test_blacklist.Attach(service()->blacklist_); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3168 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3169 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3170 | |
| 3171 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 3172 | EXPECT_EQ(good_crx, good->id()); |
| 3173 | UpdateExtension(good_crx, path, FAILED_SILENTLY); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3174 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3175 | |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3176 | { |
| 3177 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 3178 | pref.SetIndividualExtensionInstallationAllowed(good_crx, true); |
| 3179 | } |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3180 | |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3181 | test_blacklist.SetBlacklistState( |
| 3182 | good_crx, extensions::BLACKLISTED_MALWARE, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3183 | content::RunAllTasksUntilIdle(); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3184 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3185 | // The good_crx is blacklisted and the whitelist doesn't negate it. |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3186 | ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3187 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3188 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3189 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3190 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3191 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3192 | // Tests that a blacklisted extension is eventually unloaded on startup, if it |
| 3193 | // wasn't already. |
[email protected] | e0cbfc4 | 2013-11-07 00:10:10 | [diff] [blame] | 3194 | TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3195 | extensions::TestBlacklist test_blacklist; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3196 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3197 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3198 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3199 | test_blacklist.Attach(service()->blacklist_); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3200 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3201 | // Blacklist good1 before the service initializes. |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3202 | test_blacklist.SetBlacklistState( |
| 3203 | good1, extensions::BLACKLISTED_MALWARE, false); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3204 | |
| 3205 | // Load extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3206 | service()->Init(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3207 | ASSERT_EQ(3u, loaded_.size()); // hasn't had time to blacklist yet |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3208 | |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3209 | content::RunAllTasksUntilIdle(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3210 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3211 | ASSERT_EQ(1u, registry()->blacklisted_extensions().size()); |
| 3212 | ASSERT_EQ(2u, registry()->enabled_extensions().size()); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 3213 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3214 | ASSERT_TRUE(registry()->enabled_extensions().Contains(good0)); |
| 3215 | ASSERT_TRUE(registry()->blacklisted_extensions().Contains(good1)); |
| 3216 | ASSERT_TRUE(registry()->enabled_extensions().Contains(good2)); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3217 | } |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3218 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3219 | |
| 3220 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3221 | // Tests extensions blacklisted in prefs on startup; one still blacklisted by |
| 3222 | // safe browsing, the other not. The not-blacklisted one should recover. |
| 3223 | TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) { |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3224 | extensions::TestBlacklist test_blacklist; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3225 | |
| 3226 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3227 | test_blacklist.Attach(service()->blacklist_); |
atuchin | 6dc7c44 | 2016-07-20 07:04:34 | [diff] [blame] | 3228 | ExtensionPrefs::Get(profile())->SetExtensionBlacklistState( |
| 3229 | good0, extensions::BLACKLISTED_MALWARE); |
| 3230 | ExtensionPrefs::Get(profile())->SetExtensionBlacklistState( |
| 3231 | good1, extensions::BLACKLISTED_MALWARE); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3232 | |
[email protected] | f71b582c | 2014-01-10 17:03:15 | [diff] [blame] | 3233 | test_blacklist.SetBlacklistState( |
| 3234 | good1, extensions::BLACKLISTED_MALWARE, false); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3235 | |
[email protected] | 27e52832 | 2014-05-27 20:54:30 | [diff] [blame] | 3236 | // Extension service hasn't loaded yet, but IsExtensionEnabled reads out of |
| 3237 | // prefs. Ensure it takes into account the blacklist state (crbug.com/373842). |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3238 | EXPECT_FALSE(service()->IsExtensionEnabled(good0)); |
| 3239 | EXPECT_FALSE(service()->IsExtensionEnabled(good1)); |
| 3240 | EXPECT_TRUE(service()->IsExtensionEnabled(good2)); |
[email protected] | 27e52832 | 2014-05-27 20:54:30 | [diff] [blame] | 3241 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3242 | service()->Init(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3243 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3244 | EXPECT_EQ(2u, registry()->blacklisted_extensions().size()); |
| 3245 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3246 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3247 | EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good0)); |
| 3248 | EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good1)); |
| 3249 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3250 | |
| 3251 | // Give time for the blacklist to update. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3252 | content::RunAllTasksUntilIdle(); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3253 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3254 | EXPECT_EQ(1u, registry()->blacklisted_extensions().size()); |
| 3255 | EXPECT_EQ(2u, registry()->enabled_extensions().size()); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3256 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3257 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good0)); |
| 3258 | EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good1)); |
| 3259 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good2)); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 3260 | } |
| 3261 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3262 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3263 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3264 | // Extension is added to blacklist with BLACKLISTED_POTENTIALLY_UNWANTED state |
| 3265 | // after it is installed. It is then successfully re-enabled by the user. |
| 3266 | TEST_F(ExtensionServiceTest, GreylistedExtensionDisabled) { |
| 3267 | extensions::TestBlacklist test_blacklist; |
| 3268 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3269 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3270 | test_blacklist.Attach(service()->blacklist_); |
| 3271 | service()->Init(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3272 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3273 | const extensions::ExtensionSet& enabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3274 | registry()->enabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3275 | const extensions::ExtensionSet& disabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3276 | registry()->disabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3277 | |
| 3278 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3279 | EXPECT_TRUE(enabled_extensions.Contains(good1)); |
| 3280 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3281 | |
| 3282 | // Blacklist good0 and good1 (and an invalid extension ID). |
| 3283 | test_blacklist.SetBlacklistState( |
| 3284 | good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); |
| 3285 | test_blacklist.SetBlacklistState( |
| 3286 | good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); |
| 3287 | test_blacklist.SetBlacklistState( |
| 3288 | "invalid_id", extensions::BLACKLISTED_MALWARE, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3289 | content::RunAllTasksUntilIdle(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3290 | |
| 3291 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3292 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3293 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3294 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3295 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3296 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3297 | |
| 3298 | ValidateIntegerPref( |
| 3299 | good0, "blacklist_state", extensions::BLACKLISTED_CWS_POLICY_VIOLATION); |
| 3300 | ValidateIntegerPref( |
| 3301 | good1, "blacklist_state", extensions::BLACKLISTED_POTENTIALLY_UNWANTED); |
| 3302 | |
| 3303 | // Now user enables good0. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3304 | service()->EnableExtension(good0); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3305 | |
| 3306 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3307 | EXPECT_FALSE(disabled_extensions.Contains(good0)); |
| 3308 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3309 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3310 | |
| 3311 | // Remove extensions from blacklist. |
| 3312 | test_blacklist.SetBlacklistState( |
| 3313 | good0, extensions::NOT_BLACKLISTED, true); |
| 3314 | test_blacklist.SetBlacklistState( |
| 3315 | good1, extensions::NOT_BLACKLISTED, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3316 | content::RunAllTasksUntilIdle(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3317 | |
| 3318 | // All extensions are enabled. |
| 3319 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3320 | EXPECT_FALSE(disabled_extensions.Contains(good0)); |
| 3321 | EXPECT_TRUE(enabled_extensions.Contains(good1)); |
| 3322 | EXPECT_FALSE(disabled_extensions.Contains(good1)); |
| 3323 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3324 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3325 | } |
| 3326 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3327 | |
| 3328 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3329 | // When extension is removed from greylist, do not re-enable it if it is |
| 3330 | // disabled by user. |
| 3331 | TEST_F(ExtensionServiceTest, GreylistDontEnableManuallyDisabled) { |
| 3332 | extensions::TestBlacklist test_blacklist; |
| 3333 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3334 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3335 | test_blacklist.Attach(service()->blacklist_); |
| 3336 | service()->Init(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3337 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3338 | const extensions::ExtensionSet& enabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3339 | registry()->enabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3340 | const extensions::ExtensionSet& disabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3341 | registry()->disabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3342 | |
| 3343 | // Manually disable. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3344 | service()->DisableExtension(good0, |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 3345 | extensions::disable_reason::DISABLE_USER_ACTION); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3346 | |
| 3347 | test_blacklist.SetBlacklistState( |
| 3348 | good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); |
| 3349 | test_blacklist.SetBlacklistState( |
| 3350 | good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); |
| 3351 | test_blacklist.SetBlacklistState( |
| 3352 | good2, extensions::BLACKLISTED_SECURITY_VULNERABILITY, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3353 | content::RunAllTasksUntilIdle(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3354 | |
| 3355 | // All extensions disabled. |
| 3356 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3357 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3358 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3359 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3360 | EXPECT_FALSE(enabled_extensions.Contains(good2)); |
| 3361 | EXPECT_TRUE(disabled_extensions.Contains(good2)); |
| 3362 | |
| 3363 | // Greylisted extension can be enabled. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3364 | service()->EnableExtension(good1); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3365 | EXPECT_TRUE(enabled_extensions.Contains(good1)); |
| 3366 | EXPECT_FALSE(disabled_extensions.Contains(good1)); |
| 3367 | |
| 3368 | // good1 is now manually disabled. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3369 | service()->DisableExtension(good1, |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 3370 | extensions::disable_reason::DISABLE_USER_ACTION); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3371 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3372 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3373 | |
| 3374 | // Remove extensions from blacklist. |
| 3375 | test_blacklist.SetBlacklistState( |
| 3376 | good0, extensions::NOT_BLACKLISTED, true); |
| 3377 | test_blacklist.SetBlacklistState( |
| 3378 | good1, extensions::NOT_BLACKLISTED, true); |
| 3379 | test_blacklist.SetBlacklistState( |
| 3380 | good2, extensions::NOT_BLACKLISTED, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3381 | content::RunAllTasksUntilIdle(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3382 | |
| 3383 | // good0 and good1 remain disabled. |
| 3384 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3385 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3386 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3387 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3388 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3389 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3390 | } |
| 3391 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3392 | |
| 3393 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3394 | // Blacklisted extension with unknown state are not enabled/disabled. |
| 3395 | TEST_F(ExtensionServiceTest, GreylistUnknownDontChange) { |
| 3396 | extensions::TestBlacklist test_blacklist; |
| 3397 | // A profile with 3 extensions installed: good0, good1, and good2. |
| 3398 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3399 | test_blacklist.Attach(service()->blacklist_); |
| 3400 | service()->Init(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3401 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3402 | const extensions::ExtensionSet& enabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3403 | registry()->enabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3404 | const extensions::ExtensionSet& disabled_extensions = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3405 | registry()->disabled_extensions(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3406 | |
| 3407 | test_blacklist.SetBlacklistState( |
| 3408 | good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true); |
| 3409 | test_blacklist.SetBlacklistState( |
| 3410 | good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3411 | content::RunAllTasksUntilIdle(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3412 | |
| 3413 | EXPECT_FALSE(enabled_extensions.Contains(good0)); |
| 3414 | EXPECT_TRUE(disabled_extensions.Contains(good0)); |
| 3415 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3416 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3417 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3418 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3419 | |
| 3420 | test_blacklist.SetBlacklistState( |
| 3421 | good0, extensions::NOT_BLACKLISTED, true); |
| 3422 | test_blacklist.SetBlacklistState( |
| 3423 | good1, extensions::BLACKLISTED_UNKNOWN, true); |
| 3424 | test_blacklist.SetBlacklistState( |
| 3425 | good2, extensions::BLACKLISTED_UNKNOWN, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3426 | content::RunAllTasksUntilIdle(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3427 | |
| 3428 | // good0 re-enabled, other remain as they were. |
| 3429 | EXPECT_TRUE(enabled_extensions.Contains(good0)); |
| 3430 | EXPECT_FALSE(disabled_extensions.Contains(good0)); |
| 3431 | EXPECT_FALSE(enabled_extensions.Contains(good1)); |
| 3432 | EXPECT_TRUE(disabled_extensions.Contains(good1)); |
| 3433 | EXPECT_TRUE(enabled_extensions.Contains(good2)); |
| 3434 | EXPECT_FALSE(disabled_extensions.Contains(good2)); |
| 3435 | } |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3436 | |
| 3437 | // Tests that blacklisted extensions cannot be reloaded, both those loaded |
| 3438 | // before and after extension service startup. |
| 3439 | TEST_F(ExtensionServiceTest, ReloadBlacklistedExtension) { |
| 3440 | extensions::TestBlacklist test_blacklist; |
| 3441 | |
| 3442 | InitializeGoodInstalledExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3443 | test_blacklist.Attach(service()->blacklist_); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3444 | |
| 3445 | test_blacklist.SetBlacklistState( |
| 3446 | good1, extensions::BLACKLISTED_MALWARE, false); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3447 | service()->Init(); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3448 | test_blacklist.SetBlacklistState( |
| 3449 | good2, extensions::BLACKLISTED_MALWARE, false); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3450 | content::RunAllTasksUntilIdle(); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3451 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3452 | EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs()); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3453 | EXPECT_EQ(StringSet(good1, good2), |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3454 | registry()->blacklisted_extensions().GetIDs()); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3455 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3456 | service()->ReloadExtension(good1); |
| 3457 | service()->ReloadExtension(good2); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3458 | content::RunAllTasksUntilIdle(); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3459 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3460 | EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs()); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3461 | EXPECT_EQ(StringSet(good1, good2), |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3462 | registry()->blacklisted_extensions().GetIDs()); |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 3463 | } |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 3464 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3465 | |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 3466 | // Tests blocking then unblocking enabled extensions after the service has been |
| 3467 | // initialized. |
| 3468 | TEST_F(ExtensionServiceTest, BlockAndUnblockEnabledExtension) { |
| 3469 | InitializeGoodInstalledExtensionService(); |
| 3470 | service()->Init(); |
| 3471 | |
| 3472 | AssertExtensionBlocksAndUnblocks(true, good0); |
| 3473 | } |
| 3474 | |
| 3475 | // Tests blocking then unblocking disabled extensions after the service has been |
| 3476 | // initialized. |
| 3477 | TEST_F(ExtensionServiceTest, BlockAndUnblockDisabledExtension) { |
| 3478 | InitializeGoodInstalledExtensionService(); |
| 3479 | service()->Init(); |
| 3480 | |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 3481 | service()->DisableExtension(good0, |
| 3482 | extensions::disable_reason::DISABLE_RELOAD); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 3483 | |
| 3484 | AssertExtensionBlocksAndUnblocks(true, good0); |
| 3485 | } |
| 3486 | |
| 3487 | // Tests blocking then unblocking terminated extensions after the service has |
| 3488 | // been initialized. |
| 3489 | TEST_F(ExtensionServiceTest, BlockAndUnblockTerminatedExtension) { |
| 3490 | InitializeGoodInstalledExtensionService(); |
| 3491 | service()->Init(); |
| 3492 | |
| 3493 | TerminateExtension(good0); |
| 3494 | |
| 3495 | AssertExtensionBlocksAndUnblocks(true, good0); |
| 3496 | } |
| 3497 | |
| 3498 | // Tests blocking then unblocking policy-forced extensions after the service has |
| 3499 | // been initialized. |
| 3500 | TEST_F(ExtensionServiceTest, BlockAndUnblockPolicyExtension) { |
| 3501 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
| 3502 | |
| 3503 | { |
| 3504 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 3505 | // // Blacklist everything. |
| 3506 | // pref.SetBlacklistedByDefault(true); |
| 3507 | // Mark good.crx for force-installation. |
| 3508 | pref.SetIndividualExtensionAutoInstalled( |
| 3509 | good_crx, "http://example.com/update_url", true); |
| 3510 | } |
| 3511 | |
| 3512 | // Have policy force-install an extension. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 3513 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 3514 | AddMockExternalProvider(Manifest::EXTERNAL_POLICY_DOWNLOAD); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 3515 | provider->UpdateOrAddExtension( |
| 3516 | good_crx, "1.0.0.0", data_dir().AppendASCII("good_crx")); |
| 3517 | |
| 3518 | // Reloading extensions should find our externally registered extension |
| 3519 | // and install it. |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 3520 | WaitForExternalExtensionInstalled(); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 3521 | |
| 3522 | AssertExtensionBlocksAndUnblocks(false, good_crx); |
| 3523 | } |
| 3524 | |
| 3525 | |
| 3526 | #if defined(ENABLE_BLACKLIST_TESTS) |
| 3527 | // Tests blocking then unblocking extensions that are blacklisted both before |
| 3528 | // and after Init(). |
| 3529 | TEST_F(ExtensionServiceTest, BlockAndUnblockBlacklistedExtension) { |
| 3530 | extensions::TestBlacklist test_blacklist; |
| 3531 | |
| 3532 | InitializeGoodInstalledExtensionService(); |
| 3533 | test_blacklist.Attach(service()->blacklist_); |
| 3534 | |
| 3535 | test_blacklist.SetBlacklistState( |
| 3536 | good0, extensions::BLACKLISTED_MALWARE, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3537 | content::RunAllTasksUntilIdle(); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 3538 | |
| 3539 | service()->Init(); |
| 3540 | |
| 3541 | test_blacklist.SetBlacklistState( |
| 3542 | good1, extensions::BLACKLISTED_MALWARE, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3543 | content::RunAllTasksUntilIdle(); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 3544 | |
| 3545 | // Blacklisted extensions stay blacklisted. |
| 3546 | AssertExtensionBlocksAndUnblocks(false, good0); |
| 3547 | AssertExtensionBlocksAndUnblocks(false, good1); |
| 3548 | |
| 3549 | service()->BlockAllExtensions(); |
| 3550 | |
| 3551 | // Remove an extension from the blacklist while the service is blocked. |
| 3552 | test_blacklist.SetBlacklistState( |
| 3553 | good0, extensions::NOT_BLACKLISTED, true); |
| 3554 | // Add an extension to the blacklist while the service is blocked. |
| 3555 | test_blacklist.SetBlacklistState( |
| 3556 | good2, extensions::BLACKLISTED_MALWARE, true); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3557 | content::RunAllTasksUntilIdle(); |
mlerman | 6a37b6a4 | 2014-11-26 22:10:53 | [diff] [blame] | 3558 | |
| 3559 | // Go directly to blocked, do not pass go, do not collect $200. |
| 3560 | ASSERT_TRUE(IsBlocked(good0)); |
| 3561 | // Get on the blacklist - even if you were blocked! |
| 3562 | ASSERT_FALSE(IsBlocked(good2)); |
| 3563 | } |
| 3564 | #endif // defined(ENABLE_BLACKLIST_TESTS) |
| 3565 | |
| 3566 | // Tests blocking then unblocking enabled component extensions after the service |
| 3567 | // has been initialized. |
| 3568 | TEST_F(ExtensionServiceTest, BlockAndUnblockEnabledComponentExtension) { |
| 3569 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
| 3570 | |
| 3571 | // Install a component extension. |
| 3572 | base::FilePath path = data_dir() |
| 3573 | .AppendASCII("good") |
| 3574 | .AppendASCII("Extensions") |
| 3575 | .AppendASCII(good0) |
| 3576 | .AppendASCII("1.0.0.0"); |
| 3577 | std::string manifest; |
| 3578 | ASSERT_TRUE(base::ReadFileToString( |
| 3579 | path.Append(extensions::kManifestFilename), &manifest)); |
| 3580 | service()->component_loader()->Add(manifest, path); |
| 3581 | service()->Init(); |
| 3582 | |
| 3583 | // Component extension should never block. |
| 3584 | AssertExtensionBlocksAndUnblocks(false, good0); |
| 3585 | } |
| 3586 | |
| 3587 | // Tests blocking then unblocking a theme after the service has been |
| 3588 | // initialized. |
| 3589 | TEST_F(ExtensionServiceTest, BlockAndUnblockTheme) { |
| 3590 | InitializeEmptyExtensionService(); |
| 3591 | service()->Init(); |
| 3592 | |
| 3593 | base::FilePath path = data_dir().AppendASCII("theme.crx"); |
| 3594 | InstallCRX(path, INSTALL_NEW); |
| 3595 | |
| 3596 | AssertExtensionBlocksAndUnblocks(true, theme_crx); |
| 3597 | } |
| 3598 | |
| 3599 | // Tests that blocking extensions before Init() results in loading blocked |
| 3600 | // extensions. |
| 3601 | TEST_F(ExtensionServiceTest, WillNotLoadExtensionsWhenBlocked) { |
| 3602 | InitializeGoodInstalledExtensionService(); |
| 3603 | |
| 3604 | service()->BlockAllExtensions(); |
| 3605 | |
| 3606 | service()->Init(); |
| 3607 | |
| 3608 | ASSERT_TRUE(IsBlocked(good0)); |
| 3609 | ASSERT_TRUE(IsBlocked(good0)); |
| 3610 | ASSERT_TRUE(IsBlocked(good0)); |
| 3611 | } |
| 3612 | |
mlerman | 3690e5be | 2014-12-01 22:57:44 | [diff] [blame] | 3613 | // Tests that IsEnabledExtension won't crash on an uninstalled extension. |
| 3614 | TEST_F(ExtensionServiceTest, IsEnabledExtensionBlockedAndNotInstalled) { |
| 3615 | InitializeEmptyExtensionService(); |
| 3616 | |
| 3617 | service()->BlockAllExtensions(); |
| 3618 | |
| 3619 | service()->IsExtensionEnabled(theme_crx); |
| 3620 | } |
| 3621 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3622 | // Will not install extension blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3623 | TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 3624 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3625 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3626 | // Blacklist everything. |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3627 | { |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3628 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 3629 | pref.SetBlacklistedByDefault(true); |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3630 | } |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3631 | |
| 3632 | // Blacklist prevents us from installing good_crx. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3633 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3634 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3635 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3636 | |
| 3637 | // Now whitelist this particular extension. |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3638 | { |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3639 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 3640 | pref.SetIndividualExtensionInstallationAllowed(good_crx, true); |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3641 | } |
| 3642 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3643 | // Ensure we can now install good_crx. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3644 | InstallCRX(path, INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3645 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3646 | } |
| 3647 | |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3648 | // Extension blacklisted by policy get unloaded after installing. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3649 | TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3650 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3651 | |
| 3652 | // Install good_crx. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3653 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3654 | InstallCRX(path, INSTALL_NEW); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3655 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3656 | |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3657 | { |
| 3658 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3659 | // Blacklist this extension. |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3660 | pref.SetIndividualExtensionInstallationAllowed(good_crx, false); |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3661 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3662 | |
| 3663 | // Extension should not be running now. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3664 | content::RunAllTasksUntilIdle(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3665 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3666 | } |
| 3667 | |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3668 | // Tests that component extensions are not blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3669 | TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3670 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3671 | |
| 3672 | // Blacklist everything. |
| 3673 | { |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3674 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 3675 | pref.SetBlacklistedByDefault(true); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3676 | } |
| 3677 | |
| 3678 | // Install a component extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3679 | base::FilePath path = data_dir() |
| 3680 | .AppendASCII("good") |
| 3681 | .AppendASCII("Extensions") |
| 3682 | .AppendASCII(good0) |
| 3683 | .AppendASCII("1.0.0.0"); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3684 | std::string manifest; |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 3685 | ASSERT_TRUE(base::ReadFileToString( |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 3686 | path.Append(extensions::kManifestFilename), &manifest)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3687 | service()->component_loader()->Add(manifest, path); |
| 3688 | service()->Init(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3689 | |
| 3690 | // Extension should be installed despite blacklist. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3691 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 3692 | EXPECT_TRUE(service()->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3693 | |
| 3694 | // Poke external providers and make sure the extension is still present. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3695 | service()->CheckForExternalUpdates(); |
| 3696 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 3697 | EXPECT_TRUE(service()->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3698 | |
| 3699 | // Extension should not be uninstalled on blacklist changes. |
| 3700 | { |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3701 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 3702 | pref.SetIndividualExtensionInstallationAllowed(good0, false); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3703 | } |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3704 | content::RunAllTasksUntilIdle(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3705 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 3706 | EXPECT_TRUE(service()->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3707 | } |
| 3708 | |
Nick Peterson | 0203be4a | 2017-07-19 00:25:14 | [diff] [blame] | 3709 | // Tests that active permissions are not revoked from component extensions |
| 3710 | // by policy when the policy is updated. https://crbug.com/746017. |
| 3711 | TEST_F(ExtensionServiceTest, ComponentExtensionWhitelistedPermission) { |
| 3712 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
| 3713 | |
| 3714 | // Install a component extension. |
| 3715 | base::FilePath path = data_dir() |
| 3716 | .AppendASCII("good") |
| 3717 | .AppendASCII("Extensions") |
| 3718 | .AppendASCII(good0) |
| 3719 | .AppendASCII("1.0.0.0"); |
| 3720 | std::string manifest; |
| 3721 | ASSERT_TRUE(base::ReadFileToString(path.Append(extensions::kManifestFilename), |
| 3722 | &manifest)); |
| 3723 | service()->component_loader()->Add(manifest, path); |
| 3724 | service()->Init(); |
| 3725 | |
| 3726 | // Extension should have the "tabs" permission. |
| 3727 | EXPECT_TRUE(service() |
| 3728 | ->GetExtensionById(good0, false) |
| 3729 | ->permissions_data() |
| 3730 | ->active_permissions() |
| 3731 | .HasAPIPermission(extensions::APIPermission::kTab)); |
| 3732 | |
| 3733 | // Component should not lose permissions on policy change. |
| 3734 | { |
| 3735 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 3736 | pref.AddBlockedPermission(good0, "tabs"); |
| 3737 | } |
| 3738 | |
| 3739 | service()->OnExtensionManagementSettingsChanged(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3740 | content::RunAllTasksUntilIdle(); |
Nick Peterson | 0203be4a | 2017-07-19 00:25:14 | [diff] [blame] | 3741 | EXPECT_TRUE(service() |
| 3742 | ->GetExtensionById(good0, false) |
| 3743 | ->permissions_data() |
| 3744 | ->active_permissions() |
| 3745 | .HasAPIPermission(extensions::APIPermission::kTab)); |
| 3746 | } |
| 3747 | |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3748 | // Tests that policy-installed extensions are not blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3749 | TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 3750 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3751 | |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3752 | { |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3753 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 3754 | // Blacklist everything. |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3755 | pref.SetBlacklistedByDefault(true); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 3756 | // Mark good.crx for force-installation. |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3757 | pref.SetIndividualExtensionAutoInstalled( |
| 3758 | good_crx, "http://example.com/update_url", true); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | // Have policy force-install an extension. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 3762 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 3763 | AddMockExternalProvider(Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3764 | provider->UpdateOrAddExtension( |
| 3765 | good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx")); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3766 | |
| 3767 | // Reloading extensions should find our externally registered extension |
| 3768 | // and install it. |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 3769 | WaitForExternalExtensionInstalled(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3770 | |
| 3771 | // Extension should be installed despite blacklist. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3772 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 3773 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3774 | |
| 3775 | // Blacklist update should not uninstall the extension. |
| 3776 | { |
binjin | b245438 | 2014-09-22 15:17:43 | [diff] [blame] | 3777 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 3778 | pref.SetIndividualExtensionInstallationAllowed(good0, false); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3779 | } |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 3780 | content::RunAllTasksUntilIdle(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3781 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 3782 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3783 | } |
| 3784 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3785 | // Tests that extensions cannot be installed if the policy provider prohibits |
| 3786 | // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3787 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3788 | InitializeEmptyExtensionService(); |
| 3789 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3790 | GetManagementPolicy()->UnregisterAllProviders(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3791 | extensions::TestManagementPolicyProvider provider_( |
| 3792 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3793 | GetManagementPolicy()->RegisterProvider(&provider_); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3794 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3795 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_FAILED); |
| 3796 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | // Tests that extensions cannot be loaded from prefs if the policy provider |
| 3800 | // prohibits it. This functionality is implemented in InstalledLoader::Load(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3801 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3802 | InitializeEmptyExtensionService(); |
| 3803 | |
| 3804 | // Create a fake extension to be loaded as though it were read from prefs. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3805 | base::FilePath path = |
| 3806 | data_dir().AppendASCII("management").AppendASCII("simple_extension"); |
[email protected] | 023b3d1 | 2013-12-23 18:46:49 | [diff] [blame] | 3807 | base::DictionaryValue manifest; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3808 | manifest.SetString(keys::kName, "simple_extension"); |
| 3809 | manifest.SetString(keys::kVersion, "1"); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 3810 | // UNPACKED is for extensions loaded from a directory. We use it here, even |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3811 | // though we're testing loading from prefs, so that we don't need to provide |
| 3812 | // an extension key. |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 3813 | extensions::ExtensionInfo extension_info( |
| 3814 | &manifest, std::string(), path, Manifest::UNPACKED); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3815 | |
| 3816 | // Ensure we can load it with no management policy in place. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3817 | GetManagementPolicy()->UnregisterAllProviders(); |
| 3818 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 3819 | extensions::InstalledLoader(service()).Load(extension_info, false); |
| 3820 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3821 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3822 | const Extension* extension = |
| 3823 | (registry()->enabled_extensions().begin())->get(); |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 3824 | EXPECT_TRUE( |
| 3825 | service()->UninstallExtension(extension->id(), |
| 3826 | extensions::UNINSTALL_REASON_FOR_TESTING, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 3827 | NULL)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3828 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3829 | |
| 3830 | // Ensure we cannot load it if management policy prohibits installation. |
| 3831 | extensions::TestManagementPolicyProvider provider_( |
| 3832 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3833 | GetManagementPolicy()->RegisterProvider(&provider_); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3834 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3835 | extensions::InstalledLoader(service()).Load(extension_info, false); |
| 3836 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3837 | } |
| 3838 | |
| 3839 | // Tests disabling an extension when prohibited by the ManagementPolicy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3840 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3841 | InitializeEmptyExtensionService(); |
| 3842 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3843 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 3844 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3845 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3846 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3847 | GetManagementPolicy()->UnregisterAllProviders(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3848 | extensions::TestManagementPolicyProvider provider( |
| 3849 | extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3850 | GetManagementPolicy()->RegisterProvider(&provider); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3851 | |
| 3852 | // Attempt to disable it. |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 3853 | service()->DisableExtension(good_crx, |
| 3854 | extensions::disable_reason::DISABLE_USER_ACTION); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3855 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3856 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3857 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
| 3858 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
Michael Giuffrida | b16cab3 | 2017-10-04 21:56:09 | [diff] [blame] | 3859 | EXPECT_EQ(extensions::disable_reason::DISABLE_NONE, |
| 3860 | ExtensionPrefs::Get(profile())->GetDisableReasons(good_crx)); |
| 3861 | |
| 3862 | // Internal disable reasons are allowed. |
| 3863 | service()->DisableExtension( |
| 3864 | good_crx, extensions::disable_reason::DISABLE_CORRUPTED | |
| 3865 | extensions::disable_reason::DISABLE_USER_ACTION); |
| 3866 | |
| 3867 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 3868 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 3869 | EXPECT_TRUE(service()->GetExtensionById(good_crx, true)); |
| 3870 | EXPECT_FALSE(service()->GetExtensionById(good_crx, false)); |
| 3871 | EXPECT_EQ(extensions::disable_reason::DISABLE_CORRUPTED, |
| 3872 | ExtensionPrefs::Get(profile())->GetDisableReasons(good_crx)); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | // Tests uninstalling an extension when prohibited by the ManagementPolicy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3876 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3877 | InitializeEmptyExtensionService(); |
| 3878 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3879 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 3880 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3881 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3882 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3883 | GetManagementPolicy()->UnregisterAllProviders(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3884 | extensions::TestManagementPolicyProvider provider( |
| 3885 | extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3886 | GetManagementPolicy()->RegisterProvider(&provider); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3887 | |
| 3888 | // Attempt to uninstall it. |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 3889 | EXPECT_FALSE( |
| 3890 | service()->UninstallExtension(good_crx, |
| 3891 | extensions::UNINSTALL_REASON_FOR_TESTING, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 3892 | NULL)); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3893 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3894 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3895 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | // Tests that previously installed extensions that are now prohibited from |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 3899 | // being installed are disabled. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3900 | TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3901 | InitializeEmptyExtensionService(); |
| 3902 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3903 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 3904 | InstallCRX(data_dir().AppendASCII("page_action.crx"), INSTALL_NEW); |
| 3905 | EXPECT_EQ(2u, registry()->enabled_extensions().size()); |
| 3906 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3907 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3908 | GetManagementPolicy()->UnregisterAllProviders(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3909 | extensions::TestManagementPolicyProvider provider( |
| 3910 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3911 | GetManagementPolicy()->RegisterProvider(&provider); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3912 | |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 3913 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 3914 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3915 | // Run the policy check. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3916 | service()->CheckManagementPolicy(); |
| 3917 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 3918 | EXPECT_EQ(2u, registry()->disabled_extensions().size()); |
| 3919 | EXPECT_EQ(extensions::disable_reason::DISABLE_BLOCKED_BY_POLICY, |
| 3920 | prefs->GetDisableReasons(good_crx)); |
| 3921 | EXPECT_EQ(extensions::disable_reason::DISABLE_BLOCKED_BY_POLICY, |
| 3922 | prefs->GetDisableReasons(page_action)); |
| 3923 | |
| 3924 | // Removing the extensions from policy blacklist should re-enable them. |
| 3925 | GetManagementPolicy()->UnregisterAllProviders(); |
| 3926 | service()->CheckManagementPolicy(); |
| 3927 | EXPECT_EQ(2u, registry()->enabled_extensions().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3928 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3929 | } |
| 3930 | |
| 3931 | // Tests that previously disabled extensions that are now required to be |
| 3932 | // enabled are re-enabled on reinstall. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3933 | TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3934 | InitializeEmptyExtensionService(); |
| 3935 | |
| 3936 | // Install, then disable, an extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3937 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 3938 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 3939 | service()->DisableExtension(good_crx, |
| 3940 | extensions::disable_reason::DISABLE_USER_ACTION); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3941 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3942 | |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 3943 | // Register an ExtensionManagementPolicy that requires the extension to remain |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3944 | // enabled. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3945 | GetManagementPolicy()->UnregisterAllProviders(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3946 | extensions::TestManagementPolicyProvider provider( |
| 3947 | extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3948 | GetManagementPolicy()->RegisterProvider(&provider); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3949 | |
| 3950 | // Reinstall the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 3951 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_UPDATED); |
| 3952 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 3953 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3954 | } |
| 3955 | |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 3956 | // Tests that extensions disabled by management policy can be installed but |
| 3957 | // will get disabled after installing. |
| 3958 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsEnableOnInstalled) { |
| 3959 | InitializeEmptyExtensionService(); |
| 3960 | |
| 3961 | // Register an ExtensionManagementPolicy that disables all extensions, with |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 3962 | // a specified disable_reason::DisableReason. |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 3963 | GetManagementPolicy()->UnregisterAllProviders(); |
| 3964 | extensions::TestManagementPolicyProvider provider( |
| 3965 | extensions::TestManagementPolicyProvider::MUST_REMAIN_DISABLED); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 3966 | provider.SetDisableReason(extensions::disable_reason::DISABLE_NOT_VERIFIED); |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 3967 | GetManagementPolicy()->RegisterProvider(&provider); |
| 3968 | |
| 3969 | // Attempts to install an extensions, it should be installed but disabled. |
| 3970 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 3971 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 3972 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_WITHOUT_LOAD); |
| 3973 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 3974 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 3975 | |
| 3976 | // Verifies that the disable reason is set properly. |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 3977 | EXPECT_EQ(extensions::disable_reason::DISABLE_NOT_VERIFIED, |
binjin | 47947f84 | 2014-11-18 12:10:24 | [diff] [blame] | 3978 | service()->extension_prefs_->GetDisableReasons(kGoodId)); |
| 3979 | } |
| 3980 | |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 3981 | // Tests that extensions with conflicting required permissions by enterprise |
| 3982 | // policy cannot be installed. |
| 3983 | TEST_F(ExtensionServiceTest, PolicyBlockedPermissionNewExtensionInstall) { |
| 3984 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
| 3985 | base::FilePath path = data_dir().AppendASCII("permissions_blocklist"); |
| 3986 | |
| 3987 | { |
| 3988 | // Update policy to block one of the required permissions of target. |
| 3989 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 3990 | pref.AddBlockedPermission("*", "tabs"); |
| 3991 | } |
| 3992 | |
| 3993 | // The extension should be failed to install. |
| 3994 | PackAndInstallCRX(path, INSTALL_FAILED); |
| 3995 | |
| 3996 | { |
| 3997 | // Update policy to block one of the optional permissions instead. |
| 3998 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 3999 | pref.ClearBlockedPermissions("*"); |
| 4000 | pref.AddBlockedPermission("*", "history"); |
| 4001 | } |
| 4002 | |
| 4003 | // The extension should succeed to install this time. |
| 4004 | std::string id = PackAndInstallCRX(path, INSTALL_NEW)->id(); |
| 4005 | |
| 4006 | // Uninstall the extension and update policy to block some arbitrary |
| 4007 | // unknown permission. |
Devlin Cronin | 6fd1cd6 | 2017-12-05 19:13:57 | [diff] [blame] | 4008 | UninstallExtension(id); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 4009 | { |
| 4010 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 4011 | pref.ClearBlockedPermissions("*"); |
| 4012 | pref.AddBlockedPermission("*", "unknown.permission.for.testing"); |
| 4013 | } |
| 4014 | |
| 4015 | // The extension should succeed to install as well. |
| 4016 | PackAndInstallCRX(path, INSTALL_NEW); |
| 4017 | } |
| 4018 | |
| 4019 | // Tests that extension supposed to be force installed but with conflicting |
| 4020 | // required permissions cannot be installed. |
| 4021 | TEST_F(ExtensionServiceTest, PolicyBlockedPermissionConflictsWithForceInstall) { |
| 4022 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
| 4023 | |
| 4024 | // Pack the crx file. |
| 4025 | base::FilePath path = data_dir().AppendASCII("permissions_blocklist"); |
| 4026 | base::FilePath pem_path = data_dir().AppendASCII("permissions_blocklist.pem"); |
| 4027 | base::ScopedTempDir temp_dir; |
| 4028 | EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 4029 | base::FilePath crx_path = temp_dir.GetPath().AppendASCII("temp.crx"); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 4030 | |
| 4031 | PackCRX(path, pem_path, crx_path); |
| 4032 | |
| 4033 | { |
| 4034 | // Block one of the required permissions. |
| 4035 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 4036 | pref.AddBlockedPermission("*", "tabs"); |
| 4037 | } |
| 4038 | |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 4039 | // Use MockExternalProvider to simulate force installing extension. |
| 4040 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 4041 | AddMockExternalProvider(Manifest::EXTERNAL_POLICY_DOWNLOAD); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 4042 | provider->UpdateOrAddExtension(permissions_blocklist, "1.0", crx_path); |
| 4043 | |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 4044 | // Attempts to force install this extension. |
| 4045 | WaitForExternalExtensionInstalled(); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 4046 | |
| 4047 | // The extension should not be installed. |
| 4048 | ASSERT_FALSE(service()->GetInstalledExtension(permissions_blocklist)); |
| 4049 | |
| 4050 | // Remove this extension from pending extension manager as we would like to |
| 4051 | // give another attempt later. |
| 4052 | service()->pending_extension_manager()->Remove(permissions_blocklist); |
| 4053 | |
| 4054 | { |
| 4055 | // Clears the permission block list. |
| 4056 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 4057 | pref.ClearBlockedPermissions("*"); |
| 4058 | } |
| 4059 | |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 4060 | // Attempts to force install this extension again. |
| 4061 | WaitForExternalExtensionInstalled(); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 4062 | |
| 4063 | const Extension* installed = |
| 4064 | service()->GetInstalledExtension(permissions_blocklist); |
| 4065 | ASSERT_TRUE(installed); |
| 4066 | EXPECT_EQ(installed->location(), Manifest::EXTERNAL_POLICY_DOWNLOAD); |
| 4067 | } |
| 4068 | |
| 4069 | // Tests that newer versions of an extension with conflicting required |
| 4070 | // permissions by enterprise policy cannot be updated to. |
| 4071 | TEST_F(ExtensionServiceTest, PolicyBlockedPermissionExtensionUpdate) { |
| 4072 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
| 4073 | |
| 4074 | base::FilePath path = data_dir().AppendASCII("permissions_blocklist"); |
| 4075 | base::FilePath path2 = data_dir().AppendASCII("permissions_blocklist2"); |
| 4076 | base::FilePath pem_path = data_dir().AppendASCII("permissions_blocklist.pem"); |
| 4077 | |
| 4078 | // Install 'permissions_blocklist'. |
| 4079 | const Extension* installed = PackAndInstallCRX(path, pem_path, INSTALL_NEW); |
| 4080 | EXPECT_EQ(installed->id(), permissions_blocklist); |
| 4081 | |
| 4082 | { |
| 4083 | // Block one of the required permissions of 'permissions_blocklist2'. |
| 4084 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 4085 | pref.AddBlockedPermission("*", "downloads"); |
| 4086 | } |
| 4087 | |
| 4088 | // Install 'permissions_blocklist' again, should be updated. |
| 4089 | const Extension* updated = PackAndInstallCRX(path, pem_path, INSTALL_UPDATED); |
| 4090 | EXPECT_EQ(updated->id(), permissions_blocklist); |
| 4091 | |
| 4092 | std::string old_version = updated->VersionString(); |
| 4093 | |
| 4094 | // Attempts to update to 'permissions_blocklist2' should fail. |
| 4095 | PackAndInstallCRX(path2, pem_path, INSTALL_FAILED); |
| 4096 | |
| 4097 | // Verify that the old version is still enabled. |
| 4098 | updated = service()->GetExtensionById(permissions_blocklist, false); |
| 4099 | ASSERT_TRUE(updated); |
| 4100 | EXPECT_EQ(old_version, updated->VersionString()); |
| 4101 | } |
| 4102 | |
| 4103 | // Tests that policy update with additional permissions blocked revoke |
| 4104 | // conflicting granted optional permissions and unload extensions with |
| 4105 | // conflicting required permissions, including the force installed ones. |
| 4106 | TEST_F(ExtensionServiceTest, PolicyBlockedPermissionPolicyUpdate) { |
| 4107 | InitializeEmptyExtensionServiceWithTestingPrefs(); |
| 4108 | |
| 4109 | base::FilePath path = data_dir().AppendASCII("permissions_blocklist"); |
| 4110 | base::FilePath path2 = data_dir().AppendASCII("permissions_blocklist2"); |
| 4111 | base::FilePath pem_path = data_dir().AppendASCII("permissions_blocklist.pem"); |
| 4112 | |
| 4113 | // Pack the crx file. |
| 4114 | base::ScopedTempDir temp_dir; |
| 4115 | EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 4116 | base::FilePath crx_path = temp_dir.GetPath().AppendASCII("temp.crx"); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 4117 | |
| 4118 | PackCRX(path2, pem_path, crx_path); |
| 4119 | |
| 4120 | // Install two arbitary extensions with specified manifest. |
| 4121 | std::string ext1 = PackAndInstallCRX(path, INSTALL_NEW)->id(); |
| 4122 | std::string ext2 = PackAndInstallCRX(path2, INSTALL_NEW)->id(); |
| 4123 | ASSERT_NE(ext1, permissions_blocklist); |
| 4124 | ASSERT_NE(ext2, permissions_blocklist); |
| 4125 | ASSERT_NE(ext1, ext2); |
| 4126 | |
| 4127 | // Force install another extension with known id and same manifest as 'ext2'. |
| 4128 | std::string ext2_forced = permissions_blocklist; |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 4129 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 4130 | AddMockExternalProvider(Manifest::EXTERNAL_POLICY_DOWNLOAD); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 4131 | provider->UpdateOrAddExtension(ext2_forced, "2.0", crx_path); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 4132 | WaitForExternalExtensionInstalled(); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 4133 | |
| 4134 | extensions::ExtensionRegistry* registry = |
| 4135 | extensions::ExtensionRegistry::Get(profile()); |
| 4136 | |
| 4137 | // Verify all three extensions are installed and enabled. |
| 4138 | ASSERT_TRUE(registry->enabled_extensions().GetByID(ext1)); |
| 4139 | ASSERT_TRUE(registry->enabled_extensions().GetByID(ext2)); |
| 4140 | ASSERT_TRUE(registry->enabled_extensions().GetByID(ext2_forced)); |
| 4141 | |
| 4142 | // Grant all optional permissions to each extension. |
| 4143 | GrantAllOptionalPermissions(ext1); |
| 4144 | GrantAllOptionalPermissions(ext2); |
| 4145 | GrantAllOptionalPermissions(ext2_forced); |
| 4146 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 4147 | std::unique_ptr<const PermissionSet> active_permissions = |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 4148 | ExtensionPrefs::Get(profile())->GetActivePermissions(ext1); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 4149 | EXPECT_TRUE(active_permissions->HasAPIPermission( |
| 4150 | extensions::APIPermission::kDownloads)); |
| 4151 | |
| 4152 | // Set policy to block 'downloads' permission. |
| 4153 | { |
| 4154 | ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
| 4155 | pref.AddBlockedPermission("*", "downloads"); |
| 4156 | } |
| 4157 | |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4158 | content::RunAllTasksUntilIdle(); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 4159 | |
| 4160 | // 'ext1' should still be enabled, but with 'downloads' permission revoked. |
| 4161 | EXPECT_TRUE(registry->enabled_extensions().GetByID(ext1)); |
| 4162 | active_permissions = |
| 4163 | ExtensionPrefs::Get(profile())->GetActivePermissions(ext1); |
| 4164 | EXPECT_FALSE(active_permissions->HasAPIPermission( |
| 4165 | extensions::APIPermission::kDownloads)); |
| 4166 | |
| 4167 | // 'ext2' should be disabled because one of its required permissions is |
| 4168 | // blocked. |
| 4169 | EXPECT_FALSE(registry->enabled_extensions().GetByID(ext2)); |
| 4170 | |
| 4171 | // 'ext2_forced' should be handled the same as 'ext2' |
| 4172 | EXPECT_FALSE(registry->enabled_extensions().GetByID(ext2_forced)); |
| 4173 | } |
| 4174 | |
[email protected] | ebc3aec | 2013-10-22 02:39:17 | [diff] [blame] | 4175 | // Flaky on windows; http://crbug.com/309833 |
| 4176 | #if defined(OS_WIN) |
| 4177 | #define MAYBE_ExternalExtensionAutoAcknowledgement DISABLED_ExternalExtensionAutoAcknowledgement |
| 4178 | #else |
| 4179 | #define MAYBE_ExternalExtensionAutoAcknowledgement ExternalExtensionAutoAcknowledgement |
| 4180 | #endif |
[email protected] | 893642c | 2014-02-03 06:53:13 | [diff] [blame] | 4181 | TEST_F(ExtensionServiceTest, MAYBE_ExternalExtensionAutoAcknowledgement) { |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 4182 | InitializeEmptyExtensionService(); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 4183 | |
| 4184 | { |
| 4185 | // Register and install an external extension. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 4186 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 4187 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4188 | provider->UpdateOrAddExtension( |
| 4189 | good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx")); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 4190 | } |
| 4191 | { |
| 4192 | // Have policy force-install an extension. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 4193 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 4194 | AddMockExternalProvider(Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4195 | provider->UpdateOrAddExtension( |
| 4196 | page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 4197 | } |
| 4198 | |
| 4199 | // Providers are set up. Let them run. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4200 | int count = 2; |
| 4201 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 4202 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4203 | base::Bind(&WaitForCountNotificationsCallback, &count)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4204 | service()->CheckForExternalUpdates(); |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 4205 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 4206 | observer.Wait(); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 4207 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4208 | ASSERT_EQ(2u, registry()->enabled_extensions().size()); |
| 4209 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
| 4210 | EXPECT_TRUE(service()->GetExtensionById(page_action, false)); |
| 4211 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 4212 | ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); |
| 4213 | ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); |
| 4214 | } |
| 4215 | |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 4216 | // Tests that an extension added through an external source is initially |
| 4217 | // disabled with the "prompt for external extensions" feature. |
| 4218 | TEST_F(ExtensionServiceTest, ExternalExtensionDisabledOnInstallation) { |
| 4219 | FeatureSwitch::ScopedOverride external_prompt_override( |
| 4220 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 4221 | InitializeEmptyExtensionService(); |
| 4222 | |
| 4223 | // Register and install an external extension. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 4224 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 4225 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); // Takes ownership. |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 4226 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 4227 | data_dir().AppendASCII("good.crx")); |
| 4228 | |
| 4229 | WaitForExternalExtensionInstalled(); |
| 4230 | |
| 4231 | EXPECT_TRUE(registry()->disabled_extensions().Contains(good_crx)); |
| 4232 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 4233 | EXPECT_FALSE(prefs->IsExternalExtensionAcknowledged(good_crx)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 4234 | EXPECT_EQ(extensions::disable_reason::DISABLE_EXTERNAL_EXTENSION, |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 4235 | prefs->GetDisableReasons(good_crx)); |
| 4236 | |
| 4237 | // Updating the extension shouldn't cause it to be enabled. |
| 4238 | provider->UpdateOrAddExtension(good_crx, "1.0.0.1", |
| 4239 | data_dir().AppendASCII("good2.crx")); |
| 4240 | WaitForExternalExtensionInstalled(); |
| 4241 | |
| 4242 | EXPECT_TRUE(registry()->disabled_extensions().Contains(good_crx)); |
| 4243 | EXPECT_FALSE(prefs->IsExternalExtensionAcknowledged(good_crx)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 4244 | EXPECT_EQ(extensions::disable_reason::DISABLE_EXTERNAL_EXTENSION, |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 4245 | prefs->GetDisableReasons(good_crx)); |
| 4246 | const Extension* extension = |
| 4247 | registry()->disabled_extensions().GetByID(good_crx); |
| 4248 | ASSERT_TRUE(extension); |
| 4249 | // Double check that we did, in fact, update the extension. |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 4250 | EXPECT_EQ("1.0.0.1", extension->version().GetString()); |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | // Test that if an extension is installed before the "prompt for external |
| 4254 | // extensions" feature is enabled, but is updated when the feature is |
| 4255 | // enabled, the extension is not disabled. |
| 4256 | TEST_F(ExtensionServiceTest, ExternalExtensionIsNotDisabledOnUpdate) { |
| 4257 | auto external_prompt_override = |
| 4258 | base::MakeUnique<FeatureSwitch::ScopedOverride>( |
| 4259 | FeatureSwitch::prompt_for_external_extensions(), false); |
| 4260 | InitializeEmptyExtensionService(); |
| 4261 | |
| 4262 | // Register and install an external extension. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 4263 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 4264 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 4265 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 4266 | data_dir().AppendASCII("good.crx")); |
| 4267 | |
| 4268 | WaitForExternalExtensionInstalled(); |
| 4269 | |
| 4270 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good_crx)); |
| 4271 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 4272 | EXPECT_FALSE(prefs->IsExternalExtensionAcknowledged(good_crx)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 4273 | EXPECT_EQ(extensions::disable_reason::DISABLE_NONE, |
| 4274 | prefs->GetDisableReasons(good_crx)); |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 4275 | |
| 4276 | provider->UpdateOrAddExtension(good_crx, "1.0.0.1", |
| 4277 | data_dir().AppendASCII("good2.crx")); |
| 4278 | |
| 4279 | // We explicitly reset the override first. ScopedOverrides reset the value |
| 4280 | // to the original value on destruction, but if we reset by passing a new |
| 4281 | // object, the new object is constructed (overriding the current value) |
| 4282 | // before the old is destructed (which will immediately reset to the |
| 4283 | // original). |
| 4284 | external_prompt_override.reset(); |
| 4285 | external_prompt_override = base::MakeUnique<FeatureSwitch::ScopedOverride>( |
| 4286 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 4287 | WaitForExternalExtensionInstalled(); |
| 4288 | |
| 4289 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good_crx)); |
| 4290 | { |
| 4291 | const Extension* extension = |
| 4292 | registry()->enabled_extensions().GetByID(good_crx); |
| 4293 | ASSERT_TRUE(extension); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 4294 | EXPECT_EQ("1.0.0.1", extension->version().GetString()); |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 4295 | } |
| 4296 | EXPECT_FALSE(prefs->IsExternalExtensionAcknowledged(good_crx)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 4297 | EXPECT_EQ(extensions::disable_reason::DISABLE_NONE, |
| 4298 | prefs->GetDisableReasons(good_crx)); |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 4299 | } |
| 4300 | |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4301 | #if !defined(OS_CHROMEOS) |
| 4302 | // This tests if default apps are installed correctly. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4303 | TEST_F(ExtensionServiceTest, DefaultAppsInstall) { |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4304 | InitializeEmptyExtensionService(); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4305 | |
| 4306 | { |
| 4307 | std::string json_data = |
| 4308 | "{" |
| 4309 | " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {" |
| 4310 | " \"external_crx\": \"good.crx\"," |
| 4311 | " \"external_version\": \"1.0.0.0\"," |
| 4312 | " \"is_bookmark_app\": false" |
| 4313 | " }" |
| 4314 | "}"; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4315 | default_apps::Provider* provider = new default_apps::Provider( |
| 4316 | profile(), |
| 4317 | service(), |
| 4318 | new extensions::ExternalTestingLoader(json_data, data_dir()), |
| 4319 | Manifest::INTERNAL, |
| 4320 | Manifest::INVALID_LOCATION, |
| 4321 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4322 | |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 4323 | service()->AddProviderForTesting(base::WrapUnique(provider)); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4324 | } |
| 4325 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4326 | ASSERT_EQ(0u, registry()->enabled_extensions().size()); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 4327 | WaitForExternalExtensionInstalled(); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4328 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4329 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 4330 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
| 4331 | const Extension* extension = service()->GetExtensionById(good_crx, false); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4332 | EXPECT_TRUE(extension->from_webstore()); |
| 4333 | EXPECT_TRUE(extension->was_installed_by_default()); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 4334 | } |
| 4335 | #endif |
| 4336 | |
timloh | ac69562 | 2017-04-03 07:52:58 | [diff] [blame] | 4337 | // Crashes on Linux/CrOS. https://crbug.com/703712 |
| 4338 | #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
| 4339 | #define MAYBE_UpdatingPendingExternalExtensionWithFlags \ |
| 4340 | DISABLED_UpdatingPendingExternalExtensionWithFlags |
| 4341 | #else |
| 4342 | #define MAYBE_UpdatingPendingExternalExtensionWithFlags \ |
| 4343 | UpdatingPendingExternalExtensionWithFlags |
| 4344 | #endif |
| 4345 | |
| 4346 | TEST_F(ExtensionServiceTest, MAYBE_UpdatingPendingExternalExtensionWithFlags) { |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 4347 | // Regression test for crbug.com/627522 |
| 4348 | const char kPrefFromBookmark[] = "from_bookmark"; |
| 4349 | |
| 4350 | InitializeEmptyExtensionService(); |
| 4351 | |
| 4352 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 4353 | |
| 4354 | // Register and install an external extension. |
Devlin Cronin | d4c2a8f3 | 2017-09-29 17:08:30 | [diff] [blame] | 4355 | base::Version version("1.0.0.0"); |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 4356 | content::WindowedNotificationObserver observer( |
| 4357 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
| 4358 | content::NotificationService::AllSources()); |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 4359 | ExternalInstallInfoFile info(good_crx, version, path, Manifest::EXTERNAL_PREF, |
| 4360 | Extension::FROM_BOOKMARK, |
| 4361 | false /* mark_acknowledged */, |
| 4362 | false /* install_immediately */); |
| 4363 | ASSERT_TRUE(service()->OnExternalExtensionFileFound(info)); |
mamir | 0128d5a | 2016-07-15 20:55:48 | [diff] [blame] | 4364 | EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(good_crx)); |
| 4365 | |
| 4366 | // Upgrade to version 2.0, the flag should be preserved. |
| 4367 | path = data_dir().AppendASCII("good2.crx"); |
| 4368 | UpdateExtension(good_crx, path, ENABLED); |
| 4369 | ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
| 4370 | const Extension* extension = service()->GetExtensionById(good_crx, false); |
| 4371 | ASSERT_TRUE(extension); |
| 4372 | ASSERT_TRUE(extension->from_bookmark()); |
| 4373 | } |
| 4374 | |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4375 | // Tests disabling extensions |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4376 | TEST_F(ExtensionServiceTest, DisableExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4377 | InitializeEmptyExtensionService(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4378 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4379 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 4380 | EXPECT_TRUE(service()->GetExtensionById(good_crx, true)); |
| 4381 | EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 4382 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4383 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4384 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 4385 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 4386 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4387 | |
| 4388 | // Disable it. |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 4389 | service()->DisableExtension(good_crx, |
| 4390 | extensions::disable_reason::DISABLE_USER_ACTION); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4391 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4392 | EXPECT_TRUE(service()->GetExtensionById(good_crx, true)); |
| 4393 | EXPECT_FALSE(service()->GetExtensionById(good_crx, false)); |
| 4394 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4395 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 4396 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 4397 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4398 | } |
| 4399 | |
| 4400 | TEST_F(ExtensionServiceTest, TerminateExtension) { |
| 4401 | InitializeEmptyExtensionService(); |
| 4402 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4403 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 4404 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4405 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 4406 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 4407 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4408 | |
| 4409 | TerminateExtension(good_crx); |
| 4410 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4411 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4412 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 4413 | EXPECT_EQ(1u, registry()->terminated_extensions().size()); |
| 4414 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4415 | } |
| 4416 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4417 | TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4418 | InitializeEmptyExtensionService(); |
| 4419 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4420 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4421 | TerminateExtension(good_crx); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4422 | EXPECT_TRUE(registry()->GetExtensionById( |
[email protected] | e066da3 | 2014-03-26 18:27:35 | [diff] [blame] | 4423 | good_crx, extensions::ExtensionRegistry::TERMINATED)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4424 | |
| 4425 | // Disable it. |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 4426 | service()->DisableExtension(good_crx, |
| 4427 | extensions::disable_reason::DISABLE_USER_ACTION); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4428 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4429 | EXPECT_FALSE(registry()->GetExtensionById( |
[email protected] | e066da3 | 2014-03-26 18:27:35 | [diff] [blame] | 4430 | good_crx, extensions::ExtensionRegistry::TERMINATED)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4431 | EXPECT_TRUE(service()->GetExtensionById(good_crx, true)); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 4432 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4433 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4434 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 4435 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 4436 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4437 | } |
| 4438 | |
rdevlin.cronin | 7217be5 | 2017-03-24 20:47:05 | [diff] [blame] | 4439 | // Tests that with the kDisableExtensions flag, extensions are not loaded by |
| 4440 | // the ExtensionService... |
| 4441 | TEST_F(ExtensionServiceTest, PRE_DisableAllExtensions) { |
| 4442 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 4443 | switches::kDisableExtensions); |
| 4444 | InitializeGoodInstalledExtensionService(); |
| 4445 | service()->Init(); |
| 4446 | EXPECT_TRUE(registry()->GenerateInstalledExtensionsSet()->is_empty()); |
| 4447 | } |
| 4448 | |
| 4449 | // ... But, if we remove the switch, they are. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4450 | TEST_F(ExtensionServiceTest, DisableAllExtensions) { |
rdevlin.cronin | 7217be5 | 2017-03-24 20:47:05 | [diff] [blame] | 4451 | EXPECT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 4452 | switches::kDisableExtensions)); |
| 4453 | InitializeGoodInstalledExtensionService(); |
| 4454 | service()->Init(); |
| 4455 | EXPECT_FALSE(registry()->GenerateInstalledExtensionsSet()->is_empty()); |
| 4456 | EXPECT_FALSE(registry()->enabled_extensions().is_empty()); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 4457 | } |
| 4458 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4459 | // Tests reloading extensions. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4460 | TEST_F(ExtensionServiceTest, ReloadExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4461 | InitializeEmptyExtensionService(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4462 | |
| 4463 | // Simple extension that should install without error. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4464 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 4465 | InstallCRX(path, INSTALL_NEW, |
| 4466 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
thestig | 4b36dd3 | 2014-10-31 20:30:19 | [diff] [blame] | 4467 | const char* const extension_id = good_crx; |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 4468 | service()->DisableExtension(extension_id, |
| 4469 | extensions::disable_reason::DISABLE_USER_ACTION); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4470 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4471 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4472 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4473 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4474 | service()->ReloadExtensionsForTest(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4475 | |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 4476 | // The creation flags should not change when reloading the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4477 | const Extension* extension = service()->GetExtensionById(good_crx, true); |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 4478 | EXPECT_TRUE(extension->from_webstore()); |
| 4479 | EXPECT_TRUE(extension->was_installed_by_default()); |
| 4480 | EXPECT_FALSE(extension->from_bookmark()); |
| 4481 | |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4482 | // Extension counts shouldn't change. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4483 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4484 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4485 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4486 | service()->EnableExtension(extension_id); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4487 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4488 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4489 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4490 | |
[email protected] | 5a73f90 | 2010-06-30 02:29:41 | [diff] [blame] | 4491 | // Need to clear |loaded_| manually before reloading as the |
| 4492 | // EnableExtension() call above inserted into it and |
| 4493 | // UnloadAllExtensions() doesn't send out notifications. |
| 4494 | loaded_.clear(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4495 | service()->ReloadExtensionsForTest(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4496 | |
| 4497 | // Extension counts shouldn't change. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4498 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4499 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 4500 | } |
| 4501 | |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4502 | // Tests reloading an extension. |
| 4503 | TEST_F(ExtensionServiceTest, ReloadExtension) { |
| 4504 | InitializeEmptyExtensionService(); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4505 | |
| 4506 | // Simple extension that should install without error. |
thestig | 4b36dd3 | 2014-10-31 20:30:19 | [diff] [blame] | 4507 | const char extension_id[] = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4508 | base::FilePath ext = data_dir() |
| 4509 | .AppendASCII("good") |
| 4510 | .AppendASCII("Extensions") |
| 4511 | .AppendASCII(extension_id) |
| 4512 | .AppendASCII("1.0.0.0"); |
| 4513 | extensions::UnpackedInstaller::Create(service())->Load(ext); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4514 | content::RunAllTasksUntilIdle(); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4515 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4516 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4517 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4518 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4519 | service()->ReloadExtension(extension_id); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4520 | |
| 4521 | // Extension should be disabled now, waiting to be reloaded. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4522 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4523 | EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 4524 | EXPECT_EQ(extensions::disable_reason::DISABLE_RELOAD, |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4525 | ExtensionPrefs::Get(profile())->GetDisableReasons(extension_id)); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4526 | |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 4527 | // Reloading again should not crash. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4528 | service()->ReloadExtension(extension_id); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4529 | |
| 4530 | // Finish reloading |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4531 | content::RunAllTasksUntilIdle(); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4532 | |
| 4533 | // Extension should be enabled again. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4534 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4535 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 4536 | } |
| 4537 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4538 | TEST_F(ExtensionServiceTest, UninstallExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4539 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4540 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
| 4541 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
Devlin Cronin | 6fd1cd6 | 2017-12-05 19:13:57 | [diff] [blame] | 4542 | UninstallExtension(good_crx); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4543 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 4544 | EXPECT_EQ(UnloadedExtensionReason::UNINSTALL, unloaded_reason_); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4545 | } |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 4546 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4547 | TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4548 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4549 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 4550 | TerminateExtension(good_crx); |
Devlin Cronin | 6fd1cd6 | 2017-12-05 19:13:57 | [diff] [blame] | 4551 | UninstallExtension(good_crx); |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 4552 | EXPECT_EQ(UnloadedExtensionReason::TERMINATE, unloaded_reason_); |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 4553 | } |
| 4554 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4555 | // An extension disabled because of unsupported requirements should re-enabled |
| 4556 | // if updated to a version with supported requirements as long as there are no |
| 4557 | // other disable reasons. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4558 | TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4559 | InitializeEmptyExtensionService(); |
zmo | 2602bcf | 2017-04-01 00:12:03 | [diff] [blame] | 4560 | content::GpuDataManager::GetInstance()->BlacklistWebGLForTesting(); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4561 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4562 | base::FilePath path = data_dir().AppendASCII("requirements"); |
| 4563 | base::FilePath pem_path = |
| 4564 | data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem"); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4565 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 4566 | pem_path, |
| 4567 | INSTALL_NEW); |
| 4568 | std::string id = extension_v1->id(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4569 | EXPECT_TRUE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4570 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4571 | base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4572 | |
| 4573 | PackCRX(path.AppendASCII("v2_bad_requirements"), |
| 4574 | pem_path, |
| 4575 | v2_bad_requirements_crx); |
| 4576 | UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4577 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4578 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4579 | base::FilePath v3_good_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4580 | |
| 4581 | PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); |
| 4582 | UpdateExtension(id, v3_good_crx, ENABLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4583 | EXPECT_TRUE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4584 | } |
| 4585 | |
| 4586 | // Extensions disabled through user action should stay disabled. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4587 | TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4588 | InitializeEmptyExtensionService(); |
zmo | 2602bcf | 2017-04-01 00:12:03 | [diff] [blame] | 4589 | content::GpuDataManager::GetInstance()->BlacklistWebGLForTesting(); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4590 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4591 | base::FilePath path = data_dir().AppendASCII("requirements"); |
| 4592 | base::FilePath pem_path = |
| 4593 | data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem"); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4594 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 4595 | pem_path, |
| 4596 | INSTALL_NEW); |
| 4597 | std::string id = extension_v1->id(); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 4598 | service()->DisableExtension(id, |
| 4599 | extensions::disable_reason::DISABLE_USER_ACTION); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4600 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4601 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4602 | base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4603 | |
| 4604 | PackCRX(path.AppendASCII("v2_bad_requirements"), |
| 4605 | pem_path, |
| 4606 | v2_bad_requirements_crx); |
| 4607 | UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4608 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4609 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4610 | base::FilePath v3_good_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4611 | |
| 4612 | PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); |
| 4613 | UpdateExtension(id, v3_good_crx, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4614 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4615 | } |
| 4616 | |
| 4617 | // The extension should not re-enabled because it was disabled from a |
| 4618 | // permission increase. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4619 | TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4620 | InitializeEmptyExtensionService(); |
zmo | 2602bcf | 2017-04-01 00:12:03 | [diff] [blame] | 4621 | content::GpuDataManager::GetInstance()->BlacklistWebGLForTesting(); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4622 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4623 | base::FilePath path = data_dir().AppendASCII("requirements"); |
| 4624 | base::FilePath pem_path = |
| 4625 | data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem"); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4626 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 4627 | pem_path, |
| 4628 | INSTALL_NEW); |
| 4629 | std::string id = extension_v1->id(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4630 | EXPECT_TRUE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4631 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4632 | base::FilePath v2_bad_requirements_and_permissions_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4633 | |
| 4634 | PackCRX(path.AppendASCII("v2_bad_requirements_and_permissions"), |
| 4635 | pem_path, |
| 4636 | v2_bad_requirements_and_permissions_crx); |
| 4637 | UpdateExtension(id, v2_bad_requirements_and_permissions_crx, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4638 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4639 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4640 | base::FilePath v3_bad_permissions_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 4641 | |
| 4642 | PackCRX(path.AppendASCII("v3_bad_permissions"), |
| 4643 | pem_path, |
| 4644 | v3_bad_permissions_crx); |
| 4645 | UpdateExtension(id, v3_bad_permissions_crx, INSTALLED); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4646 | EXPECT_FALSE(service()->IsExtensionEnabled(id)); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | // Unpacked extensions are not allowed to be installed if they have unsupported |
| 4650 | // requirements. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4651 | TEST_F(ExtensionServiceTest, UnpackedRequirements) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4652 | InitializeEmptyExtensionService(); |
zmo | 2602bcf | 2017-04-01 00:12:03 | [diff] [blame] | 4653 | content::GpuDataManager::GetInstance()->BlacklistWebGLForTesting(); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4654 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4655 | base::FilePath path = |
| 4656 | data_dir().AppendASCII("requirements").AppendASCII("v2_bad_requirements"); |
| 4657 | extensions::UnpackedInstaller::Create(service())->Load(path); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4658 | content::RunAllTasksUntilIdle(); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4659 | EXPECT_EQ(1u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4660 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 4661 | } |
| 4662 | |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4663 | class ExtensionCookieCallback { |
| 4664 | public: |
Gabriel Charette | e3769cf | 2017-07-27 16:52:50 | [diff] [blame] | 4665 | ExtensionCookieCallback() : result_(false) {} |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4666 | |
| 4667 | void SetCookieCallback(bool result) { |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4668 | result_ = result; |
| 4669 | } |
| 4670 | |
| 4671 | void GetAllCookiesCallback(const net::CookieList& list) { |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4672 | list_ = list; |
| 4673 | } |
| 4674 | net::CookieList list_; |
| 4675 | bool result_; |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4676 | }; |
| 4677 | |
Joshua Bell | 607cb14 | 2017-07-24 19:17:16 | [diff] [blame] | 4678 | namespace { |
| 4679 | // Helper to create (open, close, verify) a WebSQL database. |
| 4680 | // Must be run on the DatabaseTracker's task runner. |
| 4681 | void CreateDatabase(storage::DatabaseTracker* db_tracker, |
| 4682 | const std::string& origin_id) { |
| 4683 | DCHECK(db_tracker->task_runner()->RunsTasksInCurrentSequence()); |
| 4684 | base::string16 db_name = base::UTF8ToUTF16("db"); |
| 4685 | base::string16 description = base::UTF8ToUTF16("db_description"); |
| 4686 | int64_t size; |
| 4687 | db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
| 4688 | db_tracker->DatabaseClosed(origin_id, db_name); |
| 4689 | std::vector<storage::OriginInfo> origins; |
| 4690 | db_tracker->GetAllOriginsInfo(&origins); |
| 4691 | EXPECT_EQ(1U, origins.size()); |
| 4692 | EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); |
| 4693 | } |
| 4694 | } // namespace |
| 4695 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4696 | // Verifies extension state is removed upon uninstall. |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 4697 | TEST_F(ExtensionServiceTest, ClearExtensionData) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4698 | InitializeEmptyExtensionService(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4699 | ExtensionCookieCallback callback; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4700 | |
| 4701 | // Load a test extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4702 | base::FilePath path = data_dir(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4703 | path = path.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4704 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4705 | ASSERT_TRUE(extension); |
| 4706 | GURL ext_url(extension->url()); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 4707 | std::string origin_id = storage::GetIdentifierFromOrigin(ext_url); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4708 | |
| 4709 | // Set a cookie for the extension. |
mmenke | e28c9aa | 2016-01-20 23:54:04 | [diff] [blame] | 4710 | net::CookieStore* cookie_store = profile()->GetRequestContextForExtensions() |
| 4711 | ->GetURLRequestContext() |
| 4712 | ->cookie_store(); |
| 4713 | ASSERT_TRUE(cookie_store); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4714 | net::CookieOptions options; |
mmenke | e28c9aa | 2016-01-20 23:54:04 | [diff] [blame] | 4715 | cookie_store->SetCookieWithOptionsAsync( |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 4716 | ext_url, "dummy=value", options, |
| 4717 | base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 4718 | base::Unretained(&callback))); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4719 | content::RunAllTasksUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4720 | EXPECT_TRUE(callback.result_); |
| 4721 | |
mmenke | e28c9aa | 2016-01-20 23:54:04 | [diff] [blame] | 4722 | cookie_store->GetAllCookiesForURLAsync( |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4723 | ext_url, |
| 4724 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4725 | base::Unretained(&callback))); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4726 | content::RunAllTasksUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4727 | EXPECT_EQ(1U, callback.list_.size()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4728 | |
| 4729 | // Open a database. |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 4730 | storage::DatabaseTracker* db_tracker = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4731 | BrowserContext::GetDefaultStoragePartition(profile()) |
| 4732 | ->GetDatabaseTracker(); |
Joshua Bell | 607cb14 | 2017-07-24 19:17:16 | [diff] [blame] | 4733 | db_tracker->task_runner()->PostTask( |
| 4734 | FROM_HERE, |
| 4735 | base::BindOnce(&CreateDatabase, base::Unretained(db_tracker), origin_id)); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4736 | content::RunAllTasksUntilIdle(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4737 | |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 4738 | // Create local storage. We only simulate this by creating the backing files. |
| 4739 | // Note: This test depends on details of how the dom_storage library |
| 4740 | // stores data in the host file system. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4741 | base::FilePath lso_dir_path = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4742 | profile()->GetPath().AppendASCII("Local Storage"); |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 4743 | base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) |
| 4744 | .AddExtension(FILE_PATH_LITERAL(".localstorage")); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4745 | EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 4746 | EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4747 | EXPECT_TRUE(base::PathExists(lso_file_path)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4748 | |
[email protected] | ab30809 | 2011-08-25 23:37:19 | [diff] [blame] | 4749 | // Create indexed db. Similarly, it is enough to only simulate this by |
jsbell | bd2caa0 | 2017-07-14 01:13:07 | [diff] [blame] | 4750 | // creating the directory on the disk, and resetting the caches of |
| 4751 | // "known" origins. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4752 | IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition( |
| 4753 | profile())->GetIndexedDBContext(); |
jsbell | b8f7a91 | 2016-03-10 18:59:50 | [diff] [blame] | 4754 | base::FilePath idb_path = idb_context->GetFilePathForTesting(ext_url); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4755 | EXPECT_TRUE(base::CreateDirectory(idb_path)); |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4756 | EXPECT_TRUE(base::DirectoryExists(idb_path)); |
jsbell | bd2caa0 | 2017-07-14 01:13:07 | [diff] [blame] | 4757 | idb_context->ResetCachesForTesting(); |
[email protected] | e1dcf92 | 2010-11-22 19:12:12 | [diff] [blame] | 4758 | |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4759 | // Uninstall the extension. |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 4760 | ASSERT_TRUE( |
| 4761 | service()->UninstallExtension(good_crx, |
| 4762 | extensions::UNINSTALL_REASON_FOR_TESTING, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 4763 | NULL)); |
Devlin Cronin | 218df7f | 2017-11-21 21:41:31 | [diff] [blame] | 4764 | // The data deletion happens on the IO thread; since we use a |
| 4765 | // TestBrowserThreadBundle (without REAL_IO_THREAD), the IO and UI threads are |
| 4766 | // the same, and RunAllTasksUntilIdle() should run IO thread tasks. |
| 4767 | content::RunAllTasksUntilIdle(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4768 | |
| 4769 | // Check that the cookie is gone. |
mmenke | e28c9aa | 2016-01-20 23:54:04 | [diff] [blame] | 4770 | cookie_store->GetAllCookiesForURLAsync( |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4771 | ext_url, |
| 4772 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4773 | base::Unretained(&callback))); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4774 | content::RunAllTasksUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 4775 | EXPECT_EQ(0U, callback.list_.size()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4776 | |
| 4777 | // The database should have vanished as well. |
Joshua Bell | 607cb14 | 2017-07-24 19:17:16 | [diff] [blame] | 4778 | db_tracker->task_runner()->PostTask( |
| 4779 | FROM_HERE, base::BindOnce( |
| 4780 | [](storage::DatabaseTracker* db_tracker) { |
| 4781 | std::vector<storage::OriginInfo> origins; |
| 4782 | db_tracker->GetAllOriginsInfo(&origins); |
| 4783 | EXPECT_EQ(0U, origins.size()); |
| 4784 | }, |
| 4785 | base::Unretained(db_tracker))); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4786 | content::RunAllTasksUntilIdle(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4787 | |
| 4788 | // Check that the LSO file has been removed. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4789 | EXPECT_FALSE(base::PathExists(lso_file_path)); |
[email protected] | e1dcf92 | 2010-11-22 19:12:12 | [diff] [blame] | 4790 | |
| 4791 | // Check if the indexed db has disappeared too. |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4792 | EXPECT_FALSE(base::DirectoryExists(idb_path)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 4793 | } |
| 4794 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4795 | // Verifies app state is removed upon uninstall. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4796 | TEST_F(ExtensionServiceTest, ClearAppData) { |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4797 | InitializeEmptyExtensionService(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4798 | ExtensionCookieCallback callback; |
| 4799 | |
| 4800 | int pref_count = 0; |
| 4801 | |
| 4802 | // Install app1 with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4803 | const Extension* extension = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4804 | PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4805 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4806 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4807 | const std::string id1 = extension->id(); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 4808 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 4809 | APIPermission::kUnlimitedStorage)); |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 4810 | const GURL origin1( |
| 4811 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4812 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 4813 | origin1)); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 4814 | std::string origin_id = storage::GetIdentifierFromOrigin(origin1); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4815 | |
| 4816 | // Install app2 from the same origin with unlimited storage. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4817 | extension = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4818 | ValidatePrefKeyCount(++pref_count); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4819 | ASSERT_EQ(2u, registry()->enabled_extensions().size()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4820 | const std::string id2 = extension->id(); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 4821 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 4822 | APIPermission::kUnlimitedStorage)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4823 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 4824 | extensions::AppLaunchInfo::GetFullLaunchURL(extension))); |
| 4825 | const GURL origin2( |
| 4826 | extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4827 | EXPECT_EQ(origin1, origin2); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4828 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 4829 | origin2)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4830 | |
| 4831 | // Set a cookie for the extension. |
mmenke | e28c9aa | 2016-01-20 23:54:04 | [diff] [blame] | 4832 | net::CookieStore* cookie_store = profile()->GetRequestContext() |
| 4833 | ->GetURLRequestContext() |
| 4834 | ->cookie_store(); |
| 4835 | ASSERT_TRUE(cookie_store); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4836 | net::CookieOptions options; |
mmenke | e28c9aa | 2016-01-20 23:54:04 | [diff] [blame] | 4837 | cookie_store->SetCookieWithOptionsAsync( |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4838 | origin1, "dummy=value", options, |
| 4839 | base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 4840 | base::Unretained(&callback))); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4841 | content::RunAllTasksUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4842 | EXPECT_TRUE(callback.result_); |
| 4843 | |
mmenke | e28c9aa | 2016-01-20 23:54:04 | [diff] [blame] | 4844 | cookie_store->GetAllCookiesForURLAsync( |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4845 | origin1, |
| 4846 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4847 | base::Unretained(&callback))); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4848 | content::RunAllTasksUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4849 | EXPECT_EQ(1U, callback.list_.size()); |
| 4850 | |
| 4851 | // Open a database. |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 4852 | storage::DatabaseTracker* db_tracker = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4853 | BrowserContext::GetDefaultStoragePartition(profile()) |
| 4854 | ->GetDatabaseTracker(); |
Joshua Bell | 607cb14 | 2017-07-24 19:17:16 | [diff] [blame] | 4855 | db_tracker->task_runner()->PostTask( |
| 4856 | FROM_HERE, |
| 4857 | base::BindOnce(&CreateDatabase, base::Unretained(db_tracker), origin_id)); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4858 | content::RunAllTasksUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4859 | |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 4860 | // Create local storage. We only simulate this by creating the backing files. |
| 4861 | // Note: This test depends on details of how the dom_storage library |
| 4862 | // stores data in the host file system. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4863 | base::FilePath lso_dir_path = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4864 | profile()->GetPath().AppendASCII("Local Storage"); |
[email protected] | 5e30159 | 2013-06-18 06:36:05 | [diff] [blame] | 4865 | base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) |
| 4866 | .AddExtension(FILE_PATH_LITERAL(".localstorage")); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4867 | EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 4868 | EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0)); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4869 | EXPECT_TRUE(base::PathExists(lso_file_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4870 | |
| 4871 | // Create indexed db. Similarly, it is enough to only simulate this by |
jsbell | bd2caa0 | 2017-07-14 01:13:07 | [diff] [blame] | 4872 | // creating the directory on the disk, and resetting the caches of |
| 4873 | // "known" origins. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4874 | IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition( |
| 4875 | profile())->GetIndexedDBContext(); |
jsbell | b8f7a91 | 2016-03-10 18:59:50 | [diff] [blame] | 4876 | base::FilePath idb_path = idb_context->GetFilePathForTesting(origin1); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 4877 | EXPECT_TRUE(base::CreateDirectory(idb_path)); |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4878 | EXPECT_TRUE(base::DirectoryExists(idb_path)); |
jsbell | bd2caa0 | 2017-07-14 01:13:07 | [diff] [blame] | 4879 | idb_context->ResetCachesForTesting(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4880 | |
| 4881 | // Uninstall one of them, unlimited storage should still be granted |
| 4882 | // to the origin. |
Devlin Cronin | 6fd1cd6 | 2017-12-05 19:13:57 | [diff] [blame] | 4883 | UninstallExtension(id1); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4884 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4885 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 4886 | origin1)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4887 | |
| 4888 | // Check that the cookie is still there. |
mmenke | e28c9aa | 2016-01-20 23:54:04 | [diff] [blame] | 4889 | cookie_store->GetAllCookiesForURLAsync( |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4890 | origin1, |
| 4891 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4892 | base::Unretained(&callback))); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4893 | content::RunAllTasksUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4894 | EXPECT_EQ(1U, callback.list_.size()); |
| 4895 | |
| 4896 | // Now uninstall the other. Storage should be cleared for the apps. |
Devlin Cronin | 6fd1cd6 | 2017-12-05 19:13:57 | [diff] [blame] | 4897 | UninstallExtension(id2); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4898 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 4899 | EXPECT_FALSE( |
| 4900 | profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 4901 | origin1)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4902 | |
| 4903 | // Check that the cookie is gone. |
mmenke | e28c9aa | 2016-01-20 23:54:04 | [diff] [blame] | 4904 | cookie_store->GetAllCookiesForURLAsync( |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4905 | origin1, |
| 4906 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4907 | base::Unretained(&callback))); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4908 | content::RunAllTasksUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4909 | EXPECT_EQ(0U, callback.list_.size()); |
| 4910 | |
| 4911 | // The database should have vanished as well. |
Joshua Bell | 607cb14 | 2017-07-24 19:17:16 | [diff] [blame] | 4912 | db_tracker->task_runner()->PostTask( |
| 4913 | FROM_HERE, base::BindOnce( |
| 4914 | [](storage::DatabaseTracker* db_tracker) { |
| 4915 | std::vector<storage::OriginInfo> origins; |
| 4916 | db_tracker->GetAllOriginsInfo(&origins); |
| 4917 | EXPECT_EQ(0U, origins.size()); |
| 4918 | }, |
| 4919 | base::Unretained(db_tracker))); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4920 | content::RunAllTasksUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4921 | |
| 4922 | // Check that the LSO file has been removed. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 4923 | EXPECT_FALSE(base::PathExists(lso_file_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4924 | |
| 4925 | // Check if the indexed db has disappeared too. |
[email protected] | dcd1661 | 2013-07-15 20:18:09 | [diff] [blame] | 4926 | EXPECT_FALSE(base::DirectoryExists(idb_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4927 | } |
| 4928 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4929 | // Tests loading single extensions (like --load-extension) |
Devlin Cronin | a7baea2 | 2017-12-12 14:43:05 | [diff] [blame] | 4930 | TEST_F(ExtensionServiceTest, LoadExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4931 | InitializeEmptyExtensionService(); |
Devlin Cronin | a7baea2 | 2017-12-12 14:43:05 | [diff] [blame] | 4932 | extensions::TestExtensionDir good_extension_dir; |
| 4933 | good_extension_dir.WriteManifest( |
| 4934 | R"({ |
| 4935 | "name": "Good Extension", |
| 4936 | "version": "0.1", |
| 4937 | "manifest_version": 2 |
| 4938 | })"); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 4939 | |
Devlin Cronin | a7baea2 | 2017-12-12 14:43:05 | [diff] [blame] | 4940 | { |
| 4941 | extensions::ChromeTestExtensionLoader loader(profile()); |
| 4942 | loader.set_pack_extension(false); |
| 4943 | loader.LoadExtension(good_extension_dir.UnpackedPath()); |
| 4944 | } |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 4945 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 4946 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 4947 | ValidatePrefKeyCount(1); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4948 | |
Devlin Cronin | a7baea2 | 2017-12-12 14:43:05 | [diff] [blame] | 4949 | auto get_extension_by_name = [](const extensions::ExtensionSet& extensions, |
| 4950 | const std::string& name) { |
| 4951 | // NOTE: lambda type deduction doesn't recognize returning |
| 4952 | // const Extension* in one place and nullptr in another as the same type, so |
| 4953 | // we have to make sure to return an explicit type here. |
| 4954 | const extensions::Extension* result = nullptr; |
| 4955 | for (const auto& extension : extensions) { |
| 4956 | if (extension->name() == name) { |
| 4957 | result = extension.get(); |
| 4958 | break; |
| 4959 | } |
| 4960 | } |
| 4961 | return result; |
| 4962 | }; |
| 4963 | constexpr const char kGoodExtension[] = "Good Extension"; |
| 4964 | { |
| 4965 | const Extension* extension = |
| 4966 | get_extension_by_name(registry()->enabled_extensions(), kGoodExtension); |
| 4967 | ASSERT_TRUE(extension); |
| 4968 | EXPECT_EQ(Manifest::UNPACKED, extension->location()); |
| 4969 | } |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4970 | |
Devlin Cronin | a7baea2 | 2017-12-12 14:43:05 | [diff] [blame] | 4971 | // Try loading an extension with no manifest. It should fail. |
| 4972 | extensions::TestExtensionDir bad_extension_dir; |
| 4973 | bad_extension_dir.WriteFile(FILE_PATH_LITERAL("background.js"), "// some JS"); |
| 4974 | { |
| 4975 | extensions::ChromeTestExtensionLoader loader(profile()); |
| 4976 | loader.set_pack_extension(false); |
| 4977 | loader.set_should_fail(true); |
| 4978 | loader.LoadExtension(bad_extension_dir.UnpackedPath()); |
| 4979 | } |
| 4980 | |
| 4981 | EXPECT_EQ(1u, GetErrors().size()); |
| 4982 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 4983 | EXPECT_EQ(1u, registry()->GenerateInstalledExtensionsSet()->size()); |
| 4984 | EXPECT_TRUE( |
| 4985 | get_extension_by_name(registry()->enabled_extensions(), kGoodExtension)); |
| 4986 | |
| 4987 | // Test uninstalling the good extension. |
| 4988 | const extensions::ExtensionId good_id = |
| 4989 | get_extension_by_name(registry()->enabled_extensions(), kGoodExtension) |
| 4990 | ->id(); |
| 4991 | service()->UninstallExtension( |
| 4992 | good_id, extensions::UNINSTALL_REASON_FOR_TESTING, nullptr); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 4993 | content::RunAllTasksUntilIdle(); |
Devlin Cronin | a7baea2 | 2017-12-12 14:43:05 | [diff] [blame] | 4994 | EXPECT_TRUE(registry()->GenerateInstalledExtensionsSet()->is_empty()); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 4995 | } |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4996 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4997 | // Tests that we generate IDs when they are not specified in the manifest for |
| 4998 | // --load-extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4999 | TEST_F(ExtensionServiceTest, GenerateID) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5000 | InitializeEmptyExtensionService(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 5001 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5002 | base::FilePath no_id_ext = data_dir().AppendASCII("no_id"); |
| 5003 | extensions::UnpackedInstaller::Create(service())->Load(no_id_ext); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5004 | content::RunAllTasksUntilIdle(); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 5005 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5006 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 5007 | ASSERT_TRUE(crx_file::id_util::IdIsValid(loaded_[0]->id())); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 5008 | EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 5009 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 5010 | ValidatePrefKeyCount(1); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 5011 | |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 5012 | std::string previous_id = loaded_[0]->id(); |
| 5013 | |
| 5014 | // If we reload the same path, we should get the same extension ID. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5015 | extensions::UnpackedInstaller::Create(service())->Load(no_id_ext); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5016 | content::RunAllTasksUntilIdle(); |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 5017 | ASSERT_EQ(1u, loaded_.size()); |
| 5018 | ASSERT_EQ(previous_id, loaded_[0]->id()); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 5019 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5020 | |
[email protected] | 557c7bd | 2013-09-18 21:51:25 | [diff] [blame] | 5021 | TEST_F(ExtensionServiceTest, UnpackedValidatesLocales) { |
| 5022 | InitializeEmptyExtensionService(); |
| 5023 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5024 | base::FilePath bad_locale = |
| 5025 | data_dir().AppendASCII("unpacked").AppendASCII("bad_messages_file"); |
| 5026 | extensions::UnpackedInstaller::Create(service())->Load(bad_locale); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5027 | content::RunAllTasksUntilIdle(); |
[email protected] | 557c7bd | 2013-09-18 21:51:25 | [diff] [blame] | 5028 | EXPECT_EQ(1u, GetErrors().size()); |
| 5029 | base::FilePath ms_messages_file = bad_locale.AppendASCII("_locales") |
| 5030 | .AppendASCII("ms") |
| 5031 | .AppendASCII("messages.json"); |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 5032 | EXPECT_THAT(base::UTF16ToUTF8(GetErrors()[0]), testing::AllOf( |
| 5033 | testing::HasSubstr( |
| 5034 | base::UTF16ToUTF8(ms_messages_file.LossyDisplayName())), |
[email protected] | 557c7bd | 2013-09-18 21:51:25 | [diff] [blame] | 5035 | testing::HasSubstr("Dictionary keys must be quoted."))); |
| 5036 | ASSERT_EQ(0u, loaded_.size()); |
| 5037 | } |
| 5038 | |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 5039 | void ExtensionServiceTest::TestExternalProvider(MockExternalProvider* provider, |
| 5040 | Manifest::Location location) { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 5041 | // Verify that starting with no providers loads no extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5042 | service()->Init(); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 5043 | ASSERT_EQ(0u, loaded_.size()); |
| 5044 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 5045 | provider->set_visit_count(0); |
| 5046 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 5047 | // Register a test extension externally using the mock registry provider. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5048 | base::FilePath source_path = data_dir().AppendASCII("good.crx"); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5049 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 5050 | // Add the extension. |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 5051 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5052 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 5053 | // Reloading extensions should find our externally registered extension |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5054 | // and install it. |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 5055 | WaitForExternalExtensionInstalled(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5056 | |
| 5057 | ASSERT_EQ(0u, GetErrors().size()); |
| 5058 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 5059 | ASSERT_EQ(location, loaded_[0]->location()); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 5060 | ASSERT_EQ("1.0.0.0", loaded_[0]->version().GetString()); |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 5061 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 5062 | EXPECT_TRUE(prefs->GetInstalledExtensionInfo(good_crx)); |
| 5063 | // TODO(devlin): Testing the underlying values of the prefs for extensions |
| 5064 | // should be done in an ExtensionPrefs test, not here. This should only be |
| 5065 | // using the public ExtensionPrefs interfaces. |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 5066 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 5067 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5068 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 5069 | // Reload extensions without changing anything. The extension should be |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5070 | // loaded again. |
| 5071 | loaded_.clear(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5072 | service()->ReloadExtensionsForTest(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5073 | content::RunAllTasksUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5074 | ASSERT_EQ(0u, GetErrors().size()); |
| 5075 | ASSERT_EQ(1u, loaded_.size()); |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 5076 | EXPECT_TRUE(prefs->GetInstalledExtensionInfo(good_crx)); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 5077 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 5078 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 5079 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5080 | // Now update the extension with a new version. We should get upgraded. |
| 5081 | source_path = source_path.DirName().AppendASCII("good2.crx"); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 5082 | provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5083 | |
| 5084 | loaded_.clear(); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 5085 | WaitForExternalExtensionInstalled(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5086 | ASSERT_EQ(0u, GetErrors().size()); |
| 5087 | ASSERT_EQ(1u, loaded_.size()); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 5088 | ASSERT_EQ("1.0.0.1", loaded_[0]->version().GetString()); |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 5089 | EXPECT_TRUE(prefs->GetInstalledExtensionInfo(good_crx)); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 5090 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 5091 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5092 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5093 | // Uninstall the extension and reload. Nothing should happen because the |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5094 | // preference should prevent us from reinstalling. |
| 5095 | std::string id = loaded_[0]->id(); |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 5096 | EXPECT_EQ(id, good_crx); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 5097 | bool no_uninstall = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5098 | GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL); |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 5099 | service()->UninstallExtension(id, |
| 5100 | extensions::UNINSTALL_REASON_FOR_TESTING, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 5101 | NULL); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5102 | content::RunAllTasksUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5103 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5104 | base::FilePath install_path = extensions_install_dir().AppendASCII(id); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 5105 | if (no_uninstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 5106 | // Policy controlled extensions should not have been touched by uninstall. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 5107 | ASSERT_TRUE(base::PathExists(install_path)); |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 5108 | EXPECT_TRUE(prefs->GetInstalledExtensionInfo(good_crx)); |
| 5109 | EXPECT_FALSE(prefs->IsExternalExtensionUninstalled(good_crx)); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 5110 | } else { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5111 | // The extension should also be gone from the install directory. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 5112 | ASSERT_FALSE(base::PathExists(install_path)); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5113 | loaded_.clear(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5114 | service()->CheckForExternalUpdates(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5115 | content::RunAllTasksUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5116 | ASSERT_EQ(0u, loaded_.size()); |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 5117 | EXPECT_TRUE(prefs->IsExternalExtensionUninstalled(good_crx)); |
| 5118 | EXPECT_FALSE(prefs->GetInstalledExtensionInfo(good_crx)); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 5119 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5120 | // Now clear the preference and reinstall. |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 5121 | prefs->ClearExternalUninstallForTesting(good_crx); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 5122 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5123 | loaded_.clear(); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 5124 | WaitForExternalExtensionInstalled(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5125 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5126 | } |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 5127 | EXPECT_TRUE(prefs->GetInstalledExtensionInfo(good_crx)); |
| 5128 | EXPECT_FALSE(prefs->IsExternalExtensionUninstalled(good_crx)); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 5129 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 5130 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 5131 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5132 | if (GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL)) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 5133 | EXPECT_EQ(2, provider->visit_count()); |
| 5134 | } else { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5135 | // Now test an externally triggered uninstall (deleting the registry key or |
| 5136 | // the pref entry). |
| 5137 | provider->RemoveExtension(good_crx); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 5138 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5139 | loaded_.clear(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5140 | service()->OnExternalProviderReady(provider); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5141 | content::RunAllTasksUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5142 | ASSERT_EQ(0u, loaded_.size()); |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 5143 | EXPECT_FALSE(prefs->IsExternalExtensionUninstalled(good_crx)); |
| 5144 | EXPECT_FALSE(prefs->GetInstalledExtensionInfo(good_crx)); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 5145 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5146 | // The extension should also be gone from the install directory. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 5147 | ASSERT_FALSE(base::PathExists(install_path)); |
[email protected] | abe7a894 | 2009-06-23 05:14:29 | [diff] [blame] | 5148 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5149 | // Now test the case where user uninstalls and then the extension is removed |
| 5150 | // from the external provider. |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 5151 | provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 5152 | WaitForExternalExtensionInstalled(); |
[email protected] | abe7a894 | 2009-06-23 05:14:29 | [diff] [blame] | 5153 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5154 | ASSERT_EQ(1u, loaded_.size()); |
| 5155 | ASSERT_EQ(0u, GetErrors().size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 5156 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5157 | // User uninstalls. |
| 5158 | loaded_.clear(); |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 5159 | service()->UninstallExtension(id, |
| 5160 | extensions::UNINSTALL_REASON_FOR_TESTING, |
[email protected] | 42d58f6 | 2014-07-31 01:32:45 | [diff] [blame] | 5161 | NULL); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5162 | content::RunAllTasksUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5163 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 5164 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5165 | // Then remove the extension from the extension provider. |
| 5166 | provider->RemoveExtension(good_crx); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 5167 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5168 | // Should still be at 0. |
| 5169 | loaded_.clear(); |
rdevlin.cronin | f2e1cb01 | 2017-05-27 01:27:59 | [diff] [blame] | 5170 | service()->ReloadExtensionsForTest(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5171 | content::RunAllTasksUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5172 | ASSERT_EQ(0u, loaded_.size()); |
Devlin Cronin | 55fab54d | 2017-12-16 02:27:19 | [diff] [blame] | 5173 | |
| 5174 | EXPECT_FALSE(prefs->GetInstalledExtensionInfo(good_crx)); |
| 5175 | EXPECT_TRUE(prefs->IsExternalExtensionUninstalled(good_crx)); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 5176 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5177 | EXPECT_EQ(5, provider->visit_count()); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5178 | } |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 5179 | } |
| 5180 | |
| 5181 | // Tests the external installation feature |
| 5182 | #if defined(OS_WIN) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5183 | TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 5184 | // This should all work, even when normal extension installation is disabled. |
rdevlin.cronin | 7217be5 | 2017-03-24 20:47:05 | [diff] [blame] | 5185 | InitializeExtensionServiceWithExtensionsDisabled(); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 5186 | |
| 5187 | // Now add providers. Extension system takes ownership of the objects. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 5188 | MockExternalProvider* reg_provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 5189 | AddMockExternalProvider(Manifest::EXTERNAL_REGISTRY); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5190 | TestExternalProvider(reg_provider, Manifest::EXTERNAL_REGISTRY); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 5191 | } |
| 5192 | #endif |
| 5193 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5194 | TEST_F(ExtensionServiceTest, ExternalInstallPref) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5195 | InitializeEmptyExtensionService(); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 5196 | |
| 5197 | // Now add providers. Extension system takes ownership of the objects. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 5198 | MockExternalProvider* pref_provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 5199 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 5200 | |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5201 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5202 | } |
| 5203 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5204 | TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 5205 | // This should all work, even when normal extension installation is disabled. |
rdevlin.cronin | 7217be5 | 2017-03-24 20:47:05 | [diff] [blame] | 5206 | InitializeExtensionServiceWithExtensionsDisabled(); |
[email protected] | 55196e9 | 2010-09-29 15:04:46 | [diff] [blame] | 5207 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 5208 | // TODO(skerner): The mock provider is not a good model of a provider |
| 5209 | // that works with update URLs, because it adds file and version info. |
| 5210 | // Extend the mock to work with update URLs. This test checks the |
| 5211 | // behavior that is common to all external extension visitors. The |
| 5212 | // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| 5213 | // what the visitor does results in an extension being downloaded and |
| 5214 | // installed. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 5215 | MockExternalProvider* pref_provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 5216 | AddMockExternalProvider(Manifest::EXTERNAL_PREF_DOWNLOAD); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5217 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF_DOWNLOAD); |
[email protected] | 55196e9 | 2010-09-29 15:04:46 | [diff] [blame] | 5218 | } |
| 5219 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5220 | TEST_F(ExtensionServiceTest, ExternalInstallPolicyUpdateUrl) { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5221 | // This should all work, even when normal extension installation is disabled. |
rdevlin.cronin | 7217be5 | 2017-03-24 20:47:05 | [diff] [blame] | 5222 | InitializeExtensionServiceWithExtensionsDisabled(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5223 | |
| 5224 | // TODO(skerner): The mock provider is not a good model of a provider |
| 5225 | // that works with update URLs, because it adds file and version info. |
| 5226 | // Extend the mock to work with update URLs. This test checks the |
| 5227 | // behavior that is common to all external extension visitors. The |
| 5228 | // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| 5229 | // what the visitor does results in an extension being downloaded and |
| 5230 | // installed. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 5231 | MockExternalProvider* pref_provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 5232 | AddMockExternalProvider(Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5233 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 5234 | } |
| 5235 | |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 5236 | // Tests that external extensions get uninstalled when the external extension |
| 5237 | // providers can't account for them. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5238 | TEST_F(ExtensionServiceTest, ExternalUninstall) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 5239 | // Start the extensions service with one external extension already installed. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5240 | base::FilePath source_install_dir = |
| 5241 | data_dir().AppendASCII("good").AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5242 | base::FilePath pref_path = source_install_dir |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 5243 | .DirName() |
| 5244 | .AppendASCII("PreferencesExternal"); |
| 5245 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5246 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5247 | service()->Init(); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 5248 | |
| 5249 | ASSERT_EQ(0u, GetErrors().size()); |
[email protected] | 1f4728f | 2012-12-05 20:40:05 | [diff] [blame] | 5250 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 5251 | } |
| 5252 | |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5253 | // Test that running multiple update checks simultaneously does not |
| 5254 | // keep the update from succeeding. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5255 | TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5256 | InitializeEmptyExtensionService(); |
| 5257 | |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 5258 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 5259 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5260 | |
| 5261 | // Verify that starting with no providers loads no extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5262 | service()->Init(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5263 | ASSERT_EQ(0u, loaded_.size()); |
| 5264 | |
| 5265 | // Start two checks for updates. |
| 5266 | provider->set_visit_count(0); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5267 | service()->CheckForExternalUpdates(); |
| 5268 | service()->CheckForExternalUpdates(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5269 | content::RunAllTasksUntilIdle(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5270 | |
| 5271 | // Two calls should cause two checks for external extensions. |
| 5272 | EXPECT_EQ(2, provider->visit_count()); |
| 5273 | EXPECT_EQ(0u, GetErrors().size()); |
| 5274 | EXPECT_EQ(0u, loaded_.size()); |
| 5275 | |
| 5276 | // Register a test extension externally using the mock registry provider. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5277 | base::FilePath source_path = data_dir().AppendASCII("good.crx"); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5278 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); |
| 5279 | |
| 5280 | // Two checks for external updates should find the extension, and install it |
| 5281 | // once. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5282 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 5283 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5284 | content::NotificationService::AllSources()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5285 | provider->set_visit_count(0); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5286 | service()->CheckForExternalUpdates(); |
| 5287 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5288 | observer.Wait(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5289 | EXPECT_EQ(2, provider->visit_count()); |
| 5290 | ASSERT_EQ(0u, GetErrors().size()); |
| 5291 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5292 | ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 5293 | ASSERT_EQ("1.0.0.0", loaded_[0]->version().GetString()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5294 | ValidatePrefKeyCount(1); |
| 5295 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5296 | ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5297 | |
| 5298 | provider->RemoveExtension(good_crx); |
| 5299 | provider->set_visit_count(0); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5300 | service()->CheckForExternalUpdates(); |
| 5301 | service()->CheckForExternalUpdates(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5302 | content::RunAllTasksUntilIdle(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 5303 | |
| 5304 | // Two calls should cause two checks for external extensions. |
| 5305 | // Because the external source no longer includes good_crx, |
| 5306 | // good_crx will be uninstalled. So, expect that no extensions |
| 5307 | // are loaded. |
| 5308 | EXPECT_EQ(2, provider->visit_count()); |
| 5309 | EXPECT_EQ(0u, GetErrors().size()); |
| 5310 | EXPECT_EQ(0u, loaded_.size()); |
| 5311 | } |
| 5312 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5313 | TEST_F(ExtensionServiceTest, ExternalPrefProvider) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5314 | InitializeEmptyExtensionService(); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5315 | |
| 5316 | // Test some valid extension records. |
| 5317 | // Set a base path to avoid erroring out on relative paths. |
| 5318 | // Paths starting with // are absolute on every platform we support. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5319 | base::FilePath base_path(FILE_PATH_LITERAL("//base/path")); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5320 | ASSERT_TRUE(base_path.IsAbsolute()); |
| 5321 | MockProviderVisitor visitor(base_path); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5322 | std::string json_data = |
| 5323 | "{" |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5324 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5325 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5326 | " \"external_version\": \"1.0\"" |
| 5327 | " }," |
| 5328 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5329 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5330 | " \"external_version\": \"2.0\"" |
| 5331 | " }," |
| 5332 | " \"cccccccccccccccccccccccccccccccc\": {" |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 5333 | " \"external_update_url\": \"http:\\\\foo.com/update\"," |
| 5334 | " \"install_parameter\": \"id\"" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5335 | " }" |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5336 | "}"; |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5337 | EXPECT_EQ(3, visitor.Visit(json_data)); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5338 | |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5339 | // Simulate an external_extensions.json file that contains seven invalid |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5340 | // records: |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5341 | // - One that is missing the 'external_crx' key. |
| 5342 | // - One that is missing the 'external_version' key. |
| 5343 | // - One that is specifying .. in the path. |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 5344 | // - One that specifies both a file and update URL. |
| 5345 | // - One that specifies no file or update URL. |
| 5346 | // - One that has an update URL that is not well formed. |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5347 | // - One that contains a malformed version. |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 5348 | // - One that has an invalid id. |
| 5349 | // - One that has a non-dictionary value. |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 5350 | // - One that has an integer 'external_version' instead of a string. |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5351 | // The final extension is valid, and we check that it is read to make sure |
| 5352 | // failures don't stop valid records from being read. |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5353 | json_data = |
| 5354 | "{" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5355 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5356 | " \"external_version\": \"1.0\"" |
| 5357 | " }," |
| 5358 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5359 | " \"external_crx\": \"RandomExtension.crx\"" |
| 5360 | " }," |
| 5361 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 5362 | " \"external_crx\": \"..\\\\foo\\\\RandomExtension2.crx\"," |
| 5363 | " \"external_version\": \"2.0\"" |
| 5364 | " }," |
| 5365 | " \"dddddddddddddddddddddddddddddddd\": {" |
| 5366 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5367 | " \"external_version\": \"2.0\"," |
| 5368 | " \"external_update_url\": \"http:\\\\foo.com/update\"" |
| 5369 | " }," |
| 5370 | " \"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\": {" |
| 5371 | " }," |
| 5372 | " \"ffffffffffffffffffffffffffffffff\": {" |
| 5373 | " \"external_update_url\": \"This string is not a valid URL\"" |
| 5374 | " }," |
| 5375 | " \"gggggggggggggggggggggggggggggggg\": {" |
| 5376 | " \"external_crx\": \"RandomExtension3.crx\"," |
| 5377 | " \"external_version\": \"This is not a valid version!\"" |
| 5378 | " }," |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 5379 | " \"This is not a valid id!\": {}," |
| 5380 | " \"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\": true," |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 5381 | " \"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\": {" |
| 5382 | " \"external_crx\": \"RandomExtension4.crx\"," |
| 5383 | " \"external_version\": 1.0" |
| 5384 | " }," |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 5385 | " \"pppppppppppppppppppppppppppppppp\": {" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 5386 | " \"external_crx\": \"RandomValidExtension.crx\"," |
| 5387 | " \"external_version\": \"1.0\"" |
| 5388 | " }" |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 5389 | "}"; |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 5390 | EXPECT_EQ(1, visitor.Visit(json_data)); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5391 | |
| 5392 | // Check that if a base path is not provided, use of a relative |
| 5393 | // path fails. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5394 | base::FilePath empty; |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 5395 | MockProviderVisitor visitor_no_relative_paths(empty); |
| 5396 | |
| 5397 | // Use absolute paths. Expect success. |
| 5398 | json_data = |
| 5399 | "{" |
| 5400 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5401 | " \"external_crx\": \"//RandomExtension1.crx\"," |
| 5402 | " \"external_version\": \"3.0\"" |
| 5403 | " }," |
| 5404 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5405 | " \"external_crx\": \"//path/to/RandomExtension2.crx\"," |
| 5406 | " \"external_version\": \"3.0\"" |
| 5407 | " }" |
| 5408 | "}"; |
| 5409 | EXPECT_EQ(2, visitor_no_relative_paths.Visit(json_data)); |
| 5410 | |
| 5411 | // Use a relative path. Expect that it will error out. |
| 5412 | json_data = |
| 5413 | "{" |
| 5414 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 5415 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5416 | " \"external_version\": \"3.0\"" |
| 5417 | " }" |
| 5418 | "}"; |
| 5419 | EXPECT_EQ(0, visitor_no_relative_paths.Visit(json_data)); |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 5420 | |
| 5421 | // Test supported_locales. |
| 5422 | json_data = |
| 5423 | "{" |
| 5424 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5425 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5426 | " \"external_version\": \"1.0\"," |
| 5427 | " \"supported_locales\": [ \"en\" ]" |
| 5428 | " }," |
| 5429 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5430 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5431 | " \"external_version\": \"2.0\"," |
| 5432 | " \"supported_locales\": [ \"en-GB\" ]" |
| 5433 | " }," |
| 5434 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 5435 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5436 | " \"external_version\": \"3.0\"," |
| 5437 | " \"supported_locales\": [ \"en_US\", \"fr\" ]" |
| 5438 | " }" |
| 5439 | "}"; |
| 5440 | { |
| 5441 | ScopedBrowserLocale guard("en-US"); |
| 5442 | EXPECT_EQ(2, visitor.Visit(json_data)); |
| 5443 | } |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 5444 | |
[email protected] | 19eac6d | 2013-05-30 06:51:03 | [diff] [blame] | 5445 | // Test keep_if_present. |
| 5446 | json_data = |
| 5447 | "{" |
| 5448 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5449 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5450 | " \"external_version\": \"1.0\"," |
| 5451 | " \"keep_if_present\": true" |
| 5452 | " }" |
| 5453 | "}"; |
| 5454 | { |
| 5455 | EXPECT_EQ(0, visitor.Visit(json_data)); |
| 5456 | } |
| 5457 | |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 5458 | // Test is_bookmark_app. |
| 5459 | MockProviderVisitor from_bookmark_visitor( |
| 5460 | base_path, Extension::FROM_BOOKMARK); |
| 5461 | json_data = |
| 5462 | "{" |
| 5463 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5464 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5465 | " \"external_version\": \"1.0\"," |
| 5466 | " \"is_bookmark_app\": true" |
| 5467 | " }" |
| 5468 | "}"; |
| 5469 | EXPECT_EQ(1, from_bookmark_visitor.Visit(json_data)); |
[email protected] | 7425d7df | 2012-11-28 14:35:42 | [diff] [blame] | 5470 | |
| 5471 | // Test is_from_webstore. |
| 5472 | MockProviderVisitor from_webstore_visitor( |
| 5473 | base_path, Extension::FROM_WEBSTORE); |
| 5474 | json_data = |
| 5475 | "{" |
| 5476 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5477 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5478 | " \"external_version\": \"1.0\"," |
| 5479 | " \"is_from_webstore\": true" |
| 5480 | " }" |
| 5481 | "}"; |
| 5482 | EXPECT_EQ(1, from_webstore_visitor.Visit(json_data)); |
[email protected] | bf9fd5ae | 2014-04-09 22:50:06 | [diff] [blame] | 5483 | |
| 5484 | // Test was_installed_by_eom. |
| 5485 | MockProviderVisitor was_installed_by_eom_visitor( |
| 5486 | base_path, Extension::WAS_INSTALLED_BY_OEM); |
| 5487 | json_data = |
| 5488 | "{" |
| 5489 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5490 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5491 | " \"external_version\": \"1.0\"," |
| 5492 | " \"was_installed_by_oem\": true" |
| 5493 | " }" |
| 5494 | "}"; |
| 5495 | EXPECT_EQ(1, was_installed_by_eom_visitor.Visit(json_data)); |
dpolukhin | 2c6ef293 | 2015-05-12 16:06:13 | [diff] [blame] | 5496 | |
| 5497 | // Test min_profile_created_by_version. |
| 5498 | MockProviderVisitor min_profile_created_by_version_visitor(base_path); |
| 5499 | json_data = |
| 5500 | "{" |
| 5501 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5502 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5503 | " \"external_version\": \"1.0\"," |
| 5504 | " \"min_profile_created_by_version\": \"42.0.0.1\"" |
| 5505 | " }," |
| 5506 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5507 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5508 | " \"external_version\": \"1.0\"," |
| 5509 | " \"min_profile_created_by_version\": \"43.0.0.1\"" |
| 5510 | " }," |
| 5511 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 5512 | " \"external_crx\": \"RandomExtension3.crx\"," |
| 5513 | " \"external_version\": \"3.0\"," |
| 5514 | " \"min_profile_created_by_version\": \"44.0.0.1\"" |
| 5515 | " }" |
| 5516 | "}"; |
| 5517 | min_profile_created_by_version_visitor.profile()->GetPrefs()->SetString( |
| 5518 | prefs::kProfileCreatedByVersion, "40.0.0.1"); |
| 5519 | EXPECT_EQ(0, min_profile_created_by_version_visitor.Visit(json_data)); |
| 5520 | min_profile_created_by_version_visitor.profile()->GetPrefs()->SetString( |
| 5521 | prefs::kProfileCreatedByVersion, "43.0.0.1"); |
| 5522 | EXPECT_EQ(2, min_profile_created_by_version_visitor.Visit(json_data)); |
| 5523 | min_profile_created_by_version_visitor.profile()->GetPrefs()->SetString( |
| 5524 | prefs::kProfileCreatedByVersion, "45.0.0.1"); |
| 5525 | EXPECT_EQ(3, min_profile_created_by_version_visitor.Visit(json_data)); |
[email protected] | e18236b | 2009-06-22 21:32:10 | [diff] [blame] | 5526 | } |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5527 | |
dpolukhin | 1687ef3 | 2015-06-22 11:12:37 | [diff] [blame] | 5528 | TEST_F(ExtensionServiceTest, DoNotInstallForEnterprise) { |
| 5529 | InitializeEmptyExtensionService(); |
| 5530 | |
| 5531 | const base::FilePath base_path(FILE_PATH_LITERAL("//base/path")); |
| 5532 | ASSERT_TRUE(base_path.IsAbsolute()); |
| 5533 | MockProviderVisitor visitor(base_path); |
| 5534 | policy::ProfilePolicyConnector* const connector = |
| 5535 | policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
| 5536 | visitor.profile()); |
| 5537 | connector->OverrideIsManagedForTesting(true); |
| 5538 | EXPECT_TRUE(connector->IsManaged()); |
| 5539 | |
| 5540 | std::string json_data = |
| 5541 | "{" |
| 5542 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5543 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5544 | " \"external_version\": \"1.0\"," |
| 5545 | " \"do_not_install_for_enterprise\": true" |
| 5546 | " }," |
| 5547 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5548 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5549 | " \"external_version\": \"1.0\"" |
| 5550 | " }" |
| 5551 | "}"; |
| 5552 | EXPECT_EQ(1, visitor.Visit(json_data)); |
| 5553 | } |
| 5554 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 5555 | TEST_F(ExtensionServiceTest, IncrementalUpdateThroughRegistry) { |
| 5556 | InitializeEmptyExtensionService(); |
| 5557 | |
| 5558 | // Test some valid extension records. |
| 5559 | // Set a base path to avoid erroring out on relative paths. |
| 5560 | // Paths starting with // are absolute on every platform we support. |
| 5561 | base::FilePath base_path(FILE_PATH_LITERAL("//base/path")); |
| 5562 | ASSERT_TRUE(base_path.IsAbsolute()); |
| 5563 | MockUpdateProviderVisitor visitor(base_path); |
| 5564 | std::string json_data = |
| 5565 | "{" |
| 5566 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5567 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5568 | " \"external_version\": \"1.0\"" |
| 5569 | " }," |
| 5570 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5571 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5572 | " \"external_version\": \"2.0\"" |
| 5573 | " }," |
| 5574 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 5575 | " \"external_update_url\": \"http:\\\\foo.com/update\"," |
| 5576 | " \"install_parameter\": \"id\"" |
| 5577 | " }" |
| 5578 | "}"; |
| 5579 | EXPECT_EQ(3, visitor.Visit(json_data, Manifest::EXTERNAL_REGISTRY, |
| 5580 | Manifest::EXTERNAL_PREF_DOWNLOAD)); |
| 5581 | |
| 5582 | // c* removed and d*, e*, f* added, a*, b* existing. |
| 5583 | json_data = |
| 5584 | "{" |
| 5585 | " \"dddddddddddddddddddddddddddddddd\": {" |
| 5586 | " \"external_crx\": \"RandomExtension3.crx\"," |
| 5587 | " \"external_version\": \"1.0\"" |
| 5588 | " }," |
| 5589 | " \"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\": {" |
| 5590 | " \"external_update_url\": \"http:\\\\foo.com/update\"," |
| 5591 | " \"install_parameter\": \"id\"" |
| 5592 | " }," |
| 5593 | " \"ffffffffffffffffffffffffffffffff\": {" |
| 5594 | " \"external_update_url\": \"http:\\\\bar.com/update\"," |
| 5595 | " \"install_parameter\": \"id\"" |
| 5596 | " }," |
| 5597 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 5598 | " \"external_crx\": \"RandomExtension.crx\"," |
| 5599 | " \"external_version\": \"1.0\"" |
| 5600 | " }," |
| 5601 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 5602 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 5603 | " \"external_version\": \"2.0\"" |
| 5604 | " }" |
| 5605 | "}"; |
| 5606 | |
| 5607 | // This will simulate registry loader observing new changes in registry and |
| 5608 | // hence will discover new extensions. |
| 5609 | visitor.VisitDueToUpdate(json_data); |
| 5610 | |
| 5611 | // UpdateUrl. |
| 5612 | EXPECT_EQ(2u, visitor.GetUpdateURLExtensionCount()); |
| 5613 | EXPECT_TRUE( |
| 5614 | visitor.HasSeenUpdateWithUpdateUrl("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")); |
| 5615 | EXPECT_TRUE( |
| 5616 | visitor.HasSeenUpdateWithUpdateUrl("ffffffffffffffffffffffffffffffff")); |
| 5617 | |
| 5618 | // File. |
| 5619 | EXPECT_EQ(3u, visitor.GetFileExtensionCount()); |
| 5620 | EXPECT_TRUE( |
| 5621 | visitor.HasSeenUpdateWithFile("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); |
| 5622 | EXPECT_TRUE( |
| 5623 | visitor.HasSeenUpdateWithFile("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); |
| 5624 | EXPECT_TRUE( |
| 5625 | visitor.HasSeenUpdateWithFile("dddddddddddddddddddddddddddddddd")); |
| 5626 | |
| 5627 | // Removed extensions. |
| 5628 | EXPECT_EQ(1u, visitor.GetRemovedExtensionCount()); |
| 5629 | EXPECT_TRUE(visitor.HasSeenRemoval("cccccccccccccccccccccccccccccccc")); |
| 5630 | |
| 5631 | // Simulate all 5 extensions being removed. |
| 5632 | json_data = "{}"; |
| 5633 | visitor.VisitDueToUpdate(json_data); |
| 5634 | EXPECT_EQ(0u, visitor.GetUpdateURLExtensionCount()); |
| 5635 | EXPECT_EQ(0u, visitor.GetFileExtensionCount()); |
| 5636 | EXPECT_EQ(5u, visitor.GetRemovedExtensionCount()); |
| 5637 | } |
| 5638 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5639 | // Test loading good extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5640 | TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) { |
[email protected] | 6884a80 | 2012-08-07 03:55:22 | [diff] [blame] | 5641 | // Ensure we're testing in "en" and leave global state untouched. |
| 5642 | extension_l10n_util::ScopedLocaleForTest testLocale("en"); |
| 5643 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5644 | // Initialize the test dir with a good Preferences/extensions. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5645 | base::FilePath source_install_dir = data_dir().AppendASCII("l10n"); |
[email protected] | e96a060 | 2014-02-15 08:27:42 | [diff] [blame] | 5646 | base::FilePath pref_path = |
| 5647 | source_install_dir.Append(chrome::kPreferencesFilename); |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5648 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5649 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5650 | service()->Init(); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 5651 | |
| 5652 | ASSERT_EQ(3u, loaded_.size()); |
| 5653 | |
| 5654 | // This was equal to "sr" on load. |
| 5655 | ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en"); |
| 5656 | |
| 5657 | // These are untouched by re-localization. |
| 5658 | ValidateStringPref(loaded_[1]->id(), keys::kCurrentLocale, "en"); |
| 5659 | EXPECT_FALSE(IsPrefExist(loaded_[1]->id(), keys::kCurrentLocale)); |
| 5660 | |
| 5661 | // This one starts with Serbian name, and gets re-localized into English. |
| 5662 | EXPECT_EQ("My name is simple.", loaded_[0]->name()); |
| 5663 | |
| 5664 | // These are untouched by re-localization. |
| 5665 | EXPECT_EQ("My name is simple.", loaded_[1]->name()); |
| 5666 | EXPECT_EQ("no l10n", loaded_[2]->name()); |
| 5667 | } |
| 5668 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5669 | class ExtensionsReadyRecorder : public content::NotificationObserver { |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5670 | public: |
| 5671 | ExtensionsReadyRecorder() : ready_(false) { |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 5672 | registrar_.Add(this, |
| 5673 | extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 5674 | content::NotificationService::AllSources()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5675 | } |
| 5676 | |
| 5677 | void set_ready(bool value) { ready_ = value; } |
| 5678 | bool ready() { return ready_; } |
| 5679 | |
| 5680 | private: |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 5681 | void Observe(int type, |
| 5682 | const content::NotificationSource& source, |
| 5683 | const content::NotificationDetails& details) override { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 5684 | switch (type) { |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 5685 | case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED: |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5686 | ready_ = true; |
| 5687 | break; |
| 5688 | default: |
| 5689 | NOTREACHED(); |
| 5690 | } |
| 5691 | } |
| 5692 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 5693 | content::NotificationRegistrar registrar_; |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5694 | bool ready_; |
| 5695 | }; |
| 5696 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5697 | // Test that we get enabled/disabled correctly for all the pref/command-line |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5698 | // combinations. We don't want to derive from the ExtensionServiceTest class |
| 5699 | // for this test, so we use ExtensionServiceTestSimple. |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5700 | // |
| 5701 | // Also tests that we always fire EXTENSIONS_READY, no matter whether we are |
| 5702 | // enabled or not. |
skyostil | 0becb33 | 2015-04-27 17:59:37 | [diff] [blame] | 5703 | class ExtensionServiceTestSimple : public testing::Test { |
| 5704 | content::TestBrowserThreadBundle thread_bundle_; |
| 5705 | }; |
| 5706 | |
| 5707 | TEST_F(ExtensionServiceTestSimple, Enabledness) { |
[email protected] | 5a24d2b | 2012-11-14 20:38:31 | [diff] [blame] | 5708 | // Make sure the PluginService singleton is destroyed at the end of the test. |
[email protected] | 39fdf520 | 2012-11-14 00:38:17 | [diff] [blame] | 5709 | base::ShadowingAtExitManager at_exit_manager; |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 5710 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 5711 | content::PluginService::GetInstance()->Init(); |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 5712 | #endif |
[email protected] | 5a24d2b | 2012-11-14 20:38:31 | [diff] [blame] | 5713 | |
Devlin Cronin | 9722a72 | 2017-12-16 03:35:10 | [diff] [blame] | 5714 | extensions::LoadErrorReporter::Init(false); // no noisy errors |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5715 | ExtensionsReadyRecorder recorder; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 5716 | std::unique_ptr<TestingProfile> profile(new TestingProfile()); |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 5717 | std::unique_ptr<base::CommandLine> command_line; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5718 | base::FilePath install_dir = profile->GetPath() |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 5719 | .AppendASCII(extensions::kInstallDirectoryName); |
[email protected] | be5a6db | 2012-11-13 14:39:11 | [diff] [blame] | 5720 | |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5721 | // By default, we are enabled. |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 5722 | command_line.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5723 | ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5724 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5725 | CreateExtensionService( |
| 5726 | command_line.get(), |
| 5727 | install_dir, |
| 5728 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5729 | EXPECT_TRUE(service->extensions_enabled()); |
| 5730 | service->Init(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5731 | content::RunAllTasksUntilIdle(); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5732 | EXPECT_TRUE(recorder.ready()); |
| 5733 | |
| 5734 | // If either the command line or pref is set, we are disabled. |
| 5735 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 5736 | profile.reset(new TestingProfile()); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5737 | command_line->AppendSwitch(switches::kDisableExtensions); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5738 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5739 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5740 | CreateExtensionService( |
| 5741 | command_line.get(), |
| 5742 | install_dir, |
| 5743 | false); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5744 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5745 | service->Init(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5746 | content::RunAllTasksUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5747 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5748 | |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5749 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 5750 | profile.reset(new TestingProfile()); |
| 5751 | profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5752 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5753 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5754 | CreateExtensionService( |
| 5755 | command_line.get(), |
| 5756 | install_dir, |
| 5757 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5758 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5759 | service->Init(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5760 | content::RunAllTasksUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5761 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5762 | |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5763 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 5764 | profile.reset(new TestingProfile()); |
| 5765 | profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 5766 | command_line.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 5767 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 5768 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 5769 | CreateExtensionService( |
| 5770 | command_line.get(), |
| 5771 | install_dir, |
| 5772 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 5773 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5774 | service->Init(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5775 | content::RunAllTasksUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 5776 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 7e1951a | 2010-09-30 10:22:20 | [diff] [blame] | 5777 | |
| 5778 | // Explicitly delete all the resources used in this test. |
| 5779 | profile.reset(); |
| 5780 | service = NULL; |
[email protected] | 060d497 | 2012-07-19 17:22:39 | [diff] [blame] | 5781 | // Execute any pending deletion tasks. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5782 | content::RunAllTasksUntilIdle(); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 5783 | } |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5784 | |
| 5785 | // Test loading extensions that require limited and unlimited storage quotas. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5786 | TEST_F(ExtensionServiceTest, StorageQuota) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5787 | InitializeEmptyExtensionService(); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5788 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5789 | base::FilePath extensions_path = data_dir().AppendASCII("storage_quota"); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5790 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5791 | base::FilePath limited_quota_ext = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 5792 | extensions_path.AppendASCII("limited_quota") |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5793 | .AppendASCII("1.0"); |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 5794 | |
| 5795 | // The old permission name for unlimited quota was "unlimited_storage", but |
| 5796 | // we changed it to "unlimitedStorage". This tests both versions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5797 | base::FilePath unlimited_quota_ext = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 5798 | extensions_path.AppendASCII("unlimited_quota") |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5799 | .AppendASCII("1.0"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5800 | base::FilePath unlimited_quota_ext2 = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 5801 | extensions_path.AppendASCII("unlimited_quota") |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 5802 | .AppendASCII("2.0"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5803 | extensions::UnpackedInstaller::Create(service())->Load(limited_quota_ext); |
| 5804 | extensions::UnpackedInstaller::Create(service())->Load(unlimited_quota_ext); |
| 5805 | extensions::UnpackedInstaller::Create(service())->Load(unlimited_quota_ext2); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 5806 | content::RunAllTasksUntilIdle(); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5807 | |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 5808 | ASSERT_EQ(3u, loaded_.size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5809 | EXPECT_TRUE(profile()); |
| 5810 | EXPECT_FALSE(profile()->IsOffTheRecord()); |
| 5811 | EXPECT_FALSE( |
| 5812 | profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 5813 | loaded_[0]->url())); |
| 5814 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
[email protected] | 7c5f2ec | 2011-05-26 19:15:26 | [diff] [blame] | 5815 | loaded_[1]->url())); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5816 | EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
[email protected] | 7c5f2ec | 2011-05-26 19:15:26 | [diff] [blame] | 5817 | loaded_[2]->url())); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 5818 | } |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5819 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 5820 | // Tests ComponentLoader::Add(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5821 | TEST_F(ExtensionServiceTest, ComponentExtensions) { |
[email protected] | f0b97f1 | 2010-10-11 21:44:35 | [diff] [blame] | 5822 | // Component extensions should work even when extensions are disabled. |
rdevlin.cronin | 7217be5 | 2017-03-24 20:47:05 | [diff] [blame] | 5823 | InitializeExtensionServiceWithExtensionsDisabled(); |
[email protected] | f0b97f1 | 2010-10-11 21:44:35 | [diff] [blame] | 5824 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5825 | base::FilePath path = data_dir() |
| 5826 | .AppendASCII("good") |
| 5827 | .AppendASCII("Extensions") |
| 5828 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 5829 | .AppendASCII("1.0.0.0"); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5830 | |
| 5831 | std::string manifest; |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 5832 | ASSERT_TRUE(base::ReadFileToString( |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 5833 | path.Append(extensions::kManifestFilename), &manifest)); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5834 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5835 | service()->component_loader()->Add(manifest, path); |
| 5836 | service()->Init(); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5837 | |
| 5838 | // Note that we do not pump messages -- the extension should be loaded |
| 5839 | // immediately. |
| 5840 | |
| 5841 | EXPECT_EQ(0u, GetErrors().size()); |
| 5842 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5843 | EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5844 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5845 | |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 5846 | // Component extensions get a prefs entry on first install. |
| 5847 | ValidatePrefKeyCount(1); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5848 | |
| 5849 | // Reload all extensions, and make sure it comes back. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5850 | std::string extension_id = (*registry()->enabled_extensions().begin())->id(); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5851 | loaded_.clear(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5852 | service()->ReloadExtensionsForTest(); |
| 5853 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
| 5854 | EXPECT_EQ(extension_id, (*registry()->enabled_extensions().begin())->id()); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 5855 | } |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5856 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5857 | TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5858 | InitializeEmptyExtensionService(); |
| 5859 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5860 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5861 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5862 | ValidatePrefKeyCount(1u); |
| 5863 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5864 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5865 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 5866 | extensions::PendingExtensionManager* pending = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5867 | service()->pending_extension_manager(); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5868 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5869 | |
| 5870 | // Skip install when the location is the same. |
Devlin Cronin | d4c2a8f3 | 2017-09-29 17:08:30 | [diff] [blame] | 5871 | GURL good_update_url(kGoodUpdateURL); |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5872 | ExternalInstallInfoUpdateUrl info( |
| 5873 | kGoodId, std::string(), std::move(good_update_url), Manifest::INTERNAL, |
| 5874 | Extension::NO_FLAGS, false); |
| 5875 | EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(info, true)); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5876 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5877 | |
| 5878 | // Install when the location has higher priority. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5879 | info.download_location = Manifest::EXTERNAL_POLICY_DOWNLOAD; |
| 5880 | EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(info, true)); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5881 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5882 | |
| 5883 | // Try the low priority again. Should be rejected. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5884 | info.download_location = Manifest::EXTERNAL_PREF_DOWNLOAD; |
| 5885 | EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(info, true)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5886 | // The existing record should still be present in the pending extension |
| 5887 | // manager. |
| 5888 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5889 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5890 | pending->Remove(kGoodId); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5891 | |
| 5892 | // Skip install when the location has the same priority as the installed |
| 5893 | // location. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5894 | info.download_location = Manifest::INTERNAL; |
| 5895 | EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(info, true)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5896 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5897 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5898 | } |
| 5899 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5900 | TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 5901 | base::Version older_version("0.1.0.0"); |
| 5902 | base::Version newer_version("2.0.0.0"); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5903 | |
| 5904 | // We don't want the extension to be installed. A path that doesn't |
| 5905 | // point to a valid CRX ensures this. |
ginkage | 553af320 | 2015-02-04 12:39:09 | [diff] [blame] | 5906 | const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path")); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5907 | |
| 5908 | const int kCreationFlags = 0; |
| 5909 | const bool kDontMarkAcknowledged = false; |
xiyuan | 4d82f7b6 | 2015-03-04 02:29:22 | [diff] [blame] | 5910 | const bool kDontInstallImmediately = false; |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5911 | |
| 5912 | InitializeEmptyExtensionService(); |
| 5913 | |
| 5914 | // The test below uses install source constants to test that |
| 5915 | // priority is enforced. It assumes a specific ranking of install |
| 5916 | // sources: Registry (EXTERNAL_REGISTRY) overrides external pref |
| 5917 | // (EXTERNAL_PREF), and external pref overrides user install (INTERNAL). |
| 5918 | // The following assertions verify these assumptions: |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5919 | ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, |
| 5920 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
| 5921 | Manifest::EXTERNAL_PREF)); |
| 5922 | ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, |
| 5923 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
| 5924 | Manifest::INTERNAL)); |
| 5925 | ASSERT_EQ(Manifest::EXTERNAL_PREF, |
| 5926 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, |
| 5927 | Manifest::INTERNAL)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5928 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 5929 | extensions::PendingExtensionManager* pending = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5930 | service()->pending_extension_manager(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5931 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5932 | |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5933 | ExternalInstallInfoFile info(kGoodId, older_version, kInvalidPathToCrx, |
| 5934 | Manifest::INTERNAL, kCreationFlags, |
| 5935 | kDontMarkAcknowledged, kDontInstallImmediately); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5936 | { |
| 5937 | // Simulate an external source adding the extension as INTERNAL. |
| 5938 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 5939 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5940 | content::NotificationService::AllSources()); |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5941 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5942 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5943 | observer.Wait(); |
| 5944 | VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 5945 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5946 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5947 | { |
| 5948 | // Simulate an external source adding the extension as EXTERNAL_PREF. |
| 5949 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 5950 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5951 | content::NotificationService::AllSources()); |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5952 | info.crx_location = Manifest::EXTERNAL_PREF; |
| 5953 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5954 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5955 | observer.Wait(); |
| 5956 | VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 5957 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5958 | |
| 5959 | // Simulate an external source adding as EXTERNAL_PREF again. |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 5960 | // This is rejected because the version and the location are the same as |
| 5961 | // the previous installation, which is still pending. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5962 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5963 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5964 | |
| 5965 | // Try INTERNAL again. Should fail. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5966 | info.crx_location = Manifest::INTERNAL; |
| 5967 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5968 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5969 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5970 | { |
| 5971 | // Now the registry adds the extension. |
| 5972 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 5973 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5974 | content::NotificationService::AllSources()); |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5975 | info.crx_location = Manifest::EXTERNAL_REGISTRY; |
| 5976 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 5977 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5978 | observer.Wait(); |
| 5979 | VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 5980 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5981 | |
| 5982 | // Registry outranks both external pref and internal, so both fail. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5983 | info.crx_location = Manifest::EXTERNAL_PREF; |
| 5984 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5985 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5986 | |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 5987 | info.crx_location = Manifest::INTERNAL; |
| 5988 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5989 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5990 | |
| 5991 | pending->Remove(kGoodId); |
| 5992 | |
| 5993 | // Install the extension. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 5994 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5995 | const Extension* ext = InstallCRX(path, INSTALL_NEW); |
| 5996 | ValidatePrefKeyCount(1u); |
| 5997 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5998 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5999 | |
| 6000 | // Now test the logic of OnExternalExtensionFileFound() when the extension |
| 6001 | // being added is already installed. |
| 6002 | |
| 6003 | // Tests assume |older_version| is less than the installed version, and |
| 6004 | // |newer_version| is greater. Verify this: |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 6005 | ASSERT_LT(older_version, ext->version()); |
| 6006 | ASSERT_GT(newer_version, ext->version()); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6007 | |
| 6008 | // An external install for the same location should fail if the version is |
| 6009 | // older, or the same, and succeed if the version is newer. |
| 6010 | |
| 6011 | // Older than the installed version... |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6012 | info.version = older_version; |
| 6013 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6014 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6015 | |
| 6016 | // Same version as the installed version... |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame^] | 6017 | info.version = ext->version(); |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6018 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6019 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6020 | |
| 6021 | // Newer than the installed version... |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6022 | info.version = newer_version; |
| 6023 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6024 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6025 | |
| 6026 | // An external install for a higher priority install source should succeed |
| 6027 | // if the version is greater. |older_version| is not... |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6028 | info.version = older_version; |
| 6029 | info.crx_location = Manifest::EXTERNAL_PREF; |
| 6030 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6031 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6032 | |
| 6033 | // |newer_version| is newer. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6034 | info.version = newer_version; |
| 6035 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6036 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6037 | |
| 6038 | // An external install for an even higher priority install source should |
| 6039 | // succeed if the version is greater. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6040 | info.crx_location = Manifest::EXTERNAL_REGISTRY; |
| 6041 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6042 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6043 | |
| 6044 | // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, |
| 6045 | // adding from external pref will now fail. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6046 | info.crx_location = Manifest::EXTERNAL_PREF; |
| 6047 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(info)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6048 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 6049 | } |
| 6050 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6051 | TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 6052 | base::Version kVersion123("1.2.3"); |
| 6053 | base::Version kVersion124("1.2.4"); |
| 6054 | base::Version kVersion125("1.2.5"); |
ginkage | 553af320 | 2015-02-04 12:39:09 | [diff] [blame] | 6055 | const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path")); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6056 | const int kCreationFlags = 0; |
| 6057 | const bool kDontMarkAcknowledged = false; |
xiyuan | 4d82f7b6 | 2015-03-04 02:29:22 | [diff] [blame] | 6058 | const bool kDontInstallImmediately = false; |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6059 | |
| 6060 | InitializeEmptyExtensionService(); |
| 6061 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6062 | extensions::PendingExtensionManager* pending = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6063 | service()->pending_extension_manager(); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6064 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 6065 | |
| 6066 | // An external provider starts installing from a local crx. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6067 | ExternalInstallInfoFile info(kGoodId, kVersion123, kInvalidPathToCrx, |
| 6068 | Manifest::EXTERNAL_PREF, kCreationFlags, |
| 6069 | kDontMarkAcknowledged, kDontInstallImmediately); |
| 6070 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(info)); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 6071 | |
| 6072 | const extensions::PendingExtensionInfo* pending_info; |
| 6073 | EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
| 6074 | EXPECT_TRUE(pending_info->version().IsValid()); |
| 6075 | EXPECT_EQ(pending_info->version(), kVersion123); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6076 | |
| 6077 | // Adding a newer version overrides the currently pending version. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6078 | info.version = base::Version(kVersion124); |
| 6079 | EXPECT_TRUE(service()->OnExternalExtensionFileFound(info)); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 6080 | EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
| 6081 | EXPECT_TRUE(pending_info->version().IsValid()); |
| 6082 | EXPECT_EQ(pending_info->version(), kVersion124); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6083 | |
| 6084 | // Adding an older version fails. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6085 | info.version = kVersion123; |
| 6086 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(info)); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 6087 | EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
| 6088 | EXPECT_TRUE(pending_info->version().IsValid()); |
| 6089 | EXPECT_EQ(pending_info->version(), kVersion124); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6090 | |
| 6091 | // Adding an older version fails even when coming from a higher-priority |
| 6092 | // location. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6093 | info.crx_location = Manifest::EXTERNAL_REGISTRY; |
| 6094 | EXPECT_FALSE(service()->OnExternalExtensionFileFound(info)); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 6095 | EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
| 6096 | EXPECT_TRUE(pending_info->version().IsValid()); |
| 6097 | EXPECT_EQ(pending_info->version(), kVersion124); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6098 | |
| 6099 | // Adding the latest version from the webstore overrides a specific version. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6100 | GURL kUpdateUrl("http://example.com/update"); |
| 6101 | ExternalInstallInfoUpdateUrl update_info(kGoodId, std::string(), kUpdateUrl, |
| 6102 | Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 6103 | Extension::NO_FLAGS, false); |
| 6104 | EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(update_info, true)); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 6105 | EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
| 6106 | EXPECT_FALSE(pending_info->version().IsValid()); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 6107 | } |
| 6108 | |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6109 | // This makes sure we can package and install CRX files that use whitelisted |
| 6110 | // permissions. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6111 | TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6112 | std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 6113 | base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
[email protected] | a612eb3 | 2014-03-31 22:09:17 | [diff] [blame] | 6114 | extensions::switches::kWhitelistedExtensionID, test_id); |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6115 | |
| 6116 | InitializeEmptyExtensionService(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6117 | base::FilePath path = data_dir().AppendASCII("permissions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6118 | base::FilePath pem_path = path |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6119 | .AppendASCII("whitelist.pem"); |
| 6120 | path = path |
| 6121 | .AppendASCII("whitelist"); |
| 6122 | |
| 6123 | const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); |
| 6124 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6125 | ASSERT_EQ(1u, registry()->enabled_extensions().size()); |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 6126 | EXPECT_EQ(test_id, extension->id()); |
| 6127 | } |
| 6128 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6129 | // Test that when multiple sources try to install an extension, |
| 6130 | // we consistently choose the right one. To make tests easy to read, |
| 6131 | // methods that fake requests to install crx files in several ways |
| 6132 | // are provided. |
| 6133 | class ExtensionSourcePriorityTest : public ExtensionServiceTest { |
| 6134 | public: |
dcheng | 7219181 | 2014-10-28 20:49:56 | [diff] [blame] | 6135 | void SetUp() override { |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6136 | ExtensionServiceTest::SetUp(); |
| 6137 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6138 | // All tests use a single extension. Put the id and path in member vars |
| 6139 | // that all methods can read. |
| 6140 | crx_id_ = kGoodId; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6141 | crx_path_ = data_dir().AppendASCII("good.crx"); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6142 | } |
| 6143 | |
| 6144 | // Fake an external source adding a URL to fetch an extension from. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6145 | bool AddPendingExternalPrefUrl() { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6146 | return service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 6147 | crx_id_, |
| 6148 | std::string(), |
| 6149 | GURL(), |
| 6150 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
| 6151 | Extension::NO_FLAGS, |
| 6152 | false); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | // Fake an external file from external_extensions.json. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6156 | bool AddPendingExternalPrefFileInstall() { |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6157 | ExternalInstallInfoFile info(crx_id_, base::Version("1.0.0.0"), crx_path_, |
| 6158 | Manifest::EXTERNAL_PREF, Extension::NO_FLAGS, |
| 6159 | false, false); |
| 6160 | return service()->OnExternalExtensionFileFound(info); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6161 | } |
| 6162 | |
| 6163 | // Fake a request from sync to install an extension. |
| 6164 | bool AddPendingSyncInstall() { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6165 | return service()->pending_extension_manager()->AddFromSync( |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 6166 | crx_id_, |
| 6167 | GURL(kGoodUpdateURL), |
treib | e960e28 | 2015-09-11 10:38:08 | [diff] [blame] | 6168 | base::Version(), |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 6169 | &IsExtension, |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 6170 | kGoodRemoteInstall); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6171 | } |
| 6172 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6173 | // Fake a policy install. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6174 | bool AddPendingPolicyInstall() { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6175 | // Get path to the CRX with id |kGoodId|. |
Devlin Cronin | 92c52cac | 2017-10-02 21:29:01 | [diff] [blame] | 6176 | ExternalInstallInfoUpdateUrl info(crx_id_, std::string(), GURL(), |
| 6177 | Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 6178 | Extension::NO_FLAGS, false); |
| 6179 | return service()->OnExternalExtensionUpdateUrlFound(info, true); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6180 | } |
| 6181 | |
| 6182 | // Get the install source of a pending extension. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6183 | Manifest::Location GetPendingLocation() { |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6184 | const extensions::PendingExtensionInfo* info; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6185 | EXPECT_TRUE( |
| 6186 | (info = service()->pending_extension_manager()->GetById(crx_id_))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6187 | return info->install_source(); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6188 | } |
| 6189 | |
| 6190 | // Is an extension pending from a sync request? |
| 6191 | bool GetPendingIsFromSync() { |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 6192 | const extensions::PendingExtensionInfo* info; |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6193 | EXPECT_TRUE( |
| 6194 | (info = service()->pending_extension_manager()->GetById(crx_id_))); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 6195 | return info->is_from_sync(); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6196 | } |
| 6197 | |
| 6198 | // Is the CRX id these tests use pending? |
| 6199 | bool IsCrxPending() { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6200 | return service()->pending_extension_manager()->IsIdPending(crx_id_); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | // Is an extension installed? |
| 6204 | bool IsCrxInstalled() { |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6205 | return (service()->GetExtensionById(crx_id_, true) != NULL); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6206 | } |
| 6207 | |
| 6208 | protected: |
| 6209 | // All tests use a single extension. Making the id and path member |
| 6210 | // vars avoids pasing the same argument to every method. |
| 6211 | std::string crx_id_; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 6212 | base::FilePath crx_path_; |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6213 | }; |
| 6214 | |
[email protected] | 3634ebd | 2011-04-20 00:34:12 | [diff] [blame] | 6215 | // Test that a pending request for installation of an external CRX from |
| 6216 | // an update URL overrides a pending request to install the same extension |
| 6217 | // from sync. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6218 | TEST_F(ExtensionSourcePriorityTest, PendingExternalFileOverSync) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6219 | InitializeEmptyExtensionService(); |
| 6220 | |
| 6221 | ASSERT_FALSE(IsCrxInstalled()); |
| 6222 | |
| 6223 | // Install pending extension from sync. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6224 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6225 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6226 | content::NotificationService::AllSources()); |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6227 | EXPECT_TRUE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6228 | ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6229 | EXPECT_TRUE(GetPendingIsFromSync()); |
| 6230 | ASSERT_FALSE(IsCrxInstalled()); |
| 6231 | |
| 6232 | // Install pending as external prefs json would. |
| 6233 | AddPendingExternalPrefFileInstall(); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6234 | ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6235 | ASSERT_FALSE(IsCrxInstalled()); |
| 6236 | |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6237 | // Another request from sync should be ignored. |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6238 | EXPECT_FALSE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6239 | ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6240 | ASSERT_FALSE(IsCrxInstalled()); |
| 6241 | |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6242 | observer.Wait(); |
| 6243 | VerifyCrxInstall(crx_path_, INSTALL_NEW); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6244 | ASSERT_TRUE(IsCrxInstalled()); |
| 6245 | } |
| 6246 | |
| 6247 | // Test that an install of an external CRX from an update overrides |
| 6248 | // an install of the same extension from sync. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6249 | TEST_F(ExtensionSourcePriorityTest, PendingExternalUrlOverSync) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6250 | InitializeEmptyExtensionService(); |
| 6251 | ASSERT_FALSE(IsCrxInstalled()); |
| 6252 | |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6253 | EXPECT_TRUE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6254 | ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6255 | EXPECT_TRUE(GetPendingIsFromSync()); |
| 6256 | ASSERT_FALSE(IsCrxInstalled()); |
| 6257 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 6258 | ASSERT_TRUE(AddPendingExternalPrefUrl()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6259 | ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6260 | EXPECT_FALSE(GetPendingIsFromSync()); |
| 6261 | ASSERT_FALSE(IsCrxInstalled()); |
| 6262 | |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 6263 | EXPECT_FALSE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 6264 | ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6265 | EXPECT_FALSE(GetPendingIsFromSync()); |
| 6266 | ASSERT_FALSE(IsCrxInstalled()); |
| 6267 | } |
| 6268 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6269 | // Test that an external install request stops sync from installing |
| 6270 | // the same extension. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 6271 | TEST_F(ExtensionSourcePriorityTest, InstallExternalBlocksSyncRequest) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6272 | InitializeEmptyExtensionService(); |
| 6273 | ASSERT_FALSE(IsCrxInstalled()); |
| 6274 | |
| 6275 | // External prefs starts an install. |
| 6276 | AddPendingExternalPrefFileInstall(); |
| 6277 | |
| 6278 | // Crx installer was made, but has not yet run. |
| 6279 | ASSERT_FALSE(IsCrxInstalled()); |
| 6280 | |
| 6281 | // Before the CRX installer runs, Sync requests that the same extension |
| 6282 | // be installed. Should fail, because an external source is pending. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6283 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6284 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6285 | content::NotificationService::AllSources()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6286 | ASSERT_FALSE(AddPendingSyncInstall()); |
| 6287 | |
| 6288 | // Wait for the external source to install. |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6289 | observer.Wait(); |
| 6290 | VerifyCrxInstall(crx_path_, INSTALL_NEW); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 6291 | ASSERT_TRUE(IsCrxInstalled()); |
| 6292 | |
| 6293 | // Now that the extension is installed, sync request should fail |
| 6294 | // because the extension is already installed. |
| 6295 | ASSERT_FALSE(AddPendingSyncInstall()); |
| 6296 | } |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6297 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6298 | // Test that installing an external extension displays a GlobalError. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6299 | TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 6300 | FeatureSwitch::ScopedOverride prompt( |
| 6301 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6302 | |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6303 | InitializeEmptyExtensionService(); |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 6304 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6305 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6306 | |
[email protected] | 374ceb6f | 2014-07-02 19:25:34 | [diff] [blame] | 6307 | service()->external_install_manager()->UpdateExternalExtensionAlert(); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6308 | // Should return false, meaning there aren't any extensions that the user |
| 6309 | // needs to know about. |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6310 | EXPECT_FALSE(HasExternalInstallErrors(service())); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6311 | |
| 6312 | // This is a normal extension, installed normally. |
| 6313 | // This should NOT trigger an alert. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6314 | base::FilePath path = data_dir().AppendASCII("good.crx"); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6315 | InstallCRX(path, INSTALL_NEW); |
| 6316 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6317 | service()->CheckForExternalUpdates(); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 6318 | content::RunAllTasksUntilIdle(); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6319 | EXPECT_FALSE(HasExternalInstallErrors(service())); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6320 | |
| 6321 | // A hosted app, installed externally. |
[email protected] | 2c495c4 | 2013-01-04 21:49:54 | [diff] [blame] | 6322 | // This should NOT trigger an alert. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6323 | provider->UpdateOrAddExtension( |
| 6324 | hosted_app, "1.0.0.0", data_dir().AppendASCII("hosted_app.crx")); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6325 | |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6326 | WaitForExternalExtensionInstalled(); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6327 | EXPECT_FALSE(HasExternalInstallErrors(service())); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6328 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6329 | // Another normal extension, but installed externally. |
| 6330 | // This SHOULD trigger an alert. |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6331 | provider->UpdateOrAddExtension( |
| 6332 | page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6333 | |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6334 | WaitForExternalExtensionInstalled(); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6335 | EXPECT_TRUE(HasExternalInstallErrors(service())); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 6336 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6337 | |
| 6338 | // Test that external extensions are initially disabled, and that enabling |
| 6339 | // them clears the prompt. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 6340 | TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 6341 | FeatureSwitch::ScopedOverride prompt( |
| 6342 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6343 | |
| 6344 | InitializeEmptyExtensionService(); |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 6345 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6346 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6347 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6348 | provider->UpdateOrAddExtension( |
| 6349 | page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6350 | WaitForExternalExtensionInstalled(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6351 | |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6352 | EXPECT_TRUE(HasExternalInstallErrors(service())); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6353 | EXPECT_FALSE(service()->IsExtensionEnabled(page_action)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6354 | |
| 6355 | const Extension* extension = |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6356 | registry()->disabled_extensions().GetByID(page_action); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6357 | EXPECT_TRUE(extension); |
| 6358 | EXPECT_EQ(page_action, extension->id()); |
| 6359 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6360 | service()->EnableExtension(page_action); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6361 | EXPECT_FALSE(HasExternalInstallErrors(service())); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6362 | EXPECT_TRUE(service()->IsExtensionEnabled(page_action)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6363 | } |
| 6364 | |
mtomasz | 622f70d2 | 2017-01-27 03:36:26 | [diff] [blame] | 6365 | // As for components, only external component extensions can be disabled. |
| 6366 | TEST_F(ExtensionServiceTest, DisablingComponentExtensions) { |
| 6367 | InitializeEmptyExtensionService(); |
| 6368 | service_->Init(); |
| 6369 | |
| 6370 | scoped_refptr<Extension> external_component_extension = CreateExtension( |
| 6371 | base::ASCIIToUTF16("external_component_extension"), |
| 6372 | base::FilePath(FILE_PATH_LITERAL("//external_component_extension")), |
| 6373 | Manifest::EXTERNAL_COMPONENT); |
| 6374 | service_->AddExtension(external_component_extension.get()); |
| 6375 | EXPECT_TRUE(registry()->enabled_extensions().Contains( |
| 6376 | external_component_extension->id())); |
| 6377 | service_->DisableExtension(external_component_extension->id(), |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 6378 | extensions::disable_reason::DISABLE_USER_ACTION); |
mtomasz | 622f70d2 | 2017-01-27 03:36:26 | [diff] [blame] | 6379 | EXPECT_TRUE(registry()->disabled_extensions().Contains( |
| 6380 | external_component_extension->id())); |
| 6381 | |
| 6382 | scoped_refptr<Extension> component_extension = CreateExtension( |
| 6383 | base::ASCIIToUTF16("component_extension"), |
| 6384 | base::FilePath(FILE_PATH_LITERAL("//component_extension")), |
| 6385 | Manifest::COMPONENT); |
| 6386 | service_->AddExtension(component_extension.get()); |
| 6387 | EXPECT_TRUE( |
| 6388 | registry()->enabled_extensions().Contains(component_extension->id())); |
| 6389 | service_->DisableExtension(component_extension->id(), |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 6390 | extensions::disable_reason::DISABLE_USER_ACTION); |
mtomasz | 622f70d2 | 2017-01-27 03:36:26 | [diff] [blame] | 6391 | EXPECT_FALSE( |
| 6392 | registry()->disabled_extensions().Contains(component_extension->id())); |
| 6393 | } |
| 6394 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6395 | // Test that installing multiple external extensions works. |
[email protected] | 404d1a2 | 2013-09-20 17:28:07 | [diff] [blame] | 6396 | // Flaky on windows; http://crbug.com/295757 . |
jyasskin | 3220c32 | 2015-08-10 22:19:06 | [diff] [blame] | 6397 | // Causes race conditions with an in-process utility thread, so disable under |
| 6398 | // TSan: https://crbug.com/518957 |
| 6399 | #if defined(OS_WIN) || defined(THREAD_SANITIZER) |
[email protected] | 404d1a2 | 2013-09-20 17:28:07 | [diff] [blame] | 6400 | #define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple |
| 6401 | #else |
| 6402 | #define MAYBE_ExternalInstallMultiple ExternalInstallMultiple |
| 6403 | #endif |
| 6404 | TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 6405 | FeatureSwitch::ScopedOverride prompt( |
| 6406 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6407 | |
| 6408 | InitializeEmptyExtensionService(); |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 6409 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6410 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6411 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6412 | provider->UpdateOrAddExtension( |
| 6413 | page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx")); |
| 6414 | provider->UpdateOrAddExtension( |
| 6415 | good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx")); |
| 6416 | provider->UpdateOrAddExtension( |
| 6417 | theme_crx, "2.0", data_dir().AppendASCII("theme.crx")); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6418 | |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 6419 | int count = 3; |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6420 | content::WindowedNotificationObserver observer( |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 6421 | extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6422 | base::Bind(&WaitForCountNotificationsCallback, &count)); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6423 | service()->CheckForExternalUpdates(); |
[email protected] | 97d6a5c | 2013-11-11 23:51:24 | [diff] [blame] | 6424 | observer.Wait(); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6425 | EXPECT_TRUE(HasExternalInstallErrors(service())); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6426 | EXPECT_FALSE(service()->IsExtensionEnabled(page_action)); |
| 6427 | EXPECT_FALSE(service()->IsExtensionEnabled(good_crx)); |
| 6428 | EXPECT_FALSE(service()->IsExtensionEnabled(theme_crx)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6429 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6430 | service()->EnableExtension(page_action); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6431 | EXPECT_FALSE(GetError(page_action)); |
| 6432 | EXPECT_TRUE(GetError(good_crx)); |
| 6433 | EXPECT_TRUE(GetError(theme_crx)); |
| 6434 | EXPECT_TRUE(HasExternalInstallErrors(service())); |
| 6435 | EXPECT_FALSE(HasExternalInstallBubble(service())); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6436 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6437 | service()->EnableExtension(theme_crx); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6438 | EXPECT_FALSE(GetError(page_action)); |
| 6439 | EXPECT_FALSE(GetError(theme_crx)); |
| 6440 | EXPECT_TRUE(GetError(good_crx)); |
| 6441 | EXPECT_TRUE(HasExternalInstallErrors(service())); |
| 6442 | EXPECT_FALSE(HasExternalInstallBubble(service())); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6443 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6444 | service()->EnableExtension(good_crx); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6445 | EXPECT_FALSE(GetError(page_action)); |
| 6446 | EXPECT_FALSE(GetError(good_crx)); |
| 6447 | EXPECT_FALSE(GetError(theme_crx)); |
| 6448 | EXPECT_FALSE(HasExternalInstallErrors(service())); |
| 6449 | EXPECT_FALSE(HasExternalInstallBubble(service())); |
| 6450 | } |
| 6451 | |
| 6452 | TEST_F(ExtensionServiceTest, MultipleExternalInstallErrors) { |
| 6453 | FeatureSwitch::ScopedOverride prompt( |
| 6454 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6455 | InitializeEmptyExtensionService(); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6456 | |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 6457 | MockExternalProvider* reg_provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6458 | AddMockExternalProvider(Manifest::EXTERNAL_REGISTRY); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6459 | |
| 6460 | std::string extension_info[][3] = { |
| 6461 | // {id, path, version} |
| 6462 | {good_crx, "1.0.0.0", "good.crx"}, |
| 6463 | {page_action, "1.0.0.0", "page_action.crx"}, |
| 6464 | {minimal_platform_app_crx, "0.1", "minimal_platform_app.crx"}}; |
| 6465 | |
| 6466 | for (size_t i = 0; i < arraysize(extension_info); ++i) { |
| 6467 | reg_provider->UpdateOrAddExtension( |
| 6468 | extension_info[i][0], extension_info[i][1], |
| 6469 | data_dir().AppendASCII(extension_info[i][2])); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6470 | WaitForExternalExtensionInstalled(); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6471 | const size_t expected_error_count = i + 1u; |
| 6472 | EXPECT_EQ( |
| 6473 | expected_error_count, |
| 6474 | service()->external_install_manager()->GetErrorsForTesting().size()); |
| 6475 | EXPECT_FALSE(service()->IsExtensionEnabled(extension_info[i][0])); |
| 6476 | } |
| 6477 | |
| 6478 | std::string extension_ids[] = { |
| 6479 | extension_info[0][0], extension_info[1][0], extension_info[2][0] |
| 6480 | }; |
| 6481 | |
| 6482 | // Each extension should end up in error. |
| 6483 | ASSERT_TRUE(GetError(extension_ids[0])); |
| 6484 | EXPECT_TRUE(GetError(extension_ids[1])); |
| 6485 | EXPECT_TRUE(GetError(extension_ids[2])); |
| 6486 | |
| 6487 | // Accept the first extension, this will remove the error associated with |
| 6488 | // this extension. Also verify the other errors still exist. |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 6489 | GetError(extension_ids[0])->OnInstallPromptDone( |
| 6490 | ExtensionInstallPrompt::Result::ACCEPTED); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6491 | EXPECT_FALSE(GetError(extension_ids[0])); |
| 6492 | ASSERT_TRUE(GetError(extension_ids[1])); |
| 6493 | EXPECT_TRUE(GetError(extension_ids[2])); |
| 6494 | |
| 6495 | // Abort the second extension. |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 6496 | GetError(extension_ids[1])->OnInstallPromptDone( |
| 6497 | ExtensionInstallPrompt::Result::USER_CANCELED); |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6498 | EXPECT_FALSE(GetError(extension_ids[0])); |
| 6499 | EXPECT_FALSE(GetError(extension_ids[1])); |
| 6500 | ASSERT_TRUE(GetError(extension_ids[2])); |
| 6501 | |
| 6502 | // Finally, re-enable the third extension, all errors should be removed. |
| 6503 | service()->EnableExtension(extension_ids[2]); |
| 6504 | EXPECT_FALSE(GetError(extension_ids[0])); |
| 6505 | EXPECT_FALSE(GetError(extension_ids[1])); |
| 6506 | EXPECT_FALSE(GetError(extension_ids[2])); |
| 6507 | |
| 6508 | EXPECT_FALSE(HasExternalInstallErrors(service_)); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6509 | } |
| 6510 | |
Karan Bhatia | e9d5166f | 2017-07-17 22:06:43 | [diff] [blame] | 6511 | // Regression test for crbug.com/739142. Verifies that no UAF occurs when |
| 6512 | // ExternalInstallError needs to be deleted asynchronously. |
| 6513 | TEST_F(ExtensionServiceTest, InstallPromptAborted) { |
| 6514 | FeatureSwitch::ScopedOverride prompt( |
| 6515 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6516 | InitializeEmptyExtensionService(); |
| 6517 | |
| 6518 | MockExternalProvider* reg_provider = |
| 6519 | AddMockExternalProvider(Manifest::EXTERNAL_REGISTRY); |
| 6520 | |
| 6521 | reg_provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 6522 | data_dir().AppendASCII("good.crx")); |
| 6523 | WaitForExternalExtensionInstalled(); |
| 6524 | EXPECT_EQ( |
| 6525 | 1u, service()->external_install_manager()->GetErrorsForTesting().size()); |
| 6526 | EXPECT_FALSE(service()->IsExtensionEnabled(good_crx)); |
| 6527 | EXPECT_TRUE(GetError(good_crx)); |
| 6528 | |
| 6529 | // Abort the extension install prompt. This should cause the |
| 6530 | // ExternalInstallError to be deleted asynchronously. |
| 6531 | GetError(good_crx)->OnInstallPromptDone( |
| 6532 | ExtensionInstallPrompt::Result::ABORTED); |
| 6533 | EXPECT_TRUE(GetError(good_crx)); |
| 6534 | base::RunLoop().RunUntilIdle(); |
| 6535 | EXPECT_FALSE(GetError(good_crx)); |
| 6536 | |
| 6537 | EXPECT_FALSE(HasExternalInstallErrors(service_)); |
| 6538 | } |
| 6539 | |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6540 | TEST_F(ExtensionServiceTest, MultipleExternalInstallBubbleErrors) { |
| 6541 | FeatureSwitch::ScopedOverride prompt( |
| 6542 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6543 | // This sets up the ExtensionPrefs used by our ExtensionService to be |
| 6544 | // post-first run. |
| 6545 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 6546 | params.is_first_run = false; |
| 6547 | InitializeExtensionService(params); |
| 6548 | |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 6549 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6550 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6551 | |
| 6552 | std::vector<BubbleErrorsTestData> data; |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 6553 | data.push_back(BubbleErrorsTestData( |
| 6554 | updates_from_webstore, "1", |
| 6555 | temp_dir().GetPath().AppendASCII("webstore.crx"), 1u)); |
| 6556 | data.push_back(BubbleErrorsTestData( |
| 6557 | updates_from_webstore2, "1", |
| 6558 | temp_dir().GetPath().AppendASCII("webstore2.crx"), 2u)); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6559 | data.push_back(BubbleErrorsTestData(good_crx, "1.0.0.0", |
| 6560 | data_dir().AppendASCII("good.crx"), 2u)); |
| 6561 | |
| 6562 | PackCRX(data_dir().AppendASCII("update_from_webstore"), |
| 6563 | data_dir().AppendASCII("update_from_webstore.pem"), data[0].crx_path); |
| 6564 | PackCRX(data_dir().AppendASCII("update_from_webstore2"), |
| 6565 | data_dir().AppendASCII("update_from_webstore2.pem"), |
| 6566 | data[1].crx_path); |
| 6567 | |
| 6568 | // Install extensions from |data| one by one and expect each of them to result |
| 6569 | // in an error. The first two extensions are from webstore, so they will |
| 6570 | // trigger BUBBLE_ALERT type errors. After each step, we verify that we got |
| 6571 | // the expected number of errors in external_install_manager(). We also verify |
| 6572 | // that only the first BUBBLE_ALERT error is shown. |
| 6573 | for (size_t i = 0; i < data.size(); ++i) { |
| 6574 | content::WindowedNotificationObserver global_error_observer( |
| 6575 | chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
| 6576 | content::NotificationService::AllSources()); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6577 | provider->UpdateOrAddExtension(data[i].id, data[i].version, |
| 6578 | data[i].crx_path); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6579 | WaitForExternalExtensionInstalled(); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6580 | // Make sure ExternalInstallError::OnDialogReady() fires. |
| 6581 | global_error_observer.Wait(); |
| 6582 | |
| 6583 | const size_t expected_error_count = i + 1u; |
| 6584 | std::vector<ExternalInstallError*> errors = |
| 6585 | service_->external_install_manager()->GetErrorsForTesting(); |
| 6586 | EXPECT_EQ(expected_error_count, errors.size()); |
| 6587 | EXPECT_EQ(data[i].expected_bubble_error_count, |
| 6588 | GetExternalInstallBubbleCount(service())); |
| 6589 | EXPECT_TRUE(service() |
| 6590 | ->external_install_manager() |
| 6591 | ->has_currently_visible_install_alert()); |
| 6592 | // Make sure that the first error is only being shown. |
| 6593 | EXPECT_EQ(errors[0], service() |
| 6594 | ->external_install_manager() |
| 6595 | ->currently_visible_install_alert_for_testing()); |
| 6596 | EXPECT_FALSE(service()->IsExtensionEnabled(data[i].id)); |
| 6597 | } |
| 6598 | |
| 6599 | // Cancel all the install prompts. |
| 6600 | for (size_t i = 0; i < data.size(); ++i) { |
| 6601 | const std::string& extension_id = data[i].id; |
| 6602 | EXPECT_TRUE(GetError(extension_id)); |
| 6603 | GetError(extension_id) |
| 6604 | ->OnInstallPromptDone(ExtensionInstallPrompt::Result::USER_CANCELED); |
| 6605 | EXPECT_FALSE(GetError(extension_id)); |
| 6606 | } |
| 6607 | EXPECT_FALSE(service() |
| 6608 | ->external_install_manager() |
| 6609 | ->has_currently_visible_install_alert()); |
| 6610 | EXPECT_EQ(0u, GetExternalInstallBubbleCount(service())); |
| 6611 | EXPECT_FALSE(HasExternalInstallErrors(service())); |
| 6612 | |
| 6613 | // Add a new webstore install. Verify that this shows an error bubble since |
| 6614 | // there are no error bubbles pending at this point. Also verify that the |
| 6615 | // error bubble is for this newly added extension. |
| 6616 | { |
| 6617 | base::FilePath webstore_crx_three = |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 6618 | temp_dir().GetPath().AppendASCII("webstore3.crx"); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6619 | PackCRX(data_dir().AppendASCII("update_from_webstore3"), |
| 6620 | data_dir().AppendASCII("update_from_webstore3.pem"), |
| 6621 | webstore_crx_three); |
| 6622 | |
| 6623 | content::WindowedNotificationObserver global_error_observer( |
| 6624 | chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
| 6625 | content::NotificationService::AllSources()); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6626 | provider->UpdateOrAddExtension( |
| 6627 | updates_from_webstore3, "1", |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 6628 | temp_dir().GetPath().AppendASCII("webstore3.crx")); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6629 | WaitForExternalExtensionInstalled(); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6630 | // Make sure ExternalInstallError::OnDialogReady() fires. |
| 6631 | global_error_observer.Wait(); |
| 6632 | |
| 6633 | std::vector<ExternalInstallError*> errors = |
| 6634 | service_->external_install_manager()->GetErrorsForTesting(); |
| 6635 | EXPECT_EQ(1u, errors.size()); |
| 6636 | EXPECT_EQ(1u, GetExternalInstallBubbleCount(service())); |
| 6637 | EXPECT_TRUE(service() |
| 6638 | ->external_install_manager() |
| 6639 | ->has_currently_visible_install_alert()); |
| 6640 | // Verify that the visible alert is for the current error. |
| 6641 | EXPECT_EQ(errors[0], service() |
| 6642 | ->external_install_manager() |
| 6643 | ->currently_visible_install_alert_for_testing()); |
| 6644 | EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore3)); |
| 6645 | } |
| 6646 | } |
| 6647 | |
| 6648 | // Verifies that an error alert of type BUBBLE_ALERT does not replace an |
| 6649 | // existing visible alert that was previously opened by clicking menu item. |
| 6650 | TEST_F(ExtensionServiceTest, BubbleAlertDoesNotHideAnotherAlertFromMenu) { |
| 6651 | FeatureSwitch::ScopedOverride prompt( |
| 6652 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6653 | // This sets up the ExtensionPrefs used by our ExtensionService to be |
| 6654 | // post-first run. |
| 6655 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 6656 | params.is_first_run = false; |
| 6657 | InitializeExtensionService(params); |
| 6658 | |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 6659 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6660 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6661 | |
| 6662 | std::vector<BubbleErrorsTestData> data; |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 6663 | data.push_back(BubbleErrorsTestData( |
| 6664 | updates_from_webstore, "1", |
| 6665 | temp_dir().GetPath().AppendASCII("webstore.crx"), 1u)); |
| 6666 | data.push_back(BubbleErrorsTestData( |
| 6667 | updates_from_webstore2, "1", |
| 6668 | temp_dir().GetPath().AppendASCII("webstore2.crx"), 2u)); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6669 | |
| 6670 | PackCRX(data_dir().AppendASCII("update_from_webstore"), |
| 6671 | data_dir().AppendASCII("update_from_webstore.pem"), data[0].crx_path); |
| 6672 | PackCRX(data_dir().AppendASCII("update_from_webstore2"), |
| 6673 | data_dir().AppendASCII("update_from_webstore2.pem"), |
| 6674 | data[1].crx_path); |
| 6675 | { |
| 6676 | content::WindowedNotificationObserver global_error_observer( |
| 6677 | chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
| 6678 | content::NotificationService::AllSources()); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6679 | provider->UpdateOrAddExtension(data[0].id, data[0].version, |
| 6680 | data[0].crx_path); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6681 | WaitForExternalExtensionInstalled(); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6682 | // Make sure ExternalInstallError::OnDialogReady() fires. |
| 6683 | global_error_observer.Wait(); |
| 6684 | |
| 6685 | std::vector<ExternalInstallError*> errors = |
| 6686 | service_->external_install_manager()->GetErrorsForTesting(); |
| 6687 | EXPECT_EQ(1u, errors.size()); |
| 6688 | EXPECT_EQ(1u, GetExternalInstallBubbleCount(service())); |
| 6689 | EXPECT_TRUE(service() |
| 6690 | ->external_install_manager() |
| 6691 | ->has_currently_visible_install_alert()); |
| 6692 | // Verify that the visible alert is for the current error. |
| 6693 | EXPECT_EQ(errors[0], service() |
| 6694 | ->external_install_manager() |
| 6695 | ->currently_visible_install_alert_for_testing()); |
| 6696 | } |
| 6697 | |
| 6698 | ExternalInstallError* first_extension_error = GetError(data[0].id); |
| 6699 | |
| 6700 | // Close the bubble alert. |
| 6701 | GlobalError* global_error = |
| 6702 | GlobalErrorServiceFactory::GetForProfile(profile()) |
| 6703 | ->GetHighestSeverityGlobalErrorWithAppMenuItem(); |
| 6704 | first_extension_error->DidCloseBubbleView(); |
| 6705 | |
| 6706 | // Bring the bubble alert error again by clicking its menu item. |
| 6707 | global_error->ExecuteMenuItem(nullptr); |
| 6708 | |
| 6709 | // Install another webstore extension that will trigger an erorr of type |
| 6710 | // BUBBLE_ALERT. |
| 6711 | // Make sure that this bubble alert does not replace the current bubble alert. |
| 6712 | { |
| 6713 | content::WindowedNotificationObserver global_error_observer( |
| 6714 | chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
| 6715 | content::NotificationService::AllSources()); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6716 | provider->UpdateOrAddExtension(data[1].id, data[1].version, |
| 6717 | data[1].crx_path); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6718 | WaitForExternalExtensionInstalled(); |
lazyboy | 1899eec4 | 2016-03-08 19:00:50 | [diff] [blame] | 6719 | // Make sure ExternalInstallError::OnDialogReady() fires. |
| 6720 | global_error_observer.Wait(); |
| 6721 | |
| 6722 | std::vector<ExternalInstallError*> errors = |
| 6723 | service_->external_install_manager()->GetErrorsForTesting(); |
| 6724 | EXPECT_EQ(2u, errors.size()); |
| 6725 | EXPECT_EQ(2u, GetExternalInstallBubbleCount(service())); |
| 6726 | EXPECT_TRUE(service() |
| 6727 | ->external_install_manager() |
| 6728 | ->has_currently_visible_install_alert()); |
| 6729 | // Verify that the old bubble alert was *not* replaced by the new alert. |
| 6730 | EXPECT_EQ(first_extension_error, |
| 6731 | service() |
| 6732 | ->external_install_manager() |
| 6733 | ->currently_visible_install_alert_for_testing()); |
| 6734 | } |
| 6735 | } |
| 6736 | |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6737 | // Test that there is a bubble for external extensions that update |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 6738 | // from the webstore if the profile is not new. |
| 6739 | TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) { |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6740 | FeatureSwitch::ScopedOverride prompt( |
| 6741 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6742 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 6743 | // This sets up the ExtensionPrefs used by our ExtensionService to be |
| 6744 | // post-first run. |
[email protected] | 371662e37 | 2013-10-17 22:05:22 | [diff] [blame] | 6745 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 6746 | params.is_first_run = false; |
| 6747 | InitializeExtensionService(params); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6748 | |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 6749 | base::FilePath crx_path = temp_dir().GetPath().AppendASCII("webstore.crx"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6750 | PackCRX(data_dir().AppendASCII("update_from_webstore"), |
| 6751 | data_dir().AppendASCII("update_from_webstore.pem"), |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6752 | crx_path); |
| 6753 | |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 6754 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6755 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 6756 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6757 | WaitForExternalExtensionInstalled(); |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6758 | |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6759 | EXPECT_TRUE(HasExternalInstallErrors(service())); |
| 6760 | ASSERT_TRUE(GetError(updates_from_webstore)); |
| 6761 | EXPECT_EQ(ExternalInstallError::BUBBLE_ALERT, |
| 6762 | GetError(updates_from_webstore)->alert_type()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6763 | EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 6764 | } |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6765 | |
| 6766 | // Test that there is no bubble for external extensions if the profile is new. |
| 6767 | TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) { |
| 6768 | FeatureSwitch::ScopedOverride prompt( |
| 6769 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6770 | |
| 6771 | InitializeEmptyExtensionService(); |
| 6772 | |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 6773 | base::FilePath crx_path = temp_dir().GetPath().AppendASCII("webstore.crx"); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6774 | PackCRX(data_dir().AppendASCII("update_from_webstore"), |
| 6775 | data_dir().AppendASCII("update_from_webstore.pem"), |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6776 | crx_path); |
| 6777 | |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 6778 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6779 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6780 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6781 | WaitForExternalExtensionInstalled(); |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6782 | |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6783 | EXPECT_TRUE(HasExternalInstallErrors(service())); |
| 6784 | ASSERT_TRUE(GetError(updates_from_webstore)); |
| 6785 | EXPECT_NE(ExternalInstallError::BUBBLE_ALERT, |
| 6786 | GetError(updates_from_webstore)->alert_type()); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6787 | EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore)); |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 6788 | } |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6789 | |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6790 | // Test that clicking to remove the extension on an external install warning |
| 6791 | // uninstalls the extension. |
| 6792 | TEST_F(ExtensionServiceTest, ExternalInstallClickToRemove) { |
| 6793 | FeatureSwitch::ScopedOverride prompt( |
| 6794 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6795 | |
| 6796 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 6797 | params.is_first_run = false; |
| 6798 | InitializeExtensionService(params); |
| 6799 | |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 6800 | base::FilePath crx_path = temp_dir().GetPath().AppendASCII("webstore.crx"); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6801 | PackCRX(data_dir().AppendASCII("update_from_webstore"), |
| 6802 | data_dir().AppendASCII("update_from_webstore.pem"), |
| 6803 | crx_path); |
| 6804 | |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 6805 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6806 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6807 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6808 | WaitForExternalExtensionInstalled(); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6809 | |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6810 | EXPECT_TRUE(HasExternalInstallErrors(service_)); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6811 | |
| 6812 | // We check both enabled and disabled, since these are "eventually exclusive" |
| 6813 | // sets. |
| 6814 | EXPECT_TRUE(registry()->disabled_extensions().GetByID(updates_from_webstore)); |
| 6815 | EXPECT_FALSE(registry()->enabled_extensions().GetByID(updates_from_webstore)); |
| 6816 | |
| 6817 | // Click the negative response. |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6818 | service_->external_install_manager() |
| 6819 | ->GetErrorsForTesting()[0] |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 6820 | ->OnInstallPromptDone(ExtensionInstallPrompt::Result::USER_CANCELED); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6821 | // The Extension should be uninstalled. |
| 6822 | EXPECT_FALSE(registry()->GetExtensionById(updates_from_webstore, |
| 6823 | ExtensionRegistry::EVERYTHING)); |
| 6824 | // The error should be removed. |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6825 | EXPECT_FALSE(HasExternalInstallErrors(service_)); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6826 | } |
| 6827 | |
| 6828 | // Test that clicking to keep the extension on an external install warning |
| 6829 | // re-enables the extension. |
| 6830 | TEST_F(ExtensionServiceTest, ExternalInstallClickToKeep) { |
| 6831 | FeatureSwitch::ScopedOverride prompt( |
| 6832 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6833 | |
| 6834 | ExtensionServiceInitParams params = CreateDefaultInitParams(); |
| 6835 | params.is_first_run = false; |
| 6836 | InitializeExtensionService(params); |
| 6837 | |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 6838 | base::FilePath crx_path = temp_dir().GetPath().AppendASCII("webstore.crx"); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6839 | PackCRX(data_dir().AppendASCII("update_from_webstore"), |
| 6840 | data_dir().AppendASCII("update_from_webstore.pem"), |
| 6841 | crx_path); |
| 6842 | |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 6843 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6844 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6845 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6846 | WaitForExternalExtensionInstalled(); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6847 | |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6848 | EXPECT_TRUE(HasExternalInstallErrors(service_)); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6849 | |
| 6850 | // We check both enabled and disabled, since these are "eventually exclusive" |
| 6851 | // sets. |
| 6852 | EXPECT_TRUE(registry()->disabled_extensions().GetByID(updates_from_webstore)); |
| 6853 | EXPECT_FALSE(registry()->enabled_extensions().GetByID(updates_from_webstore)); |
| 6854 | |
| 6855 | // Accept the extension. |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6856 | service_->external_install_manager() |
| 6857 | ->GetErrorsForTesting()[0] |
rdevlin.cronin | 4159305 | 2016-01-08 01:40:12 | [diff] [blame] | 6858 | ->OnInstallPromptDone(ExtensionInstallPrompt::Result::ACCEPTED); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6859 | |
| 6860 | // It should be enabled again. |
| 6861 | EXPECT_TRUE(registry()->enabled_extensions().GetByID(updates_from_webstore)); |
| 6862 | EXPECT_FALSE( |
| 6863 | registry()->disabled_extensions().GetByID(updates_from_webstore)); |
| 6864 | |
| 6865 | // The error should be removed. |
lazyboy | 0b9b30f | 2016-01-05 03:15:37 | [diff] [blame] | 6866 | EXPECT_FALSE(HasExternalInstallErrors(service_)); |
[email protected] | 2894a51 | 2014-06-26 19:03:56 | [diff] [blame] | 6867 | } |
| 6868 | |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 6869 | // Test that the external install bubble only takes disabled extensions into |
| 6870 | // account - enabled extensions, even those that weren't acknowledged, should |
| 6871 | // not be warned about. This lets us grandfather extensions in. |
| 6872 | TEST_F(ExtensionServiceTest, |
| 6873 | ExternalInstallBubbleDoesntShowForEnabledExtensions) { |
| 6874 | auto external_prompt_override = |
| 6875 | base::MakeUnique<FeatureSwitch::ScopedOverride>( |
| 6876 | FeatureSwitch::prompt_for_external_extensions(), false); |
| 6877 | InitializeEmptyExtensionService(); |
| 6878 | |
| 6879 | // Register and install an external extension. |
lazyboy | a00eafc | 2017-04-08 00:57:19 | [diff] [blame] | 6880 | MockExternalProvider* provider = |
lazyboy | 8a08c9d | 2017-04-11 19:53:22 | [diff] [blame] | 6881 | AddMockExternalProvider(Manifest::EXTERNAL_PREF); |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 6882 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 6883 | data_dir().AppendASCII("good.crx")); |
| 6884 | |
| 6885 | WaitForExternalExtensionInstalled(); |
| 6886 | |
| 6887 | EXPECT_TRUE(registry()->enabled_extensions().Contains(good_crx)); |
| 6888 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 6889 | EXPECT_FALSE(prefs->IsExternalExtensionAcknowledged(good_crx)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 6890 | EXPECT_EQ(extensions::disable_reason::DISABLE_NONE, |
| 6891 | prefs->GetDisableReasons(good_crx)); |
rdevlin.cronin | e145671 | 2016-12-29 22:47:28 | [diff] [blame] | 6892 | |
| 6893 | // We explicitly reset the override first. ScopedOverrides reset the value |
| 6894 | // to the original value on destruction, but if we reset by passing a new |
| 6895 | // object, the new object is constructed (overriding the current value) |
| 6896 | // before the old is destructed (which will immediately reset to the |
| 6897 | // original). |
| 6898 | external_prompt_override.reset(); |
| 6899 | external_prompt_override = base::MakeUnique<FeatureSwitch::ScopedOverride>( |
| 6900 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 6901 | |
| 6902 | extensions::ExternalInstallManager* external_manager = |
| 6903 | service()->external_install_manager(); |
| 6904 | external_manager->UpdateExternalExtensionAlert(); |
| 6905 | EXPECT_FALSE(external_manager->has_currently_visible_install_alert()); |
| 6906 | EXPECT_TRUE(external_manager->GetErrorsForTesting().empty()); |
| 6907 | |
| 6908 | provider->UpdateOrAddExtension(good_crx, "1.0.0.1", |
| 6909 | data_dir().AppendASCII("good2.crx")); |
| 6910 | |
| 6911 | WaitForExternalExtensionInstalled(); |
| 6912 | |
| 6913 | external_manager->UpdateExternalExtensionAlert(); |
| 6914 | EXPECT_FALSE(external_manager->has_currently_visible_install_alert()); |
| 6915 | EXPECT_TRUE(external_manager->GetErrorsForTesting().empty()); |
| 6916 | } |
| 6917 | |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6918 | TEST_F(ExtensionServiceTest, InstallBlacklistedExtension) { |
| 6919 | InitializeEmptyExtensionService(); |
| 6920 | |
Devlin Cronin | 05b047d | 2017-08-22 21:53:55 | [diff] [blame] | 6921 | scoped_refptr<Extension> extension = ExtensionBuilder("extension").Build(); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6922 | ASSERT_TRUE(extension.get()); |
| 6923 | const std::string& id = extension->id(); |
| 6924 | |
| 6925 | std::set<std::string> id_set; |
| 6926 | id_set.insert(id); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6927 | |
limasdf | e1d046f | 2015-10-29 00:48:00 | [diff] [blame] | 6928 | extensions::TestExtensionRegistryObserver observer( |
| 6929 | extensions::ExtensionRegistry::Get(profile())); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6930 | // Installation should be allowed but the extension should never have been |
| 6931 | // loaded and it should be blacklisted in prefs. |
[email protected] | 4a1d9c0d | 2014-06-13 12:50:11 | [diff] [blame] | 6932 | service()->OnExtensionInstalled( |
| 6933 | extension.get(), |
| 6934 | syncer::StringOrdinal(), |
| 6935 | (extensions::kInstallFlagIsBlacklistedForMalware | |
| 6936 | extensions::kInstallFlagInstallImmediately)); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 6937 | content::RunAllTasksUntilIdle(); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6938 | |
| 6939 | // Extension was installed but not loaded. |
limasdf | e1d046f | 2015-10-29 00:48:00 | [diff] [blame] | 6940 | observer.WaitForExtensionWillBeInstalled(); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6941 | EXPECT_TRUE(service()->GetInstalledExtension(id)); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 6942 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6943 | EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 6944 | EXPECT_TRUE(registry()->blacklisted_extensions().Contains(id)); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 6945 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 6946 | EXPECT_TRUE(ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(id)); |
| 6947 | EXPECT_TRUE( |
| 6948 | ExtensionPrefs::Get(profile())->IsBlacklistedExtensionAcknowledged(id)); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 6949 | } |
[email protected] | 59ee99d | 2013-10-11 15:46:16 | [diff] [blame] | 6950 | |
asargent | 96c7ec4 | 2016-05-27 02:45:47 | [diff] [blame] | 6951 | // Test that we won't allow enabling a blacklisted extension. |
| 6952 | TEST_F(ExtensionServiceTest, CannotEnableBlacklistedExtension) { |
| 6953 | InitializeGoodInstalledExtensionService(); |
| 6954 | service()->Init(); |
| 6955 | ASSERT_FALSE(registry()->enabled_extensions().is_empty()); |
| 6956 | |
| 6957 | // Blacklist the first extension; then try enabling it. |
| 6958 | std::string id = (*(registry()->enabled_extensions().begin()))->id(); |
| 6959 | service()->BlacklistExtensionForTest(id); |
| 6960 | EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 6961 | EXPECT_FALSE(registry()->disabled_extensions().Contains(id)); |
| 6962 | service()->EnableExtension(id); |
| 6963 | EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 6964 | EXPECT_FALSE(registry()->disabled_extensions().Contains(id)); |
| 6965 | EXPECT_TRUE(registry()->blacklisted_extensions().Contains(id)); |
| 6966 | EXPECT_TRUE(ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(id)); |
| 6967 | |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 6968 | service()->DisableExtension(id, |
| 6969 | extensions::disable_reason::DISABLE_USER_ACTION); |
asargent | 96c7ec4 | 2016-05-27 02:45:47 | [diff] [blame] | 6970 | EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 6971 | EXPECT_FALSE(registry()->disabled_extensions().Contains(id)); |
| 6972 | EXPECT_TRUE(registry()->blacklisted_extensions().Contains(id)); |
| 6973 | EXPECT_TRUE(ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(id)); |
| 6974 | } |
| 6975 | |
elijahtaylor | 49c09c5c | 2016-07-09 01:06:22 | [diff] [blame] | 6976 | // Test that calls to disable Shared Modules do not work. |
| 6977 | TEST_F(ExtensionServiceTest, CannotDisableSharedModules) { |
| 6978 | InitializeEmptyExtensionService(); |
Devlin Cronin | 05b047d | 2017-08-22 21:53:55 | [diff] [blame] | 6979 | std::unique_ptr<base::DictionaryValue> export_dict = |
elijahtaylor | 49c09c5c | 2016-07-09 01:06:22 | [diff] [blame] | 6980 | extensions::DictionaryBuilder() |
Devlin Cronin | 05b047d | 2017-08-22 21:53:55 | [diff] [blame] | 6981 | .Set("resources", extensions::ListBuilder().Append("foo.js").Build()) |
elijahtaylor | 49c09c5c | 2016-07-09 01:06:22 | [diff] [blame] | 6982 | .Build(); |
| 6983 | |
Devlin Cronin | 05b047d | 2017-08-22 21:53:55 | [diff] [blame] | 6984 | scoped_refptr<Extension> extension = |
| 6985 | ExtensionBuilder("Shared Module") |
| 6986 | .MergeManifest(extensions::DictionaryBuilder() |
| 6987 | .Set("export", std::move(export_dict)) |
| 6988 | .Build()) |
| 6989 | .AddFlags(Extension::FROM_WEBSTORE) |
| 6990 | .Build(); |
elijahtaylor | 49c09c5c | 2016-07-09 01:06:22 | [diff] [blame] | 6991 | |
| 6992 | service()->OnExtensionInstalled(extension.get(), syncer::StringOrdinal(), |
| 6993 | extensions::kInstallFlagInstallImmediately); |
| 6994 | |
| 6995 | ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id())); |
| 6996 | // Try to disable the extension. |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 6997 | service()->DisableExtension(extension->id(), |
| 6998 | extensions::disable_reason::DISABLE_USER_ACTION); |
elijahtaylor | 49c09c5c | 2016-07-09 01:06:22 | [diff] [blame] | 6999 | // Shared Module should still be enabled. |
| 7000 | EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id())); |
| 7001 | } |
| 7002 | |
asargent | 96c7ec4 | 2016-05-27 02:45:47 | [diff] [blame] | 7003 | // Make sure we can uninstall a blacklisted extension |
| 7004 | TEST_F(ExtensionServiceTest, UninstallBlacklistedExtension) { |
| 7005 | InitializeGoodInstalledExtensionService(); |
| 7006 | service()->Init(); |
| 7007 | ASSERT_FALSE(registry()->enabled_extensions().is_empty()); |
| 7008 | |
| 7009 | // Blacklist the first extension; then try uninstalling it. |
| 7010 | std::string id = (*(registry()->enabled_extensions().begin()))->id(); |
| 7011 | service()->BlacklistExtensionForTest(id); |
| 7012 | EXPECT_NE(nullptr, registry()->GetInstalledExtension(id)); |
| 7013 | base::string16 error; |
| 7014 | EXPECT_TRUE(service()->UninstallExtension( |
Devlin Cronin | 218df7f | 2017-11-21 21:41:31 | [diff] [blame] | 7015 | id, extensions::UNINSTALL_REASON_USER_INITIATED, nullptr)); |
asargent | 96c7ec4 | 2016-05-27 02:45:47 | [diff] [blame] | 7016 | EXPECT_EQ(nullptr, registry()->GetInstalledExtension(id)); |
| 7017 | } |
| 7018 | |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 7019 | // Tests a profile being destroyed correctly disables extensions. |
| 7020 | TEST_F(ExtensionServiceTest, DestroyingProfileClearsExtensions) { |
| 7021 | InitializeEmptyExtensionService(); |
| 7022 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7023 | InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 7024 | EXPECT_NE(UnloadedExtensionReason::PROFILE_SHUTDOWN, unloaded_reason_); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7025 | EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 7026 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 7027 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 7028 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 7029 | |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7030 | service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 7031 | content::Source<Profile>(profile()), |
| 7032 | content::NotificationService::NoDetails()); |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 7033 | EXPECT_EQ(UnloadedExtensionReason::PROFILE_SHUTDOWN, unloaded_reason_); |
[email protected] | f484f8d5 | 2014-06-12 08:38:18 | [diff] [blame] | 7034 | EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 7035 | EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 7036 | EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
| 7037 | EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 7038 | } |
asargent | e4de9f9 | 2016-09-15 01:40:06 | [diff] [blame] | 7039 | |
| 7040 | // Test that updating a corrupt extension removes the DISABLE_CORRUPTED disable |
| 7041 | // reason. |
| 7042 | TEST_F(ExtensionServiceTest, CorruptExtensionUpdate) { |
| 7043 | InitializeEmptyExtensionService(); |
| 7044 | |
| 7045 | base::FilePath v1_path = data_dir().AppendASCII("good.crx"); |
| 7046 | const Extension* v1 = InstallCRX(v1_path, INSTALL_NEW); |
| 7047 | std::string id = v1->id(); |
| 7048 | |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 7049 | service()->DisableExtension(id, |
| 7050 | extensions::disable_reason::DISABLE_CORRUPTED); |
asargent | e4de9f9 | 2016-09-15 01:40:06 | [diff] [blame] | 7051 | |
| 7052 | ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 7053 | EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 7054 | EXPECT_TRUE(prefs->HasDisableReason( |
| 7055 | id, extensions::disable_reason::DISABLE_CORRUPTED)); |
asargent | e4de9f9 | 2016-09-15 01:40:06 | [diff] [blame] | 7056 | |
| 7057 | base::FilePath v2_path = data_dir().AppendASCII("good2.crx"); |
| 7058 | UpdateExtension(id, v2_path, ENABLED); |
| 7059 | |
| 7060 | EXPECT_FALSE(registry()->disabled_extensions().Contains(id)); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 7061 | EXPECT_FALSE(prefs->HasDisableReason( |
| 7062 | id, extensions::disable_reason::DISABLE_CORRUPTED)); |
asargent | e4de9f9 | 2016-09-15 01:40:06 | [diff] [blame] | 7063 | } |
rdevlin.cronin | f87d15f | 2017-01-26 22:57:19 | [diff] [blame] | 7064 | |
| 7065 | // Try re-enabling a reloading extension. Regression test for crbug.com/676815. |
| 7066 | TEST_F(ExtensionServiceTest, ReloadAndReEnableExtension) { |
| 7067 | InitializeEmptyExtensionService(); |
| 7068 | |
| 7069 | // Add an extension in an unpacked location. |
| 7070 | scoped_refptr<const Extension> extension = |
| 7071 | extensions::ChromeTestExtensionLoader(profile()). |
| 7072 | LoadExtension(data_dir().AppendASCII("simple_with_file")); |
| 7073 | const std::string kExtensionId = extension->id(); |
| 7074 | ASSERT_TRUE(extension); |
| 7075 | ASSERT_TRUE(extensions::Manifest::IsUnpackedLocation(extension->location())); |
| 7076 | EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); |
| 7077 | |
| 7078 | // Begin the reload process. |
| 7079 | service()->ReloadExtension(extension->id()); |
| 7080 | EXPECT_TRUE(registry()->disabled_extensions().Contains(kExtensionId)); |
| 7081 | |
| 7082 | // While the extension is reloading, try to re-enable it. This is the flow |
| 7083 | // that could happen if, e.g., the user hit the enable toggle in the |
| 7084 | // chrome://extensions page while it was reloading. |
| 7085 | service()->GrantPermissionsAndEnableExtension(extension.get()); |
| 7086 | EXPECT_FALSE(registry()->enabled_extensions().Contains(kExtensionId)); |
| 7087 | |
| 7088 | // Wait for the reload to complete. This previously crashed (see |
| 7089 | // crbug.com/676815). |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 7090 | content::RunAllTasksUntilIdle(); |
rdevlin.cronin | f87d15f | 2017-01-26 22:57:19 | [diff] [blame] | 7091 | // The extension should be enabled again... |
| 7092 | EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); |
| 7093 | // ...and should have reloaded (for ease, we just compare the extension |
| 7094 | // objects). |
| 7095 | EXPECT_NE(extension, registry()->enabled_extensions().GetByID(kExtensionId)); |
| 7096 | } |
rdevlin.cronin | 07f10c1 | 2017-02-08 19:37:58 | [diff] [blame] | 7097 | |
| 7098 | // Test reloading a shared module. Regression test for crbug.com/676815. |
| 7099 | TEST_F(ExtensionServiceTest, ReloadSharedModule) { |
| 7100 | InitializeEmptyExtensionService(); |
| 7101 | |
| 7102 | // Add a shared module and an extension that depends on it (the latter is |
| 7103 | // important to ensure we don't remove the unused shared module). |
| 7104 | scoped_refptr<const Extension> shared_module = |
| 7105 | extensions::ChromeTestExtensionLoader(profile()).LoadExtension( |
| 7106 | data_dir().AppendASCII("api_test/shared_module/shared")); |
| 7107 | scoped_refptr<const Extension> dependent = |
| 7108 | extensions::ChromeTestExtensionLoader(profile()).LoadExtension( |
| 7109 | data_dir().AppendASCII("api_test/shared_module/import_pass")); |
| 7110 | ASSERT_TRUE(shared_module); |
| 7111 | ASSERT_TRUE(dependent); |
| 7112 | const std::string kExtensionId = shared_module->id(); |
| 7113 | ASSERT_TRUE( |
| 7114 | extensions::Manifest::IsUnpackedLocation(shared_module->location())); |
| 7115 | ASSERT_EQ(extensions::Manifest::TYPE_SHARED_MODULE, |
| 7116 | shared_module->manifest()->type()); |
| 7117 | EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); |
| 7118 | |
| 7119 | // Reload the extension and wait for it to complete. This previously crashed |
| 7120 | // (see crbug.com/676815). |
| 7121 | service()->ReloadExtension(kExtensionId); |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 7122 | content::RunAllTasksUntilIdle(); |
rdevlin.cronin | 07f10c1 | 2017-02-08 19:37:58 | [diff] [blame] | 7123 | // The shared module should be enabled. |
| 7124 | EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); |
| 7125 | } |
Takumi Fujimoto | 43c8c00f | 2017-07-26 22:48:56 | [diff] [blame] | 7126 | |
| 7127 | // Tests that extensions that have been migrated to component extensions can be |
| 7128 | // uninstalled. |
| 7129 | TEST_F(ExtensionServiceTest, UninstallMigratedExtensions) { |
| 7130 | InitializeEmptyExtensionService(); |
| 7131 | |
| 7132 | scoped_refptr<const Extension> cast_extension = |
Devlin Cronin | 05b047d | 2017-08-22 21:53:55 | [diff] [blame] | 7133 | ExtensionBuilder("stable") |
| 7134 | .SetID(cast_stable) |
| 7135 | .SetLocation(Manifest::INTERNAL) |
| 7136 | .Build(); |
Takumi Fujimoto | 43c8c00f | 2017-07-26 22:48:56 | [diff] [blame] | 7137 | scoped_refptr<const Extension> cast_beta_extension = |
Devlin Cronin | 05b047d | 2017-08-22 21:53:55 | [diff] [blame] | 7138 | ExtensionBuilder("beta") |
| 7139 | .SetID(cast_beta) |
| 7140 | .SetLocation(Manifest::INTERNAL) |
| 7141 | .Build(); |
Takumi Fujimoto | 43c8c00f | 2017-07-26 22:48:56 | [diff] [blame] | 7142 | service()->AddExtension(cast_extension.get()); |
| 7143 | service()->AddExtension(cast_beta_extension.get()); |
| 7144 | ASSERT_TRUE(registry()->enabled_extensions().Contains(cast_stable)); |
| 7145 | ASSERT_TRUE(registry()->enabled_extensions().Contains(cast_beta)); |
| 7146 | |
| 7147 | service()->UninstallMigratedExtensionsForTest(); |
| 7148 | EXPECT_FALSE(service()->GetInstalledExtension(cast_stable)); |
| 7149 | EXPECT_FALSE(service()->GetInstalledExtension(cast_beta)); |
| 7150 | } |
| 7151 | |
| 7152 | // Tests that extensions that have been migrated to component extensions can be |
| 7153 | // uninstalled even when they are disabled. |
| 7154 | TEST_F(ExtensionServiceTest, UninstallDisabledMigratedExtension) { |
| 7155 | InitializeEmptyExtensionService(); |
| 7156 | |
| 7157 | scoped_refptr<const Extension> cast_extension = |
Devlin Cronin | 05b047d | 2017-08-22 21:53:55 | [diff] [blame] | 7158 | ExtensionBuilder("stable") |
| 7159 | .SetID(cast_stable) |
| 7160 | .SetLocation(Manifest::INTERNAL) |
| 7161 | .Build(); |
Takumi Fujimoto | 43c8c00f | 2017-07-26 22:48:56 | [diff] [blame] | 7162 | service()->AddExtension(cast_extension.get()); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 7163 | service()->DisableExtension(cast_stable, |
| 7164 | extensions::disable_reason::DISABLE_USER_ACTION); |
Takumi Fujimoto | 43c8c00f | 2017-07-26 22:48:56 | [diff] [blame] | 7165 | ASSERT_TRUE(registry()->disabled_extensions().Contains(cast_stable)); |
| 7166 | |
| 7167 | service()->UninstallMigratedExtensionsForTest(); |
| 7168 | EXPECT_FALSE(service()->GetInstalledExtension(cast_stable)); |
| 7169 | } |
Tatsuhisa Yamaguchi | 5ed1aece3 | 2017-10-26 10:18:56 | [diff] [blame] | 7170 | |
| 7171 | TEST_F(ExtensionServiceTest, EnableZipUnpackerExtension) { |
| 7172 | InitializeEmptyExtensionService(); |
| 7173 | |
| 7174 | scoped_refptr<const Extension> zip_unpacker_extension = |
| 7175 | ExtensionBuilder("stable") |
| 7176 | .SetID(zip_unpacker) |
| 7177 | .SetLocation(Manifest::EXTERNAL_COMPONENT) |
| 7178 | .Build(); |
| 7179 | service()->AddExtension(zip_unpacker_extension.get()); |
| 7180 | service()->DisableExtension(zip_unpacker, |
| 7181 | extensions::disable_reason::DISABLE_USER_ACTION); |
| 7182 | ASSERT_TRUE(registry()->disabled_extensions().Contains(zip_unpacker)); |
| 7183 | |
| 7184 | service()->EnableZipUnpackerExtensionForTest(); |
| 7185 | #if defined(OS_CHROMEOS) |
| 7186 | ASSERT_TRUE(registry()->enabled_extensions().Contains(zip_unpacker)); |
| 7187 | #else |
| 7188 | ASSERT_TRUE(registry()->disabled_extensions().Contains(zip_unpacker)); |
| 7189 | #endif |
| 7190 | } |
| 7191 | |
| 7192 | TEST_F(ExtensionServiceTest, ShouldNotEnableZipUnpackerExtensionAgainstPolicy) { |
| 7193 | InitializeEmptyExtensionService(); |
| 7194 | |
| 7195 | GetManagementPolicy()->UnregisterAllProviders(); |
| 7196 | extensions::TestManagementPolicyProvider provider_( |
| 7197 | extensions::TestManagementPolicyProvider::MUST_REMAIN_DISABLED); |
| 7198 | GetManagementPolicy()->RegisterProvider(&provider_); |
| 7199 | |
| 7200 | scoped_refptr<const Extension> zip_unpacker_extension = |
| 7201 | ExtensionBuilder("stable") |
| 7202 | .SetID(zip_unpacker) |
| 7203 | .SetLocation(Manifest::EXTERNAL_COMPONENT) |
| 7204 | .Build(); |
| 7205 | service()->AddExtension(zip_unpacker_extension.get()); |
| 7206 | service()->DisableExtension(zip_unpacker, |
| 7207 | extensions::disable_reason::DISABLE_USER_ACTION); |
| 7208 | ASSERT_TRUE(registry()->disabled_extensions().Contains(zip_unpacker)); |
| 7209 | |
| 7210 | service()->EnableZipUnpackerExtensionForTest(); |
| 7211 | ASSERT_FALSE(registry()->enabled_extensions().Contains(zip_unpacker)); |
| 7212 | } |