[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5 | #include "chrome/browser/extensions/extension_service_unittest.h" |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 6 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 8 | #include <set> |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | be5a6db | 2012-11-13 14:39:11 | [diff] [blame] | 11 | #include "base/at_exit.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 12 | #include "base/basictypes.h" |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 13 | #include "base/bind.h" |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 14 | #include "base/command_line.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 15 | #include "base/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 16 | #include "base/files/scoped_temp_dir.h" |
[email protected] | ffbec69 | 2012-02-26 20:26:42 | [diff] [blame] | 17 | #include "base/json/json_file_value_serializer.h" |
[email protected] | 93d49d7 | 2009-10-23 20:00:20 | [diff] [blame] | 18 | #include "base/json/json_reader.h" |
[email protected] | ffbec69 | 2012-02-26 20:26:42 | [diff] [blame] | 19 | #include "base/json/json_string_value_serializer.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 20 | #include "base/memory/scoped_ptr.h" |
[email protected] | 71cb8aa | 2011-12-29 19:14:00 | [diff] [blame] | 21 | #include "base/memory/weak_ptr.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 22 | #include "base/message_loop.h" |
| 23 | #include "base/path_service.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 24 | #include "base/stl_util.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 25 | #include "base/string16.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 26 | #include "base/string_util.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 27 | #include "base/strings/string_number_conversions.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 28 | #include "base/utf_string_conversions.h" |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 29 | #include "base/version.h" |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 30 | #include "chrome/browser/browser_process.h" |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 31 | #include "chrome/browser/extensions/app_sync_data.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 32 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | eb6c7ef | 2011-12-12 23:12:20 | [diff] [blame] | 33 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 34 | #include "chrome/browser/extensions/default_apps.h" |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 35 | #include "chrome/browser/extensions/extension_creator.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 36 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 37 | #include "chrome/browser/extensions/extension_error_ui.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 38 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 1bcf30e | 2012-03-10 01:06:41 | [diff] [blame] | 39 | #include "chrome/browser/extensions/extension_sorting.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 40 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 41 | #include "chrome/browser/extensions/extension_sync_data.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 42 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 43 | #include "chrome/browser/extensions/external_install_ui.h" |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 44 | #include "chrome/browser/extensions/external_policy_loader.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 45 | #include "chrome/browser/extensions/external_pref_loader.h" |
| 46 | #include "chrome/browser/extensions/external_provider_impl.h" |
| 47 | #include "chrome/browser/extensions/external_provider_interface.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 48 | #include "chrome/browser/extensions/installed_loader.h" |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 49 | #include "chrome/browser/extensions/management_policy.h" |
[email protected] | f0bfe62 | 2012-06-22 01:01:44 | [diff] [blame] | 50 | #include "chrome/browser/extensions/pack_extension_job.h" |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 51 | #include "chrome/browser/extensions/pending_extension_info.h" |
| 52 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 53 | #include "chrome/browser/extensions/test_extension_system.h" |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 54 | #include "chrome/browser/extensions/test_management_policy.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 55 | #include "chrome/browser/extensions/unpacked_installer.h" |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 56 | #include "chrome/browser/extensions/updater/extension_updater.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 57 | #include "chrome/browser/prefs/browser_prefs.h" |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 58 | #include "chrome/browser/prefs/pref_service_mock_builder.h" |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 59 | #include "chrome/browser/prefs/pref_service_syncable.h" |
[email protected] | f89ee34 | 2011-03-07 09:28:27 | [diff] [blame] | 60 | #include "chrome/browser/prefs/scoped_user_pref_update.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 61 | #include "chrome/common/chrome_constants.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 62 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 63 | #include "chrome/common/chrome_paths.h" |
| 64 | #include "chrome/common/chrome_switches.h" |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 65 | #include "chrome/common/extensions/api/plugins/plugins_handler.h" |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 66 | #include "chrome/common/extensions/background_info.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 67 | #include "chrome/common/extensions/extension.h" |
[email protected] | 6884a80 | 2012-08-07 03:55:22 | [diff] [blame] | 68 | #include "chrome/common/extensions/extension_l10n_util.h" |
[email protected] | a52c0e9 | 2012-03-23 06:02:24 | [diff] [blame] | 69 | #include "chrome/common/extensions/extension_manifest_constants.h" |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 70 | #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 71 | #include "chrome/common/extensions/manifest_url_handler.h" |
[email protected] | bebe1d0 | 2012-08-02 20:17:09 | [diff] [blame] | 72 | #include "chrome/common/extensions/permissions/permission_set.h" |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 73 | #include "chrome/common/pref_names.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 74 | #include "chrome/common/url_constants.h" |
[email protected] | a4ff9eae | 2011-08-01 19:58:16 | [diff] [blame] | 75 | #include "chrome/test/base/testing_profile.h" |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 76 | #include "components/user_prefs/pref_registry_syncable.h" |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 77 | #include "content/public/browser/dom_storage_context.h" |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 78 | #include "content/public/browser/gpu_data_manager.h" |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 79 | #include "content/public/browser/indexed_db_context.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 80 | #include "content/public/browser/notification_registrar.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 81 | #include "content/public/browser/notification_service.h" |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 82 | #include "content/public/browser/plugin_service.h" |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 83 | #include "content/public/browser/storage_partition.h" |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 84 | #include "content/public/common/content_constants.h" |
[email protected] | 7e34315 | 2012-09-20 21:49:53 | [diff] [blame] | 85 | #include "content/public/common/gpu_info.h" |
[email protected] | e97882f | 2012-06-04 02:23:17 | [diff] [blame] | 86 | #include "content/public/test/test_browser_thread.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 87 | #include "extensions/common/constants.h" |
| 88 | #include "extensions/common/extension_resource.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 89 | #include "extensions/common/url_pattern.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 90 | #include "googleurl/src/gurl.h" |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 91 | #include "grit/browser_resources.h" |
[email protected] | 5b9bc35 | 2012-07-18 13:13:34 | [diff] [blame] | 92 | #include "net/cookies/canonical_cookie.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 93 | #include "net/cookies/cookie_monster.h" |
| 94 | #include "net/cookies/cookie_options.h" |
[email protected] | dbbad7a | 2010-08-13 18:18:36 | [diff] [blame] | 95 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 96 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 97 | #include "sync/api/string_ordinal.h" |
[email protected] | 895a1e5 | 2012-05-15 02:50:12 | [diff] [blame] | 98 | #include "sync/api/sync_error_factory.h" |
| 99 | #include "sync/api/sync_error_factory_mock.h" |
[email protected] | 1bcf30e | 2012-03-10 01:06:41 | [diff] [blame] | 100 | #include "sync/protocol/app_specifics.pb.h" |
| 101 | #include "sync/protocol/extension_specifics.pb.h" |
| 102 | #include "sync/protocol/sync.pb.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 103 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | f66c110c | 2008-12-05 20:26:29 | [diff] [blame] | 104 | #include "testing/platform_test.h" |
[email protected] | 391550b | 2013-05-10 04:34:12 | [diff] [blame] | 105 | #include "webkit/base/origin_url_conversions.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 106 | #include "webkit/database/database_tracker.h" |
[email protected] | eb6c7ef | 2011-12-12 23:12:20 | [diff] [blame] | 107 | #include "webkit/plugins/npapi/mock_plugin_list.h" |
[email protected] | c62983a7 | 2011-05-09 06:29:59 | [diff] [blame] | 108 | #include "webkit/quota/quota_manager.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 109 | |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 110 | #if defined(OS_CHROMEOS) |
| 111 | #include "chrome/browser/chromeos/extensions/install_limiter.h" |
[email protected] | e4854dc | 2013-04-24 00:11:51 | [diff] [blame] | 112 | #include "chrome/browser/chromeos/login/user_manager.h" |
| 113 | #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 114 | #include "chrome/browser/chromeos/settings/device_settings_service.h" |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 115 | #endif |
| 116 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 117 | using content::BrowserContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 118 | using content::BrowserThread; |
[email protected] | 35cc399e | 2012-02-23 18:19:28 | [diff] [blame] | 119 | using content::DOMStorageContext; |
| 120 | using content::IndexedDBContext; |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 121 | using content::PluginService; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 122 | using extensions::APIPermission; |
| 123 | using extensions::APIPermissionSet; |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 124 | using extensions::CrxInstaller; |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 125 | using extensions::Extension; |
[email protected] | 6d77749 | 2012-07-11 17:33:43 | [diff] [blame] | 126 | using extensions::ExtensionCreator; |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 127 | using extensions::ExtensionPrefs; |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 128 | using extensions::ExtensionResource; |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 129 | using extensions::ExtensionSystem; |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 130 | using extensions::FeatureSwitch; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 131 | using extensions::Manifest; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 132 | using extensions::PermissionSet; |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 133 | using extensions::TestExtensionSystem; |
[email protected] | e9f541a | 2012-11-19 21:52:31 | [diff] [blame] | 134 | using extensions::URLPatternSet; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 135 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 136 | namespace keys = extension_manifest_keys; |
| 137 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 138 | namespace { |
| 139 | |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 140 | // Extension ids used during testing. |
[email protected] | 5a2721f6 | 2009-06-13 07:08:20 | [diff] [blame] | 141 | const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 142 | const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; |
| 143 | const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 144 | const char* const good1 = "hpiknbiabeeppbpihjehijgoemciehgk"; |
| 145 | const char* const good2 = "bjafgdebaacbbbecmhlhpofkepfkgcpa"; |
| 146 | const char* const good_crx = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 147 | const char* const hosted_app = "kbmnembihfiondgfjekmnmcbddelicoi"; |
[email protected] | d7eaf57 | 2009-07-01 21:57:00 | [diff] [blame] | 148 | const char* const page_action = "obcimlgaoabeegjmmpldobjndiealpln"; |
[email protected] | 5a2721f6 | 2009-06-13 07:08:20 | [diff] [blame] | 149 | const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad"; |
| 150 | const char* const theme2_crx = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 151 | const char* const permissions_crx = "eagpmdpfmaekmmcejjbmjoecnejeiiin"; |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 152 | const char* const unpacked = "cbcdidchbppangcjoddlpdjlenngjldk"; |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 153 | const char* const updates_from_webstore = "akjooamlhcgeopfifcmlggaebeocgokj"; |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 154 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 155 | struct ExtensionsOrder { |
| 156 | bool operator()(const Extension* a, const Extension* b) { |
| 157 | return a->name() < b->name(); |
| 158 | } |
| 159 | }; |
| 160 | |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 161 | static std::vector<string16> GetErrors() { |
| 162 | const std::vector<string16>* errors = |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 163 | ExtensionErrorReporter::GetInstance()->GetErrors(); |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 164 | std::vector<string16> ret_val; |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 165 | |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 166 | for (std::vector<string16>::const_iterator iter = errors->begin(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 167 | iter != errors->end(); ++iter) { |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 168 | std::string utf8_error = UTF16ToUTF8(*iter); |
| 169 | if (utf8_error.find(".svn") == std::string::npos) { |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 170 | ret_val.push_back(*iter); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // The tests rely on the errors being in a certain order, which can vary |
| 175 | // depending on how filesystem iteration works. |
| 176 | std::stable_sort(ret_val.begin(), ret_val.end()); |
| 177 | |
| 178 | return ret_val; |
| 179 | } |
| 180 | |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 181 | static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 182 | int schemes = URLPattern::SCHEME_ALL; |
| 183 | extent->AddPattern(URLPattern(schemes, pattern)); |
| 184 | } |
| 185 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 186 | base::FilePath GetTemporaryFile() { |
| 187 | base::FilePath temp_file; |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 188 | CHECK(file_util::CreateTemporaryFile(&temp_file)); |
| 189 | return temp_file; |
| 190 | } |
| 191 | |
[email protected] | f0397fa | 2008-12-11 17:59:58 | [diff] [blame] | 192 | } // namespace |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 193 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 194 | class MockExtensionProvider : public extensions::ExternalProviderInterface { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 195 | public: |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 196 | MockExtensionProvider( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 197 | VisitorInterface* visitor, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 198 | Manifest::Location location) |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 199 | : location_(location), visitor_(visitor), visit_count_(0) { |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 200 | } |
| 201 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 202 | virtual ~MockExtensionProvider() {} |
| 203 | |
| 204 | void UpdateOrAddExtension(const std::string& id, |
| 205 | const std::string& version, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 206 | const base::FilePath& path) { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 207 | extension_map_[id] = std::make_pair(version, path); |
| 208 | } |
| 209 | |
| 210 | void RemoveExtension(const std::string& id) { |
| 211 | extension_map_.erase(id); |
| 212 | } |
| 213 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 214 | // ExternalProvider implementation: |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 215 | virtual void VisitRegisteredExtension() OVERRIDE { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 216 | visit_count_++; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 217 | for (DataMap::const_iterator i = extension_map_.begin(); |
| 218 | i != extension_map_.end(); ++i) { |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 219 | Version version(i->second.first); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 220 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 221 | visitor_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 222 | i->first, &version, i->second.second, location_, |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 223 | Extension::NO_FLAGS, false); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 224 | } |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 225 | visitor_->OnExternalProviderReady(this); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 226 | } |
| 227 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 228 | virtual bool HasExtension(const std::string& id) const OVERRIDE { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 229 | return extension_map_.find(id) != extension_map_.end(); |
| 230 | } |
| 231 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 232 | virtual bool GetExtensionDetails( |
| 233 | const std::string& id, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 234 | Manifest::Location* location, |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 235 | scoped_ptr<Version>* version) const OVERRIDE { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 236 | DataMap::const_iterator it = extension_map_.find(id); |
| 237 | if (it == extension_map_.end()) |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 238 | return false; |
| 239 | |
| 240 | if (version) |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 241 | version->reset(new Version(it->second.first)); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 242 | |
| 243 | if (location) |
| 244 | *location = location_; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 245 | |
| 246 | return true; |
| 247 | } |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 248 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 249 | virtual bool IsReady() const OVERRIDE { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 250 | return true; |
| 251 | } |
| 252 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 253 | virtual void ServiceShutdown() OVERRIDE { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 254 | } |
| 255 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 256 | int visit_count() const { return visit_count_; } |
| 257 | void set_visit_count(int visit_count) { |
| 258 | visit_count_ = visit_count; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | private: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 262 | typedef std::map< std::string, std::pair<std::string, base::FilePath> > |
| 263 | DataMap; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 264 | DataMap extension_map_; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 265 | Manifest::Location location_; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 266 | VisitorInterface* visitor_; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 267 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 268 | // visit_count_ tracks the number of calls to VisitRegisteredExtension(). |
| 269 | // Mutable because it must be incremented on each call to |
| 270 | // VisitRegisteredExtension(), which must be a const method to inherit |
| 271 | // from the class being mocked. |
| 272 | mutable int visit_count_; |
| 273 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 274 | DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider); |
| 275 | }; |
| 276 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 277 | class MockProviderVisitor |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 278 | : public extensions::ExternalProviderInterface::VisitorInterface { |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 279 | public: |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 280 | // The provider will return |fake_base_path| from |
| 281 | // GetBaseCrxFilePath(). User can test the behavior with |
| 282 | // and without an empty path using this parameter. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 283 | explicit MockProviderVisitor(base::FilePath fake_base_path) |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 284 | : ids_found_(0), |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 285 | fake_base_path_(fake_base_path), |
| 286 | expected_creation_flags_(Extension::NO_FLAGS) { |
| 287 | } |
| 288 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 289 | MockProviderVisitor(base::FilePath fake_base_path, |
| 290 | int expected_creation_flags) |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 291 | : ids_found_(0), |
| 292 | fake_base_path_(fake_base_path), |
| 293 | expected_creation_flags_(expected_creation_flags) { |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 294 | } |
| 295 | |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 296 | int Visit(const std::string& json_data) { |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 297 | // Give the test json file to the provider for parsing. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 298 | provider_.reset(new extensions::ExternalProviderImpl( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 299 | this, |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 300 | new extensions::ExternalTestingLoader(json_data, fake_base_path_), |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 301 | Manifest::EXTERNAL_PREF, |
| 302 | Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 303 | Extension::NO_FLAGS)); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 304 | |
| 305 | // We also parse the file into a dictionary to compare what we get back |
| 306 | // from the provider. |
| 307 | JSONStringValueSerializer serializer(json_data); |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 308 | Value* json_value = serializer.Deserialize(NULL, NULL); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 309 | |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 310 | if (!json_value || !json_value->IsType(Value::TYPE_DICTIONARY)) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 311 | NOTREACHED() << "Unable to deserialize json data"; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 312 | return -1; |
| 313 | } else { |
| 314 | DictionaryValue* external_extensions = |
| 315 | static_cast<DictionaryValue*>(json_value); |
| 316 | prefs_.reset(external_extensions); |
| 317 | } |
| 318 | |
| 319 | // Reset our counter. |
| 320 | ids_found_ = 0; |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 321 | // Ask the provider to look up all extensions and return them. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 322 | provider_->VisitRegisteredExtension(); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 323 | |
| 324 | return ids_found_; |
| 325 | } |
| 326 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 327 | virtual bool OnExternalExtensionFileFound(const std::string& id, |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 328 | const Version* version, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 329 | const base::FilePath& path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 330 | Manifest::Location unused, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 331 | int creation_flags, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 332 | bool mark_acknowledged) OVERRIDE { |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 333 | EXPECT_EQ(expected_creation_flags_, creation_flags); |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 334 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 335 | ++ids_found_; |
| 336 | DictionaryValue* pref; |
| 337 | // This tests is to make sure that the provider only notifies us of the |
| 338 | // values we gave it. So if the id we doesn't exist in our internal |
| 339 | // dictionary then something is wrong. |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 340 | EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
| 341 | << "Got back ID (" << id.c_str() << ") we weren't expecting"; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 342 | |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 343 | EXPECT_TRUE(path.IsAbsolute()); |
| 344 | if (!fake_base_path_.empty()) |
| 345 | EXPECT_TRUE(fake_base_path_.IsParent(path)); |
| 346 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 347 | if (pref) { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 348 | EXPECT_TRUE(provider_->HasExtension(id)); |
| 349 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 350 | // Ask provider if the extension we got back is registered. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 351 | Manifest::Location location = Manifest::INVALID_LOCATION; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 352 | scoped_ptr<Version> v1; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 353 | base::FilePath crx_path; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 354 | |
| 355 | EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1)); |
| 356 | EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); |
| 357 | |
| 358 | scoped_ptr<Version> v2; |
| 359 | EXPECT_TRUE(provider_->GetExtensionDetails(id, &location, &v2)); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 360 | EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); |
| 361 | EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 362 | EXPECT_EQ(Manifest::EXTERNAL_PREF, location); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 363 | |
| 364 | // Remove it so we won't count it ever again. |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 365 | prefs_->Remove(id, NULL); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 366 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 367 | return true; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 368 | } |
| 369 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 370 | virtual bool OnExternalExtensionUpdateUrlFound( |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 371 | const std::string& id, const GURL& update_url, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 372 | Manifest::Location location) OVERRIDE { |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 373 | ++ids_found_; |
| 374 | DictionaryValue* pref; |
| 375 | // This tests is to make sure that the provider only notifies us of the |
| 376 | // values we gave it. So if the id we doesn't exist in our internal |
| 377 | // dictionary then something is wrong. |
| 378 | EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) |
| 379 | << L"Got back ID (" << id.c_str() << ") we weren't expecting"; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 380 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 381 | |
| 382 | if (pref) { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 383 | EXPECT_TRUE(provider_->HasExtension(id)); |
| 384 | |
| 385 | // External extensions with update URLs do not have versions. |
| 386 | scoped_ptr<Version> v1; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 387 | Manifest::Location location1 = Manifest::INVALID_LOCATION; |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 388 | EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 389 | EXPECT_FALSE(v1.get()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 390 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 391 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 392 | // Remove it so we won't count it again. |
| 393 | prefs_->Remove(id, NULL); |
| 394 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 395 | return true; |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 396 | } |
| 397 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 398 | virtual void OnExternalProviderReady( |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 399 | const extensions::ExternalProviderInterface* provider) OVERRIDE { |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 400 | EXPECT_EQ(provider, provider_.get()); |
| 401 | EXPECT_TRUE(provider->IsReady()); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 402 | } |
| 403 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 404 | private: |
| 405 | int ids_found_; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 406 | base::FilePath fake_base_path_; |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 407 | int expected_creation_flags_; |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 408 | scoped_ptr<extensions::ExternalProviderImpl> provider_; |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 409 | scoped_ptr<DictionaryValue> prefs_; |
| 410 | |
| 411 | DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 412 | }; |
| 413 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 414 | ExtensionServiceTestBase::ExtensionServiceInitParams:: |
| 415 | ExtensionServiceInitParams() |
| 416 | : autoupdate_enabled(false), is_first_run(true) { |
| 417 | } |
| 418 | |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 419 | // Our message loop may be used in tests which require it to be an IO loop. |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 420 | ExtensionServiceTestBase::ExtensionServiceTestBase() |
| 421 | : loop_(MessageLoop::TYPE_IO), |
[email protected] | 32e2e9b | 2011-11-18 18:56:45 | [diff] [blame] | 422 | service_(NULL), |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 423 | management_policy_(NULL), |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 424 | expected_extensions_count_(0), |
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 425 | ui_thread_(BrowserThread::UI, &loop_), |
| 426 | db_thread_(BrowserThread::DB, &loop_), |
[email protected] | e1dd562 | 2011-12-20 12:28:58 | [diff] [blame] | 427 | webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), |
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 428 | file_thread_(BrowserThread::FILE, &loop_), |
[email protected] | 31dbf9d | 2011-12-07 01:25:30 | [diff] [blame] | 429 | file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_), |
[email protected] | 90c780ac | 2013-04-16 09:26:28 | [diff] [blame] | 430 | io_thread_(BrowserThread::IO, &loop_) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 431 | base::FilePath test_data_dir; |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 432 | if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { |
| 433 | ADD_FAILURE(); |
| 434 | return; |
| 435 | } |
| 436 | data_dir_ = test_data_dir.AppendASCII("extensions"); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 437 | } |
| 438 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 439 | ExtensionServiceTestBase::~ExtensionServiceTestBase() { |
| 440 | // Drop our reference to ExtensionService and TestingProfile, so that they |
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 441 | // can be destroyed while BrowserThreads and MessageLoop are still around |
| 442 | // (they are used in the destruction process). |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 443 | service_ = NULL; |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 444 | MessageLoop::current()->RunUntilIdle(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 445 | profile_.reset(NULL); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 446 | MessageLoop::current()->RunUntilIdle(); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 447 | } |
| 448 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 449 | void ExtensionServiceTestBase::InitializeExtensionService( |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 450 | const ExtensionServiceTestBase::ExtensionServiceInitParams& params) { |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 451 | TestingProfile::Builder profile_builder; |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 452 | // Create a PrefService that only contains user defined preference values. |
[email protected] | 5b19952 | 2012-12-22 17:24:44 | [diff] [blame] | 453 | PrefServiceMockBuilder builder; |
| 454 | builder.WithUserFilePrefs( |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 455 | params.pref_file, loop_.message_loop_proxy()); |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 456 | scoped_refptr<user_prefs::PrefRegistrySyncable> registry( |
| 457 | new user_prefs::PrefRegistrySyncable); |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 458 | scoped_ptr<PrefServiceSyncable> prefs(builder.CreateSyncable(registry)); |
[email protected] | 5879cef | 2013-03-02 17:02:25 | [diff] [blame] | 459 | chrome::RegisterUserPrefs(registry); |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 460 | profile_builder.SetPrefService(prefs.Pass()); |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 461 | profile_builder.SetPath(params.profile_path); |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 462 | profile_ = profile_builder.Build(); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 463 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 464 | TestExtensionSystem* system = static_cast<TestExtensionSystem*>( |
| 465 | ExtensionSystem::Get(profile_.get())); |
| 466 | if (!params.is_first_run) { |
| 467 | ExtensionPrefs* prefs = system->CreateExtensionPrefs( |
| 468 | CommandLine::ForCurrentProcess(), |
| 469 | params.extensions_install_dir); |
| 470 | prefs->SetAlertSystemFirstRun(); |
| 471 | } |
| 472 | |
| 473 | service_ = system->CreateExtensionService( |
| 474 | CommandLine::ForCurrentProcess(), |
| 475 | params.extensions_install_dir, |
| 476 | params.autoupdate_enabled); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 477 | service_->SetFileTaskRunnerForTesting(loop_.message_loop_proxy()); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 478 | service_->set_extensions_enabled(true); |
| 479 | service_->set_show_extensions_prompts(false); |
[email protected] | fc332ae | 2012-11-14 20:17:33 | [diff] [blame] | 480 | service_->set_install_updates_when_idle_for_test(false); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 481 | |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 482 | management_policy_ = |
| 483 | ExtensionSystem::Get(profile_.get())->management_policy(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 484 | |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 485 | // When we start up, we want to make sure there is no external provider, |
| 486 | // since the ExtensionService on Windows will use the Registry as a default |
| 487 | // provider and if there is something already registered there then it will |
| 488 | // interfere with the tests. Those tests that need an external provider |
| 489 | // will register one specifically. |
| 490 | service_->ClearProvidersForTesting(); |
| 491 | |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 492 | #if defined(OS_CHROMEOS) |
| 493 | extensions::InstallLimiter::Get(profile_.get())->DisableForTest(); |
| 494 | #endif |
| 495 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 496 | expected_extensions_count_ = 0; |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 497 | } |
| 498 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 499 | void ExtensionServiceTestBase::InitializeInstalledExtensionService( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 500 | const base::FilePath& prefs_file, |
| 501 | const base::FilePath& source_install_dir) { |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 502 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 503 | base::FilePath path = temp_dir_.path(); |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 504 | path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
| 505 | file_util::Delete(path, true); |
| 506 | file_util::CreateDirectory(path); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 507 | base::FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences")); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 508 | file_util::CopyFile(prefs_file, temp_prefs); |
| 509 | |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 510 | extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 511 | file_util::Delete(extensions_install_dir_, true); |
| 512 | file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); |
| 513 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 514 | ExtensionServiceInitParams params; |
| 515 | params.profile_path = path; |
| 516 | params.pref_file = temp_prefs; |
| 517 | params.extensions_install_dir = extensions_install_dir_; |
| 518 | InitializeExtensionService(params); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 519 | } |
| 520 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 521 | void ExtensionServiceTestBase::InitializeEmptyExtensionService() { |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 522 | InitializeExtensionServiceHelper(false, true); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 523 | } |
| 524 | |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 525 | void ExtensionServiceTestBase::InitializeExtensionProcessManager() { |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 526 | static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 527 | ExtensionSystem::Get(profile_.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 528 | CreateExtensionProcessManager(); |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 529 | } |
| 530 | |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 531 | void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 532 | InitializeExtensionServiceHelper(true, true); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 533 | service_->updater()->Start(); |
| 534 | } |
| 535 | |
| 536 | void ExtensionServiceTestBase::InitializeExtensionServiceHelper( |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 537 | bool autoupdate_enabled, bool is_first_run) { |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 538 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 539 | base::FilePath path = temp_dir_.path(); |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 540 | path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
| 541 | file_util::Delete(path, true); |
| 542 | file_util::CreateDirectory(path); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 543 | base::FilePath prefs_filename = |
| 544 | path.Append(FILE_PATH_LITERAL("TestPreferences")); |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 545 | extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 546 | file_util::Delete(extensions_install_dir_, true); |
| 547 | file_util::CreateDirectory(extensions_install_dir_); |
| 548 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 549 | ExtensionServiceInitParams params; |
| 550 | params.profile_path = path; |
| 551 | params.pref_file = prefs_filename; |
| 552 | params.extensions_install_dir = extensions_install_dir_; |
| 553 | params.autoupdate_enabled = autoupdate_enabled; |
| 554 | params.is_first_run = is_first_run; |
| 555 | InitializeExtensionService(params); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 556 | } |
| 557 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 558 | void ExtensionServiceTestBase::InitializeRequestContext() { |
| 559 | ASSERT_TRUE(profile_.get()); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 560 | TestingProfile* profile = |
| 561 | static_cast<TestingProfile*>(profile_.get()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 562 | profile->CreateRequestContext(); |
| 563 | } |
| 564 | |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 565 | // static |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 566 | void ExtensionServiceTestBase::SetUpTestCase() { |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 567 | ExtensionErrorReporter::Init(false); // no noisy errors |
| 568 | } |
| 569 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 570 | void ExtensionServiceTestBase::SetUp() { |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 571 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 572 | } |
| 573 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 574 | class ExtensionServiceTest |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 575 | : public ExtensionServiceTestBase, public content::NotificationObserver { |
[email protected] | bf73f0b | 2010-02-10 19:26:59 | [diff] [blame] | 576 | public: |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 577 | ExtensionServiceTest() |
| 578 | : installed_(NULL), |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 579 | was_update_(false), |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 580 | override_external_install_prompt_( |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 581 | FeatureSwitch::prompt_for_external_extensions(), false) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 582 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 583 | content::NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 584 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 585 | content::NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 586 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 587 | content::NotificationService::AllSources()); |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 588 | } |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 589 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 590 | virtual void Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 591 | const content::NotificationSource& source, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 592 | const content::NotificationDetails& details) OVERRIDE { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 593 | switch (type) { |
| 594 | case chrome::NOTIFICATION_EXTENSION_LOADED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 595 | const Extension* extension = |
| 596 | content::Details<const Extension>(details).ptr(); |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 597 | loaded_.push_back(make_scoped_refptr(extension)); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 598 | // The tests rely on the errors being in a certain order, which can vary |
| 599 | // depending on how filesystem iteration works. |
| 600 | std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder()); |
| 601 | break; |
| 602 | } |
| 603 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 604 | case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 605 | const Extension* e = |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 606 | content::Details<extensions::UnloadedExtensionInfo>( |
| 607 | details)->extension; |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 608 | unloaded_id_ = e->id(); |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 609 | extensions::ExtensionList::iterator i = |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 610 | std::find(loaded_.begin(), loaded_.end(), e); |
| 611 | // TODO(erikkay) fix so this can be an assert. Right now the tests |
| 612 | // are manually calling clear() on loaded_, so this isn't doable. |
| 613 | if (i == loaded_.end()) |
| 614 | return; |
| 615 | loaded_.erase(i); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 616 | break; |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 617 | } |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 618 | case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
| 619 | const extensions::InstalledExtensionInfo* installed_info = |
| 620 | content::Details<const extensions::InstalledExtensionInfo>(details) |
| 621 | .ptr(); |
| 622 | installed_ = installed_info->extension; |
| 623 | was_update_ = installed_info->is_update; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 624 | break; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 625 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 626 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 627 | default: |
| 628 | DCHECK(false); |
[email protected] | 3acbd42 | 2008-12-08 18:25:00 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 632 | void AddMockExternalProvider( |
| 633 | extensions::ExternalProviderInterface* provider) { |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 634 | service_->AddProviderForTesting(provider); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 635 | } |
| 636 | |
[email protected] | 9197f3b | 2009-06-02 00:49:27 | [diff] [blame] | 637 | protected: |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 638 | void TestExternalProvider(MockExtensionProvider* provider, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 639 | Manifest::Location location); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 640 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 641 | void PackCRX(const base::FilePath& dir_path, |
| 642 | const base::FilePath& pem_path, |
| 643 | const base::FilePath& crx_path) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 644 | // Use the existing pem key, if provided. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 645 | base::FilePath pem_output_path; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 646 | if (pem_path.value().empty()) { |
| 647 | pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 648 | } else { |
| 649 | ASSERT_TRUE(file_util::PathExists(pem_path)); |
| 650 | } |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 651 | |
| 652 | ASSERT_TRUE(file_util::Delete(crx_path, false)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 653 | |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 654 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 655 | ASSERT_TRUE(creator->Run(dir_path, |
| 656 | crx_path, |
| 657 | pem_path, |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 658 | pem_output_path, |
| 659 | ExtensionCreator::kOverwriteCRX)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 660 | |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 661 | ASSERT_TRUE(file_util::PathExists(crx_path)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 662 | } |
| 663 | |
[email protected] | 53da2c96 | 2011-03-03 17:08:05 | [diff] [blame] | 664 | // Create a CrxInstaller and start installation. To allow the install |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 665 | // to happen, use loop_.RunUntilIdle();. Most tests will not use this |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 666 | // method directly. Instead, use InstallCrx(), which waits for |
[email protected] | 53da2c96 | 2011-03-03 17:08:05 | [diff] [blame] | 667 | // the crx to be installed and does extra error checking. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 668 | void StartCRXInstall(const base::FilePath& crx_path) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 669 | StartCRXInstall(crx_path, Extension::NO_FLAGS); |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 670 | } |
| 671 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 672 | void StartCRXInstall(const base::FilePath& crx_path, int creation_flags) { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 673 | ASSERT_TRUE(file_util::PathExists(crx_path)) |
| 674 | << "Path does not exist: "<< crx_path.value().c_str(); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 675 | scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 676 | installer->set_creation_flags(creation_flags); |
| 677 | if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) { |
| 678 | installer->set_allow_silent_install(true); |
| 679 | } |
[email protected] | 53da2c96 | 2011-03-03 17:08:05 | [diff] [blame] | 680 | installer->InstallCrx(crx_path); |
| 681 | } |
| 682 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 683 | enum InstallState { |
| 684 | INSTALL_FAILED, |
| 685 | INSTALL_UPDATED, |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 686 | INSTALL_NEW, |
| 687 | INSTALL_WITHOUT_LOAD, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 688 | }; |
| 689 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 690 | const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
| 691 | const base::FilePath& pem_path, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 692 | InstallState install_state, |
| 693 | int creation_flags) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 694 | base::FilePath crx_path; |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 695 | base::ScopedTempDir temp_dir; |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 696 | EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 697 | crx_path = temp_dir.path().AppendASCII("temp.crx"); |
| 698 | |
| 699 | PackCRX(dir_path, pem_path, crx_path); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 700 | return InstallCRX(crx_path, install_state, creation_flags); |
| 701 | } |
| 702 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 703 | const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
| 704 | const base::FilePath& pem_path, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 705 | InstallState install_state) { |
| 706 | return PackAndInstallCRX(dir_path, pem_path, install_state, |
| 707 | Extension::NO_FLAGS); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 708 | } |
| 709 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 710 | const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 711 | InstallState install_state) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 712 | return PackAndInstallCRX(dir_path, base::FilePath(), install_state, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 713 | Extension::NO_FLAGS); |
| 714 | } |
| 715 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 716 | const Extension* InstallCRX(const base::FilePath& path, |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 717 | InstallState install_state, |
| 718 | int creation_flags) { |
| 719 | StartCRXInstall(path, creation_flags); |
| 720 | return WaitForCrxInstall(path, install_state); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 721 | } |
| 722 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 723 | // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 724 | // is expected to fail. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 725 | const Extension* InstallCRX(const base::FilePath& path, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 726 | InstallState install_state) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 727 | return InstallCRX(path, install_state, Extension::NO_FLAGS); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 728 | } |
| 729 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 730 | const Extension* InstallCRXFromWebStore(const base::FilePath& path, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 731 | InstallState install_state) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 732 | StartCRXInstall(path, Extension::FROM_WEBSTORE); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 733 | return WaitForCrxInstall(path, install_state); |
| 734 | } |
| 735 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 736 | const Extension* InstallCRXWithLocation(const base::FilePath& crx_path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 737 | Manifest::Location install_location, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 738 | InstallState install_state) { |
| 739 | EXPECT_TRUE(file_util::PathExists(crx_path)) |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 740 | << "Path does not exist: "<< crx_path.value().c_str(); |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 741 | // no client (silent install) |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 742 | scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 743 | installer->set_install_source(install_location); |
| 744 | installer->InstallCrx(crx_path); |
| 745 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 746 | return WaitForCrxInstall(crx_path, install_state); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 747 | } |
| 748 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 749 | // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the |
| 750 | // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 751 | // Returns an Extension pointer if the install succeeded, NULL otherwise. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 752 | const Extension* WaitForCrxInstall(const base::FilePath& path, |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 753 | InstallState install_state) { |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 754 | loop_.RunUntilIdle(); |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 755 | std::vector<string16> errors = GetErrors(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 756 | const Extension* extension = NULL; |
| 757 | if (install_state != INSTALL_FAILED) { |
| 758 | if (install_state == INSTALL_NEW) |
| 759 | ++expected_extensions_count_; |
[email protected] | 902f7cd | 2009-05-22 19:02:19 | [diff] [blame] | 760 | |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 761 | EXPECT_TRUE(installed_) << path.value(); |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 762 | // If and only if INSTALL_UPDATED, it should have the is_update flag. |
| 763 | EXPECT_EQ(install_state == INSTALL_UPDATED, was_update_) |
| 764 | << path.value(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 765 | EXPECT_EQ(0u, errors.size()) << path.value(); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 766 | |
| 767 | if (install_state == INSTALL_WITHOUT_LOAD) { |
| 768 | EXPECT_EQ(0u, loaded_.size()) << path.value(); |
| 769 | } else { |
| 770 | EXPECT_EQ(1u, loaded_.size()) << path.value(); |
| 771 | EXPECT_EQ(expected_extensions_count_, service_->extensions()->size()) << |
| 772 | path.value(); |
| 773 | extension = loaded_[0]; |
| 774 | EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) << |
| 775 | path.value(); |
| 776 | } |
| 777 | |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 778 | for (std::vector<string16>::iterator err = errors.begin(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 779 | err != errors.end(); ++err) { |
[email protected] | 37eeb5a | 2009-02-26 23:36:17 | [diff] [blame] | 780 | LOG(ERROR) << *err; |
| 781 | } |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 782 | } else { |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 783 | EXPECT_FALSE(installed_) << path.value(); |
[email protected] | 86a27407 | 2009-06-11 02:06:45 | [diff] [blame] | 784 | EXPECT_EQ(0u, loaded_.size()) << path.value(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 785 | EXPECT_EQ(1u, errors.size()) << path.value(); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 786 | } |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 787 | |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 788 | installed_ = NULL; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 789 | was_update_ = false; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 790 | loaded_.clear(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 791 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 792 | return extension; |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 793 | } |
| 794 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 795 | enum UpdateState { |
| 796 | FAILED_SILENTLY, |
| 797 | FAILED, |
| 798 | UPDATED, |
| 799 | INSTALLED, |
| 800 | ENABLED |
| 801 | }; |
| 802 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 803 | void BlackListWebGL() { |
| 804 | static const std::string json_blacklist = |
| 805 | "{\n" |
| 806 | " \"name\": \"gpu blacklist\",\n" |
| 807 | " \"version\": \"1.0\",\n" |
| 808 | " \"entries\": [\n" |
| 809 | " {\n" |
| 810 | " \"id\": 1,\n" |
[email protected] | 3d34657 | 2013-03-22 19:59:55 | [diff] [blame] | 811 | " \"features\": [\"webgl\"]\n" |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 812 | " }\n" |
| 813 | " ]\n" |
| 814 | "}"; |
[email protected] | 7e34315 | 2012-09-20 21:49:53 | [diff] [blame] | 815 | content::GPUInfo gpu_info; |
| 816 | content::GpuDataManager::GetInstance()->InitializeForTesting( |
| 817 | json_blacklist, gpu_info); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 818 | } |
| 819 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 820 | void UpdateExtension(const std::string& id, const base::FilePath& in_path, |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 821 | UpdateState expected_state) { |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 822 | ASSERT_TRUE(file_util::PathExists(in_path)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 823 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 824 | // We need to copy this to a temporary location because Update() will delete |
| 825 | // it. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 826 | base::FilePath path = temp_dir_.path(); |
[email protected] | a1295ba2 | 2009-09-02 03:33:39 | [diff] [blame] | 827 | path = path.Append(in_path.BaseName()); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 828 | ASSERT_TRUE(file_util::CopyFile(in_path, path)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 829 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 830 | int previous_enabled_extension_count = |
| 831 | service_->extensions()->size(); |
| 832 | int previous_installed_extension_count = |
| 833 | previous_enabled_extension_count + |
| 834 | service_->disabled_extensions()->size(); |
| 835 | |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 836 | service_->UpdateExtension(id, path, GURL(), NULL); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 837 | loop_.RunUntilIdle(); |
[email protected] | f3113e23 | 2010-06-25 01:36:40 | [diff] [blame] | 838 | |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 839 | std::vector<string16> errors = GetErrors(); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 840 | int error_count = errors.size(); |
| 841 | int enabled_extension_count = |
| 842 | service_->extensions()->size(); |
| 843 | int installed_extension_count = |
| 844 | enabled_extension_count + service_->disabled_extensions()->size(); |
| 845 | |
| 846 | int expected_error_count = (expected_state == FAILED) ? 1 : 0; |
| 847 | EXPECT_EQ(expected_error_count, error_count) << path.value(); |
| 848 | |
| 849 | if (expected_state <= FAILED) { |
| 850 | EXPECT_EQ(previous_enabled_extension_count, |
| 851 | enabled_extension_count); |
| 852 | EXPECT_EQ(previous_installed_extension_count, |
| 853 | installed_extension_count); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 854 | } else { |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 855 | int expected_installed_extension_count = |
| 856 | (expected_state >= INSTALLED) ? 1 : 0; |
| 857 | int expected_enabled_extension_count = |
| 858 | (expected_state >= ENABLED) ? 1 : 0; |
| 859 | EXPECT_EQ(expected_installed_extension_count, |
| 860 | installed_extension_count); |
| 861 | EXPECT_EQ(expected_enabled_extension_count, |
| 862 | enabled_extension_count); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 863 | } |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 864 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 865 | // Update() should the temporary input file. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 866 | EXPECT_FALSE(file_util::PathExists(path)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 867 | } |
| 868 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 869 | void TerminateExtension(const std::string& id) { |
| 870 | const Extension* extension = service_->GetInstalledExtension(id); |
| 871 | if (!extension) { |
| 872 | ADD_FAILURE(); |
| 873 | return; |
| 874 | } |
| 875 | service_->TrackTerminatedExtensionForTest(extension); |
| 876 | } |
| 877 | |
| 878 | size_t GetPrefKeyCount() { |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 879 | const DictionaryValue* dict = |
| 880 | profile_->GetPrefs()->GetDictionary("extensions.settings"); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 881 | if (!dict) { |
| 882 | ADD_FAILURE(); |
| 883 | return 0; |
| 884 | } |
| 885 | return dict->size(); |
| 886 | } |
| 887 | |
| 888 | void UninstallExtension(const std::string& id, bool use_helper) { |
| 889 | // Verify that the extension is installed. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 890 | base::FilePath extension_path = extensions_install_dir_.AppendASCII(id); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 891 | EXPECT_TRUE(file_util::PathExists(extension_path)); |
| 892 | size_t pref_key_count = GetPrefKeyCount(); |
| 893 | EXPECT_GT(pref_key_count, 0u); |
| 894 | ValidateIntegerPref(id, "state", Extension::ENABLED); |
| 895 | |
| 896 | // Uninstall it. |
| 897 | if (use_helper) { |
| 898 | EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service_, id)); |
| 899 | } else { |
| 900 | EXPECT_TRUE(service_->UninstallExtension(id, false, NULL)); |
| 901 | } |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 902 | --expected_extensions_count_; |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 903 | |
| 904 | // We should get an unload notification. |
| 905 | EXPECT_FALSE(unloaded_id_.empty()); |
| 906 | EXPECT_EQ(id, unloaded_id_); |
| 907 | |
| 908 | // Verify uninstalled state. |
| 909 | size_t new_pref_key_count = GetPrefKeyCount(); |
| 910 | if (new_pref_key_count == pref_key_count) { |
| 911 | ValidateIntegerPref(id, "location", |
| 912 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 913 | } else { |
| 914 | EXPECT_EQ(new_pref_key_count, pref_key_count - 1); |
| 915 | } |
| 916 | |
| 917 | // The extension should not be in the service anymore. |
| 918 | EXPECT_FALSE(service_->GetInstalledExtension(id)); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 919 | loop_.RunUntilIdle(); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 920 | |
| 921 | // The directory should be gone. |
| 922 | EXPECT_FALSE(file_util::PathExists(extension_path)); |
| 923 | } |
| 924 | |
| 925 | void ValidatePrefKeyCount(size_t count) { |
| 926 | EXPECT_EQ(count, GetPrefKeyCount()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 927 | } |
| 928 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 929 | void ValidateBooleanPref(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 930 | const std::string& pref_path, |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 931 | bool expected_val) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 932 | std::string msg = " while checking: "; |
| 933 | msg += extension_id; |
| 934 | msg += " "; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 935 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 936 | msg += " == "; |
| 937 | msg += expected_val ? "true" : "false"; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 938 | |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 939 | PrefService* prefs = profile_->GetPrefs(); |
| 940 | const DictionaryValue* dict = |
| 941 | prefs->GetDictionary("extensions.settings"); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 942 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 943 | const DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 944 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 945 | EXPECT_TRUE(pref != NULL) << msg; |
| 946 | bool val; |
[email protected] | 4c91487e | 2009-10-02 04:11:04 | [diff] [blame] | 947 | ASSERT_TRUE(pref->GetBoolean(pref_path, &val)) << msg; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 948 | EXPECT_EQ(expected_val, val) << msg; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | bool IsPrefExist(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 952 | const std::string& pref_path) { |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 953 | const DictionaryValue* dict = |
| 954 | profile_->GetPrefs()->GetDictionary("extensions.settings"); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 955 | if (dict == NULL) return false; |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 956 | const DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 957 | if (!dict->GetDictionary(extension_id, &pref)) { |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 958 | return false; |
| 959 | } |
| 960 | if (pref == NULL) { |
| 961 | return false; |
| 962 | } |
| 963 | bool val; |
| 964 | if (!pref->GetBoolean(pref_path, &val)) { |
| 965 | return false; |
| 966 | } |
| 967 | return true; |
| 968 | } |
| 969 | |
| 970 | void ValidateIntegerPref(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 971 | const std::string& pref_path, |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 972 | int expected_val) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 973 | std::string msg = " while checking: "; |
| 974 | msg += extension_id; |
| 975 | msg += " "; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 976 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 977 | msg += " == "; |
| 978 | msg += base::IntToString(expected_val); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 979 | |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 980 | PrefService* prefs = profile_->GetPrefs(); |
| 981 | const DictionaryValue* dict = |
| 982 | prefs->GetDictionary("extensions.settings"); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 983 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 984 | const DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 985 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 986 | EXPECT_TRUE(pref != NULL) << msg; |
| 987 | int val; |
[email protected] | 4c91487e | 2009-10-02 04:11:04 | [diff] [blame] | 988 | ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 989 | EXPECT_EQ(expected_val, val) << msg; |
| 990 | } |
| 991 | |
| 992 | void ValidateStringPref(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 993 | const std::string& pref_path, |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 994 | const std::string& expected_val) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 995 | std::string msg = " while checking: "; |
| 996 | msg += extension_id; |
| 997 | msg += ".manifest."; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 998 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 999 | msg += " == "; |
| 1000 | msg += expected_val; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1001 | |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 1002 | const DictionaryValue* dict = |
| 1003 | profile_->GetPrefs()->GetDictionary("extensions.settings"); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1004 | ASSERT_TRUE(dict != NULL) << msg; |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 1005 | const DictionaryValue* pref = NULL; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1006 | std::string manifest_path = extension_id + ".manifest"; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1007 | ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1008 | EXPECT_TRUE(pref != NULL) << msg; |
| 1009 | std::string val; |
| 1010 | ASSERT_TRUE(pref->GetString(pref_path, &val)) << msg; |
| 1011 | EXPECT_EQ(expected_val, val) << msg; |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1012 | } |
| 1013 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1014 | void SetPref(const std::string& extension_id, |
| 1015 | const std::string& pref_path, |
| 1016 | Value* value, |
| 1017 | const std::string& msg) { |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 1018 | DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); |
| 1019 | DictionaryValue* dict = update.Get(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1020 | ASSERT_TRUE(dict != NULL) << msg; |
| 1021 | DictionaryValue* pref = NULL; |
| 1022 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
| 1023 | EXPECT_TRUE(pref != NULL) << msg; |
| 1024 | pref->Set(pref_path, value); |
| 1025 | } |
| 1026 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1027 | void SetPrefInteg(const std::string& extension_id, |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1028 | const std::string& pref_path, |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1029 | int value) { |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1030 | std::string msg = " while setting: "; |
| 1031 | msg += extension_id; |
| 1032 | msg += " "; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1033 | msg += pref_path; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1034 | msg += " = "; |
| 1035 | msg += base::IntToString(value); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1036 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1037 | SetPref(extension_id, pref_path, Value::CreateIntegerValue(value), msg); |
| 1038 | } |
| 1039 | |
| 1040 | void SetPrefBool(const std::string& extension_id, |
| 1041 | const std::string& pref_path, |
| 1042 | bool value) { |
| 1043 | std::string msg = " while setting: "; |
| 1044 | msg += extension_id + " " + pref_path; |
| 1045 | msg += " = "; |
| 1046 | msg += (value ? "true" : "false"); |
| 1047 | |
| 1048 | SetPref(extension_id, pref_path, Value::CreateBooleanValue(value), msg); |
| 1049 | } |
| 1050 | |
| 1051 | void ClearPref(const std::string& extension_id, |
| 1052 | const std::string& pref_path) { |
| 1053 | std::string msg = " while clearing: "; |
| 1054 | msg += extension_id + " " + pref_path; |
| 1055 | |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 1056 | DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); |
| 1057 | DictionaryValue* dict = update.Get(); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1058 | ASSERT_TRUE(dict != NULL) << msg; |
| 1059 | DictionaryValue* pref = NULL; |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1060 | ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1061 | EXPECT_TRUE(pref != NULL) << msg; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1062 | pref->Remove(pref_path, NULL); |
| 1063 | } |
| 1064 | |
| 1065 | void SetPrefStringSet(const std::string& extension_id, |
| 1066 | const std::string& pref_path, |
| 1067 | const std::set<std::string>& value) { |
| 1068 | std::string msg = " while setting: "; |
| 1069 | msg += extension_id + " " + pref_path; |
| 1070 | |
| 1071 | ListValue* list_value = new ListValue(); |
| 1072 | for (std::set<std::string>::const_iterator iter = value.begin(); |
| 1073 | iter != value.end(); ++iter) |
| 1074 | list_value->Append(Value::CreateStringValue(*iter)); |
| 1075 | |
| 1076 | SetPref(extension_id, pref_path, list_value, msg); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 1077 | } |
| 1078 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1079 | void InitPluginService() { |
| 1080 | #if defined(ENABLE_PLUGINS) |
| 1081 | PluginService::GetInstance()->Init(); |
| 1082 | #endif |
| 1083 | } |
| 1084 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1085 | protected: |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 1086 | extensions::ExtensionList loaded_; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1087 | std::string unloaded_id_; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1088 | const Extension* installed_; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1089 | bool was_update_; |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 1090 | FeatureSwitch::ScopedOverride override_external_install_prompt_; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1091 | |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1092 | private: |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1093 | content::NotificationRegistrar registrar_; |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 1094 | }; |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1095 | |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1096 | // Receives notifications from a PackExtensionJob, indicating either that |
| 1097 | // packing succeeded or that there was some error. |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 1098 | class PackExtensionTestClient : public extensions::PackExtensionJob::Client { |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1099 | public: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1100 | PackExtensionTestClient(const base::FilePath& expected_crx_path, |
| 1101 | const base::FilePath& expected_private_key_path); |
| 1102 | virtual void OnPackSuccess(const base::FilePath& crx_path, |
| 1103 | const base::FilePath& private_key_path) OVERRIDE; |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1104 | virtual void OnPackFailure(const std::string& error_message, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 1105 | ExtensionCreator::ErrorType type) OVERRIDE; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1106 | |
| 1107 | private: |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1108 | const base::FilePath expected_crx_path_; |
| 1109 | const base::FilePath expected_private_key_path_; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1110 | DISALLOW_COPY_AND_ASSIGN(PackExtensionTestClient); |
| 1111 | }; |
| 1112 | |
| 1113 | PackExtensionTestClient::PackExtensionTestClient( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1114 | const base::FilePath& expected_crx_path, |
| 1115 | const base::FilePath& expected_private_key_path) |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1116 | : expected_crx_path_(expected_crx_path), |
| 1117 | expected_private_key_path_(expected_private_key_path) {} |
| 1118 | |
| 1119 | // If packing succeeded, we make sure that the package names match our |
| 1120 | // expectations. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1121 | void PackExtensionTestClient::OnPackSuccess( |
| 1122 | const base::FilePath& crx_path, |
| 1123 | const base::FilePath& private_key_path) { |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1124 | // We got the notification and processed it; we don't expect any further tasks |
| 1125 | // to be posted to the current thread, so we should stop blocking and continue |
| 1126 | // on with the rest of the test. |
| 1127 | // This call to |Quit()| matches the call to |Run()| in the |
| 1128 | // |PackPunctuatedExtension| test. |
| 1129 | MessageLoop::current()->Quit(); |
| 1130 | EXPECT_EQ(expected_crx_path_.value(), crx_path.value()); |
| 1131 | EXPECT_EQ(expected_private_key_path_.value(), private_key_path.value()); |
| 1132 | ASSERT_TRUE(file_util::PathExists(private_key_path)); |
| 1133 | } |
| 1134 | |
| 1135 | // 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] | 1136 | void PackExtensionTestClient::OnPackFailure(const std::string& error_message, |
| 1137 | ExtensionCreator::ErrorType type) { |
| 1138 | if (type == ExtensionCreator::kCRXExists) |
| 1139 | FAIL() << "Packing should not fail."; |
| 1140 | else |
| 1141 | FAIL() << "Existing CRX should have been overwritten."; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1142 | } |
| 1143 | |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1144 | // Test loading good extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1145 | TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1146 | InitPluginService(); |
[email protected] | 183d4b8 | 2011-11-11 18:50:26 | [diff] [blame] | 1147 | |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1148 | // Initialize the test dir with a good Preferences/extensions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1149 | base::FilePath source_install_dir = data_dir_ |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1150 | .AppendASCII("good") |
| 1151 | .AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1152 | base::FilePath pref_path = source_install_dir |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1153 | .DirName() |
| 1154 | .AppendASCII("Preferences"); |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1155 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1156 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1157 | service_->Init(); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1158 | |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1159 | uint32 expected_num_extensions = 3u; |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1160 | ASSERT_EQ(expected_num_extensions, loaded_.size()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1161 | |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 1162 | EXPECT_EQ(std::string(good0), loaded_[0]->id()); |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 1163 | EXPECT_EQ(std::string("My extension 1"), |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1164 | loaded_[0]->name()); |
[email protected] | e1cec06c | 2008-12-18 01:22:23 | [diff] [blame] | 1165 | EXPECT_EQ(std::string("The first extension that I made."), |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1166 | loaded_[0]->description()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1167 | EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location()); |
[email protected] | 61b41161 | 2009-11-10 23:17:41 | [diff] [blame] | 1168 | EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)); |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1169 | EXPECT_EQ(expected_num_extensions, service_->extensions()->size()); |
[email protected] | eab9b45 | 2009-01-23 20:48:59 | [diff] [blame] | 1170 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1171 | ValidatePrefKeyCount(3); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1172 | ValidateIntegerPref(good0, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1173 | ValidateIntegerPref(good0, "location", Manifest::INTERNAL); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1174 | ValidateIntegerPref(good1, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1175 | ValidateIntegerPref(good1, "location", Manifest::INTERNAL); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1176 | ValidateIntegerPref(good2, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1177 | ValidateIntegerPref(good2, "location", Manifest::INTERNAL); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1178 | |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1179 | URLPatternSet expected_patterns; |
| 1180 | AddPattern(&expected_patterns, "file:///*"); |
| 1181 | AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 1182 | AddPattern(&expected_patterns, "https://*.google.com/*"); |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1183 | const Extension* extension = loaded_[0]; |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 1184 | const extensions::UserScriptList& scripts = |
| 1185 | extensions::ContentScriptsInfo::GetContentScripts(extension); |
[email protected] | e66de89 | 2009-03-20 20:38:43 | [diff] [blame] | 1186 | ASSERT_EQ(2u, scripts.size()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1187 | EXPECT_EQ(expected_patterns, scripts[0].url_patterns()); |
[email protected] | e66de89 | 2009-03-20 20:38:43 | [diff] [blame] | 1188 | EXPECT_EQ(2u, scripts[0].js_scripts().size()); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 1189 | ExtensionResource resource00(extension->id(), |
| 1190 | scripts[0].js_scripts()[0].extension_root(), |
[email protected] | 9194b3f | 2009-10-20 15:27:21 | [diff] [blame] | 1191 | scripts[0].js_scripts()[0].relative_path()); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 1192 | base::FilePath expected_path = |
| 1193 | base::MakeAbsoluteFilePath(extension->path().AppendASCII("script1.js")); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1194 | EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path)); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 1195 | ExtensionResource resource01(extension->id(), |
| 1196 | scripts[0].js_scripts()[1].extension_root(), |
[email protected] | 9194b3f | 2009-10-20 15:27:21 | [diff] [blame] | 1197 | scripts[0].js_scripts()[1].relative_path()); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 1198 | expected_path = |
| 1199 | base::MakeAbsoluteFilePath(extension->path().AppendASCII("script2.js")); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1200 | EXPECT_TRUE(resource01.ComparePathWithDefault(expected_path)); |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1201 | EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(extension)); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1202 | EXPECT_EQ(1u, scripts[1].url_patterns().patterns().size()); |
| 1203 | EXPECT_EQ("http://*.news.com/*", |
| 1204 | scripts[1].url_patterns().begin()->GetAsString()); |
[email protected] | 052c9270 | 2010-06-25 07:25:52 | [diff] [blame] | 1205 | ExtensionResource resource10(extension->id(), |
| 1206 | scripts[1].js_scripts()[0].extension_root(), |
[email protected] | 9194b3f | 2009-10-20 15:27:21 | [diff] [blame] | 1207 | scripts[1].js_scripts()[0].relative_path()); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1208 | expected_path = |
| 1209 | extension->path().AppendASCII("js_files").AppendASCII("script3.js"); |
[email protected] | 1547693 | 2013-04-12 05:17:15 | [diff] [blame] | 1210 | expected_path = base::MakeAbsoluteFilePath(expected_path); |
[email protected] | a14b16b | 2009-10-28 12:41:29 | [diff] [blame] | 1211 | EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path)); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1212 | |
| 1213 | expected_patterns.ClearPatterns(); |
| 1214 | AddPattern(&expected_patterns, "http://*.google.com/*"); |
| 1215 | AddPattern(&expected_patterns, "https://*.google.com/*"); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1216 | EXPECT_EQ(expected_patterns, |
| 1217 | extension->GetActivePermissions()->explicit_hosts()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1218 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1219 | EXPECT_EQ(std::string(good1), loaded_[1]->id()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1220 | EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name()); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 1221 | EXPECT_EQ(std::string(), loaded_[1]->description()); |
[email protected] | 81067e0 | 2009-07-27 15:12:09 | [diff] [blame] | 1222 | EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"), |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 1223 | extensions::BackgroundInfo::GetBackgroundURL(loaded_[1])); |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 1224 | EXPECT_EQ( |
| 1225 | 0u, extensions::ContentScriptsInfo::GetContentScripts(loaded_[1]).size()); |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1226 | |
[email protected] | b8fb303 | 2011-04-29 18:45:56 | [diff] [blame] | 1227 | // We don't parse the plugins section on Chrome OS. |
| 1228 | #if defined(OS_CHROMEOS) |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1229 | EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(loaded_[1])); |
[email protected] | b8fb303 | 2011-04-29 18:45:56 | [diff] [blame] | 1230 | #else |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1231 | ASSERT_TRUE(extensions::PluginInfo::HasPlugins(loaded_[1])); |
| 1232 | const std::vector<extensions::PluginInfo>* plugins = |
| 1233 | extensions::PluginInfo::GetPlugins(loaded_[1]); |
| 1234 | ASSERT_TRUE(plugins); |
| 1235 | ASSERT_EQ(2u, plugins->size()); |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 1236 | EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(), |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1237 | plugins->at(0).path.value()); |
| 1238 | EXPECT_TRUE(plugins->at(0).is_public); |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 1239 | EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(), |
[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1240 | plugins->at(1).path.value()); |
| 1241 | EXPECT_FALSE(plugins->at(1).is_public); |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1242 | #endif |
[email protected] | 18a1235 | 2009-01-31 01:33:28 | [diff] [blame] | 1243 | |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1244 | EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location()); |
[email protected] | b8fb303 | 2011-04-29 18:45:56 | [diff] [blame] | 1245 | |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 1246 | int index = expected_num_extensions - 1; |
| 1247 | EXPECT_EQ(std::string(good2), loaded_[index]->id()); |
| 1248 | EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name()); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 1249 | EXPECT_EQ(std::string(), loaded_[index]->description()); |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 1250 | EXPECT_EQ( |
| 1251 | 0u, |
| 1252 | extensions::ContentScriptsInfo::GetContentScripts(loaded_[index]).size()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1253 | EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location()); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1254 | }; |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1255 | |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1256 | // Test loading bad extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1257 | TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1258 | // Initialize the test dir with a bad Preferences/extensions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1259 | base::FilePath source_install_dir = data_dir_ |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1260 | .AppendASCII("bad") |
| 1261 | .AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1262 | base::FilePath pref_path = source_install_dir |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1263 | .DirName() |
| 1264 | .AppendASCII("Preferences"); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1265 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1266 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1267 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1268 | service_->Init(); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1269 | |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1270 | ASSERT_EQ(4u, GetErrors().size()); |
| 1271 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1272 | |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 1273 | EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[0]), |
[email protected] | d7b36dc | 2009-10-29 21:47:40 | [diff] [blame] | 1274 | std::string("Could not load extension from '*'. ") + |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 1275 | extension_manifest_errors::kManifestUnreadable)) << |
| 1276 | UTF16ToUTF8(GetErrors()[0]); |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1277 | |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 1278 | EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[1]), |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1279 | std::string("Could not load extension from '*'. ") + |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 1280 | extension_manifest_errors::kManifestUnreadable)) << |
| 1281 | UTF16ToUTF8(GetErrors()[1]); |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1282 | |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 1283 | EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[2]), |
[email protected] | 8d6d9ff | 2009-02-20 08:14:39 | [diff] [blame] | 1284 | std::string("Could not load extension from '*'. ") + |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 1285 | extension_manifest_errors::kMissingFile)) << |
| 1286 | UTF16ToUTF8(GetErrors()[2]); |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1287 | |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 1288 | EXPECT_TRUE(MatchPattern(UTF16ToUTF8(GetErrors()[3]), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1289 | std::string("Could not load extension from '*'. ") + |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 1290 | extension_manifest_errors::kManifestUnreadable)) << |
| 1291 | UTF16ToUTF8(GetErrors()[3]); |
[email protected] | 54cb3c9 | 2009-02-17 22:30:21 | [diff] [blame] | 1292 | }; |
| 1293 | |
[email protected] | 2f8757c3 | 2012-06-19 19:17:47 | [diff] [blame] | 1294 | // Test that partially deleted extensions are cleaned up during startup |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1295 | // Test loading bad extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1296 | TEST_F(ExtensionServiceTest, CleanupOnStartup) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1297 | InitPluginService(); |
[email protected] | 183d4b8 | 2011-11-11 18:50:26 | [diff] [blame] | 1298 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1299 | base::FilePath source_install_dir = data_dir_ |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 1300 | .AppendASCII("good") |
| 1301 | .AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1302 | base::FilePath pref_path = source_install_dir |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 1303 | .DirName() |
| 1304 | .AppendASCII("Preferences"); |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1305 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1306 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1307 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 1308 | // Simulate that one of them got partially deleted by clearing its pref. |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 1309 | { |
| 1310 | DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); |
| 1311 | DictionaryValue* dict = update.Get(); |
[email protected] | 2f8757c3 | 2012-06-19 19:17:47 | [diff] [blame] | 1312 | ASSERT_TRUE(dict != NULL); |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 1313 | dict->Remove("behllobkkfkfnphdnhnkndlbkcpglgmj", NULL); |
| 1314 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1315 | |
| 1316 | service_->Init(); |
[email protected] | 1f4728f | 2012-12-05 20:40:05 | [diff] [blame] | 1317 | // Wait for GarbageCollectExtensions task to complete. |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1318 | loop_.RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1319 | |
[email protected] | 9e66a9b | 2013-05-08 05:46:20 | [diff] [blame] | 1320 | file_util::FileEnumerator dirs(extensions_install_dir_, false, |
| 1321 | file_util::FileEnumerator::DIRECTORIES); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1322 | size_t count = 0; |
| 1323 | while (!dirs.Next().empty()) |
| 1324 | count++; |
| 1325 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1326 | // We should have only gotten two extensions now. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1327 | EXPECT_EQ(2u, count); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1328 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1329 | // And extension1 dir should now be toast. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1330 | base::FilePath extension_dir = extensions_install_dir_ |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 1331 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj"); |
| 1332 | ASSERT_FALSE(file_util::PathExists(extension_dir)); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1333 | } |
| 1334 | |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1335 | // Test that GarbageCollectExtensions deletes the right versions of an |
| 1336 | // extension. |
| 1337 | TEST_F(ExtensionServiceTest, GarbageCollectWithPendingUpdates) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1338 | InitPluginService(); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1339 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1340 | base::FilePath source_install_dir = data_dir_ |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1341 | .AppendASCII("pending_updates") |
| 1342 | .AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1343 | base::FilePath pref_path = source_install_dir |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1344 | .DirName() |
| 1345 | .AppendASCII("Preferences"); |
| 1346 | |
| 1347 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1348 | |
| 1349 | // This is the directory that is going to be deleted, so make sure it actually |
| 1350 | // is there before the garbage collection. |
| 1351 | ASSERT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
| 1352 | "hpiknbiabeeppbpihjehijgoemciehgk/3"))); |
| 1353 | |
| 1354 | service_->GarbageCollectExtensions(); |
[email protected] | 1f4728f | 2012-12-05 20:40:05 | [diff] [blame] | 1355 | // Wait for GarbageCollectExtensions task to complete. |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1356 | loop_.RunUntilIdle(); |
| 1357 | |
| 1358 | // Verify that the pending update for the first extension didn't get |
| 1359 | // deleted. |
| 1360 | EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
| 1361 | "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); |
| 1362 | EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
| 1363 | "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); |
| 1364 | EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
| 1365 | "hpiknbiabeeppbpihjehijgoemciehgk/2"))); |
| 1366 | EXPECT_FALSE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
| 1367 | "hpiknbiabeeppbpihjehijgoemciehgk/3"))); |
| 1368 | } |
| 1369 | |
| 1370 | // Test that pending updates are properly handled on startup. |
| 1371 | TEST_F(ExtensionServiceTest, UpdateOnStartup) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1372 | InitPluginService(); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1373 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1374 | base::FilePath source_install_dir = data_dir_ |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1375 | .AppendASCII("pending_updates") |
| 1376 | .AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1377 | base::FilePath pref_path = source_install_dir |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1378 | .DirName() |
| 1379 | .AppendASCII("Preferences"); |
| 1380 | |
| 1381 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1382 | |
| 1383 | // This is the directory that is going to be deleted, so make sure it actually |
| 1384 | // is there before the garbage collection. |
| 1385 | ASSERT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
| 1386 | "hpiknbiabeeppbpihjehijgoemciehgk/3"))); |
| 1387 | |
| 1388 | service_->Init(); |
[email protected] | 1f4728f | 2012-12-05 20:40:05 | [diff] [blame] | 1389 | // Wait for GarbageCollectExtensions task to complete. |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1390 | loop_.RunUntilIdle(); |
| 1391 | |
| 1392 | // Verify that the pending update for the first extension got installed. |
| 1393 | EXPECT_FALSE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
| 1394 | "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0"))); |
| 1395 | EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
| 1396 | "bjafgdebaacbbbecmhlhpofkepfkgcpa/2.0"))); |
| 1397 | EXPECT_TRUE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
| 1398 | "hpiknbiabeeppbpihjehijgoemciehgk/2"))); |
| 1399 | EXPECT_FALSE(file_util::PathExists(extensions_install_dir_.AppendASCII( |
| 1400 | "hpiknbiabeeppbpihjehijgoemciehgk/3"))); |
| 1401 | |
| 1402 | // Make sure update information got deleted. |
| 1403 | ExtensionPrefs* prefs = service_->extension_prefs(); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1404 | EXPECT_FALSE( |
| 1405 | prefs->GetDelayedInstallInfo("bjafgdebaacbbbecmhlhpofkepfkgcpa")); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1406 | } |
| 1407 | |
[email protected] | d7eaf57 | 2009-07-01 21:57:00 | [diff] [blame] | 1408 | // Test installing extensions. This test tries to install few extensions using |
| 1409 | // crx files. If you need to change those crx files, feel free to repackage |
| 1410 | // them, throw away the key used and change the id's above. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1411 | TEST_F(ExtensionServiceTest, InstallExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1412 | InitializeEmptyExtensionService(); |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1413 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1414 | // Extensions not enabled. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1415 | set_extensions_enabled(false); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1416 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1417 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1418 | set_extensions_enabled(true); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1419 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1420 | ValidatePrefKeyCount(0); |
| 1421 | |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 1422 | // A simple extension that should install without error. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1423 | path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1424 | InstallCRX(path, INSTALL_NEW); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1425 | // TODO(erikkay): verify the contents of the installed extension. |
| 1426 | |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1427 | int pref_count = 0; |
| 1428 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1429 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1430 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1431 | |
[email protected] | 902f7cd | 2009-05-22 19:02:19 | [diff] [blame] | 1432 | // An extension with page actions. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1433 | path = data_dir_.AppendASCII("page_action.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1434 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1435 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 1436 | ValidateIntegerPref(page_action, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1437 | ValidateIntegerPref(page_action, "location", Manifest::INTERNAL); |
[email protected] | 902f7cd | 2009-05-22 19:02:19 | [diff] [blame] | 1438 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1439 | // Bad signature. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1440 | path = data_dir_.AppendASCII("bad_signature.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1441 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | d7eaf57 | 2009-07-01 21:57:00 | [diff] [blame] | 1442 | ValidatePrefKeyCount(pref_count); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 1443 | |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1444 | // 0-length extension file. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1445 | path = data_dir_.AppendASCII("not_an_extension.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1446 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1447 | ValidatePrefKeyCount(pref_count); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1448 | |
| 1449 | // Bad magic number. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1450 | path = data_dir_.AppendASCII("bad_magic.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1451 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1452 | ValidatePrefKeyCount(pref_count); |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1453 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 1454 | // Extensions cannot have folders or files that have underscores except in |
[email protected] | 99872e3 | 2009-09-25 22:02:49 | [diff] [blame] | 1455 | // certain whitelisted cases (eg _locales). This is an example of a broader |
| 1456 | // class of validation that we do to the directory structure of the extension. |
| 1457 | // We did not used to handle this correctly for installation. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1458 | path = data_dir_.AppendASCII("bad_underscore.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1459 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 99872e3 | 2009-09-25 22:02:49 | [diff] [blame] | 1460 | ValidatePrefKeyCount(pref_count); |
| 1461 | |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 1462 | // TODO(erikkay): add more tests for many of the failure cases. |
| 1463 | // TODO(erikkay): add tests for upgrade cases. |
| 1464 | } |
| 1465 | |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 1466 | // Tests that flags passed to OnExternalExtensionFileFound() make it to the |
| 1467 | // extension object. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1468 | TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1469 | const char kPrefFromBookmark[] = "from_bookmark"; |
| 1470 | |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 1471 | InitializeEmptyExtensionService(); |
| 1472 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1473 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 1474 | set_extensions_enabled(true); |
| 1475 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1476 | // Register and install an external extension. |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1477 | Version version("1.0.0.0"); |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 1478 | service_->OnExternalExtensionFileFound( |
| 1479 | good_crx, |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1480 | &version, |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 1481 | path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1482 | Manifest::EXTERNAL_PREF, |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 1483 | Extension::FROM_BOOKMARK, |
| 1484 | false /* mark_acknowledged */); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 1485 | loop_.RunUntilIdle(); |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 1486 | |
| 1487 | const Extension* extension = service_->GetExtensionById(good_crx, false); |
| 1488 | ASSERT_TRUE(extension); |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 1489 | ASSERT_TRUE(extension->from_bookmark()); |
| 1490 | ValidateBooleanPref(good_crx, kPrefFromBookmark, true); |
| 1491 | |
| 1492 | // Upgrade to version 2.0, the flag should be preserved. |
| 1493 | path = data_dir_.AppendASCII("good2.crx"); |
| 1494 | UpdateExtension(good_crx, path, ENABLED); |
| 1495 | ValidateBooleanPref(good_crx, kPrefFromBookmark, true); |
| 1496 | extension = service_->GetExtensionById(good_crx, false); |
| 1497 | ASSERT_TRUE(extension); |
| 1498 | ASSERT_TRUE(extension->from_bookmark()); |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 1499 | } |
| 1500 | |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1501 | // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1502 | TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1503 | InitializeEmptyExtensionService(); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1504 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1505 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1506 | set_extensions_enabled(true); |
| 1507 | |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1508 | Version version("1.0.0.0"); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1509 | // Install an external extension. |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1510 | service_->OnExternalExtensionFileFound(good_crx, &version, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1511 | path, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1512 | Extension::NO_FLAGS, false); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 1513 | loop_.RunUntilIdle(); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1514 | ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1515 | |
| 1516 | // Uninstall it and check that its killbit gets set. |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1517 | UninstallExtension(good_crx, false); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1518 | ValidateIntegerPref(good_crx, "location", |
| 1519 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1520 | |
| 1521 | // Try to re-install it externally. This should fail because of the killbit. |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1522 | service_->OnExternalExtensionFileFound(good_crx, &version, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1523 | path, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1524 | Extension::NO_FLAGS, false); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 1525 | loop_.RunUntilIdle(); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1526 | ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1527 | ValidateIntegerPref(good_crx, "location", |
| 1528 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1529 | |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1530 | version = Version("1.0.0.1"); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1531 | // Repeat the same thing with a newer version of the extension. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 1532 | path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1533 | service_->OnExternalExtensionFileFound(good_crx, &version, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1534 | path, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1535 | Extension::NO_FLAGS, false); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 1536 | loop_.RunUntilIdle(); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1537 | ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 1538 | ValidateIntegerPref(good_crx, "location", |
| 1539 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1540 | |
| 1541 | // Try adding the same extension from an external update URL. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1542 | ASSERT_FALSE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1543 | good_crx, |
| 1544 | GURL("http:://fake.update/url"), |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1545 | Manifest::EXTERNAL_PREF_DOWNLOAD)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 1546 | |
| 1547 | ASSERT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 1548 | } |
| 1549 | |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1550 | // Test that uninstalling an external extension does not crash when |
| 1551 | // the extension could not be loaded. |
| 1552 | // This extension shown in preferences file requires an experimental permission. |
| 1553 | // It could not be loaded without such permission. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1554 | TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1555 | base::FilePath source_install_dir = data_dir_ |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1556 | .AppendASCII("good") |
| 1557 | .AppendASCII("Extensions"); |
| 1558 | // The preference contains an external extension |
| 1559 | // that requires 'experimental' permission. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1560 | base::FilePath pref_path = source_install_dir |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1561 | .DirName() |
| 1562 | .AppendASCII("PreferencesExperimental"); |
| 1563 | |
| 1564 | // Aforementioned extension will not be loaded if |
| 1565 | // there is no '--enable-experimental-extension-apis' command line flag. |
| 1566 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 1567 | |
| 1568 | service_->Init(); |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1569 | |
| 1570 | // Check and try to uninstall it. |
| 1571 | // If we don't check whether the extension is loaded before we uninstall it |
| 1572 | // in CheckExternalUninstall, a crash will happen here because we will get or |
| 1573 | // dereference a NULL pointer (extension) inside UninstallExtension. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1574 | MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1575 | service_->OnExternalProviderReady(&provider); |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 1576 | } |
| 1577 | |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1578 | // Test that external extensions with incorrect IDs are not installed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1579 | TEST_F(ExtensionServiceTest, FailOnWrongId) { |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1580 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1581 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1582 | set_extensions_enabled(true); |
| 1583 | |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1584 | Version version("1.0.0.0"); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1585 | |
| 1586 | const std::string wrong_id = all_zero; |
| 1587 | const std::string correct_id = good_crx; |
| 1588 | ASSERT_NE(correct_id, wrong_id); |
| 1589 | |
| 1590 | // Install an external extension with an ID from the external |
| 1591 | // source that is not equal to the ID in the extension manifest. |
| 1592 | service_->OnExternalExtensionFileFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1593 | wrong_id, &version, path, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1594 | Extension::NO_FLAGS, false); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1595 | |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 1596 | loop_.RunUntilIdle(); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1597 | ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); |
| 1598 | |
| 1599 | // Try again with the right ID. Expect success. |
| 1600 | service_->OnExternalExtensionFileFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1601 | correct_id, &version, path, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1602 | Extension::NO_FLAGS, false); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 1603 | loop_.RunUntilIdle(); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1604 | ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1605 | } |
| 1606 | |
| 1607 | // Test that external extensions with incorrect versions are not installed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1608 | TEST_F(ExtensionServiceTest, FailOnWrongVersion) { |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1609 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1610 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1611 | set_extensions_enabled(true); |
| 1612 | |
| 1613 | // Install an external extension with a version from the external |
| 1614 | // source that is not equal to the version in the extension manifest. |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1615 | Version wrong_version("1.2.3.4"); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1616 | service_->OnExternalExtensionFileFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1617 | good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1618 | Extension::NO_FLAGS, false); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1619 | |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 1620 | loop_.RunUntilIdle(); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1621 | ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); |
| 1622 | |
| 1623 | // Try again with the right version. Expect success. |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 1624 | service_->pending_extension_manager()->Remove(good_crx); |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 1625 | Version correct_version("1.0.0.0"); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1626 | service_->OnExternalExtensionFileFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1627 | good_crx, &correct_version, path, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1628 | Extension::NO_FLAGS, false); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 1629 | loop_.RunUntilIdle(); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 1630 | ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1631 | } |
| 1632 | |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1633 | // Install a user script (they get converted automatically to an extension) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1634 | TEST_F(ExtensionServiceTest, InstallUserScript) { |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1635 | // The details of script conversion are tested elsewhere, this just tests |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1636 | // integration with ExtensionService. |
| 1637 | InitializeEmptyExtensionService(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1638 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1639 | base::FilePath path = data_dir_ |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1640 | .AppendASCII("user_script_basic.user.js"); |
| 1641 | |
| 1642 | ASSERT_TRUE(file_util::PathExists(path)); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 1643 | scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1644 | installer->set_allow_silent_install(true); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 1645 | installer->InstallUserScript( |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1646 | path, |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 1647 | GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js")); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1648 | |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 1649 | loop_.RunUntilIdle(); |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 1650 | std::vector<string16> errors = GetErrors(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1651 | EXPECT_TRUE(installed_) << "Nothing was installed."; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1652 | EXPECT_FALSE(was_update_) << path.value(); |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1653 | ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded."; |
| 1654 | EXPECT_EQ(0u, errors.size()) << "There were errors: " |
| 1655 | << JoinString(errors, ','); |
| 1656 | EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false)) << |
| 1657 | path.value(); |
| 1658 | |
| 1659 | installed_ = NULL; |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1660 | was_update_ = false; |
[email protected] | da0aa3b | 2009-12-06 21:41:03 | [diff] [blame] | 1661 | loaded_.clear(); |
| 1662 | ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| 1663 | } |
| 1664 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1665 | // Extensions don't install during shutdown. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1666 | TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1667 | InitializeEmptyExtensionService(); |
| 1668 | |
| 1669 | // Simulate shutdown. |
| 1670 | service_->set_browser_terminating_for_test(true); |
| 1671 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1672 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1673 | scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
| 1674 | installer->set_allow_silent_install(true); |
| 1675 | installer->InstallCrx(path); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 1676 | loop_.RunUntilIdle(); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 1677 | |
| 1678 | EXPECT_FALSE(installed_) << "Extension installed during shutdown."; |
| 1679 | ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown."; |
| 1680 | } |
| 1681 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1682 | // This tests that the granted permissions preferences are correctly set when |
| 1683 | // installing an extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1684 | TEST_F(ExtensionServiceTest, GrantedPermissions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1685 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1686 | base::FilePath path = data_dir_ |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1687 | .AppendASCII("permissions"); |
| 1688 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1689 | base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1690 | path = path.AppendASCII("unknown"); |
| 1691 | |
| 1692 | ASSERT_TRUE(file_util::PathExists(pem_path)); |
| 1693 | ASSERT_TRUE(file_util::PathExists(path)); |
| 1694 | |
| 1695 | ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1696 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1697 | APIPermissionSet expected_api_perms; |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 1698 | URLPatternSet expected_host_perms; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1699 | |
| 1700 | // Make sure there aren't any granted permissions before the |
| 1701 | // extension is installed. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1702 | scoped_refptr<PermissionSet> known_perms( |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1703 | prefs->GetGrantedPermissions(permissions_crx)); |
| 1704 | EXPECT_FALSE(known_perms.get()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1705 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1706 | const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1707 | |
| 1708 | EXPECT_EQ(0u, GetErrors().size()); |
| 1709 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1710 | EXPECT_EQ(permissions_crx, extension->id()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1711 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1712 | // Verify that the valid API permissions have been recognized. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1713 | expected_api_perms.insert(APIPermission::kTab); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1714 | |
| 1715 | AddPattern(&expected_host_perms, "http://*.google.com/*"); |
| 1716 | AddPattern(&expected_host_perms, "https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 1717 | AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1718 | AddPattern(&expected_host_perms, "http://www.example.com/*"); |
| 1719 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1720 | known_perms = prefs->GetGrantedPermissions(extension->id()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1721 | EXPECT_TRUE(known_perms.get()); |
| 1722 | EXPECT_FALSE(known_perms->IsEmpty()); |
| 1723 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1724 | EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1725 | EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1726 | } |
| 1727 | |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1728 | |
| 1729 | #if !defined(OS_CHROMEOS) |
| 1730 | // This tests that the granted permissions preferences are correctly set for |
| 1731 | // default apps. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1732 | TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1733 | InitializeEmptyExtensionService(); |
| 1734 | InitializeRequestContext(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1735 | base::FilePath path = data_dir_ |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1736 | .AppendASCII("permissions"); |
| 1737 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1738 | base::FilePath pem_path = path.AppendASCII("unknown.pem"); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1739 | path = path.AppendASCII("unknown"); |
| 1740 | |
| 1741 | ASSERT_TRUE(file_util::PathExists(pem_path)); |
| 1742 | ASSERT_TRUE(file_util::PathExists(path)); |
| 1743 | |
| 1744 | ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1745 | |
| 1746 | APIPermissionSet expected_api_perms; |
| 1747 | URLPatternSet expected_host_perms; |
| 1748 | |
| 1749 | // Make sure there aren't any granted permissions before the |
| 1750 | // extension is installed. |
| 1751 | scoped_refptr<PermissionSet> known_perms( |
| 1752 | prefs->GetGrantedPermissions(permissions_crx)); |
| 1753 | EXPECT_FALSE(known_perms.get()); |
| 1754 | |
| 1755 | const Extension* extension = PackAndInstallCRX( |
| 1756 | path, pem_path, INSTALL_NEW, Extension::WAS_INSTALLED_BY_DEFAULT); |
| 1757 | |
| 1758 | EXPECT_EQ(0u, GetErrors().size()); |
| 1759 | ASSERT_EQ(1u, service_->extensions()->size()); |
| 1760 | EXPECT_EQ(permissions_crx, extension->id()); |
| 1761 | |
| 1762 | // Verify that the valid API permissions have been recognized. |
| 1763 | expected_api_perms.insert(APIPermission::kTab); |
| 1764 | |
| 1765 | known_perms = prefs->GetGrantedPermissions(extension->id()); |
| 1766 | EXPECT_TRUE(known_perms.get()); |
| 1767 | EXPECT_FALSE(known_perms->IsEmpty()); |
| 1768 | EXPECT_EQ(expected_api_perms, known_perms->apis()); |
| 1769 | EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
| 1770 | } |
| 1771 | #endif |
| 1772 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1773 | #if !defined(OS_CHROMEOS) |
| 1774 | // Tests that the granted permissions full_access bit gets set correctly when |
| 1775 | // an extension contains an NPAPI plugin. Don't run this test on Chrome OS |
| 1776 | // since they don't support plugins. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1777 | TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 1778 | InitPluginService(); |
[email protected] | 183d4b8 | 2011-11-11 18:50:26 | [diff] [blame] | 1779 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1780 | InitializeEmptyExtensionService(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1781 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1782 | base::FilePath path = data_dir_ |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1783 | .AppendASCII("good") |
| 1784 | .AppendASCII("Extensions") |
| 1785 | .AppendASCII(good1) |
| 1786 | .AppendASCII("2"); |
| 1787 | |
| 1788 | ASSERT_TRUE(file_util::PathExists(path)); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1789 | const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1790 | EXPECT_EQ(0u, GetErrors().size()); |
| 1791 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1792 | ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1793 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1794 | scoped_refptr<PermissionSet> permissions( |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1795 | prefs->GetGrantedPermissions(extension->id())); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1796 | EXPECT_FALSE(permissions->IsEmpty()); |
| 1797 | EXPECT_TRUE(permissions->HasEffectiveFullAccess()); |
| 1798 | EXPECT_FALSE(permissions->apis().empty()); |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1799 | EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1800 | |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1801 | // Full access implies full host access too... |
| 1802 | EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1803 | } |
| 1804 | #endif |
| 1805 | |
| 1806 | // Tests that the extension is disabled when permissions are missing from |
| 1807 | // the extension's granted permissions preferences. (This simulates updating |
| 1808 | // the browser to a version which recognizes more permissions). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1809 | TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1810 | InitializeEmptyExtensionService(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1811 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1812 | base::FilePath path = data_dir_ |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1813 | .AppendASCII("permissions") |
| 1814 | .AppendASCII("unknown"); |
| 1815 | |
| 1816 | ASSERT_TRUE(file_util::PathExists(path)); |
| 1817 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1818 | const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1819 | |
| 1820 | EXPECT_EQ(0u, GetErrors().size()); |
| 1821 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1822 | std::string extension_id = extension->id(); |
| 1823 | |
| 1824 | ExtensionPrefs* prefs = service_->extension_prefs(); |
| 1825 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1826 | APIPermissionSet expected_api_permissions; |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 1827 | URLPatternSet expected_host_permissions; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1828 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1829 | expected_api_permissions.insert(APIPermission::kTab); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1830 | AddPattern(&expected_host_permissions, "http://*.google.com/*"); |
| 1831 | AddPattern(&expected_host_permissions, "https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 1832 | AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1833 | AddPattern(&expected_host_permissions, "http://www.example.com/*"); |
| 1834 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1835 | std::set<std::string> host_permissions; |
| 1836 | |
| 1837 | // Test that the extension is disabled when an API permission is missing from |
| 1838 | // the extension's granted api permissions preference. (This simulates |
| 1839 | // updating the browser to a version which recognizes a new API permission). |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1840 | SetPref(extension_id, "granted_permissions.api", |
| 1841 | new ListValue(), "granted_permissions.api"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1842 | service_->ReloadExtensions(); |
| 1843 | |
| 1844 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1845 | extension = *service_->disabled_extensions()->begin(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1846 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1847 | ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 1848 | ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1849 | ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1850 | |
| 1851 | // Now grant and re-enable the extension, making sure the prefs are updated. |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 1852 | service_->GrantPermissionsAndEnableExtension(extension); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1853 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1854 | ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 1855 | ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1856 | ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1857 | |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1858 | scoped_refptr<PermissionSet> current_perms( |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1859 | prefs->GetGrantedPermissions(extension_id)); |
| 1860 | ASSERT_TRUE(current_perms.get()); |
| 1861 | ASSERT_FALSE(current_perms->IsEmpty()); |
| 1862 | ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); |
| 1863 | ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1864 | ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1865 | |
| 1866 | // Tests that the extension is disabled when a host permission is missing from |
| 1867 | // the extension's granted host permissions preference. (This simulates |
| 1868 | // updating the browser to a version which recognizes additional host |
| 1869 | // permissions). |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1870 | host_permissions.clear(); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1871 | current_perms = NULL; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1872 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1873 | host_permissions.insert("http://*.google.com/*"); |
| 1874 | host_permissions.insert("https://*.google.com/*"); |
[email protected] | d6a5c78c | 2010-12-07 05:18:15 | [diff] [blame] | 1875 | host_permissions.insert("http://*.google.com.hk/*"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1876 | |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1877 | ListValue* api_permissions = new ListValue(); |
| 1878 | api_permissions->Append( |
[email protected] | 1d8b79a | 2012-08-16 20:22:54 | [diff] [blame] | 1879 | Value::CreateStringValue("tabs")); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1880 | SetPref(extension_id, "granted_permissions.api", |
| 1881 | api_permissions, "granted_permissions.api"); |
| 1882 | SetPrefStringSet( |
| 1883 | extension_id, "granted_permissions.scriptable_host", host_permissions); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1884 | |
| 1885 | service_->ReloadExtensions(); |
| 1886 | |
| 1887 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1888 | extension = *service_->disabled_extensions()->begin(); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1889 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 1890 | ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 1891 | ASSERT_FALSE(service_->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1892 | ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1893 | |
| 1894 | // Now grant and re-enable the extension, making sure the prefs are updated. |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 1895 | service_->GrantPermissionsAndEnableExtension(extension); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1896 | |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 1897 | ASSERT_TRUE(service_->IsExtensionEnabled(extension_id)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1898 | ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); |
| 1899 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1900 | current_perms = prefs->GetGrantedPermissions(extension_id); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1901 | ASSERT_TRUE(current_perms.get()); |
| 1902 | ASSERT_FALSE(current_perms->IsEmpty()); |
| 1903 | ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); |
| 1904 | ASSERT_EQ(expected_api_permissions, current_perms->apis()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 1905 | ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1906 | } |
| 1907 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1908 | // Test Packaging and installing an extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1909 | TEST_F(ExtensionServiceTest, PackExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1910 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1911 | base::FilePath input_directory = data_dir_ |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 1912 | .AppendASCII("good") |
| 1913 | .AppendASCII("Extensions") |
| 1914 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 1915 | .AppendASCII("1.0.0.0"); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1916 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 1917 | base::ScopedTempDir temp_dir; |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 1918 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1919 | base::FilePath output_directory = temp_dir.path(); |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 1920 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1921 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 1922 | base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1923 | |
| 1924 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1925 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1926 | privkey_path, ExtensionCreator::kNoRunFlags)); |
| 1927 | ASSERT_TRUE(file_util::PathExists(crx_path)); |
| 1928 | ASSERT_TRUE(file_util::PathExists(privkey_path)); |
| 1929 | |
| 1930 | // Repeat the run with the pem file gone, and no special flags |
| 1931 | // Should refuse to overwrite the existing crx. |
| 1932 | file_util::Delete(privkey_path, false); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1933 | ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1934 | privkey_path, ExtensionCreator::kNoRunFlags)); |
| 1935 | |
| 1936 | // OK, now try it with a flag to overwrite existing crx. Should work. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1937 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1938 | privkey_path, ExtensionCreator::kOverwriteCRX)); |
| 1939 | |
| 1940 | // Repeat the run allowing existing crx, but the existing pem is still |
| 1941 | // an error. Should fail. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1942 | ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | 93d973a | 2012-01-08 07:38:26 | [diff] [blame] | 1943 | privkey_path, ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1944 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1945 | ASSERT_TRUE(file_util::PathExists(privkey_path)); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 1946 | InstallCRX(crx_path, INSTALL_NEW); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 1947 | |
| 1948 | // Try packing with invalid paths. |
| 1949 | creator.reset(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1950 | ASSERT_FALSE( |
| 1951 | creator->Run(base::FilePath(), base::FilePath(), base::FilePath(), |
| 1952 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 1953 | |
| 1954 | // Try packing an empty directory. Should fail because an empty directory is |
| 1955 | // not a valid extension. |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 1956 | base::ScopedTempDir temp_dir2; |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 1957 | ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
| 1958 | creator.reset(new ExtensionCreator()); |
| 1959 | ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1960 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 1961 | |
| 1962 | // Try packing with an invalid manifest. |
| 1963 | std::string invalid_manifest_content = "I am not a manifest."; |
| 1964 | ASSERT_TRUE(file_util::WriteFile( |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 1965 | temp_dir2.path().Append(extensions::kManifestFilename), |
[email protected] | 0dc2ca8 | 2009-11-17 07:06:16 | [diff] [blame] | 1966 | invalid_manifest_content.c_str(), invalid_manifest_content.size())); |
| 1967 | creator.reset(new ExtensionCreator()); |
| 1968 | ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1969 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 1970 | } |
| 1971 | |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1972 | // Test Packaging and installing an extension whose name contains punctuation. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 1973 | TEST_F(ExtensionServiceTest, PackPunctuatedExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1974 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1975 | base::FilePath input_directory = data_dir_ |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1976 | .AppendASCII("good") |
| 1977 | .AppendASCII("Extensions") |
| 1978 | .AppendASCII(good0) |
| 1979 | .AppendASCII("1.0.0.0"); |
| 1980 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 1981 | base::ScopedTempDir temp_dir; |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1982 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1983 | |
| 1984 | // Extension names containing punctuation, and the expected names for the |
| 1985 | // packed extensions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1986 | const base::FilePath punctuated_names[] = { |
| 1987 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods")), |
| 1988 | base::FilePath(FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod")), |
| 1989 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname/")). |
[email protected] | d9034ed2 | 2012-02-10 02:04:40 | [diff] [blame] | 1990 | NormalizePathSeparators(), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1991 | }; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1992 | const base::FilePath expected_crx_names[] = { |
| 1993 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods.crx")), |
| 1994 | base::FilePath( |
| 1995 | FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.crx")), |
| 1996 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.crx")), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 1997 | }; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 1998 | const base::FilePath expected_private_key_names[] = { |
| 1999 | base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods.pem")), |
| 2000 | base::FilePath( |
| 2001 | FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.pem")), |
| 2002 | base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.pem")), |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2003 | }; |
| 2004 | |
| 2005 | for (size_t i = 0; i < arraysize(punctuated_names); ++i) { |
| 2006 | SCOPED_TRACE(punctuated_names[i].value().c_str()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2007 | base::FilePath output_dir = temp_dir.path().Append(punctuated_names[i]); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2008 | |
| 2009 | // Copy the extension into the output directory, as PackExtensionJob doesn't |
| 2010 | // let us choose where to output the packed extension. |
| 2011 | ASSERT_TRUE(file_util::CopyDirectory(input_directory, output_dir, true)); |
| 2012 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2013 | base::FilePath expected_crx_path = |
| 2014 | temp_dir.path().Append(expected_crx_names[i]); |
| 2015 | base::FilePath expected_private_key_path = |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2016 | temp_dir.path().Append(expected_private_key_names[i]); |
| 2017 | PackExtensionTestClient pack_client(expected_crx_path, |
| 2018 | expected_private_key_path); |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 2019 | scoped_refptr<extensions::PackExtensionJob> packer( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2020 | new extensions::PackExtensionJob(&pack_client, output_dir, |
| 2021 | base::FilePath(), |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 2022 | ExtensionCreator::kOverwriteCRX)); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2023 | packer->Start(); |
| 2024 | |
| 2025 | // The packer will post a notification task to the current thread's message |
| 2026 | // loop when it is finished. We manually run the loop here so that we |
| 2027 | // block and catch the notification; otherwise, the process would exit. |
| 2028 | // This call to |Run()| is matched by a call to |Quit()| in the |
| 2029 | // |PackExtensionTestClient|'s notification handling code. |
| 2030 | MessageLoop::current()->Run(); |
| 2031 | |
| 2032 | if (HasFatalFailure()) |
| 2033 | return; |
| 2034 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2035 | InstallCRX(expected_crx_path, INSTALL_NEW); |
[email protected] | 0349ab5d | 2010-08-11 21:41:57 | [diff] [blame] | 2036 | } |
| 2037 | } |
| 2038 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2039 | TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) { |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2040 | InitializeEmptyExtensionService(); |
| 2041 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2042 | base::ScopedTempDir extension_temp_dir; |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2043 | ASSERT_TRUE(extension_temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2044 | base::FilePath input_directory = extension_temp_dir.path().AppendASCII("ext"); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2045 | ASSERT_TRUE(file_util::CopyDirectory( |
| 2046 | data_dir_ |
| 2047 | .AppendASCII("good") |
| 2048 | .AppendASCII("Extensions") |
| 2049 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 2050 | .AppendASCII("1.0.0.0"), |
| 2051 | input_directory, |
| 2052 | /*recursive=*/true)); |
| 2053 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2054 | base::ScopedTempDir output_temp_dir; |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2055 | ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2056 | base::FilePath output_directory = output_temp_dir.path(); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2057 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2058 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 2059 | base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2060 | |
| 2061 | // Pack the extension once to get a private key. |
| 2062 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2063 | ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2064 | privkey_path, ExtensionCreator::kNoRunFlags)) |
| 2065 | << creator->error_message(); |
| 2066 | ASSERT_TRUE(file_util::PathExists(crx_path)); |
| 2067 | ASSERT_TRUE(file_util::PathExists(privkey_path)); |
| 2068 | |
| 2069 | file_util::Delete(crx_path, false); |
| 2070 | // Move the pem file into the extension. |
| 2071 | file_util::Move(privkey_path, |
| 2072 | input_directory.AppendASCII("privkey.pem")); |
| 2073 | |
| 2074 | // This pack should fail because of the contained private key. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2075 | EXPECT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
[email protected] | ab55c2b | 2012-06-01 23:55:03 | [diff] [blame] | 2076 | privkey_path, ExtensionCreator::kNoRunFlags)); |
| 2077 | EXPECT_THAT(creator->error_message(), |
| 2078 | testing::ContainsRegex( |
| 2079 | "extension includes the key file.*privkey.pem")); |
| 2080 | } |
| 2081 | |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2082 | // Test Packaging and installing an extension using an openssl generated key. |
| 2083 | // The openssl is generated with the following: |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 2084 | // > openssl genrsa -out privkey.pem 1024 |
[email protected] | df4956e | 2009-06-10 16:53:42 | [diff] [blame] | 2085 | // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 2086 | // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2087 | // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2088 | TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2089 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2090 | base::FilePath input_directory = data_dir_ |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 2091 | .AppendASCII("good") |
| 2092 | .AppendASCII("Extensions") |
| 2093 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 2094 | .AppendASCII("1.0.0.0"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2095 | base::FilePath privkey_path(data_dir_.AppendASCII( |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2096 | "openssl_privkey_asn1.pem")); |
| 2097 | ASSERT_TRUE(file_util::PathExists(privkey_path)); |
| 2098 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2099 | base::ScopedTempDir temp_dir; |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 2100 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2101 | base::FilePath output_directory = temp_dir.path(); |
[email protected] | aca3e9b | 2009-11-03 01:14:21 | [diff] [blame] | 2102 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2103 | base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2104 | |
| 2105 | scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 2106 | ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2107 | base::FilePath(), ExtensionCreator::kOverwriteCRX)); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2108 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2109 | InstallCRX(crx_path, INSTALL_NEW); |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2110 | } |
[email protected] | a17f946 | 2009-06-09 02:56:41 | [diff] [blame] | 2111 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2112 | TEST_F(ExtensionServiceTest, InstallTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2113 | InitializeEmptyExtensionService(); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2114 | |
| 2115 | // A theme. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2116 | base::FilePath path = data_dir_.AppendASCII("theme.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2117 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2118 | int pref_count = 0; |
| 2119 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2120 | ValidateIntegerPref(theme_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2121 | ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2122 | |
[email protected] | 6ef635e4 | 2009-07-26 06:16:12 | [diff] [blame] | 2123 | // A theme when extensions are disabled. Themes can be installed, even when |
| 2124 | // extensions are disabled. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2125 | set_extensions_enabled(false); |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2126 | path = data_dir_.AppendASCII("theme2.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2127 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2128 | ValidatePrefKeyCount(++pref_count); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 2129 | ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2130 | ValidateIntegerPref(theme2_crx, "location", Manifest::INTERNAL); |
[email protected] | 494c06e | 2009-07-25 01:06:42 | [diff] [blame] | 2131 | |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2132 | // A theme with extension elements. Themes cannot have extension elements, |
| 2133 | // so any such elements (like content scripts) should be ignored. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2134 | set_extensions_enabled(true); |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2135 | { |
| 2136 | path = data_dir_.AppendASCII("theme_with_extension.crx"); |
| 2137 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 2138 | ValidatePrefKeyCount(++pref_count); |
| 2139 | ASSERT_TRUE(extension); |
| 2140 | EXPECT_TRUE(extension->is_theme()); |
[email protected] | 334ec0a | 2013-03-24 01:36:16 | [diff] [blame] | 2141 | EXPECT_EQ( |
| 2142 | 0u, |
| 2143 | extensions::ContentScriptsInfo::GetContentScripts(extension).size()); |
[email protected] | f6dec1e32 | 2012-04-30 21:04:51 | [diff] [blame] | 2144 | } |
[email protected] | 1219891 | 2009-06-05 03:41:22 | [diff] [blame] | 2145 | |
| 2146 | // A theme with image resources missing (misspelt path). |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2147 | path = data_dir_.AppendASCII("theme_missing_image.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2148 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2149 | ValidatePrefKeyCount(pref_count); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 2150 | } |
| 2151 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2152 | TEST_F(ExtensionServiceTest, LoadLocalizedTheme) { |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2153 | // Load. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2154 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2155 | base::FilePath extension_path = data_dir_ |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2156 | .AppendASCII("theme_i18n"); |
| 2157 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2158 | extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 2159 | loop_.RunUntilIdle(); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2160 | EXPECT_EQ(0u, GetErrors().size()); |
| 2161 | ASSERT_EQ(1u, loaded_.size()); |
| 2162 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2163 | const Extension* theme = *service_->extensions()->begin(); |
| 2164 | EXPECT_EQ("name", theme->name()); |
| 2165 | EXPECT_EQ("description", theme->description()); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 2166 | |
| 2167 | // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a |
| 2168 | // temporary directory, but it automatically installs to the extension's |
| 2169 | // directory, and we don't want to copy the whole extension for a unittest. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2170 | base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 2171 | ASSERT_TRUE(file_util::PathExists(theme_file)); |
| 2172 | ASSERT_TRUE(file_util::Delete(theme_file, false)); // Not recursive. |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2173 | } |
| 2174 | |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2175 | // Tests that we can change the ID of an unpacked extension by adding a key |
| 2176 | // to its manifest. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2177 | TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) { |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2178 | InitializeEmptyExtensionService(); |
| 2179 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2180 | base::ScopedTempDir temp; |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2181 | ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 2182 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2183 | base::FilePath extension_path = temp.path(); |
| 2184 | base::FilePath manifest_path = |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2185 | extension_path.Append(extensions::kManifestFilename); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2186 | base::FilePath manifest_no_key = data_dir_. |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2187 | AppendASCII("unpacked"). |
| 2188 | AppendASCII("manifest_no_key.json"); |
| 2189 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2190 | base::FilePath manifest_with_key = data_dir_. |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2191 | AppendASCII("unpacked"). |
| 2192 | AppendASCII("manifest_with_key.json"); |
| 2193 | |
| 2194 | ASSERT_TRUE(file_util::PathExists(manifest_no_key)); |
| 2195 | ASSERT_TRUE(file_util::PathExists(manifest_with_key)); |
| 2196 | |
| 2197 | // Load the unpacked extension with no key. |
| 2198 | file_util::CopyFile(manifest_no_key, manifest_path); |
| 2199 | extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
| 2200 | |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 2201 | loop_.RunUntilIdle(); |
[email protected] | c24fb29 | 2012-02-01 22:52:11 | [diff] [blame] | 2202 | EXPECT_EQ(0u, GetErrors().size()); |
| 2203 | ASSERT_EQ(1u, loaded_.size()); |
| 2204 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 2205 | |
| 2206 | // Add the key to the manifest. |
| 2207 | file_util::CopyFile(manifest_with_key, manifest_path); |
| 2208 | loaded_.clear(); |
| 2209 | |
| 2210 | // Reload the extensions. |
| 2211 | service_->ReloadExtensions(); |
| 2212 | const Extension* extension = service_->GetExtensionById(unpacked, false); |
| 2213 | EXPECT_EQ(unpacked, extension->id()); |
| 2214 | ASSERT_EQ(1u, loaded_.size()); |
| 2215 | |
| 2216 | // TODO(jstritar): Right now this just makes sure we don't crash and burn, but |
| 2217 | // we should also test that preferences are preserved. |
| 2218 | } |
| 2219 | |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2220 | #if defined(OS_POSIX) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2221 | TEST_F(ExtensionServiceTest, UnpackedExtensionMayContainSymlinkedFiles) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2222 | base::FilePath source_data_dir = data_dir_. |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2223 | AppendASCII("unpacked"). |
| 2224 | AppendASCII("symlinks_allowed"); |
| 2225 | |
| 2226 | // Paths to test data files. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2227 | base::FilePath source_manifest = source_data_dir.AppendASCII("manifest.json"); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2228 | ASSERT_TRUE(file_util::PathExists(source_manifest)); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2229 | base::FilePath source_icon = source_data_dir.AppendASCII("icon.png"); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2230 | ASSERT_TRUE(file_util::PathExists(source_icon)); |
| 2231 | |
| 2232 | // Set up the temporary extension directory. |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2233 | base::ScopedTempDir temp; |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2234 | ASSERT_TRUE(temp.CreateUniqueTempDir()); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2235 | base::FilePath extension_path = temp.path(); |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2236 | base::FilePath manifest = extension_path.Append( |
| 2237 | extensions::kManifestFilename); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2238 | base::FilePath icon_symlink = extension_path.AppendASCII("icon.png"); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2239 | file_util::CopyFile(source_manifest, manifest); |
| 2240 | file_util::CreateSymbolicLink(source_icon, icon_symlink); |
| 2241 | |
| 2242 | // Load extension. |
| 2243 | InitializeEmptyExtensionService(); |
| 2244 | extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 2245 | loop_.RunUntilIdle(); |
[email protected] | 9123652116 | 2012-05-24 15:02:51 | [diff] [blame] | 2246 | |
| 2247 | EXPECT_TRUE(GetErrors().empty()); |
| 2248 | ASSERT_EQ(1u, loaded_.size()); |
| 2249 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 2250 | } |
| 2251 | #endif |
| 2252 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2253 | TEST_F(ExtensionServiceTest, InstallLocalizedTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2254 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2255 | base::FilePath theme_path = data_dir_ |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2256 | .AppendASCII("theme_i18n"); |
| 2257 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2258 | const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2259 | |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2260 | EXPECT_EQ(0u, GetErrors().size()); |
| 2261 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2262 | EXPECT_EQ("name", theme->name()); |
| 2263 | EXPECT_EQ("description", theme->description()); |
[email protected] | 584245e5 | 2010-06-17 01:08:13 | [diff] [blame] | 2264 | } |
| 2265 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2266 | TEST_F(ExtensionServiceTest, InstallApps) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2267 | InitializeEmptyExtensionService(); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2268 | |
| 2269 | // An empty app. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2270 | const Extension* app = PackAndInstallCRX(data_dir_.AppendASCII("app1"), |
| 2271 | INSTALL_NEW); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2272 | int pref_count = 0; |
| 2273 | ValidatePrefKeyCount(++pref_count); |
[email protected] | 3ba0fd3 | 2010-06-19 05:39:10 | [diff] [blame] | 2274 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2275 | ValidateIntegerPref(app->id(), "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2276 | ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2277 | |
| 2278 | // Another app with non-overlapping extent. Should succeed. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2279 | PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2280 | ValidatePrefKeyCount(++pref_count); |
| 2281 | |
| 2282 | // A third app whose extent overlaps the first. Should fail. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2283 | PackAndInstallCRX(data_dir_.AppendASCII("app3"), INSTALL_FAILED); |
[email protected] | cd10e28 | 2010-10-26 21:04:51 | [diff] [blame] | 2284 | ValidatePrefKeyCount(pref_count); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2285 | } |
| 2286 | |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2287 | // Tests that file access is OFF by default. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2288 | TEST_F(ExtensionServiceTest, DefaultFileAccess) { |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2289 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2290 | const Extension* extension = |
| 2291 | PackAndInstallCRX(data_dir_ |
| 2292 | .AppendASCII("permissions") |
| 2293 | .AppendASCII("files"), |
| 2294 | INSTALL_NEW); |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2295 | EXPECT_EQ(0u, GetErrors().size()); |
| 2296 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2297 | EXPECT_FALSE(service_->extension_prefs()->AllowFileAccess(extension->id())); |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2298 | } |
| 2299 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2300 | TEST_F(ExtensionServiceTest, UpdateApps) { |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2301 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2302 | base::FilePath extensions_path = data_dir_.AppendASCII("app_update"); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2303 | |
| 2304 | // First install v1 of a hosted app. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2305 | const Extension* extension = |
| 2306 | InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2307 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2308 | std::string id = extension->id(); |
| 2309 | ASSERT_EQ(std::string("1"), extension->version()->GetString()); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2310 | |
| 2311 | // Now try updating to v2. |
| 2312 | UpdateExtension(id, |
| 2313 | extensions_path.AppendASCII("v2.crx"), |
| 2314 | ENABLED); |
| 2315 | ASSERT_EQ(std::string("2"), |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2316 | service_->GetExtensionById(id, false)->version()->GetString()); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 2317 | } |
| 2318 | |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2319 | // Verifies that the NTP page and launch ordinals are kept when updating apps. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2320 | TEST_F(ExtensionServiceTest, UpdateAppsRetainOrdinals) { |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2321 | InitializeEmptyExtensionService(); |
| 2322 | ExtensionSorting* sorting = service_->extension_prefs()->extension_sorting(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2323 | base::FilePath extensions_path = data_dir_.AppendASCII("app_update"); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2324 | |
| 2325 | // First install v1 of a hosted app. |
| 2326 | const Extension* extension = |
| 2327 | InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); |
| 2328 | ASSERT_EQ(1u, service_->extensions()->size()); |
| 2329 | std::string id = extension->id(); |
| 2330 | ASSERT_EQ(std::string("1"), extension->version()->GetString()); |
| 2331 | |
| 2332 | // Modify the ordinals so we can distinguish them from the defaults. |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 2333 | syncer::StringOrdinal new_page_ordinal = |
| 2334 | sorting->GetPageOrdinal(id).CreateAfter(); |
| 2335 | syncer::StringOrdinal new_launch_ordinal = |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2336 | sorting->GetAppLaunchOrdinal(id).CreateBefore(); |
| 2337 | |
| 2338 | sorting->SetPageOrdinal(id, new_page_ordinal); |
| 2339 | sorting->SetAppLaunchOrdinal(id, new_launch_ordinal); |
| 2340 | |
| 2341 | // Now try updating to v2. |
| 2342 | UpdateExtension(id, extensions_path.AppendASCII("v2.crx"), ENABLED); |
| 2343 | ASSERT_EQ(std::string("2"), |
| 2344 | service_->GetExtensionById(id, false)->version()->GetString()); |
| 2345 | |
| 2346 | // Verify that the ordinals match. |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 2347 | ASSERT_TRUE(new_page_ordinal.Equals(sorting->GetPageOrdinal(id))); |
| 2348 | ASSERT_TRUE(new_launch_ordinal.Equals(sorting->GetAppLaunchOrdinal(id))); |
[email protected] | e6a6c2e0 | 2012-01-13 00:06:48 | [diff] [blame] | 2349 | } |
| 2350 | |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2351 | // Ensures that the CWS has properly initialized ordinals. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2352 | TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) { |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2353 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2354 | service_->component_loader()->Add( |
| 2355 | IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store"))); |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2356 | service_->Init(); |
| 2357 | |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 2358 | ExtensionSorting* sorting = service_->extension_prefs()->extension_sorting(); |
| 2359 | EXPECT_TRUE( |
| 2360 | sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid()); |
| 2361 | EXPECT_TRUE( |
| 2362 | sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid()); |
| 2363 | } |
| 2364 | |
[email protected] | fe10c20 | 2013-03-11 23:44:34 | [diff] [blame] | 2365 | TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2366 | InitializeEmptyExtensionService(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 2367 | InitializeRequestContext(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2368 | EXPECT_TRUE(service_->extensions()->is_empty()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2369 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2370 | int pref_count = 0; |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2371 | |
| 2372 | // Install app1 with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2373 | const Extension* extension = |
| 2374 | PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2375 | ValidatePrefKeyCount(++pref_count); |
| 2376 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2377 | const std::string id1 = extension->id(); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2378 | EXPECT_TRUE(extension->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2379 | APIPermission::kUnlimitedStorage)); |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2380 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2381 | extension->GetFullLaunchURL())); |
| 2382 | const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2383 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2384 | IsStorageUnlimited(origin1)); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2385 | |
| 2386 | // Install app2 from the same origin with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2387 | extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2388 | ValidatePrefKeyCount(++pref_count); |
| 2389 | ASSERT_EQ(2u, service_->extensions()->size()); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2390 | const std::string id2 = extension->id(); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2391 | EXPECT_TRUE(extension->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2392 | APIPermission::kUnlimitedStorage)); |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2393 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2394 | extension->GetFullLaunchURL())); |
| 2395 | const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 2396 | EXPECT_EQ(origin1, origin2); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2397 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2398 | IsStorageUnlimited(origin2)); |
| 2399 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2400 | |
| 2401 | // Uninstall one of them, unlimited storage should still be granted |
| 2402 | // to the origin. |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2403 | UninstallExtension(id1, false); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2404 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2405 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2406 | IsStorageUnlimited(origin1)); |
| 2407 | |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2408 | // Uninstall the other, unlimited storage should be revoked. |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2409 | UninstallExtension(id2, false); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2410 | EXPECT_EQ(0u, service_->extensions()->size()); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2411 | EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2412 | IsStorageUnlimited(origin2)); |
[email protected] | c2c263c | 2010-08-13 21:59:48 | [diff] [blame] | 2413 | } |
| 2414 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2415 | TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2416 | InitializeEmptyExtensionService(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 2417 | InitializeRequestContext(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2418 | EXPECT_TRUE(service_->extensions()->is_empty()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2419 | |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2420 | int pref_count = 0; |
| 2421 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2422 | const Extension* extension = |
| 2423 | PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2424 | ValidatePrefKeyCount(++pref_count); |
| 2425 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2426 | EXPECT_TRUE(extension->is_app()); |
| 2427 | const std::string id1 = extension->id(); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2428 | const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2429 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2430 | IsStorageProtected(origin1)); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2431 | |
| 2432 | // App 4 has a different origin (maps.google.com). |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2433 | extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2434 | ValidatePrefKeyCount(++pref_count); |
| 2435 | ASSERT_EQ(2u, service_->extensions()->size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2436 | const std::string id2 = extension->id(); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2437 | const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 2438 | ASSERT_NE(origin1, origin2); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2439 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2440 | IsStorageProtected(origin2)); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2441 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2442 | UninstallExtension(id1, false); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2443 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2444 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2445 | UninstallExtension(id2, false); |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 2446 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2447 | EXPECT_TRUE(service_->extensions()->is_empty()); |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 2448 | EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2449 | IsStorageProtected(origin1)); |
| 2450 | EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2451 | IsStorageProtected(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] | 650b2d5 | 2013-02-10 03:41:45 | [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] | 650b2d5 | 2013-02-10 03:41:45 | [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); |
| 2486 | 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); |
| 2493 | 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. |
| 2496 | service_->ReloadExtensions(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 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 |
| 2501 | path = data_dir_.AppendASCII("good2.crx"); |
| 2502 | UpdateExtension(good_crx, path, ENABLED); |
| 2503 | ValidatePrefKeyCount(1); |
| 2504 | 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] | 650b2d5 | 2013-02-10 03:41:45 | [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 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [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] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2518 | // Upgrade to version 1.0.0.1 |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2519 | path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2520 | InstallCRX(path, INSTALL_UPDATED); |
| 2521 | extension = service_->GetExtensionById(id, false); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2522 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2523 | ASSERT_EQ("1.0.0.1", extension->version()->GetString()); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2524 | ASSERT_EQ(0u, GetErrors().size()); |
| 2525 | } |
| 2526 | |
| 2527 | // Test upgrading a signed extension with a bad signature. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2528 | TEST_F(ExtensionServiceTest, UpgradeSignedBad) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2529 | InitializeEmptyExtensionService(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2530 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2531 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2532 | InstallCRX(path, INSTALL_NEW); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2533 | |
| 2534 | // Try upgrading with a bad signature. This should fail during the unpack, |
| 2535 | // because the key will not match the signature. |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2536 | path = data_dir_.AppendASCII("bad_signature.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2537 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 2538 | } |
| 2539 | |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2540 | // Test a normal update via the UpdateExtension API |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2541 | TEST_F(ExtensionServiceTest, UpdateExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2542 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2543 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2544 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2545 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2546 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2547 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2548 | ASSERT_EQ(good_crx, good->id()); |
| 2549 | |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2550 | path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2551 | UpdateExtension(good_crx, path, ENABLED); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2552 | ASSERT_EQ("1.0.0.1", |
| 2553 | service_->GetExtensionById(good_crx, false)-> |
| 2554 | version()->GetString()); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2555 | } |
| 2556 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2557 | // Extensions should not be updated during browser shutdown. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2558 | TEST_F(ExtensionServiceTest, UpdateExtensionDuringShutdown) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2559 | InitializeEmptyExtensionService(); |
| 2560 | |
| 2561 | // Install an extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2562 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2563 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 2564 | ASSERT_EQ(good_crx, good->id()); |
| 2565 | |
| 2566 | // Simulate shutdown. |
| 2567 | service_->set_browser_terminating_for_test(true); |
| 2568 | |
| 2569 | // Update should fail and extension should not be updated. |
| 2570 | path = data_dir_.AppendASCII("good2.crx"); |
| 2571 | bool updated = service_->UpdateExtension(good_crx, path, GURL(), NULL); |
| 2572 | ASSERT_FALSE(updated); |
| 2573 | ASSERT_EQ("1.0.0.0", |
| 2574 | service_->GetExtensionById(good_crx, false)-> |
| 2575 | version()->GetString()); |
| 2576 | } |
| 2577 | |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2578 | // Test updating a not-already-installed extension - this should fail |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2579 | TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2580 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2581 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2582 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2583 | UpdateExtension(good_crx, path, UPDATED); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 2584 | loop_.RunUntilIdle(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2585 | |
| 2586 | ASSERT_EQ(0u, service_->extensions()->size()); |
| 2587 | ASSERT_FALSE(installed_); |
| 2588 | ASSERT_EQ(0u, loaded_.size()); |
| 2589 | } |
| 2590 | |
| 2591 | // Makes sure you can't downgrade an extension via UpdateExtension |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2592 | TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2593 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2594 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2595 | base::FilePath path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2596 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2597 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2598 | ASSERT_EQ("1.0.0.1", good->VersionString()); |
| 2599 | ASSERT_EQ(good_crx, good->id()); |
| 2600 | |
| 2601 | // Change path from good2.crx -> good.crx |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2602 | path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2603 | UpdateExtension(good_crx, path, FAILED); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2604 | ASSERT_EQ("1.0.0.1", |
| 2605 | service_->GetExtensionById(good_crx, false)-> |
| 2606 | version()->GetString()); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | // Make sure calling update with an identical version does nothing |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2610 | TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2611 | InitializeEmptyExtensionService(); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2612 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2613 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2614 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2615 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2616 | ASSERT_EQ(good_crx, good->id()); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2617 | UpdateExtension(good_crx, path, FAILED_SILENTLY); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2618 | } |
| 2619 | |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2620 | // Tests that updating an extension does not clobber old state. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2621 | TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2622 | InitializeEmptyExtensionService(); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2623 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2624 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2625 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2626 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2627 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2628 | ASSERT_EQ(good_crx, good->id()); |
| 2629 | |
| 2630 | // Disable it and allow it to run in incognito. These settings should carry |
| 2631 | // over to the updated version. |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 2632 | service_->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2633 | service_->SetIsIncognitoEnabled(good->id(), true); |
[email protected] | c38fd35 | 2012-03-28 04:06:12 | [diff] [blame] | 2634 | service_->extension_prefs()->SetDidExtensionEscalatePermissions(good, true); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2635 | |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2636 | path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2637 | UpdateExtension(good_crx, path, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 2638 | ASSERT_EQ(1u, service_->disabled_extensions()->size());\ |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2639 | const Extension* good2 = service_->GetExtensionById(good_crx, true); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2640 | ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2641 | EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id())); |
[email protected] | c38fd35 | 2012-03-28 04:06:12 | [diff] [blame] | 2642 | EXPECT_TRUE(service_->extension_prefs()->DidExtensionEscalatePermissions( |
| 2643 | good2->id())); |
[email protected] | dbec379 | 2010-08-10 00:08:45 | [diff] [blame] | 2644 | } |
| 2645 | |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2646 | // Tests that updating preserves extension location. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2647 | TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2648 | InitializeEmptyExtensionService(); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2649 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2650 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2651 | |
[email protected] | d41e215 | 2012-02-24 04:20:27 | [diff] [blame] | 2652 | const Extension* good = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2653 | InstallCRXWithLocation(path, Manifest::EXTERNAL_PREF, INSTALL_NEW); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2654 | |
| 2655 | ASSERT_EQ("1.0.0.0", good->VersionString()); |
| 2656 | ASSERT_EQ(good_crx, good->id()); |
| 2657 | |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 2658 | path = data_dir_.AppendASCII("good2.crx"); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2659 | UpdateExtension(good_crx, path, ENABLED); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 2660 | const Extension* good2 = service_->GetExtensionById(good_crx, false); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2661 | ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2662 | EXPECT_EQ(good2->location(), Manifest::EXTERNAL_PREF); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 2663 | } |
| 2664 | |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2665 | // Makes sure that LOAD extension types can downgrade. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2666 | TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2667 | InitializeEmptyExtensionService(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2668 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 2669 | base::ScopedTempDir temp; |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2670 | ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 2671 | |
| 2672 | // We'll write the extension manifest dynamically to a temporary path |
| 2673 | // to make it easier to change the version number. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2674 | base::FilePath extension_path = temp.path(); |
| 2675 | base::FilePath manifest_path = |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 2676 | extension_path.Append(extensions::kManifestFilename); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2677 | ASSERT_FALSE(file_util::PathExists(manifest_path)); |
| 2678 | |
| 2679 | // Start with version 2.0. |
| 2680 | DictionaryValue manifest; |
| 2681 | manifest.SetString("version", "2.0"); |
| 2682 | manifest.SetString("name", "LOAD Downgrade Test"); |
[email protected] | b3d5285 | 2011-12-07 01:01:11 | [diff] [blame] | 2683 | manifest.SetInteger("manifest_version", 2); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2684 | |
| 2685 | JSONFileValueSerializer serializer(manifest_path); |
| 2686 | ASSERT_TRUE(serializer.Serialize(manifest)); |
| 2687 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2688 | extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 2689 | loop_.RunUntilIdle(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2690 | |
| 2691 | EXPECT_EQ(0u, GetErrors().size()); |
| 2692 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 2693 | EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2694 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 2695 | EXPECT_EQ("2.0", loaded_[0]->VersionString()); |
| 2696 | |
| 2697 | // Now set the version number to 1.0, reload the extensions and verify that |
| 2698 | // the downgrade was accepted. |
| 2699 | manifest.SetString("version", "1.0"); |
| 2700 | ASSERT_TRUE(serializer.Serialize(manifest)); |
| 2701 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2702 | extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 2703 | loop_.RunUntilIdle(); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2704 | |
| 2705 | EXPECT_EQ(0u, GetErrors().size()); |
| 2706 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 2707 | EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2708 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 2709 | EXPECT_EQ("1.0", loaded_[0]->VersionString()); |
| 2710 | } |
| 2711 | |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2712 | #if !defined(OS_CHROMEOS) |
| 2713 | // LOAD extensions with plugins require approval. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2714 | TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2715 | base::FilePath extension_with_plugin_path = data_dir_ |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2716 | .AppendASCII("good") |
| 2717 | .AppendASCII("Extensions") |
| 2718 | .AppendASCII(good1) |
| 2719 | .AppendASCII("2"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2720 | base::FilePath extension_no_plugin_path = data_dir_ |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2721 | .AppendASCII("good") |
| 2722 | .AppendASCII("Extensions") |
| 2723 | .AppendASCII(good2) |
| 2724 | .AppendASCII("1.0"); |
| 2725 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 2726 | InitPluginService(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2727 | InitializeEmptyExtensionService(); |
| 2728 | InitializeExtensionProcessManager(); |
| 2729 | service_->set_show_extensions_prompts(true); |
| 2730 | |
| 2731 | // Start by canceling any install prompts. |
| 2732 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 2733 | switches::kAppsGalleryInstallAutoConfirmForTests, |
| 2734 | "cancel"); |
| 2735 | |
| 2736 | // The extension that has a plugin should not install. |
| 2737 | extensions::UnpackedInstaller::Create(service_)->Load( |
| 2738 | extension_with_plugin_path); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 2739 | loop_.RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2740 | EXPECT_EQ(0u, GetErrors().size()); |
| 2741 | EXPECT_EQ(0u, loaded_.size()); |
| 2742 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 2743 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2744 | |
| 2745 | // But the extension with no plugin should since there's no prompt. |
| 2746 | extensions::UnpackedInstaller::Create(service_)->Load( |
| 2747 | extension_no_plugin_path); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 2748 | loop_.RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2749 | EXPECT_EQ(0u, GetErrors().size()); |
| 2750 | EXPECT_EQ(1u, loaded_.size()); |
| 2751 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 2752 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2753 | EXPECT_TRUE(service_->extensions()->Contains(good2)); |
| 2754 | |
| 2755 | // The plugin extension should install if we accept the dialog. |
| 2756 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 2757 | switches::kAppsGalleryInstallAutoConfirmForTests, |
| 2758 | "accept"); |
| 2759 | |
| 2760 | extensions::UnpackedInstaller::Create(service_)->Load( |
| 2761 | extension_with_plugin_path); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 2762 | loop_.RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2763 | EXPECT_EQ(0u, GetErrors().size()); |
| 2764 | EXPECT_EQ(2u, loaded_.size()); |
| 2765 | EXPECT_EQ(2u, service_->extensions()->size()); |
| 2766 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2767 | EXPECT_TRUE(service_->extensions()->Contains(good1)); |
| 2768 | EXPECT_TRUE(service_->extensions()->Contains(good2)); |
| 2769 | |
| 2770 | // Make sure the granted permissions have been setup. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2771 | scoped_refptr<PermissionSet> permissions( |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2772 | service_->extension_prefs()->GetGrantedPermissions(good1)); |
| 2773 | EXPECT_FALSE(permissions->IsEmpty()); |
| 2774 | EXPECT_TRUE(permissions->HasEffectiveFullAccess()); |
| 2775 | EXPECT_FALSE(permissions->apis().empty()); |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2776 | EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2777 | |
| 2778 | // We should be able to reload the extension without getting another prompt. |
| 2779 | loaded_.clear(); |
| 2780 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 2781 | switches::kAppsGalleryInstallAutoConfirmForTests, |
| 2782 | "cancel"); |
| 2783 | |
| 2784 | service_->ReloadExtension(good1); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 2785 | loop_.RunUntilIdle(); |
[email protected] | 0d90431 | 2012-01-25 23:00:16 | [diff] [blame] | 2786 | EXPECT_EQ(1u, loaded_.size()); |
| 2787 | EXPECT_EQ(2u, service_->extensions()->size()); |
| 2788 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2789 | } |
| 2790 | #endif |
| 2791 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2792 | namespace { |
| 2793 | |
| 2794 | bool IsExtension(const Extension& extension) { |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2795 | return extension.GetType() == Manifest::TYPE_EXTENSION; |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | } // namespace |
| 2799 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2800 | // Test adding a pending extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2801 | TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2802 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2803 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 2804 | const std::string kFakeId(all_zero); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2805 | const GURL kFakeUpdateURL("http:://fake.update/url"); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2806 | const bool kFakeInstallSilently(true); |
| 2807 | |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 2808 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2809 | kFakeId, kFakeUpdateURL, &IsExtension, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2810 | kFakeInstallSilently)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2811 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 2812 | const extensions::PendingExtensionInfo* pending_extension_info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2813 | ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 2814 | GetById(kFakeId))); |
| 2815 | EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); |
| 2816 | EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); |
| 2817 | EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently()); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2818 | } |
| 2819 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2820 | namespace { |
| 2821 | const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 2822 | const char kGoodUpdateURL[] = "http://good.update/url"; |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2823 | const bool kGoodIsFromSync = true; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2824 | const bool kGoodInstallSilently = true; |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2825 | } // namespace |
| 2826 | |
| 2827 | // Test updating a pending extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2828 | TEST_F(ExtensionServiceTest, UpdatePendingExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2829 | InitializeEmptyExtensionService(); |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 2830 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2831 | kGoodId, GURL(kGoodUpdateURL), &IsExtension, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2832 | kGoodInstallSilently)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2833 | EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2834 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2835 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2836 | UpdateExtension(kGoodId, path, ENABLED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2837 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2838 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2839 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2840 | const Extension* extension = service_->GetExtensionById(kGoodId, true); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2841 | ASSERT_TRUE(extension); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2842 | } |
| 2843 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2844 | namespace { |
| 2845 | |
| 2846 | bool IsTheme(const Extension& extension) { |
| 2847 | return extension.is_theme(); |
| 2848 | } |
| 2849 | |
| 2850 | } // namespace |
| 2851 | |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2852 | // Test updating a pending theme. |
[email protected] | 7f2c555 | 2011-12-20 22:53:16 | [diff] [blame] | 2853 | // Disabled due to ASAN failure. http://crbug.com/108320 |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2854 | TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2855 | InitializeEmptyExtensionService(); |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 2856 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2857 | theme_crx, GURL(), &IsTheme, false)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2858 | EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2859 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2860 | base::FilePath path = data_dir_.AppendASCII("theme.crx"); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2861 | UpdateExtension(theme_crx, path, ENABLED); |
| 2862 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2863 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2864 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2865 | const Extension* extension = service_->GetExtensionById(theme_crx, true); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2866 | ASSERT_TRUE(extension); |
| 2867 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 2868 | EXPECT_FALSE( |
| 2869 | service_->extension_prefs()->IsExtensionDisabled(extension->id())); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 2870 | EXPECT_TRUE(service_->IsExtensionEnabled(theme_crx)); |
[email protected] | 11edd1e | 2010-07-21 00:14:50 | [diff] [blame] | 2871 | } |
| 2872 | |
[email protected] | d74f92e | 2011-04-18 15:39:23 | [diff] [blame] | 2873 | #if defined(OS_CHROMEOS) |
| 2874 | // Always fails on ChromeOS: http://crbug.com/79737 |
[email protected] | e00ccc9 | 2012-11-01 17:32:30 | [diff] [blame] | 2875 | #define MAYBE_UpdatePendingExternalCrx DISABLED_UpdatePendingExternalCrx |
[email protected] | d74f92e | 2011-04-18 15:39:23 | [diff] [blame] | 2876 | #else |
| 2877 | #define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx |
| 2878 | #endif |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2879 | // Test updating a pending CRX as if the source is an external extension |
| 2880 | // with an update URL. In this case we don't know if the CRX is a theme |
| 2881 | // or not. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2882 | TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2883 | InitializeEmptyExtensionService(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2884 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2885 | theme_crx, GURL(), Manifest::EXTERNAL_PREF_DOWNLOAD)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2886 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2887 | EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2888 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2889 | base::FilePath path = data_dir_.AppendASCII("theme.crx"); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2890 | UpdateExtension(theme_crx, path, ENABLED); |
| 2891 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2892 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2893 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2894 | const Extension* extension = service_->GetExtensionById(theme_crx, true); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2895 | ASSERT_TRUE(extension); |
| 2896 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 2897 | EXPECT_FALSE( |
| 2898 | service_->extension_prefs()->IsExtensionDisabled(extension->id())); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 2899 | EXPECT_TRUE(service_->IsExtensionEnabled(extension->id())); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2900 | EXPECT_FALSE(service_->IsIncognitoEnabled(extension->id())); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2901 | } |
| 2902 | |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2903 | // Test updating a pending CRX as if the source is an external extension |
| 2904 | // with an update URL. The external update should overwrite a sync update, |
| 2905 | // but a sync update should not overwrite a non-sync update. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2906 | TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2907 | InitializeEmptyExtensionService(); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2908 | |
| 2909 | // Add a crx to be installed from the update mechanism. |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 2910 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2911 | kGoodId, GURL(kGoodUpdateURL), &IsExtension, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2912 | kGoodInstallSilently)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2913 | |
| 2914 | // 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] | 2915 | const extensions::PendingExtensionInfo* pending_extension_info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2916 | ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 2917 | GetById(kGoodId))); |
| 2918 | EXPECT_TRUE(pending_extension_info->is_from_sync()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2919 | |
| 2920 | // Add a crx to be updated, with the same ID, from a non-sync source. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2921 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2922 | kGoodId, GURL(kGoodUpdateURL), Manifest::EXTERNAL_PREF_DOWNLOAD)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2923 | |
| 2924 | // Check that there is a pending crx, with is_from_sync set to false. |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2925 | ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 2926 | GetById(kGoodId))); |
| 2927 | EXPECT_FALSE(pending_extension_info->is_from_sync()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2928 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2929 | pending_extension_info->install_source()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2930 | |
| 2931 | // Add a crx to be installed from the update mechanism. |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 2932 | EXPECT_FALSE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2933 | kGoodId, GURL(kGoodUpdateURL), &IsExtension, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2934 | kGoodInstallSilently)); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2935 | |
| 2936 | // Check that the external, non-sync update was not overridden. |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2937 | ASSERT_TRUE((pending_extension_info = service_->pending_extension_manager()-> |
| 2938 | GetById(kGoodId))); |
| 2939 | EXPECT_FALSE(pending_extension_info->is_from_sync()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2940 | EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2941 | pending_extension_info->install_source()); |
[email protected] | 1afaf2a5 | 2010-11-02 19:29:17 | [diff] [blame] | 2942 | } |
| 2943 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2944 | // Updating a theme should fail if the updater is explicitly told that |
| 2945 | // the CRX is not a theme. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2946 | TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2947 | InitializeEmptyExtensionService(); |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 2948 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2949 | theme_crx, GURL(), &IsExtension, true)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2950 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2951 | EXPECT_TRUE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2952 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2953 | base::FilePath path = data_dir_.AppendASCII("theme.crx"); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2954 | UpdateExtension(theme_crx, path, FAILED_SILENTLY); |
| 2955 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2956 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(theme_crx)); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2957 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2958 | const Extension* extension = service_->GetExtensionById(theme_crx, true); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2959 | ASSERT_FALSE(extension); |
| 2960 | } |
| 2961 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2962 | // TODO(akalin): Test updating a pending extension non-silently once |
| 2963 | // we can mock out ExtensionInstallUI and inject our version into |
| 2964 | // UpdateExtension(). |
| 2965 | |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2966 | // Test updating a pending extension which fails the should-install test. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 2967 | TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2968 | InitializeEmptyExtensionService(); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2969 | // Add pending extension with a flipped is_theme. |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 2970 | EXPECT_TRUE(service_->pending_extension_manager()->AddFromSync( |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2971 | kGoodId, GURL(kGoodUpdateURL), &IsTheme, kGoodInstallSilently)); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [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] | 650b2d5 | 2013-02-10 03:41:45 | [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] | b2907fd | 2011-03-25 16:43:37 | [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] | 650b2d5 | 2013-02-10 03:41:45 | [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] | b2907fd | 2011-03-25 16:43:37 | [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] | 650b2d5 | 2013-02-10 03:41:45 | [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] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3003 | ASSERT_EQ(1u, service_->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. |
| 3008 | service_->pending_extension_manager()->AddExtensionImpl( |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 3009 | good->id(), extensions::ManifestURL::GetUpdateURL(good), |
| 3010 | Version(), &IsExtension, kGoodIsFromSync, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3011 | kGoodInstallSilently, Manifest::INTERNAL); |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 3012 | UpdateExtension(good->id(), path, ENABLED); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 3013 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 3014 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 3015 | } |
| 3016 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3017 | // Test pref settings for blacklist and unblacklist extensions. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3018 | TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3019 | InitializeEmptyExtensionService(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3020 | std::vector<std::string> blacklist; |
| 3021 | blacklist.push_back(good0); |
| 3022 | blacklist.push_back("invalid_id"); // an invalid id |
| 3023 | blacklist.push_back(good1); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3024 | ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, |
| 3025 | "v1"); |
| 3026 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3027 | // Make sure pref is updated |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3028 | loop_.RunUntilIdle(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3029 | |
| 3030 | // blacklist is set for good0,1,2 |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 3031 | ValidateBooleanPref(good0, "blacklist", true); |
| 3032 | ValidateBooleanPref(good1, "blacklist", true); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3033 | // invalid_id should not be inserted to pref. |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 3034 | EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3035 | |
| 3036 | // remove good1, add good2 |
| 3037 | blacklist.pop_back(); |
| 3038 | blacklist.push_back(good2); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3039 | ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, |
| 3040 | "v2"); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3041 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3042 | // only good0 and good1 should be set |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 3043 | ValidateBooleanPref(good0, "blacklist", true); |
| 3044 | EXPECT_FALSE(IsPrefExist(good1, "blacklist")); |
| 3045 | ValidateBooleanPref(good2, "blacklist", true); |
| 3046 | EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | // Unload installed extension from blacklist. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3050 | TEST_F(ExtensionServiceTest, UnloadBlacklistedExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3051 | InitializeEmptyExtensionService(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3052 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3053 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3054 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3055 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3056 | EXPECT_EQ(good_crx, good->id()); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 3057 | UpdateExtension(good_crx, path, FAILED_SILENTLY); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3058 | |
| 3059 | std::vector<std::string> blacklist; |
| 3060 | blacklist.push_back(good_crx); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3061 | ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, |
| 3062 | "v1"); |
| 3063 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3064 | // Make sure pref is updated |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3065 | loop_.RunUntilIdle(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3066 | |
| 3067 | // Now, the good_crx is blacklisted. |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 3068 | ValidateBooleanPref(good_crx, "blacklist", true); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3069 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3070 | |
| 3071 | // Remove good_crx from blacklist |
| 3072 | blacklist.pop_back(); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3073 | ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, |
| 3074 | "v2"); |
| 3075 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3076 | // Make sure pref is updated |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3077 | loop_.RunUntilIdle(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3078 | // blacklist value should not be set for good_crx |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 3079 | EXPECT_FALSE(IsPrefExist(good_crx, "blacklist")); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | // Unload installed extension from blacklist. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3083 | TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3084 | InitializeEmptyExtensionService(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3085 | std::vector<std::string> blacklist; |
| 3086 | blacklist.push_back(good_crx); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3087 | ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, |
| 3088 | "v1"); |
| 3089 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3090 | // Make sure pref is updated |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3091 | loop_.RunUntilIdle(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3092 | |
| 3093 | // Now, the good_crx is blacklisted. |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 3094 | ValidateBooleanPref(good_crx, "blacklist", true); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3095 | |
| 3096 | // We can not install good_crx. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3097 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 3098 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3099 | EXPECT_EQ(0u, service_->extensions()->size()); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 3100 | ValidateBooleanPref(good_crx, "blacklist", true); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3101 | } |
| 3102 | |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3103 | // Unload blacklisted extension on policy change. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3104 | TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3105 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3106 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3107 | |
| 3108 | const Extension* good = InstallCRX(path, INSTALL_NEW); |
| 3109 | EXPECT_EQ(good_crx, good->id()); |
| 3110 | UpdateExtension(good_crx, path, FAILED_SILENTLY); |
| 3111 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3112 | |
| 3113 | base::ListValue whitelist; |
| 3114 | PrefService* prefs = service_->extension_prefs()->pref_service(); |
| 3115 | whitelist.Append(base::Value::CreateStringValue(good_crx)); |
| 3116 | prefs->Set(prefs::kExtensionInstallAllowList, whitelist); |
| 3117 | |
| 3118 | std::vector<std::string> blacklist; |
| 3119 | blacklist.push_back(good_crx); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3120 | ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, |
| 3121 | "v1"); |
| 3122 | |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3123 | // Make sure pref is updated |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3124 | loop_.RunUntilIdle(); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3125 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3126 | // The good_crx is blacklisted and the whitelist doesn't negate it. |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3127 | ValidateBooleanPref(good_crx, "blacklist", true); |
| 3128 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3129 | } |
| 3130 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3131 | // Test loading extensions from the profile directory, except |
| 3132 | // blacklisted ones. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3133 | TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3134 | // Initialize the test dir with a good Preferences/extensions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3135 | base::FilePath source_install_dir = data_dir_ |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3136 | .AppendASCII("good") |
| 3137 | .AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3138 | base::FilePath pref_path = source_install_dir |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3139 | .DirName() |
| 3140 | .AppendASCII("Preferences"); |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3141 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3142 | |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 3143 | // Blacklist good1. |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3144 | std::vector<std::string> blacklist; |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 3145 | blacklist.push_back(good1); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3146 | ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, |
| 3147 | "v1"); |
| 3148 | |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3149 | // Make sure pref is updated |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3150 | loop_.RunUntilIdle(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3151 | |
[email protected] | e50013c3 | 2010-08-18 21:05:24 | [diff] [blame] | 3152 | ValidateBooleanPref(good1, "blacklist", true); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3153 | |
| 3154 | // Load extensions. |
| 3155 | service_->Init(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3156 | |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 3157 | std::vector<string16> errors = GetErrors(); |
| 3158 | for (std::vector<string16>::iterator err = errors.begin(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3159 | err != errors.end(); ++err) { |
| 3160 | LOG(ERROR) << *err; |
| 3161 | } |
[email protected] | d7b36dc | 2009-10-29 21:47:40 | [diff] [blame] | 3162 | ASSERT_EQ(2u, loaded_.size()); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3163 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3164 | EXPECT_TRUE(service_->GetInstalledExtension(good1)); |
| 3165 | int include_mask = ExtensionService::INCLUDE_EVERYTHING & |
| 3166 | ~ExtensionService::INCLUDE_BLACKLISTED; |
| 3167 | EXPECT_FALSE(service_->GetExtensionById(good1, include_mask)); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 3168 | } |
| 3169 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3170 | // Will not install extension blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3171 | TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3172 | InitializeEmptyExtensionService(); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3173 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3174 | // Blacklist everything. |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3175 | { |
| 3176 | ListPrefUpdate update(profile_->GetPrefs(), |
| 3177 | prefs::kExtensionInstallDenyList); |
| 3178 | ListValue* blacklist = update.Get(); |
| 3179 | blacklist->Append(Value::CreateStringValue("*")); |
| 3180 | } |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3181 | |
| 3182 | // Blacklist prevents us from installing good_crx. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3183 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3184 | InstallCRX(path, INSTALL_FAILED); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3185 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3186 | |
| 3187 | // Now whitelist this particular extension. |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3188 | { |
| 3189 | ListPrefUpdate update(profile_->GetPrefs(), |
| 3190 | prefs::kExtensionInstallAllowList); |
| 3191 | ListValue* whitelist = update.Get(); |
| 3192 | whitelist->Append(Value::CreateStringValue(good_crx)); |
| 3193 | } |
| 3194 | |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3195 | // Ensure we can now install good_crx. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3196 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 3197 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3198 | } |
| 3199 | |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3200 | // Extension blacklisted by policy get unloaded after installing. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3201 | TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3202 | InitializeEmptyExtensionService(); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3203 | |
| 3204 | // Install good_crx. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3205 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3206 | InstallCRX(path, INSTALL_NEW); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3207 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3208 | |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3209 | { // Scope for pref update notification. |
| 3210 | PrefService* prefs = profile_->GetPrefs(); |
[email protected] | 43d3bf8 | 2011-04-11 07:46:58 | [diff] [blame] | 3211 | ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); |
| 3212 | ListValue* blacklist = update.Get(); |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3213 | ASSERT_TRUE(blacklist != NULL); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3214 | |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3215 | // Blacklist this extension. |
| 3216 | blacklist->Append(Value::CreateStringValue(good_crx)); |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 3217 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3218 | |
| 3219 | // Extension should not be running now. |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3220 | loop_.RunUntilIdle(); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 3221 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3222 | } |
| 3223 | |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3224 | // Tests that component extensions are not blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3225 | TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3226 | InitializeEmptyExtensionService(); |
| 3227 | |
| 3228 | // Blacklist everything. |
| 3229 | { |
| 3230 | ListPrefUpdate update(profile_->GetPrefs(), |
| 3231 | prefs::kExtensionInstallDenyList); |
| 3232 | ListValue* blacklist = update.Get(); |
| 3233 | blacklist->Append(Value::CreateStringValue("*")); |
| 3234 | } |
| 3235 | |
| 3236 | // Install a component extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3237 | base::FilePath path = data_dir_ |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3238 | .AppendASCII("good") |
| 3239 | .AppendASCII("Extensions") |
| 3240 | .AppendASCII(good0) |
| 3241 | .AppendASCII("1.0.0.0"); |
| 3242 | std::string manifest; |
| 3243 | ASSERT_TRUE(file_util::ReadFileToString( |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 3244 | path.Append(extensions::kManifestFilename), &manifest)); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 3245 | service_->component_loader()->Add(manifest, path); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3246 | service_->Init(); |
| 3247 | |
| 3248 | // Extension should be installed despite blacklist. |
| 3249 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3250 | EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3251 | |
| 3252 | // Poke external providers and make sure the extension is still present. |
| 3253 | service_->CheckForExternalUpdates(); |
| 3254 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3255 | EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3256 | |
| 3257 | // Extension should not be uninstalled on blacklist changes. |
| 3258 | { |
| 3259 | ListPrefUpdate update(profile_->GetPrefs(), |
| 3260 | prefs::kExtensionInstallDenyList); |
| 3261 | ListValue* blacklist = update.Get(); |
| 3262 | blacklist->Append(Value::CreateStringValue(good0)); |
| 3263 | } |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3264 | loop_.RunUntilIdle(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3265 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3266 | EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | // Tests that policy-installed extensions are not blacklisted by policy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3270 | TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3271 | InitializeEmptyExtensionService(); |
| 3272 | |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3273 | { |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 3274 | // Blacklist everything. |
| 3275 | ListPrefUpdate blacklist_update(profile_->GetPrefs(), |
| 3276 | prefs::kExtensionInstallDenyList); |
| 3277 | ListValue* blacklist = blacklist_update.Get(); |
| 3278 | blacklist->AppendString("*"); |
| 3279 | |
| 3280 | // Mark good.crx for force-installation. |
| 3281 | DictionaryPrefUpdate forcelist_update(profile_->GetPrefs(), |
| 3282 | prefs::kExtensionInstallForceList); |
| 3283 | extensions::ExternalPolicyLoader::AddExtension( |
| 3284 | forcelist_update.Get(), good_crx, "http://example.com/update_url"); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | // Have policy force-install an extension. |
| 3288 | MockExtensionProvider* provider = |
| 3289 | new MockExtensionProvider(service_, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3290 | Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3291 | AddMockExternalProvider(provider); |
| 3292 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 3293 | data_dir_.AppendASCII("good.crx")); |
| 3294 | |
| 3295 | // Reloading extensions should find our externally registered extension |
| 3296 | // and install it. |
| 3297 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3298 | loop_.RunUntilIdle(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3299 | |
| 3300 | // Extension should be installed despite blacklist. |
| 3301 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3302 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3303 | |
| 3304 | // Blacklist update should not uninstall the extension. |
| 3305 | { |
| 3306 | ListPrefUpdate update(profile_->GetPrefs(), |
| 3307 | prefs::kExtensionInstallDenyList); |
| 3308 | ListValue* blacklist = update.Get(); |
| 3309 | blacklist->Append(Value::CreateStringValue(good0)); |
| 3310 | } |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3311 | loop_.RunUntilIdle(); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3312 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3313 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 3314 | } |
| 3315 | |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3316 | // Tests that extensions cannot be installed if the policy provider prohibits |
| 3317 | // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3318 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3319 | InitializeEmptyExtensionService(); |
| 3320 | |
| 3321 | management_policy_->UnregisterAllProviders(); |
| 3322 | extensions::TestManagementPolicyProvider provider_( |
| 3323 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
| 3324 | management_policy_->RegisterProvider(&provider_); |
| 3325 | |
| 3326 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_FAILED); |
| 3327 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3328 | } |
| 3329 | |
| 3330 | // Tests that extensions cannot be loaded from prefs if the policy provider |
| 3331 | // prohibits it. This functionality is implemented in InstalledLoader::Load(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3332 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3333 | InitializeEmptyExtensionService(); |
| 3334 | |
| 3335 | // Create a fake extension to be loaded as though it were read from prefs. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3336 | base::FilePath path = data_dir_.AppendASCII("management") |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3337 | .AppendASCII("simple_extension"); |
| 3338 | DictionaryValue manifest; |
| 3339 | manifest.SetString(keys::kName, "simple_extension"); |
| 3340 | manifest.SetString(keys::kVersion, "1"); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 3341 | // UNPACKED is for extensions loaded from a directory. We use it here, even |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3342 | // though we're testing loading from prefs, so that we don't need to provide |
| 3343 | // an extension key. |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 3344 | extensions::ExtensionInfo extension_info( |
| 3345 | &manifest, std::string(), path, Manifest::UNPACKED); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3346 | |
| 3347 | // Ensure we can load it with no management policy in place. |
| 3348 | management_policy_->UnregisterAllProviders(); |
| 3349 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3350 | extensions::InstalledLoader(service_).Load(extension_info, false); |
| 3351 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3352 | |
| 3353 | const Extension* extension = *(service_->extensions()->begin()); |
| 3354 | EXPECT_TRUE(service_->UninstallExtension(extension->id(), false, NULL)); |
| 3355 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3356 | |
| 3357 | // Ensure we cannot load it if management policy prohibits installation. |
| 3358 | extensions::TestManagementPolicyProvider provider_( |
| 3359 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
| 3360 | management_policy_->RegisterProvider(&provider_); |
| 3361 | |
| 3362 | extensions::InstalledLoader(service_).Load(extension_info, false); |
| 3363 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3364 | } |
| 3365 | |
| 3366 | // Tests disabling an extension when prohibited by the ManagementPolicy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3367 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3368 | InitializeEmptyExtensionService(); |
| 3369 | |
| 3370 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3371 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3372 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3373 | |
| 3374 | management_policy_->UnregisterAllProviders(); |
| 3375 | extensions::TestManagementPolicyProvider provider( |
| 3376 | extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
| 3377 | management_policy_->RegisterProvider(&provider); |
| 3378 | |
| 3379 | // Attempt to disable it. |
| 3380 | service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
| 3381 | |
| 3382 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3383 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3384 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3385 | } |
| 3386 | |
| 3387 | // Tests uninstalling an extension when prohibited by the ManagementPolicy. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3388 | TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3389 | InitializeEmptyExtensionService(); |
| 3390 | |
| 3391 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3392 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3393 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3394 | |
| 3395 | management_policy_->UnregisterAllProviders(); |
| 3396 | extensions::TestManagementPolicyProvider provider( |
| 3397 | extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
| 3398 | management_policy_->RegisterProvider(&provider); |
| 3399 | |
| 3400 | // Attempt to uninstall it. |
| 3401 | EXPECT_FALSE(service_->UninstallExtension(good_crx, false, NULL)); |
| 3402 | |
| 3403 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3404 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3405 | } |
| 3406 | |
| 3407 | // Tests that previously installed extensions that are now prohibited from |
| 3408 | // being installed are removed. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3409 | TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3410 | InitializeEmptyExtensionService(); |
| 3411 | |
| 3412 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3413 | InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); |
| 3414 | EXPECT_EQ(2u, service_->extensions()->size()); |
| 3415 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3416 | |
| 3417 | management_policy_->UnregisterAllProviders(); |
| 3418 | extensions::TestManagementPolicyProvider provider( |
| 3419 | extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
| 3420 | management_policy_->RegisterProvider(&provider); |
| 3421 | |
| 3422 | // Run the policy check. |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 3423 | service_->CheckManagementPolicy(); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3424 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3425 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3426 | } |
| 3427 | |
| 3428 | // Tests that previously disabled extensions that are now required to be |
| 3429 | // enabled are re-enabled on reinstall. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3430 | TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3431 | InitializeEmptyExtensionService(); |
| 3432 | |
| 3433 | // Install, then disable, an extension. |
| 3434 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3435 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3436 | service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
| 3437 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 3438 | |
| 3439 | // Register an ExtensionMnagementPolicy that requires the extension to remain |
| 3440 | // enabled. |
| 3441 | management_policy_->UnregisterAllProviders(); |
| 3442 | extensions::TestManagementPolicyProvider provider( |
| 3443 | extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED); |
| 3444 | management_policy_->RegisterProvider(&provider); |
| 3445 | |
| 3446 | // Reinstall the extension. |
| 3447 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_UPDATED); |
| 3448 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3449 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3450 | } |
| 3451 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3452 | TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) { |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3453 | InitializeEmptyExtensionService(); |
| 3454 | set_extensions_enabled(true); |
| 3455 | |
| 3456 | { |
| 3457 | // Register and install an external extension. |
| 3458 | MockExtensionProvider* provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3459 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3460 | AddMockExternalProvider(provider); |
| 3461 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 3462 | data_dir_.AppendASCII("good.crx")); |
| 3463 | } |
| 3464 | { |
| 3465 | // Have policy force-install an extension. |
| 3466 | MockExtensionProvider* provider = |
| 3467 | new MockExtensionProvider(service_, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3468 | Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3469 | AddMockExternalProvider(provider); |
| 3470 | provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 3471 | data_dir_.AppendASCII("page_action.crx")); |
| 3472 | } |
| 3473 | |
| 3474 | // Providers are set up. Let them run. |
| 3475 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3476 | loop_.RunUntilIdle(); |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 3477 | |
| 3478 | ASSERT_EQ(2u, service_->extensions()->size()); |
| 3479 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3480 | EXPECT_TRUE(service_->GetExtensionById(page_action, false)); |
| 3481 | ExtensionPrefs* prefs = service_->extension_prefs(); |
| 3482 | ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); |
| 3483 | ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); |
| 3484 | } |
| 3485 | |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 3486 | #if !defined(OS_CHROMEOS) |
| 3487 | // This tests if default apps are installed correctly. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3488 | TEST_F(ExtensionServiceTest, DefaultAppsInstall) { |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 3489 | InitializeEmptyExtensionService(); |
| 3490 | InitializeRequestContext(); |
| 3491 | set_extensions_enabled(true); |
| 3492 | |
| 3493 | { |
| 3494 | std::string json_data = |
| 3495 | "{" |
| 3496 | " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {" |
| 3497 | " \"external_crx\": \"good.crx\"," |
| 3498 | " \"external_version\": \"1.0.0.0\"," |
| 3499 | " \"is_bookmark_app\": false" |
| 3500 | " }" |
| 3501 | "}"; |
| 3502 | default_apps::Provider* provider = |
| 3503 | new default_apps::Provider( |
| 3504 | profile_.get(), |
| 3505 | service_, |
| 3506 | new extensions::ExternalTestingLoader(json_data, data_dir_), |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3507 | Manifest::INTERNAL, |
| 3508 | Manifest::INVALID_LOCATION, |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 3509 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
| 3510 | |
| 3511 | AddMockExternalProvider(provider); |
| 3512 | } |
| 3513 | |
| 3514 | ASSERT_EQ(0u, service_->extensions()->size()); |
| 3515 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3516 | loop_.RunUntilIdle(); |
[email protected] | a7cd28e | 2012-10-05 21:03:36 | [diff] [blame] | 3517 | |
| 3518 | ASSERT_EQ(1u, service_->extensions()->size()); |
| 3519 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3520 | const Extension* extension = service_->GetExtensionById(good_crx, false); |
| 3521 | EXPECT_TRUE(extension->from_webstore()); |
| 3522 | EXPECT_TRUE(extension->was_installed_by_default()); |
| 3523 | |
| 3524 | } |
| 3525 | #endif |
| 3526 | |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3527 | // Tests disabling extensions |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3528 | TEST_F(ExtensionServiceTest, DisableExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3529 | InitializeEmptyExtensionService(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3530 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3531 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 3532 | EXPECT_FALSE(service_->extensions()->is_empty()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3533 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 3534 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 3535 | EXPECT_TRUE(service_->disabled_extensions()->is_empty()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3536 | |
| 3537 | // Disable it. |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 3538 | service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3539 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 3540 | EXPECT_TRUE(service_->extensions()->is_empty()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3541 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 3542 | EXPECT_FALSE(service_->GetExtensionById(good_crx, false)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 3543 | EXPECT_FALSE(service_->disabled_extensions()->is_empty()); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3544 | } |
| 3545 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3546 | TEST_F(ExtensionServiceTest, DisableTerminatedExtension) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3547 | InitializeEmptyExtensionService(); |
| 3548 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3549 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3550 | TerminateExtension(good_crx); |
| 3551 | EXPECT_TRUE(service_->GetTerminatedExtension(good_crx)); |
| 3552 | |
| 3553 | // Disable it. |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 3554 | service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3555 | |
| 3556 | EXPECT_FALSE(service_->GetTerminatedExtension(good_crx)); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3557 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 3558 | EXPECT_FALSE(service_->disabled_extensions()->is_empty()); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3559 | } |
| 3560 | |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 3561 | // Tests disabling all extensions (simulating --disable-extensions flag). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3562 | TEST_F(ExtensionServiceTest, DisableAllExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3563 | InitializeEmptyExtensionService(); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 3564 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3565 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3566 | InstallCRX(path, INSTALL_NEW); |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 3567 | |
| 3568 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3569 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3570 | |
| 3571 | // Disable extensions. |
| 3572 | service_->set_extensions_enabled(false); |
| 3573 | service_->ReloadExtensions(); |
| 3574 | |
| 3575 | // There shouldn't be extensions in either list. |
| 3576 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3577 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3578 | |
| 3579 | // This shouldn't do anything when all extensions are disabled. |
| 3580 | service_->EnableExtension(good_crx); |
| 3581 | service_->ReloadExtensions(); |
| 3582 | |
| 3583 | // There still shouldn't be extensions in either list. |
| 3584 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3585 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3586 | |
| 3587 | // And then re-enable the extensions. |
| 3588 | service_->set_extensions_enabled(true); |
| 3589 | service_->ReloadExtensions(); |
| 3590 | |
| 3591 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3592 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3593 | } |
| 3594 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3595 | // Tests reloading extensions. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3596 | TEST_F(ExtensionServiceTest, ReloadExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3597 | InitializeEmptyExtensionService(); |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 3598 | InitializeRequestContext(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3599 | |
| 3600 | // Simple extension that should install without error. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3601 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 3602 | InstallCRX(path, INSTALL_NEW, |
| 3603 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3604 | const char* extension_id = good_crx; |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 3605 | service_->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3606 | |
| 3607 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3608 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 3609 | |
| 3610 | service_->ReloadExtensions(); |
| 3611 | |
[email protected] | 26367b6 | 2012-10-04 23:03:32 | [diff] [blame] | 3612 | // The creation flags should not change when reloading the extension. |
| 3613 | const Extension* extension = service_->GetExtensionById(good_crx, true); |
| 3614 | EXPECT_TRUE(extension->from_webstore()); |
| 3615 | EXPECT_TRUE(extension->was_installed_by_default()); |
| 3616 | EXPECT_FALSE(extension->from_bookmark()); |
| 3617 | |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3618 | // Extension counts shouldn't change. |
| 3619 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3620 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 3621 | |
| 3622 | service_->EnableExtension(extension_id); |
| 3623 | |
| 3624 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3625 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3626 | |
[email protected] | 5a73f90 | 2010-06-30 02:29:41 | [diff] [blame] | 3627 | // Need to clear |loaded_| manually before reloading as the |
| 3628 | // EnableExtension() call above inserted into it and |
| 3629 | // UnloadAllExtensions() doesn't send out notifications. |
| 3630 | loaded_.clear(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 3631 | service_->ReloadExtensions(); |
| 3632 | |
| 3633 | // Extension counts shouldn't change. |
| 3634 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3635 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3636 | } |
| 3637 | |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 3638 | // Tests reloading an extension. |
| 3639 | TEST_F(ExtensionServiceTest, ReloadExtension) { |
| 3640 | InitializeEmptyExtensionService(); |
| 3641 | InitializeExtensionProcessManager(); |
| 3642 | |
| 3643 | // Simple extension that should install without error. |
| 3644 | const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 3645 | base::FilePath ext = data_dir_ |
| 3646 | .AppendASCII("good") |
| 3647 | .AppendASCII("Extensions") |
| 3648 | .AppendASCII(extension_id) |
| 3649 | .AppendASCII("1.0.0.0"); |
| 3650 | extensions::UnpackedInstaller::Create(service_)->Load(ext); |
| 3651 | loop_.RunUntilIdle(); |
| 3652 | |
| 3653 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3654 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3655 | |
| 3656 | service_->ReloadExtension(extension_id); |
| 3657 | |
| 3658 | // Extension should be disabled now, waiting to be reloaded. |
| 3659 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3660 | EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 3661 | EXPECT_EQ(Extension::DISABLE_RELOAD, |
| 3662 | service_->extension_prefs()->GetDisableReasons(extension_id)); |
| 3663 | |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 3664 | // Reloading again should not crash. |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 3665 | service_->ReloadExtension(extension_id); |
| 3666 | |
| 3667 | // Finish reloading |
| 3668 | loop_.RunUntilIdle(); |
| 3669 | |
| 3670 | // Extension should be enabled again. |
| 3671 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 3672 | EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3673 | } |
| 3674 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3675 | TEST_F(ExtensionServiceTest, UninstallExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3676 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3677 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3678 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3679 | UninstallExtension(good_crx, false); |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 3680 | EXPECT_EQ(0u, service_->extensions()->size()); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3681 | } |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 3682 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3683 | TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3684 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3685 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3686 | TerminateExtension(good_crx); |
| 3687 | UninstallExtension(good_crx, false); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 3688 | } |
| 3689 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 3690 | // Tests the uninstaller helper. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3691 | TEST_F(ExtensionServiceTest, UninstallExtensionHelper) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3692 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3693 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3694 | UninstallExtension(good_crx, true); |
| 3695 | } |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 3696 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3697 | TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3698 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3699 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 3700 | TerminateExtension(good_crx); |
| 3701 | UninstallExtension(good_crx, true); |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 3702 | } |
| 3703 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3704 | // An extension disabled because of unsupported requirements should re-enabled |
| 3705 | // if updated to a version with supported requirements as long as there are no |
| 3706 | // other disable reasons. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3707 | TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3708 | InitializeEmptyExtensionService(); |
| 3709 | BlackListWebGL(); |
| 3710 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3711 | base::FilePath path = data_dir_.AppendASCII("requirements"); |
| 3712 | base::FilePath pem_path = data_dir_.AppendASCII("requirements") |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3713 | .AppendASCII("v1_good.pem"); |
| 3714 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 3715 | pem_path, |
| 3716 | INSTALL_NEW); |
| 3717 | std::string id = extension_v1->id(); |
| 3718 | EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 3719 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3720 | base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 3721 | |
| 3722 | PackCRX(path.AppendASCII("v2_bad_requirements"), |
| 3723 | pem_path, |
| 3724 | v2_bad_requirements_crx); |
| 3725 | UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3726 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3727 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3728 | base::FilePath v3_good_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 3729 | |
| 3730 | PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); |
| 3731 | UpdateExtension(id, v3_good_crx, ENABLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3732 | EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 3733 | } |
| 3734 | |
| 3735 | // Extensions disabled through user action should stay disabled. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3736 | TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3737 | InitializeEmptyExtensionService(); |
| 3738 | BlackListWebGL(); |
| 3739 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3740 | base::FilePath path = data_dir_.AppendASCII("requirements"); |
| 3741 | base::FilePath pem_path = data_dir_.AppendASCII("requirements") |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3742 | .AppendASCII("v1_good.pem"); |
| 3743 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 3744 | pem_path, |
| 3745 | INSTALL_NEW); |
| 3746 | std::string id = extension_v1->id(); |
| 3747 | service_->DisableExtension(id, Extension::DISABLE_USER_ACTION); |
| 3748 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3749 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3750 | base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 3751 | |
| 3752 | PackCRX(path.AppendASCII("v2_bad_requirements"), |
| 3753 | pem_path, |
| 3754 | v2_bad_requirements_crx); |
| 3755 | UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3756 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3757 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3758 | base::FilePath v3_good_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 3759 | |
| 3760 | PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); |
| 3761 | UpdateExtension(id, v3_good_crx, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3762 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3763 | } |
| 3764 | |
| 3765 | // The extension should not re-enabled because it was disabled from a |
| 3766 | // permission increase. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3767 | TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3768 | InitializeEmptyExtensionService(); |
| 3769 | BlackListWebGL(); |
| 3770 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3771 | base::FilePath path = data_dir_.AppendASCII("requirements"); |
| 3772 | base::FilePath pem_path = data_dir_.AppendASCII("requirements") |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3773 | .AppendASCII("v1_good.pem"); |
| 3774 | const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 3775 | pem_path, |
| 3776 | INSTALL_NEW); |
| 3777 | std::string id = extension_v1->id(); |
| 3778 | EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 3779 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3780 | base::FilePath v2_bad_requirements_and_permissions_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 3781 | |
| 3782 | PackCRX(path.AppendASCII("v2_bad_requirements_and_permissions"), |
| 3783 | pem_path, |
| 3784 | v2_bad_requirements_and_permissions_crx); |
| 3785 | UpdateExtension(id, v2_bad_requirements_and_permissions_crx, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3786 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3787 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3788 | base::FilePath v3_bad_permissions_crx = GetTemporaryFile(); |
[email protected] | a17dfcf | 2012-12-30 02:07:09 | [diff] [blame] | 3789 | |
| 3790 | PackCRX(path.AppendASCII("v3_bad_permissions"), |
| 3791 | pem_path, |
| 3792 | v3_bad_permissions_crx); |
| 3793 | UpdateExtension(id, v3_bad_permissions_crx, INSTALLED); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3794 | EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3795 | } |
| 3796 | |
| 3797 | // Unpacked extensions are not allowed to be installed if they have unsupported |
| 3798 | // requirements. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3799 | TEST_F(ExtensionServiceTest, UnpackedRequirements) { |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3800 | InitializeEmptyExtensionService(); |
| 3801 | BlackListWebGL(); |
| 3802 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3803 | base::FilePath path = data_dir_.AppendASCII("requirements") |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3804 | .AppendASCII("v2_bad_requirements"); |
| 3805 | extensions::UnpackedInstaller::Create(service_)->Load(path); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3806 | loop_.RunUntilIdle(); |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 3807 | EXPECT_EQ(1u, GetErrors().size()); |
| 3808 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 3809 | } |
| 3810 | |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 3811 | class ExtensionCookieCallback { |
| 3812 | public: |
| 3813 | ExtensionCookieCallback() |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 3814 | : result_(false), |
| 3815 | weak_factory_(MessageLoop::current()) {} |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 3816 | |
| 3817 | void SetCookieCallback(bool result) { |
| 3818 | MessageLoop::current()->PostTask( |
[email protected] | 51d0215 | 2011-12-24 05:55:22 | [diff] [blame] | 3819 | FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 3820 | result_ = result; |
| 3821 | } |
| 3822 | |
| 3823 | void GetAllCookiesCallback(const net::CookieList& list) { |
| 3824 | MessageLoop::current()->PostTask( |
[email protected] | 51d0215 | 2011-12-24 05:55:22 | [diff] [blame] | 3825 | FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 3826 | list_ = list; |
| 3827 | } |
| 3828 | net::CookieList list_; |
| 3829 | bool result_; |
[email protected] | 51d0215 | 2011-12-24 05:55:22 | [diff] [blame] | 3830 | base::WeakPtrFactory<MessageLoop> weak_factory_; |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 3831 | }; |
| 3832 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3833 | // Verifies extension state is removed upon uninstall. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3834 | TEST_F(ExtensionServiceTest, ClearExtensionData) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 3835 | InitializeEmptyExtensionService(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 3836 | ExtensionCookieCallback callback; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3837 | |
| 3838 | // Load a test extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3839 | base::FilePath path = data_dir_; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3840 | path = path.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3841 | const Extension* extension = InstallCRX(path, INSTALL_NEW); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3842 | ASSERT_TRUE(extension); |
| 3843 | GURL ext_url(extension->url()); |
[email protected] | 391550b | 2013-05-10 04:34:12 | [diff] [blame] | 3844 | base::string16 origin_id = webkit_base::GetOriginIdentifierFromURL(ext_url); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3845 | |
| 3846 | // Set a cookie for the extension. |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 3847 | net::CookieMonster* cookie_monster = |
| 3848 | profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> |
| 3849 | cookie_store()->GetCookieMonster(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3850 | ASSERT_TRUE(cookie_monster); |
| 3851 | net::CookieOptions options; |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 3852 | cookie_monster->SetCookieWithOptionsAsync( |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 3853 | ext_url, "dummy=value", options, |
| 3854 | base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 3855 | base::Unretained(&callback))); |
| 3856 | loop_.RunUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 3857 | EXPECT_TRUE(callback.result_); |
| 3858 | |
| 3859 | cookie_monster->GetAllCookiesForURLAsync( |
| 3860 | ext_url, |
| 3861 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 3862 | base::Unretained(&callback))); |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 3863 | loop_.RunUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 3864 | EXPECT_EQ(1U, callback.list_.size()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3865 | |
| 3866 | // Open a database. |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 3867 | webkit_database::DatabaseTracker* db_tracker = |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 3868 | BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 3869 | GetDatabaseTracker(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3870 | string16 db_name = UTF8ToUTF16("db"); |
| 3871 | string16 description = UTF8ToUTF16("db_description"); |
| 3872 | int64 size; |
[email protected] | 7c5f2ec | 2011-05-26 19:15:26 | [diff] [blame] | 3873 | db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3874 | db_tracker->DatabaseClosed(origin_id, db_name); |
| 3875 | std::vector<webkit_database::OriginInfo> origins; |
| 3876 | db_tracker->GetAllOriginsInfo(&origins); |
| 3877 | EXPECT_EQ(1U, origins.size()); |
| 3878 | EXPECT_EQ(origin_id, origins[0].GetOrigin()); |
| 3879 | |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 3880 | // Create local storage. We only simulate this by creating the backing files. |
| 3881 | // Note: This test depends on details of how the dom_storage library |
| 3882 | // stores data in the host file system. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3883 | base::FilePath lso_dir_path = |
| 3884 | profile_->GetPath().AppendASCII("Local Storage"); |
| 3885 | base::FilePath lso_file_path = lso_dir_path.AppendASCII( |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 3886 | UTF16ToUTF8(origin_id) + ".localstorage"); |
| 3887 | EXPECT_TRUE(file_util::CreateDirectory(lso_dir_path)); |
| 3888 | EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); |
| 3889 | EXPECT_TRUE(file_util::PathExists(lso_file_path)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3890 | |
[email protected] | ab30809 | 2011-08-25 23:37:19 | [diff] [blame] | 3891 | // Create indexed db. Similarly, it is enough to only simulate this by |
| 3892 | // creating the directory on the disk. |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 3893 | IndexedDBContext* idb_context = |
| 3894 | BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 3895 | GetIndexedDBContext(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3896 | base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
[email protected] | ab30809 | 2011-08-25 23:37:19 | [diff] [blame] | 3897 | EXPECT_TRUE(file_util::CreateDirectory(idb_path)); |
| 3898 | EXPECT_TRUE(file_util::DirectoryExists(idb_path)); |
[email protected] | e1dcf92 | 2010-11-22 19:12:12 | [diff] [blame] | 3899 | |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3900 | // Uninstall the extension. |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 3901 | service_->UninstallExtension(good_crx, false, NULL); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3902 | loop_.RunUntilIdle(); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3903 | |
| 3904 | // Check that the cookie is gone. |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 3905 | cookie_monster->GetAllCookiesForURLAsync( |
| 3906 | ext_url, |
| 3907 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 3908 | base::Unretained(&callback))); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3909 | loop_.RunUntilIdle(); |
[email protected] | c4148a7 | 2011-08-09 23:04:20 | [diff] [blame] | 3910 | EXPECT_EQ(0U, callback.list_.size()); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3911 | |
| 3912 | // The database should have vanished as well. |
| 3913 | origins.clear(); |
| 3914 | db_tracker->GetAllOriginsInfo(&origins); |
| 3915 | EXPECT_EQ(0U, origins.size()); |
| 3916 | |
| 3917 | // Check that the LSO file has been removed. |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 3918 | EXPECT_FALSE(file_util::PathExists(lso_file_path)); |
[email protected] | e1dcf92 | 2010-11-22 19:12:12 | [diff] [blame] | 3919 | |
| 3920 | // Check if the indexed db has disappeared too. |
[email protected] | ab30809 | 2011-08-25 23:37:19 | [diff] [blame] | 3921 | EXPECT_FALSE(file_util::DirectoryExists(idb_path)); |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 3922 | } |
| 3923 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3924 | // Verifies app state is removed upon uninstall. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3925 | TEST_F(ExtensionServiceTest, ClearAppData) { |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3926 | InitializeEmptyExtensionService(); |
| 3927 | InitializeRequestContext(); |
| 3928 | ExtensionCookieCallback callback; |
| 3929 | |
| 3930 | int pref_count = 0; |
| 3931 | |
| 3932 | // Install app1 with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3933 | const Extension* extension = |
| 3934 | PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3935 | ValidatePrefKeyCount(++pref_count); |
| 3936 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3937 | const std::string id1 = extension->id(); |
| 3938 | EXPECT_TRUE(extension->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 3939 | APIPermission::kUnlimitedStorage)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3940 | const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); |
| 3941 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 3942 | IsStorageUnlimited(origin1)); |
[email protected] | 391550b | 2013-05-10 04:34:12 | [diff] [blame] | 3943 | base::string16 origin_id = webkit_base::GetOriginIdentifierFromURL(origin1); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3944 | |
| 3945 | // Install app2 from the same origin with unlimited storage. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 3946 | extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3947 | ValidatePrefKeyCount(++pref_count); |
| 3948 | ASSERT_EQ(2u, service_->extensions()->size()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3949 | const std::string id2 = extension->id(); |
| 3950 | EXPECT_TRUE(extension->HasAPIPermission( |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 3951 | APIPermission::kUnlimitedStorage)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3952 | EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 3953 | extension->GetFullLaunchURL())); |
| 3954 | const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 3955 | EXPECT_EQ(origin1, origin2); |
| 3956 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 3957 | IsStorageUnlimited(origin2)); |
| 3958 | |
| 3959 | // Set a cookie for the extension. |
[email protected] | a576851 | 2013-04-12 19:35:35 | [diff] [blame] | 3960 | net::CookieMonster* cookie_monster = |
| 3961 | profile_->GetRequestContext()->GetURLRequestContext()-> |
| 3962 | cookie_store()->GetCookieMonster(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3963 | ASSERT_TRUE(cookie_monster); |
| 3964 | net::CookieOptions options; |
| 3965 | cookie_monster->SetCookieWithOptionsAsync( |
| 3966 | origin1, "dummy=value", options, |
| 3967 | base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 3968 | base::Unretained(&callback))); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3969 | loop_.RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3970 | EXPECT_TRUE(callback.result_); |
| 3971 | |
| 3972 | cookie_monster->GetAllCookiesForURLAsync( |
| 3973 | origin1, |
| 3974 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 3975 | base::Unretained(&callback))); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 3976 | loop_.RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3977 | EXPECT_EQ(1U, callback.list_.size()); |
| 3978 | |
| 3979 | // Open a database. |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 3980 | webkit_database::DatabaseTracker* db_tracker = |
[email protected] | 5c8e67c | 2012-08-29 00:48:52 | [diff] [blame] | 3981 | BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 3982 | GetDatabaseTracker(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 3983 | string16 db_name = UTF8ToUTF16("db"); |
| 3984 | string16 description = UTF8ToUTF16("db_description"); |
| 3985 | int64 size; |
| 3986 | db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
| 3987 | db_tracker->DatabaseClosed(origin_id, db_name); |
| 3988 | std::vector<webkit_database::OriginInfo> origins; |
| 3989 | db_tracker->GetAllOriginsInfo(&origins); |
| 3990 | EXPECT_EQ(1U, origins.size()); |
| 3991 | EXPECT_EQ(origin_id, origins[0].GetOrigin()); |
| 3992 | |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 3993 | // Create local storage. We only simulate this by creating the backing files. |
| 3994 | // Note: This test depends on details of how the dom_storage library |
| 3995 | // stores data in the host file system. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3996 | base::FilePath lso_dir_path = |
| 3997 | profile_->GetPath().AppendASCII("Local Storage"); |
| 3998 | base::FilePath lso_file_path = lso_dir_path.AppendASCII( |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 3999 | UTF16ToUTF8(origin_id) + ".localstorage"); |
| 4000 | EXPECT_TRUE(file_util::CreateDirectory(lso_dir_path)); |
| 4001 | EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); |
| 4002 | EXPECT_TRUE(file_util::PathExists(lso_file_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4003 | |
| 4004 | // Create indexed db. Similarly, it is enough to only simulate this by |
| 4005 | // creating the directory on the disk. |
[email protected] | b1b502e | 2012-09-16 07:31:43 | [diff] [blame] | 4006 | IndexedDBContext* idb_context = |
| 4007 | BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 4008 | GetIndexedDBContext(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4009 | base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4010 | EXPECT_TRUE(file_util::CreateDirectory(idb_path)); |
| 4011 | EXPECT_TRUE(file_util::DirectoryExists(idb_path)); |
| 4012 | |
| 4013 | // Uninstall one of them, unlimited storage should still be granted |
| 4014 | // to the origin. |
| 4015 | UninstallExtension(id1, false); |
| 4016 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 4017 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 4018 | IsStorageUnlimited(origin1)); |
| 4019 | |
| 4020 | // Check that the cookie is still there. |
| 4021 | cookie_monster->GetAllCookiesForURLAsync( |
| 4022 | origin1, |
| 4023 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4024 | base::Unretained(&callback))); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4025 | loop_.RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4026 | EXPECT_EQ(1U, callback.list_.size()); |
| 4027 | |
| 4028 | // Now uninstall the other. Storage should be cleared for the apps. |
| 4029 | UninstallExtension(id2, false); |
| 4030 | EXPECT_EQ(0u, service_->extensions()->size()); |
| 4031 | EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 4032 | IsStorageUnlimited(origin1)); |
| 4033 | |
| 4034 | // Check that the cookie is gone. |
| 4035 | cookie_monster->GetAllCookiesForURLAsync( |
| 4036 | origin1, |
| 4037 | base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4038 | base::Unretained(&callback))); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4039 | loop_.RunUntilIdle(); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4040 | EXPECT_EQ(0U, callback.list_.size()); |
| 4041 | |
| 4042 | // The database should have vanished as well. |
| 4043 | origins.clear(); |
| 4044 | db_tracker->GetAllOriginsInfo(&origins); |
| 4045 | EXPECT_EQ(0U, origins.size()); |
| 4046 | |
| 4047 | // Check that the LSO file has been removed. |
[email protected] | 98823c68 | 2012-06-11 21:18:24 | [diff] [blame] | 4048 | EXPECT_FALSE(file_util::PathExists(lso_file_path)); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 4049 | |
| 4050 | // Check if the indexed db has disappeared too. |
| 4051 | EXPECT_FALSE(file_util::DirectoryExists(idb_path)); |
| 4052 | } |
| 4053 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4054 | // Tests loading single extensions (like --load-extension) |
[email protected] | e3f610b | 2013-05-03 02:22:38 | [diff] [blame] | 4055 | // Flaky crashes. http://crbug.com/231806 |
| 4056 | TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4057 | InitializeEmptyExtensionService(); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 4058 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4059 | base::FilePath ext1 = data_dir_ |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 4060 | .AppendASCII("good") |
| 4061 | .AppendASCII("Extensions") |
[email protected] | 5a2721f6 | 2009-06-13 07:08:20 | [diff] [blame] | 4062 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 4063 | .AppendASCII("1.0.0.0"); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4064 | extensions::UnpackedInstaller::Create(service_)->Load(ext1); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4065 | loop_.RunUntilIdle(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 4066 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4067 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 4068 | EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location()); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4069 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 4070 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 4071 | ValidatePrefKeyCount(1); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4072 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4073 | base::FilePath no_manifest = data_dir_ |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 4074 | .AppendASCII("bad") |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 4075 | // .AppendASCII("Extensions") |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 4076 | .AppendASCII("cccccccccccccccccccccccccccccccc") |
| 4077 | .AppendASCII("1"); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4078 | extensions::UnpackedInstaller::Create(service_)->Load(no_manifest); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4079 | loop_.RunUntilIdle(); |
[email protected] | bb28e06 | 2009-02-27 17:19:18 | [diff] [blame] | 4080 | EXPECT_EQ(1u, GetErrors().size()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4081 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4082 | EXPECT_EQ(1u, service_->extensions()->size()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4083 | |
| 4084 | // Test uninstall. |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4085 | std::string id = loaded_[0]->id(); |
| 4086 | EXPECT_FALSE(unloaded_id_.length()); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 4087 | service_->UninstallExtension(id, false, NULL); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4088 | loop_.RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4089 | EXPECT_EQ(id, unloaded_id_); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4090 | ASSERT_EQ(0u, loaded_.size()); |
| 4091 | EXPECT_EQ(0u, service_->extensions()->size()); |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 4092 | } |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4093 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4094 | // Tests that we generate IDs when they are not specified in the manifest for |
| 4095 | // --load-extension. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4096 | TEST_F(ExtensionServiceTest, GenerateID) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4097 | InitializeEmptyExtensionService(); |
[email protected] | fbcc4030 | 2009-06-12 20:45:45 | [diff] [blame] | 4098 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4099 | base::FilePath no_id_ext = data_dir_.AppendASCII("no_id"); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4100 | extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4101 | loop_.RunUntilIdle(); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4102 | EXPECT_EQ(0u, GetErrors().size()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4103 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 4104 | ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 4105 | EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4106 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 4107 | ValidatePrefKeyCount(1); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4108 | |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 4109 | std::string previous_id = loaded_[0]->id(); |
| 4110 | |
| 4111 | // If we reload the same path, we should get the same extension ID. |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4112 | extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4113 | loop_.RunUntilIdle(); |
[email protected] | 84ac7f3 | 2009-10-06 06:17:54 | [diff] [blame] | 4114 | ASSERT_EQ(1u, loaded_.size()); |
| 4115 | ASSERT_EQ(previous_id, loaded_[0]->id()); |
[email protected] | 0b34496 | 2009-03-31 04:21:45 | [diff] [blame] | 4116 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4117 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4118 | void ExtensionServiceTest::TestExternalProvider( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4119 | MockExtensionProvider* provider, Manifest::Location location) { |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4120 | // Verify that starting with no providers loads no extensions. |
| 4121 | service_->Init(); |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4122 | ASSERT_EQ(0u, loaded_.size()); |
| 4123 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4124 | provider->set_visit_count(0); |
| 4125 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4126 | // Register a test extension externally using the mock registry provider. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4127 | base::FilePath source_path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4128 | |
[email protected] | a1257b1 | 2009-06-12 02:51:34 | [diff] [blame] | 4129 | // Add the extension. |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4130 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4131 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4132 | // Reloading extensions should find our externally registered extension |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4133 | // and install it. |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 4134 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4135 | loop_.RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4136 | |
| 4137 | ASSERT_EQ(0u, GetErrors().size()); |
| 4138 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4139 | ASSERT_EQ(location, loaded_[0]->location()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4140 | ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4141 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4142 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4143 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4144 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4145 | // Reload extensions without changing anything. The extension should be |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4146 | // loaded again. |
| 4147 | loaded_.clear(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 4148 | service_->ReloadExtensions(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4149 | loop_.RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4150 | ASSERT_EQ(0u, GetErrors().size()); |
| 4151 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4152 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4153 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4154 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 4155 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4156 | // Now update the extension with a new version. We should get upgraded. |
| 4157 | source_path = source_path.DirName().AppendASCII("good2.crx"); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4158 | provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4159 | |
| 4160 | loaded_.clear(); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 4161 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4162 | loop_.RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4163 | ASSERT_EQ(0u, GetErrors().size()); |
| 4164 | ASSERT_EQ(1u, loaded_.size()); |
| 4165 | ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4166 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4167 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4168 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4169 | |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4170 | // Uninstall the extension and reload. Nothing should happen because the |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4171 | // preference should prevent us from reinstalling. |
| 4172 | std::string id = loaded_[0]->id(); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 4173 | bool no_uninstall = management_policy_->MustRemainEnabled(loaded_[0], NULL); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 4174 | service_->UninstallExtension(id, false, NULL); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4175 | loop_.RunUntilIdle(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4176 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4177 | base::FilePath install_path = extensions_install_dir_.AppendASCII(id); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 4178 | if (no_uninstall) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 4179 | // Policy controlled extensions should not have been touched by uninstall. |
| 4180 | ASSERT_TRUE(file_util::PathExists(install_path)); |
| 4181 | } else { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4182 | // The extension should also be gone from the install directory. |
| 4183 | ASSERT_FALSE(file_util::PathExists(install_path)); |
| 4184 | loaded_.clear(); |
| 4185 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4186 | loop_.RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4187 | ASSERT_EQ(0u, loaded_.size()); |
| 4188 | ValidatePrefKeyCount(1); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 4189 | ValidateIntegerPref(good_crx, "state", |
| 4190 | Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4191 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 4192 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4193 | // Now clear the preference and reinstall. |
| 4194 | SetPrefInteg(good_crx, "state", Extension::ENABLED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4195 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4196 | loaded_.clear(); |
| 4197 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4198 | loop_.RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4199 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4200 | } |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4201 | ValidatePrefKeyCount(1); |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 4202 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4203 | ValidateIntegerPref(good_crx, "location", location); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4204 | |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 4205 | if (management_policy_->MustRemainEnabled(loaded_[0], NULL)) { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 4206 | EXPECT_EQ(2, provider->visit_count()); |
| 4207 | } else { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4208 | // Now test an externally triggered uninstall (deleting the registry key or |
| 4209 | // the pref entry). |
| 4210 | provider->RemoveExtension(good_crx); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4211 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4212 | loaded_.clear(); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 4213 | service_->OnExternalProviderReady(provider); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4214 | loop_.RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4215 | ASSERT_EQ(0u, loaded_.size()); |
| 4216 | ValidatePrefKeyCount(0); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 4217 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4218 | // The extension should also be gone from the install directory. |
| 4219 | ASSERT_FALSE(file_util::PathExists(install_path)); |
[email protected] | abe7a894 | 2009-06-23 05:14:29 | [diff] [blame] | 4220 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4221 | // Now test the case where user uninstalls and then the extension is removed |
| 4222 | // from the external provider. |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 4223 | provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4224 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4225 | loop_.RunUntilIdle(); |
[email protected] | abe7a894 | 2009-06-23 05:14:29 | [diff] [blame] | 4226 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4227 | ASSERT_EQ(1u, loaded_.size()); |
| 4228 | ASSERT_EQ(0u, GetErrors().size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4229 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4230 | // User uninstalls. |
| 4231 | loaded_.clear(); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 4232 | service_->UninstallExtension(id, false, NULL); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4233 | loop_.RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4234 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4235 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4236 | // Then remove the extension from the extension provider. |
| 4237 | provider->RemoveExtension(good_crx); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4238 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4239 | // Should still be at 0. |
| 4240 | loaded_.clear(); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4241 | extensions::InstalledLoader(service_).LoadAllExtensions(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4242 | loop_.RunUntilIdle(); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4243 | ASSERT_EQ(0u, loaded_.size()); |
| 4244 | ValidatePrefKeyCount(1); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4245 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4246 | EXPECT_EQ(5, provider->visit_count()); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4247 | } |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | // Tests the external installation feature |
| 4251 | #if defined(OS_WIN) |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4252 | TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4253 | // This should all work, even when normal extension installation is disabled. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4254 | InitializeEmptyExtensionService(); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4255 | set_extensions_enabled(false); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4256 | |
| 4257 | // Now add providers. Extension system takes ownership of the objects. |
| 4258 | MockExtensionProvider* reg_provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4259 | new MockExtensionProvider(service_, Manifest::EXTERNAL_REGISTRY); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4260 | AddMockExternalProvider(reg_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4261 | TestExternalProvider(reg_provider, Manifest::EXTERNAL_REGISTRY); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4262 | } |
| 4263 | #endif |
| 4264 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4265 | TEST_F(ExtensionServiceTest, ExternalInstallPref) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4266 | InitializeEmptyExtensionService(); |
[email protected] | d55e760 | 2009-12-16 04:20:42 | [diff] [blame] | 4267 | |
| 4268 | // Now add providers. Extension system takes ownership of the objects. |
| 4269 | MockExtensionProvider* pref_provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4270 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4271 | |
| 4272 | AddMockExternalProvider(pref_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4273 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4274 | } |
| 4275 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4276 | TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4277 | // This should all work, even when normal extension installation is disabled. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4278 | InitializeEmptyExtensionService(); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4279 | set_extensions_enabled(false); |
[email protected] | 55196e9 | 2010-09-29 15:04:46 | [diff] [blame] | 4280 | |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4281 | // TODO(skerner): The mock provider is not a good model of a provider |
| 4282 | // that works with update URLs, because it adds file and version info. |
| 4283 | // Extend the mock to work with update URLs. This test checks the |
| 4284 | // behavior that is common to all external extension visitors. The |
| 4285 | // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| 4286 | // what the visitor does results in an extension being downloaded and |
| 4287 | // installed. |
[email protected] | 55196e9 | 2010-09-29 15:04:46 | [diff] [blame] | 4288 | MockExtensionProvider* pref_provider = |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 4289 | new MockExtensionProvider(service_, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4290 | Manifest::EXTERNAL_PREF_DOWNLOAD); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 4291 | AddMockExternalProvider(pref_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4292 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF_DOWNLOAD); |
[email protected] | 55196e9 | 2010-09-29 15:04:46 | [diff] [blame] | 4293 | } |
| 4294 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4295 | TEST_F(ExtensionServiceTest, ExternalInstallPolicyUpdateUrl) { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4296 | // This should all work, even when normal extension installation is disabled. |
| 4297 | InitializeEmptyExtensionService(); |
| 4298 | set_extensions_enabled(false); |
| 4299 | |
| 4300 | // TODO(skerner): The mock provider is not a good model of a provider |
| 4301 | // that works with update URLs, because it adds file and version info. |
| 4302 | // Extend the mock to work with update URLs. This test checks the |
| 4303 | // behavior that is common to all external extension visitors. The |
| 4304 | // browser test ExtensionManagementTest.ExternalUrlUpdate tests that |
| 4305 | // what the visitor does results in an extension being downloaded and |
| 4306 | // installed. |
| 4307 | MockExtensionProvider* pref_provider = |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 4308 | new MockExtensionProvider(service_, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4309 | Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4310 | AddMockExternalProvider(pref_provider); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4311 | TestExternalProvider(pref_provider, Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 4312 | } |
| 4313 | |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4314 | // Tests that external extensions get uninstalled when the external extension |
| 4315 | // providers can't account for them. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4316 | TEST_F(ExtensionServiceTest, ExternalUninstall) { |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4317 | // Start the extensions service with one external extension already installed. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4318 | base::FilePath source_install_dir = data_dir_ |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4319 | .AppendASCII("good") |
| 4320 | .AppendASCII("Extensions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4321 | base::FilePath pref_path = source_install_dir |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4322 | .DirName() |
| 4323 | .AppendASCII("PreferencesExternal"); |
| 4324 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 4325 | // This initializes the extensions service with no ExternalProviders. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4326 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4327 | set_extensions_enabled(false); |
| 4328 | |
| 4329 | service_->Init(); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4330 | |
| 4331 | ASSERT_EQ(0u, GetErrors().size()); |
[email protected] | 1f4728f | 2012-12-05 20:40:05 | [diff] [blame] | 4332 | ASSERT_EQ(0u, loaded_.size()); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4333 | |
| 4334 | // Verify that it's not the disabled extensions flag causing it not to load. |
| 4335 | set_extensions_enabled(true); |
| 4336 | service_->ReloadExtensions(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4337 | loop_.RunUntilIdle(); |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 4338 | |
| 4339 | ASSERT_EQ(0u, GetErrors().size()); |
| 4340 | ASSERT_EQ(0u, loaded_.size()); |
| 4341 | } |
| 4342 | |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4343 | // Test that running multiple update checks simultaneously does not |
| 4344 | // keep the update from succeeding. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4345 | TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4346 | InitializeEmptyExtensionService(); |
| 4347 | |
| 4348 | MockExtensionProvider* provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4349 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4350 | AddMockExternalProvider(provider); |
| 4351 | |
| 4352 | // Verify that starting with no providers loads no extensions. |
| 4353 | service_->Init(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4354 | ASSERT_EQ(0u, loaded_.size()); |
| 4355 | |
| 4356 | // Start two checks for updates. |
| 4357 | provider->set_visit_count(0); |
| 4358 | service_->CheckForExternalUpdates(); |
| 4359 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4360 | loop_.RunUntilIdle(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4361 | |
| 4362 | // Two calls should cause two checks for external extensions. |
| 4363 | EXPECT_EQ(2, provider->visit_count()); |
| 4364 | EXPECT_EQ(0u, GetErrors().size()); |
| 4365 | EXPECT_EQ(0u, loaded_.size()); |
| 4366 | |
| 4367 | // Register a test extension externally using the mock registry provider. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4368 | base::FilePath source_path = data_dir_.AppendASCII("good.crx"); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4369 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); |
| 4370 | |
| 4371 | // Two checks for external updates should find the extension, and install it |
| 4372 | // once. |
| 4373 | provider->set_visit_count(0); |
| 4374 | service_->CheckForExternalUpdates(); |
| 4375 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4376 | loop_.RunUntilIdle(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4377 | EXPECT_EQ(2, provider->visit_count()); |
| 4378 | ASSERT_EQ(0u, GetErrors().size()); |
| 4379 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4380 | ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4381 | ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); |
| 4382 | ValidatePrefKeyCount(1); |
| 4383 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4384 | ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4385 | |
| 4386 | provider->RemoveExtension(good_crx); |
| 4387 | provider->set_visit_count(0); |
| 4388 | service_->CheckForExternalUpdates(); |
| 4389 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4390 | loop_.RunUntilIdle(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 4391 | |
| 4392 | // Two calls should cause two checks for external extensions. |
| 4393 | // Because the external source no longer includes good_crx, |
| 4394 | // good_crx will be uninstalled. So, expect that no extensions |
| 4395 | // are loaded. |
| 4396 | EXPECT_EQ(2, provider->visit_count()); |
| 4397 | EXPECT_EQ(0u, GetErrors().size()); |
| 4398 | EXPECT_EQ(0u, loaded_.size()); |
| 4399 | } |
| 4400 | |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 4401 | namespace { |
| 4402 | class ScopedBrowserLocale { |
| 4403 | public: |
| 4404 | explicit ScopedBrowserLocale(const std::string& new_locale) |
| 4405 | : old_locale_(g_browser_process->GetApplicationLocale()) { |
| 4406 | g_browser_process->SetApplicationLocale(new_locale); |
| 4407 | } |
| 4408 | |
| 4409 | ~ScopedBrowserLocale() { |
| 4410 | g_browser_process->SetApplicationLocale(old_locale_); |
| 4411 | } |
| 4412 | |
| 4413 | private: |
| 4414 | std::string old_locale_; |
| 4415 | }; |
| 4416 | } |
| 4417 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4418 | TEST_F(ExtensionServiceTest, ExternalPrefProvider) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4419 | InitializeEmptyExtensionService(); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4420 | |
| 4421 | // Test some valid extension records. |
| 4422 | // Set a base path to avoid erroring out on relative paths. |
| 4423 | // Paths starting with // are absolute on every platform we support. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4424 | base::FilePath base_path(FILE_PATH_LITERAL("//base/path")); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4425 | ASSERT_TRUE(base_path.IsAbsolute()); |
| 4426 | MockProviderVisitor visitor(base_path); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4427 | std::string json_data = |
| 4428 | "{" |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4429 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4430 | " \"external_crx\": \"RandomExtension.crx\"," |
| 4431 | " \"external_version\": \"1.0\"" |
| 4432 | " }," |
| 4433 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 4434 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 4435 | " \"external_version\": \"2.0\"" |
| 4436 | " }," |
| 4437 | " \"cccccccccccccccccccccccccccccccc\": {" |
[email protected] | a424d84c | 2010-09-24 09:31:15 | [diff] [blame] | 4438 | " \"external_update_url\": \"http:\\\\foo.com/update\"" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4439 | " }" |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4440 | "}"; |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4441 | EXPECT_EQ(3, visitor.Visit(json_data)); |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4442 | |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4443 | // Simulate an external_extensions.json file that contains seven invalid |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4444 | // records: |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4445 | // - One that is missing the 'external_crx' key. |
| 4446 | // - One that is missing the 'external_version' key. |
| 4447 | // - One that is specifying .. in the path. |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 4448 | // - One that specifies both a file and update URL. |
| 4449 | // - One that specifies no file or update URL. |
| 4450 | // - One that has an update URL that is not well formed. |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4451 | // - One that contains a malformed version. |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 4452 | // - One that has an invalid id. |
| 4453 | // - One that has a non-dictionary value. |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 4454 | // - One that has an integer 'external_version' instead of a string. |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4455 | // The final extension is valid, and we check that it is read to make sure |
| 4456 | // failures don't stop valid records from being read. |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4457 | json_data = |
| 4458 | "{" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4459 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 4460 | " \"external_version\": \"1.0\"" |
| 4461 | " }," |
| 4462 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 4463 | " \"external_crx\": \"RandomExtension.crx\"" |
| 4464 | " }," |
| 4465 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 4466 | " \"external_crx\": \"..\\\\foo\\\\RandomExtension2.crx\"," |
| 4467 | " \"external_version\": \"2.0\"" |
| 4468 | " }," |
| 4469 | " \"dddddddddddddddddddddddddddddddd\": {" |
| 4470 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 4471 | " \"external_version\": \"2.0\"," |
| 4472 | " \"external_update_url\": \"http:\\\\foo.com/update\"" |
| 4473 | " }," |
| 4474 | " \"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\": {" |
| 4475 | " }," |
| 4476 | " \"ffffffffffffffffffffffffffffffff\": {" |
| 4477 | " \"external_update_url\": \"This string is not a valid URL\"" |
| 4478 | " }," |
| 4479 | " \"gggggggggggggggggggggggggggggggg\": {" |
| 4480 | " \"external_crx\": \"RandomExtension3.crx\"," |
| 4481 | " \"external_version\": \"This is not a valid version!\"" |
| 4482 | " }," |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 4483 | " \"This is not a valid id!\": {}," |
| 4484 | " \"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\": true," |
[email protected] | 0d461c5 | 2012-07-03 19:29:41 | [diff] [blame] | 4485 | " \"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\": {" |
| 4486 | " \"external_crx\": \"RandomExtension4.crx\"," |
| 4487 | " \"external_version\": 1.0" |
| 4488 | " }," |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 4489 | " \"pppppppppppppppppppppppppppppppp\": {" |
[email protected] | 9e54cb57 | 2010-09-03 20:08:06 | [diff] [blame] | 4490 | " \"external_crx\": \"RandomValidExtension.crx\"," |
| 4491 | " \"external_version\": \"1.0\"" |
| 4492 | " }" |
[email protected] | 27b985d | 2009-06-25 17:53:15 | [diff] [blame] | 4493 | "}"; |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 4494 | EXPECT_EQ(1, visitor.Visit(json_data)); |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4495 | |
| 4496 | // Check that if a base path is not provided, use of a relative |
| 4497 | // path fails. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4498 | base::FilePath empty; |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 4499 | MockProviderVisitor visitor_no_relative_paths(empty); |
| 4500 | |
| 4501 | // Use absolute paths. Expect success. |
| 4502 | json_data = |
| 4503 | "{" |
| 4504 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 4505 | " \"external_crx\": \"//RandomExtension1.crx\"," |
| 4506 | " \"external_version\": \"3.0\"" |
| 4507 | " }," |
| 4508 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 4509 | " \"external_crx\": \"//path/to/RandomExtension2.crx\"," |
| 4510 | " \"external_version\": \"3.0\"" |
| 4511 | " }" |
| 4512 | "}"; |
| 4513 | EXPECT_EQ(2, visitor_no_relative_paths.Visit(json_data)); |
| 4514 | |
| 4515 | // Use a relative path. Expect that it will error out. |
| 4516 | json_data = |
| 4517 | "{" |
| 4518 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 4519 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 4520 | " \"external_version\": \"3.0\"" |
| 4521 | " }" |
| 4522 | "}"; |
| 4523 | EXPECT_EQ(0, visitor_no_relative_paths.Visit(json_data)); |
[email protected] | 9d32ded07 | 2011-10-11 16:31:05 | [diff] [blame] | 4524 | |
| 4525 | // Test supported_locales. |
| 4526 | json_data = |
| 4527 | "{" |
| 4528 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 4529 | " \"external_crx\": \"RandomExtension.crx\"," |
| 4530 | " \"external_version\": \"1.0\"," |
| 4531 | " \"supported_locales\": [ \"en\" ]" |
| 4532 | " }," |
| 4533 | " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {" |
| 4534 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 4535 | " \"external_version\": \"2.0\"," |
| 4536 | " \"supported_locales\": [ \"en-GB\" ]" |
| 4537 | " }," |
| 4538 | " \"cccccccccccccccccccccccccccccccc\": {" |
| 4539 | " \"external_crx\": \"RandomExtension2.crx\"," |
| 4540 | " \"external_version\": \"3.0\"," |
| 4541 | " \"supported_locales\": [ \"en_US\", \"fr\" ]" |
| 4542 | " }" |
| 4543 | "}"; |
| 4544 | { |
| 4545 | ScopedBrowserLocale guard("en-US"); |
| 4546 | EXPECT_EQ(2, visitor.Visit(json_data)); |
| 4547 | } |
[email protected] | f121003b | 2012-05-04 21:57:47 | [diff] [blame] | 4548 | |
| 4549 | // Test is_bookmark_app. |
| 4550 | MockProviderVisitor from_bookmark_visitor( |
| 4551 | base_path, Extension::FROM_BOOKMARK); |
| 4552 | json_data = |
| 4553 | "{" |
| 4554 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 4555 | " \"external_crx\": \"RandomExtension.crx\"," |
| 4556 | " \"external_version\": \"1.0\"," |
| 4557 | " \"is_bookmark_app\": true" |
| 4558 | " }" |
| 4559 | "}"; |
| 4560 | EXPECT_EQ(1, from_bookmark_visitor.Visit(json_data)); |
[email protected] | 7425d7df | 2012-11-28 14:35:42 | [diff] [blame] | 4561 | |
| 4562 | // Test is_from_webstore. |
| 4563 | MockProviderVisitor from_webstore_visitor( |
| 4564 | base_path, Extension::FROM_WEBSTORE); |
| 4565 | json_data = |
| 4566 | "{" |
| 4567 | " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {" |
| 4568 | " \"external_crx\": \"RandomExtension.crx\"," |
| 4569 | " \"external_version\": \"1.0\"," |
| 4570 | " \"is_from_webstore\": true" |
| 4571 | " }" |
| 4572 | "}"; |
| 4573 | EXPECT_EQ(1, from_webstore_visitor.Visit(json_data)); |
[email protected] | e18236b | 2009-06-22 21:32:10 | [diff] [blame] | 4574 | } |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 4575 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 4576 | // Test loading good extensions from the profile directory. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4577 | TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) { |
[email protected] | 6884a80 | 2012-08-07 03:55:22 | [diff] [blame] | 4578 | // Ensure we're testing in "en" and leave global state untouched. |
| 4579 | extension_l10n_util::ScopedLocaleForTest testLocale("en"); |
| 4580 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 4581 | // Initialize the test dir with a good Preferences/extensions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4582 | base::FilePath source_install_dir = data_dir_ |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 4583 | .AppendASCII("l10n"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4584 | base::FilePath pref_path = source_install_dir.AppendASCII("Preferences"); |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4585 | InitializeInstalledExtensionService(pref_path, source_install_dir); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 4586 | |
| 4587 | service_->Init(); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 4588 | |
| 4589 | ASSERT_EQ(3u, loaded_.size()); |
| 4590 | |
| 4591 | // This was equal to "sr" on load. |
| 4592 | ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en"); |
| 4593 | |
| 4594 | // These are untouched by re-localization. |
| 4595 | ValidateStringPref(loaded_[1]->id(), keys::kCurrentLocale, "en"); |
| 4596 | EXPECT_FALSE(IsPrefExist(loaded_[1]->id(), keys::kCurrentLocale)); |
| 4597 | |
| 4598 | // This one starts with Serbian name, and gets re-localized into English. |
| 4599 | EXPECT_EQ("My name is simple.", loaded_[0]->name()); |
| 4600 | |
| 4601 | // These are untouched by re-localization. |
| 4602 | EXPECT_EQ("My name is simple.", loaded_[1]->name()); |
| 4603 | EXPECT_EQ("no l10n", loaded_[2]->name()); |
| 4604 | } |
| 4605 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4606 | class ExtensionsReadyRecorder : public content::NotificationObserver { |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4607 | public: |
| 4608 | ExtensionsReadyRecorder() : ready_(false) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4609 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 4610 | content::NotificationService::AllSources()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | void set_ready(bool value) { ready_ = value; } |
| 4614 | bool ready() { return ready_; } |
| 4615 | |
| 4616 | private: |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4617 | virtual void Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4618 | const content::NotificationSource& source, |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 4619 | const content::NotificationDetails& details) OVERRIDE { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 4620 | switch (type) { |
| 4621 | case chrome::NOTIFICATION_EXTENSIONS_READY: |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4622 | ready_ = true; |
| 4623 | break; |
| 4624 | default: |
| 4625 | NOTREACHED(); |
| 4626 | } |
| 4627 | } |
| 4628 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 4629 | content::NotificationRegistrar registrar_; |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4630 | bool ready_; |
| 4631 | }; |
| 4632 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 4633 | // Test that we get enabled/disabled correctly for all the pref/command-line |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4634 | // combinations. We don't want to derive from the ExtensionServiceTest class |
| 4635 | // for this test, so we use ExtensionServiceTestSimple. |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4636 | // |
| 4637 | // Also tests that we always fire EXTENSIONS_READY, no matter whether we are |
| 4638 | // enabled or not. |
[email protected] | 39fdf520 | 2012-11-14 00:38:17 | [diff] [blame] | 4639 | TEST(ExtensionServiceTestSimple, Enabledness) { |
[email protected] | 5a24d2b | 2012-11-14 20:38:31 | [diff] [blame] | 4640 | // Make sure the PluginService singleton is destroyed at the end of the test. |
[email protected] | 39fdf520 | 2012-11-14 00:38:17 | [diff] [blame] | 4641 | base::ShadowingAtExitManager at_exit_manager; |
[email protected] | 5a24d2b | 2012-11-14 20:38:31 | [diff] [blame] | 4642 | |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 4643 | ExtensionErrorReporter::Init(false); // no noisy errors |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4644 | ExtensionsReadyRecorder recorder; |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 4645 | scoped_ptr<TestingProfile> profile(new TestingProfile()); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 4646 | MessageLoop loop; |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 4647 | content::TestBrowserThread ui_thread(BrowserThread::UI, &loop); |
| 4648 | content::TestBrowserThread file_thread(BrowserThread::FILE, &loop); |
[email protected] | e4854dc | 2013-04-24 00:11:51 | [diff] [blame] | 4649 | #if defined OS_CHROMEOS |
| 4650 | chromeos::ScopedTestDeviceSettingsService device_settings_service; |
| 4651 | chromeos::ScopedTestCrosSettings cros_settings; |
| 4652 | scoped_ptr<chromeos::ScopedTestUserManager> user_manager( |
| 4653 | new chromeos::ScopedTestUserManager); |
| 4654 | #endif |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 4655 | scoped_ptr<CommandLine> command_line; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4656 | base::FilePath install_dir = profile->GetPath() |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4657 | .AppendASCII(ExtensionService::kInstallDirectoryName); |
[email protected] | be5a6db | 2012-11-13 14:39:11 | [diff] [blame] | 4658 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 4659 | #if defined(ENABLE_PLUGINS) |
[email protected] | 0b30017 | 2012-09-27 16:11:52 | [diff] [blame] | 4660 | webkit::npapi::MockPluginList plugin_list; |
[email protected] | eb6c7ef | 2011-12-12 23:12:20 | [diff] [blame] | 4661 | PluginService::GetInstance()->SetPluginListForTesting(&plugin_list); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 4662 | #endif |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 4663 | |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 4664 | // By default, we are enabled. |
[email protected] | 947446b | 2010-10-21 03:36:31 | [diff] [blame] | 4665 | command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 4666 | ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 4667 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 4668 | CreateExtensionService( |
| 4669 | command_line.get(), |
| 4670 | install_dir, |
| 4671 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 4672 | EXPECT_TRUE(service->extensions_enabled()); |
| 4673 | service->Init(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4674 | loop.RunUntilIdle(); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 4675 | EXPECT_TRUE(recorder.ready()); |
[email protected] | e4854dc | 2013-04-24 00:11:51 | [diff] [blame] | 4676 | #if defined OS_CHROMEOS |
| 4677 | user_manager.reset(); |
| 4678 | #endif |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 4679 | |
| 4680 | // If either the command line or pref is set, we are disabled. |
| 4681 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 4682 | profile.reset(new TestingProfile()); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 4683 | command_line->AppendSwitch(switches::kDisableExtensions); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 4684 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 4685 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 4686 | CreateExtensionService( |
| 4687 | command_line.get(), |
| 4688 | install_dir, |
| 4689 | false); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 4690 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4691 | service->Init(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4692 | loop.RunUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4693 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 4694 | |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4695 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 4696 | profile.reset(new TestingProfile()); |
| 4697 | profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 4698 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 4699 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 4700 | CreateExtensionService( |
| 4701 | command_line.get(), |
| 4702 | install_dir, |
| 4703 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 4704 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4705 | service->Init(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4706 | loop.RunUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4707 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 4708 | |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4709 | recorder.set_ready(false); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 4710 | profile.reset(new TestingProfile()); |
| 4711 | profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
[email protected] | 947446b | 2010-10-21 03:36:31 | [diff] [blame] | 4712 | command_line.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 4713 | service = static_cast<extensions::TestExtensionSystem*>( |
[email protected] | 749d59a | 2012-04-05 00:23:24 | [diff] [blame] | 4714 | ExtensionSystem::Get(profile.get()))-> |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 4715 | CreateExtensionService( |
| 4716 | command_line.get(), |
| 4717 | install_dir, |
| 4718 | false); |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 4719 | EXPECT_FALSE(service->extensions_enabled()); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4720 | service->Init(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4721 | loop.RunUntilIdle(); |
[email protected] | f0488f2f | 2009-07-01 05:25:22 | [diff] [blame] | 4722 | EXPECT_TRUE(recorder.ready()); |
[email protected] | 7e1951a | 2010-09-30 10:22:20 | [diff] [blame] | 4723 | |
| 4724 | // Explicitly delete all the resources used in this test. |
| 4725 | profile.reset(); |
| 4726 | service = NULL; |
[email protected] | 060d497 | 2012-07-19 17:22:39 | [diff] [blame] | 4727 | // Execute any pending deletion tasks. |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4728 | loop.RunUntilIdle(); |
[email protected] | 5a24d2b | 2012-11-14 20:38:31 | [diff] [blame] | 4729 | |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 4730 | #if defined(ENABLE_PLUGINS) |
[email protected] | 5a24d2b | 2012-11-14 20:38:31 | [diff] [blame] | 4731 | // Ensure that even if the PluginService is re-used for a later test, it |
| 4732 | // won't still hold a reference to the stack position of our MockPluginList. |
| 4733 | // See crbug.com/159754. |
| 4734 | PluginService::GetInstance()->SetPluginListForTesting(NULL); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 4735 | #endif |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 4736 | } |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 4737 | |
| 4738 | // Test loading extensions that require limited and unlimited storage quotas. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4739 | TEST_F(ExtensionServiceTest, StorageQuota) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4740 | InitializeEmptyExtensionService(); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 4741 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4742 | base::FilePath extensions_path = data_dir_ |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 4743 | .AppendASCII("storage_quota"); |
| 4744 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4745 | base::FilePath limited_quota_ext = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 4746 | extensions_path.AppendASCII("limited_quota") |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 4747 | .AppendASCII("1.0"); |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 4748 | |
| 4749 | // The old permission name for unlimited quota was "unlimited_storage", but |
| 4750 | // we changed it to "unlimitedStorage". This tests both versions. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4751 | base::FilePath unlimited_quota_ext = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 4752 | extensions_path.AppendASCII("unlimited_quota") |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 4753 | .AppendASCII("1.0"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4754 | base::FilePath unlimited_quota_ext2 = |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 4755 | extensions_path.AppendASCII("unlimited_quota") |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 4756 | .AppendASCII("2.0"); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4757 | extensions::UnpackedInstaller::Create(service_)->Load(limited_quota_ext); |
| 4758 | extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext); |
| 4759 | extensions::UnpackedInstaller::Create(service_)->Load(unlimited_quota_ext2); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 4760 | loop_.RunUntilIdle(); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 4761 | |
[email protected] | 03b612f | 2010-08-13 21:09:21 | [diff] [blame] | 4762 | ASSERT_EQ(3u, loaded_.size()); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 4763 | EXPECT_TRUE(profile_.get()); |
| 4764 | EXPECT_FALSE(profile_->IsOffTheRecord()); |
[email protected] | 7c5f2ec | 2011-05-26 19:15:26 | [diff] [blame] | 4765 | EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 4766 | loaded_[0]->url())); |
| 4767 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 4768 | loaded_[1]->url())); |
| 4769 | EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited( |
| 4770 | loaded_[2]->url())); |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 4771 | } |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 4772 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4773 | // Tests ComponentLoader::Add(). |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4774 | TEST_F(ExtensionServiceTest, ComponentExtensions) { |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 4775 | InitializeEmptyExtensionService(); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 4776 | |
[email protected] | f0b97f1 | 2010-10-11 21:44:35 | [diff] [blame] | 4777 | // Component extensions should work even when extensions are disabled. |
| 4778 | set_extensions_enabled(false); |
| 4779 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 4780 | base::FilePath path = data_dir_ |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 4781 | .AppendASCII("good") |
| 4782 | .AppendASCII("Extensions") |
| 4783 | .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 4784 | .AppendASCII("1.0.0.0"); |
| 4785 | |
| 4786 | std::string manifest; |
| 4787 | ASSERT_TRUE(file_util::ReadFileToString( |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 4788 | path.Append(extensions::kManifestFilename), &manifest)); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 4789 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 4790 | service_->component_loader()->Add(manifest, path); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 4791 | service_->Init(); |
| 4792 | |
| 4793 | // Note that we do not pump messages -- the extension should be loaded |
| 4794 | // immediately. |
| 4795 | |
| 4796 | EXPECT_EQ(0u, GetErrors().size()); |
| 4797 | ASSERT_EQ(1u, loaded_.size()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4798 | EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location()); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 4799 | EXPECT_EQ(1u, service_->extensions()->size()); |
| 4800 | |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 4801 | // Component extensions get a prefs entry on first install. |
| 4802 | ValidatePrefKeyCount(1); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 4803 | |
| 4804 | // Reload all extensions, and make sure it comes back. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4805 | std::string extension_id = (*service_->extensions()->begin())->id(); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 4806 | loaded_.clear(); |
| 4807 | service_->ReloadExtensions(); |
| 4808 | ASSERT_EQ(1u, service_->extensions()->size()); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4809 | EXPECT_EQ(extension_id, (*service_->extensions()->begin())->id()); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 4810 | } |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 4811 | |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 4812 | namespace { |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 4813 | class TestSyncProcessorStub : public syncer::SyncChangeProcessor { |
| 4814 | virtual syncer::SyncError ProcessSyncChanges( |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4815 | const tracked_objects::Location& from_here, |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 4816 | const syncer::SyncChangeList& change_list) OVERRIDE { |
| 4817 | return syncer::SyncError(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4818 | } |
| 4819 | }; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 4820 | } |
| 4821 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4822 | TEST_F(ExtensionServiceTest, GetSyncData) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4823 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4824 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 4825 | const Extension* extension = service_->GetInstalledExtension(good_crx); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4826 | ASSERT_TRUE(extension); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 4827 | |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 4828 | service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4829 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 4830 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 4831 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4832 | |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4833 | syncer::SyncDataList list = service_->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4834 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 4835 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4836 | EXPECT_EQ(extension->id(), data.id()); |
| 4837 | EXPECT_FALSE(data.uninstalled()); |
| 4838 | EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); |
| 4839 | EXPECT_EQ(service_->IsIncognitoEnabled(good_crx), data.incognito_enabled()); |
| 4840 | EXPECT_TRUE(data.version().Equals(*extension->version())); |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 4841 | EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension), |
| 4842 | data.update_url()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4843 | EXPECT_EQ(extension->name(), data.name()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4844 | } |
| 4845 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4846 | TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 4847 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4848 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 4849 | TerminateExtension(good_crx); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 4850 | const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 4851 | ASSERT_TRUE(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4852 | |
| 4853 | TestSyncProcessorStub processor; |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 4854 | service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4855 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 4856 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 4857 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4858 | |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4859 | syncer::SyncDataList list = service_->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4860 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 4861 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4862 | EXPECT_EQ(extension->id(), data.id()); |
| 4863 | EXPECT_FALSE(data.uninstalled()); |
| 4864 | EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); |
| 4865 | EXPECT_EQ(service_->IsIncognitoEnabled(good_crx), data.incognito_enabled()); |
| 4866 | EXPECT_TRUE(data.version().Equals(*extension->version())); |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 4867 | EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension), |
| 4868 | data.update_url()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4869 | EXPECT_EQ(extension->name(), data.name()); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 4870 | } |
| 4871 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4872 | TEST_F(ExtensionServiceTest, GetSyncDataFilter) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4873 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4874 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 4875 | const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 4876 | ASSERT_TRUE(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4877 | |
| 4878 | TestSyncProcessorStub processor; |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4879 | service_->MergeDataAndStartSyncing(syncer::APPS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 4880 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 4881 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4882 | |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4883 | syncer::SyncDataList list = service_->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4884 | ASSERT_EQ(list.size(), 0U); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4885 | } |
| 4886 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4887 | TEST_F(ExtensionServiceTest, GetSyncExtensionDataUserSettings) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4888 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 4889 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 4890 | const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 4891 | ASSERT_TRUE(extension); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4892 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4893 | TestSyncProcessorStub processor; |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 4894 | service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4895 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 4896 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 4897 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4898 | |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4899 | { |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4900 | syncer::SyncDataList list = service_->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4901 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 4902 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4903 | EXPECT_TRUE(data.enabled()); |
| 4904 | EXPECT_FALSE(data.incognito_enabled()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4905 | } |
| 4906 | |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 4907 | service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4908 | { |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4909 | syncer::SyncDataList list = service_->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4910 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 4911 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4912 | EXPECT_FALSE(data.enabled()); |
| 4913 | EXPECT_FALSE(data.incognito_enabled()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4914 | } |
| 4915 | |
| 4916 | service_->SetIsIncognitoEnabled(good_crx, true); |
| 4917 | { |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4918 | syncer::SyncDataList list = service_->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4919 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 4920 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4921 | EXPECT_FALSE(data.enabled()); |
| 4922 | EXPECT_TRUE(data.incognito_enabled()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | service_->EnableExtension(good_crx); |
| 4926 | { |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4927 | syncer::SyncDataList list = service_->GetAllSyncData(syncer::EXTENSIONS); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4928 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 4929 | extensions::ExtensionSyncData data(list[0]); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 4930 | EXPECT_TRUE(data.enabled()); |
| 4931 | EXPECT_TRUE(data.incognito_enabled()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 4932 | } |
| 4933 | } |
| 4934 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4935 | TEST_F(ExtensionServiceTest, SyncForUninstalledExternalExtension) { |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 4936 | InitializeEmptyExtensionService(); |
| 4937 | InstallCRXWithLocation(data_dir_.AppendASCII("good.crx"), |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 4938 | Manifest::EXTERNAL_PREF, INSTALL_NEW); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 4939 | const Extension* extension = service_->GetInstalledExtension(good_crx); |
| 4940 | ASSERT_TRUE(extension); |
| 4941 | |
| 4942 | TestSyncProcessorStub processor; |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 4943 | service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4944 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 4945 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 4946 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 4947 | |
| 4948 | UninstallExtension(good_crx, false); |
| 4949 | EXPECT_TRUE(service_->IsExternalExtensionUninstalled(good_crx)); |
| 4950 | |
| 4951 | sync_pb::EntitySpecifics specifics; |
| 4952 | sync_pb::AppSpecifics* app_specifics = specifics.mutable_app(); |
| 4953 | sync_pb::ExtensionSpecifics* extension_specifics = |
| 4954 | app_specifics->mutable_extension(); |
| 4955 | extension_specifics->set_id(good_crx); |
| 4956 | extension_specifics->set_version("1.0"); |
| 4957 | extension_specifics->set_enabled(true); |
| 4958 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 4959 | syncer::SyncData sync_data = |
| 4960 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 4961 | syncer::SyncChange sync_change(FROM_HERE, |
| 4962 | syncer::SyncChange::ACTION_UPDATE, |
| 4963 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 4964 | syncer::SyncChangeList list(1); |
[email protected] | e8b0f25 | 2012-05-05 09:44:42 | [diff] [blame] | 4965 | list[0] = sync_change; |
| 4966 | |
| 4967 | service_->ProcessSyncChanges(FROM_HERE, list); |
| 4968 | EXPECT_TRUE(service_->IsExternalExtensionUninstalled(good_crx)); |
| 4969 | } |
| 4970 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 4971 | TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettings) { |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 4972 | InitializeEmptyExtensionService(); |
| 4973 | const Extension* app = |
| 4974 | PackAndInstallCRX(data_dir_.AppendASCII("app"), INSTALL_NEW); |
| 4975 | ASSERT_TRUE(app); |
| 4976 | ASSERT_TRUE(app->is_app()); |
| 4977 | |
| 4978 | TestSyncProcessorStub processor; |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4979 | service_->MergeDataAndStartSyncing(syncer::APPS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 4980 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 4981 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 4982 | |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 4983 | syncer::StringOrdinal initial_ordinal = |
| 4984 | syncer::StringOrdinal::CreateInitialOrdinal(); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 4985 | { |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4986 | syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 4987 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 4988 | |
| 4989 | extensions::AppSyncData app_sync_data(list[0]); |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 4990 | EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.app_launch_ordinal())); |
| 4991 | EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 4992 | } |
| 4993 | |
[email protected] | fb82dcd | 2012-03-21 14:15:46 | [diff] [blame] | 4994 | ExtensionSorting* sorting = service_->extension_prefs()->extension_sorting(); |
| 4995 | sorting->SetAppLaunchOrdinal(app->id(), initial_ordinal.CreateAfter()); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 4996 | { |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 4997 | syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 4998 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 4999 | |
| 5000 | extensions::AppSyncData app_sync_data(list[0]); |
| 5001 | EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 5002 | EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5003 | } |
| 5004 | |
[email protected] | fb82dcd | 2012-03-21 14:15:46 | [diff] [blame] | 5005 | sorting->SetPageOrdinal(app->id(), initial_ordinal.CreateAfter()); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5006 | { |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5007 | syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5008 | ASSERT_EQ(list.size(), 1U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5009 | |
| 5010 | extensions::AppSyncData app_sync_data(list[0]); |
| 5011 | EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); |
| 5012 | EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.page_ordinal())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5013 | } |
| 5014 | } |
| 5015 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5016 | TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettingsOnExtensionMoved) { |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5017 | InitializeEmptyExtensionService(); |
| 5018 | const size_t kAppCount = 3; |
| 5019 | const Extension* apps[kAppCount]; |
| 5020 | apps[0] = PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW); |
| 5021 | apps[1] = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
| 5022 | apps[2] = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW); |
| 5023 | for (size_t i = 0; i < kAppCount; ++i) { |
| 5024 | ASSERT_TRUE(apps[i]); |
| 5025 | ASSERT_TRUE(apps[i]->is_app()); |
| 5026 | } |
| 5027 | |
| 5028 | TestSyncProcessorStub processor; |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5029 | service_->MergeDataAndStartSyncing(syncer::APPS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5030 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5031 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5032 | |
| 5033 | service_->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id()); |
| 5034 | { |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5035 | syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5036 | ASSERT_EQ(list.size(), 3U); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5037 | |
| 5038 | extensions::AppSyncData data[kAppCount]; |
[email protected] | bb05cae1 | 2012-09-06 00:37:52 | [diff] [blame] | 5039 | for (size_t i = 0; i < kAppCount; ++i) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 5040 | data[i] = extensions::AppSyncData(list[i]); |
| 5041 | } |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5042 | |
| 5043 | // The sync data is not always in the same order our apps were installed in, |
| 5044 | // so we do that sorting here so we can make sure the values are changed as |
| 5045 | // expected. |
[email protected] | 36b64321 | 2012-09-07 12:53:00 | [diff] [blame] | 5046 | syncer::StringOrdinal app_launch_ordinals[kAppCount]; |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 5047 | for (size_t i = 0; i < kAppCount; ++i) { |
| 5048 | for (size_t j = 0; j < kAppCount; ++j) { |
| 5049 | if (apps[i]->id() == data[j].id()) |
| 5050 | app_launch_ordinals[i] = data[j].app_launch_ordinal(); |
| 5051 | } |
| 5052 | } |
| 5053 | |
| 5054 | EXPECT_TRUE(app_launch_ordinals[1].LessThan(app_launch_ordinals[0])); |
| 5055 | EXPECT_TRUE(app_launch_ordinals[0].LessThan(app_launch_ordinals[2])); |
| 5056 | } |
| 5057 | } |
| 5058 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5059 | TEST_F(ExtensionServiceTest, GetSyncDataList) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5060 | InitializeEmptyExtensionService(); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5061 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 5062 | InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); |
| 5063 | InstallCRX(data_dir_.AppendASCII("theme.crx"), INSTALL_NEW); |
| 5064 | InstallCRX(data_dir_.AppendASCII("theme2.crx"), INSTALL_NEW); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5065 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5066 | TestSyncProcessorStub processor; |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5067 | service_->MergeDataAndStartSyncing(syncer::APPS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5068 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5069 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 5070 | service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5071 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5072 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5073 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5074 | |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 5075 | service_->DisableExtension(page_action, Extension::DISABLE_USER_ACTION); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 5076 | TerminateExtension(theme2_crx); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5077 | |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5078 | EXPECT_EQ(0u, service_->GetAllSyncData(syncer::APPS).size()); |
| 5079 | EXPECT_EQ(2u, service_->GetAllSyncData(syncer::EXTENSIONS).size()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 5080 | } |
| 5081 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5082 | TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5083 | InitializeEmptyExtensionService(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5084 | TestSyncProcessorStub processor; |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 5085 | service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5086 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5087 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5088 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5089 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5090 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5091 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5092 | ext_specifics->set_id(good_crx); |
| 5093 | ext_specifics->set_version("1.0"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5094 | syncer::SyncData sync_data = |
| 5095 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5096 | syncer::SyncChange sync_change(FROM_HERE, |
| 5097 | syncer::SyncChange::ACTION_DELETE, |
| 5098 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5099 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5100 | list[0] = sync_change; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5101 | |
| 5102 | // Should do nothing. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5103 | service_->ProcessSyncChanges(FROM_HERE, list); |
| 5104 | EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5105 | |
| 5106 | // Install the extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5107 | base::FilePath extension_path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5108 | InstallCRX(extension_path, INSTALL_NEW); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5109 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 5110 | |
| 5111 | // Should uninstall the extension. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5112 | service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5113 | EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); |
| 5114 | |
| 5115 | // Should again do nothing. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5116 | service_->ProcessSyncChanges(FROM_HERE, list); |
| 5117 | EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5118 | } |
| 5119 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5120 | TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) { |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5121 | InitializeEmptyExtensionService(); |
| 5122 | |
| 5123 | // Install the extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5124 | base::FilePath extension_path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5125 | InstallCRX(extension_path, INSTALL_NEW); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5126 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 5127 | |
| 5128 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5129 | sync_pb::AppSpecifics* app_specifics = specifics.mutable_app(); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5130 | sync_pb::ExtensionSpecifics* extension_specifics = |
| 5131 | app_specifics->mutable_extension(); |
| 5132 | extension_specifics->set_id(good_crx); |
| 5133 | extension_specifics->set_version( |
| 5134 | service_->GetInstalledExtension(good_crx)->version()->GetString()); |
| 5135 | |
| 5136 | { |
| 5137 | extension_specifics->set_enabled(true); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5138 | syncer::SyncData sync_data = |
| 5139 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5140 | syncer::SyncChange sync_change(FROM_HERE, |
| 5141 | syncer::SyncChange::ACTION_DELETE, |
| 5142 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5143 | syncer::SyncChangeList list(1); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5144 | list[0] = sync_change; |
| 5145 | |
| 5146 | // Should do nothing |
| 5147 | service_->ProcessSyncChanges(FROM_HERE, list); |
| 5148 | EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| 5149 | } |
| 5150 | |
| 5151 | { |
| 5152 | extension_specifics->set_enabled(false); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5153 | syncer::SyncData sync_data = |
| 5154 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5155 | syncer::SyncChange sync_change(FROM_HERE, |
| 5156 | syncer::SyncChange::ACTION_UPDATE, |
| 5157 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5158 | syncer::SyncChangeList list(1); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 5159 | list[0] = sync_change; |
| 5160 | |
| 5161 | // Should again do nothing. |
| 5162 | service_->ProcessSyncChanges(FROM_HERE, list); |
| 5163 | EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 5164 | } |
| 5165 | } |
| 5166 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5167 | TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5168 | InitializeEmptyExtensionService(); |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 5169 | InitializeExtensionProcessManager(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5170 | TestSyncProcessorStub processor; |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 5171 | service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5172 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5173 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5174 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5175 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5176 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5177 | EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
| 5178 | EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
| 5179 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5180 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5181 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5182 | ext_specifics->set_id(good_crx); |
| 5183 | ext_specifics->set_version( |
| 5184 | service_->GetInstalledExtension(good_crx)->version()->GetString()); |
| 5185 | ext_specifics->set_enabled(false); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5186 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5187 | { |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5188 | syncer::SyncData sync_data = |
| 5189 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5190 | syncer::SyncChange sync_change(FROM_HERE, |
| 5191 | syncer::SyncChange::ACTION_UPDATE, |
| 5192 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5193 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5194 | list[0] = sync_change; |
| 5195 | service_->ProcessSyncChanges(FROM_HERE, list); |
| 5196 | EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 5197 | EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
| 5198 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5199 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5200 | { |
| 5201 | ext_specifics->set_enabled(true); |
| 5202 | ext_specifics->set_incognito_enabled(true); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5203 | syncer::SyncData sync_data = |
| 5204 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5205 | syncer::SyncChange sync_change(FROM_HERE, |
| 5206 | syncer::SyncChange::ACTION_UPDATE, |
| 5207 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5208 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5209 | list[0] = sync_change; |
| 5210 | service_->ProcessSyncChanges(FROM_HERE, list); |
| 5211 | EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
| 5212 | EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
| 5213 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5214 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5215 | { |
| 5216 | ext_specifics->set_enabled(false); |
| 5217 | ext_specifics->set_incognito_enabled(true); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5218 | syncer::SyncData sync_data = |
| 5219 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5220 | syncer::SyncChange sync_change(FROM_HERE, |
| 5221 | syncer::SyncChange::ACTION_UPDATE, |
| 5222 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5223 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5224 | list[0] = sync_change; |
| 5225 | service_->ProcessSyncChanges(FROM_HERE, list); |
| 5226 | EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 5227 | EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
| 5228 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5229 | |
| 5230 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
| 5231 | } |
| 5232 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5233 | TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 5234 | InitializeExtensionServiceWithUpdater(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5235 | TestSyncProcessorStub processor; |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 5236 | service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5237 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5238 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5239 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 5240 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5241 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 5242 | TerminateExtension(good_crx); |
| 5243 | EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
| 5244 | EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
| 5245 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5246 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5247 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5248 | ext_specifics->set_id(good_crx); |
| 5249 | ext_specifics->set_version( |
| 5250 | service_->GetInstalledExtension(good_crx)->version()->GetString()); |
| 5251 | ext_specifics->set_enabled(false); |
| 5252 | ext_specifics->set_incognito_enabled(true); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5253 | syncer::SyncData sync_data = |
| 5254 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5255 | syncer::SyncChange sync_change(FROM_HERE, |
| 5256 | syncer::SyncChange::ACTION_UPDATE, |
| 5257 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5258 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5259 | list[0] = sync_change; |
| 5260 | |
| 5261 | service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 5262 | EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 5263 | EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
| 5264 | |
| 5265 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
| 5266 | } |
| 5267 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5268 | TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5269 | InitializeExtensionServiceWithUpdater(); |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 5270 | InitializeRequestContext(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5271 | TestSyncProcessorStub processor; |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 5272 | service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5273 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5274 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5275 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5276 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5277 | InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5278 | EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
| 5279 | EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
| 5280 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5281 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5282 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5283 | ext_specifics->set_id(good_crx); |
| 5284 | ext_specifics->set_enabled(true); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5285 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5286 | { |
| 5287 | ext_specifics->set_version( |
| 5288 | service_->GetInstalledExtension(good_crx)->version()->GetString()); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5289 | syncer::SyncData sync_data = |
| 5290 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5291 | syncer::SyncChange sync_change(FROM_HERE, |
| 5292 | syncer::SyncChange::ACTION_UPDATE, |
| 5293 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5294 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5295 | list[0] = sync_change; |
| 5296 | |
| 5297 | // Should do nothing if extension version == sync version. |
| 5298 | service_->ProcessSyncChanges(FROM_HERE, list); |
| 5299 | EXPECT_FALSE(service_->updater()->WillCheckSoon()); |
| 5300 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5301 | |
| 5302 | // Should do nothing if extension version > sync version (but see |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5303 | // the TODO in ProcessExtensionSyncData). |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5304 | { |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5305 | ext_specifics->set_version("0.0.0.0"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5306 | syncer::SyncData sync_data = |
| 5307 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5308 | syncer::SyncChange sync_change(FROM_HERE, |
| 5309 | syncer::SyncChange::ACTION_UPDATE, |
| 5310 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5311 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5312 | list[0] = sync_change; |
| 5313 | |
| 5314 | service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5315 | EXPECT_FALSE(service_->updater()->WillCheckSoon()); |
| 5316 | } |
| 5317 | |
| 5318 | // Should kick off an update if extension version < sync version. |
| 5319 | { |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5320 | ext_specifics->set_version("9.9.9.9"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5321 | syncer::SyncData sync_data = |
| 5322 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5323 | syncer::SyncChange sync_change(FROM_HERE, |
| 5324 | syncer::SyncChange::ACTION_UPDATE, |
| 5325 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5326 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5327 | list[0] = sync_change; |
| 5328 | |
| 5329 | service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5330 | EXPECT_TRUE(service_->updater()->WillCheckSoon()); |
| 5331 | } |
| 5332 | |
| 5333 | EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
| 5334 | } |
| 5335 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5336 | TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5337 | InitializeExtensionServiceWithUpdater(); |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 5338 | InitializeRequestContext(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5339 | TestSyncProcessorStub processor; |
[email protected] | cb02f61 | 2012-06-27 03:15:50 | [diff] [blame] | 5340 | service_->MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 5341 | syncer::EXTENSIONS, syncer::SyncDataList(), |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5342 | scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), |
| 5343 | scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5344 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5345 | sync_pb::EntitySpecifics specifics; |
[email protected] | 4557d22 | 2012-03-04 23:33:36 | [diff] [blame] | 5346 | sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5347 | ext_specifics->set_id(good_crx); |
| 5348 | ext_specifics->set_enabled(false); |
| 5349 | ext_specifics->set_incognito_enabled(true); |
| 5350 | ext_specifics->set_update_url("http://www.google.com/"); |
| 5351 | ext_specifics->set_version("1.2.3.4"); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5352 | syncer::SyncData sync_data = |
| 5353 | syncer::SyncData::CreateLocalData(good_crx, "Name", specifics); |
[email protected] | b78170f | 2012-07-11 03:34:26 | [diff] [blame] | 5354 | syncer::SyncChange sync_change(FROM_HERE, |
| 5355 | syncer::SyncChange::ACTION_UPDATE, |
| 5356 | sync_data); |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 5357 | syncer::SyncChangeList list(1); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5358 | list[0] = sync_change; |
| 5359 | |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5360 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 5361 | EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 5362 | EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 5363 | service_->ProcessSyncChanges(FROM_HERE, list); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5364 | EXPECT_TRUE(service_->updater()->WillCheckSoon()); |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 5365 | EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 5366 | EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5367 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 5368 | const extensions::PendingExtensionInfo* info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 5369 | EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| 5370 | GetById(good_crx))); |
| 5371 | EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec()); |
| 5372 | EXPECT_TRUE(info->is_from_sync()); |
| 5373 | EXPECT_TRUE(info->install_silently()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5374 | EXPECT_EQ(Manifest::INTERNAL, info->install_source()); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 5375 | // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. |
| 5376 | } |
| 5377 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5378 | TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) { |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5379 | InitializeEmptyExtensionService(); |
| 5380 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5381 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5382 | InstallCRX(path, INSTALL_NEW); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5383 | ValidatePrefKeyCount(1u); |
| 5384 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5385 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5386 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 5387 | extensions::PendingExtensionManager* pending = |
| 5388 | service_->pending_extension_manager(); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5389 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5390 | |
| 5391 | // Skip install when the location is the same. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5392 | EXPECT_FALSE( |
| 5393 | service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5394 | kGoodId, GURL(kGoodUpdateURL), Manifest::INTERNAL)); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5395 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5396 | |
| 5397 | // Install when the location has higher priority. |
| 5398 | EXPECT_TRUE( |
| 5399 | service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5400 | kGoodId, GURL(kGoodUpdateURL), Manifest::EXTERNAL_POLICY_DOWNLOAD)); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5401 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5402 | |
| 5403 | // Try the low priority again. Should be rejected. |
| 5404 | EXPECT_FALSE( |
| 5405 | service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5406 | kGoodId, GURL(kGoodUpdateURL), Manifest::EXTERNAL_PREF_DOWNLOAD)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5407 | // The existing record should still be present in the pending extension |
| 5408 | // manager. |
| 5409 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5410 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5411 | pending->Remove(kGoodId); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5412 | |
| 5413 | // Skip install when the location has the same priority as the installed |
| 5414 | // location. |
| 5415 | EXPECT_FALSE(service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5416 | kGoodId, GURL(kGoodUpdateURL), Manifest::INTERNAL)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5417 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 5418 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5419 | } |
| 5420 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5421 | TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5422 | Version older_version("0.1.0.0"); |
| 5423 | Version newer_version("2.0.0.0"); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5424 | |
| 5425 | // We don't want the extension to be installed. A path that doesn't |
| 5426 | // point to a valid CRX ensures this. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5427 | const base::FilePath kInvalidPathToCrx = base::FilePath(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5428 | |
| 5429 | const int kCreationFlags = 0; |
| 5430 | const bool kDontMarkAcknowledged = false; |
| 5431 | |
| 5432 | InitializeEmptyExtensionService(); |
| 5433 | |
| 5434 | // The test below uses install source constants to test that |
| 5435 | // priority is enforced. It assumes a specific ranking of install |
| 5436 | // sources: Registry (EXTERNAL_REGISTRY) overrides external pref |
| 5437 | // (EXTERNAL_PREF), and external pref overrides user install (INTERNAL). |
| 5438 | // The following assertions verify these assumptions: |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5439 | ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, |
| 5440 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
| 5441 | Manifest::EXTERNAL_PREF)); |
| 5442 | ASSERT_EQ(Manifest::EXTERNAL_REGISTRY, |
| 5443 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
| 5444 | Manifest::INTERNAL)); |
| 5445 | ASSERT_EQ(Manifest::EXTERNAL_PREF, |
| 5446 | Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, |
| 5447 | Manifest::INTERNAL)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5448 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 5449 | extensions::PendingExtensionManager* pending = |
| 5450 | service_->pending_extension_manager(); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5451 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5452 | |
| 5453 | // Simulate an external source adding the extension as INTERNAL. |
| 5454 | EXPECT_TRUE( |
| 5455 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5456 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5457 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5458 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5459 | WaitForCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 5460 | |
| 5461 | // Simulate an external source adding the extension as EXTERNAL_PREF. |
| 5462 | EXPECT_TRUE( |
| 5463 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5464 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5465 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5466 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5467 | WaitForCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 5468 | |
| 5469 | // Simulate an external source adding as EXTERNAL_PREF again. |
[email protected] | 4ec0f4b | 2012-12-07 09:41:46 | [diff] [blame] | 5470 | // This is rejected because the version and the location are the same as |
| 5471 | // the previous installation, which is still pending. |
| 5472 | EXPECT_FALSE( |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5473 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5474 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5475 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5476 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5477 | |
| 5478 | // Try INTERNAL again. Should fail. |
| 5479 | EXPECT_FALSE( |
| 5480 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5481 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5482 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5483 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5484 | |
| 5485 | // Now the registry adds the extension. |
| 5486 | EXPECT_TRUE( |
| 5487 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5488 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5489 | Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5490 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5491 | WaitForCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
| 5492 | |
| 5493 | // Registry outranks both external pref and internal, so both fail. |
| 5494 | EXPECT_FALSE( |
| 5495 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5496 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5497 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5498 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5499 | |
| 5500 | EXPECT_FALSE( |
| 5501 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5502 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5503 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5504 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5505 | |
| 5506 | pending->Remove(kGoodId); |
| 5507 | |
| 5508 | // Install the extension. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5509 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5510 | const Extension* ext = InstallCRX(path, INSTALL_NEW); |
| 5511 | ValidatePrefKeyCount(1u); |
| 5512 | ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5513 | ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5514 | |
| 5515 | // Now test the logic of OnExternalExtensionFileFound() when the extension |
| 5516 | // being added is already installed. |
| 5517 | |
| 5518 | // Tests assume |older_version| is less than the installed version, and |
| 5519 | // |newer_version| is greater. Verify this: |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5520 | ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); |
| 5521 | ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5522 | |
| 5523 | // An external install for the same location should fail if the version is |
| 5524 | // older, or the same, and succeed if the version is newer. |
| 5525 | |
| 5526 | // Older than the installed version... |
| 5527 | EXPECT_FALSE( |
| 5528 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5529 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5530 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5531 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5532 | |
| 5533 | // Same version as the installed version... |
| 5534 | EXPECT_FALSE( |
| 5535 | service_->OnExternalExtensionFileFound( |
| 5536 | kGoodId, ext->version(), kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5537 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5538 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5539 | |
| 5540 | // Newer than the installed version... |
| 5541 | EXPECT_TRUE( |
| 5542 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5543 | kGoodId, &newer_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5544 | Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5545 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5546 | |
| 5547 | // An external install for a higher priority install source should succeed |
| 5548 | // if the version is greater. |older_version| is not... |
| 5549 | EXPECT_FALSE( |
| 5550 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5551 | kGoodId, &older_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5552 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5553 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5554 | |
| 5555 | // |newer_version| is newer. |
| 5556 | EXPECT_TRUE( |
| 5557 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5558 | kGoodId, &newer_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5559 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5560 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5561 | |
| 5562 | // An external install for an even higher priority install source should |
| 5563 | // succeed if the version is greater. |
| 5564 | EXPECT_TRUE( |
| 5565 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5566 | kGoodId, &newer_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5567 | Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5568 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5569 | |
| 5570 | // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, |
| 5571 | // adding from external pref will now fail. |
| 5572 | EXPECT_FALSE( |
| 5573 | service_->OnExternalExtensionFileFound( |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5574 | kGoodId, &newer_version, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5575 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5576 | EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
| 5577 | } |
| 5578 | |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5579 | TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 5580 | Version kVersion123("1.2.3"); |
| 5581 | Version kVersion124("1.2.4"); |
| 5582 | Version kVersion125("1.2.5"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5583 | const base::FilePath kInvalidPathToCrx = base::FilePath(); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 5584 | const int kCreationFlags = 0; |
| 5585 | const bool kDontMarkAcknowledged = false; |
| 5586 | |
| 5587 | InitializeEmptyExtensionService(); |
| 5588 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 5589 | extensions::PendingExtensionManager* pending = |
| 5590 | service_->pending_extension_manager(); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 5591 | EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
| 5592 | |
| 5593 | // An external provider starts installing from a local crx. |
| 5594 | EXPECT_TRUE( |
| 5595 | service_->OnExternalExtensionFileFound( |
| 5596 | kGoodId, &kVersion123, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5597 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 5598 | const extensions::PendingExtensionInfo* info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 5599 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5600 | EXPECT_TRUE(info->version().IsValid()); |
| 5601 | EXPECT_TRUE(info->version().Equals(kVersion123)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 5602 | |
| 5603 | // Adding a newer version overrides the currently pending version. |
| 5604 | EXPECT_TRUE( |
| 5605 | service_->OnExternalExtensionFileFound( |
| 5606 | kGoodId, &kVersion124, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5607 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 5608 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5609 | EXPECT_TRUE(info->version().IsValid()); |
| 5610 | EXPECT_TRUE(info->version().Equals(kVersion124)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 5611 | |
| 5612 | // Adding an older version fails. |
| 5613 | EXPECT_FALSE( |
| 5614 | service_->OnExternalExtensionFileFound( |
| 5615 | kGoodId, &kVersion123, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5616 | Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 5617 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5618 | EXPECT_TRUE(info->version().IsValid()); |
| 5619 | EXPECT_TRUE(info->version().Equals(kVersion124)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 5620 | |
| 5621 | // Adding an older version fails even when coming from a higher-priority |
| 5622 | // location. |
| 5623 | EXPECT_FALSE( |
| 5624 | service_->OnExternalExtensionFileFound( |
| 5625 | kGoodId, &kVersion123, kInvalidPathToCrx, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5626 | Manifest::EXTERNAL_REGISTRY, kCreationFlags, kDontMarkAcknowledged)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 5627 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5628 | EXPECT_TRUE(info->version().IsValid()); |
| 5629 | EXPECT_TRUE(info->version().Equals(kVersion124)); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 5630 | |
| 5631 | // Adding the latest version from the webstore overrides a specific version. |
| 5632 | GURL kUpdateUrl("http://example.com/update"); |
| 5633 | EXPECT_TRUE( |
| 5634 | service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5635 | kGoodId, kUpdateUrl, Manifest::EXTERNAL_POLICY_DOWNLOAD)); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 5636 | EXPECT_TRUE((info = pending->GetById(kGoodId))); |
| 5637 | EXPECT_FALSE(info->version().IsValid()); |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 5638 | } |
| 5639 | |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 5640 | // This makes sure we can package and install CRX files that use whitelisted |
| 5641 | // permissions. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5642 | TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 5643 | std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; |
| 5644 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 5645 | switches::kWhitelistedExtensionID, test_id); |
| 5646 | |
| 5647 | InitializeEmptyExtensionService(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5648 | base::FilePath path = data_dir_ |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 5649 | .AppendASCII("permissions"); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5650 | base::FilePath pem_path = path |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 5651 | .AppendASCII("whitelist.pem"); |
| 5652 | path = path |
| 5653 | .AppendASCII("whitelist"); |
| 5654 | |
| 5655 | const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW); |
| 5656 | EXPECT_EQ(0u, GetErrors().size()); |
| 5657 | ASSERT_EQ(1u, service_->extensions()->size()); |
| 5658 | EXPECT_EQ(test_id, extension->id()); |
| 5659 | } |
| 5660 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5661 | // Test that when multiple sources try to install an extension, |
| 5662 | // we consistently choose the right one. To make tests easy to read, |
| 5663 | // methods that fake requests to install crx files in several ways |
| 5664 | // are provided. |
| 5665 | class ExtensionSourcePriorityTest : public ExtensionServiceTest { |
| 5666 | public: |
[email protected] | 49aeab6 | 2013-02-07 02:53:11 | [diff] [blame] | 5667 | virtual void SetUp() { |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 5668 | ExtensionServiceTest::SetUp(); |
| 5669 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5670 | // All tests use a single extension. Put the id and path in member vars |
| 5671 | // that all methods can read. |
| 5672 | crx_id_ = kGoodId; |
[email protected] | e85e34c3 | 2011-04-13 18:38:35 | [diff] [blame] | 5673 | crx_path_ = data_dir_.AppendASCII("good.crx"); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5674 | } |
| 5675 | |
| 5676 | // Fake an external source adding a URL to fetch an extension from. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5677 | bool AddPendingExternalPrefUrl() { |
| 5678 | return service_->pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5679 | crx_id_, GURL(), Manifest::EXTERNAL_PREF_DOWNLOAD); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5680 | } |
| 5681 | |
| 5682 | // Fake an external file from external_extensions.json. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5683 | bool AddPendingExternalPrefFileInstall() { |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 5684 | Version version("1.0.0.0"); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5685 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5686 | return service_->OnExternalExtensionFileFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5687 | crx_id_, &version, crx_path_, Manifest::EXTERNAL_PREF, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 5688 | Extension::NO_FLAGS, false); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5689 | } |
| 5690 | |
| 5691 | // Fake a request from sync to install an extension. |
| 5692 | bool AddPendingSyncInstall() { |
| 5693 | return service_->pending_extension_manager()->AddFromSync( |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 5694 | crx_id_, GURL(kGoodUpdateURL), &IsExtension, kGoodInstallSilently); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5695 | } |
| 5696 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5697 | // Fake a policy install. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5698 | bool AddPendingPolicyInstall() { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5699 | // Get path to the CRX with id |kGoodId|. |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5700 | return service_->OnExternalExtensionUpdateUrlFound( |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5701 | crx_id_, GURL(), Manifest::EXTERNAL_POLICY_DOWNLOAD); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5702 | } |
| 5703 | |
| 5704 | // Get the install source of a pending extension. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5705 | Manifest::Location GetPendingLocation() { |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 5706 | const extensions::PendingExtensionInfo* info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 5707 | EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| 5708 | GetById(crx_id_))); |
| 5709 | return info->install_source(); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5710 | } |
| 5711 | |
| 5712 | // Is an extension pending from a sync request? |
| 5713 | bool GetPendingIsFromSync() { |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 5714 | const extensions::PendingExtensionInfo* info; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 5715 | EXPECT_TRUE((info = service_->pending_extension_manager()-> |
| 5716 | GetById(crx_id_))); |
| 5717 | return info->is_from_sync(); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5718 | } |
| 5719 | |
| 5720 | // Is the CRX id these tests use pending? |
| 5721 | bool IsCrxPending() { |
| 5722 | return service_->pending_extension_manager()->IsIdPending(crx_id_); |
| 5723 | } |
| 5724 | |
| 5725 | // Is an extension installed? |
| 5726 | bool IsCrxInstalled() { |
| 5727 | return (service_->GetExtensionById(crx_id_, true) != NULL); |
| 5728 | } |
| 5729 | |
| 5730 | protected: |
| 5731 | // All tests use a single extension. Making the id and path member |
| 5732 | // vars avoids pasing the same argument to every method. |
| 5733 | std::string crx_id_; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5734 | base::FilePath crx_path_; |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5735 | }; |
| 5736 | |
[email protected] | 3634ebd | 2011-04-20 00:34:12 | [diff] [blame] | 5737 | // Test that a pending request for installation of an external CRX from |
| 5738 | // an update URL overrides a pending request to install the same extension |
| 5739 | // from sync. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 5740 | TEST_F(ExtensionSourcePriorityTest, PendingExternalFileOverSync) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5741 | InitializeEmptyExtensionService(); |
| 5742 | |
| 5743 | ASSERT_FALSE(IsCrxInstalled()); |
| 5744 | |
| 5745 | // Install pending extension from sync. |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 5746 | EXPECT_TRUE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5747 | ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5748 | EXPECT_TRUE(GetPendingIsFromSync()); |
| 5749 | ASSERT_FALSE(IsCrxInstalled()); |
| 5750 | |
| 5751 | // Install pending as external prefs json would. |
| 5752 | AddPendingExternalPrefFileInstall(); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5753 | ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5754 | ASSERT_FALSE(IsCrxInstalled()); |
| 5755 | |
| 5756 | // Another request from sync should be ignorred. |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 5757 | EXPECT_FALSE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5758 | ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5759 | ASSERT_FALSE(IsCrxInstalled()); |
| 5760 | |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5761 | WaitForCrxInstall(crx_path_, INSTALL_NEW); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5762 | ASSERT_TRUE(IsCrxInstalled()); |
| 5763 | } |
| 5764 | |
| 5765 | // Test that an install of an external CRX from an update overrides |
| 5766 | // an install of the same extension from sync. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 5767 | TEST_F(ExtensionSourcePriorityTest, PendingExternalUrlOverSync) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5768 | InitializeEmptyExtensionService(); |
| 5769 | ASSERT_FALSE(IsCrxInstalled()); |
| 5770 | |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 5771 | EXPECT_TRUE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5772 | ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5773 | EXPECT_TRUE(GetPendingIsFromSync()); |
| 5774 | ASSERT_FALSE(IsCrxInstalled()); |
| 5775 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 5776 | ASSERT_TRUE(AddPendingExternalPrefUrl()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5777 | ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5778 | EXPECT_FALSE(GetPendingIsFromSync()); |
| 5779 | ASSERT_FALSE(IsCrxInstalled()); |
| 5780 | |
[email protected] | f4d5e1a | 2011-04-28 02:08:25 | [diff] [blame] | 5781 | EXPECT_FALSE(AddPendingSyncInstall()); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5782 | ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation()); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5783 | EXPECT_FALSE(GetPendingIsFromSync()); |
| 5784 | ASSERT_FALSE(IsCrxInstalled()); |
| 5785 | } |
| 5786 | |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5787 | // Test that an external install request stops sync from installing |
| 5788 | // the same extension. |
[email protected] | ed8ee72 | 2011-04-22 06:49:44 | [diff] [blame] | 5789 | TEST_F(ExtensionSourcePriorityTest, InstallExternalBlocksSyncRequest) { |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5790 | InitializeEmptyExtensionService(); |
| 5791 | ASSERT_FALSE(IsCrxInstalled()); |
| 5792 | |
| 5793 | // External prefs starts an install. |
| 5794 | AddPendingExternalPrefFileInstall(); |
| 5795 | |
| 5796 | // Crx installer was made, but has not yet run. |
| 5797 | ASSERT_FALSE(IsCrxInstalled()); |
| 5798 | |
| 5799 | // Before the CRX installer runs, Sync requests that the same extension |
| 5800 | // be installed. Should fail, because an external source is pending. |
| 5801 | ASSERT_FALSE(AddPendingSyncInstall()); |
| 5802 | |
| 5803 | // Wait for the external source to install. |
[email protected] | 8f512c7 | 2011-11-22 21:02:50 | [diff] [blame] | 5804 | WaitForCrxInstall(crx_path_, INSTALL_NEW); |
[email protected] | 145a317b | 2011-04-12 16:03:46 | [diff] [blame] | 5805 | ASSERT_TRUE(IsCrxInstalled()); |
| 5806 | |
| 5807 | // Now that the extension is installed, sync request should fail |
| 5808 | // because the extension is already installed. |
| 5809 | ASSERT_FALSE(AddPendingSyncInstall()); |
| 5810 | } |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 5811 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5812 | // Test that installing an external extension displays a GlobalError. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5813 | TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 5814 | FeatureSwitch::ScopedOverride prompt( |
| 5815 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5816 | |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 5817 | InitializeEmptyExtensionService(); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 5818 | MockExtensionProvider* provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5819 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 5820 | AddMockExternalProvider(provider); |
| 5821 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5822 | service_->UpdateExternalExtensionAlert(); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 5823 | // Should return false, meaning there aren't any extensions that the user |
| 5824 | // needs to know about. |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5825 | EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 5826 | |
| 5827 | // This is a normal extension, installed normally. |
| 5828 | // This should NOT trigger an alert. |
| 5829 | set_extensions_enabled(true); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 5830 | base::FilePath path = data_dir_.AppendASCII("good.crx"); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 5831 | InstallCRX(path, INSTALL_NEW); |
| 5832 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5833 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 5834 | loop_.RunUntilIdle(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5835 | EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 5836 | |
| 5837 | // A hosted app, installed externally. |
[email protected] | 2c495c4 | 2013-01-04 21:49:54 | [diff] [blame] | 5838 | // This should NOT trigger an alert. |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 5839 | provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
| 5840 | data_dir_.AppendASCII("hosted_app.crx")); |
| 5841 | |
| 5842 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 5843 | loop_.RunUntilIdle(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5844 | EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 5845 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5846 | // Another normal extension, but installed externally. |
| 5847 | // This SHOULD trigger an alert. |
| 5848 | provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 5849 | data_dir_.AppendASCII("page_action.crx")); |
| 5850 | |
| 5851 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 5852 | loop_.RunUntilIdle(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5853 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 5854 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5855 | |
| 5856 | // Test that external extensions are initially disabled, and that enabling |
| 5857 | // them clears the prompt. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5858 | TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 5859 | FeatureSwitch::ScopedOverride prompt( |
| 5860 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5861 | |
| 5862 | InitializeEmptyExtensionService(); |
| 5863 | MockExtensionProvider* provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5864 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5865 | AddMockExternalProvider(provider); |
| 5866 | |
| 5867 | provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 5868 | data_dir_.AppendASCII("page_action.crx")); |
| 5869 | |
| 5870 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 5871 | loop_.RunUntilIdle(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5872 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 5873 | EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); |
| 5874 | |
| 5875 | const Extension* extension = |
| 5876 | service_->disabled_extensions()->GetByID(page_action); |
| 5877 | EXPECT_TRUE(extension); |
| 5878 | EXPECT_EQ(page_action, extension->id()); |
| 5879 | |
| 5880 | service_->EnableExtension(page_action); |
| 5881 | EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5882 | EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); |
| 5883 | } |
| 5884 | |
| 5885 | // Test that installing multiple external extensions works. |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 5886 | TEST_F(ExtensionServiceTest, ExternalInstallMultiple) { |
[email protected] | 00b5d0a5 | 2012-10-30 13:13:53 | [diff] [blame] | 5887 | FeatureSwitch::ScopedOverride prompt( |
| 5888 | FeatureSwitch::prompt_for_external_extensions(), true); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5889 | |
| 5890 | InitializeEmptyExtensionService(); |
| 5891 | MockExtensionProvider* provider = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 5892 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5893 | AddMockExternalProvider(provider); |
| 5894 | |
| 5895 | provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 5896 | data_dir_.AppendASCII("page_action.crx")); |
| 5897 | provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 5898 | data_dir_.AppendASCII("good.crx")); |
| 5899 | provider->UpdateOrAddExtension(theme_crx, "2.0", |
| 5900 | data_dir_.AppendASCII("theme.crx")); |
| 5901 | |
| 5902 | service_->CheckForExternalUpdates(); |
[email protected] | b8f50ce | 2012-11-17 12:37:57 | [diff] [blame] | 5903 | loop_.RunUntilIdle(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5904 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 5905 | EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); |
| 5906 | EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 5907 | EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx)); |
| 5908 | |
| 5909 | service_->EnableExtension(page_action); |
| 5910 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 5911 | EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5912 | service_->EnableExtension(theme_crx); |
| 5913 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 5914 | EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5915 | service_->EnableExtension(good_crx); |
| 5916 | EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 5917 | EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
| 5918 | } |
| 5919 | |
| 5920 | // Test that there is a bubble for external extensions that update |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 5921 | // from the webstore if the profile is not new. |
| 5922 | TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) { |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 5923 | FeatureSwitch::ScopedOverride prompt( |
| 5924 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 5925 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 5926 | // This sets up the ExtensionPrefs used by our ExtensionService to be |
| 5927 | // post-first run. |
| 5928 | InitializeExtensionServiceHelper(false, false); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 5929 | |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 5930 | base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); |
| 5931 | PackCRX(data_dir_.AppendASCII("update_from_webstore"), |
| 5932 | data_dir_.AppendASCII("update_from_webstore.pem"), |
| 5933 | crx_path); |
| 5934 | |
| 5935 | MockExtensionProvider* provider = |
| 5936 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 5937 | AddMockExternalProvider(provider); |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 5938 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 5939 | |
[email protected] | aa55be7f | 2013-04-22 20:56:04 | [diff] [blame] | 5940 | service_->CheckForExternalUpdates(); |
| 5941 | loop_.RunUntilIdle(); |
| 5942 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 5943 | EXPECT_TRUE(extensions::HasExternalInstallBubble(service_)); |
| 5944 | EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 5945 | } |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 5946 | |
| 5947 | // Test that there is no bubble for external extensions if the profile is new. |
| 5948 | TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) { |
| 5949 | FeatureSwitch::ScopedOverride prompt( |
| 5950 | FeatureSwitch::prompt_for_external_extensions(), true); |
| 5951 | |
| 5952 | InitializeEmptyExtensionService(); |
| 5953 | |
| 5954 | base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); |
| 5955 | PackCRX(data_dir_.AppendASCII("update_from_webstore"), |
| 5956 | data_dir_.AppendASCII("update_from_webstore.pem"), |
| 5957 | crx_path); |
| 5958 | |
| 5959 | MockExtensionProvider* provider = |
| 5960 | new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 5961 | AddMockExternalProvider(provider); |
| 5962 | provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
| 5963 | |
| 5964 | service_->CheckForExternalUpdates(); |
| 5965 | loop_.RunUntilIdle(); |
| 5966 | EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 5967 | EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
| 5968 | EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
| 5969 | } |