blob: d297132a3df3fddb2a259338ad6b6e4d5cf63e47 [file] [log] [blame]
[email protected]098fa7a2013-03-08 22:11:171// Copyright (c) 2013 The Chromium Authors. All rights reserved.
[email protected]6014d672008-12-05 00:38:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]f0397fa2008-12-11 17:59:585#include <algorithm>
[email protected]7fa19f82010-12-21 19:40:086#include <set>
[email protected]6014d672008-12-05 00:38:257#include <vector>
8
[email protected]be5a6db2012-11-13 14:39:119#include "base/at_exit.h"
[email protected]24b538a2010-02-27 01:22:4410#include "base/basictypes.h"
[email protected]c4148a72011-08-09 23:04:2011#include "base/bind.h"
[email protected]36a784c2009-06-23 06:21:0812#include "base/command_line.h"
[email protected]6014d672008-12-05 00:38:2513#include "base/file_util.h"
[email protected]25a4c1c2013-06-08 04:53:3614#include "base/files/file_enumerator.h"
[email protected]ea1a3f62012-11-16 20:34:2315#include "base/files/scoped_temp_dir.h"
[email protected]ffbec692012-02-26 20:26:4216#include "base/json/json_file_value_serializer.h"
[email protected]93d49d72009-10-23 20:00:2017#include "base/json/json_reader.h"
[email protected]ffbec692012-02-26 20:26:4218#include "base/json/json_string_value_serializer.h"
[email protected]3b63f8f42011-03-28 01:54:1519#include "base/memory/scoped_ptr.h"
[email protected]71cb8aa2011-12-29 19:14:0020#include "base/memory/weak_ptr.h"
[email protected]b19fe572013-07-18 04:54:2621#include "base/message_loop/message_loop.h"
[email protected]9eec53fe2013-10-30 20:21:1722#include "base/prefs/scoped_user_pref_update.h"
[email protected]7286e3fc2011-07-19 22:13:2423#include "base/stl_util.h"
[email protected]00e7bef2013-06-10 20:35:1724#include "base/strings/string16.h"
[email protected]3ea1b182013-02-08 22:38:4125#include "base/strings/string_number_conversions.h"
[email protected]00e7bef2013-06-10 20:35:1726#include "base/strings/string_util.h"
[email protected]112158af2013-06-07 23:46:1827#include "base/strings/utf_string_conversions.h"
[email protected]aa142702010-03-26 01:26:3328#include "base/version.h"
[email protected]9d32ded072011-10-11 16:31:0529#include "chrome/browser/browser_process.h"
[email protected]9ea0cd32013-07-12 01:50:3630#include "chrome/browser/chrome_notification_types.h"
[email protected]5db9ada2012-04-11 13:48:2031#include "chrome/browser/extensions/app_sync_data.h"
[email protected]3f2a2fa2013-09-24 02:55:2532#include "chrome/browser/extensions/blacklist.h"
[email protected]74474042013-11-21 12:03:5433#include "chrome/browser/extensions/chrome_app_sorting.h"
[email protected]d8c8f25f2011-11-02 18:18:0134#include "chrome/browser/extensions/component_loader.h"
[email protected]eb6c7ef2011-12-12 23:12:2035#include "chrome/browser/extensions/crx_installer.h"
[email protected]a7cd28e2012-10-05 21:03:3636#include "chrome/browser/extensions/default_apps.h"
[email protected]a17f9462009-06-09 02:56:4137#include "chrome/browser/extensions/extension_creator.h"
[email protected]14a000d2010-04-29 21:44:2438#include "chrome/browser/extensions/extension_error_reporter.h"
[email protected]89226982012-07-16 20:09:1839#include "chrome/browser/extensions/extension_error_ui.h"
[email protected]9f3c8532013-07-31 19:52:0740#include "chrome/browser/extensions/extension_notification_observer.h"
[email protected]eaa7dd182010-12-14 11:09:0041#include "chrome/browser/extensions/extension_service.h"
[email protected]f484f8d52014-06-12 08:38:1842#include "chrome/browser/extensions/extension_service_test_base.h"
[email protected]19eb80152011-02-26 00:28:4343#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]90310d92011-04-17 07:35:0444#include "chrome/browser/extensions/extension_sync_data.h"
[email protected]dccba4f82014-05-29 00:52:5645#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]a7ff4b72013-10-17 20:56:0246#include "chrome/browser/extensions/extension_util.h"
[email protected]2894a512014-06-26 19:03:5647#include "chrome/browser/extensions/external_install_error.h"
48#include "chrome/browser/extensions/external_install_manager.h"
[email protected]e410b5f2012-12-14 14:02:2449#include "chrome/browser/extensions/external_policy_loader.h"
[email protected]5df038b2012-07-16 19:03:2750#include "chrome/browser/extensions/external_pref_loader.h"
51#include "chrome/browser/extensions/external_provider_impl.h"
[email protected]3f2a2fa2013-09-24 02:55:2552#include "chrome/browser/extensions/fake_safe_browsing_database_manager.h"
[email protected]d8c8f25f2011-11-02 18:18:0153#include "chrome/browser/extensions/installed_loader.h"
[email protected]f0bfe622012-06-22 01:01:4454#include "chrome/browser/extensions/pack_extension_job.h"
[email protected]f3d3b382014-03-14 21:19:2855#include "chrome/browser/extensions/pending_extension_info.h"
56#include "chrome/browser/extensions/pending_extension_manager.h"
[email protected]f71b582c2014-01-10 17:03:1557#include "chrome/browser/extensions/test_blacklist.h"
[email protected]31d8f5f22012-04-02 15:22:0858#include "chrome/browser/extensions/test_extension_system.h"
[email protected]d8c8f25f2011-11-02 18:18:0159#include "chrome/browser/extensions/unpacked_installer.h"
[email protected]42a08162012-03-16 18:09:1160#include "chrome/browser/extensions/updater/extension_updater.h"
[email protected]c753f142013-02-10 13:14:0461#include "chrome/browser/prefs/pref_service_syncable.h"
[email protected]343a0d872014-08-05 11:44:1862#include "chrome/browser/supervised_user/supervised_user_service.h"
63#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
[email protected]50736a12013-09-26 08:58:3464#include "chrome/browser/sync/profile_sync_service.h"
65#include "chrome/browser/sync/profile_sync_service_factory.h"
[email protected]31d8f5f22012-04-02 15:22:0866#include "chrome/common/chrome_constants.h"
[email protected]37858e52010-08-26 00:22:0267#include "chrome/common/chrome_switches.h"
[email protected]098fa7a2013-03-08 22:11:1768#include "chrome/common/extensions/api/plugins/plugins_handler.h"
[email protected]6b414c232013-06-05 07:53:3469#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
[email protected]334ec0a2013-03-24 01:36:1670#include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
[email protected]65348062013-01-15 07:27:2271#include "chrome/common/extensions/manifest_url_handler.h"
[email protected]36a784c2009-06-23 06:21:0872#include "chrome/common/pref_names.h"
[email protected]24b538a2010-02-27 01:22:4473#include "chrome/common/url_constants.h"
[email protected]078c3192013-08-22 08:18:0574#include "chrome/test/base/scoped_browser_locale.h"
[email protected]a4ff9eae2011-08-01 19:58:1675#include "chrome/test/base/testing_profile.h"
[email protected]fdd28372014-08-21 02:27:2676#include "components/crx_file/id_util.h"
[email protected]f0c8c4992014-05-15 17:37:2677#include "components/pref_registry/pref_registry_syncable.h"
[email protected]35cc399e2012-02-23 18:19:2878#include "content/public/browser/dom_storage_context.h"
[email protected]98270432012-09-11 20:51:2479#include "content/public/browser/gpu_data_manager.h"
[email protected]35cc399e2012-02-23 18:19:2880#include "content/public/browser/indexed_db_context.h"
[email protected]6c2381d2011-10-19 02:52:5381#include "content/public/browser/notification_registrar.h"
[email protected]ad50def52011-10-19 23:17:0782#include "content/public/browser/notification_service.h"
[email protected]e67385f2011-12-21 06:00:5683#include "content/public/browser/plugin_service.h"
[email protected]6d057a0c2013-07-09 21:12:0784#include "content/public/browser/render_process_host.h"
[email protected]5c8e67c2012-08-29 00:48:5285#include "content/public/browser/storage_partition.h"
[email protected]55eb70e762012-02-20 17:38:3986#include "content/public/common/content_constants.h"
[email protected]6d057a0c2013-07-09 21:12:0787#include "content/public/test/test_utils.h"
[email protected]5fdfa562013-12-27 17:43:5988#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2489#include "extensions/browser/extension_system.h"
[email protected]301116c62013-11-26 10:37:4590#include "extensions/browser/external_provider_interface.h"
[email protected]4a1d9c0d2014-06-13 12:50:1191#include "extensions/browser/install_flag.h"
[email protected]301116c62013-11-26 10:37:4592#include "extensions/browser/management_policy.h"
[email protected]234fc5ff2014-01-16 23:32:2893#include "extensions/browser/pref_names.h"
[email protected]301116c62013-11-26 10:37:4594#include "extensions/browser/test_management_policy.h"
[email protected]e43c61f2014-07-20 21:46:3495#include "extensions/browser/uninstall_reason.h"
[email protected]993da5e2013-03-23 21:25:1696#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:4197#include "extensions/common/extension.h"
[email protected]22b7b2c2013-11-05 22:52:4298#include "extensions/common/extension_builder.h"
[email protected]6668e5d2014-04-08 23:32:5299#include "extensions/common/extension_l10n_util.h"
[email protected]993da5e2013-03-23 21:25:16100#include "extensions/common/extension_resource.h"
[email protected]f484f8d52014-06-12 08:38:18101#include "extensions/common/feature_switch.h"
[email protected]0c3c9732013-09-16 08:53:41102#include "extensions/common/manifest_constants.h"
[email protected]558878cc82013-11-09 01:25:51103#include "extensions/common/manifest_handlers/background_info.h"
[email protected]5a55f3f2013-10-29 01:08:29104#include "extensions/common/permissions/permission_set.h"
[email protected]076ebeda2014-06-06 21:47:26105#include "extensions/common/permissions/permissions_data.h"
[email protected]a612eb32014-03-31 22:09:17106#include "extensions/common/switches.h"
[email protected]885c0e92012-11-13 20:27:42107#include "extensions/common/url_pattern.h"
[email protected]22b7b2c2013-11-05 22:52:42108#include "extensions/common/value_builder.h"
[email protected]d7b5cc72013-05-23 20:05:00109#include "gpu/config/gpu_info.h"
[email protected]b873cd92012-02-09 21:51:48110#include "grit/browser_resources.h"
[email protected]5b9bc352012-07-18 13:13:34111#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06112#include "net/cookies/cookie_monster.h"
113#include "net/cookies/cookie_options.h"
[email protected]dbbad7a2010-08-13 18:18:36114#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34115#include "net/url_request/url_request_context_getter.h"
[email protected]d0b23522014-02-19 02:15:25116#include "sync/api/fake_sync_change_processor.h"
[email protected]36b643212012-09-07 12:53:00117#include "sync/api/string_ordinal.h"
[email protected]50736a12013-09-26 08:58:34118#include "sync/api/sync_data.h"
[email protected]895a1e52012-05-15 02:50:12119#include "sync/api/sync_error_factory.h"
120#include "sync/api/sync_error_factory_mock.h"
[email protected]6d147912013-07-09 08:02:14121#include "sync/api/syncable_service.h"
[email protected]1bcf30e2012-03-10 01:06:41122#include "sync/protocol/app_specifics.pb.h"
123#include "sync/protocol/extension_specifics.pb.h"
124#include "sync/protocol/sync.pb.h"
[email protected]6014d672008-12-05 00:38:25125#include "testing/gtest/include/gtest/gtest.h"
[email protected]f66c110c2008-12-05 20:26:29126#include "testing/platform_test.h"
[email protected]a6483d22013-07-03 22:11:00127#include "url/gurl.h"
[email protected]08b1f75f2013-05-22 22:02:38128#include "webkit/browser/database/database_tracker.h"
[email protected]7660ec92013-05-30 05:12:39129#include "webkit/browser/quota/quota_manager.h"
[email protected]2a9644c2013-06-19 06:19:34130#include "webkit/common/database/database_identifier.h"
[email protected]6014d672008-12-05 00:38:25131
[email protected]88e8ec9152013-01-17 04:05:18132#if defined(OS_CHROMEOS)
[email protected]4d390782014-08-15 09:22:58133#include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h"
[email protected]e4854dc2013-04-24 00:11:51134#include "chrome/browser/chromeos/settings/cros_settings.h"
135#include "chrome/browser/chromeos/settings/device_settings_service.h"
[email protected]88e8ec9152013-01-17 04:05:18136#endif
137
[email protected]3f2a2fa2013-09-24 02:55:25138// The blacklist tests rely on safe browsing.
139#if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
140#define ENABLE_BLACKLIST_TESTS
141#endif
142
[email protected]aeca23f2013-06-21 22:34:41143using base::DictionaryValue;
144using base::ListValue;
145using base::Value;
[email protected]55eb70e762012-02-20 17:38:39146using content::BrowserContext;
[email protected]631bb742011-11-02 11:29:39147using content::BrowserThread;
[email protected]35cc399e2012-02-23 18:19:28148using content::DOMStorageContext;
149using content::IndexedDBContext;
[email protected]e67385f2011-12-21 06:00:56150using content::PluginService;
[email protected]c2e66e12012-06-27 06:27:06151using extensions::APIPermission;
152using extensions::APIPermissionSet;
[email protected]74474042013-11-21 12:03:54153using extensions::AppSorting;
[email protected]3f2a2fa2013-09-24 02:55:25154using extensions::Blacklist;
[email protected]bf3d9df2012-07-24 23:20:27155using extensions::CrxInstaller;
[email protected]1c321ee52012-05-21 03:02:34156using extensions::Extension;
[email protected]6d777492012-07-11 17:33:43157using extensions::ExtensionCreator;
[email protected]45759612012-07-10 17:21:23158using extensions::ExtensionPrefs;
[email protected]5fdfa562013-12-27 17:43:59159using extensions::ExtensionRegistry;
[email protected]993da5e2013-03-23 21:25:16160using extensions::ExtensionResource;
[email protected]bd306722012-07-11 20:43:59161using extensions::ExtensionSystem;
[email protected]3f2a2fa2013-09-24 02:55:25162using extensions::FakeSafeBrowsingDatabaseManager;
[email protected]00b5d0a52012-10-30 13:13:53163using extensions::FeatureSwitch;
[email protected]1d5e58b2013-01-31 08:41:40164using extensions::Manifest;
[email protected]c2e66e12012-06-27 06:27:06165using extensions::PermissionSet;
[email protected]b3aa7182013-04-25 04:45:23166using extensions::TestExtensionSystem;
[email protected]ebe07772014-05-22 04:16:06167using extensions::UnloadedExtensionInfo;
[email protected]e9f541a2012-11-19 21:52:31168using extensions::URLPatternSet;
[email protected]631bb742011-11-02 11:29:39169
[email protected]6bf90612013-08-15 00:36:27170namespace keys = extensions::manifest_keys;
[email protected]c6d474f82009-12-16 21:11:06171
[email protected]f0397fa2008-12-11 17:59:58172namespace {
173
[email protected]df4956e2009-06-10 16:53:42174// Extension ids used during testing.
[email protected]095ccbe42013-09-26 00:06:42175const char good0[] = "behllobkkfkfnphdnhnkndlbkcpglgmj";
176const char good1[] = "hpiknbiabeeppbpihjehijgoemciehgk";
177const char good2[] = "bjafgdebaacbbbecmhlhpofkepfkgcpa";
[email protected]aa5219d2013-11-09 19:25:41178const char all_zero[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
[email protected]095ccbe42013-09-26 00:06:42179const char good2048[] = "nmgjhmhbleinmjpbdhgajfjkbijcmgbh";
180const char good_crx[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
181const char hosted_app[] = "kbmnembihfiondgfjekmnmcbddelicoi";
182const char page_action[] = "obcimlgaoabeegjmmpldobjndiealpln";
183const char theme_crx[] = "iamefpfkojoapidjnbafmgkgncegbkad";
184const char theme2_crx[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf";
185const char permissions_crx[] = "eagpmdpfmaekmmcejjbmjoecnejeiiin";
186const char unpacked[] = "cbcdidchbppangcjoddlpdjlenngjldk";
187const char updates_from_webstore[] = "akjooamlhcgeopfifcmlggaebeocgokj";
[email protected]df4956e2009-06-10 16:53:42188
[email protected]f0397fa2008-12-11 17:59:58189struct ExtensionsOrder {
[email protected]198b5902013-06-27 10:36:11190 bool operator()(const scoped_refptr<const Extension>& a,
191 const scoped_refptr<const Extension>& b) {
[email protected]f0397fa2008-12-11 17:59:58192 return a->name() < b->name();
193 }
194};
195
[email protected]d2065e062013-12-12 23:49:52196static std::vector<base::string16> GetErrors() {
197 const std::vector<base::string16>* errors =
[email protected]bb28e062009-02-27 17:19:18198 ExtensionErrorReporter::GetInstance()->GetErrors();
[email protected]d2065e062013-12-12 23:49:52199 std::vector<base::string16> ret_val;
[email protected]bb28e062009-02-27 17:19:18200
[email protected]d2065e062013-12-12 23:49:52201 for (std::vector<base::string16>::const_iterator iter = errors->begin();
[email protected]bb28e062009-02-27 17:19:18202 iter != errors->end(); ++iter) {
[email protected]04338722013-12-24 23:18:05203 std::string utf8_error = base::UTF16ToUTF8(*iter);
[email protected]fc670822011-12-17 09:33:49204 if (utf8_error.find(".svn") == std::string::npos) {
[email protected]bb28e062009-02-27 17:19:18205 ret_val.push_back(*iter);
206 }
207 }
208
209 // The tests rely on the errors being in a certain order, which can vary
210 // depending on how filesystem iteration works.
211 std::stable_sort(ret_val.begin(), ret_val.end());
212
213 return ret_val;
214}
215
[email protected]cced75a2011-05-20 08:31:12216static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
[email protected]8d888c12010-11-30 00:00:25217 int schemes = URLPattern::SCHEME_ALL;
218 extent->AddPattern(URLPattern(schemes, pattern));
219}
220
[email protected]650b2d52013-02-10 03:41:45221base::FilePath GetTemporaryFile() {
222 base::FilePath temp_file;
[email protected]03d9afc02013-12-03 17:55:52223 CHECK(base::CreateTemporaryFile(&temp_file));
[email protected]a17dfcf2012-12-30 02:07:09224 return temp_file;
225}
226
[email protected]6d057a0c2013-07-09 21:12:07227bool WaitForCountNotificationsCallback(int *count) {
228 return --(*count) == 0;
229}
230
[email protected]f0397fa2008-12-11 17:59:58231} // namespace
[email protected]6014d672008-12-05 00:38:25232
[email protected]5df038b2012-07-16 19:03:27233class MockExtensionProvider : public extensions::ExternalProviderInterface {
[email protected]a1257b12009-06-12 02:51:34234 public:
[email protected]a12ce8b22012-01-17 18:40:53235 MockExtensionProvider(
[email protected]8e4560b62011-01-14 10:09:14236 VisitorInterface* visitor,
[email protected]1d5e58b2013-01-31 08:41:40237 Manifest::Location location)
[email protected]f121003b2012-05-04 21:57:47238 : location_(location), visitor_(visitor), visit_count_(0) {
[email protected]a12ce8b22012-01-17 18:40:53239 }
240
[email protected]a1257b12009-06-12 02:51:34241 virtual ~MockExtensionProvider() {}
242
243 void UpdateOrAddExtension(const std::string& id,
244 const std::string& version,
[email protected]650b2d52013-02-10 03:41:45245 const base::FilePath& path) {
[email protected]a1257b12009-06-12 02:51:34246 extension_map_[id] = std::make_pair(version, path);
247 }
248
249 void RemoveExtension(const std::string& id) {
250 extension_map_.erase(id);
251 }
252
[email protected]5df038b2012-07-16 19:03:27253 // ExternalProvider implementation:
[email protected]a12ce8b22012-01-17 18:40:53254 virtual void VisitRegisteredExtension() OVERRIDE {
[email protected]0a60a2e2010-10-25 16:15:21255 visit_count_++;
[email protected]a1257b12009-06-12 02:51:34256 for (DataMap::const_iterator i = extension_map_.begin();
257 i != extension_map_.end(); ++i) {
[email protected]c5e4a2222014-01-03 16:06:13258 Version version(i->second.first);
[email protected]a1257b12009-06-12 02:51:34259
[email protected]8e4560b62011-01-14 10:09:14260 visitor_->OnExternalExtensionFileFound(
[email protected]12126d372012-07-11 18:40:53261 i->first, &version, i->second.second, location_,
[email protected]f121003b2012-05-04 21:57:47262 Extension::NO_FLAGS, false);
[email protected]a1257b12009-06-12 02:51:34263 }
[email protected]50067e52011-10-20 23:17:07264 visitor_->OnExternalProviderReady(this);
[email protected]a1257b12009-06-12 02:51:34265 }
266
[email protected]a12ce8b22012-01-17 18:40:53267 virtual bool HasExtension(const std::string& id) const OVERRIDE {
[email protected]0a60a2e2010-10-25 16:15:21268 return extension_map_.find(id) != extension_map_.end();
269 }
270
[email protected]a12ce8b22012-01-17 18:40:53271 virtual bool GetExtensionDetails(
272 const std::string& id,
[email protected]1d5e58b2013-01-31 08:41:40273 Manifest::Location* location,
[email protected]c5e4a2222014-01-03 16:06:13274 scoped_ptr<Version>* version) const OVERRIDE {
[email protected]a1257b12009-06-12 02:51:34275 DataMap::const_iterator it = extension_map_.find(id);
276 if (it == extension_map_.end())
[email protected]0a60a2e2010-10-25 16:15:21277 return false;
278
279 if (version)
[email protected]c5e4a2222014-01-03 16:06:13280 version->reset(new Version(it->second.first));
[email protected]a1257b12009-06-12 02:51:34281
282 if (location)
283 *location = location_;
[email protected]0a60a2e2010-10-25 16:15:21284
285 return true;
286 }
[email protected]8e4560b62011-01-14 10:09:14287
[email protected]a12ce8b22012-01-17 18:40:53288 virtual bool IsReady() const OVERRIDE {
[email protected]8e4560b62011-01-14 10:09:14289 return true;
290 }
291
[email protected]a12ce8b22012-01-17 18:40:53292 virtual void ServiceShutdown() OVERRIDE {
[email protected]8e4560b62011-01-14 10:09:14293 }
294
[email protected]0a60a2e2010-10-25 16:15:21295 int visit_count() const { return visit_count_; }
296 void set_visit_count(int visit_count) {
297 visit_count_ = visit_count;
[email protected]a1257b12009-06-12 02:51:34298 }
299
300 private:
[email protected]650b2d52013-02-10 03:41:45301 typedef std::map< std::string, std::pair<std::string, base::FilePath> >
302 DataMap;
[email protected]a1257b12009-06-12 02:51:34303 DataMap extension_map_;
[email protected]1d5e58b2013-01-31 08:41:40304 Manifest::Location location_;
[email protected]8e4560b62011-01-14 10:09:14305 VisitorInterface* visitor_;
[email protected]27b985d2009-06-25 17:53:15306
[email protected]0a60a2e2010-10-25 16:15:21307 // visit_count_ tracks the number of calls to VisitRegisteredExtension().
308 // Mutable because it must be incremented on each call to
309 // VisitRegisteredExtension(), which must be a const method to inherit
310 // from the class being mocked.
311 mutable int visit_count_;
312
[email protected]27b985d2009-06-25 17:53:15313 DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider);
314};
315
[email protected]8e4560b62011-01-14 10:09:14316class MockProviderVisitor
[email protected]5df038b2012-07-16 19:03:27317 : public extensions::ExternalProviderInterface::VisitorInterface {
[email protected]27b985d2009-06-25 17:53:15318 public:
[email protected]f0841cd2011-01-19 15:07:24319 // The provider will return |fake_base_path| from
320 // GetBaseCrxFilePath(). User can test the behavior with
321 // and without an empty path using this parameter.
[email protected]650b2d52013-02-10 03:41:45322 explicit MockProviderVisitor(base::FilePath fake_base_path)
[email protected]f0841cd2011-01-19 15:07:24323 : ids_found_(0),
[email protected]f121003b2012-05-04 21:57:47324 fake_base_path_(fake_base_path),
325 expected_creation_flags_(Extension::NO_FLAGS) {
[email protected]19eac6d2013-05-30 06:51:03326 profile_.reset(new TestingProfile);
[email protected]f121003b2012-05-04 21:57:47327 }
328
[email protected]650b2d52013-02-10 03:41:45329 MockProviderVisitor(base::FilePath fake_base_path,
330 int expected_creation_flags)
[email protected]f121003b2012-05-04 21:57:47331 : ids_found_(0),
332 fake_base_path_(fake_base_path),
333 expected_creation_flags_(expected_creation_flags) {
[email protected]27b985d2009-06-25 17:53:15334 }
335
[email protected]683d0702010-12-06 16:25:57336 int Visit(const std::string& json_data) {
[email protected]27b985d2009-06-25 17:53:15337 // Give the test json file to the provider for parsing.
[email protected]5df038b2012-07-16 19:03:27338 provider_.reset(new extensions::ExternalProviderImpl(
[email protected]8e4560b62011-01-14 10:09:14339 this,
[email protected]5df038b2012-07-16 19:03:27340 new extensions::ExternalTestingLoader(json_data, fake_base_path_),
[email protected]19eac6d2013-05-30 06:51:03341 profile_.get(),
[email protected]1d5e58b2013-01-31 08:41:40342 Manifest::EXTERNAL_PREF,
343 Manifest::EXTERNAL_PREF_DOWNLOAD,
[email protected]1bf73cc32011-10-26 22:38:31344 Extension::NO_FLAGS));
[email protected]27b985d2009-06-25 17:53:15345
346 // We also parse the file into a dictionary to compare what we get back
347 // from the provider.
348 JSONStringValueSerializer serializer(json_data);
[email protected]023b3d12013-12-23 18:46:49349 base::Value* json_value = serializer.Deserialize(NULL, NULL);
[email protected]27b985d2009-06-25 17:53:15350
[email protected]023b3d12013-12-23 18:46:49351 if (!json_value || !json_value->IsType(base::Value::TYPE_DICTIONARY)) {
[email protected]e2194742010-08-12 05:54:34352 NOTREACHED() << "Unable to deserialize json data";
[email protected]27b985d2009-06-25 17:53:15353 return -1;
354 } else {
[email protected]023b3d12013-12-23 18:46:49355 base::DictionaryValue* external_extensions =
356 static_cast<base::DictionaryValue*>(json_value);
[email protected]27b985d2009-06-25 17:53:15357 prefs_.reset(external_extensions);
358 }
359
360 // Reset our counter.
361 ids_found_ = 0;
[email protected]683d0702010-12-06 16:25:57362 // Ask the provider to look up all extensions and return them.
[email protected]8e4560b62011-01-14 10:09:14363 provider_->VisitRegisteredExtension();
[email protected]27b985d2009-06-25 17:53:15364
365 return ids_found_;
366 }
367
[email protected]9060d8b02012-01-13 02:14:30368 virtual bool OnExternalExtensionFileFound(const std::string& id,
[email protected]c5e4a2222014-01-03 16:06:13369 const Version* version,
[email protected]650b2d52013-02-10 03:41:45370 const base::FilePath& path,
[email protected]1d5e58b2013-01-31 08:41:40371 Manifest::Location unused,
[email protected]47fc70c2011-12-06 07:29:51372 int creation_flags,
[email protected]49aeab62013-02-07 02:53:11373 bool mark_acknowledged) OVERRIDE {
[email protected]f121003b2012-05-04 21:57:47374 EXPECT_EQ(expected_creation_flags_, creation_flags);
[email protected]1bf73cc32011-10-26 22:38:31375
[email protected]27b985d2009-06-25 17:53:15376 ++ids_found_;
[email protected]023b3d12013-12-23 18:46:49377 base::DictionaryValue* pref;
[email protected]27b985d2009-06-25 17:53:15378 // This tests is to make sure that the provider only notifies us of the
379 // values we gave it. So if the id we doesn't exist in our internal
380 // dictionary then something is wrong.
[email protected]e2194742010-08-12 05:54:34381 EXPECT_TRUE(prefs_->GetDictionary(id, &pref))
382 << "Got back ID (" << id.c_str() << ") we weren't expecting";
[email protected]27b985d2009-06-25 17:53:15383
[email protected]f0841cd2011-01-19 15:07:24384 EXPECT_TRUE(path.IsAbsolute());
385 if (!fake_base_path_.empty())
386 EXPECT_TRUE(fake_base_path_.IsParent(path));
387
[email protected]27b985d2009-06-25 17:53:15388 if (pref) {
[email protected]0a60a2e2010-10-25 16:15:21389 EXPECT_TRUE(provider_->HasExtension(id));
390
[email protected]27b985d2009-06-25 17:53:15391 // Ask provider if the extension we got back is registered.
[email protected]1d5e58b2013-01-31 08:41:40392 Manifest::Location location = Manifest::INVALID_LOCATION;
[email protected]c5e4a2222014-01-03 16:06:13393 scoped_ptr<Version> v1;
[email protected]650b2d52013-02-10 03:41:45394 base::FilePath crx_path;
[email protected]0a60a2e2010-10-25 16:15:21395
396 EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1));
397 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str());
398
[email protected]c5e4a2222014-01-03 16:06:13399 scoped_ptr<Version> v2;
[email protected]0a60a2e2010-10-25 16:15:21400 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location, &v2));
[email protected]27b985d2009-06-25 17:53:15401 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str());
402 EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str());
[email protected]1d5e58b2013-01-31 08:41:40403 EXPECT_EQ(Manifest::EXTERNAL_PREF, location);
[email protected]27b985d2009-06-25 17:53:15404
405 // Remove it so we won't count it ever again.
[email protected]e2194742010-08-12 05:54:34406 prefs_->Remove(id, NULL);
[email protected]27b985d2009-06-25 17:53:15407 }
[email protected]9060d8b02012-01-13 02:14:30408 return true;
[email protected]27b985d2009-06-25 17:53:15409 }
410
[email protected]9060d8b02012-01-13 02:14:30411 virtual bool OnExternalExtensionUpdateUrlFound(
[email protected]d8fd0fd2014-03-24 13:16:06412 const std::string& id,
413 const std::string& install_parameter,
414 const GURL& update_url,
[email protected]464213a2013-10-15 01:06:48415 Manifest::Location location,
416 int creation_flags,
417 bool mark_acknowledged) OVERRIDE {
[email protected]8ef78fd2010-08-19 17:14:32418 ++ids_found_;
[email protected]023b3d12013-12-23 18:46:49419 base::DictionaryValue* pref;
[email protected]8ef78fd2010-08-19 17:14:32420 // This tests is to make sure that the provider only notifies us of the
421 // values we gave it. So if the id we doesn't exist in our internal
422 // dictionary then something is wrong.
423 EXPECT_TRUE(prefs_->GetDictionary(id, &pref))
424 << L"Got back ID (" << id.c_str() << ") we weren't expecting";
[email protected]1d5e58b2013-01-31 08:41:40425 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location);
[email protected]8ef78fd2010-08-19 17:14:32426
427 if (pref) {
[email protected]0a60a2e2010-10-25 16:15:21428 EXPECT_TRUE(provider_->HasExtension(id));
429
430 // External extensions with update URLs do not have versions.
[email protected]c5e4a2222014-01-03 16:06:13431 scoped_ptr<Version> v1;
[email protected]1d5e58b2013-01-31 08:41:40432 Manifest::Location location1 = Manifest::INVALID_LOCATION;
[email protected]21a5a672010-11-04 10:47:42433 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1));
[email protected]0a60a2e2010-10-25 16:15:21434 EXPECT_FALSE(v1.get());
[email protected]1d5e58b2013-01-31 08:41:40435 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1);
[email protected]0a60a2e2010-10-25 16:15:21436
[email protected]d8fd0fd2014-03-24 13:16:06437 std::string parsed_install_parameter;
438 pref->GetString("install_parameter", &parsed_install_parameter);
439 EXPECT_EQ(parsed_install_parameter, install_parameter);
440
[email protected]8ef78fd2010-08-19 17:14:32441 // Remove it so we won't count it again.
442 prefs_->Remove(id, NULL);
443 }
[email protected]9060d8b02012-01-13 02:14:30444 return true;
[email protected]8ef78fd2010-08-19 17:14:32445 }
446
[email protected]50067e52011-10-20 23:17:07447 virtual void OnExternalProviderReady(
[email protected]49aeab62013-02-07 02:53:11448 const extensions::ExternalProviderInterface* provider) OVERRIDE {
[email protected]50067e52011-10-20 23:17:07449 EXPECT_EQ(provider, provider_.get());
450 EXPECT_TRUE(provider->IsReady());
[email protected]8e4560b62011-01-14 10:09:14451 }
452
[email protected]27b985d2009-06-25 17:53:15453 private:
454 int ids_found_;
[email protected]650b2d52013-02-10 03:41:45455 base::FilePath fake_base_path_;
[email protected]f121003b2012-05-04 21:57:47456 int expected_creation_flags_;
[email protected]5df038b2012-07-16 19:03:27457 scoped_ptr<extensions::ExternalProviderImpl> provider_;
[email protected]023b3d12013-12-23 18:46:49458 scoped_ptr<base::DictionaryValue> prefs_;
[email protected]19eac6d2013-05-30 06:51:03459 scoped_ptr<TestingProfile> profile_;
[email protected]27b985d2009-06-25 17:53:15460
461 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
[email protected]a1257b12009-06-12 02:51:34462};
463
[email protected]f484f8d52014-06-12 08:38:18464class ExtensionServiceTest : public extensions::ExtensionServiceTestBase,
465 public content::NotificationObserver {
[email protected]bf73f0b2010-02-10 19:26:59466 public:
[email protected]612a1cb12012-10-17 13:18:03467 ExtensionServiceTest()
[email protected]ebe07772014-05-22 04:16:06468 : unloaded_reason_(UnloadedExtensionInfo::REASON_UNDEFINED),
469 installed_(NULL),
[email protected]41bb80bd2013-05-03 10:56:02470 was_update_(false),
[email protected]612a1cb12012-10-17 13:18:03471 override_external_install_prompt_(
[email protected]ebe07772014-05-22 04:16:06472 FeatureSwitch::prompt_for_external_extensions(),
[email protected]f484f8d52014-06-12 08:38:18473 false),
474 expected_extensions_count_(0) {
[email protected]fdc76192014-04-20 21:54:41475 registrar_.Add(this,
[email protected]adf5a102014-07-31 12:44:06476 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
[email protected]ad50def52011-10-19 23:17:07477 content::NotificationService::AllSources());
[email protected]0403d4e2014-05-23 07:56:36478 registrar_.Add(this,
[email protected]adf5a102014-07-31 12:44:06479 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
[email protected]ad50def52011-10-19 23:17:07480 content::NotificationService::AllSources());
[email protected]adf5a102014-07-31 12:44:06481 registrar_.Add(
482 this,
483 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
484 content::NotificationService::AllSources());
[email protected]a9b00ac2009-06-25 21:03:23485 }
[email protected]cc655912009-01-29 23:19:19486
[email protected]432115822011-07-10 15:52:27487 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53488 const content::NotificationSource& source,
[email protected]49aeab62013-02-07 02:53:11489 const content::NotificationDetails& details) OVERRIDE {
[email protected]432115822011-07-10 15:52:27490 switch (type) {
[email protected]adf5a102014-07-31 12:44:06491 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
[email protected]6c2381d2011-10-19 02:52:53492 const Extension* extension =
493 content::Details<const Extension>(details).ptr();
[email protected]00cd9c42010-11-02 20:15:57494 loaded_.push_back(make_scoped_refptr(extension));
[email protected]894bb502009-05-21 22:39:57495 // The tests rely on the errors being in a certain order, which can vary
496 // depending on how filesystem iteration works.
497 std::stable_sort(loaded_.begin(), loaded_.end(), ExtensionsOrder());
498 break;
499 }
500
[email protected]adf5a102014-07-31 12:44:06501 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
[email protected]ebe07772014-05-22 04:16:06502 UnloadedExtensionInfo* unloaded_info =
503 content::Details<UnloadedExtensionInfo>(details).ptr();
504 const Extension* e = unloaded_info->extension;
[email protected]9f1087e2009-06-15 17:29:32505 unloaded_id_ = e->id();
[email protected]ebe07772014-05-22 04:16:06506 unloaded_reason_ = unloaded_info->reason;
[email protected]1c321ee52012-05-21 03:02:34507 extensions::ExtensionList::iterator i =
[email protected]9f1087e2009-06-15 17:29:32508 std::find(loaded_.begin(), loaded_.end(), e);
509 // TODO(erikkay) fix so this can be an assert. Right now the tests
510 // are manually calling clear() on loaded_, so this isn't doable.
511 if (i == loaded_.end())
512 return;
513 loaded_.erase(i);
[email protected]894bb502009-05-21 22:39:57514 break;
[email protected]9f1087e2009-06-15 17:29:32515 }
[email protected]adf5a102014-07-31 12:44:06516 case extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED: {
[email protected]41bb80bd2013-05-03 10:56:02517 const extensions::InstalledExtensionInfo* installed_info =
518 content::Details<const extensions::InstalledExtensionInfo>(details)
519 .ptr();
520 installed_ = installed_info->extension;
521 was_update_ = installed_info->is_update;
[email protected]e7554c3f2013-05-29 00:36:56522 old_name_ = installed_info->old_name;
[email protected]894bb502009-05-21 22:39:57523 break;
[email protected]41bb80bd2013-05-03 10:56:02524 }
[email protected]894bb502009-05-21 22:39:57525
[email protected]894bb502009-05-21 22:39:57526 default:
527 DCHECK(false);
[email protected]3acbd422008-12-08 18:25:00528 }
529 }
530
[email protected]5df038b2012-07-16 19:03:27531 void AddMockExternalProvider(
532 extensions::ExternalProviderInterface* provider) {
[email protected]f484f8d52014-06-12 08:38:18533 service()->AddProviderForTesting(provider);
[email protected]a1257b12009-06-12 02:51:34534 }
535
[email protected]6d147912013-07-09 08:02:14536 void MockSyncStartFlare(bool* was_called,
537 syncer::ModelType* model_type_passed_in,
538 syncer::ModelType model_type) {
539 *was_called = true;
540 *model_type_passed_in = model_type;
541 }
542
[email protected]9197f3b2009-06-02 00:49:27543 protected:
[email protected]3f2a2fa2013-09-24 02:55:25544 // Paths to some of the fake extensions.
545 base::FilePath good0_path() {
[email protected]f484f8d52014-06-12 08:38:18546 return data_dir()
547 .AppendASCII("good")
548 .AppendASCII("Extensions")
549 .AppendASCII(good0)
550 .AppendASCII("1.0.0.0");
[email protected]3f2a2fa2013-09-24 02:55:25551 }
552
553 base::FilePath good1_path() {
[email protected]f484f8d52014-06-12 08:38:18554 return data_dir()
555 .AppendASCII("good")
556 .AppendASCII("Extensions")
557 .AppendASCII(good1)
558 .AppendASCII("2");
[email protected]3f2a2fa2013-09-24 02:55:25559 }
560
561 base::FilePath good2_path() {
[email protected]f484f8d52014-06-12 08:38:18562 return data_dir()
563 .AppendASCII("good")
564 .AppendASCII("Extensions")
565 .AppendASCII(good2)
566 .AppendASCII("1.0");
[email protected]3f2a2fa2013-09-24 02:55:25567 }
568
[email protected]d55e7602009-12-16 04:20:42569 void TestExternalProvider(MockExtensionProvider* provider,
[email protected]1d5e58b2013-01-31 08:41:40570 Manifest::Location location);
[email protected]d55e7602009-12-16 04:20:42571
[email protected]650b2d52013-02-10 03:41:45572 void PackCRX(const base::FilePath& dir_path,
573 const base::FilePath& pem_path,
574 const base::FilePath& crx_path) {
[email protected]8d888c12010-11-30 00:00:25575 // Use the existing pem key, if provided.
[email protected]650b2d52013-02-10 03:41:45576 base::FilePath pem_output_path;
[email protected]8d888c12010-11-30 00:00:25577 if (pem_path.value().empty()) {
578 pem_output_path = crx_path.DirName().AppendASCII("temp.pem");
[email protected]8d888c12010-11-30 00:00:25579 } else {
[email protected]7567484142013-07-11 17:36:07580 ASSERT_TRUE(base::PathExists(pem_path));
[email protected]8d888c12010-11-30 00:00:25581 }
[email protected]3ba0fd32010-06-19 05:39:10582
[email protected]dd3aa792013-07-16 19:10:23583 ASSERT_TRUE(base::DeleteFile(crx_path, false));
[email protected]8d888c12010-11-30 00:00:25584
[email protected]3ba0fd32010-06-19 05:39:10585 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
[email protected]8d888c12010-11-30 00:00:25586 ASSERT_TRUE(creator->Run(dir_path,
587 crx_path,
588 pem_path,
[email protected]93d973a2012-01-08 07:38:26589 pem_output_path,
590 ExtensionCreator::kOverwriteCRX));
[email protected]8d888c12010-11-30 00:00:25591
[email protected]7567484142013-07-11 17:36:07592 ASSERT_TRUE(base::PathExists(crx_path));
[email protected]8d888c12010-11-30 00:00:25593 }
594
[email protected]8f512c72011-11-22 21:02:50595 enum InstallState {
596 INSTALL_FAILED,
597 INSTALL_UPDATED,
[email protected]695b5712012-12-06 23:55:28598 INSTALL_NEW,
599 INSTALL_WITHOUT_LOAD,
[email protected]8f512c72011-11-22 21:02:50600 };
601
[email protected]650b2d52013-02-10 03:41:45602 const Extension* PackAndInstallCRX(const base::FilePath& dir_path,
603 const base::FilePath& pem_path,
[email protected]be083862012-09-01 03:53:45604 InstallState install_state,
605 int creation_flags) {
[email protected]650b2d52013-02-10 03:41:45606 base::FilePath crx_path;
[email protected]ea1a3f62012-11-16 20:34:23607 base::ScopedTempDir temp_dir;
[email protected]8f512c72011-11-22 21:02:50608 EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
609 crx_path = temp_dir.path().AppendASCII("temp.crx");
610
611 PackCRX(dir_path, pem_path, crx_path);
[email protected]be083862012-09-01 03:53:45612 return InstallCRX(crx_path, install_state, creation_flags);
613 }
614
[email protected]650b2d52013-02-10 03:41:45615 const Extension* PackAndInstallCRX(const base::FilePath& dir_path,
616 const base::FilePath& pem_path,
[email protected]be083862012-09-01 03:53:45617 InstallState install_state) {
618 return PackAndInstallCRX(dir_path, pem_path, install_state,
619 Extension::NO_FLAGS);
[email protected]145a317b2011-04-12 16:03:46620 }
621
[email protected]650b2d52013-02-10 03:41:45622 const Extension* PackAndInstallCRX(const base::FilePath& dir_path,
[email protected]8f512c72011-11-22 21:02:50623 InstallState install_state) {
[email protected]650b2d52013-02-10 03:41:45624 return PackAndInstallCRX(dir_path, base::FilePath(), install_state,
[email protected]be083862012-09-01 03:53:45625 Extension::NO_FLAGS);
626 }
627
[email protected]e7554c3f2013-05-29 00:36:56628 // Attempts to install an extension. Use INSTALL_FAILED if the installation
629 // is expected to fail.
630 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is
631 // non-empty, expects that the existing extension's title was
632 // |expected_old_name|.
633 const Extension* InstallCRX(const base::FilePath& path,
634 InstallState install_state,
635 int creation_flags,
636 const std::string& expected_old_name) {
[email protected]97d6a5c2013-11-11 23:51:24637 InstallCRXInternal(path, creation_flags);
638 return VerifyCrxInstall(path, install_state, expected_old_name);
[email protected]e7554c3f2013-05-29 00:36:56639 }
640
641 // Attempts to install an extension. Use INSTALL_FAILED if the installation
642 // is expected to fail.
[email protected]650b2d52013-02-10 03:41:45643 const Extension* InstallCRX(const base::FilePath& path,
[email protected]be083862012-09-01 03:53:45644 InstallState install_state,
645 int creation_flags) {
[email protected]97d6a5c2013-11-11 23:51:24646 return InstallCRX(path, install_state, creation_flags, std::string());
[email protected]8f512c72011-11-22 21:02:50647 }
648
[email protected]65187152012-06-02 13:14:14649 // Attempts to install an extension. Use INSTALL_FAILED if the installation
650 // is expected to fail.
[email protected]650b2d52013-02-10 03:41:45651 const Extension* InstallCRX(const base::FilePath& path,
[email protected]8f512c72011-11-22 21:02:50652 InstallState install_state) {
[email protected]be083862012-09-01 03:53:45653 return InstallCRX(path, install_state, Extension::NO_FLAGS);
[email protected]8f512c72011-11-22 21:02:50654 }
655
[email protected]650b2d52013-02-10 03:41:45656 const Extension* InstallCRXFromWebStore(const base::FilePath& path,
[email protected]8f512c72011-11-22 21:02:50657 InstallState install_state) {
[email protected]97d6a5c2013-11-11 23:51:24658 InstallCRXInternal(path, Extension::FROM_WEBSTORE);
659 return VerifyCrxInstall(path, install_state);
[email protected]8f512c72011-11-22 21:02:50660 }
661
[email protected]650b2d52013-02-10 03:41:45662 const Extension* InstallCRXWithLocation(const base::FilePath& crx_path,
[email protected]1d5e58b2013-01-31 08:41:40663 Manifest::Location install_location,
[email protected]8f512c72011-11-22 21:02:50664 InstallState install_state) {
[email protected]7567484142013-07-11 17:36:07665 EXPECT_TRUE(base::PathExists(crx_path))
[email protected]145a317b2011-04-12 16:03:46666 << "Path does not exist: "<< crx_path.value().c_str();
[email protected]14908b72011-04-20 06:54:36667 // no client (silent install)
[email protected]f484f8d52014-06-12 08:38:18668 scoped_refptr<CrxInstaller> installer(
669 CrxInstaller::CreateSilent(service()));
[email protected]145a317b2011-04-12 16:03:46670 installer->set_install_source(install_location);
[email protected]145a317b2011-04-12 16:03:46671
[email protected]97d6a5c2013-11-11 23:51:24672 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:06673 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:24674 content::NotificationService::AllSources());
675 installer->InstallCrx(crx_path);
676 observer.Wait();
677
678 return VerifyCrxInstall(crx_path, install_state);
[email protected]145a317b2011-04-12 16:03:46679 }
680
[email protected]97d6a5c2013-11-11 23:51:24681 // Verifies the result of a CRX installation. Used by InstallCRX. Set the
[email protected]65187152012-06-02 13:14:14682 // |install_state| to INSTALL_FAILED if the installation is expected to fail.
[email protected]8f512c72011-11-22 21:02:50683 // Returns an Extension pointer if the install succeeded, NULL otherwise.
[email protected]97d6a5c2013-11-11 23:51:24684 const Extension* VerifyCrxInstall(const base::FilePath& path,
685 InstallState install_state) {
686 return VerifyCrxInstall(path, install_state, std::string());
[email protected]e7554c3f2013-05-29 00:36:56687 }
688
[email protected]97d6a5c2013-11-11 23:51:24689 // Verifies the result of a CRX installation. Used by InstallCRX. Set the
[email protected]e7554c3f2013-05-29 00:36:56690 // |install_state| to INSTALL_FAILED if the installation is expected to fail.
691 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is
692 // non-empty, expects that the existing extension's title was
693 // |expected_old_name|.
694 // Returns an Extension pointer if the install succeeded, NULL otherwise.
[email protected]97d6a5c2013-11-11 23:51:24695 const Extension* VerifyCrxInstall(const base::FilePath& path,
696 InstallState install_state,
697 const std::string& expected_old_name) {
[email protected]d2065e062013-12-12 23:49:52698 std::vector<base::string16> errors = GetErrors();
[email protected]8f512c72011-11-22 21:02:50699 const Extension* extension = NULL;
700 if (install_state != INSTALL_FAILED) {
701 if (install_state == INSTALL_NEW)
702 ++expected_extensions_count_;
[email protected]902f7cd2009-05-22 19:02:19703
[email protected]a57209872009-05-04 22:53:14704 EXPECT_TRUE(installed_) << path.value();
[email protected]41bb80bd2013-05-03 10:56:02705 // If and only if INSTALL_UPDATED, it should have the is_update flag.
706 EXPECT_EQ(install_state == INSTALL_UPDATED, was_update_)
707 << path.value();
[email protected]e7554c3f2013-05-29 00:36:56708 // If INSTALL_UPDATED, old_name_ should match the given string.
709 if (install_state == INSTALL_UPDATED && !expected_old_name.empty())
710 EXPECT_EQ(expected_old_name, old_name_);
[email protected]bb28e062009-02-27 17:19:18711 EXPECT_EQ(0u, errors.size()) << path.value();
[email protected]695b5712012-12-06 23:55:28712
713 if (install_state == INSTALL_WITHOUT_LOAD) {
714 EXPECT_EQ(0u, loaded_.size()) << path.value();
715 } else {
716 EXPECT_EQ(1u, loaded_.size()) << path.value();
[email protected]f484f8d52014-06-12 08:38:18717 size_t actual_extension_count =
718 registry()->enabled_extensions().size() +
719 registry()->disabled_extensions().size();
[email protected]b1ac70462013-08-14 21:33:30720 EXPECT_EQ(expected_extensions_count_, actual_extension_count) <<
[email protected]695b5712012-12-06 23:55:28721 path.value();
[email protected]dc24976f2013-06-02 21:15:09722 extension = loaded_[0].get();
[email protected]f484f8d52014-06-12 08:38:18723 EXPECT_TRUE(service()->GetExtensionById(extension->id(), false))
[email protected]dc24976f2013-06-02 21:15:09724 << path.value();
[email protected]695b5712012-12-06 23:55:28725 }
726
[email protected]d2065e062013-12-12 23:49:52727 for (std::vector<base::string16>::iterator err = errors.begin();
[email protected]bb28e062009-02-27 17:19:18728 err != errors.end(); ++err) {
[email protected]37eeb5a2009-02-26 23:36:17729 LOG(ERROR) << *err;
730 }
[email protected]cc655912009-01-29 23:19:19731 } else {
[email protected]a57209872009-05-04 22:53:14732 EXPECT_FALSE(installed_) << path.value();
[email protected]86a274072009-06-11 02:06:45733 EXPECT_EQ(0u, loaded_.size()) << path.value();
[email protected]bb28e062009-02-27 17:19:18734 EXPECT_EQ(1u, errors.size()) << path.value();
[email protected]cc655912009-01-29 23:19:19735 }
[email protected]bb28e062009-02-27 17:19:18736
[email protected]a57209872009-05-04 22:53:14737 installed_ = NULL;
[email protected]41bb80bd2013-05-03 10:56:02738 was_update_ = false;
[email protected]e7554c3f2013-05-29 00:36:56739 old_name_ = "";
[email protected]894bb502009-05-21 22:39:57740 loaded_.clear();
[email protected]bb28e062009-02-27 17:19:18741 ExtensionErrorReporter::GetInstance()->ClearErrors();
[email protected]8f512c72011-11-22 21:02:50742 return extension;
[email protected]cc655912009-01-29 23:19:19743 }
744
[email protected]4416c5a2010-06-26 01:28:57745 enum UpdateState {
746 FAILED_SILENTLY,
747 FAILED,
748 UPDATED,
749 INSTALLED,
[email protected]343a0d872014-08-05 11:44:18750 DISABLED,
[email protected]4416c5a2010-06-26 01:28:57751 ENABLED
752 };
753
[email protected]98270432012-09-11 20:51:24754 void BlackListWebGL() {
755 static const std::string json_blacklist =
756 "{\n"
757 " \"name\": \"gpu blacklist\",\n"
758 " \"version\": \"1.0\",\n"
759 " \"entries\": [\n"
760 " {\n"
761 " \"id\": 1,\n"
[email protected]3d346572013-03-22 19:59:55762 " \"features\": [\"webgl\"]\n"
[email protected]98270432012-09-11 20:51:24763 " }\n"
764 " ]\n"
765 "}";
[email protected]d7b5cc72013-05-23 20:05:00766 gpu::GPUInfo gpu_info;
[email protected]7e343152012-09-20 21:49:53767 content::GpuDataManager::GetInstance()->InitializeForTesting(
768 json_blacklist, gpu_info);
[email protected]98270432012-09-11 20:51:24769 }
770
[email protected]97d6a5c2013-11-11 23:51:24771 // Helper method to set up a WindowedNotificationObserver to wait for a
772 // specific CrxInstaller to finish if we don't know the value of the
773 // |installer| yet.
774 static bool IsCrxInstallerDone(extensions::CrxInstaller** installer,
775 const content::NotificationSource& source,
776 const content::NotificationDetails& details) {
777 return content::Source<extensions::CrxInstaller>(source).ptr() ==
778 *installer;
779 }
780
[email protected]343a0d872014-08-05 11:44:18781 void PackCRXAndUpdateExtension(const std::string& id,
782 const base::FilePath& dir_path,
783 const base::FilePath& pem_path,
784 UpdateState expected_state) {
785 base::ScopedTempDir temp_dir;
786 EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
787 base::FilePath crx_path = temp_dir.path().AppendASCII("temp.crx");
788
789 PackCRX(dir_path, pem_path, crx_path);
790 UpdateExtension(id, crx_path, expected_state);
791 }
792
[email protected]97d6a5c2013-11-11 23:51:24793 void UpdateExtension(const std::string& id,
794 const base::FilePath& in_path,
[email protected]4416c5a2010-06-26 01:28:57795 UpdateState expected_state) {
[email protected]7567484142013-07-11 17:36:07796 ASSERT_TRUE(base::PathExists(in_path));
[email protected]e957fe52009-06-23 16:51:05797
[email protected]7577a5c52009-07-30 06:21:58798 // We need to copy this to a temporary location because Update() will delete
799 // it.
[email protected]f484f8d52014-06-12 08:38:18800 base::FilePath path = temp_dir().path();
[email protected]a1295ba22009-09-02 03:33:39801 path = path.Append(in_path.BaseName());
[email protected]f0ff2ad2013-07-09 17:42:26802 ASSERT_TRUE(base::CopyFile(in_path, path));
[email protected]e957fe52009-06-23 16:51:05803
[email protected]4416c5a2010-06-26 01:28:57804 int previous_enabled_extension_count =
[email protected]f484f8d52014-06-12 08:38:18805 registry()->enabled_extensions().size();
[email protected]4416c5a2010-06-26 01:28:57806 int previous_installed_extension_count =
807 previous_enabled_extension_count +
[email protected]f484f8d52014-06-12 08:38:18808 registry()->disabled_extensions().size();
[email protected]4416c5a2010-06-26 01:28:57809
[email protected]6d057a0c2013-07-09 21:12:07810 extensions::CrxInstaller* installer = NULL;
[email protected]97d6a5c2013-11-11 23:51:24811 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:06812 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:24813 base::Bind(&IsCrxInstallerDone, &installer));
[email protected]f484f8d52014-06-12 08:38:18814 service()->UpdateExtension(id, path, true, &installer);
[email protected]6d057a0c2013-07-09 21:12:07815
[email protected]97d6a5c2013-11-11 23:51:24816 if (installer)
817 observer.Wait();
818 else
[email protected]eedc1c752013-08-09 18:51:55819 base::RunLoop().RunUntilIdle();
[email protected]f3113e232010-06-25 01:36:40820
[email protected]d2065e062013-12-12 23:49:52821 std::vector<base::string16> errors = GetErrors();
[email protected]4416c5a2010-06-26 01:28:57822 int error_count = errors.size();
[email protected]f484f8d52014-06-12 08:38:18823 int enabled_extension_count = registry()->enabled_extensions().size();
[email protected]4416c5a2010-06-26 01:28:57824 int installed_extension_count =
[email protected]f484f8d52014-06-12 08:38:18825 enabled_extension_count + registry()->disabled_extensions().size();
[email protected]4416c5a2010-06-26 01:28:57826
827 int expected_error_count = (expected_state == FAILED) ? 1 : 0;
828 EXPECT_EQ(expected_error_count, error_count) << path.value();
829
830 if (expected_state <= FAILED) {
831 EXPECT_EQ(previous_enabled_extension_count,
832 enabled_extension_count);
833 EXPECT_EQ(previous_installed_extension_count,
834 installed_extension_count);
[email protected]e957fe52009-06-23 16:51:05835 } else {
[email protected]4416c5a2010-06-26 01:28:57836 int expected_installed_extension_count =
837 (expected_state >= INSTALLED) ? 1 : 0;
838 int expected_enabled_extension_count =
839 (expected_state >= ENABLED) ? 1 : 0;
840 EXPECT_EQ(expected_installed_extension_count,
841 installed_extension_count);
842 EXPECT_EQ(expected_enabled_extension_count,
843 enabled_extension_count);
[email protected]e957fe52009-06-23 16:51:05844 }
[email protected]7577a5c52009-07-30 06:21:58845
[email protected]31d8f5f22012-04-02 15:22:08846 // Update() should the temporary input file.
[email protected]7567484142013-07-11 17:36:07847 EXPECT_FALSE(base::PathExists(path));
[email protected]e957fe52009-06-23 16:51:05848 }
849
[email protected]fa2416f2011-05-03 08:41:20850 void TerminateExtension(const std::string& id) {
[email protected]f484f8d52014-06-12 08:38:18851 const Extension* extension = service()->GetInstalledExtension(id);
[email protected]fa2416f2011-05-03 08:41:20852 if (!extension) {
853 ADD_FAILURE();
854 return;
855 }
[email protected]f484f8d52014-06-12 08:38:18856 service()->TrackTerminatedExtensionForTest(extension);
[email protected]fa2416f2011-05-03 08:41:20857 }
858
859 size_t GetPrefKeyCount() {
[email protected]023b3d12013-12-23 18:46:49860 const base::DictionaryValue* dict =
[email protected]f484f8d52014-06-12 08:38:18861 profile()->GetPrefs()->GetDictionary("extensions.settings");
[email protected]fa2416f2011-05-03 08:41:20862 if (!dict) {
863 ADD_FAILURE();
864 return 0;
865 }
866 return dict->size();
867 }
868
869 void UninstallExtension(const std::string& id, bool use_helper) {
870 // Verify that the extension is installed.
[email protected]f484f8d52014-06-12 08:38:18871 base::FilePath extension_path = extensions_install_dir().AppendASCII(id);
[email protected]7567484142013-07-11 17:36:07872 EXPECT_TRUE(base::PathExists(extension_path));
[email protected]fa2416f2011-05-03 08:41:20873 size_t pref_key_count = GetPrefKeyCount();
874 EXPECT_GT(pref_key_count, 0u);
875 ValidateIntegerPref(id, "state", Extension::ENABLED);
876
877 // Uninstall it.
878 if (use_helper) {
[email protected]cc2f55c2014-07-08 02:19:04879 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(
[email protected]e43c61f2014-07-20 21:46:34880 service(), id, extensions::UNINSTALL_REASON_FOR_TESTING));
[email protected]fa2416f2011-05-03 08:41:20881 } else {
[email protected]cc2f55c2014-07-08 02:19:04882 EXPECT_TRUE(service()->UninstallExtension(
[email protected]42d58f62014-07-31 01:32:45883 id,
884 extensions::UNINSTALL_REASON_FOR_TESTING,
885 base::Bind(&base::DoNothing),
886 NULL));
[email protected]fa2416f2011-05-03 08:41:20887 }
[email protected]8f512c72011-11-22 21:02:50888 --expected_extensions_count_;
[email protected]fa2416f2011-05-03 08:41:20889
890 // We should get an unload notification.
891 EXPECT_FALSE(unloaded_id_.empty());
892 EXPECT_EQ(id, unloaded_id_);
893
894 // Verify uninstalled state.
895 size_t new_pref_key_count = GetPrefKeyCount();
896 if (new_pref_key_count == pref_key_count) {
897 ValidateIntegerPref(id, "location",
898 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
899 } else {
900 EXPECT_EQ(new_pref_key_count, pref_key_count - 1);
901 }
902
903 // The extension should not be in the service anymore.
[email protected]f484f8d52014-06-12 08:38:18904 EXPECT_FALSE(service()->GetInstalledExtension(id));
[email protected]eedc1c752013-08-09 18:51:55905 base::RunLoop().RunUntilIdle();
[email protected]fa2416f2011-05-03 08:41:20906
907 // The directory should be gone.
[email protected]7567484142013-07-11 17:36:07908 EXPECT_FALSE(base::PathExists(extension_path));
[email protected]fa2416f2011-05-03 08:41:20909 }
910
911 void ValidatePrefKeyCount(size_t count) {
912 EXPECT_EQ(count, GetPrefKeyCount());
[email protected]25b34332009-06-05 21:53:19913 }
914
[email protected]3f2a2fa2013-09-24 02:55:25915 testing::AssertionResult ValidateBooleanPref(
916 const std::string& extension_id,
917 const std::string& pref_path,
918 bool expected_val) {
919 std::string msg = "while checking: ";
[email protected]e2194742010-08-12 05:54:34920 msg += extension_id;
921 msg += " ";
[email protected]6b75ec32009-08-14 06:37:18922 msg += pref_path;
[email protected]e2194742010-08-12 05:54:34923 msg += " == ";
924 msg += expected_val ? "true" : "false";
[email protected]6b75ec32009-08-14 06:37:18925
[email protected]f484f8d52014-06-12 08:38:18926 PrefService* prefs = profile()->GetPrefs();
[email protected]023b3d12013-12-23 18:46:49927 const base::DictionaryValue* dict =
[email protected]2fb7dc982010-09-29 12:24:28928 prefs->GetDictionary("extensions.settings");
[email protected]3f2a2fa2013-09-24 02:55:25929 if (!dict) {
930 return testing::AssertionFailure()
931 << "extension.settings does not exist " << msg;
932 }
933
[email protected]023b3d12013-12-23 18:46:49934 const base::DictionaryValue* pref = NULL;
[email protected]3f2a2fa2013-09-24 02:55:25935 if (!dict->GetDictionary(extension_id, &pref)) {
936 return testing::AssertionFailure()
937 << "extension pref does not exist " << msg;
938 }
939
[email protected]6b75ec32009-08-14 06:37:18940 bool val;
[email protected]3f2a2fa2013-09-24 02:55:25941 if (!pref->GetBoolean(pref_path, &val)) {
942 return testing::AssertionFailure()
943 << pref_path << " pref not found " << msg;
944 }
945
946 return expected_val == val
947 ? testing::AssertionSuccess()
[email protected]023b3d12013-12-23 18:46:49948 : testing::AssertionFailure() << "base::Value is incorrect " << msg;
[email protected]6b75ec32009-08-14 06:37:18949 }
950
951 bool IsPrefExist(const std::string& extension_id,
[email protected]e2194742010-08-12 05:54:34952 const std::string& pref_path) {
[email protected]023b3d12013-12-23 18:46:49953 const base::DictionaryValue* dict =
[email protected]f484f8d52014-06-12 08:38:18954 profile()->GetPrefs()->GetDictionary("extensions.settings");
[email protected]6b75ec32009-08-14 06:37:18955 if (dict == NULL) return false;
[email protected]023b3d12013-12-23 18:46:49956 const base::DictionaryValue* pref = NULL;
[email protected]e2194742010-08-12 05:54:34957 if (!dict->GetDictionary(extension_id, &pref)) {
[email protected]6b75ec32009-08-14 06:37:18958 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]e2194742010-08-12 05:54:34971 const std::string& pref_path,
[email protected]c6d474f82009-12-16 21:11:06972 int expected_val) {
[email protected]e2194742010-08-12 05:54:34973 std::string msg = " while checking: ";
974 msg += extension_id;
975 msg += " ";
[email protected]25b34332009-06-05 21:53:19976 msg += pref_path;
[email protected]e2194742010-08-12 05:54:34977 msg += " == ";
978 msg += base::IntToString(expected_val);
[email protected]25b34332009-06-05 21:53:19979
[email protected]f484f8d52014-06-12 08:38:18980 PrefService* prefs = profile()->GetPrefs();
[email protected]023b3d12013-12-23 18:46:49981 const base::DictionaryValue* dict =
[email protected]2fb7dc982010-09-29 12:24:28982 prefs->GetDictionary("extensions.settings");
[email protected]25b34332009-06-05 21:53:19983 ASSERT_TRUE(dict != NULL) << msg;
[email protected]023b3d12013-12-23 18:46:49984 const base::DictionaryValue* pref = NULL;
[email protected]e2194742010-08-12 05:54:34985 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
[email protected]25b34332009-06-05 21:53:19986 EXPECT_TRUE(pref != NULL) << msg;
987 int val;
[email protected]4c91487e2009-10-02 04:11:04988 ASSERT_TRUE(pref->GetInteger(pref_path, &val)) << msg;
[email protected]c6d474f82009-12-16 21:11:06989 EXPECT_EQ(expected_val, val) << msg;
990 }
991
992 void ValidateStringPref(const std::string& extension_id,
[email protected]e2194742010-08-12 05:54:34993 const std::string& pref_path,
[email protected]c6d474f82009-12-16 21:11:06994 const std::string& expected_val) {
[email protected]e2194742010-08-12 05:54:34995 std::string msg = " while checking: ";
996 msg += extension_id;
997 msg += ".manifest.";
[email protected]c6d474f82009-12-16 21:11:06998 msg += pref_path;
[email protected]e2194742010-08-12 05:54:34999 msg += " == ";
1000 msg += expected_val;
[email protected]c6d474f82009-12-16 21:11:061001
[email protected]023b3d12013-12-23 18:46:491002 const base::DictionaryValue* dict =
[email protected]f484f8d52014-06-12 08:38:181003 profile()->GetPrefs()->GetDictionary("extensions.settings");
[email protected]c6d474f82009-12-16 21:11:061004 ASSERT_TRUE(dict != NULL) << msg;
[email protected]023b3d12013-12-23 18:46:491005 const base::DictionaryValue* pref = NULL;
[email protected]c6d474f82009-12-16 21:11:061006 std::string manifest_path = extension_id + ".manifest";
[email protected]e2194742010-08-12 05:54:341007 ASSERT_TRUE(dict->GetDictionary(manifest_path, &pref)) << msg;
[email protected]c6d474f82009-12-16 21:11:061008 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]25b34332009-06-05 21:53:191012 }
1013
[email protected]8d888c12010-11-30 00:00:251014 void SetPref(const std::string& extension_id,
1015 const std::string& pref_path,
[email protected]023b3d12013-12-23 18:46:491016 base::Value* value,
[email protected]8d888c12010-11-30 00:00:251017 const std::string& msg) {
[email protected]f484f8d52014-06-12 08:38:181018 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings");
[email protected]023b3d12013-12-23 18:46:491019 base::DictionaryValue* dict = update.Get();
[email protected]8d888c12010-11-30 00:00:251020 ASSERT_TRUE(dict != NULL) << msg;
[email protected]023b3d12013-12-23 18:46:491021 base::DictionaryValue* pref = NULL;
[email protected]8d888c12010-11-30 00:00:251022 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
1023 EXPECT_TRUE(pref != NULL) << msg;
1024 pref->Set(pref_path, value);
1025 }
1026
[email protected]6b75ec32009-08-14 06:37:181027 void SetPrefInteg(const std::string& extension_id,
[email protected]e2194742010-08-12 05:54:341028 const std::string& pref_path,
[email protected]6b75ec32009-08-14 06:37:181029 int value) {
[email protected]e2194742010-08-12 05:54:341030 std::string msg = " while setting: ";
1031 msg += extension_id;
1032 msg += " ";
[email protected]a1257b12009-06-12 02:51:341033 msg += pref_path;
[email protected]e2194742010-08-12 05:54:341034 msg += " = ";
1035 msg += base::IntToString(value);
[email protected]a1257b12009-06-12 02:51:341036
[email protected]aa15e2e2013-08-14 02:13:581037 SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg);
[email protected]8d888c12010-11-30 00:00:251038 }
1039
1040 void SetPrefBool(const std::string& extension_id,
1041 const std::string& pref_path,
1042 bool value) {
1043 std::string msg = " while setting: ";
1044 msg += extension_id + " " + pref_path;
1045 msg += " = ";
1046 msg += (value ? "true" : "false");
1047
[email protected]aa15e2e2013-08-14 02:13:581048 SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg);
[email protected]8d888c12010-11-30 00:00:251049 }
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]f484f8d52014-06-12 08:38:181056 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings");
[email protected]023b3d12013-12-23 18:46:491057 base::DictionaryValue* dict = update.Get();
[email protected]a1257b12009-06-12 02:51:341058 ASSERT_TRUE(dict != NULL) << msg;
[email protected]023b3d12013-12-23 18:46:491059 base::DictionaryValue* pref = NULL;
[email protected]e2194742010-08-12 05:54:341060 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
[email protected]a1257b12009-06-12 02:51:341061 EXPECT_TRUE(pref != NULL) << msg;
[email protected]8d888c12010-11-30 00:00:251062 pref->Remove(pref_path, NULL);
1063 }
1064
1065 void SetPrefStringSet(const std::string& extension_id,
1066 const std::string& pref_path,
1067 const std::set<std::string>& value) {
1068 std::string msg = " while setting: ";
1069 msg += extension_id + " " + pref_path;
1070
[email protected]023b3d12013-12-23 18:46:491071 base::ListValue* list_value = new base::ListValue();
[email protected]8d888c12010-11-30 00:00:251072 for (std::set<std::string>::const_iterator iter = value.begin();
1073 iter != value.end(); ++iter)
[email protected]aa15e2e2013-08-14 02:13:581074 list_value->Append(new base::StringValue(*iter));
[email protected]8d888c12010-11-30 00:00:251075
1076 SetPref(extension_id, pref_path, list_value, msg);
[email protected]a1257b12009-06-12 02:51:341077 }
1078
[email protected]ebd71962012-12-20 02:56:551079 void InitPluginService() {
1080#if defined(ENABLE_PLUGINS)
1081 PluginService::GetInstance()->Init();
1082#endif
1083 }
1084
[email protected]f484f8d52014-06-12 08:38:181085 void InitializeExtensionSyncService() {
1086 extension_sync_service_.reset(new ExtensionSyncService(
1087 profile(), ExtensionPrefs::Get(browser_context()), service()));
1088 }
1089
1090 extensions::ManagementPolicy* GetManagementPolicy() {
1091 return ExtensionSystem::Get(browser_context())->management_policy();
1092 }
1093
1094 ExtensionSyncService* extension_sync_service() {
1095 return extension_sync_service_.get();
1096 }
1097
[email protected]25b34332009-06-05 21:53:191098 protected:
[email protected]f484f8d52014-06-12 08:38:181099 scoped_ptr<ExtensionSyncService> extension_sync_service_;
[email protected]1c321ee52012-05-21 03:02:341100 extensions::ExtensionList loaded_;
[email protected]894bb502009-05-21 22:39:571101 std::string unloaded_id_;
[email protected]ebe07772014-05-22 04:16:061102 UnloadedExtensionInfo::Reason unloaded_reason_;
[email protected]9adb9692010-10-29 23:14:021103 const Extension* installed_;
[email protected]41bb80bd2013-05-03 10:56:021104 bool was_update_;
[email protected]e7554c3f2013-05-29 00:36:561105 std::string old_name_;
[email protected]00b5d0a52012-10-30 13:13:531106 FeatureSwitch::ScopedOverride override_external_install_prompt_;
[email protected]894bb502009-05-21 22:39:571107
[email protected]6014d672008-12-05 00:38:251108 private:
[email protected]97d6a5c2013-11-11 23:51:241109 // Create a CrxInstaller and install the CRX file.
1110 // Instead of calling this method yourself, use InstallCRX(), which does extra
1111 // error checking.
1112 void InstallCRXInternal(const base::FilePath& crx_path) {
1113 InstallCRXInternal(crx_path, Extension::NO_FLAGS);
1114 }
1115
1116 void InstallCRXInternal(const base::FilePath& crx_path, int creation_flags) {
1117 ASSERT_TRUE(base::PathExists(crx_path))
1118 << "Path does not exist: "<< crx_path.value().c_str();
[email protected]f484f8d52014-06-12 08:38:181119 scoped_refptr<CrxInstaller> installer(
1120 CrxInstaller::CreateSilent(service()));
[email protected]97d6a5c2013-11-11 23:51:241121 installer->set_creation_flags(creation_flags);
1122 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT))
1123 installer->set_allow_silent_install(true);
1124
1125 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:061126 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:241127 content::Source<extensions::CrxInstaller>(installer));
1128
1129 installer->InstallCrx(crx_path);
1130
1131 observer.Wait();
1132 }
1133
[email protected]f484f8d52014-06-12 08:38:181134 size_t expected_extensions_count_;
[email protected]6c2381d2011-10-19 02:52:531135 content::NotificationRegistrar registrar_;
[email protected]bb28e062009-02-27 17:19:181136};
[email protected]6014d672008-12-05 00:38:251137
[email protected]0349ab5d2010-08-11 21:41:571138// Receives notifications from a PackExtensionJob, indicating either that
1139// packing succeeded or that there was some error.
[email protected]d9ede582012-08-14 19:21:381140class PackExtensionTestClient : public extensions::PackExtensionJob::Client {
[email protected]0349ab5d2010-08-11 21:41:571141 public:
[email protected]650b2d52013-02-10 03:41:451142 PackExtensionTestClient(const base::FilePath& expected_crx_path,
1143 const base::FilePath& expected_private_key_path);
1144 virtual void OnPackSuccess(const base::FilePath& crx_path,
1145 const base::FilePath& private_key_path) OVERRIDE;
[email protected]93d973a2012-01-08 07:38:261146 virtual void OnPackFailure(const std::string& error_message,
[email protected]49aeab62013-02-07 02:53:111147 ExtensionCreator::ErrorType type) OVERRIDE;
[email protected]0349ab5d2010-08-11 21:41:571148
1149 private:
[email protected]650b2d52013-02-10 03:41:451150 const base::FilePath expected_crx_path_;
1151 const base::FilePath expected_private_key_path_;
[email protected]0349ab5d2010-08-11 21:41:571152 DISALLOW_COPY_AND_ASSIGN(PackExtensionTestClient);
1153};
1154
1155PackExtensionTestClient::PackExtensionTestClient(
[email protected]650b2d52013-02-10 03:41:451156 const base::FilePath& expected_crx_path,
1157 const base::FilePath& expected_private_key_path)
[email protected]0349ab5d2010-08-11 21:41:571158 : expected_crx_path_(expected_crx_path),
1159 expected_private_key_path_(expected_private_key_path) {}
1160
1161// If packing succeeded, we make sure that the package names match our
1162// expectations.
[email protected]650b2d52013-02-10 03:41:451163void PackExtensionTestClient::OnPackSuccess(
1164 const base::FilePath& crx_path,
1165 const base::FilePath& private_key_path) {
[email protected]0349ab5d2010-08-11 21:41:571166 // We got the notification and processed it; we don't expect any further tasks
1167 // to be posted to the current thread, so we should stop blocking and continue
1168 // on with the rest of the test.
1169 // This call to |Quit()| matches the call to |Run()| in the
1170 // |PackPunctuatedExtension| test.
[email protected]b3a25092013-05-28 22:08:161171 base::MessageLoop::current()->Quit();
[email protected]0349ab5d2010-08-11 21:41:571172 EXPECT_EQ(expected_crx_path_.value(), crx_path.value());
1173 EXPECT_EQ(expected_private_key_path_.value(), private_key_path.value());
[email protected]7567484142013-07-11 17:36:071174 ASSERT_TRUE(base::PathExists(private_key_path));
[email protected]0349ab5d2010-08-11 21:41:571175}
1176
1177// The tests are designed so that we never expect to see a packing error.
[email protected]93d973a2012-01-08 07:38:261178void PackExtensionTestClient::OnPackFailure(const std::string& error_message,
1179 ExtensionCreator::ErrorType type) {
1180 if (type == ExtensionCreator::kCRXExists)
1181 FAIL() << "Packing should not fail.";
1182 else
1183 FAIL() << "Existing CRX should have been overwritten.";
[email protected]0349ab5d2010-08-11 21:41:571184}
1185
[email protected]54cb3c92009-02-17 22:30:211186// Test loading good extensions from the profile directory.
[email protected]d9a61e12012-11-14 02:43:471187TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) {
[email protected]ebd71962012-12-20 02:56:551188 InitPluginService();
[email protected]3f2a2fa2013-09-24 02:55:251189 InitializeGoodInstalledExtensionService();
[email protected]f484f8d52014-06-12 08:38:181190 service()->Init();
[email protected]6014d672008-12-05 00:38:251191
[email protected]e50013c32010-08-18 21:05:241192 uint32 expected_num_extensions = 3u;
[email protected]e50013c32010-08-18 21:05:241193 ASSERT_EQ(expected_num_extensions, loaded_.size());
[email protected]6014d672008-12-05 00:38:251194
[email protected]fbcc40302009-06-12 20:45:451195 EXPECT_EQ(std::string(good0), loaded_[0]->id());
[email protected]e1cec06c2008-12-18 01:22:231196 EXPECT_EQ(std::string("My extension 1"),
[email protected]894bb502009-05-21 22:39:571197 loaded_[0]->name());
[email protected]e1cec06c2008-12-18 01:22:231198 EXPECT_EQ(std::string("The first extension that I made."),
[email protected]894bb502009-05-21 22:39:571199 loaded_[0]->description());
[email protected]1d5e58b2013-01-31 08:41:401200 EXPECT_EQ(Manifest::INTERNAL, loaded_[0]->location());
[email protected]f484f8d52014-06-12 08:38:181201 EXPECT_TRUE(service()->GetExtensionById(loaded_[0]->id(), false));
1202 EXPECT_EQ(expected_num_extensions, registry()->enabled_extensions().size());
[email protected]eab9b452009-01-23 20:48:591203
[email protected]25b34332009-06-05 21:53:191204 ValidatePrefKeyCount(3);
[email protected]e2194742010-08-12 05:54:341205 ValidateIntegerPref(good0, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:401206 ValidateIntegerPref(good0, "location", Manifest::INTERNAL);
[email protected]e2194742010-08-12 05:54:341207 ValidateIntegerPref(good1, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:401208 ValidateIntegerPref(good1, "location", Manifest::INTERNAL);
[email protected]e2194742010-08-12 05:54:341209 ValidateIntegerPref(good2, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:401210 ValidateIntegerPref(good2, "location", Manifest::INTERNAL);
[email protected]25b34332009-06-05 21:53:191211
[email protected]06e8b8ff2011-07-13 15:03:471212 URLPatternSet expected_patterns;
1213 AddPattern(&expected_patterns, "file:///*");
1214 AddPattern(&expected_patterns, "http://*.google.com/*");
1215 AddPattern(&expected_patterns, "https://*.google.com/*");
[email protected]dc24976f2013-06-02 21:15:091216 const Extension* extension = loaded_[0].get();
[email protected]334ec0a2013-03-24 01:36:161217 const extensions::UserScriptList& scripts =
1218 extensions::ContentScriptsInfo::GetContentScripts(extension);
[email protected]e66de892009-03-20 20:38:431219 ASSERT_EQ(2u, scripts.size());
[email protected]06e8b8ff2011-07-13 15:03:471220 EXPECT_EQ(expected_patterns, scripts[0].url_patterns());
[email protected]e66de892009-03-20 20:38:431221 EXPECT_EQ(2u, scripts[0].js_scripts().size());
[email protected]052c92702010-06-25 07:25:521222 ExtensionResource resource00(extension->id(),
1223 scripts[0].js_scripts()[0].extension_root(),
[email protected]9194b3f2009-10-20 15:27:211224 scripts[0].js_scripts()[0].relative_path());
[email protected]15476932013-04-12 05:17:151225 base::FilePath expected_path =
1226 base::MakeAbsoluteFilePath(extension->path().AppendASCII("script1.js"));
[email protected]a14b16b2009-10-28 12:41:291227 EXPECT_TRUE(resource00.ComparePathWithDefault(expected_path));
[email protected]052c92702010-06-25 07:25:521228 ExtensionResource resource01(extension->id(),
1229 scripts[0].js_scripts()[1].extension_root(),
[email protected]9194b3f2009-10-20 15:27:211230 scripts[0].js_scripts()[1].relative_path());
[email protected]15476932013-04-12 05:17:151231 expected_path =
1232 base::MakeAbsoluteFilePath(extension->path().AppendASCII("script2.js"));
[email protected]a14b16b2009-10-28 12:41:291233 EXPECT_TRUE(resource01.ComparePathWithDefault(expected_path));
[email protected]098fa7a2013-03-08 22:11:171234 EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(extension));
[email protected]06e8b8ff2011-07-13 15:03:471235 EXPECT_EQ(1u, scripts[1].url_patterns().patterns().size());
1236 EXPECT_EQ("http://*.news.com/*",
1237 scripts[1].url_patterns().begin()->GetAsString());
[email protected]052c92702010-06-25 07:25:521238 ExtensionResource resource10(extension->id(),
1239 scripts[1].js_scripts()[0].extension_root(),
[email protected]9194b3f2009-10-20 15:27:211240 scripts[1].js_scripts()[0].relative_path());
[email protected]a14b16b2009-10-28 12:41:291241 expected_path =
1242 extension->path().AppendASCII("js_files").AppendASCII("script3.js");
[email protected]15476932013-04-12 05:17:151243 expected_path = base::MakeAbsoluteFilePath(expected_path);
[email protected]a14b16b2009-10-28 12:41:291244 EXPECT_TRUE(resource10.ComparePathWithDefault(expected_path));
[email protected]06e8b8ff2011-07-13 15:03:471245
1246 expected_patterns.ClearPatterns();
1247 AddPattern(&expected_patterns, "http://*.google.com/*");
1248 AddPattern(&expected_patterns, "https://*.google.com/*");
[email protected]076ebeda2014-06-06 21:47:261249 EXPECT_EQ(
1250 expected_patterns,
1251 extension->permissions_data()->active_permissions()->explicit_hosts());
[email protected]6014d672008-12-05 00:38:251252
[email protected]25b34332009-06-05 21:53:191253 EXPECT_EQ(std::string(good1), loaded_[1]->id());
[email protected]894bb502009-05-21 22:39:571254 EXPECT_EQ(std::string("My extension 2"), loaded_[1]->name());
[email protected]007b3f82013-04-09 08:46:451255 EXPECT_EQ(std::string(), loaded_[1]->description());
[email protected]81067e02009-07-27 15:12:091256 EXPECT_EQ(loaded_[1]->GetResourceURL("background.html"),
[email protected]dc24976f2013-06-02 21:15:091257 extensions::BackgroundInfo::GetBackgroundURL(loaded_[1].get()));
1258 EXPECT_EQ(0u,
1259 extensions::ContentScriptsInfo::GetContentScripts(loaded_[1].get())
1260 .size());
[email protected]098fa7a2013-03-08 22:11:171261
[email protected]b8fb3032011-04-29 18:45:561262 // We don't parse the plugins section on Chrome OS.
1263#if defined(OS_CHROMEOS)
[email protected]144b6c42013-06-14 07:30:381264 EXPECT_TRUE(!extensions::PluginInfo::HasPlugins(loaded_[1].get()));
[email protected]b8fb3032011-04-29 18:45:561265#else
[email protected]dc24976f2013-06-02 21:15:091266 ASSERT_TRUE(extensions::PluginInfo::HasPlugins(loaded_[1].get()));
[email protected]098fa7a2013-03-08 22:11:171267 const std::vector<extensions::PluginInfo>* plugins =
[email protected]dc24976f2013-06-02 21:15:091268 extensions::PluginInfo::GetPlugins(loaded_[1].get());
[email protected]098fa7a2013-03-08 22:11:171269 ASSERT_TRUE(plugins);
1270 ASSERT_EQ(2u, plugins->size());
[email protected]c533bb22009-06-03 19:06:111271 EXPECT_EQ(loaded_[1]->path().AppendASCII("content_plugin.dll").value(),
[email protected]098fa7a2013-03-08 22:11:171272 plugins->at(0).path.value());
1273 EXPECT_TRUE(plugins->at(0).is_public);
[email protected]c533bb22009-06-03 19:06:111274 EXPECT_EQ(loaded_[1]->path().AppendASCII("extension_plugin.dll").value(),
[email protected]098fa7a2013-03-08 22:11:171275 plugins->at(1).path.value());
1276 EXPECT_FALSE(plugins->at(1).is_public);
[email protected]e50013c32010-08-18 21:05:241277#endif
[email protected]18a12352009-01-31 01:33:281278
[email protected]1d5e58b2013-01-31 08:41:401279 EXPECT_EQ(Manifest::INTERNAL, loaded_[1]->location());
[email protected]b8fb3032011-04-29 18:45:561280
[email protected]e50013c32010-08-18 21:05:241281 int index = expected_num_extensions - 1;
1282 EXPECT_EQ(std::string(good2), loaded_[index]->id());
1283 EXPECT_EQ(std::string("My extension 3"), loaded_[index]->name());
[email protected]007b3f82013-04-09 08:46:451284 EXPECT_EQ(std::string(), loaded_[index]->description());
[email protected]dc24976f2013-06-02 21:15:091285 EXPECT_EQ(0u,
1286 extensions::ContentScriptsInfo::GetContentScripts(
1287 loaded_[index].get()).size());
[email protected]1d5e58b2013-01-31 08:41:401288 EXPECT_EQ(Manifest::INTERNAL, loaded_[index]->location());
[email protected]6014d672008-12-05 00:38:251289};
[email protected]cc655912009-01-29 23:19:191290
[email protected]54cb3c92009-02-17 22:30:211291// Test loading bad extensions from the profile directory.
[email protected]d9a61e12012-11-14 02:43:471292TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) {
[email protected]c6d474f82009-12-16 21:11:061293 // Initialize the test dir with a bad Preferences/extensions.
[email protected]f484f8d52014-06-12 08:38:181294 base::FilePath source_install_dir =
1295 data_dir().AppendASCII("bad").AppendASCII("Extensions");
[email protected]e96a0602014-02-15 08:27:421296 base::FilePath pref_path =
1297 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
[email protected]54cb3c92009-02-17 22:30:211298
[email protected]eaa7dd182010-12-14 11:09:001299 InitializeInstalledExtensionService(pref_path, source_install_dir);
[email protected]54cb3c92009-02-17 22:30:211300
[email protected]f484f8d52014-06-12 08:38:181301 service()->Init();
[email protected]54cb3c92009-02-17 22:30:211302
[email protected]a9b00ac2009-06-25 21:03:231303 ASSERT_EQ(4u, GetErrors().size());
1304 ASSERT_EQ(0u, loaded_.size());
[email protected]25b34332009-06-05 21:53:191305
[email protected]04338722013-12-24 23:18:051306 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[0]),
[email protected]d7b36dc2009-10-29 21:47:401307 std::string("Could not load extension from '*'. ") +
[email protected]0c3c9732013-09-16 08:53:411308 extensions::manifest_errors::kManifestUnreadable)) <<
[email protected]04338722013-12-24 23:18:051309 base::UTF16ToUTF8(GetErrors()[0]);
[email protected]8d6d9ff2009-02-20 08:14:391310
[email protected]04338722013-12-24 23:18:051311 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[1]),
[email protected]8d6d9ff2009-02-20 08:14:391312 std::string("Could not load extension from '*'. ") +
[email protected]0c3c9732013-09-16 08:53:411313 extensions::manifest_errors::kManifestUnreadable)) <<
[email protected]04338722013-12-24 23:18:051314 base::UTF16ToUTF8(GetErrors()[1]);
[email protected]8d6d9ff2009-02-20 08:14:391315
[email protected]04338722013-12-24 23:18:051316 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[2]),
[email protected]8d6d9ff2009-02-20 08:14:391317 std::string("Could not load extension from '*'. ") +
[email protected]0c3c9732013-09-16 08:53:411318 extensions::manifest_errors::kMissingFile)) <<
[email protected]04338722013-12-24 23:18:051319 base::UTF16ToUTF8(GetErrors()[2]);
[email protected]a9b00ac2009-06-25 21:03:231320
[email protected]04338722013-12-24 23:18:051321 EXPECT_TRUE(MatchPattern(base::UTF16ToUTF8(GetErrors()[3]),
[email protected]a9b00ac2009-06-25 21:03:231322 std::string("Could not load extension from '*'. ") +
[email protected]0c3c9732013-09-16 08:53:411323 extensions::manifest_errors::kManifestUnreadable)) <<
[email protected]04338722013-12-24 23:18:051324 base::UTF16ToUTF8(GetErrors()[3]);
[email protected]54cb3c92009-02-17 22:30:211325};
1326
[email protected]9f4e4f082013-06-21 07:11:191327// Test various cases for delayed install because of missing imports.
1328TEST_F(ExtensionServiceTest, PendingImports) {
1329 InitPluginService();
1330
[email protected]f484f8d52014-06-12 08:38:181331 base::FilePath source_install_dir =
1332 data_dir().AppendASCII("pending_updates_with_imports").AppendASCII(
1333 "Extensions");
[email protected]e96a0602014-02-15 08:27:421334 base::FilePath pref_path =
1335 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
[email protected]9f4e4f082013-06-21 07:11:191336
1337 InitializeInstalledExtensionService(pref_path, source_install_dir);
1338
1339 // Verify there are no pending extensions initially.
[email protected]f484f8d52014-06-12 08:38:181340 EXPECT_FALSE(service()->pending_extension_manager()->HasPendingExtensions());
[email protected]9f4e4f082013-06-21 07:11:191341
[email protected]f484f8d52014-06-12 08:38:181342 service()->Init();
[email protected]9f4e4f082013-06-21 07:11:191343 // Wait for GarbageCollectExtensions task to complete.
[email protected]eedc1c752013-08-09 18:51:551344 base::RunLoop().RunUntilIdle();
[email protected]9f4e4f082013-06-21 07:11:191345
1346 // These extensions are used by the extensions we test below, they must be
1347 // installed.
[email protected]f484f8d52014-06-12 08:38:181348 EXPECT_TRUE(base::PathExists(extensions_install_dir().AppendASCII(
[email protected]9f4e4f082013-06-21 07:11:191349 "bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0")));
[email protected]f484f8d52014-06-12 08:38:181350 EXPECT_TRUE(base::PathExists(extensions_install_dir().AppendASCII(
[email protected]9f4e4f082013-06-21 07:11:191351 "hpiknbiabeeppbpihjehijgoemciehgk/2")));
1352
1353 // Each of these extensions should have been rejected because of dependencies
1354 // that cannot be satisfied.
[email protected]f484f8d52014-06-12 08:38:181355 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
[email protected]9f4e4f082013-06-21 07:11:191356 EXPECT_FALSE(
1357 prefs->GetDelayedInstallInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
1358 EXPECT_FALSE(
1359 prefs->GetInstalledExtensionInfo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
1360 EXPECT_FALSE(
1361 prefs->GetDelayedInstallInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"));
1362 EXPECT_FALSE(
1363 prefs->GetInstalledExtensionInfo("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"));
1364 EXPECT_FALSE(
1365 prefs->GetDelayedInstallInfo("cccccccccccccccccccccccccccccccc"));
1366 EXPECT_FALSE(
1367 prefs->GetInstalledExtensionInfo("cccccccccccccccccccccccccccccccc"));
1368
1369 // Make sure the import started for the extension with a dependency.
1370 EXPECT_TRUE(
1371 prefs->GetDelayedInstallInfo("behllobkkfkfnphdnhnkndlbkcpglgmj"));
1372 EXPECT_EQ(ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS,
1373 prefs->GetDelayedInstallReason("behllobkkfkfnphdnhnkndlbkcpglgmj"));
1374
[email protected]f484f8d52014-06-12 08:38:181375 EXPECT_FALSE(base::PathExists(extensions_install_dir().AppendASCII(
[email protected]9f4e4f082013-06-21 07:11:191376 "behllobkkfkfnphdnhnkndlbkcpglgmj/1.0.0.0")));
1377
[email protected]f484f8d52014-06-12 08:38:181378 EXPECT_TRUE(service()->pending_extension_manager()->HasPendingExtensions());
[email protected]9f4e4f082013-06-21 07:11:191379 std::string pending_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
[email protected]f484f8d52014-06-12 08:38:181380 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(pending_id));
[email protected]9f4e4f082013-06-21 07:11:191381 // Remove it because we are not testing the pending extension manager's
1382 // ability to download and install extensions.
[email protected]f484f8d52014-06-12 08:38:181383 EXPECT_TRUE(service()->pending_extension_manager()->Remove(pending_id));
[email protected]9f4e4f082013-06-21 07:11:191384}
1385
[email protected]d7eaf572009-07-01 21:57:001386// Test installing extensions. This test tries to install few extensions using
1387// crx files. If you need to change those crx files, feel free to repackage
1388// them, throw away the key used and change the id's above.
[email protected]d9a61e12012-11-14 02:43:471389TEST_F(ExtensionServiceTest, InstallExtension) {
[email protected]eaa7dd182010-12-14 11:09:001390 InitializeEmptyExtensionService();
[email protected]a9b00ac2009-06-25 21:03:231391
[email protected]e2eb43112009-05-29 21:19:541392 // Extensions not enabled.
[email protected]f484f8d52014-06-12 08:38:181393 service()->set_extensions_enabled(false);
1394 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:501395 InstallCRX(path, INSTALL_FAILED);
[email protected]f484f8d52014-06-12 08:38:181396 service()->set_extensions_enabled(true);
[email protected]e2eb43112009-05-29 21:19:541397
[email protected]25b34332009-06-05 21:53:191398 ValidatePrefKeyCount(0);
1399
[email protected]e2eb43112009-05-29 21:19:541400 // A simple extension that should install without error.
[email protected]f484f8d52014-06-12 08:38:181401 path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:501402 InstallCRX(path, INSTALL_NEW);
[email protected]cc655912009-01-29 23:19:191403 // TODO(erikkay): verify the contents of the installed extension.
1404
[email protected]25b34332009-06-05 21:53:191405 int pref_count = 0;
1406 ValidatePrefKeyCount(++pref_count);
[email protected]e2194742010-08-12 05:54:341407 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:401408 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
[email protected]25b34332009-06-05 21:53:191409
[email protected]902f7cd2009-05-22 19:02:191410 // An extension with page actions.
[email protected]f484f8d52014-06-12 08:38:181411 path = data_dir().AppendASCII("page_action.crx");
[email protected]8f512c72011-11-22 21:02:501412 InstallCRX(path, INSTALL_NEW);
[email protected]25b34332009-06-05 21:53:191413 ValidatePrefKeyCount(++pref_count);
[email protected]e2194742010-08-12 05:54:341414 ValidateIntegerPref(page_action, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:401415 ValidateIntegerPref(page_action, "location", Manifest::INTERNAL);
[email protected]902f7cd2009-05-22 19:02:191416
[email protected]9f1087e2009-06-15 17:29:321417 // Bad signature.
[email protected]f484f8d52014-06-12 08:38:181418 path = data_dir().AppendASCII("bad_signature.crx");
[email protected]8f512c72011-11-22 21:02:501419 InstallCRX(path, INSTALL_FAILED);
[email protected]d7eaf572009-07-01 21:57:001420 ValidatePrefKeyCount(pref_count);
[email protected]fbcc40302009-06-12 20:45:451421
[email protected]cc655912009-01-29 23:19:191422 // 0-length extension file.
[email protected]f484f8d52014-06-12 08:38:181423 path = data_dir().AppendASCII("not_an_extension.crx");
[email protected]8f512c72011-11-22 21:02:501424 InstallCRX(path, INSTALL_FAILED);
[email protected]25b34332009-06-05 21:53:191425 ValidatePrefKeyCount(pref_count);
[email protected]cc655912009-01-29 23:19:191426
1427 // Bad magic number.
[email protected]f484f8d52014-06-12 08:38:181428 path = data_dir().AppendASCII("bad_magic.crx");
[email protected]8f512c72011-11-22 21:02:501429 InstallCRX(path, INSTALL_FAILED);
[email protected]25b34332009-06-05 21:53:191430 ValidatePrefKeyCount(pref_count);
[email protected]cc655912009-01-29 23:19:191431
[email protected]622813ee02013-08-21 21:00:291432 // Packed extensions may have folders or files that have underscores.
1433 // This will only cause a warning, rather than a fatal error.
[email protected]f484f8d52014-06-12 08:38:181434 path = data_dir().AppendASCII("bad_underscore.crx");
[email protected]622813ee02013-08-21 21:00:291435 InstallCRX(path, INSTALL_NEW);
1436 ValidatePrefKeyCount(++pref_count);
[email protected]99872e32009-09-25 22:02:491437
[email protected]5fda91942013-09-24 06:47:531438 // A test for an extension with a 2048-bit public key.
[email protected]f484f8d52014-06-12 08:38:181439 path = data_dir().AppendASCII("good2048.crx");
[email protected]5fda91942013-09-24 06:47:531440 InstallCRX(path, INSTALL_NEW);
1441 ValidatePrefKeyCount(++pref_count);
1442 ValidateIntegerPref(good2048, "state", Extension::ENABLED);
1443 ValidateIntegerPref(good2048, "location", Manifest::INTERNAL);
1444
[email protected]cc655912009-01-29 23:19:191445 // TODO(erikkay): add more tests for many of the failure cases.
1446 // TODO(erikkay): add tests for upgrade cases.
1447}
1448
[email protected]b8e45df2014-06-11 19:32:361449struct MockExtensionRegistryObserver
1450 : public extensions::ExtensionRegistryObserver {
1451 virtual void OnExtensionWillBeInstalled(
1452 content::BrowserContext* browser_context,
1453 const Extension* extension,
1454 bool is_update,
1455 bool from_ephemeral,
1456 const std::string& old_name) OVERRIDE {
[email protected]0d55b9a2013-07-19 10:40:261457 last_extension_installed = extension->id();
1458 }
1459
[email protected]e43c61f2014-07-20 21:46:341460 virtual void OnExtensionUninstalled(
1461 content::BrowserContext* browser_context,
1462 const Extension* extension,
1463 extensions::UninstallReason reason) OVERRIDE {
[email protected]0d55b9a2013-07-19 10:40:261464 last_extension_uninstalled = extension->id();
1465 }
1466
[email protected]0d55b9a2013-07-19 10:40:261467 std::string last_extension_installed;
1468 std::string last_extension_uninstalled;
1469};
1470
[email protected]b8e45df2014-06-11 19:32:361471// Test that correct notifications are sent to ExtensionRegistryObserver on
[email protected]0d55b9a2013-07-19 10:40:261472// extension install and uninstall.
1473TEST_F(ExtensionServiceTest, InstallObserverNotified) {
1474 InitializeEmptyExtensionService();
1475
[email protected]b8e45df2014-06-11 19:32:361476 extensions::ExtensionRegistry* registry(
[email protected]f484f8d52014-06-12 08:38:181477 extensions::ExtensionRegistry::Get(profile()));
[email protected]b8e45df2014-06-11 19:32:361478 MockExtensionRegistryObserver observer;
1479 registry->AddObserver(&observer);
[email protected]0d55b9a2013-07-19 10:40:261480
1481 // A simple extension that should install without error.
1482 ASSERT_TRUE(observer.last_extension_installed.empty());
[email protected]f484f8d52014-06-12 08:38:181483 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]0d55b9a2013-07-19 10:40:261484 InstallCRX(path, INSTALL_NEW);
1485 ASSERT_EQ(good_crx, observer.last_extension_installed);
1486
1487 // Uninstall the extension.
1488 ASSERT_TRUE(observer.last_extension_uninstalled.empty());
1489 UninstallExtension(good_crx, false);
1490 ASSERT_EQ(good_crx, observer.last_extension_uninstalled);
1491
[email protected]b8e45df2014-06-11 19:32:361492 registry->RemoveObserver(&observer);
[email protected]0d55b9a2013-07-19 10:40:261493}
1494
[email protected]1bf73cc32011-10-26 22:38:311495// Tests that flags passed to OnExternalExtensionFileFound() make it to the
1496// extension object.
[email protected]d9a61e12012-11-14 02:43:471497TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) {
[email protected]a12ce8b22012-01-17 18:40:531498 const char kPrefFromBookmark[] = "from_bookmark";
1499
[email protected]1bf73cc32011-10-26 22:38:311500 InitializeEmptyExtensionService();
1501
[email protected]f484f8d52014-06-12 08:38:181502 base::FilePath path = data_dir().AppendASCII("good.crx");
1503 service()->set_extensions_enabled(true);
[email protected]1bf73cc32011-10-26 22:38:311504
[email protected]a12ce8b22012-01-17 18:40:531505 // Register and install an external extension.
[email protected]c5e4a2222014-01-03 16:06:131506 Version version("1.0.0.0");
[email protected]97d6a5c2013-11-11 23:51:241507 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:061508 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:241509 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:181510 if (service()->OnExternalExtensionFileFound(good_crx,
1511 &version,
1512 path,
1513 Manifest::EXTERNAL_PREF,
1514 Extension::FROM_BOOKMARK,
1515 false /* mark_acknowledged */)) {
[email protected]97d6a5c2013-11-11 23:51:241516 observer.Wait();
[email protected]6d057a0c2013-07-09 21:12:071517 }
[email protected]1bf73cc32011-10-26 22:38:311518
[email protected]f484f8d52014-06-12 08:38:181519 const Extension* extension = service()->GetExtensionById(good_crx, false);
[email protected]1bf73cc32011-10-26 22:38:311520 ASSERT_TRUE(extension);
[email protected]a12ce8b22012-01-17 18:40:531521 ASSERT_TRUE(extension->from_bookmark());
[email protected]3f2a2fa2013-09-24 02:55:251522 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true));
[email protected]a12ce8b22012-01-17 18:40:531523
1524 // Upgrade to version 2.0, the flag should be preserved.
[email protected]f484f8d52014-06-12 08:38:181525 path = data_dir().AppendASCII("good2.crx");
[email protected]a12ce8b22012-01-17 18:40:531526 UpdateExtension(good_crx, path, ENABLED);
[email protected]3f2a2fa2013-09-24 02:55:251527 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true));
[email protected]f484f8d52014-06-12 08:38:181528 extension = service()->GetExtensionById(good_crx, false);
[email protected]a12ce8b22012-01-17 18:40:531529 ASSERT_TRUE(extension);
1530 ASSERT_TRUE(extension->from_bookmark());
[email protected]1bf73cc32011-10-26 22:38:311531}
1532
[email protected]79c833b52011-04-05 18:31:011533// Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED
[email protected]d9a61e12012-11-14 02:43:471534TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) {
[email protected]eaa7dd182010-12-14 11:09:001535 InitializeEmptyExtensionService();
[email protected]683d0702010-12-06 16:25:571536
[email protected]f484f8d52014-06-12 08:38:181537 base::FilePath path = data_dir().AppendASCII("good.crx");
1538 service()->set_extensions_enabled(true);
[email protected]683d0702010-12-06 16:25:571539
1540 // Install an external extension.
[email protected]c5e4a2222014-01-03 16:06:131541 Version version("1.0.0.0");
[email protected]97d6a5c2013-11-11 23:51:241542 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:061543 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:241544 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:181545 if (service()->OnExternalExtensionFileFound(good_crx,
1546 &version,
1547 path,
1548 Manifest::EXTERNAL_PREF,
1549 Extension::NO_FLAGS,
1550 false)) {
[email protected]97d6a5c2013-11-11 23:51:241551 observer.Wait();
[email protected]6d057a0c2013-07-09 21:12:071552 }
1553
[email protected]f484f8d52014-06-12 08:38:181554 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
[email protected]683d0702010-12-06 16:25:571555
1556 // Uninstall it and check that its killbit gets set.
[email protected]fa2416f2011-05-03 08:41:201557 UninstallExtension(good_crx, false);
[email protected]79c833b52011-04-05 18:31:011558 ValidateIntegerPref(good_crx, "location",
1559 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
[email protected]683d0702010-12-06 16:25:571560
1561 // Try to re-install it externally. This should fail because of the killbit.
[email protected]f484f8d52014-06-12 08:38:181562 service()->OnExternalExtensionFileFound(good_crx,
1563 &version,
1564 path,
1565 Manifest::EXTERNAL_PREF,
1566 Extension::NO_FLAGS,
1567 false);
[email protected]eedc1c752013-08-09 18:51:551568 base::RunLoop().RunUntilIdle();
[email protected]f484f8d52014-06-12 08:38:181569 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false));
[email protected]79c833b52011-04-05 18:31:011570 ValidateIntegerPref(good_crx, "location",
1571 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
[email protected]683d0702010-12-06 16:25:571572
[email protected]c5e4a2222014-01-03 16:06:131573 version = Version("1.0.0.1");
[email protected]683d0702010-12-06 16:25:571574 // Repeat the same thing with a newer version of the extension.
[email protected]f484f8d52014-06-12 08:38:181575 path = data_dir().AppendASCII("good2.crx");
1576 service()->OnExternalExtensionFileFound(good_crx,
1577 &version,
1578 path,
1579 Manifest::EXTERNAL_PREF,
1580 Extension::NO_FLAGS,
1581 false);
[email protected]eedc1c752013-08-09 18:51:551582 base::RunLoop().RunUntilIdle();
[email protected]f484f8d52014-06-12 08:38:181583 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false));
[email protected]79c833b52011-04-05 18:31:011584 ValidateIntegerPref(good_crx, "location",
1585 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
[email protected]683d0702010-12-06 16:25:571586
1587 // Try adding the same extension from an external update URL.
[email protected]f484f8d52014-06-12 08:38:181588 ASSERT_FALSE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]683d0702010-12-06 16:25:571589 good_crx,
[email protected]d8fd0fd2014-03-24 13:16:061590 std::string(),
[email protected]683d0702010-12-06 16:25:571591 GURL("http:://fake.update/url"),
[email protected]464213a2013-10-15 01:06:481592 Manifest::EXTERNAL_PREF_DOWNLOAD,
1593 Extension::NO_FLAGS,
1594 false));
[email protected]b2907fd2011-03-25 16:43:371595
[email protected]f484f8d52014-06-12 08:38:181596 ASSERT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
[email protected]683d0702010-12-06 16:25:571597}
1598
[email protected]0f48fca2011-05-19 18:46:351599// Test that uninstalling an external extension does not crash when
1600// the extension could not be loaded.
1601// This extension shown in preferences file requires an experimental permission.
1602// It could not be loaded without such permission.
[email protected]d9a61e12012-11-14 02:43:471603TEST_F(ExtensionServiceTest, UninstallingNotLoadedExtension) {
[email protected]f484f8d52014-06-12 08:38:181604 base::FilePath source_install_dir =
1605 data_dir().AppendASCII("good").AppendASCII("Extensions");
[email protected]0f48fca2011-05-19 18:46:351606 // The preference contains an external extension
1607 // that requires 'experimental' permission.
[email protected]650b2d52013-02-10 03:41:451608 base::FilePath pref_path = source_install_dir
[email protected]0f48fca2011-05-19 18:46:351609 .DirName()
1610 .AppendASCII("PreferencesExperimental");
1611
1612 // Aforementioned extension will not be loaded if
1613 // there is no '--enable-experimental-extension-apis' command line flag.
1614 InitializeInstalledExtensionService(pref_path, source_install_dir);
1615
[email protected]f484f8d52014-06-12 08:38:181616 service()->Init();
[email protected]0f48fca2011-05-19 18:46:351617
1618 // Check and try to uninstall it.
1619 // If we don't check whether the extension is loaded before we uninstall it
1620 // in CheckExternalUninstall, a crash will happen here because we will get or
1621 // dereference a NULL pointer (extension) inside UninstallExtension.
[email protected]1d5e58b2013-01-31 08:41:401622 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY);
[email protected]f484f8d52014-06-12 08:38:181623 service()->OnExternalProviderReady(&provider);
[email protected]0f48fca2011-05-19 18:46:351624}
1625
[email protected]604322d2011-03-22 16:51:561626// Test that external extensions with incorrect IDs are not installed.
[email protected]d9a61e12012-11-14 02:43:471627TEST_F(ExtensionServiceTest, FailOnWrongId) {
[email protected]604322d2011-03-22 16:51:561628 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:181629 base::FilePath path = data_dir().AppendASCII("good.crx");
1630 service()->set_extensions_enabled(true);
[email protected]604322d2011-03-22 16:51:561631
[email protected]c5e4a2222014-01-03 16:06:131632 Version version("1.0.0.0");
[email protected]604322d2011-03-22 16:51:561633
1634 const std::string wrong_id = all_zero;
1635 const std::string correct_id = good_crx;
1636 ASSERT_NE(correct_id, wrong_id);
1637
1638 // Install an external extension with an ID from the external
1639 // source that is not equal to the ID in the extension manifest.
[email protected]97d6a5c2013-11-11 23:51:241640 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:061641 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:241642 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:181643 service()->OnExternalExtensionFileFound(wrong_id,
1644 &version,
1645 path,
1646 Manifest::EXTERNAL_PREF,
1647 Extension::NO_FLAGS,
1648 false);
[email protected]604322d2011-03-22 16:51:561649
[email protected]97d6a5c2013-11-11 23:51:241650 observer.Wait();
[email protected]f484f8d52014-06-12 08:38:181651 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
[email protected]604322d2011-03-22 16:51:561652
1653 // Try again with the right ID. Expect success.
[email protected]97d6a5c2013-11-11 23:51:241654 content::WindowedNotificationObserver observer2(
[email protected]adf5a102014-07-31 12:44:061655 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:241656 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:181657 if (service()->OnExternalExtensionFileFound(correct_id,
1658 &version,
1659 path,
1660 Manifest::EXTERNAL_PREF,
1661 Extension::NO_FLAGS,
1662 false)) {
[email protected]97d6a5c2013-11-11 23:51:241663 observer2.Wait();
[email protected]6d057a0c2013-07-09 21:12:071664 }
[email protected]f484f8d52014-06-12 08:38:181665 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
[email protected]604322d2011-03-22 16:51:561666}
1667
1668// Test that external extensions with incorrect versions are not installed.
[email protected]d9a61e12012-11-14 02:43:471669TEST_F(ExtensionServiceTest, FailOnWrongVersion) {
[email protected]604322d2011-03-22 16:51:561670 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:181671 base::FilePath path = data_dir().AppendASCII("good.crx");
1672 service()->set_extensions_enabled(true);
[email protected]604322d2011-03-22 16:51:561673
1674 // Install an external extension with a version from the external
1675 // source that is not equal to the version in the extension manifest.
[email protected]c5e4a2222014-01-03 16:06:131676 Version wrong_version("1.2.3.4");
[email protected]97d6a5c2013-11-11 23:51:241677 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:061678 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:241679 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:181680 service()->OnExternalExtensionFileFound(good_crx,
1681 &wrong_version,
1682 path,
1683 Manifest::EXTERNAL_PREF,
1684 Extension::NO_FLAGS,
1685 false);
[email protected]604322d2011-03-22 16:51:561686
[email protected]97d6a5c2013-11-11 23:51:241687 observer.Wait();
[email protected]f484f8d52014-06-12 08:38:181688 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
[email protected]604322d2011-03-22 16:51:561689
1690 // Try again with the right version. Expect success.
[email protected]f484f8d52014-06-12 08:38:181691 service()->pending_extension_manager()->Remove(good_crx);
[email protected]c5e4a2222014-01-03 16:06:131692 Version correct_version("1.0.0.0");
[email protected]97d6a5c2013-11-11 23:51:241693 content::WindowedNotificationObserver observer2(
[email protected]adf5a102014-07-31 12:44:061694 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:241695 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:181696 if (service()->OnExternalExtensionFileFound(good_crx,
1697 &correct_version,
1698 path,
1699 Manifest::EXTERNAL_PREF,
1700 Extension::NO_FLAGS,
1701 false)) {
[email protected]97d6a5c2013-11-11 23:51:241702 observer2.Wait();
[email protected]6d057a0c2013-07-09 21:12:071703 }
[email protected]f484f8d52014-06-12 08:38:181704 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
[email protected]604322d2011-03-22 16:51:561705}
1706
[email protected]da0aa3b2009-12-06 21:41:031707// Install a user script (they get converted automatically to an extension)
[email protected]d9a61e12012-11-14 02:43:471708TEST_F(ExtensionServiceTest, InstallUserScript) {
[email protected]da0aa3b2009-12-06 21:41:031709 // The details of script conversion are tested elsewhere, this just tests
[email protected]eaa7dd182010-12-14 11:09:001710 // integration with ExtensionService.
1711 InitializeEmptyExtensionService();
[email protected]da0aa3b2009-12-06 21:41:031712
[email protected]f484f8d52014-06-12 08:38:181713 base::FilePath path = data_dir().AppendASCII("user_script_basic.user.js");
[email protected]da0aa3b2009-12-06 21:41:031714
[email protected]7567484142013-07-11 17:36:071715 ASSERT_TRUE(base::PathExists(path));
[email protected]f484f8d52014-06-12 08:38:181716 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service()));
[email protected]0d3e4a22011-06-23 19:02:521717 installer->set_allow_silent_install(true);
[email protected]6dfbbf82010-03-12 23:09:161718 installer->InstallUserScript(
[email protected]da0aa3b2009-12-06 21:41:031719 path,
[email protected]6dfbbf82010-03-12 23:09:161720 GURL("http://www.aaronboodman.com/scripts/user_script_basic.user.js"));
[email protected]da0aa3b2009-12-06 21:41:031721
[email protected]eedc1c752013-08-09 18:51:551722 base::RunLoop().RunUntilIdle();
[email protected]d2065e062013-12-12 23:49:521723 std::vector<base::string16> errors = GetErrors();
[email protected]da0aa3b2009-12-06 21:41:031724 EXPECT_TRUE(installed_) << "Nothing was installed.";
[email protected]41bb80bd2013-05-03 10:56:021725 EXPECT_FALSE(was_update_) << path.value();
[email protected]da0aa3b2009-12-06 21:41:031726 ASSERT_EQ(1u, loaded_.size()) << "Nothing was loaded.";
1727 EXPECT_EQ(0u, errors.size()) << "There were errors: "
1728 << JoinString(errors, ',');
[email protected]f484f8d52014-06-12 08:38:181729 EXPECT_TRUE(service()->GetExtensionById(loaded_[0]->id(), false))
1730 << path.value();
[email protected]da0aa3b2009-12-06 21:41:031731
1732 installed_ = NULL;
[email protected]41bb80bd2013-05-03 10:56:021733 was_update_ = false;
[email protected]da0aa3b2009-12-06 21:41:031734 loaded_.clear();
1735 ExtensionErrorReporter::GetInstance()->ClearErrors();
1736}
1737
[email protected]3c4abc82012-10-22 22:25:541738// Extensions don't install during shutdown.
[email protected]d9a61e12012-11-14 02:43:471739TEST_F(ExtensionServiceTest, InstallExtensionDuringShutdown) {
[email protected]3c4abc82012-10-22 22:25:541740 InitializeEmptyExtensionService();
1741
1742 // Simulate shutdown.
[email protected]f484f8d52014-06-12 08:38:181743 service()->set_browser_terminating_for_test(true);
[email protected]3c4abc82012-10-22 22:25:541744
[email protected]f484f8d52014-06-12 08:38:181745 base::FilePath path = data_dir().AppendASCII("good.crx");
1746 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service()));
[email protected]3c4abc82012-10-22 22:25:541747 installer->set_allow_silent_install(true);
1748 installer->InstallCrx(path);
[email protected]eedc1c752013-08-09 18:51:551749 base::RunLoop().RunUntilIdle();
[email protected]3c4abc82012-10-22 22:25:541750
1751 EXPECT_FALSE(installed_) << "Extension installed during shutdown.";
1752 ASSERT_EQ(0u, loaded_.size()) << "Extension loaded during shutdown.";
1753}
1754
[email protected]8d888c12010-11-30 00:00:251755// This tests that the granted permissions preferences are correctly set when
1756// installing an extension.
[email protected]d9a61e12012-11-14 02:43:471757TEST_F(ExtensionServiceTest, GrantedPermissions) {
[email protected]eaa7dd182010-12-14 11:09:001758 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:181759 base::FilePath path = data_dir().AppendASCII("permissions");
[email protected]8d888c12010-11-30 00:00:251760
[email protected]650b2d52013-02-10 03:41:451761 base::FilePath pem_path = path.AppendASCII("unknown.pem");
[email protected]8d888c12010-11-30 00:00:251762 path = path.AppendASCII("unknown");
1763
[email protected]7567484142013-07-11 17:36:071764 ASSERT_TRUE(base::PathExists(pem_path));
1765 ASSERT_TRUE(base::PathExists(path));
[email protected]8d888c12010-11-30 00:00:251766
[email protected]f484f8d52014-06-12 08:38:181767 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
[email protected]8d888c12010-11-30 00:00:251768
[email protected]c2e66e12012-06-27 06:27:061769 APIPermissionSet expected_api_perms;
[email protected]cced75a2011-05-20 08:31:121770 URLPatternSet expected_host_perms;
[email protected]8d888c12010-11-30 00:00:251771
1772 // Make sure there aren't any granted permissions before the
1773 // extension is installed.
[email protected]c2e66e12012-06-27 06:27:061774 scoped_refptr<PermissionSet> known_perms(
[email protected]0d3e4a22011-06-23 19:02:521775 prefs->GetGrantedPermissions(permissions_crx));
1776 EXPECT_FALSE(known_perms.get());
[email protected]8d888c12010-11-30 00:00:251777
[email protected]8f512c72011-11-22 21:02:501778 const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW);
[email protected]8d888c12010-11-30 00:00:251779
1780 EXPECT_EQ(0u, GetErrors().size());
[email protected]f484f8d52014-06-12 08:38:181781 ASSERT_EQ(1u, registry()->enabled_extensions().size());
[email protected]8f512c72011-11-22 21:02:501782 EXPECT_EQ(permissions_crx, extension->id());
[email protected]8d888c12010-11-30 00:00:251783
[email protected]8d888c12010-11-30 00:00:251784 // Verify that the valid API permissions have been recognized.
[email protected]c2e66e12012-06-27 06:27:061785 expected_api_perms.insert(APIPermission::kTab);
[email protected]8d888c12010-11-30 00:00:251786
1787 AddPattern(&expected_host_perms, "http://*.google.com/*");
1788 AddPattern(&expected_host_perms, "https://*.google.com/*");
[email protected]d6a5c78c2010-12-07 05:18:151789 AddPattern(&expected_host_perms, "http://*.google.com.hk/*");
[email protected]8d888c12010-11-30 00:00:251790 AddPattern(&expected_host_perms, "http://www.example.com/*");
1791
[email protected]8f512c72011-11-22 21:02:501792 known_perms = prefs->GetGrantedPermissions(extension->id());
[email protected]0d3e4a22011-06-23 19:02:521793 EXPECT_TRUE(known_perms.get());
1794 EXPECT_FALSE(known_perms->IsEmpty());
1795 EXPECT_EQ(expected_api_perms, known_perms->apis());
1796 EXPECT_FALSE(known_perms->HasEffectiveFullAccess());
[email protected]06e8b8ff2011-07-13 15:03:471797 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts());
[email protected]8d888c12010-11-30 00:00:251798}
1799
[email protected]be083862012-09-01 03:53:451800
1801#if !defined(OS_CHROMEOS)
1802// This tests that the granted permissions preferences are correctly set for
1803// default apps.
[email protected]d9a61e12012-11-14 02:43:471804TEST_F(ExtensionServiceTest, DefaultAppsGrantedPermissions) {
[email protected]be083862012-09-01 03:53:451805 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:181806 base::FilePath path = data_dir().AppendASCII("permissions");
[email protected]be083862012-09-01 03:53:451807
[email protected]650b2d52013-02-10 03:41:451808 base::FilePath pem_path = path.AppendASCII("unknown.pem");
[email protected]be083862012-09-01 03:53:451809 path = path.AppendASCII("unknown");
1810
[email protected]7567484142013-07-11 17:36:071811 ASSERT_TRUE(base::PathExists(pem_path));
1812 ASSERT_TRUE(base::PathExists(path));
[email protected]be083862012-09-01 03:53:451813
[email protected]f484f8d52014-06-12 08:38:181814 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
[email protected]be083862012-09-01 03:53:451815
1816 APIPermissionSet expected_api_perms;
1817 URLPatternSet expected_host_perms;
1818
1819 // Make sure there aren't any granted permissions before the
1820 // extension is installed.
1821 scoped_refptr<PermissionSet> known_perms(
1822 prefs->GetGrantedPermissions(permissions_crx));
1823 EXPECT_FALSE(known_perms.get());
1824
1825 const Extension* extension = PackAndInstallCRX(
1826 path, pem_path, INSTALL_NEW, Extension::WAS_INSTALLED_BY_DEFAULT);
1827
1828 EXPECT_EQ(0u, GetErrors().size());
[email protected]f484f8d52014-06-12 08:38:181829 ASSERT_EQ(1u, registry()->enabled_extensions().size());
[email protected]be083862012-09-01 03:53:451830 EXPECT_EQ(permissions_crx, extension->id());
1831
1832 // Verify that the valid API permissions have been recognized.
1833 expected_api_perms.insert(APIPermission::kTab);
1834
1835 known_perms = prefs->GetGrantedPermissions(extension->id());
1836 EXPECT_TRUE(known_perms.get());
1837 EXPECT_FALSE(known_perms->IsEmpty());
1838 EXPECT_EQ(expected_api_perms, known_perms->apis());
1839 EXPECT_FALSE(known_perms->HasEffectiveFullAccess());
1840}
1841#endif
1842
[email protected]77724b602014-05-14 11:36:121843#if !defined(OS_POSIX) || defined(OS_MACOSX)
[email protected]8d888c12010-11-30 00:00:251844// Tests that the granted permissions full_access bit gets set correctly when
[email protected]77724b602014-05-14 11:36:121845// an extension contains an NPAPI plugin.
1846// Only run this on platforms that support NPAPI plugins.
[email protected]d9a61e12012-11-14 02:43:471847TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) {
[email protected]ebd71962012-12-20 02:56:551848 InitPluginService();
[email protected]183d4b82011-11-11 18:50:261849
[email protected]eaa7dd182010-12-14 11:09:001850 InitializeEmptyExtensionService();
[email protected]8d888c12010-11-30 00:00:251851
[email protected]3f2a2fa2013-09-24 02:55:251852 ASSERT_TRUE(base::PathExists(good1_path()));
1853 const Extension* extension = PackAndInstallCRX(good1_path(), INSTALL_NEW);
[email protected]8d888c12010-11-30 00:00:251854 EXPECT_EQ(0u, GetErrors().size());
[email protected]f484f8d52014-06-12 08:38:181855 EXPECT_EQ(1u, registry()->enabled_extensions().size());
1856 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
[email protected]8d888c12010-11-30 00:00:251857
[email protected]c2e66e12012-06-27 06:27:061858 scoped_refptr<PermissionSet> permissions(
[email protected]8f512c72011-11-22 21:02:501859 prefs->GetGrantedPermissions(extension->id()));
[email protected]0d3e4a22011-06-23 19:02:521860 EXPECT_FALSE(permissions->IsEmpty());
1861 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
1862 EXPECT_FALSE(permissions->apis().empty());
[email protected]c2e66e12012-06-27 06:27:061863 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin));
[email protected]8d888c12010-11-30 00:00:251864
[email protected]0d3e4a22011-06-23 19:02:521865 // Full access implies full host access too...
1866 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts());
[email protected]8d888c12010-11-30 00:00:251867}
1868#endif
1869
1870// Tests that the extension is disabled when permissions are missing from
1871// the extension's granted permissions preferences. (This simulates updating
1872// the browser to a version which recognizes more permissions).
[email protected]d9a61e12012-11-14 02:43:471873TEST_F(ExtensionServiceTest, GrantedAPIAndHostPermissions) {
[email protected]eaa7dd182010-12-14 11:09:001874 InitializeEmptyExtensionService();
[email protected]8d888c12010-11-30 00:00:251875
[email protected]f484f8d52014-06-12 08:38:181876 base::FilePath path =
1877 data_dir().AppendASCII("permissions").AppendASCII("unknown");
[email protected]8d888c12010-11-30 00:00:251878
[email protected]7567484142013-07-11 17:36:071879 ASSERT_TRUE(base::PathExists(path));
[email protected]8d888c12010-11-30 00:00:251880
[email protected]8f512c72011-11-22 21:02:501881 const Extension* extension = PackAndInstallCRX(path, INSTALL_NEW);
[email protected]8d888c12010-11-30 00:00:251882
1883 EXPECT_EQ(0u, GetErrors().size());
[email protected]f484f8d52014-06-12 08:38:181884 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]8d888c12010-11-30 00:00:251885 std::string extension_id = extension->id();
1886
[email protected]f484f8d52014-06-12 08:38:181887 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
[email protected]8d888c12010-11-30 00:00:251888
[email protected]c2e66e12012-06-27 06:27:061889 APIPermissionSet expected_api_permissions;
[email protected]cced75a2011-05-20 08:31:121890 URLPatternSet expected_host_permissions;
[email protected]8d888c12010-11-30 00:00:251891
[email protected]c2e66e12012-06-27 06:27:061892 expected_api_permissions.insert(APIPermission::kTab);
[email protected]8d888c12010-11-30 00:00:251893 AddPattern(&expected_host_permissions, "http://*.google.com/*");
1894 AddPattern(&expected_host_permissions, "https://*.google.com/*");
[email protected]d6a5c78c2010-12-07 05:18:151895 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*");
[email protected]8d888c12010-11-30 00:00:251896 AddPattern(&expected_host_permissions, "http://www.example.com/*");
1897
[email protected]8d888c12010-11-30 00:00:251898 std::set<std::string> host_permissions;
1899
1900 // Test that the extension is disabled when an API permission is missing from
1901 // the extension's granted api permissions preference. (This simulates
1902 // updating the browser to a version which recognizes a new API permission).
[email protected]0d3e4a22011-06-23 19:02:521903 SetPref(extension_id, "granted_permissions.api",
[email protected]023b3d12013-12-23 18:46:491904 new base::ListValue(), "granted_permissions.api");
[email protected]f484f8d52014-06-12 08:38:181905 service()->ReloadExtensionsForTest();
[email protected]8d888c12010-11-30 00:00:251906
[email protected]f484f8d52014-06-12 08:38:181907 EXPECT_EQ(1u, registry()->disabled_extensions().size());
1908 extension = registry()->disabled_extensions().begin()->get();
[email protected]8d888c12010-11-30 00:00:251909
[email protected]ad83ca242011-07-29 01:32:251910 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
[email protected]f484f8d52014-06-12 08:38:181911 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id));
[email protected]8d888c12010-11-30 00:00:251912 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
1913
1914 // Now grant and re-enable the extension, making sure the prefs are updated.
[email protected]f484f8d52014-06-12 08:38:181915 service()->GrantPermissionsAndEnableExtension(extension);
[email protected]8d888c12010-11-30 00:00:251916
[email protected]ad83ca242011-07-29 01:32:251917 ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id));
[email protected]f484f8d52014-06-12 08:38:181918 ASSERT_TRUE(service()->IsExtensionEnabled(extension_id));
[email protected]8d888c12010-11-30 00:00:251919 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
1920
[email protected]c2e66e12012-06-27 06:27:061921 scoped_refptr<PermissionSet> current_perms(
[email protected]0d3e4a22011-06-23 19:02:521922 prefs->GetGrantedPermissions(extension_id));
1923 ASSERT_TRUE(current_perms.get());
1924 ASSERT_FALSE(current_perms->IsEmpty());
1925 ASSERT_FALSE(current_perms->HasEffectiveFullAccess());
1926 ASSERT_EQ(expected_api_permissions, current_perms->apis());
[email protected]06e8b8ff2011-07-13 15:03:471927 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts());
[email protected]8d888c12010-11-30 00:00:251928
1929 // Tests that the extension is disabled when a host permission is missing from
1930 // the extension's granted host permissions preference. (This simulates
1931 // updating the browser to a version which recognizes additional host
1932 // permissions).
[email protected]8d888c12010-11-30 00:00:251933 host_permissions.clear();
[email protected]902fd7b2011-07-27 18:42:311934 current_perms = NULL;
[email protected]8d888c12010-11-30 00:00:251935
[email protected]8d888c12010-11-30 00:00:251936 host_permissions.insert("http://*.google.com/*");
1937 host_permissions.insert("https://*.google.com/*");
[email protected]d6a5c78c2010-12-07 05:18:151938 host_permissions.insert("http://*.google.com.hk/*");
[email protected]8d888c12010-11-30 00:00:251939
[email protected]023b3d12013-12-23 18:46:491940 base::ListValue* api_permissions = new base::ListValue();
[email protected]0d3e4a22011-06-23 19:02:521941 api_permissions->Append(
[email protected]aa15e2e2013-08-14 02:13:581942 new base::StringValue("tabs"));
[email protected]0d3e4a22011-06-23 19:02:521943 SetPref(extension_id, "granted_permissions.api",
1944 api_permissions, "granted_permissions.api");
1945 SetPrefStringSet(
1946 extension_id, "granted_permissions.scriptable_host", host_permissions);
[email protected]8d888c12010-11-30 00:00:251947
[email protected]f484f8d52014-06-12 08:38:181948 service()->ReloadExtensionsForTest();
[email protected]8d888c12010-11-30 00:00:251949
[email protected]f484f8d52014-06-12 08:38:181950 EXPECT_EQ(1u, registry()->disabled_extensions().size());
1951 extension = registry()->disabled_extensions().begin()->get();
[email protected]8d888c12010-11-30 00:00:251952
[email protected]ad83ca242011-07-29 01:32:251953 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
[email protected]f484f8d52014-06-12 08:38:181954 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id));
[email protected]8d888c12010-11-30 00:00:251955 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
1956
1957 // Now grant and re-enable the extension, making sure the prefs are updated.
[email protected]f484f8d52014-06-12 08:38:181958 service()->GrantPermissionsAndEnableExtension(extension);
[email protected]8d888c12010-11-30 00:00:251959
[email protected]f484f8d52014-06-12 08:38:181960 ASSERT_TRUE(service()->IsExtensionEnabled(extension_id));
[email protected]8d888c12010-11-30 00:00:251961 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
1962
[email protected]902fd7b2011-07-27 18:42:311963 current_perms = prefs->GetGrantedPermissions(extension_id);
[email protected]0d3e4a22011-06-23 19:02:521964 ASSERT_TRUE(current_perms.get());
1965 ASSERT_FALSE(current_perms->IsEmpty());
1966 ASSERT_FALSE(current_perms->HasEffectiveFullAccess());
1967 ASSERT_EQ(expected_api_permissions, current_perms->apis());
[email protected]06e8b8ff2011-07-13 15:03:471968 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts());
[email protected]8d888c12010-11-30 00:00:251969}
1970
[email protected]a17f9462009-06-09 02:56:411971// Test Packaging and installing an extension.
[email protected]d9a61e12012-11-14 02:43:471972TEST_F(ExtensionServiceTest, PackExtension) {
[email protected]eaa7dd182010-12-14 11:09:001973 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:181974 base::FilePath input_directory =
1975 data_dir()
1976 .AppendASCII("good")
1977 .AppendASCII("Extensions")
1978 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
1979 .AppendASCII("1.0.0.0");
[email protected]a17f9462009-06-09 02:56:411980
[email protected]ea1a3f62012-11-16 20:34:231981 base::ScopedTempDir temp_dir;
[email protected]aca3e9b2009-11-03 01:14:211982 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
[email protected]650b2d52013-02-10 03:41:451983 base::FilePath output_directory = temp_dir.path();
[email protected]aca3e9b2009-11-03 01:14:211984
[email protected]650b2d52013-02-10 03:41:451985 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
1986 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem"));
[email protected]a17f9462009-06-09 02:56:411987
1988 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
[email protected]650b2d52013-02-10 03:41:451989 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(),
[email protected]93d973a2012-01-08 07:38:261990 privkey_path, ExtensionCreator::kNoRunFlags));
[email protected]7567484142013-07-11 17:36:071991 ASSERT_TRUE(base::PathExists(crx_path));
1992 ASSERT_TRUE(base::PathExists(privkey_path));
[email protected]93d973a2012-01-08 07:38:261993
1994 // Repeat the run with the pem file gone, and no special flags
1995 // Should refuse to overwrite the existing crx.
[email protected]dd3aa792013-07-16 19:10:231996 base::DeleteFile(privkey_path, false);
[email protected]650b2d52013-02-10 03:41:451997 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(),
[email protected]93d973a2012-01-08 07:38:261998 privkey_path, ExtensionCreator::kNoRunFlags));
1999
2000 // OK, now try it with a flag to overwrite existing crx. Should work.
[email protected]650b2d52013-02-10 03:41:452001 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(),
[email protected]93d973a2012-01-08 07:38:262002 privkey_path, ExtensionCreator::kOverwriteCRX));
2003
2004 // Repeat the run allowing existing crx, but the existing pem is still
2005 // an error. Should fail.
[email protected]650b2d52013-02-10 03:41:452006 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(),
[email protected]93d973a2012-01-08 07:38:262007 privkey_path, ExtensionCreator::kOverwriteCRX));
[email protected]a17f9462009-06-09 02:56:412008
[email protected]7567484142013-07-11 17:36:072009 ASSERT_TRUE(base::PathExists(privkey_path));
[email protected]8f512c72011-11-22 21:02:502010 InstallCRX(crx_path, INSTALL_NEW);
[email protected]0dc2ca82009-11-17 07:06:162011
2012 // Try packing with invalid paths.
2013 creator.reset(new ExtensionCreator());
[email protected]650b2d52013-02-10 03:41:452014 ASSERT_FALSE(
2015 creator->Run(base::FilePath(), base::FilePath(), base::FilePath(),
2016 base::FilePath(), ExtensionCreator::kOverwriteCRX));
[email protected]0dc2ca82009-11-17 07:06:162017
2018 // Try packing an empty directory. Should fail because an empty directory is
2019 // not a valid extension.
[email protected]ea1a3f62012-11-16 20:34:232020 base::ScopedTempDir temp_dir2;
[email protected]0dc2ca82009-11-17 07:06:162021 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
2022 creator.reset(new ExtensionCreator());
2023 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path,
[email protected]650b2d52013-02-10 03:41:452024 base::FilePath(), ExtensionCreator::kOverwriteCRX));
[email protected]0dc2ca82009-11-17 07:06:162025
2026 // Try packing with an invalid manifest.
2027 std::string invalid_manifest_content = "I am not a manifest.";
[email protected]e5c2a22e2014-03-06 20:42:302028 ASSERT_TRUE(base::WriteFile(
[email protected]993da5e2013-03-23 21:25:162029 temp_dir2.path().Append(extensions::kManifestFilename),
[email protected]0dc2ca82009-11-17 07:06:162030 invalid_manifest_content.c_str(), invalid_manifest_content.size()));
2031 creator.reset(new ExtensionCreator());
2032 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path,
[email protected]650b2d52013-02-10 03:41:452033 base::FilePath(), ExtensionCreator::kOverwriteCRX));
[email protected]c21b5b612013-07-31 07:49:162034
2035 // Try packing with a private key that is a valid key, but invalid for the
2036 // extension.
[email protected]f484f8d52014-06-12 08:38:182037 base::FilePath bad_private_key_dir =
2038 data_dir().AppendASCII("bad_private_key");
[email protected]c21b5b612013-07-31 07:49:162039 crx_path = output_directory.AppendASCII("bad_private_key.crx");
[email protected]f484f8d52014-06-12 08:38:182040 privkey_path = data_dir().AppendASCII("bad_private_key.pem");
[email protected]c21b5b612013-07-31 07:49:162041 ASSERT_FALSE(creator->Run(bad_private_key_dir, crx_path, base::FilePath(),
2042 privkey_path, ExtensionCreator::kOverwriteCRX));
[email protected]a17f9462009-06-09 02:56:412043}
2044
[email protected]0349ab5d2010-08-11 21:41:572045// Test Packaging and installing an extension whose name contains punctuation.
[email protected]d9a61e12012-11-14 02:43:472046TEST_F(ExtensionServiceTest, PackPunctuatedExtension) {
[email protected]eaa7dd182010-12-14 11:09:002047 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182048 base::FilePath input_directory = data_dir()
2049 .AppendASCII("good")
2050 .AppendASCII("Extensions")
2051 .AppendASCII(good0)
2052 .AppendASCII("1.0.0.0");
[email protected]0349ab5d2010-08-11 21:41:572053
[email protected]ea1a3f62012-11-16 20:34:232054 base::ScopedTempDir temp_dir;
[email protected]0349ab5d2010-08-11 21:41:572055 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
2056
2057 // Extension names containing punctuation, and the expected names for the
2058 // packed extensions.
[email protected]650b2d52013-02-10 03:41:452059 const base::FilePath punctuated_names[] = {
2060 base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods")),
2061 base::FilePath(FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod")),
2062 base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname/")).
[email protected]d9034ed22012-02-10 02:04:402063 NormalizePathSeparators(),
[email protected]0349ab5d2010-08-11 21:41:572064 };
[email protected]650b2d52013-02-10 03:41:452065 const base::FilePath expected_crx_names[] = {
2066 base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods.crx")),
2067 base::FilePath(
2068 FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.crx")),
2069 base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.crx")),
[email protected]0349ab5d2010-08-11 21:41:572070 };
[email protected]650b2d52013-02-10 03:41:452071 const base::FilePath expected_private_key_names[] = {
2072 base::FilePath(FILE_PATH_LITERAL("this.extensions.name.has.periods.pem")),
2073 base::FilePath(
2074 FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.pem")),
2075 base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.pem")),
[email protected]0349ab5d2010-08-11 21:41:572076 };
2077
2078 for (size_t i = 0; i < arraysize(punctuated_names); ++i) {
2079 SCOPED_TRACE(punctuated_names[i].value().c_str());
[email protected]650b2d52013-02-10 03:41:452080 base::FilePath output_dir = temp_dir.path().Append(punctuated_names[i]);
[email protected]0349ab5d2010-08-11 21:41:572081
2082 // Copy the extension into the output directory, as PackExtensionJob doesn't
2083 // let us choose where to output the packed extension.
[email protected]f0ff2ad2013-07-09 17:42:262084 ASSERT_TRUE(base::CopyDirectory(input_directory, output_dir, true));
[email protected]0349ab5d2010-08-11 21:41:572085
[email protected]650b2d52013-02-10 03:41:452086 base::FilePath expected_crx_path =
2087 temp_dir.path().Append(expected_crx_names[i]);
2088 base::FilePath expected_private_key_path =
[email protected]0349ab5d2010-08-11 21:41:572089 temp_dir.path().Append(expected_private_key_names[i]);
2090 PackExtensionTestClient pack_client(expected_crx_path,
2091 expected_private_key_path);
[email protected]d9ede582012-08-14 19:21:382092 scoped_refptr<extensions::PackExtensionJob> packer(
[email protected]650b2d52013-02-10 03:41:452093 new extensions::PackExtensionJob(&pack_client, output_dir,
2094 base::FilePath(),
[email protected]d9ede582012-08-14 19:21:382095 ExtensionCreator::kOverwriteCRX));
[email protected]0349ab5d2010-08-11 21:41:572096 packer->Start();
2097
2098 // The packer will post a notification task to the current thread's message
2099 // loop when it is finished. We manually run the loop here so that we
2100 // block and catch the notification; otherwise, the process would exit.
2101 // This call to |Run()| is matched by a call to |Quit()| in the
2102 // |PackExtensionTestClient|'s notification handling code.
[email protected]b3a25092013-05-28 22:08:162103 base::MessageLoop::current()->Run();
[email protected]0349ab5d2010-08-11 21:41:572104
2105 if (HasFatalFailure())
2106 return;
2107
[email protected]8f512c72011-11-22 21:02:502108 InstallCRX(expected_crx_path, INSTALL_NEW);
[email protected]0349ab5d2010-08-11 21:41:572109 }
2110}
2111
[email protected]d9a61e12012-11-14 02:43:472112TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) {
[email protected]ab55c2b2012-06-01 23:55:032113 InitializeEmptyExtensionService();
2114
[email protected]ea1a3f62012-11-16 20:34:232115 base::ScopedTempDir extension_temp_dir;
[email protected]ab55c2b2012-06-01 23:55:032116 ASSERT_TRUE(extension_temp_dir.CreateUniqueTempDir());
[email protected]650b2d52013-02-10 03:41:452117 base::FilePath input_directory = extension_temp_dir.path().AppendASCII("ext");
[email protected]f484f8d52014-06-12 08:38:182118 ASSERT_TRUE(
2119 base::CopyDirectory(data_dir()
2120 .AppendASCII("good")
2121 .AppendASCII("Extensions")
2122 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
2123 .AppendASCII("1.0.0.0"),
2124 input_directory,
2125 /*recursive=*/true));
[email protected]ab55c2b2012-06-01 23:55:032126
[email protected]ea1a3f62012-11-16 20:34:232127 base::ScopedTempDir output_temp_dir;
[email protected]ab55c2b2012-06-01 23:55:032128 ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir());
[email protected]650b2d52013-02-10 03:41:452129 base::FilePath output_directory = output_temp_dir.path();
[email protected]ab55c2b2012-06-01 23:55:032130
[email protected]650b2d52013-02-10 03:41:452131 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
2132 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem"));
[email protected]ab55c2b2012-06-01 23:55:032133
2134 // Pack the extension once to get a private key.
2135 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
[email protected]650b2d52013-02-10 03:41:452136 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(),
[email protected]ab55c2b2012-06-01 23:55:032137 privkey_path, ExtensionCreator::kNoRunFlags))
2138 << creator->error_message();
[email protected]7567484142013-07-11 17:36:072139 ASSERT_TRUE(base::PathExists(crx_path));
2140 ASSERT_TRUE(base::PathExists(privkey_path));
[email protected]ab55c2b2012-06-01 23:55:032141
[email protected]dd3aa792013-07-16 19:10:232142 base::DeleteFile(crx_path, false);
[email protected]ab55c2b2012-06-01 23:55:032143 // Move the pem file into the extension.
[email protected]5553d5b2013-07-01 23:07:362144 base::Move(privkey_path,
[email protected]ab55c2b2012-06-01 23:55:032145 input_directory.AppendASCII("privkey.pem"));
2146
2147 // This pack should fail because of the contained private key.
[email protected]650b2d52013-02-10 03:41:452148 EXPECT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(),
[email protected]ab55c2b2012-06-01 23:55:032149 privkey_path, ExtensionCreator::kNoRunFlags));
2150 EXPECT_THAT(creator->error_message(),
2151 testing::ContainsRegex(
2152 "extension includes the key file.*privkey.pem"));
2153}
2154
[email protected]a17f9462009-06-09 02:56:412155// Test Packaging and installing an extension using an openssl generated key.
2156// The openssl is generated with the following:
[email protected]a1257b12009-06-12 02:51:342157// > openssl genrsa -out privkey.pem 1024
[email protected]df4956e2009-06-10 16:53:422158// > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem
[email protected]a1257b12009-06-12 02:51:342159// The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a
[email protected]a17f9462009-06-09 02:56:412160// PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects.
[email protected]d9a61e12012-11-14 02:43:472161TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) {
[email protected]eaa7dd182010-12-14 11:09:002162 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182163 base::FilePath input_directory =
2164 data_dir()
2165 .AppendASCII("good")
2166 .AppendASCII("Extensions")
2167 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
2168 .AppendASCII("1.0.0.0");
2169 base::FilePath privkey_path(
2170 data_dir().AppendASCII("openssl_privkey_asn1.pem"));
[email protected]7567484142013-07-11 17:36:072171 ASSERT_TRUE(base::PathExists(privkey_path));
[email protected]a17f9462009-06-09 02:56:412172
[email protected]ea1a3f62012-11-16 20:34:232173 base::ScopedTempDir temp_dir;
[email protected]aca3e9b2009-11-03 01:14:212174 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
[email protected]650b2d52013-02-10 03:41:452175 base::FilePath output_directory = temp_dir.path();
[email protected]aca3e9b2009-11-03 01:14:212176
[email protected]650b2d52013-02-10 03:41:452177 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
[email protected]a17f9462009-06-09 02:56:412178
2179 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator());
2180 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path,
[email protected]650b2d52013-02-10 03:41:452181 base::FilePath(), ExtensionCreator::kOverwriteCRX));
[email protected]a17f9462009-06-09 02:56:412182
[email protected]8f512c72011-11-22 21:02:502183 InstallCRX(crx_path, INSTALL_NEW);
[email protected]a17f9462009-06-09 02:56:412184}
[email protected]a17f9462009-06-09 02:56:412185
[email protected]87065922014-05-28 14:50:372186#if defined(THREAD_SANITIZER)
2187// Flaky under Tsan. http://crbug.com/377702
2188#define MAYBE_InstallTheme DISABLED_InstallTheme
2189#else
2190#define MAYBE_InstallTheme InstallTheme
2191#endif
2192
2193TEST_F(ExtensionServiceTest, MAYBE_InstallTheme) {
[email protected]eaa7dd182010-12-14 11:09:002194 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182195 service()->Init();
[email protected]e2eb43112009-05-29 21:19:542196
2197 // A theme.
[email protected]f484f8d52014-06-12 08:38:182198 base::FilePath path = data_dir().AppendASCII("theme.crx");
[email protected]8f512c72011-11-22 21:02:502199 InstallCRX(path, INSTALL_NEW);
[email protected]25b34332009-06-05 21:53:192200 int pref_count = 0;
2201 ValidatePrefKeyCount(++pref_count);
[email protected]e2194742010-08-12 05:54:342202 ValidateIntegerPref(theme_crx, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:402203 ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL);
[email protected]e2eb43112009-05-29 21:19:542204
[email protected]6ef635e42009-07-26 06:16:122205 // A theme when extensions are disabled. Themes can be installed, even when
2206 // extensions are disabled.
[email protected]f484f8d52014-06-12 08:38:182207 service()->set_extensions_enabled(false);
2208 path = data_dir().AppendASCII("theme2.crx");
[email protected]8f512c72011-11-22 21:02:502209 InstallCRX(path, INSTALL_NEW);
[email protected]25b34332009-06-05 21:53:192210 ValidatePrefKeyCount(++pref_count);
[email protected]e2194742010-08-12 05:54:342211 ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:402212 ValidateIntegerPref(theme2_crx, "location", Manifest::INTERNAL);
[email protected]494c06e2009-07-25 01:06:422213
[email protected]f6dec1e322012-04-30 21:04:512214 // A theme with extension elements. Themes cannot have extension elements,
2215 // so any such elements (like content scripts) should be ignored.
[email protected]f484f8d52014-06-12 08:38:182216 service()->set_extensions_enabled(true);
[email protected]f6dec1e322012-04-30 21:04:512217 {
[email protected]f484f8d52014-06-12 08:38:182218 path = data_dir().AppendASCII("theme_with_extension.crx");
[email protected]f6dec1e322012-04-30 21:04:512219 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2220 ValidatePrefKeyCount(++pref_count);
2221 ASSERT_TRUE(extension);
2222 EXPECT_TRUE(extension->is_theme());
[email protected]334ec0a2013-03-24 01:36:162223 EXPECT_EQ(
2224 0u,
2225 extensions::ContentScriptsInfo::GetContentScripts(extension).size());
[email protected]f6dec1e322012-04-30 21:04:512226 }
[email protected]12198912009-06-05 03:41:222227
2228 // A theme with image resources missing (misspelt path).
[email protected]f484f8d52014-06-12 08:38:182229 path = data_dir().AppendASCII("theme_missing_image.crx");
[email protected]8f512c72011-11-22 21:02:502230 InstallCRX(path, INSTALL_FAILED);
[email protected]25b34332009-06-05 21:53:192231 ValidatePrefKeyCount(pref_count);
[email protected]e2eb43112009-05-29 21:19:542232}
2233
[email protected]d9a61e12012-11-14 02:43:472234TEST_F(ExtensionServiceTest, LoadLocalizedTheme) {
[email protected]584245e52010-06-17 01:08:132235 // Load.
[email protected]eaa7dd182010-12-14 11:09:002236 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182237 service()->Init();
[email protected]b1ac70462013-08-14 21:33:302238
[email protected]f484f8d52014-06-12 08:38:182239 base::FilePath extension_path = data_dir().AppendASCII("theme_i18n");
[email protected]584245e52010-06-17 01:08:132240
[email protected]f484f8d52014-06-12 08:38:182241 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
[email protected]eedc1c752013-08-09 18:51:552242 base::RunLoop().RunUntilIdle();
[email protected]584245e52010-06-17 01:08:132243 EXPECT_EQ(0u, GetErrors().size());
2244 ASSERT_EQ(1u, loaded_.size());
[email protected]f484f8d52014-06-12 08:38:182245 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2246 const Extension* theme = registry()->enabled_extensions().begin()->get();
[email protected]8f512c72011-11-22 21:02:502247 EXPECT_EQ("name", theme->name());
2248 EXPECT_EQ("description", theme->description());
[email protected]a17dfcf2012-12-30 02:07:092249
2250 // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a
2251 // temporary directory, but it automatically installs to the extension's
2252 // directory, and we don't want to copy the whole extension for a unittest.
[email protected]650b2d52013-02-10 03:41:452253 base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename);
[email protected]7567484142013-07-11 17:36:072254 ASSERT_TRUE(base::PathExists(theme_file));
[email protected]dd3aa792013-07-16 19:10:232255 ASSERT_TRUE(base::DeleteFile(theme_file, false)); // Not recursive.
[email protected]584245e52010-06-17 01:08:132256}
2257
[email protected]c24fb292012-02-01 22:52:112258// Tests that we can change the ID of an unpacked extension by adding a key
2259// to its manifest.
[email protected]d9a61e12012-11-14 02:43:472260TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) {
[email protected]c24fb292012-02-01 22:52:112261 InitializeEmptyExtensionService();
2262
[email protected]ea1a3f62012-11-16 20:34:232263 base::ScopedTempDir temp;
[email protected]c24fb292012-02-01 22:52:112264 ASSERT_TRUE(temp.CreateUniqueTempDir());
2265
[email protected]650b2d52013-02-10 03:41:452266 base::FilePath extension_path = temp.path();
2267 base::FilePath manifest_path =
[email protected]993da5e2013-03-23 21:25:162268 extension_path.Append(extensions::kManifestFilename);
[email protected]f484f8d52014-06-12 08:38:182269 base::FilePath manifest_no_key =
2270 data_dir().AppendASCII("unpacked").AppendASCII("manifest_no_key.json");
[email protected]c24fb292012-02-01 22:52:112271
[email protected]f484f8d52014-06-12 08:38:182272 base::FilePath manifest_with_key =
2273 data_dir().AppendASCII("unpacked").AppendASCII("manifest_with_key.json");
[email protected]c24fb292012-02-01 22:52:112274
[email protected]7567484142013-07-11 17:36:072275 ASSERT_TRUE(base::PathExists(manifest_no_key));
2276 ASSERT_TRUE(base::PathExists(manifest_with_key));
[email protected]c24fb292012-02-01 22:52:112277
2278 // Load the unpacked extension with no key.
[email protected]f0ff2ad2013-07-09 17:42:262279 base::CopyFile(manifest_no_key, manifest_path);
[email protected]f484f8d52014-06-12 08:38:182280 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
[email protected]c24fb292012-02-01 22:52:112281
[email protected]eedc1c752013-08-09 18:51:552282 base::RunLoop().RunUntilIdle();
[email protected]c24fb292012-02-01 22:52:112283 EXPECT_EQ(0u, GetErrors().size());
2284 ASSERT_EQ(1u, loaded_.size());
[email protected]f484f8d52014-06-12 08:38:182285 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]c24fb292012-02-01 22:52:112286
2287 // Add the key to the manifest.
[email protected]f0ff2ad2013-07-09 17:42:262288 base::CopyFile(manifest_with_key, manifest_path);
[email protected]c24fb292012-02-01 22:52:112289 loaded_.clear();
2290
2291 // Reload the extensions.
[email protected]f484f8d52014-06-12 08:38:182292 service()->ReloadExtensionsForTest();
2293 const Extension* extension = service()->GetExtensionById(unpacked, false);
[email protected]c24fb292012-02-01 22:52:112294 EXPECT_EQ(unpacked, extension->id());
2295 ASSERT_EQ(1u, loaded_.size());
2296
2297 // TODO(jstritar): Right now this just makes sure we don't crash and burn, but
2298 // we should also test that preferences are preserved.
2299}
2300
[email protected]91236521162012-05-24 15:02:512301#if defined(OS_POSIX)
[email protected]d9a61e12012-11-14 02:43:472302TEST_F(ExtensionServiceTest, UnpackedExtensionMayContainSymlinkedFiles) {
[email protected]f484f8d52014-06-12 08:38:182303 base::FilePath source_data_dir =
2304 data_dir().AppendASCII("unpacked").AppendASCII("symlinks_allowed");
[email protected]91236521162012-05-24 15:02:512305
2306 // Paths to test data files.
[email protected]650b2d52013-02-10 03:41:452307 base::FilePath source_manifest = source_data_dir.AppendASCII("manifest.json");
[email protected]7567484142013-07-11 17:36:072308 ASSERT_TRUE(base::PathExists(source_manifest));
[email protected]650b2d52013-02-10 03:41:452309 base::FilePath source_icon = source_data_dir.AppendASCII("icon.png");
[email protected]7567484142013-07-11 17:36:072310 ASSERT_TRUE(base::PathExists(source_icon));
[email protected]91236521162012-05-24 15:02:512311
2312 // Set up the temporary extension directory.
[email protected]ea1a3f62012-11-16 20:34:232313 base::ScopedTempDir temp;
[email protected]91236521162012-05-24 15:02:512314 ASSERT_TRUE(temp.CreateUniqueTempDir());
[email protected]650b2d52013-02-10 03:41:452315 base::FilePath extension_path = temp.path();
[email protected]993da5e2013-03-23 21:25:162316 base::FilePath manifest = extension_path.Append(
2317 extensions::kManifestFilename);
[email protected]650b2d52013-02-10 03:41:452318 base::FilePath icon_symlink = extension_path.AppendASCII("icon.png");
[email protected]f0ff2ad2013-07-09 17:42:262319 base::CopyFile(source_manifest, manifest);
[email protected]b264eab2013-11-27 23:22:082320 base::CreateSymbolicLink(source_icon, icon_symlink);
[email protected]91236521162012-05-24 15:02:512321
2322 // Load extension.
2323 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182324 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
[email protected]eedc1c752013-08-09 18:51:552325 base::RunLoop().RunUntilIdle();
[email protected]91236521162012-05-24 15:02:512326
2327 EXPECT_TRUE(GetErrors().empty());
2328 ASSERT_EQ(1u, loaded_.size());
[email protected]f484f8d52014-06-12 08:38:182329 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]91236521162012-05-24 15:02:512330}
2331#endif
2332
[email protected]5ccca8ad2013-08-19 22:35:342333TEST_F(ExtensionServiceTest, UnpackedExtensionMayNotHaveUnderscore) {
2334 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182335 base::FilePath extension_path = data_dir().AppendASCII("underscore_name");
2336 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
[email protected]5ccca8ad2013-08-19 22:35:342337 base::RunLoop().RunUntilIdle();
2338 EXPECT_EQ(1u, GetErrors().size());
[email protected]f484f8d52014-06-12 08:38:182339 EXPECT_EQ(0u, registry()->enabled_extensions().size());
[email protected]5ccca8ad2013-08-19 22:35:342340}
2341
[email protected]d9a61e12012-11-14 02:43:472342TEST_F(ExtensionServiceTest, InstallLocalizedTheme) {
[email protected]eaa7dd182010-12-14 11:09:002343 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182344 service()->Init();
[email protected]b1ac70462013-08-14 21:33:302345
[email protected]f484f8d52014-06-12 08:38:182346 base::FilePath theme_path = data_dir().AppendASCII("theme_i18n");
[email protected]584245e52010-06-17 01:08:132347
[email protected]8f512c72011-11-22 21:02:502348 const Extension* theme = PackAndInstallCRX(theme_path, INSTALL_NEW);
[email protected]584245e52010-06-17 01:08:132349
[email protected]584245e52010-06-17 01:08:132350 EXPECT_EQ(0u, GetErrors().size());
[email protected]f484f8d52014-06-12 08:38:182351 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]8f512c72011-11-22 21:02:502352 EXPECT_EQ("name", theme->name());
2353 EXPECT_EQ("description", theme->description());
[email protected]584245e52010-06-17 01:08:132354}
2355
[email protected]d9a61e12012-11-14 02:43:472356TEST_F(ExtensionServiceTest, InstallApps) {
[email protected]eaa7dd182010-12-14 11:09:002357 InitializeEmptyExtensionService();
[email protected]6d2e60bd2010-06-03 22:37:392358
2359 // An empty app.
[email protected]f484f8d52014-06-12 08:38:182360 const Extension* app =
2361 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
[email protected]6d2e60bd2010-06-03 22:37:392362 int pref_count = 0;
2363 ValidatePrefKeyCount(++pref_count);
[email protected]f484f8d52014-06-12 08:38:182364 ASSERT_EQ(1u, registry()->enabled_extensions().size());
[email protected]8f512c72011-11-22 21:02:502365 ValidateIntegerPref(app->id(), "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:402366 ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL);
[email protected]6d2e60bd2010-06-03 22:37:392367
2368 // Another app with non-overlapping extent. Should succeed.
[email protected]f484f8d52014-06-12 08:38:182369 PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
[email protected]6d2e60bd2010-06-03 22:37:392370 ValidatePrefKeyCount(++pref_count);
2371
2372 // A third app whose extent overlaps the first. Should fail.
[email protected]f484f8d52014-06-12 08:38:182373 PackAndInstallCRX(data_dir().AppendASCII("app3"), INSTALL_FAILED);
[email protected]cd10e282010-10-26 21:04:512374 ValidatePrefKeyCount(pref_count);
[email protected]6d2e60bd2010-06-03 22:37:392375}
2376
[email protected]b6e64fd2011-08-09 19:49:192377// Tests that file access is OFF by default.
[email protected]d9a61e12012-11-14 02:43:472378TEST_F(ExtensionServiceTest, DefaultFileAccess) {
[email protected]b6e64fd2011-08-09 19:49:192379 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182380 const Extension* extension = PackAndInstallCRX(
2381 data_dir().AppendASCII("permissions").AppendASCII("files"), INSTALL_NEW);
[email protected]b6e64fd2011-08-09 19:49:192382 EXPECT_EQ(0u, GetErrors().size());
[email protected]f484f8d52014-06-12 08:38:182383 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]7c82539c2014-02-19 06:09:172384 EXPECT_FALSE(
[email protected]f484f8d52014-06-12 08:38:182385 ExtensionPrefs::Get(profile())->AllowFileAccess(extension->id()));
[email protected]b6e64fd2011-08-09 19:49:192386}
2387
[email protected]d9a61e12012-11-14 02:43:472388TEST_F(ExtensionServiceTest, UpdateApps) {
[email protected]15300d92011-01-19 18:44:302389 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182390 base::FilePath extensions_path = data_dir().AppendASCII("app_update");
[email protected]15300d92011-01-19 18:44:302391
2392 // First install v1 of a hosted app.
[email protected]8f512c72011-11-22 21:02:502393 const Extension* extension =
2394 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW);
[email protected]f484f8d52014-06-12 08:38:182395 ASSERT_EQ(1u, registry()->enabled_extensions().size());
[email protected]8f512c72011-11-22 21:02:502396 std::string id = extension->id();
2397 ASSERT_EQ(std::string("1"), extension->version()->GetString());
[email protected]15300d92011-01-19 18:44:302398
2399 // Now try updating to v2.
2400 UpdateExtension(id,
2401 extensions_path.AppendASCII("v2.crx"),
2402 ENABLED);
2403 ASSERT_EQ(std::string("2"),
[email protected]f484f8d52014-06-12 08:38:182404 service()->GetExtensionById(id, false)->version()->GetString());
[email protected]15300d92011-01-19 18:44:302405}
2406
[email protected]e6a6c2e02012-01-13 00:06:482407// Verifies that the NTP page and launch ordinals are kept when updating apps.
[email protected]d9a61e12012-11-14 02:43:472408TEST_F(ExtensionServiceTest, UpdateAppsRetainOrdinals) {
[email protected]e6a6c2e02012-01-13 00:06:482409 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182410 AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting();
2411 base::FilePath extensions_path = data_dir().AppendASCII("app_update");
[email protected]e6a6c2e02012-01-13 00:06:482412
2413 // First install v1 of a hosted app.
2414 const Extension* extension =
2415 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW);
[email protected]f484f8d52014-06-12 08:38:182416 ASSERT_EQ(1u, registry()->enabled_extensions().size());
[email protected]e6a6c2e02012-01-13 00:06:482417 std::string id = extension->id();
2418 ASSERT_EQ(std::string("1"), extension->version()->GetString());
2419
2420 // Modify the ordinals so we can distinguish them from the defaults.
[email protected]36b643212012-09-07 12:53:002421 syncer::StringOrdinal new_page_ordinal =
2422 sorting->GetPageOrdinal(id).CreateAfter();
2423 syncer::StringOrdinal new_launch_ordinal =
[email protected]e6a6c2e02012-01-13 00:06:482424 sorting->GetAppLaunchOrdinal(id).CreateBefore();
2425
2426 sorting->SetPageOrdinal(id, new_page_ordinal);
2427 sorting->SetAppLaunchOrdinal(id, new_launch_ordinal);
2428
2429 // Now try updating to v2.
2430 UpdateExtension(id, extensions_path.AppendASCII("v2.crx"), ENABLED);
2431 ASSERT_EQ(std::string("2"),
[email protected]f484f8d52014-06-12 08:38:182432 service()->GetExtensionById(id, false)->version()->GetString());
[email protected]e6a6c2e02012-01-13 00:06:482433
2434 // Verify that the ordinals match.
[email protected]36b643212012-09-07 12:53:002435 ASSERT_TRUE(new_page_ordinal.Equals(sorting->GetPageOrdinal(id)));
2436 ASSERT_TRUE(new_launch_ordinal.Equals(sorting->GetAppLaunchOrdinal(id)));
[email protected]e6a6c2e02012-01-13 00:06:482437}
2438
[email protected]b873cd92012-02-09 21:51:482439// Ensures that the CWS has properly initialized ordinals.
[email protected]d9a61e12012-11-14 02:43:472440TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) {
[email protected]b873cd92012-02-09 21:51:482441 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182442 service()->component_loader()->Add(
[email protected]650b2d52013-02-10 03:41:452443 IDR_WEBSTORE_MANIFEST, base::FilePath(FILE_PATH_LITERAL("web_store")));
[email protected]f484f8d52014-06-12 08:38:182444 service()->Init();
[email protected]b873cd92012-02-09 21:51:482445
[email protected]f484f8d52014-06-12 08:38:182446 AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting();
[email protected]b873cd92012-02-09 21:51:482447 EXPECT_TRUE(
2448 sorting->GetPageOrdinal(extension_misc::kWebStoreAppId).IsValid());
2449 EXPECT_TRUE(
2450 sorting->GetAppLaunchOrdinal(extension_misc::kWebStoreAppId).IsValid());
2451}
2452
[email protected]fe10c202013-03-11 23:44:342453TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
[email protected]eaa7dd182010-12-14 11:09:002454 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182455 EXPECT_TRUE(registry()->enabled_extensions().is_empty());
[email protected]c2c263c2010-08-13 21:59:482456
[email protected]c2c263c2010-08-13 21:59:482457 int pref_count = 0;
[email protected]c2c263c2010-08-13 21:59:482458
2459 // Install app1 with unlimited storage.
[email protected]8f512c72011-11-22 21:02:502460 const Extension* extension =
[email protected]f484f8d52014-06-12 08:38:182461 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
[email protected]c2c263c2010-08-13 21:59:482462 ValidatePrefKeyCount(++pref_count);
[email protected]f484f8d52014-06-12 08:38:182463 ASSERT_EQ(1u, registry()->enabled_extensions().size());
[email protected]c2c263c2010-08-13 21:59:482464 const std::string id1 = extension->id();
[email protected]076ebeda2014-06-06 21:47:262465 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
[email protected]c2e66e12012-06-27 06:27:062466 APIPermission::kUnlimitedStorage));
[email protected]cced75a2011-05-20 08:31:122467 EXPECT_TRUE(extension->web_extent().MatchesURL(
[email protected]6b414c232013-06-05 07:53:342468 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
2469 const GURL origin1(
2470 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
[email protected]f484f8d52014-06-12 08:38:182471 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2472 origin1));
[email protected]c2c263c2010-08-13 21:59:482473
2474 // Install app2 from the same origin with unlimited storage.
[email protected]f484f8d52014-06-12 08:38:182475 extension = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
[email protected]c2c263c2010-08-13 21:59:482476 ValidatePrefKeyCount(++pref_count);
[email protected]f484f8d52014-06-12 08:38:182477 ASSERT_EQ(2u, registry()->enabled_extensions().size());
[email protected]c2c263c2010-08-13 21:59:482478 const std::string id2 = extension->id();
[email protected]076ebeda2014-06-06 21:47:262479 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
[email protected]c2e66e12012-06-27 06:27:062480 APIPermission::kUnlimitedStorage));
[email protected]cced75a2011-05-20 08:31:122481 EXPECT_TRUE(extension->web_extent().MatchesURL(
[email protected]6b414c232013-06-05 07:53:342482 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
2483 const GURL origin2(
2484 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
[email protected]c2c263c2010-08-13 21:59:482485 EXPECT_EQ(origin1, origin2);
[email protected]f484f8d52014-06-12 08:38:182486 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2487 origin2));
[email protected]19eb80152011-02-26 00:28:432488
[email protected]c2c263c2010-08-13 21:59:482489 // Uninstall one of them, unlimited storage should still be granted
2490 // to the origin.
[email protected]fa2416f2011-05-03 08:41:202491 UninstallExtension(id1, false);
[email protected]f484f8d52014-06-12 08:38:182492 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2493 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2494 origin1));
[email protected]19eb80152011-02-26 00:28:432495
[email protected]c2c263c2010-08-13 21:59:482496 // Uninstall the other, unlimited storage should be revoked.
[email protected]fa2416f2011-05-03 08:41:202497 UninstallExtension(id2, false);
[email protected]f484f8d52014-06-12 08:38:182498 EXPECT_EQ(0u, registry()->enabled_extensions().size());
2499 EXPECT_FALSE(
2500 profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
2501 origin2));
[email protected]c2c263c2010-08-13 21:59:482502}
2503
[email protected]d9a61e12012-11-14 02:43:472504TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
[email protected]eaa7dd182010-12-14 11:09:002505 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182506 EXPECT_TRUE(registry()->enabled_extensions().is_empty());
[email protected]654512b2010-09-01 02:09:422507
[email protected]654512b2010-09-01 02:09:422508 int pref_count = 0;
2509
[email protected]8f512c72011-11-22 21:02:502510 const Extension* extension =
[email protected]f484f8d52014-06-12 08:38:182511 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
[email protected]654512b2010-09-01 02:09:422512 ValidatePrefKeyCount(++pref_count);
[email protected]f484f8d52014-06-12 08:38:182513 ASSERT_EQ(1u, registry()->enabled_extensions().size());
[email protected]654512b2010-09-01 02:09:422514 EXPECT_TRUE(extension->is_app());
2515 const std::string id1 = extension->id();
[email protected]6b414c232013-06-05 07:53:342516 const GURL origin1(
2517 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
[email protected]f484f8d52014-06-12 08:38:182518 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2519 origin1));
[email protected]654512b2010-09-01 02:09:422520
2521 // App 4 has a different origin (maps.google.com).
[email protected]f484f8d52014-06-12 08:38:182522 extension = PackAndInstallCRX(data_dir().AppendASCII("app4"), INSTALL_NEW);
[email protected]654512b2010-09-01 02:09:422523 ValidatePrefKeyCount(++pref_count);
[email protected]f484f8d52014-06-12 08:38:182524 ASSERT_EQ(2u, registry()->enabled_extensions().size());
[email protected]654512b2010-09-01 02:09:422525 const std::string id2 = extension->id();
[email protected]6b414c232013-06-05 07:53:342526 const GURL origin2(
2527 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
[email protected]654512b2010-09-01 02:09:422528 ASSERT_NE(origin1, origin2);
[email protected]f484f8d52014-06-12 08:38:182529 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2530 origin2));
[email protected]654512b2010-09-01 02:09:422531
[email protected]fa2416f2011-05-03 08:41:202532 UninstallExtension(id1, false);
[email protected]f484f8d52014-06-12 08:38:182533 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]654512b2010-09-01 02:09:422534
[email protected]fa2416f2011-05-03 08:41:202535 UninstallExtension(id2, false);
[email protected]654512b2010-09-01 02:09:422536
[email protected]f484f8d52014-06-12 08:38:182537 EXPECT_TRUE(registry()->enabled_extensions().is_empty());
2538 EXPECT_FALSE(
2539 profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2540 origin1));
2541 EXPECT_FALSE(
2542 profile()->GetExtensionSpecialStoragePolicy()->IsStorageProtected(
2543 origin2));
[email protected]654512b2010-09-01 02:09:422544}
2545
[email protected]894bb502009-05-21 22:39:572546// Test that when an extension version is reinstalled, nothing happens.
[email protected]d9a61e12012-11-14 02:43:472547TEST_F(ExtensionServiceTest, Reinstall) {
[email protected]eaa7dd182010-12-14 11:09:002548 InitializeEmptyExtensionService();
[email protected]894bb502009-05-21 22:39:572549
2550 // A simple extension that should install without error.
[email protected]f484f8d52014-06-12 08:38:182551 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:502552 InstallCRX(path, INSTALL_NEW);
[email protected]894bb502009-05-21 22:39:572553
[email protected]25b34332009-06-05 21:53:192554 ValidatePrefKeyCount(1);
[email protected]e2194742010-08-12 05:54:342555 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:402556 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
[email protected]894bb502009-05-21 22:39:572557
[email protected]ca3dbf52010-05-19 22:27:062558 // Reinstall the same version, it should overwrite the previous one.
[email protected]8f512c72011-11-22 21:02:502559 InstallCRX(path, INSTALL_UPDATED);
[email protected]894bb502009-05-21 22:39:572560
[email protected]25b34332009-06-05 21:53:192561 ValidatePrefKeyCount(1);
[email protected]e2194742010-08-12 05:54:342562 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:402563 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
[email protected]894bb502009-05-21 22:39:572564}
2565
[email protected]620db1762011-07-15 21:57:342566// Test that we can determine if extensions came from the
2567// Chrome web store.
[email protected]d9a61e12012-11-14 02:43:472568TEST_F(ExtensionServiceTest, FromWebStore) {
[email protected]8266d662011-07-12 21:53:262569 InitializeEmptyExtensionService();
2570
2571 // A simple extension that should install without error.
[email protected]f484f8d52014-06-12 08:38:182572 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:502573 // Not from web store.
2574 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2575 std::string id = extension->id();
[email protected]8266d662011-07-12 21:53:262576
[email protected]8266d662011-07-12 21:53:262577 ValidatePrefKeyCount(1);
[email protected]3f2a2fa2013-09-24 02:55:252578 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", false));
[email protected]620db1762011-07-15 21:57:342579 ASSERT_FALSE(extension->from_webstore());
[email protected]8266d662011-07-12 21:53:262580
[email protected]8266d662011-07-12 21:53:262581 // Test install from web store.
[email protected]8f512c72011-11-22 21:02:502582 InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store.
[email protected]8266d662011-07-12 21:53:262583
[email protected]8266d662011-07-12 21:53:262584 ValidatePrefKeyCount(1);
[email protected]3f2a2fa2013-09-24 02:55:252585 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true));
[email protected]620db1762011-07-15 21:57:342586
2587 // Reload so extension gets reinitialized with new value.
[email protected]f484f8d52014-06-12 08:38:182588 service()->ReloadExtensionsForTest();
2589 extension = service()->GetExtensionById(id, false);
[email protected]620db1762011-07-15 21:57:342590 ASSERT_TRUE(extension->from_webstore());
[email protected]3d729722011-09-20 02:57:092591
2592 // Upgrade to version 2.0
[email protected]f484f8d52014-06-12 08:38:182593 path = data_dir().AppendASCII("good2.crx");
[email protected]3d729722011-09-20 02:57:092594 UpdateExtension(good_crx, path, ENABLED);
2595 ValidatePrefKeyCount(1);
[email protected]3f2a2fa2013-09-24 02:55:252596 ASSERT_TRUE(ValidateBooleanPref(good_crx, "from_webstore", true));
[email protected]8266d662011-07-12 21:53:262597}
2598
[email protected]fbcc40302009-06-12 20:45:452599// Test upgrading a signed extension.
[email protected]d9a61e12012-11-14 02:43:472600TEST_F(ExtensionServiceTest, UpgradeSignedGood) {
[email protected]eaa7dd182010-12-14 11:09:002601 InitializeEmptyExtensionService();
[email protected]fbcc40302009-06-12 20:45:452602
[email protected]f484f8d52014-06-12 08:38:182603 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:502604 const Extension* extension = InstallCRX(path, INSTALL_NEW);
2605 std::string id = extension->id();
[email protected]fbcc40302009-06-12 20:45:452606
[email protected]8f512c72011-11-22 21:02:502607 ASSERT_EQ("1.0.0.0", extension->version()->GetString());
[email protected]fbcc40302009-06-12 20:45:452608 ASSERT_EQ(0u, GetErrors().size());
2609
[email protected]e7554c3f2013-05-29 00:36:562610 // Upgrade to version 1.0.0.1.
2611 // Also test that the extension's old and new title are correctly retrieved.
[email protected]f484f8d52014-06-12 08:38:182612 path = data_dir().AppendASCII("good2.crx");
[email protected]e7554c3f2013-05-29 00:36:562613 InstallCRX(path, INSTALL_UPDATED, Extension::NO_FLAGS, "My extension 1");
[email protected]f484f8d52014-06-12 08:38:182614 extension = service()->GetExtensionById(id, false);
[email protected]fbcc40302009-06-12 20:45:452615
[email protected]8f512c72011-11-22 21:02:502616 ASSERT_EQ("1.0.0.1", extension->version()->GetString());
[email protected]e7554c3f2013-05-29 00:36:562617 ASSERT_EQ("My updated extension 1", extension->name());
[email protected]fbcc40302009-06-12 20:45:452618 ASSERT_EQ(0u, GetErrors().size());
2619}
2620
2621// Test upgrading a signed extension with a bad signature.
[email protected]d9a61e12012-11-14 02:43:472622TEST_F(ExtensionServiceTest, UpgradeSignedBad) {
[email protected]eaa7dd182010-12-14 11:09:002623 InitializeEmptyExtensionService();
[email protected]fbcc40302009-06-12 20:45:452624
[email protected]f484f8d52014-06-12 08:38:182625 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:502626 InstallCRX(path, INSTALL_NEW);
[email protected]fbcc40302009-06-12 20:45:452627
2628 // Try upgrading with a bad signature. This should fail during the unpack,
2629 // because the key will not match the signature.
[email protected]f484f8d52014-06-12 08:38:182630 path = data_dir().AppendASCII("bad_signature.crx");
[email protected]8f512c72011-11-22 21:02:502631 InstallCRX(path, INSTALL_FAILED);
[email protected]fbcc40302009-06-12 20:45:452632}
2633
[email protected]e957fe52009-06-23 16:51:052634// Test a normal update via the UpdateExtension API
[email protected]d9a61e12012-11-14 02:43:472635TEST_F(ExtensionServiceTest, UpdateExtension) {
[email protected]eaa7dd182010-12-14 11:09:002636 InitializeEmptyExtensionService();
[email protected]e957fe52009-06-23 16:51:052637
[email protected]f484f8d52014-06-12 08:38:182638 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]e957fe52009-06-23 16:51:052639
[email protected]8f512c72011-11-22 21:02:502640 const Extension* good = InstallCRX(path, INSTALL_NEW);
[email protected]e957fe52009-06-23 16:51:052641 ASSERT_EQ("1.0.0.0", good->VersionString());
2642 ASSERT_EQ(good_crx, good->id());
2643
[email protected]f484f8d52014-06-12 08:38:182644 path = data_dir().AppendASCII("good2.crx");
[email protected]4416c5a2010-06-26 01:28:572645 UpdateExtension(good_crx, path, ENABLED);
[email protected]f484f8d52014-06-12 08:38:182646 ASSERT_EQ(
2647 "1.0.0.1",
2648 service()->GetExtensionById(good_crx, false)->version()->GetString());
[email protected]e957fe52009-06-23 16:51:052649}
2650
[email protected]3c4abc82012-10-22 22:25:542651// Extensions should not be updated during browser shutdown.
[email protected]d9a61e12012-11-14 02:43:472652TEST_F(ExtensionServiceTest, UpdateExtensionDuringShutdown) {
[email protected]3c4abc82012-10-22 22:25:542653 InitializeEmptyExtensionService();
2654
2655 // Install an extension.
[email protected]f484f8d52014-06-12 08:38:182656 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]3c4abc82012-10-22 22:25:542657 const Extension* good = InstallCRX(path, INSTALL_NEW);
2658 ASSERT_EQ(good_crx, good->id());
2659
2660 // Simulate shutdown.
[email protected]f484f8d52014-06-12 08:38:182661 service()->set_browser_terminating_for_test(true);
[email protected]3c4abc82012-10-22 22:25:542662
2663 // Update should fail and extension should not be updated.
[email protected]f484f8d52014-06-12 08:38:182664 path = data_dir().AppendASCII("good2.crx");
2665 bool updated = service()->UpdateExtension(good_crx, path, true, NULL);
[email protected]3c4abc82012-10-22 22:25:542666 ASSERT_FALSE(updated);
[email protected]f484f8d52014-06-12 08:38:182667 ASSERT_EQ(
2668 "1.0.0.0",
2669 service()->GetExtensionById(good_crx, false)->version()->GetString());
[email protected]3c4abc82012-10-22 22:25:542670}
2671
[email protected]e957fe52009-06-23 16:51:052672// Test updating a not-already-installed extension - this should fail
[email protected]d9a61e12012-11-14 02:43:472673TEST_F(ExtensionServiceTest, UpdateNotInstalledExtension) {
[email protected]eaa7dd182010-12-14 11:09:002674 InitializeEmptyExtensionService();
[email protected]e957fe52009-06-23 16:51:052675
[email protected]f484f8d52014-06-12 08:38:182676 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]4416c5a2010-06-26 01:28:572677 UpdateExtension(good_crx, path, UPDATED);
[email protected]eedc1c752013-08-09 18:51:552678 base::RunLoop().RunUntilIdle();
[email protected]e957fe52009-06-23 16:51:052679
[email protected]f484f8d52014-06-12 08:38:182680 ASSERT_EQ(0u, registry()->enabled_extensions().size());
[email protected]e957fe52009-06-23 16:51:052681 ASSERT_FALSE(installed_);
2682 ASSERT_EQ(0u, loaded_.size());
2683}
2684
2685// Makes sure you can't downgrade an extension via UpdateExtension
[email protected]d9a61e12012-11-14 02:43:472686TEST_F(ExtensionServiceTest, UpdateWillNotDowngrade) {
[email protected]eaa7dd182010-12-14 11:09:002687 InitializeEmptyExtensionService();
[email protected]e957fe52009-06-23 16:51:052688
[email protected]f484f8d52014-06-12 08:38:182689 base::FilePath path = data_dir().AppendASCII("good2.crx");
[email protected]e957fe52009-06-23 16:51:052690
[email protected]8f512c72011-11-22 21:02:502691 const Extension* good = InstallCRX(path, INSTALL_NEW);
[email protected]e957fe52009-06-23 16:51:052692 ASSERT_EQ("1.0.0.1", good->VersionString());
2693 ASSERT_EQ(good_crx, good->id());
2694
2695 // Change path from good2.crx -> good.crx
[email protected]f484f8d52014-06-12 08:38:182696 path = data_dir().AppendASCII("good.crx");
[email protected]4416c5a2010-06-26 01:28:572697 UpdateExtension(good_crx, path, FAILED);
[email protected]f484f8d52014-06-12 08:38:182698 ASSERT_EQ(
2699 "1.0.0.1",
2700 service()->GetExtensionById(good_crx, false)->version()->GetString());
[email protected]e957fe52009-06-23 16:51:052701}
2702
2703// Make sure calling update with an identical version does nothing
[email protected]d9a61e12012-11-14 02:43:472704TEST_F(ExtensionServiceTest, UpdateToSameVersionIsNoop) {
[email protected]eaa7dd182010-12-14 11:09:002705 InitializeEmptyExtensionService();
[email protected]e957fe52009-06-23 16:51:052706
[email protected]f484f8d52014-06-12 08:38:182707 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]e957fe52009-06-23 16:51:052708
[email protected]8f512c72011-11-22 21:02:502709 const Extension* good = InstallCRX(path, INSTALL_NEW);
[email protected]e957fe52009-06-23 16:51:052710 ASSERT_EQ(good_crx, good->id());
[email protected]4416c5a2010-06-26 01:28:572711 UpdateExtension(good_crx, path, FAILED_SILENTLY);
[email protected]aa142702010-03-26 01:26:332712}
2713
[email protected]dbec3792010-08-10 00:08:452714// Tests that updating an extension does not clobber old state.
[email protected]d9a61e12012-11-14 02:43:472715TEST_F(ExtensionServiceTest, UpdateExtensionPreservesState) {
[email protected]eaa7dd182010-12-14 11:09:002716 InitializeEmptyExtensionService();
[email protected]dbec3792010-08-10 00:08:452717
[email protected]f484f8d52014-06-12 08:38:182718 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]dbec3792010-08-10 00:08:452719
[email protected]8f512c72011-11-22 21:02:502720 const Extension* good = InstallCRX(path, INSTALL_NEW);
[email protected]dbec3792010-08-10 00:08:452721 ASSERT_EQ("1.0.0.0", good->VersionString());
2722 ASSERT_EQ(good_crx, good->id());
2723
2724 // Disable it and allow it to run in incognito. These settings should carry
2725 // over to the updated version.
[email protected]f484f8d52014-06-12 08:38:182726 service()->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION);
2727 extensions::util::SetIsIncognitoEnabled(good->id(), profile(), true);
2728 ExtensionPrefs::Get(profile())
[email protected]7c82539c2014-02-19 06:09:172729 ->SetDidExtensionEscalatePermissions(good, true);
[email protected]dbec3792010-08-10 00:08:452730
[email protected]f484f8d52014-06-12 08:38:182731 path = data_dir().AppendASCII("good2.crx");
[email protected]dbec3792010-08-10 00:08:452732 UpdateExtension(good_crx, path, INSTALLED);
[email protected]f484f8d52014-06-12 08:38:182733 ASSERT_EQ(1u, registry()->disabled_extensions().size());
2734 const Extension* good2 = service()->GetExtensionById(good_crx, true);
[email protected]dbec3792010-08-10 00:08:452735 ASSERT_EQ("1.0.0.1", good2->version()->GetString());
[email protected]f484f8d52014-06-12 08:38:182736 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good2->id(), profile()));
2737 EXPECT_TRUE(ExtensionPrefs::Get(profile())
[email protected]7c82539c2014-02-19 06:09:172738 ->DidExtensionEscalatePermissions(good2->id()));
[email protected]dbec3792010-08-10 00:08:452739}
2740
[email protected]5eb375e92010-11-26 07:50:412741// Tests that updating preserves extension location.
[email protected]d9a61e12012-11-14 02:43:472742TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) {
[email protected]eaa7dd182010-12-14 11:09:002743 InitializeEmptyExtensionService();
[email protected]5eb375e92010-11-26 07:50:412744
[email protected]f484f8d52014-06-12 08:38:182745 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]5eb375e92010-11-26 07:50:412746
[email protected]d41e2152012-02-24 04:20:272747 const Extension* good =
[email protected]1d5e58b2013-01-31 08:41:402748 InstallCRXWithLocation(path, Manifest::EXTERNAL_PREF, INSTALL_NEW);
[email protected]5eb375e92010-11-26 07:50:412749
2750 ASSERT_EQ("1.0.0.0", good->VersionString());
2751 ASSERT_EQ(good_crx, good->id());
2752
[email protected]f484f8d52014-06-12 08:38:182753 path = data_dir().AppendASCII("good2.crx");
[email protected]5eb375e92010-11-26 07:50:412754 UpdateExtension(good_crx, path, ENABLED);
[email protected]f484f8d52014-06-12 08:38:182755 const Extension* good2 = service()->GetExtensionById(good_crx, false);
[email protected]5eb375e92010-11-26 07:50:412756 ASSERT_EQ("1.0.0.1", good2->version()->GetString());
[email protected]1d5e58b2013-01-31 08:41:402757 EXPECT_EQ(good2->location(), Manifest::EXTERNAL_PREF);
[email protected]5eb375e92010-11-26 07:50:412758}
2759
[email protected]66e26872010-12-03 20:07:252760// Makes sure that LOAD extension types can downgrade.
[email protected]d9a61e12012-11-14 02:43:472761TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) {
[email protected]eaa7dd182010-12-14 11:09:002762 InitializeEmptyExtensionService();
[email protected]66e26872010-12-03 20:07:252763
[email protected]ea1a3f62012-11-16 20:34:232764 base::ScopedTempDir temp;
[email protected]66e26872010-12-03 20:07:252765 ASSERT_TRUE(temp.CreateUniqueTempDir());
2766
2767 // We'll write the extension manifest dynamically to a temporary path
2768 // to make it easier to change the version number.
[email protected]650b2d52013-02-10 03:41:452769 base::FilePath extension_path = temp.path();
2770 base::FilePath manifest_path =
[email protected]993da5e2013-03-23 21:25:162771 extension_path.Append(extensions::kManifestFilename);
[email protected]7567484142013-07-11 17:36:072772 ASSERT_FALSE(base::PathExists(manifest_path));
[email protected]66e26872010-12-03 20:07:252773
2774 // Start with version 2.0.
[email protected]023b3d12013-12-23 18:46:492775 base::DictionaryValue manifest;
[email protected]66e26872010-12-03 20:07:252776 manifest.SetString("version", "2.0");
2777 manifest.SetString("name", "LOAD Downgrade Test");
[email protected]b3d52852011-12-07 01:01:112778 manifest.SetInteger("manifest_version", 2);
[email protected]66e26872010-12-03 20:07:252779
2780 JSONFileValueSerializer serializer(manifest_path);
2781 ASSERT_TRUE(serializer.Serialize(manifest));
2782
[email protected]f484f8d52014-06-12 08:38:182783 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
[email protected]eedc1c752013-08-09 18:51:552784 base::RunLoop().RunUntilIdle();
[email protected]66e26872010-12-03 20:07:252785
2786 EXPECT_EQ(0u, GetErrors().size());
2787 ASSERT_EQ(1u, loaded_.size());
[email protected]12075d12013-02-27 05:38:052788 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
[email protected]f484f8d52014-06-12 08:38:182789 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]66e26872010-12-03 20:07:252790 EXPECT_EQ("2.0", loaded_[0]->VersionString());
2791
2792 // Now set the version number to 1.0, reload the extensions and verify that
2793 // the downgrade was accepted.
2794 manifest.SetString("version", "1.0");
2795 ASSERT_TRUE(serializer.Serialize(manifest));
2796
[email protected]f484f8d52014-06-12 08:38:182797 extensions::UnpackedInstaller::Create(service())->Load(extension_path);
[email protected]eedc1c752013-08-09 18:51:552798 base::RunLoop().RunUntilIdle();
[email protected]66e26872010-12-03 20:07:252799
2800 EXPECT_EQ(0u, GetErrors().size());
2801 ASSERT_EQ(1u, loaded_.size());
[email protected]12075d12013-02-27 05:38:052802 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
[email protected]f484f8d52014-06-12 08:38:182803 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]66e26872010-12-03 20:07:252804 EXPECT_EQ("1.0", loaded_[0]->VersionString());
2805}
2806
[email protected]77724b602014-05-14 11:36:122807#if !defined(OS_POSIX) || defined(OS_MACOSX)
[email protected]0d904312012-01-25 23:00:162808// LOAD extensions with plugins require approval.
[email protected]77724b602014-05-14 11:36:122809// Only run this on platforms that support NPAPI plugins.
[email protected]d9a61e12012-11-14 02:43:472810TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) {
[email protected]3f2a2fa2013-09-24 02:55:252811 base::FilePath extension_with_plugin_path = good1_path();
2812 base::FilePath extension_no_plugin_path = good2_path();
[email protected]0d904312012-01-25 23:00:162813
[email protected]ebd71962012-12-20 02:56:552814 InitPluginService();
[email protected]0d904312012-01-25 23:00:162815 InitializeEmptyExtensionService();
[email protected]98b6d942013-11-10 00:34:072816 InitializeProcessManager();
[email protected]f484f8d52014-06-12 08:38:182817 service()->set_show_extensions_prompts(true);
[email protected]0d904312012-01-25 23:00:162818
2819 // Start by canceling any install prompts.
[email protected]2a74d6f62014-07-24 11:53:472820 ExtensionInstallPrompt::g_auto_confirm_for_tests =
2821 ExtensionInstallPrompt::CANCEL;
[email protected]0d904312012-01-25 23:00:162822
2823 // The extension that has a plugin should not install.
[email protected]f484f8d52014-06-12 08:38:182824 extensions::UnpackedInstaller::Create(service())
2825 ->Load(extension_with_plugin_path);
[email protected]eedc1c752013-08-09 18:51:552826 base::RunLoop().RunUntilIdle();
[email protected]0d904312012-01-25 23:00:162827 EXPECT_EQ(0u, GetErrors().size());
2828 EXPECT_EQ(0u, loaded_.size());
[email protected]f484f8d52014-06-12 08:38:182829 EXPECT_EQ(0u, registry()->enabled_extensions().size());
2830 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]0d904312012-01-25 23:00:162831
2832 // But the extension with no plugin should since there's no prompt.
[email protected]252873a2013-07-19 01:39:482833 ExtensionErrorReporter::GetInstance()->ClearErrors();
[email protected]f484f8d52014-06-12 08:38:182834 extensions::UnpackedInstaller::Create(service())
2835 ->Load(extension_no_plugin_path);
[email protected]eedc1c752013-08-09 18:51:552836 base::RunLoop().RunUntilIdle();
[email protected]0d904312012-01-25 23:00:162837 EXPECT_EQ(0u, GetErrors().size());
2838 EXPECT_EQ(1u, loaded_.size());
[email protected]f484f8d52014-06-12 08:38:182839 EXPECT_EQ(1u, registry()->enabled_extensions().size());
2840 EXPECT_EQ(0u, registry()->disabled_extensions().size());
2841 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
[email protected]0d904312012-01-25 23:00:162842
2843 // The plugin extension should install if we accept the dialog.
[email protected]2a74d6f62014-07-24 11:53:472844 ExtensionInstallPrompt::g_auto_confirm_for_tests =
2845 ExtensionInstallPrompt::ACCEPT;
[email protected]0d904312012-01-25 23:00:162846
[email protected]252873a2013-07-19 01:39:482847 ExtensionErrorReporter::GetInstance()->ClearErrors();
[email protected]f484f8d52014-06-12 08:38:182848 extensions::UnpackedInstaller::Create(service())
2849 ->Load(extension_with_plugin_path);
[email protected]eedc1c752013-08-09 18:51:552850 base::RunLoop().RunUntilIdle();
[email protected]0d904312012-01-25 23:00:162851 EXPECT_EQ(0u, GetErrors().size());
2852 EXPECT_EQ(2u, loaded_.size());
[email protected]f484f8d52014-06-12 08:38:182853 EXPECT_EQ(2u, registry()->enabled_extensions().size());
2854 EXPECT_EQ(0u, registry()->disabled_extensions().size());
2855 EXPECT_TRUE(registry()->enabled_extensions().Contains(good1));
2856 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
[email protected]0d904312012-01-25 23:00:162857
2858 // Make sure the granted permissions have been setup.
[email protected]c2e66e12012-06-27 06:27:062859 scoped_refptr<PermissionSet> permissions(
[email protected]f484f8d52014-06-12 08:38:182860 ExtensionPrefs::Get(profile())->GetGrantedPermissions(good1));
[email protected]0d904312012-01-25 23:00:162861 EXPECT_FALSE(permissions->IsEmpty());
2862 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
2863 EXPECT_FALSE(permissions->apis().empty());
[email protected]c2e66e12012-06-27 06:27:062864 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin));
[email protected]0d904312012-01-25 23:00:162865
2866 // We should be able to reload the extension without getting another prompt.
2867 loaded_.clear();
[email protected]2a74d6f62014-07-24 11:53:472868 ExtensionInstallPrompt::g_auto_confirm_for_tests =
2869 ExtensionInstallPrompt::CANCEL;
[email protected]0d904312012-01-25 23:00:162870
[email protected]f484f8d52014-06-12 08:38:182871 service()->ReloadExtension(good1);
[email protected]eedc1c752013-08-09 18:51:552872 base::RunLoop().RunUntilIdle();
[email protected]0d904312012-01-25 23:00:162873 EXPECT_EQ(1u, loaded_.size());
[email protected]f484f8d52014-06-12 08:38:182874 EXPECT_EQ(2u, registry()->enabled_extensions().size());
2875 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]0d904312012-01-25 23:00:162876}
[email protected]77724b602014-05-14 11:36:122877#endif // !defined(OS_POSIX) || defined(OS_MACOSX)
[email protected]0d904312012-01-25 23:00:162878
[email protected]7fa19f82010-12-21 19:40:082879namespace {
2880
[email protected]8f3bcbd2013-06-05 08:42:402881bool IsExtension(const Extension* extension) {
2882 return extension->GetType() == Manifest::TYPE_EXTENSION;
[email protected]7fa19f82010-12-21 19:40:082883}
2884
[email protected]757d60a2014-05-23 00:11:442885#if defined(ENABLE_BLACKLIST_TESTS)
2886std::set<std::string> StringSet(const std::string& s) {
2887 std::set<std::string> set;
2888 set.insert(s);
2889 return set;
2890}
2891std::set<std::string> StringSet(const std::string& s1, const std::string& s2) {
2892 std::set<std::string> set = StringSet(s1);
2893 set.insert(s2);
2894 return set;
2895}
2896#endif // defined(ENABLE_BLACKLIST_TESTS)
2897
[email protected]7fa19f82010-12-21 19:40:082898} // namespace
2899
[email protected]aa142702010-03-26 01:26:332900// Test adding a pending extension.
[email protected]d9a61e12012-11-14 02:43:472901TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) {
[email protected]eaa7dd182010-12-14 11:09:002902 InitializeEmptyExtensionService();
[email protected]aa142702010-03-26 01:26:332903
[email protected]145a317b2011-04-12 16:03:462904 const std::string kFakeId(all_zero);
[email protected]aa142702010-03-26 01:26:332905 const GURL kFakeUpdateURL("http:://fake.update/url");
[email protected]aa142702010-03-26 01:26:332906 const bool kFakeInstallSilently(true);
[email protected]21db9ef2014-05-16 02:06:272907 const bool kFakeRemoteInstall(false);
[email protected]6338fa32014-07-16 21:41:592908 const bool kFakeInstalledByCustodian(false);
[email protected]aa142702010-03-26 01:26:332909
[email protected]21db9ef2014-05-16 02:06:272910 EXPECT_TRUE(
[email protected]6338fa32014-07-16 21:41:592911 service()->pending_extension_manager()->AddFromSync(
2912 kFakeId,
2913 kFakeUpdateURL,
2914 &IsExtension,
2915 kFakeInstallSilently,
2916 kFakeRemoteInstall,
2917 kFakeInstalledByCustodian));
[email protected]b2907fd2011-03-25 16:43:372918
[email protected]3f213ad2012-07-26 23:39:412919 const extensions::PendingExtensionInfo* pending_extension_info;
[email protected]f484f8d52014-06-12 08:38:182920 ASSERT_TRUE((pending_extension_info =
2921 service()->pending_extension_manager()->GetById(kFakeId)));
[email protected]51a3bf8b2012-06-08 22:53:062922 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url());
2923 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_);
2924 EXPECT_EQ(kFakeInstallSilently, pending_extension_info->install_silently());
[email protected]24b5fd42014-05-17 01:14:182925 // Use
2926 // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install())
2927 // instead of
2928 // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install())
2929 // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is
2930 // turned into an error with -Werror=conversion-null:
2931 // converting 'false' to pointer type for argument 1 of
2932 // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)'
2933 // https://code.google.com/p/googletest/issues/detail?id=458
2934 EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install());
[email protected]aa142702010-03-26 01:26:332935}
2936
[email protected]aa142702010-03-26 01:26:332937namespace {
2938const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
2939const char kGoodUpdateURL[] = "http://good.update/url";
[email protected]8ef78fd2010-08-19 17:14:322940const bool kGoodIsFromSync = true;
[email protected]aa142702010-03-26 01:26:332941const bool kGoodInstallSilently = true;
[email protected]21db9ef2014-05-16 02:06:272942const bool kGoodRemoteInstall = false;
[email protected]6338fa32014-07-16 21:41:592943const bool kGoodInstalledByCustodian = false;
[email protected]aa142702010-03-26 01:26:332944} // namespace
2945
2946// Test updating a pending extension.
[email protected]d9a61e12012-11-14 02:43:472947TEST_F(ExtensionServiceTest, UpdatePendingExtension) {
[email protected]eaa7dd182010-12-14 11:09:002948 InitializeEmptyExtensionService();
[email protected]21db9ef2014-05-16 02:06:272949 EXPECT_TRUE(
[email protected]6338fa32014-07-16 21:41:592950 service()->pending_extension_manager()->AddFromSync(
2951 kGoodId,
2952 GURL(kGoodUpdateURL),
2953 &IsExtension,
2954 kGoodInstallSilently,
2955 kGoodRemoteInstall,
2956 kGoodInstalledByCustodian));
[email protected]f484f8d52014-06-12 08:38:182957 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId));
[email protected]aa142702010-03-26 01:26:332958
[email protected]f484f8d52014-06-12 08:38:182959 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]6cc7dbae2011-04-29 21:18:332960 UpdateExtension(kGoodId, path, ENABLED);
[email protected]aa142702010-03-26 01:26:332961
[email protected]f484f8d52014-06-12 08:38:182962 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
[email protected]4416c5a2010-06-26 01:28:572963
[email protected]f484f8d52014-06-12 08:38:182964 const Extension* extension = service()->GetExtensionById(kGoodId, true);
[email protected]4416c5a2010-06-26 01:28:572965 ASSERT_TRUE(extension);
[email protected]aa142702010-03-26 01:26:332966}
2967
[email protected]7fa19f82010-12-21 19:40:082968namespace {
2969
[email protected]8f3bcbd2013-06-05 08:42:402970bool IsTheme(const Extension* extension) {
2971 return extension->is_theme();
[email protected]7fa19f82010-12-21 19:40:082972}
2973
2974} // namespace
2975
[email protected]11edd1e2010-07-21 00:14:502976// Test updating a pending theme.
[email protected]7f2c5552011-12-20 22:53:162977// Disabled due to ASAN failure. http://crbug.com/108320
[email protected]d9a61e12012-11-14 02:43:472978TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) {
[email protected]eaa7dd182010-12-14 11:09:002979 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:182980 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync(
[email protected]6338fa32014-07-16 21:41:592981 theme_crx, GURL(), &IsTheme, false, false, false));
[email protected]f484f8d52014-06-12 08:38:182982 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
[email protected]11edd1e2010-07-21 00:14:502983
[email protected]f484f8d52014-06-12 08:38:182984 base::FilePath path = data_dir().AppendASCII("theme.crx");
[email protected]11edd1e2010-07-21 00:14:502985 UpdateExtension(theme_crx, path, ENABLED);
2986
[email protected]f484f8d52014-06-12 08:38:182987 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
[email protected]11edd1e2010-07-21 00:14:502988
[email protected]f484f8d52014-06-12 08:38:182989 const Extension* extension = service()->GetExtensionById(theme_crx, true);
[email protected]11edd1e2010-07-21 00:14:502990 ASSERT_TRUE(extension);
2991
[email protected]f484f8d52014-06-12 08:38:182992 EXPECT_FALSE(
2993 ExtensionPrefs::Get(profile())->IsExtensionDisabled(extension->id()));
2994 EXPECT_TRUE(service()->IsExtensionEnabled(theme_crx));
[email protected]11edd1e2010-07-21 00:14:502995}
2996
[email protected]d74f92e2011-04-18 15:39:232997#if defined(OS_CHROMEOS)
2998// Always fails on ChromeOS: http://crbug.com/79737
[email protected]e00ccc92012-11-01 17:32:302999#define MAYBE_UpdatePendingExternalCrx DISABLED_UpdatePendingExternalCrx
[email protected]d74f92e2011-04-18 15:39:233000#else
3001#define MAYBE_UpdatePendingExternalCrx UpdatePendingExternalCrx
3002#endif
[email protected]8ef78fd2010-08-19 17:14:323003// Test updating a pending CRX as if the source is an external extension
3004// with an update URL. In this case we don't know if the CRX is a theme
3005// or not.
[email protected]d9a61e12012-11-14 02:43:473006TEST_F(ExtensionServiceTest, MAYBE_UpdatePendingExternalCrx) {
[email protected]eaa7dd182010-12-14 11:09:003007 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:183008 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]d8fd0fd2014-03-24 13:16:063009 theme_crx,
3010 std::string(),
3011 GURL(),
3012 Manifest::EXTERNAL_PREF_DOWNLOAD,
3013 Extension::NO_FLAGS,
[email protected]464213a2013-10-15 01:06:483014 false));
[email protected]8ef78fd2010-08-19 17:14:323015
[email protected]f484f8d52014-06-12 08:38:183016 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
[email protected]8ef78fd2010-08-19 17:14:323017
[email protected]f484f8d52014-06-12 08:38:183018 base::FilePath path = data_dir().AppendASCII("theme.crx");
[email protected]8ef78fd2010-08-19 17:14:323019 UpdateExtension(theme_crx, path, ENABLED);
3020
[email protected]f484f8d52014-06-12 08:38:183021 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
[email protected]8ef78fd2010-08-19 17:14:323022
[email protected]f484f8d52014-06-12 08:38:183023 const Extension* extension = service()->GetExtensionById(theme_crx, true);
[email protected]8ef78fd2010-08-19 17:14:323024 ASSERT_TRUE(extension);
3025
[email protected]f484f8d52014-06-12 08:38:183026 EXPECT_FALSE(
3027 ExtensionPrefs::Get(profile())->IsExtensionDisabled(extension->id()));
3028 EXPECT_TRUE(service()->IsExtensionEnabled(extension->id()));
3029 EXPECT_FALSE(
3030 extensions::util::IsIncognitoEnabled(extension->id(), profile()));
[email protected]8ef78fd2010-08-19 17:14:323031}
3032
[email protected]1afaf2a52010-11-02 19:29:173033// Test updating a pending CRX as if the source is an external extension
3034// with an update URL. The external update should overwrite a sync update,
3035// but a sync update should not overwrite a non-sync update.
[email protected]d9a61e12012-11-14 02:43:473036TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) {
[email protected]eaa7dd182010-12-14 11:09:003037 InitializeEmptyExtensionService();
[email protected]1afaf2a52010-11-02 19:29:173038
3039 // Add a crx to be installed from the update mechanism.
[email protected]21db9ef2014-05-16 02:06:273040 EXPECT_TRUE(
[email protected]6338fa32014-07-16 21:41:593041 service()->pending_extension_manager()->AddFromSync(
3042 kGoodId,
3043 GURL(kGoodUpdateURL),
3044 &IsExtension,
3045 kGoodInstallSilently,
3046 kGoodRemoteInstall,
3047 kGoodInstalledByCustodian));
[email protected]1afaf2a52010-11-02 19:29:173048
3049 // Check that there is a pending crx, with is_from_sync set to true.
[email protected]3f213ad2012-07-26 23:39:413050 const extensions::PendingExtensionInfo* pending_extension_info;
[email protected]f484f8d52014-06-12 08:38:183051 ASSERT_TRUE((pending_extension_info =
3052 service()->pending_extension_manager()->GetById(kGoodId)));
[email protected]51a3bf8b2012-06-08 22:53:063053 EXPECT_TRUE(pending_extension_info->is_from_sync());
[email protected]1afaf2a52010-11-02 19:29:173054
3055 // Add a crx to be updated, with the same ID, from a non-sync source.
[email protected]f484f8d52014-06-12 08:38:183056 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]d8fd0fd2014-03-24 13:16:063057 kGoodId,
3058 std::string(),
3059 GURL(kGoodUpdateURL),
3060 Manifest::EXTERNAL_PREF_DOWNLOAD,
3061 Extension::NO_FLAGS,
3062 false));
[email protected]1afaf2a52010-11-02 19:29:173063
3064 // Check that there is a pending crx, with is_from_sync set to false.
[email protected]f484f8d52014-06-12 08:38:183065 ASSERT_TRUE((pending_extension_info =
3066 service()->pending_extension_manager()->GetById(kGoodId)));
[email protected]51a3bf8b2012-06-08 22:53:063067 EXPECT_FALSE(pending_extension_info->is_from_sync());
[email protected]1d5e58b2013-01-31 08:41:403068 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD,
[email protected]51a3bf8b2012-06-08 22:53:063069 pending_extension_info->install_source());
[email protected]1afaf2a52010-11-02 19:29:173070
3071 // Add a crx to be installed from the update mechanism.
[email protected]21db9ef2014-05-16 02:06:273072 EXPECT_FALSE(
[email protected]6338fa32014-07-16 21:41:593073 service()->pending_extension_manager()->AddFromSync(
3074 kGoodId,
3075 GURL(kGoodUpdateURL),
3076 &IsExtension,
3077 kGoodInstallSilently,
3078 kGoodRemoteInstall,
3079 kGoodInstalledByCustodian));
[email protected]1afaf2a52010-11-02 19:29:173080
3081 // Check that the external, non-sync update was not overridden.
[email protected]f484f8d52014-06-12 08:38:183082 ASSERT_TRUE((pending_extension_info =
3083 service()->pending_extension_manager()->GetById(kGoodId)));
[email protected]51a3bf8b2012-06-08 22:53:063084 EXPECT_FALSE(pending_extension_info->is_from_sync());
[email protected]1d5e58b2013-01-31 08:41:403085 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD,
[email protected]51a3bf8b2012-06-08 22:53:063086 pending_extension_info->install_source());
[email protected]1afaf2a52010-11-02 19:29:173087}
3088
[email protected]8ef78fd2010-08-19 17:14:323089// Updating a theme should fail if the updater is explicitly told that
3090// the CRX is not a theme.
[email protected]d9a61e12012-11-14 02:43:473091TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) {
[email protected]eaa7dd182010-12-14 11:09:003092 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:183093 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync(
[email protected]6338fa32014-07-16 21:41:593094 theme_crx, GURL(), &IsExtension, true, false, false));
[email protected]8ef78fd2010-08-19 17:14:323095
[email protected]f484f8d52014-06-12 08:38:183096 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
[email protected]8ef78fd2010-08-19 17:14:323097
[email protected]f484f8d52014-06-12 08:38:183098 base::FilePath path = data_dir().AppendASCII("theme.crx");
[email protected]8ef78fd2010-08-19 17:14:323099 UpdateExtension(theme_crx, path, FAILED_SILENTLY);
3100
[email protected]f484f8d52014-06-12 08:38:183101 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
[email protected]8ef78fd2010-08-19 17:14:323102
[email protected]f484f8d52014-06-12 08:38:183103 const Extension* extension = service()->GetExtensionById(theme_crx, true);
[email protected]8ef78fd2010-08-19 17:14:323104 ASSERT_FALSE(extension);
3105}
3106
[email protected]aa142702010-03-26 01:26:333107// TODO(akalin): Test updating a pending extension non-silently once
3108// we can mock out ExtensionInstallUI and inject our version into
3109// UpdateExtension().
3110
[email protected]7fa19f82010-12-21 19:40:083111// Test updating a pending extension which fails the should-install test.
[email protected]d9a61e12012-11-14 02:43:473112TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) {
[email protected]eaa7dd182010-12-14 11:09:003113 InitializeEmptyExtensionService();
[email protected]aa142702010-03-26 01:26:333114 // Add pending extension with a flipped is_theme.
[email protected]21db9ef2014-05-16 02:06:273115 EXPECT_TRUE(
[email protected]6338fa32014-07-16 21:41:593116 service()->pending_extension_manager()->AddFromSync(
3117 kGoodId,
3118 GURL(kGoodUpdateURL),
3119 &IsTheme,
3120 kGoodInstallSilently,
3121 kGoodRemoteInstall,
3122 kGoodInstalledByCustodian));
[email protected]f484f8d52014-06-12 08:38:183123 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId));
[email protected]aa142702010-03-26 01:26:333124
[email protected]f484f8d52014-06-12 08:38:183125 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]4416c5a2010-06-26 01:28:573126 UpdateExtension(kGoodId, path, UPDATED);
[email protected]aa142702010-03-26 01:26:333127
3128 // TODO(akalin): Figure out how to check that the extensions
3129 // directory is cleaned up properly in OnExtensionInstalled().
3130
[email protected]f484f8d52014-06-12 08:38:183131 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
[email protected]aa142702010-03-26 01:26:333132}
3133
[email protected]11edd1e2010-07-21 00:14:503134// TODO(akalin): Figure out how to test that installs of pending
3135// unsyncable extensions are blocked.
3136
[email protected]aa142702010-03-26 01:26:333137// Test updating a pending extension for one that is not pending.
[email protected]d9a61e12012-11-14 02:43:473138TEST_F(ExtensionServiceTest, UpdatePendingExtensionNotPending) {
[email protected]eaa7dd182010-12-14 11:09:003139 InitializeEmptyExtensionService();
[email protected]aa142702010-03-26 01:26:333140
[email protected]f484f8d52014-06-12 08:38:183141 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]4416c5a2010-06-26 01:28:573142 UpdateExtension(kGoodId, path, UPDATED);
[email protected]aa142702010-03-26 01:26:333143
[email protected]f484f8d52014-06-12 08:38:183144 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
[email protected]aa142702010-03-26 01:26:333145}
3146
3147// Test updating a pending extension for one that is already
3148// installed.
[email protected]d9a61e12012-11-14 02:43:473149TEST_F(ExtensionServiceTest, UpdatePendingExtensionAlreadyInstalled) {
[email protected]eaa7dd182010-12-14 11:09:003150 InitializeEmptyExtensionService();
[email protected]aa142702010-03-26 01:26:333151
[email protected]f484f8d52014-06-12 08:38:183152 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:503153 const Extension* good = InstallCRX(path, INSTALL_NEW);
[email protected]f484f8d52014-06-12 08:38:183154 ASSERT_EQ(1u, registry()->enabled_extensions().size());
[email protected]aa142702010-03-26 01:26:333155
[email protected]8ef78fd2010-08-19 17:14:323156 EXPECT_FALSE(good->is_theme());
3157
[email protected]b2907fd2011-03-25 16:43:373158 // Use AddExtensionImpl() as AddFrom*() would balk.
[email protected]f484f8d52014-06-12 08:38:183159 service()->pending_extension_manager()->AddExtensionImpl(
[email protected]d8fd0fd2014-03-24 13:16:063160 good->id(),
3161 std::string(),
3162 extensions::ManifestURL::GetUpdateURL(good),
3163 Version(),
3164 &IsExtension,
3165 kGoodIsFromSync,
3166 kGoodInstallSilently,
3167 Manifest::INTERNAL,
3168 Extension::NO_FLAGS,
[email protected]21db9ef2014-05-16 02:06:273169 false,
3170 kGoodRemoteInstall);
[email protected]6cc7dbae2011-04-29 21:18:333171 UpdateExtension(good->id(), path, ENABLED);
[email protected]aa142702010-03-26 01:26:333172
[email protected]f484f8d52014-06-12 08:38:183173 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
[email protected]e957fe52009-06-23 16:51:053174}
3175
[email protected]3f2a2fa2013-09-24 02:55:253176#if defined(ENABLE_BLACKLIST_TESTS)
3177// Tests blacklisting then unblacklisting extensions after the service has been
3178// initialized.
[email protected]7d9b4e32013-10-25 06:11:543179TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) {
[email protected]f71b582c2014-01-10 17:03:153180 extensions::TestBlacklist test_blacklist;
[email protected]3f2a2fa2013-09-24 02:55:253181 // A profile with 3 extensions installed: good0, good1, and good2.
3182 InitializeGoodInstalledExtensionService();
[email protected]f484f8d52014-06-12 08:38:183183 test_blacklist.Attach(service()->blacklist_);
3184 service()->Init();
[email protected]e636c812013-09-23 05:51:083185
[email protected]5fdfa562013-12-27 17:43:593186 const extensions::ExtensionSet& enabled_extensions =
[email protected]f484f8d52014-06-12 08:38:183187 registry()->enabled_extensions();
[email protected]5fdfa562013-12-27 17:43:593188 const extensions::ExtensionSet& blacklisted_extensions =
[email protected]f484f8d52014-06-12 08:38:183189 registry()->blacklisted_extensions();
[email protected]e636c812013-09-23 05:51:083190
[email protected]5fdfa562013-12-27 17:43:593191 EXPECT_TRUE(enabled_extensions.Contains(good0) &&
3192 !blacklisted_extensions.Contains(good0));
3193 EXPECT_TRUE(enabled_extensions.Contains(good1) &&
3194 !blacklisted_extensions.Contains(good1));
3195 EXPECT_TRUE(enabled_extensions.Contains(good2) &&
3196 !blacklisted_extensions.Contains(good2));
[email protected]e636c812013-09-23 05:51:083197
[email protected]3f2a2fa2013-09-24 02:55:253198 EXPECT_FALSE(IsPrefExist(good0, "blacklist"));
[email protected]e636c812013-09-23 05:51:083199 EXPECT_FALSE(IsPrefExist(good1, "blacklist"));
[email protected]3f2a2fa2013-09-24 02:55:253200 EXPECT_FALSE(IsPrefExist(good2, "blacklist"));
3201 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist"));
3202
3203 // Blacklist good0 and good1 (and an invalid extension ID).
[email protected]f71b582c2014-01-10 17:03:153204 test_blacklist.SetBlacklistState(
3205 good0, extensions::BLACKLISTED_MALWARE, true);
3206 test_blacklist.SetBlacklistState(
3207 good1, extensions::BLACKLISTED_MALWARE, true);
3208 test_blacklist.SetBlacklistState(
3209 "invalid_id", extensions::BLACKLISTED_MALWARE, true);
[email protected]3f2a2fa2013-09-24 02:55:253210 base::RunLoop().RunUntilIdle();
3211
[email protected]5fdfa562013-12-27 17:43:593212 EXPECT_TRUE(!enabled_extensions.Contains(good0) &&
3213 blacklisted_extensions.Contains(good0));
3214 EXPECT_TRUE(!enabled_extensions.Contains(good1) &&
3215 blacklisted_extensions.Contains(good1));
3216 EXPECT_TRUE(enabled_extensions.Contains(good2) &&
3217 !blacklisted_extensions.Contains(good2));
[email protected]3f2a2fa2013-09-24 02:55:253218
3219 EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true));
3220 EXPECT_TRUE(ValidateBooleanPref(good1, "blacklist", true));
3221 EXPECT_FALSE(IsPrefExist(good2, "blacklist"));
3222 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist"));
3223
3224 // Un-blacklist good1 and blacklist good2.
[email protected]f71b582c2014-01-10 17:03:153225 test_blacklist.Clear(false);
3226 test_blacklist.SetBlacklistState(
3227 good0, extensions::BLACKLISTED_MALWARE, true);
3228 test_blacklist.SetBlacklistState(
3229 good2, extensions::BLACKLISTED_MALWARE, true);
3230 test_blacklist.SetBlacklistState(
3231 "invalid_id", extensions::BLACKLISTED_MALWARE, true);
[email protected]3f2a2fa2013-09-24 02:55:253232 base::RunLoop().RunUntilIdle();
3233
[email protected]5fdfa562013-12-27 17:43:593234 EXPECT_TRUE(!enabled_extensions.Contains(good0) &&
3235 blacklisted_extensions.Contains(good0));
3236 EXPECT_TRUE(enabled_extensions.Contains(good1) &&
3237 !blacklisted_extensions.Contains(good1));
3238 EXPECT_TRUE(!enabled_extensions.Contains(good2) &&
3239 blacklisted_extensions.Contains(good2));
[email protected]3f2a2fa2013-09-24 02:55:253240
3241 EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true));
3242 EXPECT_FALSE(IsPrefExist(good1, "blacklist"));
3243 EXPECT_TRUE(ValidateBooleanPref(good2, "blacklist", true));
[email protected]e2194742010-08-12 05:54:343244 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist"));
[email protected]6b75ec32009-08-14 06:37:183245}
[email protected]3f2a2fa2013-09-24 02:55:253246#endif // defined(ENABLE_BLACKLIST_TESTS)
[email protected]6b75ec32009-08-14 06:37:183247
[email protected]3f2a2fa2013-09-24 02:55:253248#if defined(ENABLE_BLACKLIST_TESTS)
3249// Tests trying to install a blacklisted extension.
[email protected]e0cbfc42013-11-07 00:10:103250TEST_F(ExtensionServiceTest, BlacklistedExtensionWillNotInstall) {
[email protected]3f2a2fa2013-09-24 02:55:253251 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db(
3252 new FakeSafeBrowsingDatabaseManager(true));
3253 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db);
3254
[email protected]1747eac02013-09-23 10:58:423255 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:183256 service()->Init();
[email protected]1747eac02013-09-23 10:58:423257
[email protected]3f2a2fa2013-09-24 02:55:253258 // After blacklisting good_crx, we cannot install it.
3259 blacklist_db->SetUnsafe(good_crx).NotifyUpdate();
3260 base::RunLoop().RunUntilIdle();
[email protected]1747eac02013-09-23 10:58:423261
[email protected]f484f8d52014-06-12 08:38:183262 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]9f3c8532013-07-31 19:52:073263 // HACK: specify WAS_INSTALLED_BY_DEFAULT so that test machinery doesn't
3264 // decide to install this silently. Somebody should fix these tests, all
3265 // 6,000 lines of them. Hah!
3266 InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT);
[email protected]f484f8d52014-06-12 08:38:183267 EXPECT_EQ(0u, registry()->enabled_extensions().size());
[email protected]6b75ec32009-08-14 06:37:183268}
[email protected]3f2a2fa2013-09-24 02:55:253269#endif // defined(ENABLE_BLACKLIST_TESTS)
[email protected]6b75ec32009-08-14 06:37:183270
[email protected]3f2a2fa2013-09-24 02:55:253271#if defined(ENABLE_BLACKLIST_TESTS)
[email protected]4ee07c62012-08-21 12:40:423272// Unload blacklisted extension on policy change.
[email protected]d9a61e12012-11-14 02:43:473273TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) {
[email protected]f71b582c2014-01-10 17:03:153274 extensions::TestBlacklist test_blacklist;
[email protected]3f2a2fa2013-09-24 02:55:253275
3276 // A profile with no extensions installed.
[email protected]4ee07c62012-08-21 12:40:423277 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:183278 test_blacklist.Attach(service()->blacklist_);
[email protected]3f2a2fa2013-09-24 02:55:253279
[email protected]f484f8d52014-06-12 08:38:183280 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]4ee07c62012-08-21 12:40:423281
3282 const Extension* good = InstallCRX(path, INSTALL_NEW);
3283 EXPECT_EQ(good_crx, good->id());
3284 UpdateExtension(good_crx, path, FAILED_SILENTLY);
[email protected]f484f8d52014-06-12 08:38:183285 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]4ee07c62012-08-21 12:40:423286
3287 base::ListValue whitelist;
[email protected]f484f8d52014-06-12 08:38:183288 PrefService* prefs = ExtensionPrefs::Get(profile())->pref_service();
[email protected]aa15e2e2013-08-14 02:13:583289 whitelist.Append(new base::StringValue(good_crx));
[email protected]234fc5ff2014-01-16 23:32:283290 prefs->Set(extensions::pref_names::kInstallAllowList, whitelist);
[email protected]4ee07c62012-08-21 12:40:423291
[email protected]f71b582c2014-01-10 17:03:153292 test_blacklist.SetBlacklistState(
3293 good_crx, extensions::BLACKLISTED_MALWARE, true);
[email protected]eedc1c752013-08-09 18:51:553294 base::RunLoop().RunUntilIdle();
[email protected]4ee07c62012-08-21 12:40:423295
[email protected]695b5712012-12-06 23:55:283296 // The good_crx is blacklisted and the whitelist doesn't negate it.
[email protected]3f2a2fa2013-09-24 02:55:253297 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true));
[email protected]f484f8d52014-06-12 08:38:183298 EXPECT_EQ(0u, registry()->enabled_extensions().size());
[email protected]4ee07c62012-08-21 12:40:423299}
[email protected]3f2a2fa2013-09-24 02:55:253300#endif // defined(ENABLE_BLACKLIST_TESTS)
[email protected]4ee07c62012-08-21 12:40:423301
[email protected]3f2a2fa2013-09-24 02:55:253302#if defined(ENABLE_BLACKLIST_TESTS)
3303// Tests that a blacklisted extension is eventually unloaded on startup, if it
3304// wasn't already.
[email protected]e0cbfc42013-11-07 00:10:103305TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) {
[email protected]f71b582c2014-01-10 17:03:153306 extensions::TestBlacklist test_blacklist;
[email protected]6b75ec32009-08-14 06:37:183307
[email protected]3f2a2fa2013-09-24 02:55:253308 // A profile with 3 extensions installed: good0, good1, and good2.
3309 InitializeGoodInstalledExtensionService();
[email protected]f484f8d52014-06-12 08:38:183310 test_blacklist.Attach(service()->blacklist_);
[email protected]fdd679b2012-11-15 20:49:393311
[email protected]3f2a2fa2013-09-24 02:55:253312 // Blacklist good1 before the service initializes.
[email protected]f71b582c2014-01-10 17:03:153313 test_blacklist.SetBlacklistState(
3314 good1, extensions::BLACKLISTED_MALWARE, false);
[email protected]6b75ec32009-08-14 06:37:183315
3316 // Load extensions.
[email protected]f484f8d52014-06-12 08:38:183317 service()->Init();
[email protected]3f2a2fa2013-09-24 02:55:253318 ASSERT_EQ(3u, loaded_.size()); // hasn't had time to blacklist yet
[email protected]6b75ec32009-08-14 06:37:183319
[email protected]3f2a2fa2013-09-24 02:55:253320 base::RunLoop().RunUntilIdle();
[email protected]6b75ec32009-08-14 06:37:183321
[email protected]f484f8d52014-06-12 08:38:183322 ASSERT_EQ(1u, registry()->blacklisted_extensions().size());
3323 ASSERT_EQ(2u, registry()->enabled_extensions().size());
[email protected]5fdfa562013-12-27 17:43:593324
[email protected]f484f8d52014-06-12 08:38:183325 ASSERT_TRUE(registry()->enabled_extensions().Contains(good0));
3326 ASSERT_TRUE(registry()->blacklisted_extensions().Contains(good1));
3327 ASSERT_TRUE(registry()->enabled_extensions().Contains(good2));
[email protected]6b75ec32009-08-14 06:37:183328}
[email protected]3f2a2fa2013-09-24 02:55:253329#endif // defined(ENABLE_BLACKLIST_TESTS)
3330
3331#if defined(ENABLE_BLACKLIST_TESTS)
3332// Tests extensions blacklisted in prefs on startup; one still blacklisted by
3333// safe browsing, the other not. The not-blacklisted one should recover.
3334TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) {
[email protected]f71b582c2014-01-10 17:03:153335 extensions::TestBlacklist test_blacklist;
[email protected]3f2a2fa2013-09-24 02:55:253336
3337 InitializeGoodInstalledExtensionService();
[email protected]f484f8d52014-06-12 08:38:183338 test_blacklist.Attach(service()->blacklist_);
3339 ExtensionPrefs::Get(profile())->SetExtensionBlacklisted(good0, true);
3340 ExtensionPrefs::Get(profile())->SetExtensionBlacklisted(good1, true);
[email protected]3f2a2fa2013-09-24 02:55:253341
[email protected]f71b582c2014-01-10 17:03:153342 test_blacklist.SetBlacklistState(
3343 good1, extensions::BLACKLISTED_MALWARE, false);
[email protected]3f2a2fa2013-09-24 02:55:253344
[email protected]27e528322014-05-27 20:54:303345 // Extension service hasn't loaded yet, but IsExtensionEnabled reads out of
3346 // prefs. Ensure it takes into account the blacklist state (crbug.com/373842).
[email protected]f484f8d52014-06-12 08:38:183347 EXPECT_FALSE(service()->IsExtensionEnabled(good0));
3348 EXPECT_FALSE(service()->IsExtensionEnabled(good1));
3349 EXPECT_TRUE(service()->IsExtensionEnabled(good2));
[email protected]27e528322014-05-27 20:54:303350
[email protected]f484f8d52014-06-12 08:38:183351 service()->Init();
[email protected]3f2a2fa2013-09-24 02:55:253352
[email protected]f484f8d52014-06-12 08:38:183353 EXPECT_EQ(2u, registry()->blacklisted_extensions().size());
3354 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]3f2a2fa2013-09-24 02:55:253355
[email protected]f484f8d52014-06-12 08:38:183356 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good0));
3357 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good1));
3358 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
[email protected]3f2a2fa2013-09-24 02:55:253359
3360 // Give time for the blacklist to update.
3361 base::RunLoop().RunUntilIdle();
3362
[email protected]f484f8d52014-06-12 08:38:183363 EXPECT_EQ(1u, registry()->blacklisted_extensions().size());
3364 EXPECT_EQ(2u, registry()->enabled_extensions().size());
[email protected]3f2a2fa2013-09-24 02:55:253365
[email protected]f484f8d52014-06-12 08:38:183366 EXPECT_TRUE(registry()->enabled_extensions().Contains(good0));
3367 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(good1));
3368 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
[email protected]3f2a2fa2013-09-24 02:55:253369}
3370#endif // defined(ENABLE_BLACKLIST_TESTS)
[email protected]6b75ec32009-08-14 06:37:183371
[email protected]2d19eb6e2014-01-27 17:30:003372#if defined(ENABLE_BLACKLIST_TESTS)
3373// Extension is added to blacklist with BLACKLISTED_POTENTIALLY_UNWANTED state
3374// after it is installed. It is then successfully re-enabled by the user.
3375TEST_F(ExtensionServiceTest, GreylistedExtensionDisabled) {
3376 extensions::TestBlacklist test_blacklist;
3377 // A profile with 3 extensions installed: good0, good1, and good2.
3378 InitializeGoodInstalledExtensionService();
[email protected]f484f8d52014-06-12 08:38:183379 test_blacklist.Attach(service()->blacklist_);
3380 service()->Init();
[email protected]2d19eb6e2014-01-27 17:30:003381
[email protected]2d19eb6e2014-01-27 17:30:003382 const extensions::ExtensionSet& enabled_extensions =
[email protected]f484f8d52014-06-12 08:38:183383 registry()->enabled_extensions();
[email protected]2d19eb6e2014-01-27 17:30:003384 const extensions::ExtensionSet& disabled_extensions =
[email protected]f484f8d52014-06-12 08:38:183385 registry()->disabled_extensions();
[email protected]2d19eb6e2014-01-27 17:30:003386
3387 EXPECT_TRUE(enabled_extensions.Contains(good0));
3388 EXPECT_TRUE(enabled_extensions.Contains(good1));
3389 EXPECT_TRUE(enabled_extensions.Contains(good2));
3390
3391 // Blacklist good0 and good1 (and an invalid extension ID).
3392 test_blacklist.SetBlacklistState(
3393 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true);
3394 test_blacklist.SetBlacklistState(
3395 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true);
3396 test_blacklist.SetBlacklistState(
3397 "invalid_id", extensions::BLACKLISTED_MALWARE, true);
3398 base::RunLoop().RunUntilIdle();
3399
3400 EXPECT_FALSE(enabled_extensions.Contains(good0));
3401 EXPECT_TRUE(disabled_extensions.Contains(good0));
3402 EXPECT_FALSE(enabled_extensions.Contains(good1));
3403 EXPECT_TRUE(disabled_extensions.Contains(good1));
3404 EXPECT_TRUE(enabled_extensions.Contains(good2));
3405 EXPECT_FALSE(disabled_extensions.Contains(good2));
3406
3407 ValidateIntegerPref(
3408 good0, "blacklist_state", extensions::BLACKLISTED_CWS_POLICY_VIOLATION);
3409 ValidateIntegerPref(
3410 good1, "blacklist_state", extensions::BLACKLISTED_POTENTIALLY_UNWANTED);
3411
3412 // Now user enables good0.
[email protected]f484f8d52014-06-12 08:38:183413 service()->EnableExtension(good0);
[email protected]2d19eb6e2014-01-27 17:30:003414
3415 EXPECT_TRUE(enabled_extensions.Contains(good0));
3416 EXPECT_FALSE(disabled_extensions.Contains(good0));
3417 EXPECT_FALSE(enabled_extensions.Contains(good1));
3418 EXPECT_TRUE(disabled_extensions.Contains(good1));
3419
3420 // Remove extensions from blacklist.
3421 test_blacklist.SetBlacklistState(
3422 good0, extensions::NOT_BLACKLISTED, true);
3423 test_blacklist.SetBlacklistState(
3424 good1, extensions::NOT_BLACKLISTED, true);
3425 base::RunLoop().RunUntilIdle();
3426
3427 // All extensions are enabled.
3428 EXPECT_TRUE(enabled_extensions.Contains(good0));
3429 EXPECT_FALSE(disabled_extensions.Contains(good0));
3430 EXPECT_TRUE(enabled_extensions.Contains(good1));
3431 EXPECT_FALSE(disabled_extensions.Contains(good1));
3432 EXPECT_TRUE(enabled_extensions.Contains(good2));
3433 EXPECT_FALSE(disabled_extensions.Contains(good2));
3434}
3435#endif // defined(ENABLE_BLACKLIST_TESTS)
3436
3437#if defined(ENABLE_BLACKLIST_TESTS)
3438// When extension is removed from greylist, do not re-enable it if it is
3439// disabled by user.
3440TEST_F(ExtensionServiceTest, GreylistDontEnableManuallyDisabled) {
3441 extensions::TestBlacklist test_blacklist;
3442 // A profile with 3 extensions installed: good0, good1, and good2.
3443 InitializeGoodInstalledExtensionService();
[email protected]f484f8d52014-06-12 08:38:183444 test_blacklist.Attach(service()->blacklist_);
3445 service()->Init();
[email protected]2d19eb6e2014-01-27 17:30:003446
[email protected]2d19eb6e2014-01-27 17:30:003447 const extensions::ExtensionSet& enabled_extensions =
[email protected]f484f8d52014-06-12 08:38:183448 registry()->enabled_extensions();
[email protected]2d19eb6e2014-01-27 17:30:003449 const extensions::ExtensionSet& disabled_extensions =
[email protected]f484f8d52014-06-12 08:38:183450 registry()->disabled_extensions();
[email protected]2d19eb6e2014-01-27 17:30:003451
3452 // Manually disable.
[email protected]f484f8d52014-06-12 08:38:183453 service()->DisableExtension(good0,
3454 extensions::Extension::DISABLE_USER_ACTION);
[email protected]2d19eb6e2014-01-27 17:30:003455
3456 test_blacklist.SetBlacklistState(
3457 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true);
3458 test_blacklist.SetBlacklistState(
3459 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true);
3460 test_blacklist.SetBlacklistState(
3461 good2, extensions::BLACKLISTED_SECURITY_VULNERABILITY, true);
3462 base::RunLoop().RunUntilIdle();
3463
3464 // All extensions disabled.
3465 EXPECT_FALSE(enabled_extensions.Contains(good0));
3466 EXPECT_TRUE(disabled_extensions.Contains(good0));
3467 EXPECT_FALSE(enabled_extensions.Contains(good1));
3468 EXPECT_TRUE(disabled_extensions.Contains(good1));
3469 EXPECT_FALSE(enabled_extensions.Contains(good2));
3470 EXPECT_TRUE(disabled_extensions.Contains(good2));
3471
3472 // Greylisted extension can be enabled.
[email protected]f484f8d52014-06-12 08:38:183473 service()->EnableExtension(good1);
[email protected]2d19eb6e2014-01-27 17:30:003474 EXPECT_TRUE(enabled_extensions.Contains(good1));
3475 EXPECT_FALSE(disabled_extensions.Contains(good1));
3476
3477 // good1 is now manually disabled.
[email protected]f484f8d52014-06-12 08:38:183478 service()->DisableExtension(good1,
3479 extensions::Extension::DISABLE_USER_ACTION);
[email protected]2d19eb6e2014-01-27 17:30:003480 EXPECT_FALSE(enabled_extensions.Contains(good1));
3481 EXPECT_TRUE(disabled_extensions.Contains(good1));
3482
3483 // Remove extensions from blacklist.
3484 test_blacklist.SetBlacklistState(
3485 good0, extensions::NOT_BLACKLISTED, true);
3486 test_blacklist.SetBlacklistState(
3487 good1, extensions::NOT_BLACKLISTED, true);
3488 test_blacklist.SetBlacklistState(
3489 good2, extensions::NOT_BLACKLISTED, true);
3490 base::RunLoop().RunUntilIdle();
3491
3492 // good0 and good1 remain disabled.
3493 EXPECT_FALSE(enabled_extensions.Contains(good0));
3494 EXPECT_TRUE(disabled_extensions.Contains(good0));
3495 EXPECT_FALSE(enabled_extensions.Contains(good1));
3496 EXPECT_TRUE(disabled_extensions.Contains(good1));
3497 EXPECT_TRUE(enabled_extensions.Contains(good2));
3498 EXPECT_FALSE(disabled_extensions.Contains(good2));
3499}
3500#endif // defined(ENABLE_BLACKLIST_TESTS)
3501
3502#if defined(ENABLE_BLACKLIST_TESTS)
3503// Blacklisted extension with unknown state are not enabled/disabled.
3504TEST_F(ExtensionServiceTest, GreylistUnknownDontChange) {
3505 extensions::TestBlacklist test_blacklist;
3506 // A profile with 3 extensions installed: good0, good1, and good2.
3507 InitializeGoodInstalledExtensionService();
[email protected]f484f8d52014-06-12 08:38:183508 test_blacklist.Attach(service()->blacklist_);
3509 service()->Init();
[email protected]2d19eb6e2014-01-27 17:30:003510
[email protected]2d19eb6e2014-01-27 17:30:003511 const extensions::ExtensionSet& enabled_extensions =
[email protected]f484f8d52014-06-12 08:38:183512 registry()->enabled_extensions();
[email protected]2d19eb6e2014-01-27 17:30:003513 const extensions::ExtensionSet& disabled_extensions =
[email protected]f484f8d52014-06-12 08:38:183514 registry()->disabled_extensions();
[email protected]2d19eb6e2014-01-27 17:30:003515
3516 test_blacklist.SetBlacklistState(
3517 good0, extensions::BLACKLISTED_CWS_POLICY_VIOLATION, true);
3518 test_blacklist.SetBlacklistState(
3519 good1, extensions::BLACKLISTED_POTENTIALLY_UNWANTED, true);
3520 base::RunLoop().RunUntilIdle();
3521
3522 EXPECT_FALSE(enabled_extensions.Contains(good0));
3523 EXPECT_TRUE(disabled_extensions.Contains(good0));
3524 EXPECT_FALSE(enabled_extensions.Contains(good1));
3525 EXPECT_TRUE(disabled_extensions.Contains(good1));
3526 EXPECT_TRUE(enabled_extensions.Contains(good2));
3527 EXPECT_FALSE(disabled_extensions.Contains(good2));
3528
3529 test_blacklist.SetBlacklistState(
3530 good0, extensions::NOT_BLACKLISTED, true);
3531 test_blacklist.SetBlacklistState(
3532 good1, extensions::BLACKLISTED_UNKNOWN, true);
3533 test_blacklist.SetBlacklistState(
3534 good2, extensions::BLACKLISTED_UNKNOWN, true);
3535 base::RunLoop().RunUntilIdle();
3536
3537 // good0 re-enabled, other remain as they were.
3538 EXPECT_TRUE(enabled_extensions.Contains(good0));
3539 EXPECT_FALSE(disabled_extensions.Contains(good0));
3540 EXPECT_FALSE(enabled_extensions.Contains(good1));
3541 EXPECT_TRUE(disabled_extensions.Contains(good1));
3542 EXPECT_TRUE(enabled_extensions.Contains(good2));
3543 EXPECT_FALSE(disabled_extensions.Contains(good2));
3544}
[email protected]757d60a2014-05-23 00:11:443545
3546// Tests that blacklisted extensions cannot be reloaded, both those loaded
3547// before and after extension service startup.
3548TEST_F(ExtensionServiceTest, ReloadBlacklistedExtension) {
3549 extensions::TestBlacklist test_blacklist;
3550
3551 InitializeGoodInstalledExtensionService();
[email protected]f484f8d52014-06-12 08:38:183552 test_blacklist.Attach(service()->blacklist_);
[email protected]757d60a2014-05-23 00:11:443553
3554 test_blacklist.SetBlacklistState(
3555 good1, extensions::BLACKLISTED_MALWARE, false);
[email protected]f484f8d52014-06-12 08:38:183556 service()->Init();
[email protected]757d60a2014-05-23 00:11:443557 test_blacklist.SetBlacklistState(
3558 good2, extensions::BLACKLISTED_MALWARE, false);
3559 base::RunLoop().RunUntilIdle();
3560
[email protected]f484f8d52014-06-12 08:38:183561 EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs());
[email protected]757d60a2014-05-23 00:11:443562 EXPECT_EQ(StringSet(good1, good2),
[email protected]f484f8d52014-06-12 08:38:183563 registry()->blacklisted_extensions().GetIDs());
[email protected]757d60a2014-05-23 00:11:443564
[email protected]f484f8d52014-06-12 08:38:183565 service()->ReloadExtension(good1);
3566 service()->ReloadExtension(good2);
[email protected]757d60a2014-05-23 00:11:443567 base::RunLoop().RunUntilIdle();
3568
[email protected]f484f8d52014-06-12 08:38:183569 EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs());
[email protected]757d60a2014-05-23 00:11:443570 EXPECT_EQ(StringSet(good1, good2),
[email protected]f484f8d52014-06-12 08:38:183571 registry()->blacklisted_extensions().GetIDs());
[email protected]757d60a2014-05-23 00:11:443572}
3573
[email protected]2d19eb6e2014-01-27 17:30:003574#endif // defined(ENABLE_BLACKLIST_TESTS)
3575
[email protected]306a2bd2010-08-11 14:56:363576// Will not install extension blacklisted by policy.
[email protected]d9a61e12012-11-14 02:43:473577TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) {
[email protected]eaa7dd182010-12-14 11:09:003578 InitializeEmptyExtensionService();
[email protected]306a2bd2010-08-11 14:56:363579
[email protected]306a2bd2010-08-11 14:56:363580 // Blacklist everything.
[email protected]43d3bf82011-04-11 07:46:583581 {
[email protected]f484f8d52014-06-12 08:38:183582 ListPrefUpdate update(profile()->GetPrefs(),
[email protected]234fc5ff2014-01-16 23:32:283583 extensions::pref_names::kInstallDenyList);
[email protected]023b3d12013-12-23 18:46:493584 base::ListValue* blacklist = update.Get();
[email protected]aa15e2e2013-08-14 02:13:583585 blacklist->Append(new base::StringValue("*"));
[email protected]43d3bf82011-04-11 07:46:583586 }
[email protected]306a2bd2010-08-11 14:56:363587
3588 // Blacklist prevents us from installing good_crx.
[email protected]f484f8d52014-06-12 08:38:183589 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:503590 InstallCRX(path, INSTALL_FAILED);
[email protected]f484f8d52014-06-12 08:38:183591 EXPECT_EQ(0u, registry()->enabled_extensions().size());
[email protected]306a2bd2010-08-11 14:56:363592
3593 // Now whitelist this particular extension.
[email protected]43d3bf82011-04-11 07:46:583594 {
[email protected]f484f8d52014-06-12 08:38:183595 ListPrefUpdate update(profile()->GetPrefs(),
[email protected]234fc5ff2014-01-16 23:32:283596 extensions::pref_names::kInstallAllowList);
[email protected]023b3d12013-12-23 18:46:493597 base::ListValue* whitelist = update.Get();
[email protected]aa15e2e2013-08-14 02:13:583598 whitelist->Append(new base::StringValue(good_crx));
[email protected]43d3bf82011-04-11 07:46:583599 }
3600
[email protected]306a2bd2010-08-11 14:56:363601 // Ensure we can now install good_crx.
[email protected]8f512c72011-11-22 21:02:503602 InstallCRX(path, INSTALL_NEW);
[email protected]f484f8d52014-06-12 08:38:183603 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]306a2bd2010-08-11 14:56:363604}
3605
[email protected]aa96d3a2010-08-21 08:45:253606// Extension blacklisted by policy get unloaded after installing.
[email protected]d9a61e12012-11-14 02:43:473607TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) {
[email protected]eaa7dd182010-12-14 11:09:003608 InitializeEmptyExtensionService();
[email protected]aa96d3a2010-08-21 08:45:253609
3610 // Install good_crx.
[email protected]f484f8d52014-06-12 08:38:183611 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:503612 InstallCRX(path, INSTALL_NEW);
[email protected]f484f8d52014-06-12 08:38:183613 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]aa96d3a2010-08-21 08:45:253614
[email protected]acd78969c2010-12-08 09:49:113615 { // Scope for pref update notification.
[email protected]f484f8d52014-06-12 08:38:183616 PrefService* prefs = profile()->GetPrefs();
[email protected]234fc5ff2014-01-16 23:32:283617 ListPrefUpdate update(prefs, extensions::pref_names::kInstallDenyList);
[email protected]023b3d12013-12-23 18:46:493618 base::ListValue* blacklist = update.Get();
[email protected]acd78969c2010-12-08 09:49:113619 ASSERT_TRUE(blacklist != NULL);
[email protected]aa96d3a2010-08-21 08:45:253620
[email protected]acd78969c2010-12-08 09:49:113621 // Blacklist this extension.
[email protected]aa15e2e2013-08-14 02:13:583622 blacklist->Append(new base::StringValue(good_crx));
[email protected]acd78969c2010-12-08 09:49:113623 }
[email protected]aa96d3a2010-08-21 08:45:253624
3625 // Extension should not be running now.
[email protected]eedc1c752013-08-09 18:51:553626 base::RunLoop().RunUntilIdle();
[email protected]f484f8d52014-06-12 08:38:183627 EXPECT_EQ(0u, registry()->enabled_extensions().size());
[email protected]aa96d3a2010-08-21 08:45:253628}
3629
[email protected]05aad2da2011-10-28 10:12:373630// Tests that component extensions are not blacklisted by policy.
[email protected]d9a61e12012-11-14 02:43:473631TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) {
[email protected]05aad2da2011-10-28 10:12:373632 InitializeEmptyExtensionService();
3633
3634 // Blacklist everything.
3635 {
[email protected]f484f8d52014-06-12 08:38:183636 ListPrefUpdate update(profile()->GetPrefs(),
[email protected]234fc5ff2014-01-16 23:32:283637 extensions::pref_names::kInstallDenyList);
[email protected]023b3d12013-12-23 18:46:493638 base::ListValue* blacklist = update.Get();
[email protected]aa15e2e2013-08-14 02:13:583639 blacklist->Append(new base::StringValue("*"));
[email protected]05aad2da2011-10-28 10:12:373640 }
3641
3642 // Install a component extension.
[email protected]f484f8d52014-06-12 08:38:183643 base::FilePath path = data_dir()
3644 .AppendASCII("good")
3645 .AppendASCII("Extensions")
3646 .AppendASCII(good0)
3647 .AppendASCII("1.0.0.0");
[email protected]05aad2da2011-10-28 10:12:373648 std::string manifest;
[email protected]82f84b92013-08-30 18:23:503649 ASSERT_TRUE(base::ReadFileToString(
[email protected]993da5e2013-03-23 21:25:163650 path.Append(extensions::kManifestFilename), &manifest));
[email protected]f484f8d52014-06-12 08:38:183651 service()->component_loader()->Add(manifest, path);
3652 service()->Init();
[email protected]05aad2da2011-10-28 10:12:373653
3654 // Extension should be installed despite blacklist.
[email protected]f484f8d52014-06-12 08:38:183655 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3656 EXPECT_TRUE(service()->GetExtensionById(good0, false));
[email protected]05aad2da2011-10-28 10:12:373657
3658 // Poke external providers and make sure the extension is still present.
[email protected]f484f8d52014-06-12 08:38:183659 service()->CheckForExternalUpdates();
3660 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3661 EXPECT_TRUE(service()->GetExtensionById(good0, false));
[email protected]05aad2da2011-10-28 10:12:373662
3663 // Extension should not be uninstalled on blacklist changes.
3664 {
[email protected]f484f8d52014-06-12 08:38:183665 ListPrefUpdate update(profile()->GetPrefs(),
[email protected]234fc5ff2014-01-16 23:32:283666 extensions::pref_names::kInstallDenyList);
[email protected]023b3d12013-12-23 18:46:493667 base::ListValue* blacklist = update.Get();
[email protected]aa15e2e2013-08-14 02:13:583668 blacklist->Append(new base::StringValue(good0));
[email protected]05aad2da2011-10-28 10:12:373669 }
[email protected]eedc1c752013-08-09 18:51:553670 base::RunLoop().RunUntilIdle();
[email protected]f484f8d52014-06-12 08:38:183671 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3672 EXPECT_TRUE(service()->GetExtensionById(good0, false));
[email protected]05aad2da2011-10-28 10:12:373673}
3674
3675// Tests that policy-installed extensions are not blacklisted by policy.
[email protected]d9a61e12012-11-14 02:43:473676TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) {
[email protected]05aad2da2011-10-28 10:12:373677 InitializeEmptyExtensionService();
3678
[email protected]05aad2da2011-10-28 10:12:373679 {
[email protected]e410b5f2012-12-14 14:02:243680 // Blacklist everything.
[email protected]f484f8d52014-06-12 08:38:183681 ListPrefUpdate blacklist_update(profile()->GetPrefs(),
3682 extensions::pref_names::kInstallDenyList);
[email protected]023b3d12013-12-23 18:46:493683 base::ListValue* blacklist = blacklist_update.Get();
[email protected]e410b5f2012-12-14 14:02:243684 blacklist->AppendString("*");
3685
3686 // Mark good.crx for force-installation.
[email protected]234fc5ff2014-01-16 23:32:283687 DictionaryPrefUpdate forcelist_update(
[email protected]f484f8d52014-06-12 08:38:183688 profile()->GetPrefs(), extensions::pref_names::kInstallForceList);
[email protected]e410b5f2012-12-14 14:02:243689 extensions::ExternalPolicyLoader::AddExtension(
3690 forcelist_update.Get(), good_crx, "http://example.com/update_url");
[email protected]05aad2da2011-10-28 10:12:373691 }
3692
3693 // Have policy force-install an extension.
3694 MockExtensionProvider* provider =
[email protected]f484f8d52014-06-12 08:38:183695 new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
[email protected]05aad2da2011-10-28 10:12:373696 AddMockExternalProvider(provider);
[email protected]f484f8d52014-06-12 08:38:183697 provider->UpdateOrAddExtension(
3698 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
[email protected]05aad2da2011-10-28 10:12:373699
3700 // Reloading extensions should find our externally registered extension
3701 // and install it.
[email protected]97d6a5c2013-11-11 23:51:243702 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:063703 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:243704 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:183705 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:243706 observer.Wait();
[email protected]05aad2da2011-10-28 10:12:373707
3708 // Extension should be installed despite blacklist.
[email protected]f484f8d52014-06-12 08:38:183709 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3710 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
[email protected]05aad2da2011-10-28 10:12:373711
3712 // Blacklist update should not uninstall the extension.
3713 {
[email protected]f484f8d52014-06-12 08:38:183714 ListPrefUpdate update(profile()->GetPrefs(),
[email protected]234fc5ff2014-01-16 23:32:283715 extensions::pref_names::kInstallDenyList);
[email protected]023b3d12013-12-23 18:46:493716 base::ListValue* blacklist = update.Get();
[email protected]aa15e2e2013-08-14 02:13:583717 blacklist->Append(new base::StringValue(good0));
[email protected]05aad2da2011-10-28 10:12:373718 }
[email protected]eedc1c752013-08-09 18:51:553719 base::RunLoop().RunUntilIdle();
[email protected]f484f8d52014-06-12 08:38:183720 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3721 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
[email protected]05aad2da2011-10-28 10:12:373722}
3723
[email protected]65187152012-06-02 13:14:143724// Tests that extensions cannot be installed if the policy provider prohibits
3725// it. This functionality is implemented in CrxInstaller::ConfirmInstall().
[email protected]d9a61e12012-11-14 02:43:473726TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) {
[email protected]65187152012-06-02 13:14:143727 InitializeEmptyExtensionService();
3728
[email protected]f484f8d52014-06-12 08:38:183729 GetManagementPolicy()->UnregisterAllProviders();
[email protected]65187152012-06-02 13:14:143730 extensions::TestManagementPolicyProvider provider_(
3731 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
[email protected]f484f8d52014-06-12 08:38:183732 GetManagementPolicy()->RegisterProvider(&provider_);
[email protected]65187152012-06-02 13:14:143733
[email protected]f484f8d52014-06-12 08:38:183734 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_FAILED);
3735 EXPECT_EQ(0u, registry()->enabled_extensions().size());
[email protected]65187152012-06-02 13:14:143736}
3737
3738// Tests that extensions cannot be loaded from prefs if the policy provider
3739// prohibits it. This functionality is implemented in InstalledLoader::Load().
[email protected]d9a61e12012-11-14 02:43:473740TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) {
[email protected]65187152012-06-02 13:14:143741 InitializeEmptyExtensionService();
3742
3743 // Create a fake extension to be loaded as though it were read from prefs.
[email protected]f484f8d52014-06-12 08:38:183744 base::FilePath path =
3745 data_dir().AppendASCII("management").AppendASCII("simple_extension");
[email protected]023b3d12013-12-23 18:46:493746 base::DictionaryValue manifest;
[email protected]65187152012-06-02 13:14:143747 manifest.SetString(keys::kName, "simple_extension");
3748 manifest.SetString(keys::kVersion, "1");
[email protected]12075d12013-02-27 05:38:053749 // UNPACKED is for extensions loaded from a directory. We use it here, even
[email protected]65187152012-06-02 13:14:143750 // though we're testing loading from prefs, so that we don't need to provide
3751 // an extension key.
[email protected]007b3f82013-04-09 08:46:453752 extensions::ExtensionInfo extension_info(
3753 &manifest, std::string(), path, Manifest::UNPACKED);
[email protected]65187152012-06-02 13:14:143754
3755 // Ensure we can load it with no management policy in place.
[email protected]f484f8d52014-06-12 08:38:183756 GetManagementPolicy()->UnregisterAllProviders();
3757 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3758 extensions::InstalledLoader(service()).Load(extension_info, false);
3759 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]65187152012-06-02 13:14:143760
[email protected]f484f8d52014-06-12 08:38:183761 const Extension* extension =
3762 (registry()->enabled_extensions().begin())->get();
[email protected]42d58f62014-07-31 01:32:453763 EXPECT_TRUE(
3764 service()->UninstallExtension(extension->id(),
3765 extensions::UNINSTALL_REASON_FOR_TESTING,
3766 base::Bind(&base::DoNothing),
3767 NULL));
[email protected]f484f8d52014-06-12 08:38:183768 EXPECT_EQ(0u, registry()->enabled_extensions().size());
[email protected]65187152012-06-02 13:14:143769
3770 // Ensure we cannot load it if management policy prohibits installation.
3771 extensions::TestManagementPolicyProvider provider_(
3772 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
[email protected]f484f8d52014-06-12 08:38:183773 GetManagementPolicy()->RegisterProvider(&provider_);
[email protected]65187152012-06-02 13:14:143774
[email protected]f484f8d52014-06-12 08:38:183775 extensions::InstalledLoader(service()).Load(extension_info, false);
3776 EXPECT_EQ(0u, registry()->enabled_extensions().size());
[email protected]65187152012-06-02 13:14:143777}
3778
3779// Tests disabling an extension when prohibited by the ManagementPolicy.
[email protected]d9a61e12012-11-14 02:43:473780TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) {
[email protected]65187152012-06-02 13:14:143781 InitializeEmptyExtensionService();
3782
[email protected]f484f8d52014-06-12 08:38:183783 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3784 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3785 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]65187152012-06-02 13:14:143786
[email protected]f484f8d52014-06-12 08:38:183787 GetManagementPolicy()->UnregisterAllProviders();
[email protected]65187152012-06-02 13:14:143788 extensions::TestManagementPolicyProvider provider(
3789 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
[email protected]f484f8d52014-06-12 08:38:183790 GetManagementPolicy()->RegisterProvider(&provider);
[email protected]65187152012-06-02 13:14:143791
3792 // Attempt to disable it.
[email protected]f484f8d52014-06-12 08:38:183793 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
[email protected]65187152012-06-02 13:14:143794
[email protected]f484f8d52014-06-12 08:38:183795 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3796 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3797 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]65187152012-06-02 13:14:143798}
3799
3800// Tests uninstalling an extension when prohibited by the ManagementPolicy.
[email protected]d9a61e12012-11-14 02:43:473801TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) {
[email protected]65187152012-06-02 13:14:143802 InitializeEmptyExtensionService();
3803
[email protected]f484f8d52014-06-12 08:38:183804 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3805 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3806 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]65187152012-06-02 13:14:143807
[email protected]f484f8d52014-06-12 08:38:183808 GetManagementPolicy()->UnregisterAllProviders();
[email protected]65187152012-06-02 13:14:143809 extensions::TestManagementPolicyProvider provider(
3810 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
[email protected]f484f8d52014-06-12 08:38:183811 GetManagementPolicy()->RegisterProvider(&provider);
[email protected]65187152012-06-02 13:14:143812
3813 // Attempt to uninstall it.
[email protected]42d58f62014-07-31 01:32:453814 EXPECT_FALSE(
3815 service()->UninstallExtension(good_crx,
3816 extensions::UNINSTALL_REASON_FOR_TESTING,
3817 base::Bind(&base::DoNothing),
3818 NULL));
[email protected]65187152012-06-02 13:14:143819
[email protected]f484f8d52014-06-12 08:38:183820 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3821 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
[email protected]65187152012-06-02 13:14:143822}
3823
3824// Tests that previously installed extensions that are now prohibited from
3825// being installed are removed.
[email protected]d9a61e12012-11-14 02:43:473826TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) {
[email protected]65187152012-06-02 13:14:143827 InitializeEmptyExtensionService();
3828
[email protected]f484f8d52014-06-12 08:38:183829 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3830 InstallCRX(data_dir().AppendASCII("page_action.crx"), INSTALL_NEW);
3831 EXPECT_EQ(2u, registry()->enabled_extensions().size());
3832 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]65187152012-06-02 13:14:143833
[email protected]f484f8d52014-06-12 08:38:183834 GetManagementPolicy()->UnregisterAllProviders();
[email protected]65187152012-06-02 13:14:143835 extensions::TestManagementPolicyProvider provider(
3836 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
[email protected]f484f8d52014-06-12 08:38:183837 GetManagementPolicy()->RegisterProvider(&provider);
[email protected]65187152012-06-02 13:14:143838
3839 // Run the policy check.
[email protected]f484f8d52014-06-12 08:38:183840 service()->CheckManagementPolicy();
3841 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3842 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]65187152012-06-02 13:14:143843}
3844
3845// Tests that previously disabled extensions that are now required to be
3846// enabled are re-enabled on reinstall.
[email protected]d9a61e12012-11-14 02:43:473847TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) {
[email protected]65187152012-06-02 13:14:143848 InitializeEmptyExtensionService();
3849
3850 // Install, then disable, an extension.
[email protected]f484f8d52014-06-12 08:38:183851 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3852 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3853 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
3854 EXPECT_EQ(1u, registry()->disabled_extensions().size());
[email protected]65187152012-06-02 13:14:143855
3856 // Register an ExtensionMnagementPolicy that requires the extension to remain
3857 // enabled.
[email protected]f484f8d52014-06-12 08:38:183858 GetManagementPolicy()->UnregisterAllProviders();
[email protected]65187152012-06-02 13:14:143859 extensions::TestManagementPolicyProvider provider(
3860 extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED);
[email protected]f484f8d52014-06-12 08:38:183861 GetManagementPolicy()->RegisterProvider(&provider);
[email protected]65187152012-06-02 13:14:143862
3863 // Reinstall the extension.
[email protected]f484f8d52014-06-12 08:38:183864 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_UPDATED);
3865 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3866 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]65187152012-06-02 13:14:143867}
3868
[email protected]ebc3aec2013-10-22 02:39:173869// Flaky on windows; http://crbug.com/309833
3870#if defined(OS_WIN)
3871#define MAYBE_ExternalExtensionAutoAcknowledgement DISABLED_ExternalExtensionAutoAcknowledgement
3872#else
3873#define MAYBE_ExternalExtensionAutoAcknowledgement ExternalExtensionAutoAcknowledgement
3874#endif
[email protected]893642c2014-02-03 06:53:133875TEST_F(ExtensionServiceTest, MAYBE_ExternalExtensionAutoAcknowledgement) {
[email protected]a39921b42012-02-28 03:42:543876 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:183877 service()->set_extensions_enabled(true);
[email protected]a39921b42012-02-28 03:42:543878
3879 {
3880 // Register and install an external extension.
3881 MockExtensionProvider* provider =
[email protected]f484f8d52014-06-12 08:38:183882 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
[email protected]a39921b42012-02-28 03:42:543883 AddMockExternalProvider(provider);
[email protected]f484f8d52014-06-12 08:38:183884 provider->UpdateOrAddExtension(
3885 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
[email protected]a39921b42012-02-28 03:42:543886 }
3887 {
3888 // Have policy force-install an extension.
[email protected]f484f8d52014-06-12 08:38:183889 MockExtensionProvider* provider = new MockExtensionProvider(
3890 service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
[email protected]a39921b42012-02-28 03:42:543891 AddMockExternalProvider(provider);
[email protected]f484f8d52014-06-12 08:38:183892 provider->UpdateOrAddExtension(
3893 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
[email protected]a39921b42012-02-28 03:42:543894 }
3895
3896 // Providers are set up. Let them run.
[email protected]97d6a5c2013-11-11 23:51:243897 int count = 2;
3898 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:063899 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:243900 base::Bind(&WaitForCountNotificationsCallback, &count));
[email protected]f484f8d52014-06-12 08:38:183901 service()->CheckForExternalUpdates();
[email protected]6d057a0c2013-07-09 21:12:073902
[email protected]97d6a5c2013-11-11 23:51:243903 observer.Wait();
[email protected]a39921b42012-02-28 03:42:543904
[email protected]f484f8d52014-06-12 08:38:183905 ASSERT_EQ(2u, registry()->enabled_extensions().size());
3906 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3907 EXPECT_TRUE(service()->GetExtensionById(page_action, false));
3908 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
[email protected]a39921b42012-02-28 03:42:543909 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx));
3910 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action));
3911}
3912
[email protected]a7cd28e2012-10-05 21:03:363913#if !defined(OS_CHROMEOS)
3914// This tests if default apps are installed correctly.
[email protected]d9a61e12012-11-14 02:43:473915TEST_F(ExtensionServiceTest, DefaultAppsInstall) {
[email protected]a7cd28e2012-10-05 21:03:363916 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:183917 service()->set_extensions_enabled(true);
[email protected]a7cd28e2012-10-05 21:03:363918
3919 {
3920 std::string json_data =
3921 "{"
3922 " \"ldnnhddmnhbkjipkidpdiheffobcpfmf\" : {"
3923 " \"external_crx\": \"good.crx\","
3924 " \"external_version\": \"1.0.0.0\","
3925 " \"is_bookmark_app\": false"
3926 " }"
3927 "}";
[email protected]f484f8d52014-06-12 08:38:183928 default_apps::Provider* provider = new default_apps::Provider(
3929 profile(),
3930 service(),
3931 new extensions::ExternalTestingLoader(json_data, data_dir()),
3932 Manifest::INTERNAL,
3933 Manifest::INVALID_LOCATION,
3934 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
[email protected]a7cd28e2012-10-05 21:03:363935
3936 AddMockExternalProvider(provider);
3937 }
3938
[email protected]f484f8d52014-06-12 08:38:183939 ASSERT_EQ(0u, registry()->enabled_extensions().size());
[email protected]97d6a5c2013-11-11 23:51:243940 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:063941 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:243942 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:183943 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:243944 observer.Wait();
[email protected]a7cd28e2012-10-05 21:03:363945
[email protected]f484f8d52014-06-12 08:38:183946 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3947 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3948 const Extension* extension = service()->GetExtensionById(good_crx, false);
[email protected]a7cd28e2012-10-05 21:03:363949 EXPECT_TRUE(extension->from_webstore());
3950 EXPECT_TRUE(extension->was_installed_by_default());
[email protected]a7cd28e2012-10-05 21:03:363951}
3952#endif
3953
[email protected]cd500f72010-06-25 23:44:323954// Tests disabling extensions
[email protected]d9a61e12012-11-14 02:43:473955TEST_F(ExtensionServiceTest, DisableExtension) {
[email protected]eaa7dd182010-12-14 11:09:003956 InitializeEmptyExtensionService();
[email protected]cd500f72010-06-25 23:44:323957
[email protected]f484f8d52014-06-12 08:38:183958 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3959 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
3960 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
[email protected]5fdfa562013-12-27 17:43:593961
[email protected]f484f8d52014-06-12 08:38:183962 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3963 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3964 EXPECT_EQ(0u, registry()->terminated_extensions().size());
3965 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
[email protected]cd500f72010-06-25 23:44:323966
3967 // Disable it.
[email protected]f484f8d52014-06-12 08:38:183968 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
[email protected]cd500f72010-06-25 23:44:323969
[email protected]f484f8d52014-06-12 08:38:183970 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
3971 EXPECT_FALSE(service()->GetExtensionById(good_crx, false));
3972 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3973 EXPECT_EQ(1u, registry()->disabled_extensions().size());
3974 EXPECT_EQ(0u, registry()->terminated_extensions().size());
3975 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
[email protected]bb1bc9b32013-12-21 03:09:143976}
3977
3978TEST_F(ExtensionServiceTest, TerminateExtension) {
3979 InitializeEmptyExtensionService();
3980
[email protected]f484f8d52014-06-12 08:38:183981 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3982 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3983 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3984 EXPECT_EQ(0u, registry()->terminated_extensions().size());
3985 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
[email protected]bb1bc9b32013-12-21 03:09:143986
3987 TerminateExtension(good_crx);
3988
[email protected]f484f8d52014-06-12 08:38:183989 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3990 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3991 EXPECT_EQ(1u, registry()->terminated_extensions().size());
3992 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
[email protected]fa2416f2011-05-03 08:41:203993}
3994
[email protected]d9a61e12012-11-14 02:43:473995TEST_F(ExtensionServiceTest, DisableTerminatedExtension) {
[email protected]fa2416f2011-05-03 08:41:203996 InitializeEmptyExtensionService();
3997
[email protected]f484f8d52014-06-12 08:38:183998 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
[email protected]fa2416f2011-05-03 08:41:203999 TerminateExtension(good_crx);
[email protected]f484f8d52014-06-12 08:38:184000 EXPECT_TRUE(registry()->GetExtensionById(
[email protected]e066da32014-03-26 18:27:354001 good_crx, extensions::ExtensionRegistry::TERMINATED));
[email protected]fa2416f2011-05-03 08:41:204002
4003 // Disable it.
[email protected]f484f8d52014-06-12 08:38:184004 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
[email protected]fa2416f2011-05-03 08:41:204005
[email protected]f484f8d52014-06-12 08:38:184006 EXPECT_FALSE(registry()->GetExtensionById(
[email protected]e066da32014-03-26 18:27:354007 good_crx, extensions::ExtensionRegistry::TERMINATED));
[email protected]f484f8d52014-06-12 08:38:184008 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
[email protected]bb1bc9b32013-12-21 03:09:144009
[email protected]f484f8d52014-06-12 08:38:184010 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4011 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4012 EXPECT_EQ(0u, registry()->terminated_extensions().size());
4013 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
[email protected]cd500f72010-06-25 23:44:324014}
4015
[email protected]d728e002010-12-08 04:46:234016// Tests disabling all extensions (simulating --disable-extensions flag).
[email protected]d9a61e12012-11-14 02:43:474017TEST_F(ExtensionServiceTest, DisableAllExtensions) {
[email protected]eaa7dd182010-12-14 11:09:004018 InitializeEmptyExtensionService();
[email protected]d728e002010-12-08 04:46:234019
[email protected]f484f8d52014-06-12 08:38:184020 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:504021 InstallCRX(path, INSTALL_NEW);
[email protected]d728e002010-12-08 04:46:234022
[email protected]f484f8d52014-06-12 08:38:184023 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4024 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]d728e002010-12-08 04:46:234025
4026 // Disable extensions.
[email protected]f484f8d52014-06-12 08:38:184027 service()->set_extensions_enabled(false);
4028 service()->ReloadExtensionsForTest();
[email protected]d728e002010-12-08 04:46:234029
4030 // There shouldn't be extensions in either list.
[email protected]f484f8d52014-06-12 08:38:184031 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4032 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]d728e002010-12-08 04:46:234033
4034 // This shouldn't do anything when all extensions are disabled.
[email protected]f484f8d52014-06-12 08:38:184035 service()->EnableExtension(good_crx);
4036 service()->ReloadExtensionsForTest();
[email protected]d728e002010-12-08 04:46:234037
4038 // There still shouldn't be extensions in either list.
[email protected]f484f8d52014-06-12 08:38:184039 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4040 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]d728e002010-12-08 04:46:234041
4042 // And then re-enable the extensions.
[email protected]f484f8d52014-06-12 08:38:184043 service()->set_extensions_enabled(true);
4044 service()->ReloadExtensionsForTest();
[email protected]d728e002010-12-08 04:46:234045
[email protected]f484f8d52014-06-12 08:38:184046 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4047 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]d728e002010-12-08 04:46:234048}
4049
[email protected]8f512c72011-11-22 21:02:504050// Tests reloading extensions.
[email protected]d9a61e12012-11-14 02:43:474051TEST_F(ExtensionServiceTest, ReloadExtensions) {
[email protected]eaa7dd182010-12-14 11:09:004052 InitializeEmptyExtensionService();
[email protected]cd500f72010-06-25 23:44:324053
4054 // Simple extension that should install without error.
[email protected]f484f8d52014-06-12 08:38:184055 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]26367b62012-10-04 23:03:324056 InstallCRX(path, INSTALL_NEW,
4057 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT);
[email protected]cd500f72010-06-25 23:44:324058 const char* extension_id = good_crx;
[email protected]f484f8d52014-06-12 08:38:184059 service()->DisableExtension(extension_id, Extension::DISABLE_USER_ACTION);
[email protected]cd500f72010-06-25 23:44:324060
[email protected]f484f8d52014-06-12 08:38:184061 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4062 EXPECT_EQ(1u, registry()->disabled_extensions().size());
[email protected]cd500f72010-06-25 23:44:324063
[email protected]f484f8d52014-06-12 08:38:184064 service()->ReloadExtensionsForTest();
[email protected]cd500f72010-06-25 23:44:324065
[email protected]26367b62012-10-04 23:03:324066 // The creation flags should not change when reloading the extension.
[email protected]f484f8d52014-06-12 08:38:184067 const Extension* extension = service()->GetExtensionById(good_crx, true);
[email protected]26367b62012-10-04 23:03:324068 EXPECT_TRUE(extension->from_webstore());
4069 EXPECT_TRUE(extension->was_installed_by_default());
4070 EXPECT_FALSE(extension->from_bookmark());
4071
[email protected]cd500f72010-06-25 23:44:324072 // Extension counts shouldn't change.
[email protected]f484f8d52014-06-12 08:38:184073 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4074 EXPECT_EQ(1u, registry()->disabled_extensions().size());
[email protected]cd500f72010-06-25 23:44:324075
[email protected]f484f8d52014-06-12 08:38:184076 service()->EnableExtension(extension_id);
[email protected]cd500f72010-06-25 23:44:324077
[email protected]f484f8d52014-06-12 08:38:184078 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4079 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]cd500f72010-06-25 23:44:324080
[email protected]5a73f902010-06-30 02:29:414081 // Need to clear |loaded_| manually before reloading as the
4082 // EnableExtension() call above inserted into it and
4083 // UnloadAllExtensions() doesn't send out notifications.
4084 loaded_.clear();
[email protected]f484f8d52014-06-12 08:38:184085 service()->ReloadExtensionsForTest();
[email protected]cd500f72010-06-25 23:44:324086
4087 // Extension counts shouldn't change.
[email protected]f484f8d52014-06-12 08:38:184088 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4089 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]cd500f72010-06-25 23:44:324090}
4091
[email protected]2a947202013-03-06 04:58:054092// Tests reloading an extension.
4093TEST_F(ExtensionServiceTest, ReloadExtension) {
4094 InitializeEmptyExtensionService();
[email protected]98b6d942013-11-10 00:34:074095 InitializeProcessManager();
[email protected]2a947202013-03-06 04:58:054096
4097 // Simple extension that should install without error.
4098 const char* extension_id = "behllobkkfkfnphdnhnkndlbkcpglgmj";
[email protected]f484f8d52014-06-12 08:38:184099 base::FilePath ext = data_dir()
4100 .AppendASCII("good")
4101 .AppendASCII("Extensions")
4102 .AppendASCII(extension_id)
4103 .AppendASCII("1.0.0.0");
4104 extensions::UnpackedInstaller::Create(service())->Load(ext);
[email protected]eedc1c752013-08-09 18:51:554105 base::RunLoop().RunUntilIdle();
[email protected]2a947202013-03-06 04:58:054106
[email protected]f484f8d52014-06-12 08:38:184107 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4108 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]2a947202013-03-06 04:58:054109
[email protected]f484f8d52014-06-12 08:38:184110 service()->ReloadExtension(extension_id);
[email protected]2a947202013-03-06 04:58:054111
4112 // Extension should be disabled now, waiting to be reloaded.
[email protected]f484f8d52014-06-12 08:38:184113 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4114 EXPECT_EQ(1u, registry()->disabled_extensions().size());
4115 EXPECT_EQ(Extension::DISABLE_RELOAD,
4116 ExtensionPrefs::Get(profile())->GetDisableReasons(extension_id));
[email protected]2a947202013-03-06 04:58:054117
[email protected]a5768512013-04-12 19:35:354118 // Reloading again should not crash.
[email protected]f484f8d52014-06-12 08:38:184119 service()->ReloadExtension(extension_id);
[email protected]2a947202013-03-06 04:58:054120
4121 // Finish reloading
[email protected]eedc1c752013-08-09 18:51:554122 base::RunLoop().RunUntilIdle();
[email protected]2a947202013-03-06 04:58:054123
4124 // Extension should be enabled again.
[email protected]f484f8d52014-06-12 08:38:184125 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4126 EXPECT_EQ(0u, registry()->disabled_extensions().size());
[email protected]2a947202013-03-06 04:58:054127}
4128
[email protected]d9a61e12012-11-14 02:43:474129TEST_F(ExtensionServiceTest, UninstallExtension) {
[email protected]eaa7dd182010-12-14 11:09:004130 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:184131 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
4132 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]fa2416f2011-05-03 08:41:204133 UninstallExtension(good_crx, false);
[email protected]f484f8d52014-06-12 08:38:184134 EXPECT_EQ(0u, registry()->enabled_extensions().size());
[email protected]ebe07772014-05-22 04:16:064135 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_);
[email protected]fa2416f2011-05-03 08:41:204136}
[email protected]631cf822009-05-15 07:01:254137
[email protected]d9a61e12012-11-14 02:43:474138TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) {
[email protected]fa2416f2011-05-03 08:41:204139 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:184140 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
[email protected]fa2416f2011-05-03 08:41:204141 TerminateExtension(good_crx);
4142 UninstallExtension(good_crx, false);
[email protected]ebe07772014-05-22 04:16:064143 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_);
[email protected]631cf822009-05-15 07:01:254144}
4145
[email protected]6aeac8342010-10-01 20:21:184146// Tests the uninstaller helper.
[email protected]d9a61e12012-11-14 02:43:474147TEST_F(ExtensionServiceTest, UninstallExtensionHelper) {
[email protected]eaa7dd182010-12-14 11:09:004148 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:184149 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
[email protected]fa2416f2011-05-03 08:41:204150 UninstallExtension(good_crx, true);
[email protected]ebe07772014-05-22 04:16:064151 EXPECT_EQ(UnloadedExtensionInfo::REASON_UNINSTALL, unloaded_reason_);
[email protected]fa2416f2011-05-03 08:41:204152}
[email protected]6aeac8342010-10-01 20:21:184153
[email protected]d9a61e12012-11-14 02:43:474154TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) {
[email protected]fa2416f2011-05-03 08:41:204155 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:184156 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
[email protected]fa2416f2011-05-03 08:41:204157 TerminateExtension(good_crx);
4158 UninstallExtension(good_crx, true);
[email protected]ebe07772014-05-22 04:16:064159 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_);
[email protected]6aeac8342010-10-01 20:21:184160}
4161
[email protected]98270432012-09-11 20:51:244162// An extension disabled because of unsupported requirements should re-enabled
4163// if updated to a version with supported requirements as long as there are no
4164// other disable reasons.
[email protected]d9a61e12012-11-14 02:43:474165TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) {
[email protected]98270432012-09-11 20:51:244166 InitializeEmptyExtensionService();
4167 BlackListWebGL();
4168
[email protected]f484f8d52014-06-12 08:38:184169 base::FilePath path = data_dir().AppendASCII("requirements");
4170 base::FilePath pem_path =
4171 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
[email protected]98270432012-09-11 20:51:244172 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4173 pem_path,
4174 INSTALL_NEW);
4175 std::string id = extension_v1->id();
[email protected]f484f8d52014-06-12 08:38:184176 EXPECT_TRUE(service()->IsExtensionEnabled(id));
[email protected]98270432012-09-11 20:51:244177
[email protected]650b2d52013-02-10 03:41:454178 base::FilePath v2_bad_requirements_crx = GetTemporaryFile();
[email protected]a17dfcf2012-12-30 02:07:094179
4180 PackCRX(path.AppendASCII("v2_bad_requirements"),
4181 pem_path,
4182 v2_bad_requirements_crx);
4183 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED);
[email protected]f484f8d52014-06-12 08:38:184184 EXPECT_FALSE(service()->IsExtensionEnabled(id));
[email protected]98270432012-09-11 20:51:244185
[email protected]650b2d52013-02-10 03:41:454186 base::FilePath v3_good_crx = GetTemporaryFile();
[email protected]a17dfcf2012-12-30 02:07:094187
4188 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx);
4189 UpdateExtension(id, v3_good_crx, ENABLED);
[email protected]f484f8d52014-06-12 08:38:184190 EXPECT_TRUE(service()->IsExtensionEnabled(id));
[email protected]98270432012-09-11 20:51:244191}
4192
4193// Extensions disabled through user action should stay disabled.
[email protected]d9a61e12012-11-14 02:43:474194TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) {
[email protected]98270432012-09-11 20:51:244195 InitializeEmptyExtensionService();
4196 BlackListWebGL();
4197
[email protected]f484f8d52014-06-12 08:38:184198 base::FilePath path = data_dir().AppendASCII("requirements");
4199 base::FilePath pem_path =
4200 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
[email protected]98270432012-09-11 20:51:244201 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4202 pem_path,
4203 INSTALL_NEW);
4204 std::string id = extension_v1->id();
[email protected]f484f8d52014-06-12 08:38:184205 service()->DisableExtension(id, Extension::DISABLE_USER_ACTION);
4206 EXPECT_FALSE(service()->IsExtensionEnabled(id));
[email protected]98270432012-09-11 20:51:244207
[email protected]650b2d52013-02-10 03:41:454208 base::FilePath v2_bad_requirements_crx = GetTemporaryFile();
[email protected]a17dfcf2012-12-30 02:07:094209
4210 PackCRX(path.AppendASCII("v2_bad_requirements"),
4211 pem_path,
4212 v2_bad_requirements_crx);
4213 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED);
[email protected]f484f8d52014-06-12 08:38:184214 EXPECT_FALSE(service()->IsExtensionEnabled(id));
[email protected]98270432012-09-11 20:51:244215
[email protected]650b2d52013-02-10 03:41:454216 base::FilePath v3_good_crx = GetTemporaryFile();
[email protected]a17dfcf2012-12-30 02:07:094217
4218 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx);
4219 UpdateExtension(id, v3_good_crx, INSTALLED);
[email protected]f484f8d52014-06-12 08:38:184220 EXPECT_FALSE(service()->IsExtensionEnabled(id));
[email protected]98270432012-09-11 20:51:244221}
4222
4223// The extension should not re-enabled because it was disabled from a
4224// permission increase.
[email protected]d9a61e12012-11-14 02:43:474225TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) {
[email protected]98270432012-09-11 20:51:244226 InitializeEmptyExtensionService();
4227 BlackListWebGL();
4228
[email protected]f484f8d52014-06-12 08:38:184229 base::FilePath path = data_dir().AppendASCII("requirements");
4230 base::FilePath pem_path =
4231 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
[email protected]98270432012-09-11 20:51:244232 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4233 pem_path,
4234 INSTALL_NEW);
4235 std::string id = extension_v1->id();
[email protected]f484f8d52014-06-12 08:38:184236 EXPECT_TRUE(service()->IsExtensionEnabled(id));
[email protected]98270432012-09-11 20:51:244237
[email protected]650b2d52013-02-10 03:41:454238 base::FilePath v2_bad_requirements_and_permissions_crx = GetTemporaryFile();
[email protected]a17dfcf2012-12-30 02:07:094239
4240 PackCRX(path.AppendASCII("v2_bad_requirements_and_permissions"),
4241 pem_path,
4242 v2_bad_requirements_and_permissions_crx);
4243 UpdateExtension(id, v2_bad_requirements_and_permissions_crx, INSTALLED);
[email protected]f484f8d52014-06-12 08:38:184244 EXPECT_FALSE(service()->IsExtensionEnabled(id));
[email protected]98270432012-09-11 20:51:244245
[email protected]650b2d52013-02-10 03:41:454246 base::FilePath v3_bad_permissions_crx = GetTemporaryFile();
[email protected]a17dfcf2012-12-30 02:07:094247
4248 PackCRX(path.AppendASCII("v3_bad_permissions"),
4249 pem_path,
4250 v3_bad_permissions_crx);
4251 UpdateExtension(id, v3_bad_permissions_crx, INSTALLED);
[email protected]f484f8d52014-06-12 08:38:184252 EXPECT_FALSE(service()->IsExtensionEnabled(id));
[email protected]98270432012-09-11 20:51:244253}
4254
4255// Unpacked extensions are not allowed to be installed if they have unsupported
4256// requirements.
[email protected]d9a61e12012-11-14 02:43:474257TEST_F(ExtensionServiceTest, UnpackedRequirements) {
[email protected]98270432012-09-11 20:51:244258 InitializeEmptyExtensionService();
4259 BlackListWebGL();
4260
[email protected]f484f8d52014-06-12 08:38:184261 base::FilePath path =
4262 data_dir().AppendASCII("requirements").AppendASCII("v2_bad_requirements");
4263 extensions::UnpackedInstaller::Create(service())->Load(path);
[email protected]eedc1c752013-08-09 18:51:554264 base::RunLoop().RunUntilIdle();
[email protected]98270432012-09-11 20:51:244265 EXPECT_EQ(1u, GetErrors().size());
[email protected]f484f8d52014-06-12 08:38:184266 EXPECT_EQ(0u, registry()->enabled_extensions().size());
[email protected]98270432012-09-11 20:51:244267}
4268
[email protected]c4148a72011-08-09 23:04:204269class ExtensionCookieCallback {
4270 public:
4271 ExtensionCookieCallback()
[email protected]a5768512013-04-12 19:35:354272 : result_(false),
[email protected]b3a25092013-05-28 22:08:164273 weak_factory_(base::MessageLoop::current()) {}
[email protected]c4148a72011-08-09 23:04:204274
4275 void SetCookieCallback(bool result) {
[email protected]b3a25092013-05-28 22:08:164276 base::MessageLoop::current()->PostTask(FROM_HERE,
4277 base::Bind(&base::MessageLoop::Quit, weak_factory_.GetWeakPtr()));
[email protected]c4148a72011-08-09 23:04:204278 result_ = result;
4279 }
4280
4281 void GetAllCookiesCallback(const net::CookieList& list) {
[email protected]b3a25092013-05-28 22:08:164282 base::MessageLoop::current()->PostTask(FROM_HERE,
4283 base::Bind(&base::MessageLoop::Quit, weak_factory_.GetWeakPtr()));
[email protected]c4148a72011-08-09 23:04:204284 list_ = list;
4285 }
4286 net::CookieList list_;
4287 bool result_;
[email protected]b3a25092013-05-28 22:08:164288 base::WeakPtrFactory<base::MessageLoop> weak_factory_;
[email protected]c4148a72011-08-09 23:04:204289};
4290
[email protected]0d6ec3a72011-09-02 02:09:434291// Verifies extension state is removed upon uninstall.
[email protected]42d58f62014-07-31 01:32:454292TEST_F(ExtensionServiceTest, ClearExtensionData) {
[email protected]eaa7dd182010-12-14 11:09:004293 InitializeEmptyExtensionService();
[email protected]c4148a72011-08-09 23:04:204294 ExtensionCookieCallback callback;
[email protected]c10da4b02010-03-25 14:38:324295
4296 // Load a test extension.
[email protected]f484f8d52014-06-12 08:38:184297 base::FilePath path = data_dir();
[email protected]c10da4b02010-03-25 14:38:324298 path = path.AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:504299 const Extension* extension = InstallCRX(path, INSTALL_NEW);
[email protected]c10da4b02010-03-25 14:38:324300 ASSERT_TRUE(extension);
4301 GURL ext_url(extension->url());
[email protected]cd501a72014-08-22 19:58:314302 std::string origin_id = storage::GetIdentifierFromOrigin(ext_url);
[email protected]c10da4b02010-03-25 14:38:324303
4304 // Set a cookie for the extension.
[email protected]f484f8d52014-06-12 08:38:184305 net::CookieMonster* cookie_monster = profile()
4306 ->GetRequestContextForExtensions()
4307 ->GetURLRequestContext()
4308 ->cookie_store()
4309 ->GetCookieMonster();
[email protected]c10da4b02010-03-25 14:38:324310 ASSERT_TRUE(cookie_monster);
4311 net::CookieOptions options;
[email protected]c4148a72011-08-09 23:04:204312 cookie_monster->SetCookieWithOptionsAsync(
[email protected]a5768512013-04-12 19:35:354313 ext_url, "dummy=value", options,
4314 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
4315 base::Unretained(&callback)));
[email protected]eedc1c752013-08-09 18:51:554316 base::RunLoop().RunUntilIdle();
[email protected]c4148a72011-08-09 23:04:204317 EXPECT_TRUE(callback.result_);
4318
4319 cookie_monster->GetAllCookiesForURLAsync(
4320 ext_url,
4321 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4322 base::Unretained(&callback)));
[email protected]eedc1c752013-08-09 18:51:554323 base::RunLoop().RunUntilIdle();
[email protected]c4148a72011-08-09 23:04:204324 EXPECT_EQ(1U, callback.list_.size());
[email protected]c10da4b02010-03-25 14:38:324325
4326 // Open a database.
[email protected]cd501a72014-08-22 19:58:314327 storage::DatabaseTracker* db_tracker =
[email protected]f484f8d52014-06-12 08:38:184328 BrowserContext::GetDefaultStoragePartition(profile())
4329 ->GetDatabaseTracker();
[email protected]04338722013-12-24 23:18:054330 base::string16 db_name = base::UTF8ToUTF16("db");
4331 base::string16 description = base::UTF8ToUTF16("db_description");
[email protected]c10da4b02010-03-25 14:38:324332 int64 size;
[email protected]7c5f2ec2011-05-26 19:15:264333 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
[email protected]c10da4b02010-03-25 14:38:324334 db_tracker->DatabaseClosed(origin_id, db_name);
[email protected]cd501a72014-08-22 19:58:314335 std::vector<storage::OriginInfo> origins;
[email protected]c10da4b02010-03-25 14:38:324336 db_tracker->GetAllOriginsInfo(&origins);
4337 EXPECT_EQ(1U, origins.size());
[email protected]5e301592013-06-18 06:36:054338 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier());
[email protected]c10da4b02010-03-25 14:38:324339
[email protected]98823c682012-06-11 21:18:244340 // Create local storage. We only simulate this by creating the backing files.
4341 // Note: This test depends on details of how the dom_storage library
4342 // stores data in the host file system.
[email protected]650b2d52013-02-10 03:41:454343 base::FilePath lso_dir_path =
[email protected]f484f8d52014-06-12 08:38:184344 profile()->GetPath().AppendASCII("Local Storage");
[email protected]5e301592013-06-18 06:36:054345 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id)
4346 .AddExtension(FILE_PATH_LITERAL(".localstorage"));
[email protected]426d1c92013-12-03 20:08:544347 EXPECT_TRUE(base::CreateDirectory(lso_dir_path));
[email protected]e5c2a22e2014-03-06 20:42:304348 EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0));
[email protected]7567484142013-07-11 17:36:074349 EXPECT_TRUE(base::PathExists(lso_file_path));
[email protected]c10da4b02010-03-25 14:38:324350
[email protected]ab308092011-08-25 23:37:194351 // Create indexed db. Similarly, it is enough to only simulate this by
4352 // creating the directory on the disk.
[email protected]f484f8d52014-06-12 08:38:184353 IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition(
4354 profile())->GetIndexedDBContext();
[email protected]89acda82013-06-25 20:52:504355 idb_context->SetTaskRunnerForTesting(
[email protected]198b5902013-06-27 10:36:114356 base::MessageLoop::current()->message_loop_proxy().get());
[email protected]650b2d52013-02-10 03:41:454357 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id);
[email protected]426d1c92013-12-03 20:08:544358 EXPECT_TRUE(base::CreateDirectory(idb_path));
[email protected]dcd16612013-07-15 20:18:094359 EXPECT_TRUE(base::DirectoryExists(idb_path));
[email protected]e1dcf922010-11-22 19:12:124360
[email protected]c10da4b02010-03-25 14:38:324361 // Uninstall the extension.
[email protected]42d58f62014-07-31 01:32:454362 base::RunLoop run_loop;
4363 ASSERT_TRUE(
4364 service()->UninstallExtension(good_crx,
4365 extensions::UNINSTALL_REASON_FOR_TESTING,
4366 run_loop.QuitClosure(),
4367 NULL));
4368 // The data deletion happens on the IO thread.
4369 run_loop.Run();
[email protected]c10da4b02010-03-25 14:38:324370
4371 // Check that the cookie is gone.
[email protected]c4148a72011-08-09 23:04:204372 cookie_monster->GetAllCookiesForURLAsync(
4373 ext_url,
4374 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4375 base::Unretained(&callback)));
[email protected]eedc1c752013-08-09 18:51:554376 base::RunLoop().RunUntilIdle();
[email protected]c4148a72011-08-09 23:04:204377 EXPECT_EQ(0U, callback.list_.size());
[email protected]c10da4b02010-03-25 14:38:324378
4379 // The database should have vanished as well.
4380 origins.clear();
4381 db_tracker->GetAllOriginsInfo(&origins);
4382 EXPECT_EQ(0U, origins.size());
4383
4384 // Check that the LSO file has been removed.
[email protected]7567484142013-07-11 17:36:074385 EXPECT_FALSE(base::PathExists(lso_file_path));
[email protected]e1dcf922010-11-22 19:12:124386
4387 // Check if the indexed db has disappeared too.
[email protected]dcd16612013-07-15 20:18:094388 EXPECT_FALSE(base::DirectoryExists(idb_path));
[email protected]c10da4b02010-03-25 14:38:324389}
4390
[email protected]0d6ec3a72011-09-02 02:09:434391// Verifies app state is removed upon uninstall.
[email protected]d9a61e12012-11-14 02:43:474392TEST_F(ExtensionServiceTest, ClearAppData) {
[email protected]0d6ec3a72011-09-02 02:09:434393 InitializeEmptyExtensionService();
[email protected]0d6ec3a72011-09-02 02:09:434394 ExtensionCookieCallback callback;
4395
4396 int pref_count = 0;
4397
4398 // Install app1 with unlimited storage.
[email protected]8f512c72011-11-22 21:02:504399 const Extension* extension =
[email protected]f484f8d52014-06-12 08:38:184400 PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
[email protected]0d6ec3a72011-09-02 02:09:434401 ValidatePrefKeyCount(++pref_count);
[email protected]f484f8d52014-06-12 08:38:184402 ASSERT_EQ(1u, registry()->enabled_extensions().size());
[email protected]0d6ec3a72011-09-02 02:09:434403 const std::string id1 = extension->id();
[email protected]076ebeda2014-06-06 21:47:264404 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
[email protected]c2e66e12012-06-27 06:27:064405 APIPermission::kUnlimitedStorage));
[email protected]6b414c232013-06-05 07:53:344406 const GURL origin1(
4407 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
[email protected]f484f8d52014-06-12 08:38:184408 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4409 origin1));
[email protected]cd501a72014-08-22 19:58:314410 std::string origin_id = storage::GetIdentifierFromOrigin(origin1);
[email protected]0d6ec3a72011-09-02 02:09:434411
4412 // Install app2 from the same origin with unlimited storage.
[email protected]f484f8d52014-06-12 08:38:184413 extension = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
[email protected]0d6ec3a72011-09-02 02:09:434414 ValidatePrefKeyCount(++pref_count);
[email protected]f484f8d52014-06-12 08:38:184415 ASSERT_EQ(2u, registry()->enabled_extensions().size());
[email protected]0d6ec3a72011-09-02 02:09:434416 const std::string id2 = extension->id();
[email protected]076ebeda2014-06-06 21:47:264417 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
[email protected]c2e66e12012-06-27 06:27:064418 APIPermission::kUnlimitedStorage));
[email protected]0d6ec3a72011-09-02 02:09:434419 EXPECT_TRUE(extension->web_extent().MatchesURL(
[email protected]6b414c232013-06-05 07:53:344420 extensions::AppLaunchInfo::GetFullLaunchURL(extension)));
4421 const GURL origin2(
4422 extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
[email protected]0d6ec3a72011-09-02 02:09:434423 EXPECT_EQ(origin1, origin2);
[email protected]f484f8d52014-06-12 08:38:184424 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4425 origin2));
[email protected]0d6ec3a72011-09-02 02:09:434426
4427 // Set a cookie for the extension.
[email protected]f484f8d52014-06-12 08:38:184428 net::CookieMonster* cookie_monster = profile()
4429 ->GetRequestContext()
4430 ->GetURLRequestContext()
4431 ->cookie_store()
4432 ->GetCookieMonster();
[email protected]0d6ec3a72011-09-02 02:09:434433 ASSERT_TRUE(cookie_monster);
4434 net::CookieOptions options;
4435 cookie_monster->SetCookieWithOptionsAsync(
4436 origin1, "dummy=value", options,
4437 base::Bind(&ExtensionCookieCallback::SetCookieCallback,
4438 base::Unretained(&callback)));
[email protected]eedc1c752013-08-09 18:51:554439 base::RunLoop().RunUntilIdle();
[email protected]0d6ec3a72011-09-02 02:09:434440 EXPECT_TRUE(callback.result_);
4441
4442 cookie_monster->GetAllCookiesForURLAsync(
4443 origin1,
4444 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4445 base::Unretained(&callback)));
[email protected]eedc1c752013-08-09 18:51:554446 base::RunLoop().RunUntilIdle();
[email protected]0d6ec3a72011-09-02 02:09:434447 EXPECT_EQ(1U, callback.list_.size());
4448
4449 // Open a database.
[email protected]cd501a72014-08-22 19:58:314450 storage::DatabaseTracker* db_tracker =
[email protected]f484f8d52014-06-12 08:38:184451 BrowserContext::GetDefaultStoragePartition(profile())
4452 ->GetDatabaseTracker();
[email protected]04338722013-12-24 23:18:054453 base::string16 db_name = base::UTF8ToUTF16("db");
4454 base::string16 description = base::UTF8ToUTF16("db_description");
[email protected]0d6ec3a72011-09-02 02:09:434455 int64 size;
4456 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size);
4457 db_tracker->DatabaseClosed(origin_id, db_name);
[email protected]cd501a72014-08-22 19:58:314458 std::vector<storage::OriginInfo> origins;
[email protected]0d6ec3a72011-09-02 02:09:434459 db_tracker->GetAllOriginsInfo(&origins);
4460 EXPECT_EQ(1U, origins.size());
[email protected]5e301592013-06-18 06:36:054461 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier());
[email protected]0d6ec3a72011-09-02 02:09:434462
[email protected]98823c682012-06-11 21:18:244463 // Create local storage. We only simulate this by creating the backing files.
4464 // Note: This test depends on details of how the dom_storage library
4465 // stores data in the host file system.
[email protected]650b2d52013-02-10 03:41:454466 base::FilePath lso_dir_path =
[email protected]f484f8d52014-06-12 08:38:184467 profile()->GetPath().AppendASCII("Local Storage");
[email protected]5e301592013-06-18 06:36:054468 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id)
4469 .AddExtension(FILE_PATH_LITERAL(".localstorage"));
[email protected]426d1c92013-12-03 20:08:544470 EXPECT_TRUE(base::CreateDirectory(lso_dir_path));
[email protected]e5c2a22e2014-03-06 20:42:304471 EXPECT_EQ(0, base::WriteFile(lso_file_path, NULL, 0));
[email protected]7567484142013-07-11 17:36:074472 EXPECT_TRUE(base::PathExists(lso_file_path));
[email protected]0d6ec3a72011-09-02 02:09:434473
4474 // Create indexed db. Similarly, it is enough to only simulate this by
4475 // creating the directory on the disk.
[email protected]f484f8d52014-06-12 08:38:184476 IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition(
4477 profile())->GetIndexedDBContext();
[email protected]89acda82013-06-25 20:52:504478 idb_context->SetTaskRunnerForTesting(
[email protected]198b5902013-06-27 10:36:114479 base::MessageLoop::current()->message_loop_proxy().get());
[email protected]650b2d52013-02-10 03:41:454480 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id);
[email protected]426d1c92013-12-03 20:08:544481 EXPECT_TRUE(base::CreateDirectory(idb_path));
[email protected]dcd16612013-07-15 20:18:094482 EXPECT_TRUE(base::DirectoryExists(idb_path));
[email protected]0d6ec3a72011-09-02 02:09:434483
4484 // Uninstall one of them, unlimited storage should still be granted
4485 // to the origin.
4486 UninstallExtension(id1, false);
[email protected]f484f8d52014-06-12 08:38:184487 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4488 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4489 origin1));
[email protected]0d6ec3a72011-09-02 02:09:434490
4491 // Check that the cookie is still there.
4492 cookie_monster->GetAllCookiesForURLAsync(
4493 origin1,
4494 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4495 base::Unretained(&callback)));
[email protected]eedc1c752013-08-09 18:51:554496 base::RunLoop().RunUntilIdle();
[email protected]0d6ec3a72011-09-02 02:09:434497 EXPECT_EQ(1U, callback.list_.size());
4498
4499 // Now uninstall the other. Storage should be cleared for the apps.
4500 UninstallExtension(id2, false);
[email protected]f484f8d52014-06-12 08:38:184501 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4502 EXPECT_FALSE(
4503 profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
4504 origin1));
[email protected]0d6ec3a72011-09-02 02:09:434505
4506 // Check that the cookie is gone.
4507 cookie_monster->GetAllCookiesForURLAsync(
4508 origin1,
4509 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4510 base::Unretained(&callback)));
[email protected]eedc1c752013-08-09 18:51:554511 base::RunLoop().RunUntilIdle();
[email protected]0d6ec3a72011-09-02 02:09:434512 EXPECT_EQ(0U, callback.list_.size());
4513
4514 // The database should have vanished as well.
4515 origins.clear();
4516 db_tracker->GetAllOriginsInfo(&origins);
4517 EXPECT_EQ(0U, origins.size());
4518
4519 // Check that the LSO file has been removed.
[email protected]7567484142013-07-11 17:36:074520 EXPECT_FALSE(base::PathExists(lso_file_path));
[email protected]0d6ec3a72011-09-02 02:09:434521
4522 // Check if the indexed db has disappeared too.
[email protected]dcd16612013-07-15 20:18:094523 EXPECT_FALSE(base::DirectoryExists(idb_path));
[email protected]0d6ec3a72011-09-02 02:09:434524}
4525
[email protected]894bb502009-05-21 22:39:574526// Tests loading single extensions (like --load-extension)
[email protected]e3f610b2013-05-03 02:22:384527// Flaky crashes. http://crbug.com/231806
4528TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) {
[email protected]eaa7dd182010-12-14 11:09:004529 InitializeEmptyExtensionService();
[email protected]3cf4f0992009-02-03 23:00:304530
[email protected]f484f8d52014-06-12 08:38:184531 base::FilePath ext1 = data_dir()
4532 .AppendASCII("good")
4533 .AppendASCII("Extensions")
4534 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
4535 .AppendASCII("1.0.0.0");
4536 extensions::UnpackedInstaller::Create(service())->Load(ext1);
[email protected]eedc1c752013-08-09 18:51:554537 base::RunLoop().RunUntilIdle();
[email protected]bb28e062009-02-27 17:19:184538 EXPECT_EQ(0u, GetErrors().size());
[email protected]894bb502009-05-21 22:39:574539 ASSERT_EQ(1u, loaded_.size());
[email protected]12075d12013-02-27 05:38:054540 EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
[email protected]f484f8d52014-06-12 08:38:184541 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]3cf4f0992009-02-03 23:00:304542
[email protected]e8c729a2010-03-09 19:55:194543 ValidatePrefKeyCount(1);
[email protected]25b34332009-06-05 21:53:194544
[email protected]f484f8d52014-06-12 08:38:184545 base::FilePath no_manifest =
4546 data_dir()
4547 .AppendASCII("bad")
4548 // .AppendASCII("Extensions")
4549 .AppendASCII("cccccccccccccccccccccccccccccccc")
4550 .AppendASCII("1");
4551 extensions::UnpackedInstaller::Create(service())->Load(no_manifest);
[email protected]eedc1c752013-08-09 18:51:554552 base::RunLoop().RunUntilIdle();
[email protected]bb28e062009-02-27 17:19:184553 EXPECT_EQ(1u, GetErrors().size());
[email protected]894bb502009-05-21 22:39:574554 ASSERT_EQ(1u, loaded_.size());
[email protected]f484f8d52014-06-12 08:38:184555 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]25b34332009-06-05 21:53:194556
4557 // Test uninstall.
[email protected]894bb502009-05-21 22:39:574558 std::string id = loaded_[0]->id();
4559 EXPECT_FALSE(unloaded_id_.length());
[email protected]42d58f62014-07-31 01:32:454560 service()->UninstallExtension(id,
4561 extensions::UNINSTALL_REASON_FOR_TESTING,
4562 base::Bind(&base::DoNothing),
4563 NULL);
[email protected]eedc1c752013-08-09 18:51:554564 base::RunLoop().RunUntilIdle();
[email protected]894bb502009-05-21 22:39:574565 EXPECT_EQ(id, unloaded_id_);
[email protected]9f1087e2009-06-15 17:29:324566 ASSERT_EQ(0u, loaded_.size());
[email protected]f484f8d52014-06-12 08:38:184567 EXPECT_EQ(0u, registry()->enabled_extensions().size());
[email protected]3cf4f0992009-02-03 23:00:304568}
[email protected]0b344962009-03-31 04:21:454569
[email protected]894bb502009-05-21 22:39:574570// Tests that we generate IDs when they are not specified in the manifest for
4571// --load-extension.
[email protected]d9a61e12012-11-14 02:43:474572TEST_F(ExtensionServiceTest, GenerateID) {
[email protected]eaa7dd182010-12-14 11:09:004573 InitializeEmptyExtensionService();
[email protected]fbcc40302009-06-12 20:45:454574
[email protected]f484f8d52014-06-12 08:38:184575 base::FilePath no_id_ext = data_dir().AppendASCII("no_id");
4576 extensions::UnpackedInstaller::Create(service())->Load(no_id_ext);
[email protected]eedc1c752013-08-09 18:51:554577 base::RunLoop().RunUntilIdle();
[email protected]0b344962009-03-31 04:21:454578 EXPECT_EQ(0u, GetErrors().size());
[email protected]894bb502009-05-21 22:39:574579 ASSERT_EQ(1u, loaded_.size());
[email protected]fdd28372014-08-21 02:27:264580 ASSERT_TRUE(crx_file::id_util::IdIsValid(loaded_[0]->id()));
[email protected]12075d12013-02-27 05:38:054581 EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED);
[email protected]0b344962009-03-31 04:21:454582
[email protected]e8c729a2010-03-09 19:55:194583 ValidatePrefKeyCount(1);
[email protected]25b34332009-06-05 21:53:194584
[email protected]84ac7f32009-10-06 06:17:544585 std::string previous_id = loaded_[0]->id();
4586
4587 // If we reload the same path, we should get the same extension ID.
[email protected]f484f8d52014-06-12 08:38:184588 extensions::UnpackedInstaller::Create(service())->Load(no_id_ext);
[email protected]eedc1c752013-08-09 18:51:554589 base::RunLoop().RunUntilIdle();
[email protected]84ac7f32009-10-06 06:17:544590 ASSERT_EQ(1u, loaded_.size());
4591 ASSERT_EQ(previous_id, loaded_[0]->id());
[email protected]0b344962009-03-31 04:21:454592}
[email protected]894bb502009-05-21 22:39:574593
[email protected]557c7bd2013-09-18 21:51:254594TEST_F(ExtensionServiceTest, UnpackedValidatesLocales) {
4595 InitializeEmptyExtensionService();
4596
[email protected]f484f8d52014-06-12 08:38:184597 base::FilePath bad_locale =
4598 data_dir().AppendASCII("unpacked").AppendASCII("bad_messages_file");
4599 extensions::UnpackedInstaller::Create(service())->Load(bad_locale);
[email protected]557c7bd2013-09-18 21:51:254600 base::RunLoop().RunUntilIdle();
4601 EXPECT_EQ(1u, GetErrors().size());
4602 base::FilePath ms_messages_file = bad_locale.AppendASCII("_locales")
4603 .AppendASCII("ms")
4604 .AppendASCII("messages.json");
[email protected]04338722013-12-24 23:18:054605 EXPECT_THAT(base::UTF16ToUTF8(GetErrors()[0]), testing::AllOf(
4606 testing::HasSubstr(
4607 base::UTF16ToUTF8(ms_messages_file.LossyDisplayName())),
[email protected]557c7bd2013-09-18 21:51:254608 testing::HasSubstr("Dictionary keys must be quoted.")));
4609 ASSERT_EQ(0u, loaded_.size());
4610}
4611
[email protected]eaa7dd182010-12-14 11:09:004612void ExtensionServiceTest::TestExternalProvider(
[email protected]1d5e58b2013-01-31 08:41:404613 MockExtensionProvider* provider, Manifest::Location location) {
[email protected]a1257b12009-06-12 02:51:344614 // Verify that starting with no providers loads no extensions.
[email protected]f484f8d52014-06-12 08:38:184615 service()->Init();
[email protected]a1257b12009-06-12 02:51:344616 ASSERT_EQ(0u, loaded_.size());
4617
[email protected]0a60a2e2010-10-25 16:15:214618 provider->set_visit_count(0);
4619
[email protected]a1257b12009-06-12 02:51:344620 // Register a test extension externally using the mock registry provider.
[email protected]f484f8d52014-06-12 08:38:184621 base::FilePath source_path = data_dir().AppendASCII("good.crx");
[email protected]894bb502009-05-21 22:39:574622
[email protected]a1257b12009-06-12 02:51:344623 // Add the extension.
[email protected]d55e7602009-12-16 04:20:424624 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
[email protected]894bb502009-05-21 22:39:574625
[email protected]9f1087e2009-06-15 17:29:324626 // Reloading extensions should find our externally registered extension
[email protected]894bb502009-05-21 22:39:574627 // and install it.
[email protected]97d6a5c2013-11-11 23:51:244628 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:064629 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:244630 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:184631 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:244632 observer.Wait();
[email protected]894bb502009-05-21 22:39:574633
4634 ASSERT_EQ(0u, GetErrors().size());
4635 ASSERT_EQ(1u, loaded_.size());
[email protected]d55e7602009-12-16 04:20:424636 ASSERT_EQ(location, loaded_[0]->location());
[email protected]894bb502009-05-21 22:39:574637 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
[email protected]25b34332009-06-05 21:53:194638 ValidatePrefKeyCount(1);
[email protected]e2194742010-08-12 05:54:344639 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4640 ValidateIntegerPref(good_crx, "location", location);
[email protected]894bb502009-05-21 22:39:574641
[email protected]9f1087e2009-06-15 17:29:324642 // Reload extensions without changing anything. The extension should be
[email protected]894bb502009-05-21 22:39:574643 // loaded again.
4644 loaded_.clear();
[email protected]f484f8d52014-06-12 08:38:184645 service()->ReloadExtensionsForTest();
[email protected]eedc1c752013-08-09 18:51:554646 base::RunLoop().RunUntilIdle();
[email protected]894bb502009-05-21 22:39:574647 ASSERT_EQ(0u, GetErrors().size());
4648 ASSERT_EQ(1u, loaded_.size());
[email protected]25b34332009-06-05 21:53:194649 ValidatePrefKeyCount(1);
[email protected]e2194742010-08-12 05:54:344650 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4651 ValidateIntegerPref(good_crx, "location", location);
[email protected]e2eb43112009-05-29 21:19:544652
[email protected]894bb502009-05-21 22:39:574653 // Now update the extension with a new version. We should get upgraded.
4654 source_path = source_path.DirName().AppendASCII("good2.crx");
[email protected]d55e7602009-12-16 04:20:424655 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
[email protected]894bb502009-05-21 22:39:574656
4657 loaded_.clear();
[email protected]97d6a5c2013-11-11 23:51:244658 content::WindowedNotificationObserver observer_2(
[email protected]adf5a102014-07-31 12:44:064659 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:244660 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:184661 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:244662 observer_2.Wait();
[email protected]894bb502009-05-21 22:39:574663 ASSERT_EQ(0u, GetErrors().size());
4664 ASSERT_EQ(1u, loaded_.size());
4665 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
[email protected]25b34332009-06-05 21:53:194666 ValidatePrefKeyCount(1);
[email protected]e2194742010-08-12 05:54:344667 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4668 ValidateIntegerPref(good_crx, "location", location);
[email protected]894bb502009-05-21 22:39:574669
[email protected]27b985d2009-06-25 17:53:154670 // Uninstall the extension and reload. Nothing should happen because the
[email protected]894bb502009-05-21 22:39:574671 // preference should prevent us from reinstalling.
4672 std::string id = loaded_[0]->id();
[email protected]dc24976f2013-06-02 21:15:094673 bool no_uninstall =
[email protected]f484f8d52014-06-12 08:38:184674 GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL);
[email protected]42d58f62014-07-31 01:32:454675 service()->UninstallExtension(id,
4676 extensions::UNINSTALL_REASON_FOR_TESTING,
4677 base::Bind(&base::DoNothing),
4678 NULL);
[email protected]eedc1c752013-08-09 18:51:554679 base::RunLoop().RunUntilIdle();
[email protected]894bb502009-05-21 22:39:574680
[email protected]f484f8d52014-06-12 08:38:184681 base::FilePath install_path = extensions_install_dir().AppendASCII(id);
[email protected]e410b5f2012-12-14 14:02:244682 if (no_uninstall) {
[email protected]65187152012-06-02 13:14:144683 // Policy controlled extensions should not have been touched by uninstall.
[email protected]7567484142013-07-11 17:36:074684 ASSERT_TRUE(base::PathExists(install_path));
[email protected]65187152012-06-02 13:14:144685 } else {
[email protected]95da88c42011-03-31 10:07:334686 // The extension should also be gone from the install directory.
[email protected]7567484142013-07-11 17:36:074687 ASSERT_FALSE(base::PathExists(install_path));
[email protected]95da88c42011-03-31 10:07:334688 loaded_.clear();
[email protected]f484f8d52014-06-12 08:38:184689 service()->CheckForExternalUpdates();
[email protected]eedc1c752013-08-09 18:51:554690 base::RunLoop().RunUntilIdle();
[email protected]95da88c42011-03-31 10:07:334691 ASSERT_EQ(0u, loaded_.size());
4692 ValidatePrefKeyCount(1);
[email protected]79c833b52011-04-05 18:31:014693 ValidateIntegerPref(good_crx, "state",
4694 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
[email protected]95da88c42011-03-31 10:07:334695 ValidateIntegerPref(good_crx, "location", location);
[email protected]894bb502009-05-21 22:39:574696
[email protected]95da88c42011-03-31 10:07:334697 // Now clear the preference and reinstall.
4698 SetPrefInteg(good_crx, "state", Extension::ENABLED);
[email protected]25b34332009-06-05 21:53:194699
[email protected]95da88c42011-03-31 10:07:334700 loaded_.clear();
[email protected]97d6a5c2013-11-11 23:51:244701 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:064702 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:244703 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:184704 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:244705 observer.Wait();
[email protected]95da88c42011-03-31 10:07:334706 ASSERT_EQ(1u, loaded_.size());
[email protected]95da88c42011-03-31 10:07:334707 }
[email protected]25b34332009-06-05 21:53:194708 ValidatePrefKeyCount(1);
[email protected]e2194742010-08-12 05:54:344709 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4710 ValidateIntegerPref(good_crx, "location", location);
[email protected]25b34332009-06-05 21:53:194711
[email protected]f484f8d52014-06-12 08:38:184712 if (GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL)) {
[email protected]65187152012-06-02 13:14:144713 EXPECT_EQ(2, provider->visit_count());
4714 } else {
[email protected]95da88c42011-03-31 10:07:334715 // Now test an externally triggered uninstall (deleting the registry key or
4716 // the pref entry).
4717 provider->RemoveExtension(good_crx);
[email protected]25b34332009-06-05 21:53:194718
[email protected]95da88c42011-03-31 10:07:334719 loaded_.clear();
[email protected]f484f8d52014-06-12 08:38:184720 service()->OnExternalProviderReady(provider);
[email protected]eedc1c752013-08-09 18:51:554721 base::RunLoop().RunUntilIdle();
[email protected]95da88c42011-03-31 10:07:334722 ASSERT_EQ(0u, loaded_.size());
4723 ValidatePrefKeyCount(0);
[email protected]25b34332009-06-05 21:53:194724
[email protected]95da88c42011-03-31 10:07:334725 // The extension should also be gone from the install directory.
[email protected]7567484142013-07-11 17:36:074726 ASSERT_FALSE(base::PathExists(install_path));
[email protected]abe7a8942009-06-23 05:14:294727
[email protected]95da88c42011-03-31 10:07:334728 // Now test the case where user uninstalls and then the extension is removed
4729 // from the external provider.
[email protected]97d6a5c2013-11-11 23:51:244730 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:064731 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:244732 content::NotificationService::AllSources());
[email protected]05aad2da2011-10-28 10:12:374733 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
[email protected]f484f8d52014-06-12 08:38:184734 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:244735 observer.Wait();
[email protected]abe7a8942009-06-23 05:14:294736
[email protected]95da88c42011-03-31 10:07:334737 ASSERT_EQ(1u, loaded_.size());
4738 ASSERT_EQ(0u, GetErrors().size());
[email protected]d55e7602009-12-16 04:20:424739
[email protected]95da88c42011-03-31 10:07:334740 // User uninstalls.
4741 loaded_.clear();
[email protected]42d58f62014-07-31 01:32:454742 service()->UninstallExtension(id,
4743 extensions::UNINSTALL_REASON_FOR_TESTING,
4744 base::Bind(&base::DoNothing),
4745 NULL);
[email protected]eedc1c752013-08-09 18:51:554746 base::RunLoop().RunUntilIdle();
[email protected]95da88c42011-03-31 10:07:334747 ASSERT_EQ(0u, loaded_.size());
[email protected]d55e7602009-12-16 04:20:424748
[email protected]95da88c42011-03-31 10:07:334749 // Then remove the extension from the extension provider.
4750 provider->RemoveExtension(good_crx);
[email protected]d55e7602009-12-16 04:20:424751
[email protected]95da88c42011-03-31 10:07:334752 // Should still be at 0.
4753 loaded_.clear();
[email protected]f484f8d52014-06-12 08:38:184754 extensions::InstalledLoader(service()).LoadAllExtensions();
[email protected]eedc1c752013-08-09 18:51:554755 base::RunLoop().RunUntilIdle();
[email protected]95da88c42011-03-31 10:07:334756 ASSERT_EQ(0u, loaded_.size());
4757 ValidatePrefKeyCount(1);
[email protected]0a60a2e2010-10-25 16:15:214758
[email protected]95da88c42011-03-31 10:07:334759 EXPECT_EQ(5, provider->visit_count());
[email protected]95da88c42011-03-31 10:07:334760 }
[email protected]d55e7602009-12-16 04:20:424761}
4762
4763// Tests the external installation feature
4764#if defined(OS_WIN)
[email protected]d9a61e12012-11-14 02:43:474765TEST_F(ExtensionServiceTest, ExternalInstallRegistry) {
[email protected]aebe23a32010-12-10 22:15:484766 // This should all work, even when normal extension installation is disabled.
[email protected]eaa7dd182010-12-14 11:09:004767 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:184768 service()->set_extensions_enabled(false);
[email protected]d55e7602009-12-16 04:20:424769
4770 // Now add providers. Extension system takes ownership of the objects.
4771 MockExtensionProvider* reg_provider =
[email protected]f484f8d52014-06-12 08:38:184772 new MockExtensionProvider(service(), Manifest::EXTERNAL_REGISTRY);
[email protected]0a60a2e2010-10-25 16:15:214773 AddMockExternalProvider(reg_provider);
[email protected]1d5e58b2013-01-31 08:41:404774 TestExternalProvider(reg_provider, Manifest::EXTERNAL_REGISTRY);
[email protected]d55e7602009-12-16 04:20:424775}
4776#endif
4777
[email protected]d9a61e12012-11-14 02:43:474778TEST_F(ExtensionServiceTest, ExternalInstallPref) {
[email protected]eaa7dd182010-12-14 11:09:004779 InitializeEmptyExtensionService();
[email protected]d55e7602009-12-16 04:20:424780
4781 // Now add providers. Extension system takes ownership of the objects.
4782 MockExtensionProvider* pref_provider =
[email protected]f484f8d52014-06-12 08:38:184783 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
[email protected]0a60a2e2010-10-25 16:15:214784
4785 AddMockExternalProvider(pref_provider);
[email protected]1d5e58b2013-01-31 08:41:404786 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF);
[email protected]27b985d2009-06-25 17:53:154787}
4788
[email protected]d9a61e12012-11-14 02:43:474789TEST_F(ExtensionServiceTest, ExternalInstallPrefUpdateUrl) {
[email protected]aebe23a32010-12-10 22:15:484790 // This should all work, even when normal extension installation is disabled.
[email protected]eaa7dd182010-12-14 11:09:004791 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:184792 service()->set_extensions_enabled(false);
[email protected]55196e92010-09-29 15:04:464793
[email protected]0a60a2e2010-10-25 16:15:214794 // TODO(skerner): The mock provider is not a good model of a provider
4795 // that works with update URLs, because it adds file and version info.
4796 // Extend the mock to work with update URLs. This test checks the
4797 // behavior that is common to all external extension visitors. The
4798 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that
4799 // what the visitor does results in an extension being downloaded and
4800 // installed.
[email protected]55196e92010-09-29 15:04:464801 MockExtensionProvider* pref_provider =
[email protected]f484f8d52014-06-12 08:38:184802 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF_DOWNLOAD);
[email protected]0a60a2e2010-10-25 16:15:214803 AddMockExternalProvider(pref_provider);
[email protected]1d5e58b2013-01-31 08:41:404804 TestExternalProvider(pref_provider, Manifest::EXTERNAL_PREF_DOWNLOAD);
[email protected]55196e92010-09-29 15:04:464805}
4806
[email protected]d9a61e12012-11-14 02:43:474807TEST_F(ExtensionServiceTest, ExternalInstallPolicyUpdateUrl) {
[email protected]95da88c42011-03-31 10:07:334808 // This should all work, even when normal extension installation is disabled.
4809 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:184810 service()->set_extensions_enabled(false);
[email protected]95da88c42011-03-31 10:07:334811
4812 // TODO(skerner): The mock provider is not a good model of a provider
4813 // that works with update URLs, because it adds file and version info.
4814 // Extend the mock to work with update URLs. This test checks the
4815 // behavior that is common to all external extension visitors. The
4816 // browser test ExtensionManagementTest.ExternalUrlUpdate tests that
4817 // what the visitor does results in an extension being downloaded and
4818 // installed.
4819 MockExtensionProvider* pref_provider =
[email protected]f484f8d52014-06-12 08:38:184820 new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
[email protected]95da88c42011-03-31 10:07:334821 AddMockExternalProvider(pref_provider);
[email protected]1d5e58b2013-01-31 08:41:404822 TestExternalProvider(pref_provider, Manifest::EXTERNAL_POLICY_DOWNLOAD);
[email protected]95da88c42011-03-31 10:07:334823}
4824
[email protected]aebe23a32010-12-10 22:15:484825// Tests that external extensions get uninstalled when the external extension
4826// providers can't account for them.
[email protected]d9a61e12012-11-14 02:43:474827TEST_F(ExtensionServiceTest, ExternalUninstall) {
[email protected]aebe23a32010-12-10 22:15:484828 // Start the extensions service with one external extension already installed.
[email protected]f484f8d52014-06-12 08:38:184829 base::FilePath source_install_dir =
4830 data_dir().AppendASCII("good").AppendASCII("Extensions");
[email protected]650b2d52013-02-10 03:41:454831 base::FilePath pref_path = source_install_dir
[email protected]aebe23a32010-12-10 22:15:484832 .DirName()
4833 .AppendASCII("PreferencesExternal");
4834
[email protected]5df038b2012-07-16 19:03:274835 // This initializes the extensions service with no ExternalProviders.
[email protected]eaa7dd182010-12-14 11:09:004836 InitializeInstalledExtensionService(pref_path, source_install_dir);
[email protected]f484f8d52014-06-12 08:38:184837 service()->set_extensions_enabled(false);
[email protected]aebe23a32010-12-10 22:15:484838
[email protected]f484f8d52014-06-12 08:38:184839 service()->Init();
[email protected]aebe23a32010-12-10 22:15:484840
4841 ASSERT_EQ(0u, GetErrors().size());
[email protected]1f4728f2012-12-05 20:40:054842 ASSERT_EQ(0u, loaded_.size());
[email protected]aebe23a32010-12-10 22:15:484843
4844 // Verify that it's not the disabled extensions flag causing it not to load.
[email protected]f484f8d52014-06-12 08:38:184845 service()->set_extensions_enabled(true);
4846 service()->ReloadExtensionsForTest();
[email protected]eedc1c752013-08-09 18:51:554847 base::RunLoop().RunUntilIdle();
[email protected]aebe23a32010-12-10 22:15:484848
4849 ASSERT_EQ(0u, GetErrors().size());
4850 ASSERT_EQ(0u, loaded_.size());
4851}
4852
[email protected]a29a517a2011-01-21 21:11:124853// Test that running multiple update checks simultaneously does not
4854// keep the update from succeeding.
[email protected]d9a61e12012-11-14 02:43:474855TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) {
[email protected]a29a517a2011-01-21 21:11:124856 InitializeEmptyExtensionService();
4857
4858 MockExtensionProvider* provider =
[email protected]f484f8d52014-06-12 08:38:184859 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
[email protected]a29a517a2011-01-21 21:11:124860 AddMockExternalProvider(provider);
4861
4862 // Verify that starting with no providers loads no extensions.
[email protected]f484f8d52014-06-12 08:38:184863 service()->Init();
[email protected]a29a517a2011-01-21 21:11:124864 ASSERT_EQ(0u, loaded_.size());
4865
4866 // Start two checks for updates.
4867 provider->set_visit_count(0);
[email protected]f484f8d52014-06-12 08:38:184868 service()->CheckForExternalUpdates();
4869 service()->CheckForExternalUpdates();
[email protected]eedc1c752013-08-09 18:51:554870 base::RunLoop().RunUntilIdle();
[email protected]a29a517a2011-01-21 21:11:124871
4872 // Two calls should cause two checks for external extensions.
4873 EXPECT_EQ(2, provider->visit_count());
4874 EXPECT_EQ(0u, GetErrors().size());
4875 EXPECT_EQ(0u, loaded_.size());
4876
4877 // Register a test extension externally using the mock registry provider.
[email protected]f484f8d52014-06-12 08:38:184878 base::FilePath source_path = data_dir().AppendASCII("good.crx");
[email protected]a29a517a2011-01-21 21:11:124879 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path);
4880
4881 // Two checks for external updates should find the extension, and install it
4882 // once.
[email protected]97d6a5c2013-11-11 23:51:244883 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:064884 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:244885 content::NotificationService::AllSources());
[email protected]a29a517a2011-01-21 21:11:124886 provider->set_visit_count(0);
[email protected]f484f8d52014-06-12 08:38:184887 service()->CheckForExternalUpdates();
4888 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:244889 observer.Wait();
[email protected]a29a517a2011-01-21 21:11:124890 EXPECT_EQ(2, provider->visit_count());
4891 ASSERT_EQ(0u, GetErrors().size());
4892 ASSERT_EQ(1u, loaded_.size());
[email protected]1d5e58b2013-01-31 08:41:404893 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location());
[email protected]a29a517a2011-01-21 21:11:124894 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
4895 ValidatePrefKeyCount(1);
4896 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:404897 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF);
[email protected]a29a517a2011-01-21 21:11:124898
4899 provider->RemoveExtension(good_crx);
4900 provider->set_visit_count(0);
[email protected]f484f8d52014-06-12 08:38:184901 service()->CheckForExternalUpdates();
4902 service()->CheckForExternalUpdates();
[email protected]eedc1c752013-08-09 18:51:554903 base::RunLoop().RunUntilIdle();
[email protected]a29a517a2011-01-21 21:11:124904
4905 // Two calls should cause two checks for external extensions.
4906 // Because the external source no longer includes good_crx,
4907 // good_crx will be uninstalled. So, expect that no extensions
4908 // are loaded.
4909 EXPECT_EQ(2, provider->visit_count());
4910 EXPECT_EQ(0u, GetErrors().size());
4911 EXPECT_EQ(0u, loaded_.size());
4912}
4913
[email protected]d9a61e12012-11-14 02:43:474914TEST_F(ExtensionServiceTest, ExternalPrefProvider) {
[email protected]eaa7dd182010-12-14 11:09:004915 InitializeEmptyExtensionService();
[email protected]f0841cd2011-01-19 15:07:244916
4917 // Test some valid extension records.
4918 // Set a base path to avoid erroring out on relative paths.
4919 // Paths starting with // are absolute on every platform we support.
[email protected]650b2d52013-02-10 03:41:454920 base::FilePath base_path(FILE_PATH_LITERAL("//base/path"));
[email protected]f0841cd2011-01-19 15:07:244921 ASSERT_TRUE(base_path.IsAbsolute());
4922 MockProviderVisitor visitor(base_path);
[email protected]27b985d2009-06-25 17:53:154923 std::string json_data =
4924 "{"
[email protected]f0841cd2011-01-19 15:07:244925 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {"
[email protected]9e54cb572010-09-03 20:08:064926 " \"external_crx\": \"RandomExtension.crx\","
4927 " \"external_version\": \"1.0\""
4928 " },"
4929 " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {"
4930 " \"external_crx\": \"RandomExtension2.crx\","
4931 " \"external_version\": \"2.0\""
4932 " },"
4933 " \"cccccccccccccccccccccccccccccccc\": {"
[email protected]d8fd0fd2014-03-24 13:16:064934 " \"external_update_url\": \"http:\\\\foo.com/update\","
4935 " \"install_parameter\": \"id\""
[email protected]9e54cb572010-09-03 20:08:064936 " }"
[email protected]27b985d2009-06-25 17:53:154937 "}";
[email protected]f0841cd2011-01-19 15:07:244938 EXPECT_EQ(3, visitor.Visit(json_data));
[email protected]27b985d2009-06-25 17:53:154939
[email protected]9e54cb572010-09-03 20:08:064940 // Simulate an external_extensions.json file that contains seven invalid
[email protected]f0841cd2011-01-19 15:07:244941 // records:
[email protected]27b985d2009-06-25 17:53:154942 // - One that is missing the 'external_crx' key.
4943 // - One that is missing the 'external_version' key.
4944 // - One that is specifying .. in the path.
[email protected]8ef78fd2010-08-19 17:14:324945 // - One that specifies both a file and update URL.
4946 // - One that specifies no file or update URL.
4947 // - One that has an update URL that is not well formed.
[email protected]9e54cb572010-09-03 20:08:064948 // - One that contains a malformed version.
[email protected]ab22ba42011-01-14 16:36:384949 // - One that has an invalid id.
4950 // - One that has a non-dictionary value.
[email protected]0d461c52012-07-03 19:29:414951 // - One that has an integer 'external_version' instead of a string.
[email protected]9e54cb572010-09-03 20:08:064952 // The final extension is valid, and we check that it is read to make sure
4953 // failures don't stop valid records from being read.
[email protected]27b985d2009-06-25 17:53:154954 json_data =
4955 "{"
[email protected]9e54cb572010-09-03 20:08:064956 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {"
4957 " \"external_version\": \"1.0\""
4958 " },"
4959 " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {"
4960 " \"external_crx\": \"RandomExtension.crx\""
4961 " },"
4962 " \"cccccccccccccccccccccccccccccccc\": {"
4963 " \"external_crx\": \"..\\\\foo\\\\RandomExtension2.crx\","
4964 " \"external_version\": \"2.0\""
4965 " },"
4966 " \"dddddddddddddddddddddddddddddddd\": {"
4967 " \"external_crx\": \"RandomExtension2.crx\","
4968 " \"external_version\": \"2.0\","
4969 " \"external_update_url\": \"http:\\\\foo.com/update\""
4970 " },"
4971 " \"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\": {"
4972 " },"
4973 " \"ffffffffffffffffffffffffffffffff\": {"
4974 " \"external_update_url\": \"This string is not a valid URL\""
4975 " },"
4976 " \"gggggggggggggggggggggggggggggggg\": {"
4977 " \"external_crx\": \"RandomExtension3.crx\","
4978 " \"external_version\": \"This is not a valid version!\""
4979 " },"
[email protected]ab22ba42011-01-14 16:36:384980 " \"This is not a valid id!\": {},"
4981 " \"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\": true,"
[email protected]0d461c52012-07-03 19:29:414982 " \"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\": {"
4983 " \"external_crx\": \"RandomExtension4.crx\","
4984 " \"external_version\": 1.0"
4985 " },"
[email protected]ab22ba42011-01-14 16:36:384986 " \"pppppppppppppppppppppppppppppppp\": {"
[email protected]9e54cb572010-09-03 20:08:064987 " \"external_crx\": \"RandomValidExtension.crx\","
4988 " \"external_version\": \"1.0\""
4989 " }"
[email protected]27b985d2009-06-25 17:53:154990 "}";
[email protected]683d0702010-12-06 16:25:574991 EXPECT_EQ(1, visitor.Visit(json_data));
[email protected]f0841cd2011-01-19 15:07:244992
4993 // Check that if a base path is not provided, use of a relative
4994 // path fails.
[email protected]650b2d52013-02-10 03:41:454995 base::FilePath empty;
[email protected]f0841cd2011-01-19 15:07:244996 MockProviderVisitor visitor_no_relative_paths(empty);
4997
4998 // Use absolute paths. Expect success.
4999 json_data =
5000 "{"
5001 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {"
5002 " \"external_crx\": \"//RandomExtension1.crx\","
5003 " \"external_version\": \"3.0\""
5004 " },"
5005 " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {"
5006 " \"external_crx\": \"//path/to/RandomExtension2.crx\","
5007 " \"external_version\": \"3.0\""
5008 " }"
5009 "}";
5010 EXPECT_EQ(2, visitor_no_relative_paths.Visit(json_data));
5011
5012 // Use a relative path. Expect that it will error out.
5013 json_data =
5014 "{"
5015 " \"cccccccccccccccccccccccccccccccc\": {"
5016 " \"external_crx\": \"RandomExtension2.crx\","
5017 " \"external_version\": \"3.0\""
5018 " }"
5019 "}";
5020 EXPECT_EQ(0, visitor_no_relative_paths.Visit(json_data));
[email protected]9d32ded072011-10-11 16:31:055021
5022 // Test supported_locales.
5023 json_data =
5024 "{"
5025 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {"
5026 " \"external_crx\": \"RandomExtension.crx\","
5027 " \"external_version\": \"1.0\","
5028 " \"supported_locales\": [ \"en\" ]"
5029 " },"
5030 " \"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\": {"
5031 " \"external_crx\": \"RandomExtension2.crx\","
5032 " \"external_version\": \"2.0\","
5033 " \"supported_locales\": [ \"en-GB\" ]"
5034 " },"
5035 " \"cccccccccccccccccccccccccccccccc\": {"
5036 " \"external_crx\": \"RandomExtension2.crx\","
5037 " \"external_version\": \"3.0\","
5038 " \"supported_locales\": [ \"en_US\", \"fr\" ]"
5039 " }"
5040 "}";
5041 {
5042 ScopedBrowserLocale guard("en-US");
5043 EXPECT_EQ(2, visitor.Visit(json_data));
5044 }
[email protected]f121003b2012-05-04 21:57:475045
[email protected]19eac6d2013-05-30 06:51:035046 // Test keep_if_present.
5047 json_data =
5048 "{"
5049 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {"
5050 " \"external_crx\": \"RandomExtension.crx\","
5051 " \"external_version\": \"1.0\","
5052 " \"keep_if_present\": true"
5053 " }"
5054 "}";
5055 {
5056 EXPECT_EQ(0, visitor.Visit(json_data));
5057 }
5058
[email protected]f121003b2012-05-04 21:57:475059 // Test is_bookmark_app.
5060 MockProviderVisitor from_bookmark_visitor(
5061 base_path, Extension::FROM_BOOKMARK);
5062 json_data =
5063 "{"
5064 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {"
5065 " \"external_crx\": \"RandomExtension.crx\","
5066 " \"external_version\": \"1.0\","
5067 " \"is_bookmark_app\": true"
5068 " }"
5069 "}";
5070 EXPECT_EQ(1, from_bookmark_visitor.Visit(json_data));
[email protected]7425d7df2012-11-28 14:35:425071
5072 // Test is_from_webstore.
5073 MockProviderVisitor from_webstore_visitor(
5074 base_path, Extension::FROM_WEBSTORE);
5075 json_data =
5076 "{"
5077 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {"
5078 " \"external_crx\": \"RandomExtension.crx\","
5079 " \"external_version\": \"1.0\","
5080 " \"is_from_webstore\": true"
5081 " }"
5082 "}";
5083 EXPECT_EQ(1, from_webstore_visitor.Visit(json_data));
[email protected]bf9fd5ae2014-04-09 22:50:065084
5085 // Test was_installed_by_eom.
5086 MockProviderVisitor was_installed_by_eom_visitor(
5087 base_path, Extension::WAS_INSTALLED_BY_OEM);
5088 json_data =
5089 "{"
5090 " \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\": {"
5091 " \"external_crx\": \"RandomExtension.crx\","
5092 " \"external_version\": \"1.0\","
5093 " \"was_installed_by_oem\": true"
5094 " }"
5095 "}";
5096 EXPECT_EQ(1, was_installed_by_eom_visitor.Visit(json_data));
[email protected]e18236b2009-06-22 21:32:105097}
[email protected]36a784c2009-06-23 06:21:085098
[email protected]c6d474f82009-12-16 21:11:065099// Test loading good extensions from the profile directory.
[email protected]d9a61e12012-11-14 02:43:475100TEST_F(ExtensionServiceTest, LoadAndRelocalizeExtensions) {
[email protected]6884a802012-08-07 03:55:225101 // Ensure we're testing in "en" and leave global state untouched.
5102 extension_l10n_util::ScopedLocaleForTest testLocale("en");
5103
[email protected]c6d474f82009-12-16 21:11:065104 // Initialize the test dir with a good Preferences/extensions.
[email protected]f484f8d52014-06-12 08:38:185105 base::FilePath source_install_dir = data_dir().AppendASCII("l10n");
[email protected]e96a0602014-02-15 08:27:425106 base::FilePath pref_path =
5107 source_install_dir.Append(chrome::kPreferencesFilename);
[email protected]eaa7dd182010-12-14 11:09:005108 InitializeInstalledExtensionService(pref_path, source_install_dir);
[email protected]c6d474f82009-12-16 21:11:065109
[email protected]f484f8d52014-06-12 08:38:185110 service()->Init();
[email protected]c6d474f82009-12-16 21:11:065111
5112 ASSERT_EQ(3u, loaded_.size());
5113
5114 // This was equal to "sr" on load.
5115 ValidateStringPref(loaded_[0]->id(), keys::kCurrentLocale, "en");
5116
5117 // These are untouched by re-localization.
5118 ValidateStringPref(loaded_[1]->id(), keys::kCurrentLocale, "en");
5119 EXPECT_FALSE(IsPrefExist(loaded_[1]->id(), keys::kCurrentLocale));
5120
5121 // This one starts with Serbian name, and gets re-localized into English.
5122 EXPECT_EQ("My name is simple.", loaded_[0]->name());
5123
5124 // These are untouched by re-localization.
5125 EXPECT_EQ("My name is simple.", loaded_[1]->name());
5126 EXPECT_EQ("no l10n", loaded_[2]->name());
5127}
5128
[email protected]6c2381d2011-10-19 02:52:535129class ExtensionsReadyRecorder : public content::NotificationObserver {
[email protected]f0488f2f2009-07-01 05:25:225130 public:
5131 ExtensionsReadyRecorder() : ready_(false) {
[email protected]adf5a102014-07-31 12:44:065132 registrar_.Add(this,
5133 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
[email protected]ad50def52011-10-19 23:17:075134 content::NotificationService::AllSources());
[email protected]f0488f2f2009-07-01 05:25:225135 }
5136
5137 void set_ready(bool value) { ready_ = value; }
5138 bool ready() { return ready_; }
5139
5140 private:
[email protected]432115822011-07-10 15:52:275141 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:535142 const content::NotificationSource& source,
[email protected]49aeab62013-02-07 02:53:115143 const content::NotificationDetails& details) OVERRIDE {
[email protected]432115822011-07-10 15:52:275144 switch (type) {
[email protected]adf5a102014-07-31 12:44:065145 case extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED:
[email protected]f0488f2f2009-07-01 05:25:225146 ready_ = true;
5147 break;
5148 default:
5149 NOTREACHED();
5150 }
5151 }
5152
[email protected]6c2381d2011-10-19 02:52:535153 content::NotificationRegistrar registrar_;
[email protected]f0488f2f2009-07-01 05:25:225154 bool ready_;
5155};
5156
[email protected]36a784c2009-06-23 06:21:085157// Test that we get enabled/disabled correctly for all the pref/command-line
[email protected]eaa7dd182010-12-14 11:09:005158// combinations. We don't want to derive from the ExtensionServiceTest class
5159// for this test, so we use ExtensionServiceTestSimple.
[email protected]f0488f2f2009-07-01 05:25:225160//
5161// Also tests that we always fire EXTENSIONS_READY, no matter whether we are
5162// enabled or not.
[email protected]39fdf5202012-11-14 00:38:175163TEST(ExtensionServiceTestSimple, Enabledness) {
[email protected]5a24d2b2012-11-14 20:38:315164 // Make sure the PluginService singleton is destroyed at the end of the test.
[email protected]39fdf5202012-11-14 00:38:175165 base::ShadowingAtExitManager at_exit_manager;
[email protected]8f3372122013-07-18 04:34:145166#if defined(ENABLE_PLUGINS)
5167 content::PluginService::GetInstance()->Init();
5168 content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting();
5169#endif
[email protected]5a24d2b2012-11-14 20:38:315170
[email protected]ed8ee722011-04-22 06:49:445171 ExtensionErrorReporter::Init(false); // no noisy errors
[email protected]f0488f2f2009-07-01 05:25:225172 ExtensionsReadyRecorder recorder;
[email protected]aa96d3a2010-08-21 08:45:255173 scoped_ptr<TestingProfile> profile(new TestingProfile());
[email protected]33ad6ce92013-08-27 14:39:085174 content::TestBrowserThreadBundle thread_bundle_;
[email protected]e4854dc2013-04-24 00:11:515175#if defined OS_CHROMEOS
5176 chromeos::ScopedTestDeviceSettingsService device_settings_service;
5177 chromeos::ScopedTestCrosSettings cros_settings;
5178 scoped_ptr<chromeos::ScopedTestUserManager> user_manager(
5179 new chromeos::ScopedTestUserManager);
5180#endif
[email protected]36a784c2009-06-23 06:21:085181 scoped_ptr<CommandLine> command_line;
[email protected]650b2d52013-02-10 03:41:455182 base::FilePath install_dir = profile->GetPath()
[email protected]836e2982013-05-16 08:07:425183 .AppendASCII(extensions::kInstallDirectoryName);
[email protected]be5a6db2012-11-13 14:39:115184
[email protected]6d60703b2009-08-29 01:29:235185 // By default, we are enabled.
[email protected]947446b2010-10-21 03:36:315186 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
[email protected]bd306722012-07-11 20:43:595187 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>(
[email protected]749d59a2012-04-05 00:23:245188 ExtensionSystem::Get(profile.get()))->
[email protected]31d8f5f22012-04-02 15:22:085189 CreateExtensionService(
5190 command_line.get(),
5191 install_dir,
5192 false);
[email protected]6d60703b2009-08-29 01:29:235193 EXPECT_TRUE(service->extensions_enabled());
5194 service->Init();
[email protected]eedc1c752013-08-09 18:51:555195 base::RunLoop().RunUntilIdle();
[email protected]6d60703b2009-08-29 01:29:235196 EXPECT_TRUE(recorder.ready());
[email protected]e4854dc2013-04-24 00:11:515197#if defined OS_CHROMEOS
5198 user_manager.reset();
5199#endif
[email protected]6d60703b2009-08-29 01:29:235200
5201 // If either the command line or pref is set, we are disabled.
5202 recorder.set_ready(false);
[email protected]aa96d3a2010-08-21 08:45:255203 profile.reset(new TestingProfile());
[email protected]6d60703b2009-08-29 01:29:235204 command_line->AppendSwitch(switches::kDisableExtensions);
[email protected]bd306722012-07-11 20:43:595205 service = static_cast<extensions::TestExtensionSystem*>(
[email protected]749d59a2012-04-05 00:23:245206 ExtensionSystem::Get(profile.get()))->
[email protected]31d8f5f22012-04-02 15:22:085207 CreateExtensionService(
5208 command_line.get(),
5209 install_dir,
5210 false);
[email protected]36a784c2009-06-23 06:21:085211 EXPECT_FALSE(service->extensions_enabled());
[email protected]f0488f2f2009-07-01 05:25:225212 service->Init();
[email protected]eedc1c752013-08-09 18:51:555213 base::RunLoop().RunUntilIdle();
[email protected]f0488f2f2009-07-01 05:25:225214 EXPECT_TRUE(recorder.ready());
[email protected]36a784c2009-06-23 06:21:085215
[email protected]f0488f2f2009-07-01 05:25:225216 recorder.set_ready(false);
[email protected]aa96d3a2010-08-21 08:45:255217 profile.reset(new TestingProfile());
5218 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
[email protected]bd306722012-07-11 20:43:595219 service = static_cast<extensions::TestExtensionSystem*>(
[email protected]749d59a2012-04-05 00:23:245220 ExtensionSystem::Get(profile.get()))->
[email protected]31d8f5f22012-04-02 15:22:085221 CreateExtensionService(
5222 command_line.get(),
5223 install_dir,
5224 false);
[email protected]6d60703b2009-08-29 01:29:235225 EXPECT_FALSE(service->extensions_enabled());
[email protected]f0488f2f2009-07-01 05:25:225226 service->Init();
[email protected]eedc1c752013-08-09 18:51:555227 base::RunLoop().RunUntilIdle();
[email protected]f0488f2f2009-07-01 05:25:225228 EXPECT_TRUE(recorder.ready());
[email protected]36a784c2009-06-23 06:21:085229
[email protected]f0488f2f2009-07-01 05:25:225230 recorder.set_ready(false);
[email protected]aa96d3a2010-08-21 08:45:255231 profile.reset(new TestingProfile());
5232 profile->GetPrefs()->SetBoolean(prefs::kDisableExtensions, true);
[email protected]947446b2010-10-21 03:36:315233 command_line.reset(new CommandLine(CommandLine::NO_PROGRAM));
[email protected]bd306722012-07-11 20:43:595234 service = static_cast<extensions::TestExtensionSystem*>(
[email protected]749d59a2012-04-05 00:23:245235 ExtensionSystem::Get(profile.get()))->
[email protected]31d8f5f22012-04-02 15:22:085236 CreateExtensionService(
5237 command_line.get(),
5238 install_dir,
5239 false);
[email protected]6d60703b2009-08-29 01:29:235240 EXPECT_FALSE(service->extensions_enabled());
[email protected]f0488f2f2009-07-01 05:25:225241 service->Init();
[email protected]eedc1c752013-08-09 18:51:555242 base::RunLoop().RunUntilIdle();
[email protected]f0488f2f2009-07-01 05:25:225243 EXPECT_TRUE(recorder.ready());
[email protected]7e1951a2010-09-30 10:22:205244
5245 // Explicitly delete all the resources used in this test.
5246 profile.reset();
5247 service = NULL;
[email protected]060d4972012-07-19 17:22:395248 // Execute any pending deletion tasks.
[email protected]eedc1c752013-08-09 18:51:555249 base::RunLoop().RunUntilIdle();
[email protected]36a784c2009-06-23 06:21:085250}
[email protected]24b538a2010-02-27 01:22:445251
5252// Test loading extensions that require limited and unlimited storage quotas.
[email protected]d9a61e12012-11-14 02:43:475253TEST_F(ExtensionServiceTest, StorageQuota) {
[email protected]eaa7dd182010-12-14 11:09:005254 InitializeEmptyExtensionService();
[email protected]24b538a2010-02-27 01:22:445255
[email protected]f484f8d52014-06-12 08:38:185256 base::FilePath extensions_path = data_dir().AppendASCII("storage_quota");
[email protected]24b538a2010-02-27 01:22:445257
[email protected]650b2d52013-02-10 03:41:455258 base::FilePath limited_quota_ext =
[email protected]e85e34c32011-04-13 18:38:355259 extensions_path.AppendASCII("limited_quota")
[email protected]24b538a2010-02-27 01:22:445260 .AppendASCII("1.0");
[email protected]03b612f2010-08-13 21:09:215261
5262 // The old permission name for unlimited quota was "unlimited_storage", but
5263 // we changed it to "unlimitedStorage". This tests both versions.
[email protected]650b2d52013-02-10 03:41:455264 base::FilePath unlimited_quota_ext =
[email protected]e85e34c32011-04-13 18:38:355265 extensions_path.AppendASCII("unlimited_quota")
[email protected]24b538a2010-02-27 01:22:445266 .AppendASCII("1.0");
[email protected]650b2d52013-02-10 03:41:455267 base::FilePath unlimited_quota_ext2 =
[email protected]e85e34c32011-04-13 18:38:355268 extensions_path.AppendASCII("unlimited_quota")
[email protected]03b612f2010-08-13 21:09:215269 .AppendASCII("2.0");
[email protected]f484f8d52014-06-12 08:38:185270 extensions::UnpackedInstaller::Create(service())->Load(limited_quota_ext);
5271 extensions::UnpackedInstaller::Create(service())->Load(unlimited_quota_ext);
5272 extensions::UnpackedInstaller::Create(service())->Load(unlimited_quota_ext2);
[email protected]eedc1c752013-08-09 18:51:555273 base::RunLoop().RunUntilIdle();
[email protected]24b538a2010-02-27 01:22:445274
[email protected]03b612f2010-08-13 21:09:215275 ASSERT_EQ(3u, loaded_.size());
[email protected]f484f8d52014-06-12 08:38:185276 EXPECT_TRUE(profile());
5277 EXPECT_FALSE(profile()->IsOffTheRecord());
5278 EXPECT_FALSE(
5279 profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
5280 loaded_[0]->url()));
5281 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
[email protected]7c5f2ec2011-05-26 19:15:265282 loaded_[1]->url()));
[email protected]f484f8d52014-06-12 08:38:185283 EXPECT_TRUE(profile()->GetExtensionSpecialStoragePolicy()->IsStorageUnlimited(
[email protected]7c5f2ec2011-05-26 19:15:265284 loaded_[2]->url()));
[email protected]24b538a2010-02-27 01:22:445285}
[email protected]1952c7d2010-03-04 23:48:345286
[email protected]d8c8f25f2011-11-02 18:18:015287// Tests ComponentLoader::Add().
[email protected]d9a61e12012-11-14 02:43:475288TEST_F(ExtensionServiceTest, ComponentExtensions) {
[email protected]eaa7dd182010-12-14 11:09:005289 InitializeEmptyExtensionService();
[email protected]1952c7d2010-03-04 23:48:345290
[email protected]f0b97f12010-10-11 21:44:355291 // Component extensions should work even when extensions are disabled.
[email protected]f484f8d52014-06-12 08:38:185292 service()->set_extensions_enabled(false);
[email protected]f0b97f12010-10-11 21:44:355293
[email protected]f484f8d52014-06-12 08:38:185294 base::FilePath path = data_dir()
5295 .AppendASCII("good")
5296 .AppendASCII("Extensions")
5297 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
5298 .AppendASCII("1.0.0.0");
[email protected]1952c7d2010-03-04 23:48:345299
5300 std::string manifest;
[email protected]82f84b92013-08-30 18:23:505301 ASSERT_TRUE(base::ReadFileToString(
[email protected]993da5e2013-03-23 21:25:165302 path.Append(extensions::kManifestFilename), &manifest));
[email protected]1952c7d2010-03-04 23:48:345303
[email protected]f484f8d52014-06-12 08:38:185304 service()->component_loader()->Add(manifest, path);
5305 service()->Init();
[email protected]1952c7d2010-03-04 23:48:345306
5307 // Note that we do not pump messages -- the extension should be loaded
5308 // immediately.
5309
5310 EXPECT_EQ(0u, GetErrors().size());
5311 ASSERT_EQ(1u, loaded_.size());
[email protected]1d5e58b2013-01-31 08:41:405312 EXPECT_EQ(Manifest::COMPONENT, loaded_[0]->location());
[email protected]f484f8d52014-06-12 08:38:185313 EXPECT_EQ(1u, registry()->enabled_extensions().size());
[email protected]1952c7d2010-03-04 23:48:345314
[email protected]8c484b742012-11-29 06:05:365315 // Component extensions get a prefs entry on first install.
5316 ValidatePrefKeyCount(1);
[email protected]1952c7d2010-03-04 23:48:345317
5318 // Reload all extensions, and make sure it comes back.
[email protected]f484f8d52014-06-12 08:38:185319 std::string extension_id = (*registry()->enabled_extensions().begin())->id();
[email protected]1952c7d2010-03-04 23:48:345320 loaded_.clear();
[email protected]f484f8d52014-06-12 08:38:185321 service()->ReloadExtensionsForTest();
5322 ASSERT_EQ(1u, registry()->enabled_extensions().size());
5323 EXPECT_EQ(extension_id, (*registry()->enabled_extensions().begin())->id());
[email protected]1952c7d2010-03-04 23:48:345324}
[email protected]145a317b2011-04-12 16:03:465325
[email protected]6d147912013-07-09 08:02:145326TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledComponent) {
5327 InitializeEmptyExtensionService();
[email protected]f8aefb132013-10-30 09:29:525328 InitializeExtensionSyncService();
[email protected]6d147912013-07-09 08:02:145329
5330 bool flare_was_called = false;
5331 syncer::ModelType triggered_type(syncer::UNSPECIFIED);
5332 base::WeakPtrFactory<ExtensionServiceTest> factory(this);
[email protected]f484f8d52014-06-12 08:38:185333 extension_sync_service()->SetSyncStartFlare(
[email protected]6d147912013-07-09 08:02:145334 base::Bind(&ExtensionServiceTest::MockSyncStartFlare,
5335 factory.GetWeakPtr(),
5336 &flare_was_called, // Safe due to WeakPtrFactory scope.
5337 &triggered_type)); // Safe due to WeakPtrFactory scope.
5338
5339 // Install a component extension.
[email protected]6d147912013-07-09 08:02:145340 std::string manifest;
[email protected]82f84b92013-08-30 18:23:505341 ASSERT_TRUE(base::ReadFileToString(
[email protected]3f2a2fa2013-09-24 02:55:255342 good0_path().Append(extensions::kManifestFilename), &manifest));
[email protected]f484f8d52014-06-12 08:38:185343 service()->component_loader()->Add(manifest, good0_path());
5344 ASSERT_FALSE(service()->is_ready());
5345 service()->Init();
5346 ASSERT_TRUE(service()->is_ready());
[email protected]6d147912013-07-09 08:02:145347
5348 // Extensions added before service is_ready() don't trigger sync startup.
5349 EXPECT_FALSE(flare_was_called);
5350 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type);
5351}
5352
5353TEST_F(ExtensionServiceTest, DeferredSyncStartupPreInstalledNormal) {
[email protected]3f2a2fa2013-09-24 02:55:255354 InitializeGoodInstalledExtensionService();
[email protected]f8aefb132013-10-30 09:29:525355 InitializeExtensionSyncService();
[email protected]6d147912013-07-09 08:02:145356
5357 bool flare_was_called = false;
5358 syncer::ModelType triggered_type(syncer::UNSPECIFIED);
5359 base::WeakPtrFactory<ExtensionServiceTest> factory(this);
[email protected]f484f8d52014-06-12 08:38:185360 extension_sync_service()->SetSyncStartFlare(
[email protected]6d147912013-07-09 08:02:145361 base::Bind(&ExtensionServiceTest::MockSyncStartFlare,
5362 factory.GetWeakPtr(),
5363 &flare_was_called, // Safe due to WeakPtrFactory scope.
5364 &triggered_type)); // Safe due to WeakPtrFactory scope.
5365
[email protected]f484f8d52014-06-12 08:38:185366 ASSERT_FALSE(service()->is_ready());
5367 service()->Init();
[email protected]50736a12013-09-26 08:58:345368 ASSERT_EQ(3u, loaded_.size());
[email protected]f484f8d52014-06-12 08:38:185369 ASSERT_TRUE(service()->is_ready());
[email protected]6d147912013-07-09 08:02:145370
5371 // Extensions added before service is_ready() don't trigger sync startup.
5372 EXPECT_FALSE(flare_was_called);
5373 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type);
5374}
5375
5376TEST_F(ExtensionServiceTest, DeferredSyncStartupOnInstall) {
5377 InitializeEmptyExtensionService();
[email protected]f8aefb132013-10-30 09:29:525378 InitializeExtensionSyncService();
[email protected]f484f8d52014-06-12 08:38:185379 service()->Init();
5380 ASSERT_TRUE(service()->is_ready());
[email protected]6d147912013-07-09 08:02:145381
5382 bool flare_was_called = false;
5383 syncer::ModelType triggered_type(syncer::UNSPECIFIED);
5384 base::WeakPtrFactory<ExtensionServiceTest> factory(this);
[email protected]f484f8d52014-06-12 08:38:185385 extension_sync_service()->SetSyncStartFlare(
[email protected]6d147912013-07-09 08:02:145386 base::Bind(&ExtensionServiceTest::MockSyncStartFlare,
5387 factory.GetWeakPtr(),
5388 &flare_was_called, // Safe due to WeakPtrFactory scope.
5389 &triggered_type)); // Safe due to WeakPtrFactory scope.
5390
[email protected]f484f8d52014-06-12 08:38:185391 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]6d147912013-07-09 08:02:145392 InstallCRX(path, INSTALL_NEW);
5393
5394 EXPECT_TRUE(flare_was_called);
5395 EXPECT_EQ(syncer::EXTENSIONS, triggered_type);
5396
5397 // Reset.
5398 flare_was_called = false;
5399 triggered_type = syncer::UNSPECIFIED;
5400
5401 // Once sync starts, flare should no longer be invoked.
[email protected]f484f8d52014-06-12 08:38:185402 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255403 syncer::EXTENSIONS,
5404 syncer::SyncDataList(),
5405 scoped_ptr<syncer::SyncChangeProcessor>(
5406 new syncer::FakeSyncChangeProcessor),
[email protected]6d147912013-07-09 08:02:145407 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]f484f8d52014-06-12 08:38:185408 path = data_dir().AppendASCII("page_action.crx");
[email protected]6d147912013-07-09 08:02:145409 InstallCRX(path, INSTALL_NEW);
5410 EXPECT_FALSE(flare_was_called);
5411 ASSERT_EQ(syncer::UNSPECIFIED, triggered_type);
5412}
5413
[email protected]386db3572013-11-08 12:26:445414TEST_F(ExtensionServiceTest, DisableExtensionFromSync) {
5415 // Start the extensions service with one external extension already installed.
[email protected]f484f8d52014-06-12 08:38:185416 base::FilePath source_install_dir =
5417 data_dir().AppendASCII("good").AppendASCII("Extensions");
[email protected]e96a0602014-02-15 08:27:425418 base::FilePath pref_path =
5419 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
[email protected]386db3572013-11-08 12:26:445420
5421 InitializeInstalledExtensionService(pref_path, source_install_dir);
5422 InitializeExtensionSyncService();
5423
5424 // The user has enabled sync.
5425 ProfileSyncService* sync_service =
[email protected]f484f8d52014-06-12 08:38:185426 ProfileSyncServiceFactory::GetForProfile(profile());
[email protected]386db3572013-11-08 12:26:445427 sync_service->SetSyncSetupCompleted();
5428
[email protected]f484f8d52014-06-12 08:38:185429 service()->Init();
5430 ASSERT_TRUE(service()->is_ready());
[email protected]386db3572013-11-08 12:26:445431
5432 ASSERT_EQ(3u, loaded_.size());
5433
5434 // We start enabled.
[email protected]f484f8d52014-06-12 08:38:185435 const Extension* extension = service()->GetExtensionById(good0, true);
[email protected]386db3572013-11-08 12:26:445436 ASSERT_TRUE(extension);
[email protected]f484f8d52014-06-12 08:38:185437 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
[email protected]21db9ef2014-05-16 02:06:275438 extensions::ExtensionSyncData disable_good_crx(
5439 *extension, false, false, false);
[email protected]386db3572013-11-08 12:26:445440
5441 // Then sync data arrives telling us to disable |good0|.
5442 syncer::SyncDataList sync_data;
5443 sync_data.push_back(disable_good_crx.GetSyncData());
[email protected]f484f8d52014-06-12 08:38:185444 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255445 syncer::EXTENSIONS,
5446 sync_data,
5447 scoped_ptr<syncer::SyncChangeProcessor>(
5448 new syncer::FakeSyncChangeProcessor),
[email protected]386db3572013-11-08 12:26:445449 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]f484f8d52014-06-12 08:38:185450 ASSERT_FALSE(service()->IsExtensionEnabled(good0));
[email protected]386db3572013-11-08 12:26:445451}
5452
5453TEST_F(ExtensionServiceTest, DontDisableExtensionWithPendingEnableFromSync) {
5454 // Start the extensions service with one external extension already installed.
[email protected]f484f8d52014-06-12 08:38:185455 base::FilePath source_install_dir =
5456 data_dir().AppendASCII("good").AppendASCII("Extensions");
[email protected]e96a0602014-02-15 08:27:425457 base::FilePath pref_path =
5458 source_install_dir.DirName().Append(chrome::kPreferencesFilename);
[email protected]386db3572013-11-08 12:26:445459
5460 InitializeInstalledExtensionService(pref_path, source_install_dir);
5461 InitializeExtensionSyncService();
5462
5463 // The user has enabled sync.
5464 ProfileSyncService* sync_service =
[email protected]f484f8d52014-06-12 08:38:185465 ProfileSyncServiceFactory::GetForProfile(profile());
[email protected]386db3572013-11-08 12:26:445466 sync_service->SetSyncSetupCompleted();
5467
[email protected]f484f8d52014-06-12 08:38:185468 service()->Init();
5469 ASSERT_TRUE(service()->is_ready());
[email protected]386db3572013-11-08 12:26:445470 ASSERT_EQ(3u, loaded_.size());
5471
[email protected]f484f8d52014-06-12 08:38:185472 const Extension* extension = service()->GetExtensionById(good0, true);
5473 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
[email protected]386db3572013-11-08 12:26:445474
5475 // Disable extension before first sync data arrives.
[email protected]f484f8d52014-06-12 08:38:185476 service()->DisableExtension(good0, Extension::DISABLE_USER_ACTION);
5477 ASSERT_FALSE(service()->IsExtensionEnabled(good0));
[email protected]386db3572013-11-08 12:26:445478
5479 // Enable extension - this is now the most recent state.
[email protected]f484f8d52014-06-12 08:38:185480 service()->EnableExtension(good0);
5481 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
[email protected]386db3572013-11-08 12:26:445482
5483 // Now sync data comes in that says to disable good0. This should be
5484 // ignored.
[email protected]21db9ef2014-05-16 02:06:275485 extensions::ExtensionSyncData disable_good_crx(
5486 *extension, false, false, false);
[email protected]386db3572013-11-08 12:26:445487 syncer::SyncDataList sync_data;
5488 sync_data.push_back(disable_good_crx.GetSyncData());
[email protected]f484f8d52014-06-12 08:38:185489 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255490 syncer::EXTENSIONS,
5491 sync_data,
5492 scoped_ptr<syncer::SyncChangeProcessor>(
5493 new syncer::FakeSyncChangeProcessor),
[email protected]386db3572013-11-08 12:26:445494 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
5495
5496 // The extension was enabled locally before the sync data arrived, so it
5497 // should still be enabled now.
[email protected]f484f8d52014-06-12 08:38:185498 ASSERT_TRUE(service()->IsExtensionEnabled(good0));
[email protected]386db3572013-11-08 12:26:445499}
5500
[email protected]d9a61e12012-11-14 02:43:475501TEST_F(ExtensionServiceTest, GetSyncData) {
[email protected]b05fb9ff2011-04-23 00:07:565502 InitializeEmptyExtensionService();
[email protected]f8aefb132013-10-30 09:29:525503 InitializeExtensionSyncService();
[email protected]f484f8d52014-06-12 08:38:185504 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5505 const Extension* extension = service()->GetInstalledExtension(good_crx);
[email protected]b05fb9ff2011-04-23 00:07:565506 ASSERT_TRUE(extension);
[email protected]85fc9202011-05-05 00:04:595507
[email protected]f484f8d52014-06-12 08:38:185508 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255509 syncer::EXTENSIONS,
5510 syncer::SyncDataList(),
5511 scoped_ptr<syncer::SyncChangeProcessor>(
5512 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585513 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]3bdba0d2011-08-23 07:17:305514
[email protected]f484f8d52014-06-12 08:38:185515 syncer::SyncDataList list =
5516 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
[email protected]3bdba0d2011-08-23 07:17:305517 ASSERT_EQ(list.size(), 1U);
[email protected]5db9ada2012-04-11 13:48:205518 extensions::ExtensionSyncData data(list[0]);
[email protected]3bdba0d2011-08-23 07:17:305519 EXPECT_EQ(extension->id(), data.id());
5520 EXPECT_FALSE(data.uninstalled());
[email protected]f484f8d52014-06-12 08:38:185521 EXPECT_EQ(service()->IsExtensionEnabled(good_crx), data.enabled());
5522 EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile()),
[email protected]a7ff4b72013-10-17 20:56:025523 data.incognito_enabled());
[email protected]3bdba0d2011-08-23 07:17:305524 EXPECT_TRUE(data.version().Equals(*extension->version()));
[email protected]65348062013-01-15 07:27:225525 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension),
5526 data.update_url());
[email protected]3bdba0d2011-08-23 07:17:305527 EXPECT_EQ(extension->name(), data.name());
[email protected]b05fb9ff2011-04-23 00:07:565528}
5529
[email protected]d9a61e12012-11-14 02:43:475530TEST_F(ExtensionServiceTest, GetSyncDataTerminated) {
[email protected]45b6fee2011-05-03 09:41:315531 InitializeEmptyExtensionService();
[email protected]f8aefb132013-10-30 09:29:525532 InitializeExtensionSyncService();
[email protected]f484f8d52014-06-12 08:38:185533 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
[email protected]45b6fee2011-05-03 09:41:315534 TerminateExtension(good_crx);
[email protected]f484f8d52014-06-12 08:38:185535 const Extension* extension = service()->GetInstalledExtension(good_crx);
[email protected]85fc9202011-05-05 00:04:595536 ASSERT_TRUE(extension);
[email protected]3bdba0d2011-08-23 07:17:305537
[email protected]d0b23522014-02-19 02:15:255538 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:185539 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255540 syncer::EXTENSIONS,
5541 syncer::SyncDataList(),
5542 scoped_ptr<syncer::SyncChangeProcessor>(
5543 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585544 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]3bdba0d2011-08-23 07:17:305545
[email protected]f484f8d52014-06-12 08:38:185546 syncer::SyncDataList list =
5547 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
[email protected]3bdba0d2011-08-23 07:17:305548 ASSERT_EQ(list.size(), 1U);
[email protected]5db9ada2012-04-11 13:48:205549 extensions::ExtensionSyncData data(list[0]);
[email protected]3bdba0d2011-08-23 07:17:305550 EXPECT_EQ(extension->id(), data.id());
5551 EXPECT_FALSE(data.uninstalled());
[email protected]f484f8d52014-06-12 08:38:185552 EXPECT_EQ(service()->IsExtensionEnabled(good_crx), data.enabled());
5553 EXPECT_EQ(extensions::util::IsIncognitoEnabled(good_crx, profile()),
[email protected]a7ff4b72013-10-17 20:56:025554 data.incognito_enabled());
[email protected]3bdba0d2011-08-23 07:17:305555 EXPECT_TRUE(data.version().Equals(*extension->version()));
[email protected]65348062013-01-15 07:27:225556 EXPECT_EQ(extensions::ManifestURL::GetUpdateURL(extension),
5557 data.update_url());
[email protected]3bdba0d2011-08-23 07:17:305558 EXPECT_EQ(extension->name(), data.name());
[email protected]45b6fee2011-05-03 09:41:315559}
5560
[email protected]d9a61e12012-11-14 02:43:475561TEST_F(ExtensionServiceTest, GetSyncDataFilter) {
[email protected]b05fb9ff2011-04-23 00:07:565562 InitializeEmptyExtensionService();
[email protected]f8aefb132013-10-30 09:29:525563 InitializeExtensionSyncService();
[email protected]f484f8d52014-06-12 08:38:185564 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5565 const Extension* extension = service()->GetInstalledExtension(good_crx);
[email protected]85fc9202011-05-05 00:04:595566 ASSERT_TRUE(extension);
[email protected]3bdba0d2011-08-23 07:17:305567
[email protected]d0b23522014-02-19 02:15:255568 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:185569 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255570 syncer::APPS,
[email protected]f8aefb132013-10-30 09:29:525571 syncer::SyncDataList(),
[email protected]d0b23522014-02-19 02:15:255572 scoped_ptr<syncer::SyncChangeProcessor>(
5573 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585574 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]3bdba0d2011-08-23 07:17:305575
[email protected]f484f8d52014-06-12 08:38:185576 syncer::SyncDataList list =
5577 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
[email protected]3bdba0d2011-08-23 07:17:305578 ASSERT_EQ(list.size(), 0U);
[email protected]b05fb9ff2011-04-23 00:07:565579}
5580
[email protected]d9a61e12012-11-14 02:43:475581TEST_F(ExtensionServiceTest, GetSyncExtensionDataUserSettings) {
[email protected]b05fb9ff2011-04-23 00:07:565582 InitializeEmptyExtensionService();
[email protected]98b6d942013-11-10 00:34:075583 InitializeProcessManager();
[email protected]f8aefb132013-10-30 09:29:525584 InitializeExtensionSyncService();
[email protected]f484f8d52014-06-12 08:38:185585 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5586 const Extension* extension = service()->GetInstalledExtension(good_crx);
[email protected]85fc9202011-05-05 00:04:595587 ASSERT_TRUE(extension);
[email protected]b05fb9ff2011-04-23 00:07:565588
[email protected]d0b23522014-02-19 02:15:255589 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:185590 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255591 syncer::EXTENSIONS,
5592 syncer::SyncDataList(),
5593 scoped_ptr<syncer::SyncChangeProcessor>(
5594 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585595 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]3bdba0d2011-08-23 07:17:305596
[email protected]b05fb9ff2011-04-23 00:07:565597 {
[email protected]f484f8d52014-06-12 08:38:185598 syncer::SyncDataList list =
5599 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
[email protected]3bdba0d2011-08-23 07:17:305600 ASSERT_EQ(list.size(), 1U);
[email protected]5db9ada2012-04-11 13:48:205601 extensions::ExtensionSyncData data(list[0]);
[email protected]386db3572013-11-08 12:26:445602 EXPECT_TRUE(data.enabled());
5603 EXPECT_FALSE(data.incognito_enabled());
5604 }
5605
[email protected]f484f8d52014-06-12 08:38:185606 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
[email protected]386db3572013-11-08 12:26:445607 {
[email protected]f484f8d52014-06-12 08:38:185608 syncer::SyncDataList list =
5609 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
[email protected]386db3572013-11-08 12:26:445610 ASSERT_EQ(list.size(), 1U);
5611 extensions::ExtensionSyncData data(list[0]);
5612 EXPECT_FALSE(data.enabled());
[email protected]3bdba0d2011-08-23 07:17:305613 EXPECT_FALSE(data.incognito_enabled());
[email protected]b05fb9ff2011-04-23 00:07:565614 }
5615
[email protected]f484f8d52014-06-12 08:38:185616 extensions::util::SetIsIncognitoEnabled(good_crx, profile(), true);
[email protected]b05fb9ff2011-04-23 00:07:565617 {
[email protected]f484f8d52014-06-12 08:38:185618 syncer::SyncDataList list =
5619 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
[email protected]3bdba0d2011-08-23 07:17:305620 ASSERT_EQ(list.size(), 1U);
[email protected]5db9ada2012-04-11 13:48:205621 extensions::ExtensionSyncData data(list[0]);
[email protected]386db3572013-11-08 12:26:445622 EXPECT_FALSE(data.enabled());
5623 EXPECT_TRUE(data.incognito_enabled());
5624 }
5625
[email protected]f484f8d52014-06-12 08:38:185626 service()->EnableExtension(good_crx);
[email protected]386db3572013-11-08 12:26:445627 {
[email protected]f484f8d52014-06-12 08:38:185628 syncer::SyncDataList list =
5629 extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS);
[email protected]386db3572013-11-08 12:26:445630 ASSERT_EQ(list.size(), 1U);
5631 extensions::ExtensionSyncData data(list[0]);
5632 EXPECT_TRUE(data.enabled());
[email protected]3bdba0d2011-08-23 07:17:305633 EXPECT_TRUE(data.incognito_enabled());
[email protected]b05fb9ff2011-04-23 00:07:565634 }
5635}
5636
[email protected]d9a61e12012-11-14 02:43:475637TEST_F(ExtensionServiceTest, SyncForUninstalledExternalExtension) {
[email protected]e8b0f252012-05-05 09:44:425638 InitializeEmptyExtensionService();
[email protected]f8aefb132013-10-30 09:29:525639 InitializeExtensionSyncService();
[email protected]f484f8d52014-06-12 08:38:185640 InstallCRXWithLocation(
5641 data_dir().AppendASCII("good.crx"), Manifest::EXTERNAL_PREF, INSTALL_NEW);
5642 const Extension* extension = service()->GetInstalledExtension(good_crx);
[email protected]e8b0f252012-05-05 09:44:425643 ASSERT_TRUE(extension);
5644
[email protected]d0b23522014-02-19 02:15:255645 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:185646 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255647 syncer::EXTENSIONS,
5648 syncer::SyncDataList(),
5649 scoped_ptr<syncer::SyncChangeProcessor>(
5650 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585651 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]e8b0f252012-05-05 09:44:425652
5653 UninstallExtension(good_crx, false);
[email protected]f484f8d52014-06-12 08:38:185654 EXPECT_TRUE(
5655 ExtensionPrefs::Get(profile())->IsExternalExtensionUninstalled(good_crx));
[email protected]e8b0f252012-05-05 09:44:425656
5657 sync_pb::EntitySpecifics specifics;
5658 sync_pb::AppSpecifics* app_specifics = specifics.mutable_app();
5659 sync_pb::ExtensionSpecifics* extension_specifics =
5660 app_specifics->mutable_extension();
5661 extension_specifics->set_id(good_crx);
5662 extension_specifics->set_version("1.0");
[email protected]386db3572013-11-08 12:26:445663 extension_specifics->set_enabled(true);
[email protected]e8b0f252012-05-05 09:44:425664
[email protected]65f173552012-06-28 22:43:585665 syncer::SyncData sync_data =
5666 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
[email protected]b78170f2012-07-11 03:34:265667 syncer::SyncChange sync_change(FROM_HERE,
5668 syncer::SyncChange::ACTION_UPDATE,
5669 sync_data);
[email protected]65f173552012-06-28 22:43:585670 syncer::SyncChangeList list(1);
[email protected]e8b0f252012-05-05 09:44:425671 list[0] = sync_change;
5672
[email protected]f484f8d52014-06-12 08:38:185673 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5674 EXPECT_TRUE(
5675 ExtensionPrefs::Get(profile())->IsExternalExtensionUninstalled(good_crx));
[email protected]e8b0f252012-05-05 09:44:425676}
5677
[email protected]d9a61e12012-11-14 02:43:475678TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettings) {
[email protected]168389f2011-12-20 17:12:485679 InitializeEmptyExtensionService();
[email protected]f8aefb132013-10-30 09:29:525680 InitializeExtensionSyncService();
[email protected]168389f2011-12-20 17:12:485681 const Extension* app =
[email protected]f484f8d52014-06-12 08:38:185682 PackAndInstallCRX(data_dir().AppendASCII("app"), INSTALL_NEW);
[email protected]168389f2011-12-20 17:12:485683 ASSERT_TRUE(app);
5684 ASSERT_TRUE(app->is_app());
5685
[email protected]d0b23522014-02-19 02:15:255686 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:185687 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255688 syncer::APPS,
[email protected]f8aefb132013-10-30 09:29:525689 syncer::SyncDataList(),
[email protected]d0b23522014-02-19 02:15:255690 scoped_ptr<syncer::SyncChangeProcessor>(
5691 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585692 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]168389f2011-12-20 17:12:485693
[email protected]36b643212012-09-07 12:53:005694 syncer::StringOrdinal initial_ordinal =
5695 syncer::StringOrdinal::CreateInitialOrdinal();
[email protected]168389f2011-12-20 17:12:485696 {
[email protected]f484f8d52014-06-12 08:38:185697 syncer::SyncDataList list =
5698 extension_sync_service()->GetAllSyncData(syncer::APPS);
[email protected]168389f2011-12-20 17:12:485699 ASSERT_EQ(list.size(), 1U);
[email protected]5db9ada2012-04-11 13:48:205700
5701 extensions::AppSyncData app_sync_data(list[0]);
[email protected]36b643212012-09-07 12:53:005702 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.app_launch_ordinal()));
5703 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal()));
[email protected]168389f2011-12-20 17:12:485704 }
5705
[email protected]f484f8d52014-06-12 08:38:185706 AppSorting* sorting = ExtensionPrefs::Get(profile())->app_sorting();
[email protected]fb82dcd2012-03-21 14:15:465707 sorting->SetAppLaunchOrdinal(app->id(), initial_ordinal.CreateAfter());
[email protected]168389f2011-12-20 17:12:485708 {
[email protected]f484f8d52014-06-12 08:38:185709 syncer::SyncDataList list =
5710 extension_sync_service()->GetAllSyncData(syncer::APPS);
[email protected]168389f2011-12-20 17:12:485711 ASSERT_EQ(list.size(), 1U);
[email protected]5db9ada2012-04-11 13:48:205712
5713 extensions::AppSyncData app_sync_data(list[0]);
5714 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal()));
[email protected]36b643212012-09-07 12:53:005715 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal()));
[email protected]168389f2011-12-20 17:12:485716 }
5717
[email protected]fb82dcd2012-03-21 14:15:465718 sorting->SetPageOrdinal(app->id(), initial_ordinal.CreateAfter());
[email protected]168389f2011-12-20 17:12:485719 {
[email protected]f484f8d52014-06-12 08:38:185720 syncer::SyncDataList list =
5721 extension_sync_service()->GetAllSyncData(syncer::APPS);
[email protected]168389f2011-12-20 17:12:485722 ASSERT_EQ(list.size(), 1U);
[email protected]5db9ada2012-04-11 13:48:205723
5724 extensions::AppSyncData app_sync_data(list[0]);
5725 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal()));
5726 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.page_ordinal()));
[email protected]168389f2011-12-20 17:12:485727 }
5728}
5729
[email protected]74c5ea12014-03-19 23:14:395730// TODO (rdevlin.cronin): The OnExtensionMoved() method has been removed from
5731// ExtensionService, so this test probably needs a new home. Unfortunately, it
5732// relies pretty heavily on things like InitializeExtension[Sync]Service() and
5733// PackAndInstallCRX(). When we clean up a bit more, this should move out.
[email protected]d9a61e12012-11-14 02:43:475734TEST_F(ExtensionServiceTest, GetSyncAppDataUserSettingsOnExtensionMoved) {
[email protected]168389f2011-12-20 17:12:485735 InitializeEmptyExtensionService();
[email protected]f8aefb132013-10-30 09:29:525736 InitializeExtensionSyncService();
[email protected]168389f2011-12-20 17:12:485737 const size_t kAppCount = 3;
5738 const Extension* apps[kAppCount];
[email protected]f484f8d52014-06-12 08:38:185739 apps[0] = PackAndInstallCRX(data_dir().AppendASCII("app1"), INSTALL_NEW);
5740 apps[1] = PackAndInstallCRX(data_dir().AppendASCII("app2"), INSTALL_NEW);
5741 apps[2] = PackAndInstallCRX(data_dir().AppendASCII("app4"), INSTALL_NEW);
[email protected]168389f2011-12-20 17:12:485742 for (size_t i = 0; i < kAppCount; ++i) {
5743 ASSERT_TRUE(apps[i]);
5744 ASSERT_TRUE(apps[i]->is_app());
5745 }
5746
[email protected]d0b23522014-02-19 02:15:255747 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:185748 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255749 syncer::APPS,
[email protected]f8aefb132013-10-30 09:29:525750 syncer::SyncDataList(),
[email protected]d0b23522014-02-19 02:15:255751 scoped_ptr<syncer::SyncChangeProcessor>(
5752 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585753 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]168389f2011-12-20 17:12:485754
[email protected]f484f8d52014-06-12 08:38:185755 ExtensionPrefs::Get(service()->GetBrowserContext())
[email protected]74c5ea12014-03-19 23:14:395756 ->app_sorting()
5757 ->OnExtensionMoved(apps[0]->id(), apps[1]->id(), apps[2]->id());
[email protected]168389f2011-12-20 17:12:485758 {
[email protected]f484f8d52014-06-12 08:38:185759 syncer::SyncDataList list =
5760 extension_sync_service()->GetAllSyncData(syncer::APPS);
[email protected]168389f2011-12-20 17:12:485761 ASSERT_EQ(list.size(), 3U);
[email protected]5db9ada2012-04-11 13:48:205762
5763 extensions::AppSyncData data[kAppCount];
[email protected]bb05cae12012-09-06 00:37:525764 for (size_t i = 0; i < kAppCount; ++i) {
[email protected]5db9ada2012-04-11 13:48:205765 data[i] = extensions::AppSyncData(list[i]);
5766 }
[email protected]168389f2011-12-20 17:12:485767
5768 // The sync data is not always in the same order our apps were installed in,
5769 // so we do that sorting here so we can make sure the values are changed as
5770 // expected.
[email protected]36b643212012-09-07 12:53:005771 syncer::StringOrdinal app_launch_ordinals[kAppCount];
[email protected]168389f2011-12-20 17:12:485772 for (size_t i = 0; i < kAppCount; ++i) {
5773 for (size_t j = 0; j < kAppCount; ++j) {
5774 if (apps[i]->id() == data[j].id())
5775 app_launch_ordinals[i] = data[j].app_launch_ordinal();
5776 }
5777 }
5778
5779 EXPECT_TRUE(app_launch_ordinals[1].LessThan(app_launch_ordinals[0]));
5780 EXPECT_TRUE(app_launch_ordinals[0].LessThan(app_launch_ordinals[2]));
5781 }
5782}
5783
[email protected]d9a61e12012-11-14 02:43:475784TEST_F(ExtensionServiceTest, GetSyncDataList) {
[email protected]b05fb9ff2011-04-23 00:07:565785 InitializeEmptyExtensionService();
[email protected]f8aefb132013-10-30 09:29:525786 InitializeExtensionSyncService();
[email protected]f484f8d52014-06-12 08:38:185787 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5788 InstallCRX(data_dir().AppendASCII("page_action.crx"), INSTALL_NEW);
5789 InstallCRX(data_dir().AppendASCII("theme.crx"), INSTALL_NEW);
5790 InstallCRX(data_dir().AppendASCII("theme2.crx"), INSTALL_NEW);
[email protected]b05fb9ff2011-04-23 00:07:565791
[email protected]d0b23522014-02-19 02:15:255792 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:185793 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255794 syncer::APPS,
5795 syncer::SyncDataList(),
5796 scoped_ptr<syncer::SyncChangeProcessor>(
5797 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585798 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]f484f8d52014-06-12 08:38:185799 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255800 syncer::EXTENSIONS,
5801 syncer::SyncDataList(),
5802 scoped_ptr<syncer::SyncChangeProcessor>(
5803 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585804 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]3bdba0d2011-08-23 07:17:305805
[email protected]f484f8d52014-06-12 08:38:185806 service()->DisableExtension(page_action, Extension::DISABLE_USER_ACTION);
[email protected]45b6fee2011-05-03 09:41:315807 TerminateExtension(theme2_crx);
[email protected]b05fb9ff2011-04-23 00:07:565808
[email protected]f484f8d52014-06-12 08:38:185809 EXPECT_EQ(0u, extension_sync_service()->GetAllSyncData(syncer::APPS).size());
5810 EXPECT_EQ(
5811 2u, extension_sync_service()->GetAllSyncData(syncer::EXTENSIONS).size());
[email protected]b05fb9ff2011-04-23 00:07:565812}
5813
[email protected]d9a61e12012-11-14 02:43:475814TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) {
[email protected]90310d92011-04-17 07:35:045815 InitializeEmptyExtensionService();
[email protected]f8aefb132013-10-30 09:29:525816 InitializeExtensionSyncService();
[email protected]d0b23522014-02-19 02:15:255817 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:185818 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255819 syncer::EXTENSIONS,
5820 syncer::SyncDataList(),
5821 scoped_ptr<syncer::SyncChangeProcessor>(
5822 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585823 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]90310d92011-04-17 07:35:045824
[email protected]3bdba0d2011-08-23 07:17:305825 sync_pb::EntitySpecifics specifics;
[email protected]4557d222012-03-04 23:33:365826 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
[email protected]3bdba0d2011-08-23 07:17:305827 ext_specifics->set_id(good_crx);
5828 ext_specifics->set_version("1.0");
[email protected]65f173552012-06-28 22:43:585829 syncer::SyncData sync_data =
5830 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
[email protected]b78170f2012-07-11 03:34:265831 syncer::SyncChange sync_change(FROM_HERE,
5832 syncer::SyncChange::ACTION_DELETE,
5833 sync_data);
[email protected]65f173552012-06-28 22:43:585834 syncer::SyncChangeList list(1);
[email protected]3bdba0d2011-08-23 07:17:305835 list[0] = sync_change;
[email protected]90310d92011-04-17 07:35:045836
5837 // Should do nothing.
[email protected]f484f8d52014-06-12 08:38:185838 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5839 EXPECT_FALSE(service()->GetExtensionById(good_crx, true));
[email protected]90310d92011-04-17 07:35:045840
5841 // Install the extension.
[email protected]f484f8d52014-06-12 08:38:185842 base::FilePath extension_path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:505843 InstallCRX(extension_path, INSTALL_NEW);
[email protected]f484f8d52014-06-12 08:38:185844 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
[email protected]90310d92011-04-17 07:35:045845
5846 // Should uninstall the extension.
[email protected]f484f8d52014-06-12 08:38:185847 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5848 EXPECT_FALSE(service()->GetExtensionById(good_crx, true));
[email protected]90310d92011-04-17 07:35:045849
5850 // Should again do nothing.
[email protected]f484f8d52014-06-12 08:38:185851 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5852 EXPECT_FALSE(service()->GetExtensionById(good_crx, true));
[email protected]90310d92011-04-17 07:35:045853}
5854
[email protected]d9a61e12012-11-14 02:43:475855TEST_F(ExtensionServiceTest, ProcessSyncDataWrongType) {
[email protected]96e989b2011-08-30 19:35:065856 InitializeEmptyExtensionService();
[email protected]f8aefb132013-10-30 09:29:525857 InitializeExtensionSyncService();
[email protected]96e989b2011-08-30 19:35:065858
5859 // Install the extension.
[email protected]f484f8d52014-06-12 08:38:185860 base::FilePath extension_path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:505861 InstallCRX(extension_path, INSTALL_NEW);
[email protected]f484f8d52014-06-12 08:38:185862 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
[email protected]96e989b2011-08-30 19:35:065863
5864 sync_pb::EntitySpecifics specifics;
[email protected]4557d222012-03-04 23:33:365865 sync_pb::AppSpecifics* app_specifics = specifics.mutable_app();
[email protected]96e989b2011-08-30 19:35:065866 sync_pb::ExtensionSpecifics* extension_specifics =
5867 app_specifics->mutable_extension();
5868 extension_specifics->set_id(good_crx);
5869 extension_specifics->set_version(
[email protected]f484f8d52014-06-12 08:38:185870 service()->GetInstalledExtension(good_crx)->version()->GetString());
[email protected]96e989b2011-08-30 19:35:065871
5872 {
[email protected]386db3572013-11-08 12:26:445873 extension_specifics->set_enabled(true);
[email protected]65f173552012-06-28 22:43:585874 syncer::SyncData sync_data =
5875 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
[email protected]b78170f2012-07-11 03:34:265876 syncer::SyncChange sync_change(FROM_HERE,
5877 syncer::SyncChange::ACTION_DELETE,
5878 sync_data);
[email protected]65f173552012-06-28 22:43:585879 syncer::SyncChangeList list(1);
[email protected]96e989b2011-08-30 19:35:065880 list[0] = sync_change;
5881
5882 // Should do nothing
[email protected]f484f8d52014-06-12 08:38:185883 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5884 EXPECT_TRUE(service()->GetExtensionById(good_crx, true));
[email protected]96e989b2011-08-30 19:35:065885 }
5886
5887 {
[email protected]386db3572013-11-08 12:26:445888 extension_specifics->set_enabled(false);
[email protected]65f173552012-06-28 22:43:585889 syncer::SyncData sync_data =
5890 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
[email protected]b78170f2012-07-11 03:34:265891 syncer::SyncChange sync_change(FROM_HERE,
5892 syncer::SyncChange::ACTION_UPDATE,
5893 sync_data);
[email protected]65f173552012-06-28 22:43:585894 syncer::SyncChangeList list(1);
[email protected]96e989b2011-08-30 19:35:065895 list[0] = sync_change;
5896
5897 // Should again do nothing.
[email protected]f484f8d52014-06-12 08:38:185898 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5899 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
[email protected]96e989b2011-08-30 19:35:065900 }
5901}
5902
[email protected]d9a61e12012-11-14 02:43:475903TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) {
[email protected]90310d92011-04-17 07:35:045904 InitializeEmptyExtensionService();
[email protected]98b6d942013-11-10 00:34:075905 InitializeProcessManager();
[email protected]f8aefb132013-10-30 09:29:525906 InitializeExtensionSyncService();
[email protected]d0b23522014-02-19 02:15:255907 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:185908 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255909 syncer::EXTENSIONS,
5910 syncer::SyncDataList(),
5911 scoped_ptr<syncer::SyncChangeProcessor>(
5912 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585913 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]90310d92011-04-17 07:35:045914
[email protected]f484f8d52014-06-12 08:38:185915 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
5916 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
5917 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
[email protected]90310d92011-04-17 07:35:045918
[email protected]3bdba0d2011-08-23 07:17:305919 sync_pb::EntitySpecifics specifics;
[email protected]4557d222012-03-04 23:33:365920 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
[email protected]3bdba0d2011-08-23 07:17:305921 ext_specifics->set_id(good_crx);
5922 ext_specifics->set_version(
[email protected]f484f8d52014-06-12 08:38:185923 service()->GetInstalledExtension(good_crx)->version()->GetString());
[email protected]386db3572013-11-08 12:26:445924 ext_specifics->set_enabled(false);
[email protected]90310d92011-04-17 07:35:045925
[email protected]3bdba0d2011-08-23 07:17:305926 {
[email protected]65f173552012-06-28 22:43:585927 syncer::SyncData sync_data =
5928 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
[email protected]b78170f2012-07-11 03:34:265929 syncer::SyncChange sync_change(FROM_HERE,
5930 syncer::SyncChange::ACTION_UPDATE,
5931 sync_data);
[email protected]65f173552012-06-28 22:43:585932 syncer::SyncChangeList list(1);
[email protected]3bdba0d2011-08-23 07:17:305933 list[0] = sync_change;
[email protected]f484f8d52014-06-12 08:38:185934 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5935 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
5936 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
[email protected]3bdba0d2011-08-23 07:17:305937 }
[email protected]90310d92011-04-17 07:35:045938
[email protected]3bdba0d2011-08-23 07:17:305939 {
[email protected]386db3572013-11-08 12:26:445940 ext_specifics->set_enabled(true);
[email protected]3bdba0d2011-08-23 07:17:305941 ext_specifics->set_incognito_enabled(true);
[email protected]65f173552012-06-28 22:43:585942 syncer::SyncData sync_data =
5943 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
[email protected]b78170f2012-07-11 03:34:265944 syncer::SyncChange sync_change(FROM_HERE,
5945 syncer::SyncChange::ACTION_UPDATE,
5946 sync_data);
[email protected]65f173552012-06-28 22:43:585947 syncer::SyncChangeList list(1);
[email protected]3bdba0d2011-08-23 07:17:305948 list[0] = sync_change;
[email protected]f484f8d52014-06-12 08:38:185949 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5950 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
5951 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
[email protected]3bdba0d2011-08-23 07:17:305952 }
[email protected]90310d92011-04-17 07:35:045953
[email protected]386db3572013-11-08 12:26:445954 {
5955 ext_specifics->set_enabled(false);
5956 ext_specifics->set_incognito_enabled(true);
5957 syncer::SyncData sync_data =
5958 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
5959 syncer::SyncChange sync_change(FROM_HERE,
5960 syncer::SyncChange::ACTION_UPDATE,
5961 sync_data);
5962 syncer::SyncChangeList list(1);
5963 list[0] = sync_change;
[email protected]f484f8d52014-06-12 08:38:185964 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
5965 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
5966 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
[email protected]386db3572013-11-08 12:26:445967 }
5968
[email protected]f484f8d52014-06-12 08:38:185969 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
[email protected]90310d92011-04-17 07:35:045970}
5971
[email protected]d9a61e12012-11-14 02:43:475972TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) {
[email protected]fa2416f2011-05-03 08:41:205973 InitializeExtensionServiceWithUpdater();
[email protected]f8aefb132013-10-30 09:29:525974 InitializeExtensionSyncService();
[email protected]d0b23522014-02-19 02:15:255975 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:185976 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:255977 syncer::EXTENSIONS,
5978 syncer::SyncDataList(),
5979 scoped_ptr<syncer::SyncChangeProcessor>(
5980 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:585981 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]fa2416f2011-05-03 08:41:205982
[email protected]f484f8d52014-06-12 08:38:185983 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
[email protected]fa2416f2011-05-03 08:41:205984 TerminateExtension(good_crx);
[email protected]f484f8d52014-06-12 08:38:185985 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
5986 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
[email protected]fa2416f2011-05-03 08:41:205987
[email protected]3bdba0d2011-08-23 07:17:305988 sync_pb::EntitySpecifics specifics;
[email protected]4557d222012-03-04 23:33:365989 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
[email protected]3bdba0d2011-08-23 07:17:305990 ext_specifics->set_id(good_crx);
5991 ext_specifics->set_version(
[email protected]f484f8d52014-06-12 08:38:185992 service()->GetInstalledExtension(good_crx)->version()->GetString());
[email protected]386db3572013-11-08 12:26:445993 ext_specifics->set_enabled(false);
[email protected]3bdba0d2011-08-23 07:17:305994 ext_specifics->set_incognito_enabled(true);
[email protected]65f173552012-06-28 22:43:585995 syncer::SyncData sync_data =
5996 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
[email protected]b78170f2012-07-11 03:34:265997 syncer::SyncChange sync_change(FROM_HERE,
5998 syncer::SyncChange::ACTION_UPDATE,
5999 sync_data);
[email protected]65f173552012-06-28 22:43:586000 syncer::SyncChangeList list(1);
[email protected]3bdba0d2011-08-23 07:17:306001 list[0] = sync_change;
6002
[email protected]f484f8d52014-06-12 08:38:186003 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6004 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6005 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
[email protected]fa2416f2011-05-03 08:41:206006
[email protected]f484f8d52014-06-12 08:38:186007 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
[email protected]fa2416f2011-05-03 08:41:206008}
6009
[email protected]d9a61e12012-11-14 02:43:476010TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) {
[email protected]90310d92011-04-17 07:35:046011 InitializeExtensionServiceWithUpdater();
[email protected]f8aefb132013-10-30 09:29:526012 InitializeExtensionSyncService();
[email protected]d0b23522014-02-19 02:15:256013 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:186014 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:256015 syncer::EXTENSIONS,
6016 syncer::SyncDataList(),
6017 scoped_ptr<syncer::SyncChangeProcessor>(
6018 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:586019 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]90310d92011-04-17 07:35:046020
[email protected]f484f8d52014-06-12 08:38:186021 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
6022 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6023 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
[email protected]90310d92011-04-17 07:35:046024
[email protected]3bdba0d2011-08-23 07:17:306025 sync_pb::EntitySpecifics specifics;
[email protected]4557d222012-03-04 23:33:366026 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
[email protected]3bdba0d2011-08-23 07:17:306027 ext_specifics->set_id(good_crx);
[email protected]386db3572013-11-08 12:26:446028 ext_specifics->set_enabled(true);
[email protected]90310d92011-04-17 07:35:046029
[email protected]3bdba0d2011-08-23 07:17:306030 {
6031 ext_specifics->set_version(
[email protected]f484f8d52014-06-12 08:38:186032 service()->GetInstalledExtension(good_crx)->version()->GetString());
[email protected]65f173552012-06-28 22:43:586033 syncer::SyncData sync_data =
6034 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
[email protected]b78170f2012-07-11 03:34:266035 syncer::SyncChange sync_change(FROM_HERE,
6036 syncer::SyncChange::ACTION_UPDATE,
6037 sync_data);
[email protected]65f173552012-06-28 22:43:586038 syncer::SyncChangeList list(1);
[email protected]3bdba0d2011-08-23 07:17:306039 list[0] = sync_change;
6040
6041 // Should do nothing if extension version == sync version.
[email protected]f484f8d52014-06-12 08:38:186042 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6043 EXPECT_FALSE(service()->updater()->WillCheckSoon());
[email protected]3bdba0d2011-08-23 07:17:306044 }
[email protected]90310d92011-04-17 07:35:046045
6046 // Should do nothing if extension version > sync version (but see
[email protected]3bdba0d2011-08-23 07:17:306047 // the TODO in ProcessExtensionSyncData).
[email protected]90310d92011-04-17 07:35:046048 {
[email protected]3bdba0d2011-08-23 07:17:306049 ext_specifics->set_version("0.0.0.0");
[email protected]65f173552012-06-28 22:43:586050 syncer::SyncData sync_data =
6051 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
[email protected]b78170f2012-07-11 03:34:266052 syncer::SyncChange sync_change(FROM_HERE,
6053 syncer::SyncChange::ACTION_UPDATE,
6054 sync_data);
[email protected]65f173552012-06-28 22:43:586055 syncer::SyncChangeList list(1);
[email protected]3bdba0d2011-08-23 07:17:306056 list[0] = sync_change;
6057
[email protected]f484f8d52014-06-12 08:38:186058 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6059 EXPECT_FALSE(service()->updater()->WillCheckSoon());
[email protected]90310d92011-04-17 07:35:046060 }
6061
6062 // Should kick off an update if extension version < sync version.
6063 {
[email protected]3bdba0d2011-08-23 07:17:306064 ext_specifics->set_version("9.9.9.9");
[email protected]65f173552012-06-28 22:43:586065 syncer::SyncData sync_data =
6066 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
[email protected]b78170f2012-07-11 03:34:266067 syncer::SyncChange sync_change(FROM_HERE,
6068 syncer::SyncChange::ACTION_UPDATE,
6069 sync_data);
[email protected]65f173552012-06-28 22:43:586070 syncer::SyncChangeList list(1);
[email protected]3bdba0d2011-08-23 07:17:306071 list[0] = sync_change;
6072
[email protected]f484f8d52014-06-12 08:38:186073 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6074 EXPECT_TRUE(service()->updater()->WillCheckSoon());
[email protected]90310d92011-04-17 07:35:046075 }
6076
[email protected]f484f8d52014-06-12 08:38:186077 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(good_crx));
[email protected]90310d92011-04-17 07:35:046078}
6079
[email protected]d9a61e12012-11-14 02:43:476080TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) {
[email protected]90310d92011-04-17 07:35:046081 InitializeExtensionServiceWithUpdater();
[email protected]f8aefb132013-10-30 09:29:526082 InitializeExtensionSyncService();
[email protected]d0b23522014-02-19 02:15:256083 syncer::FakeSyncChangeProcessor processor;
[email protected]f484f8d52014-06-12 08:38:186084 extension_sync_service()->MergeDataAndStartSyncing(
[email protected]d0b23522014-02-19 02:15:256085 syncer::EXTENSIONS,
6086 syncer::SyncDataList(),
6087 scoped_ptr<syncer::SyncChangeProcessor>(
6088 new syncer::FakeSyncChangeProcessor),
[email protected]65f173552012-06-28 22:43:586089 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
[email protected]90310d92011-04-17 07:35:046090
[email protected]3bdba0d2011-08-23 07:17:306091 sync_pb::EntitySpecifics specifics;
[email protected]4557d222012-03-04 23:33:366092 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
[email protected]3bdba0d2011-08-23 07:17:306093 ext_specifics->set_id(good_crx);
[email protected]386db3572013-11-08 12:26:446094 ext_specifics->set_enabled(false);
[email protected]3bdba0d2011-08-23 07:17:306095 ext_specifics->set_incognito_enabled(true);
6096 ext_specifics->set_update_url("http://www.google.com/");
6097 ext_specifics->set_version("1.2.3.4");
[email protected]65f173552012-06-28 22:43:586098 syncer::SyncData sync_data =
6099 syncer::SyncData::CreateLocalData(good_crx, "Name", specifics);
[email protected]b78170f2012-07-11 03:34:266100 syncer::SyncChange sync_change(FROM_HERE,
6101 syncer::SyncChange::ACTION_UPDATE,
6102 sync_data);
[email protected]65f173552012-06-28 22:43:586103 syncer::SyncChangeList list(1);
[email protected]3bdba0d2011-08-23 07:17:306104 list[0] = sync_change;
6105
[email protected]f484f8d52014-06-12 08:38:186106 EXPECT_TRUE(service()->IsExtensionEnabled(good_crx));
6107 EXPECT_FALSE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
6108 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list);
6109 EXPECT_TRUE(service()->updater()->WillCheckSoon());
6110 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6111 EXPECT_TRUE(extensions::util::IsIncognitoEnabled(good_crx, profile()));
[email protected]90310d92011-04-17 07:35:046112
[email protected]3f213ad2012-07-26 23:39:416113 const extensions::PendingExtensionInfo* info;
[email protected]f484f8d52014-06-12 08:38:186114 EXPECT_TRUE(
6115 (info = service()->pending_extension_manager()->GetById(good_crx)));
[email protected]51a3bf8b2012-06-08 22:53:066116 EXPECT_EQ(ext_specifics->update_url(), info->update_url().spec());
6117 EXPECT_TRUE(info->is_from_sync());
6118 EXPECT_TRUE(info->install_silently());
[email protected]1d5e58b2013-01-31 08:41:406119 EXPECT_EQ(Manifest::INTERNAL, info->install_source());
[email protected]90310d92011-04-17 07:35:046120 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|.
6121}
6122
[email protected]343a0d872014-08-05 11:44:186123TEST_F(ExtensionServiceTest, SupervisedUser_InstallOnlyAllowedByCustodian) {
6124 ExtensionServiceInitParams params = CreateDefaultInitParams();
6125 params.profile_is_supervised = true;
6126 InitializeExtensionService(params);
6127
6128 SupervisedUserService* supervised_user_service =
6129 SupervisedUserServiceFactory::GetForProfile(profile());
6130 GetManagementPolicy()->RegisterProvider(supervised_user_service);
6131
6132 base::FilePath path1 = data_dir().AppendASCII("good.crx");
6133 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
6134 const Extension* extensions[] = {
6135 InstallCRX(path1, INSTALL_FAILED),
6136 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)
6137 };
6138
6139 // Only the extension with the "installed by custodian" flag should have been
6140 // installed and enabled.
6141 EXPECT_FALSE(extensions[0]);
6142 ASSERT_TRUE(extensions[1]);
6143 EXPECT_TRUE(registry()->enabled_extensions().Contains(extensions[1]->id()));
6144}
6145
6146TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithoutPermissionIncrease) {
6147 ExtensionServiceInitParams params = CreateDefaultInitParams();
6148 params.profile_is_supervised = true;
6149 InitializeExtensionService(params);
6150
6151 SupervisedUserService* supervised_user_service =
6152 SupervisedUserServiceFactory::GetForProfile(profile());
6153 GetManagementPolicy()->RegisterProvider(supervised_user_service);
6154
6155 base::FilePath base_path = data_dir().AppendASCII("autoupdate");
6156 base::FilePath pem_path = base_path.AppendASCII("key.pem");
6157
6158 base::FilePath path = base_path.AppendASCII("v1");
6159 const Extension* extension =
6160 PackAndInstallCRX(path, pem_path, INSTALL_NEW,
6161 Extension::WAS_INSTALLED_BY_CUSTODIAN);
6162 // The extension must now be installed and enabled.
6163 ASSERT_TRUE(extension);
6164 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
6165
6166 // Save the id, as the extension object will be destroyed during updating.
6167 std::string id = extension->id();
6168
6169 std::string old_version = extension->VersionString();
6170
6171 // Update to a new version.
6172 path = base_path.AppendASCII("v2");
6173 PackCRXAndUpdateExtension(id, path, pem_path, ENABLED);
6174
6175 // The extension should still be there and enabled.
6176 extension = registry()->enabled_extensions().GetByID(id);
6177 ASSERT_TRUE(extension);
6178 // The version should have changed.
6179 EXPECT_NE(extension->VersionString(), old_version);
6180}
6181
6182TEST_F(ExtensionServiceTest, SupervisedUser_UpdateWithPermissionIncrease) {
6183 ExtensionServiceInitParams params = CreateDefaultInitParams();
6184 params.profile_is_supervised = true;
6185 InitializeExtensionService(params);
6186
6187 SupervisedUserService* supervised_user_service =
6188 SupervisedUserServiceFactory::GetForProfile(profile());
6189 GetManagementPolicy()->RegisterProvider(supervised_user_service);
6190
6191 base::FilePath base_path = data_dir().AppendASCII("permissions_increase");
6192 base::FilePath pem_path = base_path.AppendASCII("permissions.pem");
6193
6194 base::FilePath path = base_path.AppendASCII("v1");
6195 const Extension* extension =
6196 PackAndInstallCRX(path, pem_path, INSTALL_NEW,
6197 Extension::WAS_INSTALLED_BY_CUSTODIAN);
6198 // The extension must now be installed and enabled.
6199 ASSERT_TRUE(extension);
6200 ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
6201
6202 // Save the id, as the extension object will be destroyed during updating.
6203 std::string id = extension->id();
6204
6205 std::string old_version = extension->VersionString();
6206
6207 // Update to a new version with increased permissions.
6208 path = base_path.AppendASCII("v2");
6209 PackCRXAndUpdateExtension(id, path, pem_path, DISABLED);
6210
6211 // The extension should still be there, but disabled.
6212 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
6213 extension = registry()->disabled_extensions().GetByID(id);
6214 ASSERT_TRUE(extension);
6215 // The version should have changed.
6216 EXPECT_NE(extension->VersionString(), old_version);
6217}
6218
6219TEST_F(ExtensionServiceTest,
6220 SupervisedUser_SyncUninstallByCustodianSkipsPolicy) {
[email protected]6ef60012014-07-22 19:08:126221 InitializeEmptyExtensionService();
6222 InitializeExtensionSyncService();
6223 extension_sync_service()->MergeDataAndStartSyncing(
6224 syncer::EXTENSIONS,
6225 syncer::SyncDataList(),
6226 scoped_ptr<syncer::SyncChangeProcessor>(
6227 new syncer::FakeSyncChangeProcessor),
6228 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
6229
6230 // Install two extensions.
6231 base::FilePath path1 = data_dir().AppendASCII("good.crx");
6232 base::FilePath path2 = data_dir().AppendASCII("good2048.crx");
[email protected]343a0d872014-08-05 11:44:186233 const Extension* extensions[] = {
[email protected]6ef60012014-07-22 19:08:126234 InstallCRX(path1, INSTALL_NEW),
6235 InstallCRX(path2, INSTALL_NEW, Extension::WAS_INSTALLED_BY_CUSTODIAN)
6236 };
6237
6238 // Add a policy provider that will disallow any changes.
6239 extensions::TestManagementPolicyProvider provider(
6240 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
6241 GetManagementPolicy()->RegisterProvider(&provider);
6242
6243 // Create a sync deletion for each extension.
6244 syncer::SyncChangeList change_list;
[email protected]343a0d872014-08-05 11:44:186245 for (size_t i = 0; i < arraysize(extensions); i++) {
[email protected]6ef60012014-07-22 19:08:126246 const std::string& id = extensions[i]->id();
6247 sync_pb::EntitySpecifics specifics;
6248 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension();
6249 ext_specifics->set_id(id);
6250 ext_specifics->set_version("1.0");
6251 ext_specifics->set_installed_by_custodian(
6252 extensions[i]->was_installed_by_custodian());
6253 syncer::SyncData sync_data =
6254 syncer::SyncData::CreateLocalData(id, "Name", specifics);
6255 change_list.push_back(syncer::SyncChange(FROM_HERE,
6256 syncer::SyncChange::ACTION_DELETE,
6257 sync_data));
6258 }
6259
6260 // Save the extension ids, as uninstalling destroys the Extension instance.
[email protected]343a0d872014-08-05 11:44:186261 std::string extension_ids[] = {
[email protected]6ef60012014-07-22 19:08:126262 extensions[0]->id(),
6263 extensions[1]->id()
6264 };
6265
6266 // Now apply the uninstallations.
6267 extension_sync_service()->ProcessSyncChanges(FROM_HERE, change_list);
6268
6269 // Uninstalling the extension without installed_by_custodian should have been
[email protected]343a0d872014-08-05 11:44:186270 // blocked by policy, so it should still be there.
6271 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_ids[0]));
[email protected]6ef60012014-07-22 19:08:126272
6273 // But installed_by_custodian should result in bypassing the policy check.
[email protected]343a0d872014-08-05 11:44:186274 EXPECT_FALSE(
6275 registry()->GenerateInstalledExtensionsSet()->Contains(extension_ids[1]));
[email protected]6ef60012014-07-22 19:08:126276}
6277
[email protected]d9a61e12012-11-14 02:43:476278TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) {
[email protected]8a87a5332011-08-11 17:54:596279 InitializeEmptyExtensionService();
6280
[email protected]f484f8d52014-06-12 08:38:186281 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]8f512c72011-11-22 21:02:506282 InstallCRX(path, INSTALL_NEW);
[email protected]8a87a5332011-08-11 17:54:596283 ValidatePrefKeyCount(1u);
6284 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:406285 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
[email protected]8a87a5332011-08-11 17:54:596286
[email protected]3f213ad2012-07-26 23:39:416287 extensions::PendingExtensionManager* pending =
[email protected]f484f8d52014-06-12 08:38:186288 service()->pending_extension_manager();
[email protected]8a87a5332011-08-11 17:54:596289 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6290
6291 // Skip install when the location is the same.
[email protected]f484f8d52014-06-12 08:38:186292 EXPECT_FALSE(
6293 service()->OnExternalExtensionUpdateUrlFound(kGoodId,
6294 std::string(),
6295 GURL(kGoodUpdateURL),
6296 Manifest::INTERNAL,
6297 Extension::NO_FLAGS,
6298 false));
[email protected]8a87a5332011-08-11 17:54:596299 EXPECT_FALSE(pending->IsIdPending(kGoodId));
[email protected]9060d8b02012-01-13 02:14:306300
6301 // Install when the location has higher priority.
[email protected]f484f8d52014-06-12 08:38:186302 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(
[email protected]d8fd0fd2014-03-24 13:16:066303 kGoodId,
6304 std::string(),
6305 GURL(kGoodUpdateURL),
6306 Manifest::EXTERNAL_POLICY_DOWNLOAD,
6307 Extension::NO_FLAGS,
6308 false));
[email protected]8a87a5332011-08-11 17:54:596309 EXPECT_TRUE(pending->IsIdPending(kGoodId));
[email protected]9060d8b02012-01-13 02:14:306310
6311 // Try the low priority again. Should be rejected.
[email protected]f484f8d52014-06-12 08:38:186312 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(
[email protected]d8fd0fd2014-03-24 13:16:066313 kGoodId,
6314 std::string(),
6315 GURL(kGoodUpdateURL),
6316 Manifest::EXTERNAL_PREF_DOWNLOAD,
6317 Extension::NO_FLAGS,
6318 false));
[email protected]9060d8b02012-01-13 02:14:306319 // The existing record should still be present in the pending extension
6320 // manager.
6321 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6322
[email protected]8a87a5332011-08-11 17:54:596323 pending->Remove(kGoodId);
[email protected]9060d8b02012-01-13 02:14:306324
6325 // Skip install when the location has the same priority as the installed
6326 // location.
[email protected]f484f8d52014-06-12 08:38:186327 EXPECT_FALSE(
6328 service()->OnExternalExtensionUpdateUrlFound(kGoodId,
6329 std::string(),
6330 GURL(kGoodUpdateURL),
6331 Manifest::INTERNAL,
6332 Extension::NO_FLAGS,
6333 false));
[email protected]9060d8b02012-01-13 02:14:306334
[email protected]8a87a5332011-08-11 17:54:596335 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6336}
6337
[email protected]d9a61e12012-11-14 02:43:476338TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) {
[email protected]c5e4a2222014-01-03 16:06:136339 Version older_version("0.1.0.0");
6340 Version newer_version("2.0.0.0");
[email protected]9060d8b02012-01-13 02:14:306341
6342 // We don't want the extension to be installed. A path that doesn't
6343 // point to a valid CRX ensures this.
[email protected]650b2d52013-02-10 03:41:456344 const base::FilePath kInvalidPathToCrx = base::FilePath();
[email protected]9060d8b02012-01-13 02:14:306345
6346 const int kCreationFlags = 0;
6347 const bool kDontMarkAcknowledged = false;
6348
6349 InitializeEmptyExtensionService();
6350
6351 // The test below uses install source constants to test that
6352 // priority is enforced. It assumes a specific ranking of install
6353 // sources: Registry (EXTERNAL_REGISTRY) overrides external pref
6354 // (EXTERNAL_PREF), and external pref overrides user install (INTERNAL).
6355 // The following assertions verify these assumptions:
[email protected]1d5e58b2013-01-31 08:41:406356 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY,
6357 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY,
6358 Manifest::EXTERNAL_PREF));
6359 ASSERT_EQ(Manifest::EXTERNAL_REGISTRY,
6360 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY,
6361 Manifest::INTERNAL));
6362 ASSERT_EQ(Manifest::EXTERNAL_PREF,
6363 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF,
6364 Manifest::INTERNAL));
[email protected]9060d8b02012-01-13 02:14:306365
[email protected]3f213ad2012-07-26 23:39:416366 extensions::PendingExtensionManager* pending =
[email protected]f484f8d52014-06-12 08:38:186367 service()->pending_extension_manager();
[email protected]9060d8b02012-01-13 02:14:306368 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6369
[email protected]97d6a5c2013-11-11 23:51:246370 {
6371 // Simulate an external source adding the extension as INTERNAL.
6372 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:066373 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:246374 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:186375 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6376 &older_version,
6377 kInvalidPathToCrx,
6378 Manifest::INTERNAL,
6379 kCreationFlags,
6380 kDontMarkAcknowledged));
[email protected]97d6a5c2013-11-11 23:51:246381 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6382 observer.Wait();
6383 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6384 }
[email protected]9060d8b02012-01-13 02:14:306385
[email protected]97d6a5c2013-11-11 23:51:246386 {
6387 // Simulate an external source adding the extension as EXTERNAL_PREF.
6388 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:066389 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:246390 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:186391 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6392 &older_version,
6393 kInvalidPathToCrx,
6394 Manifest::EXTERNAL_PREF,
6395 kCreationFlags,
6396 kDontMarkAcknowledged));
[email protected]97d6a5c2013-11-11 23:51:246397 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6398 observer.Wait();
6399 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6400 }
[email protected]9060d8b02012-01-13 02:14:306401
6402 // Simulate an external source adding as EXTERNAL_PREF again.
[email protected]4ec0f4b2012-12-07 09:41:466403 // This is rejected because the version and the location are the same as
6404 // the previous installation, which is still pending.
[email protected]f484f8d52014-06-12 08:38:186405 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6406 &older_version,
6407 kInvalidPathToCrx,
6408 Manifest::EXTERNAL_PREF,
6409 kCreationFlags,
6410 kDontMarkAcknowledged));
[email protected]9060d8b02012-01-13 02:14:306411 EXPECT_TRUE(pending->IsIdPending(kGoodId));
[email protected]9060d8b02012-01-13 02:14:306412
6413 // Try INTERNAL again. Should fail.
[email protected]f484f8d52014-06-12 08:38:186414 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6415 &older_version,
6416 kInvalidPathToCrx,
6417 Manifest::INTERNAL,
6418 kCreationFlags,
6419 kDontMarkAcknowledged));
[email protected]9060d8b02012-01-13 02:14:306420 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6421
[email protected]97d6a5c2013-11-11 23:51:246422 {
6423 // Now the registry adds the extension.
6424 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:066425 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:246426 content::NotificationService::AllSources());
6427 EXPECT_TRUE(
[email protected]f484f8d52014-06-12 08:38:186428 service()->OnExternalExtensionFileFound(kGoodId,
6429 &older_version,
6430 kInvalidPathToCrx,
6431 Manifest::EXTERNAL_REGISTRY,
6432 kCreationFlags,
6433 kDontMarkAcknowledged));
[email protected]97d6a5c2013-11-11 23:51:246434 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6435 observer.Wait();
6436 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED);
6437 }
[email protected]9060d8b02012-01-13 02:14:306438
6439 // Registry outranks both external pref and internal, so both fail.
[email protected]f484f8d52014-06-12 08:38:186440 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6441 &older_version,
6442 kInvalidPathToCrx,
6443 Manifest::EXTERNAL_PREF,
6444 kCreationFlags,
6445 kDontMarkAcknowledged));
[email protected]9060d8b02012-01-13 02:14:306446 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6447
[email protected]f484f8d52014-06-12 08:38:186448 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6449 &older_version,
6450 kInvalidPathToCrx,
6451 Manifest::INTERNAL,
6452 kCreationFlags,
6453 kDontMarkAcknowledged));
[email protected]9060d8b02012-01-13 02:14:306454 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6455
6456 pending->Remove(kGoodId);
6457
6458 // Install the extension.
[email protected]f484f8d52014-06-12 08:38:186459 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]9060d8b02012-01-13 02:14:306460 const Extension* ext = InstallCRX(path, INSTALL_NEW);
6461 ValidatePrefKeyCount(1u);
6462 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
[email protected]1d5e58b2013-01-31 08:41:406463 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
[email protected]9060d8b02012-01-13 02:14:306464
6465 // Now test the logic of OnExternalExtensionFileFound() when the extension
6466 // being added is already installed.
6467
6468 // Tests assume |older_version| is less than the installed version, and
6469 // |newer_version| is greater. Verify this:
[email protected]12126d372012-07-11 18:40:536470 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString()));
6471 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString()));
[email protected]9060d8b02012-01-13 02:14:306472
6473 // An external install for the same location should fail if the version is
6474 // older, or the same, and succeed if the version is newer.
6475
6476 // Older than the installed version...
[email protected]f484f8d52014-06-12 08:38:186477 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6478 &older_version,
6479 kInvalidPathToCrx,
6480 Manifest::INTERNAL,
6481 kCreationFlags,
6482 kDontMarkAcknowledged));
[email protected]9060d8b02012-01-13 02:14:306483 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6484
6485 // Same version as the installed version...
[email protected]f484f8d52014-06-12 08:38:186486 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6487 ext->version(),
6488 kInvalidPathToCrx,
6489 Manifest::INTERNAL,
6490 kCreationFlags,
6491 kDontMarkAcknowledged));
[email protected]9060d8b02012-01-13 02:14:306492 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6493
6494 // Newer than the installed version...
[email protected]f484f8d52014-06-12 08:38:186495 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6496 &newer_version,
6497 kInvalidPathToCrx,
6498 Manifest::INTERNAL,
6499 kCreationFlags,
6500 kDontMarkAcknowledged));
[email protected]9060d8b02012-01-13 02:14:306501 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6502
6503 // An external install for a higher priority install source should succeed
6504 // if the version is greater. |older_version| is not...
[email protected]f484f8d52014-06-12 08:38:186505 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6506 &older_version,
6507 kInvalidPathToCrx,
6508 Manifest::EXTERNAL_PREF,
6509 kCreationFlags,
6510 kDontMarkAcknowledged));
[email protected]9060d8b02012-01-13 02:14:306511 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6512
6513 // |newer_version| is newer.
[email protected]f484f8d52014-06-12 08:38:186514 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6515 &newer_version,
6516 kInvalidPathToCrx,
6517 Manifest::EXTERNAL_PREF,
6518 kCreationFlags,
6519 kDontMarkAcknowledged));
[email protected]9060d8b02012-01-13 02:14:306520 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6521
6522 // An external install for an even higher priority install source should
6523 // succeed if the version is greater.
6524 EXPECT_TRUE(
[email protected]f484f8d52014-06-12 08:38:186525 service()->OnExternalExtensionFileFound(kGoodId,
6526 &newer_version,
6527 kInvalidPathToCrx,
6528 Manifest::EXTERNAL_REGISTRY,
6529 kCreationFlags,
6530 kDontMarkAcknowledged));
[email protected]9060d8b02012-01-13 02:14:306531 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6532
6533 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY,
6534 // adding from external pref will now fail.
[email protected]f484f8d52014-06-12 08:38:186535 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6536 &newer_version,
6537 kInvalidPathToCrx,
6538 Manifest::EXTERNAL_PREF,
6539 kCreationFlags,
6540 kDontMarkAcknowledged));
[email protected]9060d8b02012-01-13 02:14:306541 EXPECT_TRUE(pending->IsIdPending(kGoodId));
6542}
6543
[email protected]d9a61e12012-11-14 02:43:476544TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) {
[email protected]c5e4a2222014-01-03 16:06:136545 Version kVersion123("1.2.3");
6546 Version kVersion124("1.2.4");
6547 Version kVersion125("1.2.5");
[email protected]650b2d52013-02-10 03:41:456548 const base::FilePath kInvalidPathToCrx = base::FilePath();
[email protected]e3987852012-05-04 10:06:306549 const int kCreationFlags = 0;
6550 const bool kDontMarkAcknowledged = false;
6551
6552 InitializeEmptyExtensionService();
6553
[email protected]3f213ad2012-07-26 23:39:416554 extensions::PendingExtensionManager* pending =
[email protected]f484f8d52014-06-12 08:38:186555 service()->pending_extension_manager();
[email protected]e3987852012-05-04 10:06:306556 EXPECT_FALSE(pending->IsIdPending(kGoodId));
6557
6558 // An external provider starts installing from a local crx.
[email protected]f484f8d52014-06-12 08:38:186559 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6560 &kVersion123,
6561 kInvalidPathToCrx,
6562 Manifest::EXTERNAL_PREF,
6563 kCreationFlags,
6564 kDontMarkAcknowledged));
[email protected]3f213ad2012-07-26 23:39:416565 const extensions::PendingExtensionInfo* info;
[email protected]51a3bf8b2012-06-08 22:53:066566 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6567 EXPECT_TRUE(info->version().IsValid());
6568 EXPECT_TRUE(info->version().Equals(kVersion123));
[email protected]e3987852012-05-04 10:06:306569
6570 // Adding a newer version overrides the currently pending version.
[email protected]f484f8d52014-06-12 08:38:186571 EXPECT_TRUE(service()->OnExternalExtensionFileFound(kGoodId,
6572 &kVersion124,
6573 kInvalidPathToCrx,
6574 Manifest::EXTERNAL_PREF,
6575 kCreationFlags,
6576 kDontMarkAcknowledged));
[email protected]51a3bf8b2012-06-08 22:53:066577 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6578 EXPECT_TRUE(info->version().IsValid());
6579 EXPECT_TRUE(info->version().Equals(kVersion124));
[email protected]e3987852012-05-04 10:06:306580
6581 // Adding an older version fails.
[email protected]f484f8d52014-06-12 08:38:186582 EXPECT_FALSE(service()->OnExternalExtensionFileFound(kGoodId,
6583 &kVersion123,
6584 kInvalidPathToCrx,
6585 Manifest::EXTERNAL_PREF,
6586 kCreationFlags,
6587 kDontMarkAcknowledged));
[email protected]51a3bf8b2012-06-08 22:53:066588 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6589 EXPECT_TRUE(info->version().IsValid());
6590 EXPECT_TRUE(info->version().Equals(kVersion124));
[email protected]e3987852012-05-04 10:06:306591
6592 // Adding an older version fails even when coming from a higher-priority
6593 // location.
6594 EXPECT_FALSE(
[email protected]f484f8d52014-06-12 08:38:186595 service()->OnExternalExtensionFileFound(kGoodId,
6596 &kVersion123,
6597 kInvalidPathToCrx,
6598 Manifest::EXTERNAL_REGISTRY,
6599 kCreationFlags,
6600 kDontMarkAcknowledged));
[email protected]51a3bf8b2012-06-08 22:53:066601 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6602 EXPECT_TRUE(info->version().IsValid());
6603 EXPECT_TRUE(info->version().Equals(kVersion124));
[email protected]e3987852012-05-04 10:06:306604
6605 // Adding the latest version from the webstore overrides a specific version.
6606 GURL kUpdateUrl("http://example.com/update");
[email protected]f484f8d52014-06-12 08:38:186607 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(
[email protected]d8fd0fd2014-03-24 13:16:066608 kGoodId,
6609 std::string(),
6610 kUpdateUrl,
6611 Manifest::EXTERNAL_POLICY_DOWNLOAD,
6612 Extension::NO_FLAGS,
6613 false));
[email protected]51a3bf8b2012-06-08 22:53:066614 EXPECT_TRUE((info = pending->GetById(kGoodId)));
6615 EXPECT_FALSE(info->version().IsValid());
[email protected]e3987852012-05-04 10:06:306616}
6617
[email protected]f5bf1842012-02-15 02:52:266618// This makes sure we can package and install CRX files that use whitelisted
6619// permissions.
[email protected]d9a61e12012-11-14 02:43:476620TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) {
[email protected]f5bf1842012-02-15 02:52:266621 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk";
6622 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
[email protected]a612eb32014-03-31 22:09:176623 extensions::switches::kWhitelistedExtensionID, test_id);
[email protected]f5bf1842012-02-15 02:52:266624
6625 InitializeEmptyExtensionService();
[email protected]f484f8d52014-06-12 08:38:186626 base::FilePath path = data_dir().AppendASCII("permissions");
[email protected]650b2d52013-02-10 03:41:456627 base::FilePath pem_path = path
[email protected]f5bf1842012-02-15 02:52:266628 .AppendASCII("whitelist.pem");
6629 path = path
6630 .AppendASCII("whitelist");
6631
6632 const Extension* extension = PackAndInstallCRX(path, pem_path, INSTALL_NEW);
6633 EXPECT_EQ(0u, GetErrors().size());
[email protected]f484f8d52014-06-12 08:38:186634 ASSERT_EQ(1u, registry()->enabled_extensions().size());
[email protected]f5bf1842012-02-15 02:52:266635 EXPECT_EQ(test_id, extension->id());
6636}
6637
[email protected]145a317b2011-04-12 16:03:466638// Test that when multiple sources try to install an extension,
6639// we consistently choose the right one. To make tests easy to read,
6640// methods that fake requests to install crx files in several ways
6641// are provided.
6642class ExtensionSourcePriorityTest : public ExtensionServiceTest {
6643 public:
[email protected]49aeab62013-02-07 02:53:116644 virtual void SetUp() {
[email protected]ed8ee722011-04-22 06:49:446645 ExtensionServiceTest::SetUp();
6646
[email protected]145a317b2011-04-12 16:03:466647 // All tests use a single extension. Put the id and path in member vars
6648 // that all methods can read.
6649 crx_id_ = kGoodId;
[email protected]f484f8d52014-06-12 08:38:186650 crx_path_ = data_dir().AppendASCII("good.crx");
[email protected]145a317b2011-04-12 16:03:466651 }
6652
6653 // Fake an external source adding a URL to fetch an extension from.
[email protected]9060d8b02012-01-13 02:14:306654 bool AddPendingExternalPrefUrl() {
[email protected]f484f8d52014-06-12 08:38:186655 return service()->pending_extension_manager()->AddFromExternalUpdateUrl(
[email protected]d8fd0fd2014-03-24 13:16:066656 crx_id_,
6657 std::string(),
6658 GURL(),
6659 Manifest::EXTERNAL_PREF_DOWNLOAD,
6660 Extension::NO_FLAGS,
6661 false);
[email protected]145a317b2011-04-12 16:03:466662 }
6663
6664 // Fake an external file from external_extensions.json.
[email protected]9060d8b02012-01-13 02:14:306665 bool AddPendingExternalPrefFileInstall() {
[email protected]c5e4a2222014-01-03 16:06:136666 Version version("1.0.0.0");
[email protected]145a317b2011-04-12 16:03:466667
[email protected]f484f8d52014-06-12 08:38:186668 return service()->OnExternalExtensionFileFound(crx_id_,
6669 &version,
6670 crx_path_,
6671 Manifest::EXTERNAL_PREF,
6672 Extension::NO_FLAGS,
6673 false);
[email protected]145a317b2011-04-12 16:03:466674 }
6675
6676 // Fake a request from sync to install an extension.
6677 bool AddPendingSyncInstall() {
[email protected]f484f8d52014-06-12 08:38:186678 return service()->pending_extension_manager()->AddFromSync(
[email protected]21db9ef2014-05-16 02:06:276679 crx_id_,
6680 GURL(kGoodUpdateURL),
6681 &IsExtension,
6682 kGoodInstallSilently,
[email protected]6338fa32014-07-16 21:41:596683 kGoodRemoteInstall,
6684 kGoodInstalledByCustodian);
[email protected]145a317b2011-04-12 16:03:466685 }
6686
[email protected]145a317b2011-04-12 16:03:466687 // Fake a policy install.
[email protected]9060d8b02012-01-13 02:14:306688 bool AddPendingPolicyInstall() {
[email protected]145a317b2011-04-12 16:03:466689 // Get path to the CRX with id |kGoodId|.
[email protected]f484f8d52014-06-12 08:38:186690 return service()->OnExternalExtensionUpdateUrlFound(
[email protected]d8fd0fd2014-03-24 13:16:066691 crx_id_,
6692 std::string(),
6693 GURL(),
6694 Manifest::EXTERNAL_POLICY_DOWNLOAD,
6695 Extension::NO_FLAGS,
6696 false);
[email protected]145a317b2011-04-12 16:03:466697 }
6698
6699 // Get the install source of a pending extension.
[email protected]1d5e58b2013-01-31 08:41:406700 Manifest::Location GetPendingLocation() {
[email protected]3f213ad2012-07-26 23:39:416701 const extensions::PendingExtensionInfo* info;
[email protected]f484f8d52014-06-12 08:38:186702 EXPECT_TRUE(
6703 (info = service()->pending_extension_manager()->GetById(crx_id_)));
[email protected]51a3bf8b2012-06-08 22:53:066704 return info->install_source();
[email protected]145a317b2011-04-12 16:03:466705 }
6706
6707 // Is an extension pending from a sync request?
6708 bool GetPendingIsFromSync() {
[email protected]3f213ad2012-07-26 23:39:416709 const extensions::PendingExtensionInfo* info;
[email protected]f484f8d52014-06-12 08:38:186710 EXPECT_TRUE(
6711 (info = service()->pending_extension_manager()->GetById(crx_id_)));
[email protected]51a3bf8b2012-06-08 22:53:066712 return info->is_from_sync();
[email protected]145a317b2011-04-12 16:03:466713 }
6714
6715 // Is the CRX id these tests use pending?
6716 bool IsCrxPending() {
[email protected]f484f8d52014-06-12 08:38:186717 return service()->pending_extension_manager()->IsIdPending(crx_id_);
[email protected]145a317b2011-04-12 16:03:466718 }
6719
6720 // Is an extension installed?
6721 bool IsCrxInstalled() {
[email protected]f484f8d52014-06-12 08:38:186722 return (service()->GetExtensionById(crx_id_, true) != NULL);
[email protected]145a317b2011-04-12 16:03:466723 }
6724
6725 protected:
6726 // All tests use a single extension. Making the id and path member
6727 // vars avoids pasing the same argument to every method.
6728 std::string crx_id_;
[email protected]650b2d52013-02-10 03:41:456729 base::FilePath crx_path_;
[email protected]145a317b2011-04-12 16:03:466730};
6731
[email protected]3634ebd2011-04-20 00:34:126732// Test that a pending request for installation of an external CRX from
6733// an update URL overrides a pending request to install the same extension
6734// from sync.
[email protected]ed8ee722011-04-22 06:49:446735TEST_F(ExtensionSourcePriorityTest, PendingExternalFileOverSync) {
[email protected]145a317b2011-04-12 16:03:466736 InitializeEmptyExtensionService();
6737
6738 ASSERT_FALSE(IsCrxInstalled());
6739
6740 // Install pending extension from sync.
[email protected]97d6a5c2013-11-11 23:51:246741 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:066742 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:246743 content::NotificationService::AllSources());
[email protected]f4d5e1a2011-04-28 02:08:256744 EXPECT_TRUE(AddPendingSyncInstall());
[email protected]1d5e58b2013-01-31 08:41:406745 ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation());
[email protected]145a317b2011-04-12 16:03:466746 EXPECT_TRUE(GetPendingIsFromSync());
6747 ASSERT_FALSE(IsCrxInstalled());
6748
6749 // Install pending as external prefs json would.
6750 AddPendingExternalPrefFileInstall();
[email protected]1d5e58b2013-01-31 08:41:406751 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation());
[email protected]145a317b2011-04-12 16:03:466752 ASSERT_FALSE(IsCrxInstalled());
6753
[email protected]6d057a0c2013-07-09 21:12:076754 // Another request from sync should be ignored.
[email protected]f4d5e1a2011-04-28 02:08:256755 EXPECT_FALSE(AddPendingSyncInstall());
[email protected]1d5e58b2013-01-31 08:41:406756 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation());
[email protected]145a317b2011-04-12 16:03:466757 ASSERT_FALSE(IsCrxInstalled());
6758
[email protected]97d6a5c2013-11-11 23:51:246759 observer.Wait();
6760 VerifyCrxInstall(crx_path_, INSTALL_NEW);
[email protected]145a317b2011-04-12 16:03:466761 ASSERT_TRUE(IsCrxInstalled());
6762}
6763
6764// Test that an install of an external CRX from an update overrides
6765// an install of the same extension from sync.
[email protected]ed8ee722011-04-22 06:49:446766TEST_F(ExtensionSourcePriorityTest, PendingExternalUrlOverSync) {
[email protected]145a317b2011-04-12 16:03:466767 InitializeEmptyExtensionService();
6768 ASSERT_FALSE(IsCrxInstalled());
6769
[email protected]f4d5e1a2011-04-28 02:08:256770 EXPECT_TRUE(AddPendingSyncInstall());
[email protected]1d5e58b2013-01-31 08:41:406771 ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation());
[email protected]145a317b2011-04-12 16:03:466772 EXPECT_TRUE(GetPendingIsFromSync());
6773 ASSERT_FALSE(IsCrxInstalled());
6774
[email protected]9060d8b02012-01-13 02:14:306775 ASSERT_TRUE(AddPendingExternalPrefUrl());
[email protected]1d5e58b2013-01-31 08:41:406776 ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation());
[email protected]145a317b2011-04-12 16:03:466777 EXPECT_FALSE(GetPendingIsFromSync());
6778 ASSERT_FALSE(IsCrxInstalled());
6779
[email protected]f4d5e1a2011-04-28 02:08:256780 EXPECT_FALSE(AddPendingSyncInstall());
[email protected]1d5e58b2013-01-31 08:41:406781 ASSERT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, GetPendingLocation());
[email protected]145a317b2011-04-12 16:03:466782 EXPECT_FALSE(GetPendingIsFromSync());
6783 ASSERT_FALSE(IsCrxInstalled());
6784}
6785
[email protected]145a317b2011-04-12 16:03:466786// Test that an external install request stops sync from installing
6787// the same extension.
[email protected]ed8ee722011-04-22 06:49:446788TEST_F(ExtensionSourcePriorityTest, InstallExternalBlocksSyncRequest) {
[email protected]145a317b2011-04-12 16:03:466789 InitializeEmptyExtensionService();
6790 ASSERT_FALSE(IsCrxInstalled());
6791
6792 // External prefs starts an install.
6793 AddPendingExternalPrefFileInstall();
6794
6795 // Crx installer was made, but has not yet run.
6796 ASSERT_FALSE(IsCrxInstalled());
6797
6798 // Before the CRX installer runs, Sync requests that the same extension
6799 // be installed. Should fail, because an external source is pending.
[email protected]97d6a5c2013-11-11 23:51:246800 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:066801 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:246802 content::NotificationService::AllSources());
[email protected]145a317b2011-04-12 16:03:466803 ASSERT_FALSE(AddPendingSyncInstall());
6804
6805 // Wait for the external source to install.
[email protected]97d6a5c2013-11-11 23:51:246806 observer.Wait();
6807 VerifyCrxInstall(crx_path_, INSTALL_NEW);
[email protected]145a317b2011-04-12 16:03:466808 ASSERT_TRUE(IsCrxInstalled());
6809
6810 // Now that the extension is installed, sync request should fail
6811 // because the extension is already installed.
6812 ASSERT_FALSE(AddPendingSyncInstall());
6813}
[email protected]07c9f2f42012-02-29 18:45:226814
[email protected]612a1cb12012-10-17 13:18:036815// Test that installing an external extension displays a GlobalError.
[email protected]d9a61e12012-11-14 02:43:476816TEST_F(ExtensionServiceTest, ExternalInstallGlobalError) {
[email protected]00b5d0a52012-10-30 13:13:536817 FeatureSwitch::ScopedOverride prompt(
6818 FeatureSwitch::prompt_for_external_extensions(), true);
[email protected]612a1cb12012-10-17 13:18:036819
[email protected]07c9f2f42012-02-29 18:45:226820 InitializeEmptyExtensionService();
[email protected]07c9f2f42012-02-29 18:45:226821 MockExtensionProvider* provider =
[email protected]f484f8d52014-06-12 08:38:186822 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
[email protected]07c9f2f42012-02-29 18:45:226823 AddMockExternalProvider(provider);
6824
[email protected]374ceb6f2014-07-02 19:25:346825 service()->external_install_manager()->UpdateExternalExtensionAlert();
[email protected]07c9f2f42012-02-29 18:45:226826 // Should return false, meaning there aren't any extensions that the user
6827 // needs to know about.
[email protected]2894a512014-06-26 19:03:566828 EXPECT_FALSE(
6829 service()->external_install_manager()->HasExternalInstallError());
[email protected]07c9f2f42012-02-29 18:45:226830
6831 // This is a normal extension, installed normally.
6832 // This should NOT trigger an alert.
[email protected]f484f8d52014-06-12 08:38:186833 service()->set_extensions_enabled(true);
6834 base::FilePath path = data_dir().AppendASCII("good.crx");
[email protected]07c9f2f42012-02-29 18:45:226835 InstallCRX(path, INSTALL_NEW);
6836
[email protected]f484f8d52014-06-12 08:38:186837 service()->CheckForExternalUpdates();
[email protected]eedc1c752013-08-09 18:51:556838 base::RunLoop().RunUntilIdle();
[email protected]2894a512014-06-26 19:03:566839 EXPECT_FALSE(
6840 service()->external_install_manager()->HasExternalInstallError());
[email protected]07c9f2f42012-02-29 18:45:226841
6842 // A hosted app, installed externally.
[email protected]2c495c42013-01-04 21:49:546843 // This should NOT trigger an alert.
[email protected]f484f8d52014-06-12 08:38:186844 provider->UpdateOrAddExtension(
6845 hosted_app, "1.0.0.0", data_dir().AppendASCII("hosted_app.crx"));
[email protected]07c9f2f42012-02-29 18:45:226846
[email protected]97d6a5c2013-11-11 23:51:246847 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:066848 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:246849 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:186850 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:246851 observer.Wait();
[email protected]2894a512014-06-26 19:03:566852 EXPECT_FALSE(
6853 service()->external_install_manager()->HasExternalInstallError());
[email protected]07c9f2f42012-02-29 18:45:226854
[email protected]612a1cb12012-10-17 13:18:036855 // Another normal extension, but installed externally.
6856 // This SHOULD trigger an alert.
[email protected]f484f8d52014-06-12 08:38:186857 provider->UpdateOrAddExtension(
6858 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
[email protected]612a1cb12012-10-17 13:18:036859
[email protected]97d6a5c2013-11-11 23:51:246860 content::WindowedNotificationObserver observer2(
[email protected]adf5a102014-07-31 12:44:066861 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:246862 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:186863 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:246864 observer2.Wait();
[email protected]2894a512014-06-26 19:03:566865 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
[email protected]07c9f2f42012-02-29 18:45:226866}
[email protected]612a1cb12012-10-17 13:18:036867
6868// Test that external extensions are initially disabled, and that enabling
6869// them clears the prompt.
[email protected]d9a61e12012-11-14 02:43:476870TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) {
[email protected]00b5d0a52012-10-30 13:13:536871 FeatureSwitch::ScopedOverride prompt(
6872 FeatureSwitch::prompt_for_external_extensions(), true);
[email protected]612a1cb12012-10-17 13:18:036873
6874 InitializeEmptyExtensionService();
6875 MockExtensionProvider* provider =
[email protected]f484f8d52014-06-12 08:38:186876 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
[email protected]612a1cb12012-10-17 13:18:036877 AddMockExternalProvider(provider);
6878
[email protected]f484f8d52014-06-12 08:38:186879 provider->UpdateOrAddExtension(
6880 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
[email protected]612a1cb12012-10-17 13:18:036881
[email protected]97d6a5c2013-11-11 23:51:246882 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:066883 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:246884 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:186885 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:246886 observer.Wait();
[email protected]2894a512014-06-26 19:03:566887 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
[email protected]f484f8d52014-06-12 08:38:186888 EXPECT_FALSE(service()->IsExtensionEnabled(page_action));
[email protected]612a1cb12012-10-17 13:18:036889
6890 const Extension* extension =
[email protected]f484f8d52014-06-12 08:38:186891 registry()->disabled_extensions().GetByID(page_action);
[email protected]612a1cb12012-10-17 13:18:036892 EXPECT_TRUE(extension);
6893 EXPECT_EQ(page_action, extension->id());
6894
[email protected]f484f8d52014-06-12 08:38:186895 service()->EnableExtension(page_action);
[email protected]2894a512014-06-26 19:03:566896 EXPECT_FALSE(
6897 service()->external_install_manager()->HasExternalInstallError());
[email protected]f484f8d52014-06-12 08:38:186898 EXPECT_TRUE(service()->IsExtensionEnabled(page_action));
[email protected]612a1cb12012-10-17 13:18:036899}
6900
6901// Test that installing multiple external extensions works.
[email protected]404d1a22013-09-20 17:28:076902// Flaky on windows; http://crbug.com/295757 .
6903#if defined(OS_WIN)
6904#define MAYBE_ExternalInstallMultiple DISABLED_ExternalInstallMultiple
6905#else
6906#define MAYBE_ExternalInstallMultiple ExternalInstallMultiple
6907#endif
6908TEST_F(ExtensionServiceTest, MAYBE_ExternalInstallMultiple) {
[email protected]00b5d0a52012-10-30 13:13:536909 FeatureSwitch::ScopedOverride prompt(
6910 FeatureSwitch::prompt_for_external_extensions(), true);
[email protected]612a1cb12012-10-17 13:18:036911
6912 InitializeEmptyExtensionService();
6913 MockExtensionProvider* provider =
[email protected]f484f8d52014-06-12 08:38:186914 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
[email protected]612a1cb12012-10-17 13:18:036915 AddMockExternalProvider(provider);
6916
[email protected]f484f8d52014-06-12 08:38:186917 provider->UpdateOrAddExtension(
6918 page_action, "1.0.0.0", data_dir().AppendASCII("page_action.crx"));
6919 provider->UpdateOrAddExtension(
6920 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
6921 provider->UpdateOrAddExtension(
6922 theme_crx, "2.0", data_dir().AppendASCII("theme.crx"));
[email protected]612a1cb12012-10-17 13:18:036923
[email protected]6d057a0c2013-07-09 21:12:076924 int count = 3;
[email protected]97d6a5c2013-11-11 23:51:246925 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:066926 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:246927 base::Bind(&WaitForCountNotificationsCallback, &count));
[email protected]f484f8d52014-06-12 08:38:186928 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:246929 observer.Wait();
[email protected]2894a512014-06-26 19:03:566930 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
[email protected]f484f8d52014-06-12 08:38:186931 EXPECT_FALSE(service()->IsExtensionEnabled(page_action));
6932 EXPECT_FALSE(service()->IsExtensionEnabled(good_crx));
6933 EXPECT_FALSE(service()->IsExtensionEnabled(theme_crx));
[email protected]612a1cb12012-10-17 13:18:036934
[email protected]f484f8d52014-06-12 08:38:186935 service()->EnableExtension(page_action);
[email protected]2894a512014-06-26 19:03:566936 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
[email protected]374ceb6f2014-07-02 19:25:346937 EXPECT_FALSE(service()
6938 ->external_install_manager()
6939 ->HasExternalInstallBubbleForTesting());
[email protected]2894a512014-06-26 19:03:566940
[email protected]f484f8d52014-06-12 08:38:186941 service()->EnableExtension(theme_crx);
[email protected]2894a512014-06-26 19:03:566942 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
[email protected]374ceb6f2014-07-02 19:25:346943 EXPECT_FALSE(service()
6944 ->external_install_manager()
6945 ->HasExternalInstallBubbleForTesting());
[email protected]2894a512014-06-26 19:03:566946
[email protected]f484f8d52014-06-12 08:38:186947 service()->EnableExtension(good_crx);
[email protected]2894a512014-06-26 19:03:566948 EXPECT_FALSE(
6949 service()->external_install_manager()->HasExternalInstallError());
[email protected]374ceb6f2014-07-02 19:25:346950 EXPECT_FALSE(service()
6951 ->external_install_manager()
6952 ->HasExternalInstallBubbleForTesting());
[email protected]aa55be7f2013-04-22 20:56:046953}
6954
6955// Test that there is a bubble for external extensions that update
[email protected]b3aa7182013-04-25 04:45:236956// from the webstore if the profile is not new.
6957TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) {
[email protected]aa55be7f2013-04-22 20:56:046958 FeatureSwitch::ScopedOverride prompt(
6959 FeatureSwitch::prompt_for_external_extensions(), true);
6960
[email protected]b3aa7182013-04-25 04:45:236961 // This sets up the ExtensionPrefs used by our ExtensionService to be
6962 // post-first run.
[email protected]371662e372013-10-17 22:05:226963 ExtensionServiceInitParams params = CreateDefaultInitParams();
6964 params.is_first_run = false;
6965 InitializeExtensionService(params);
[email protected]aa55be7f2013-04-22 20:56:046966
[email protected]f484f8d52014-06-12 08:38:186967 base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx");
6968 PackCRX(data_dir().AppendASCII("update_from_webstore"),
6969 data_dir().AppendASCII("update_from_webstore.pem"),
[email protected]aa55be7f2013-04-22 20:56:046970 crx_path);
6971
6972 MockExtensionProvider* provider =
[email protected]f484f8d52014-06-12 08:38:186973 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
[email protected]aa55be7f2013-04-22 20:56:046974 AddMockExternalProvider(provider);
[email protected]aa55be7f2013-04-22 20:56:046975 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
[email protected]460c6712013-04-24 07:20:016976
[email protected]97d6a5c2013-11-11 23:51:246977 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:066978 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:246979 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:186980 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:246981 observer.Wait();
[email protected]2894a512014-06-26 19:03:566982 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
[email protected]374ceb6f2014-07-02 19:25:346983 EXPECT_TRUE(service()
6984 ->external_install_manager()
6985 ->HasExternalInstallBubbleForTesting());
[email protected]f484f8d52014-06-12 08:38:186986 EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore));
[email protected]612a1cb12012-10-17 13:18:036987}
[email protected]460c6712013-04-24 07:20:016988
6989// Test that there is no bubble for external extensions if the profile is new.
6990TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) {
6991 FeatureSwitch::ScopedOverride prompt(
6992 FeatureSwitch::prompt_for_external_extensions(), true);
6993
6994 InitializeEmptyExtensionService();
6995
[email protected]f484f8d52014-06-12 08:38:186996 base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx");
6997 PackCRX(data_dir().AppendASCII("update_from_webstore"),
6998 data_dir().AppendASCII("update_from_webstore.pem"),
[email protected]460c6712013-04-24 07:20:016999 crx_path);
7000
7001 MockExtensionProvider* provider =
[email protected]f484f8d52014-06-12 08:38:187002 new MockExtensionProvider(service(), Manifest::EXTERNAL_PREF);
[email protected]460c6712013-04-24 07:20:017003 AddMockExternalProvider(provider);
7004 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
7005
[email protected]97d6a5c2013-11-11 23:51:247006 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:067007 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]97d6a5c2013-11-11 23:51:247008 content::NotificationService::AllSources());
[email protected]f484f8d52014-06-12 08:38:187009 service()->CheckForExternalUpdates();
[email protected]97d6a5c2013-11-11 23:51:247010 observer.Wait();
[email protected]2894a512014-06-26 19:03:567011 EXPECT_TRUE(service()->external_install_manager()->HasExternalInstallError());
[email protected]374ceb6f2014-07-02 19:25:347012 EXPECT_FALSE(service()
7013 ->external_install_manager()
7014 ->HasExternalInstallBubbleForTesting());
[email protected]f484f8d52014-06-12 08:38:187015 EXPECT_FALSE(service()->IsExtensionEnabled(updates_from_webstore));
[email protected]460c6712013-04-24 07:20:017016}
[email protected]9f3c8532013-07-31 19:52:077017
[email protected]2894a512014-06-26 19:03:567018// Test that clicking to remove the extension on an external install warning
7019// uninstalls the extension.
7020TEST_F(ExtensionServiceTest, ExternalInstallClickToRemove) {
7021 FeatureSwitch::ScopedOverride prompt(
7022 FeatureSwitch::prompt_for_external_extensions(), true);
7023
7024 ExtensionServiceInitParams params = CreateDefaultInitParams();
7025 params.is_first_run = false;
7026 InitializeExtensionService(params);
7027
7028 base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx");
7029 PackCRX(data_dir().AppendASCII("update_from_webstore"),
7030 data_dir().AppendASCII("update_from_webstore.pem"),
7031 crx_path);
7032
7033 MockExtensionProvider* provider =
7034 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
7035 AddMockExternalProvider(provider);
7036 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
7037
7038 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:067039 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]2894a512014-06-26 19:03:567040 content::NotificationService::AllSources());
7041 service_->CheckForExternalUpdates();
7042 observer.Wait();
7043 EXPECT_TRUE(service_->external_install_manager()->HasExternalInstallError());
7044
7045 // We check both enabled and disabled, since these are "eventually exclusive"
7046 // sets.
7047 EXPECT_TRUE(registry()->disabled_extensions().GetByID(updates_from_webstore));
7048 EXPECT_FALSE(registry()->enabled_extensions().GetByID(updates_from_webstore));
7049
7050 // Click the negative response.
7051 service_->external_install_manager()->error_for_testing()->InstallUIAbort(
7052 true);
7053 // The Extension should be uninstalled.
7054 EXPECT_FALSE(registry()->GetExtensionById(updates_from_webstore,
7055 ExtensionRegistry::EVERYTHING));
7056 // The error should be removed.
7057 EXPECT_FALSE(service_->external_install_manager()->HasExternalInstallError());
7058}
7059
7060// Test that clicking to keep the extension on an external install warning
7061// re-enables the extension.
7062TEST_F(ExtensionServiceTest, ExternalInstallClickToKeep) {
7063 FeatureSwitch::ScopedOverride prompt(
7064 FeatureSwitch::prompt_for_external_extensions(), true);
7065
7066 ExtensionServiceInitParams params = CreateDefaultInitParams();
7067 params.is_first_run = false;
7068 InitializeExtensionService(params);
7069
7070 base::FilePath crx_path = temp_dir().path().AppendASCII("webstore.crx");
7071 PackCRX(data_dir().AppendASCII("update_from_webstore"),
7072 data_dir().AppendASCII("update_from_webstore.pem"),
7073 crx_path);
7074
7075 MockExtensionProvider* provider =
7076 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
7077 AddMockExternalProvider(provider);
7078 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
7079
7080 content::WindowedNotificationObserver observer(
[email protected]adf5a102014-07-31 12:44:067081 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
[email protected]2894a512014-06-26 19:03:567082 content::NotificationService::AllSources());
7083 service_->CheckForExternalUpdates();
7084 observer.Wait();
7085 EXPECT_TRUE(service_->external_install_manager()->HasExternalInstallError());
7086
7087 // We check both enabled and disabled, since these are "eventually exclusive"
7088 // sets.
7089 EXPECT_TRUE(registry()->disabled_extensions().GetByID(updates_from_webstore));
7090 EXPECT_FALSE(registry()->enabled_extensions().GetByID(updates_from_webstore));
7091
7092 // Accept the extension.
7093 service_->external_install_manager()->error_for_testing()->InstallUIProceed();
7094
7095 // It should be enabled again.
7096 EXPECT_TRUE(registry()->enabled_extensions().GetByID(updates_from_webstore));
7097 EXPECT_FALSE(
7098 registry()->disabled_extensions().GetByID(updates_from_webstore));
7099
7100 // The error should be removed.
7101 EXPECT_FALSE(service_->external_install_manager()->HasExternalInstallError());
7102}
7103
[email protected]9f3c8532013-07-31 19:52:077104TEST_F(ExtensionServiceTest, InstallBlacklistedExtension) {
7105 InitializeEmptyExtensionService();
7106
7107 scoped_refptr<Extension> extension = extensions::ExtensionBuilder()
7108 .SetManifest(extensions::DictionaryBuilder()
7109 .Set("name", "extension")
7110 .Set("version", "1.0")
7111 .Set("manifest_version", 2).Build())
7112 .Build();
7113 ASSERT_TRUE(extension.get());
7114 const std::string& id = extension->id();
7115
7116 std::set<std::string> id_set;
7117 id_set.insert(id);
7118 extensions::ExtensionNotificationObserver notifications(
7119 content::NotificationService::AllSources(), id_set);
7120
7121 // Installation should be allowed but the extension should never have been
7122 // loaded and it should be blacklisted in prefs.
[email protected]4a1d9c0d2014-06-13 12:50:117123 service()->OnExtensionInstalled(
7124 extension.get(),
7125 syncer::StringOrdinal(),
7126 (extensions::kInstallFlagIsBlacklistedForMalware |
7127 extensions::kInstallFlagInstallImmediately));
[email protected]eedc1c752013-08-09 18:51:557128 base::RunLoop().RunUntilIdle();
[email protected]9f3c8532013-07-31 19:52:077129
7130 // Extension was installed but not loaded.
7131 EXPECT_TRUE(notifications.CheckNotifications(
[email protected]adf5a102014-07-31 12:44:067132 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED));
[email protected]f484f8d52014-06-12 08:38:187133 EXPECT_TRUE(service()->GetInstalledExtension(id));
[email protected]5fdfa562013-12-27 17:43:597134
[email protected]f484f8d52014-06-12 08:38:187135 EXPECT_FALSE(registry()->enabled_extensions().Contains(id));
7136 EXPECT_TRUE(registry()->blacklisted_extensions().Contains(id));
[email protected]5fdfa562013-12-27 17:43:597137
[email protected]f484f8d52014-06-12 08:38:187138 EXPECT_TRUE(ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(id));
7139 EXPECT_TRUE(
7140 ExtensionPrefs::Get(profile())->IsBlacklistedExtensionAcknowledged(id));
[email protected]9f3c8532013-07-31 19:52:077141}
[email protected]59ee99d2013-10-11 15:46:167142
[email protected]ebe07772014-05-22 04:16:067143// Tests a profile being destroyed correctly disables extensions.
7144TEST_F(ExtensionServiceTest, DestroyingProfileClearsExtensions) {
7145 InitializeEmptyExtensionService();
7146
[email protected]f484f8d52014-06-12 08:38:187147 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
[email protected]ebe07772014-05-22 04:16:067148 EXPECT_NE(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
[email protected]f484f8d52014-06-12 08:38:187149 EXPECT_EQ(1u, registry()->enabled_extensions().size());
7150 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7151 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7152 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
[email protected]ebe07772014-05-22 04:16:067153
[email protected]f484f8d52014-06-12 08:38:187154 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
7155 content::Source<Profile>(profile()),
7156 content::NotificationService::NoDetails());
[email protected]ebe07772014-05-22 04:16:067157 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
[email protected]f484f8d52014-06-12 08:38:187158 EXPECT_EQ(0u, registry()->enabled_extensions().size());
7159 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7160 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7161 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
[email protected]ebe07772014-05-22 04:16:067162}