OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 #include "content/public/browser/plugin_service.h" | 90 #include "content/public/browser/plugin_service.h" |
91 #include "content/public/browser/render_process_host.h" | 91 #include "content/public/browser/render_process_host.h" |
92 #include "content/public/browser/storage_partition.h" | 92 #include "content/public/browser/storage_partition.h" |
93 #include "content/public/common/content_constants.h" | 93 #include "content/public/common/content_constants.h" |
94 #include "content/public/test/test_browser_thread_bundle.h" | 94 #include "content/public/test/test_browser_thread_bundle.h" |
95 #include "content/public/test/test_utils.h" | 95 #include "content/public/test/test_utils.h" |
96 #include "extensions/browser/extension_dialog_auto_confirm.h" | 96 #include "extensions/browser/extension_dialog_auto_confirm.h" |
97 #include "extensions/browser/extension_prefs.h" | 97 #include "extensions/browser/extension_prefs.h" |
98 #include "extensions/browser/extension_registry.h" | 98 #include "extensions/browser/extension_registry.h" |
99 #include "extensions/browser/extension_system.h" | 99 #include "extensions/browser/extension_system.h" |
100 #include "extensions/browser/external_extension_install_info.h" | |
100 #include "extensions/browser/external_provider_interface.h" | 101 #include "extensions/browser/external_provider_interface.h" |
101 #include "extensions/browser/install_flag.h" | 102 #include "extensions/browser/install_flag.h" |
102 #include "extensions/browser/management_policy.h" | 103 #include "extensions/browser/management_policy.h" |
103 #include "extensions/browser/test_extension_registry_observer.h" | 104 #include "extensions/browser/test_extension_registry_observer.h" |
104 #include "extensions/browser/test_management_policy.h" | 105 #include "extensions/browser/test_management_policy.h" |
105 #include "extensions/browser/uninstall_reason.h" | 106 #include "extensions/browser/uninstall_reason.h" |
106 #include "extensions/common/constants.h" | 107 #include "extensions/common/constants.h" |
107 #include "extensions/common/extension.h" | 108 #include "extensions/common/extension.h" |
108 #include "extensions/common/extension_builder.h" | 109 #include "extensions/common/extension_builder.h" |
109 #include "extensions/common/extension_l10n_util.h" | 110 #include "extensions/common/extension_l10n_util.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 using extensions::APIPermissionSet; | 156 using extensions::APIPermissionSet; |
156 using extensions::AppSorting; | 157 using extensions::AppSorting; |
157 using extensions::Blacklist; | 158 using extensions::Blacklist; |
158 using extensions::CrxInstaller; | 159 using extensions::CrxInstaller; |
159 using extensions::Extension; | 160 using extensions::Extension; |
160 using extensions::ExtensionCreator; | 161 using extensions::ExtensionCreator; |
161 using extensions::ExtensionPrefs; | 162 using extensions::ExtensionPrefs; |
162 using extensions::ExtensionRegistry; | 163 using extensions::ExtensionRegistry; |
163 using extensions::ExtensionResource; | 164 using extensions::ExtensionResource; |
164 using extensions::ExtensionSystem; | 165 using extensions::ExtensionSystem; |
166 using extensions::ExternalExtensionInstallInfoFile; | |
167 using extensions::ExternalExtensionInstallInfoUpdateUrl; | |
165 using extensions::ExternalInstallError; | 168 using extensions::ExternalInstallError; |
169 using extensions::ExternalProviderInterface; | |
166 using extensions::FakeSafeBrowsingDatabaseManager; | 170 using extensions::FakeSafeBrowsingDatabaseManager; |
167 using extensions::FeatureSwitch; | 171 using extensions::FeatureSwitch; |
168 using extensions::Manifest; | 172 using extensions::Manifest; |
169 using extensions::PermissionSet; | 173 using extensions::PermissionSet; |
170 using extensions::TestExtensionSystem; | 174 using extensions::TestExtensionSystem; |
171 using extensions::UnloadedExtensionInfo; | 175 using extensions::UnloadedExtensionInfo; |
172 using extensions::URLPatternSet; | 176 using extensions::URLPatternSet; |
173 | 177 |
174 namespace keys = extensions::manifest_keys; | 178 namespace keys = extensions::manifest_keys; |
175 | 179 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 | 245 |
242 void RemoveExtension(const std::string& id) { | 246 void RemoveExtension(const std::string& id) { |
243 extension_map_.erase(id); | 247 extension_map_.erase(id); |
244 } | 248 } |
245 | 249 |
246 // ExternalProvider implementation: | 250 // ExternalProvider implementation: |
247 void VisitRegisteredExtension() override { | 251 void VisitRegisteredExtension() override { |
248 visit_count_++; | 252 visit_count_++; |
249 for (DataMap::const_iterator i = extension_map_.begin(); | 253 for (DataMap::const_iterator i = extension_map_.begin(); |
250 i != extension_map_.end(); ++i) { | 254 i != extension_map_.end(); ++i) { |
251 Version version(i->second.first); | 255 scoped_ptr<Version> version(new Version(i->second.first)); |
252 | 256 |
253 visitor_->OnExternalExtensionFileFound( | 257 scoped_ptr<ExternalExtensionInstallInfoFile> info( |
254 i->first, &version, i->second.second, location_, | 258 new ExternalExtensionInstallInfoFile( |
255 Extension::NO_FLAGS, false, false); | 259 i->first, std::move(version), i->second.second, location_, |
260 Extension::NO_FLAGS, false, false)); | |
261 visitor_->OnExternalExtensionFileFound(info.get()); | |
256 } | 262 } |
257 visitor_->OnExternalProviderReady(this); | 263 visitor_->OnExternalProviderReady(this); |
258 } | 264 } |
259 | 265 |
260 bool HasExtension(const std::string& id) const override { | 266 bool HasExtension(const std::string& id) const override { |
261 return extension_map_.find(id) != extension_map_.end(); | 267 return extension_map_.find(id) != extension_map_.end(); |
262 } | 268 } |
263 | 269 |
264 bool GetExtensionDetails(const std::string& id, | 270 bool GetExtensionDetails(const std::string& id, |
265 Manifest::Location* location, | 271 Manifest::Location* location, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 } | 352 } |
347 | 353 |
348 // Reset our counter. | 354 // Reset our counter. |
349 ids_found_ = 0; | 355 ids_found_ = 0; |
350 // Ask the provider to look up all extensions and return them. | 356 // Ask the provider to look up all extensions and return them. |
351 provider_->VisitRegisteredExtension(); | 357 provider_->VisitRegisteredExtension(); |
352 | 358 |
353 return ids_found_; | 359 return ids_found_; |
354 } | 360 } |
355 | 361 |
356 bool OnExternalExtensionFileFound(const std::string& id, | 362 bool OnExternalExtensionFileFound( |
357 const Version* version, | 363 ExternalExtensionInstallInfoFile* info) override { |
358 const base::FilePath& path, | 364 EXPECT_EQ(expected_creation_flags_, info->creation_flags); |
359 Manifest::Location unused, | |
360 int creation_flags, | |
361 bool mark_acknowledged, | |
362 bool install_immediately) override { | |
363 EXPECT_EQ(expected_creation_flags_, creation_flags); | |
364 | 365 |
365 ++ids_found_; | 366 ++ids_found_; |
366 base::DictionaryValue* pref; | 367 base::DictionaryValue* pref; |
367 // This tests is to make sure that the provider only notifies us of the | 368 // This tests is to make sure that the provider only notifies us of the |
368 // values we gave it. So if the id we doesn't exist in our internal | 369 // values we gave it. So if the id we doesn't exist in our internal |
369 // dictionary then something is wrong. | 370 // dictionary then something is wrong. |
370 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 371 EXPECT_TRUE(prefs_->GetDictionary(info->extension_id, &pref)) |
371 << "Got back ID (" << id.c_str() << ") we weren't expecting"; | 372 << "Got back ID (" << info->extension_id.c_str() |
373 << ") we weren't expecting"; | |
372 | 374 |
373 EXPECT_TRUE(path.IsAbsolute()); | 375 EXPECT_TRUE(info->path.IsAbsolute()); |
374 if (!fake_base_path_.empty()) | 376 if (!fake_base_path_.empty()) |
375 EXPECT_TRUE(fake_base_path_.IsParent(path)); | 377 EXPECT_TRUE(fake_base_path_.IsParent(info->path)); |
376 | 378 |
377 if (pref) { | 379 if (pref) { |
378 EXPECT_TRUE(provider_->HasExtension(id)); | 380 EXPECT_TRUE(provider_->HasExtension(info->extension_id)); |
379 | 381 |
380 // Ask provider if the extension we got back is registered. | 382 // Ask provider if the extension we got back is registered. |
381 Manifest::Location location = Manifest::INVALID_LOCATION; | 383 Manifest::Location location = Manifest::INVALID_LOCATION; |
382 scoped_ptr<Version> v1; | 384 scoped_ptr<Version> v1; |
383 base::FilePath crx_path; | 385 base::FilePath crx_path; |
384 | 386 |
385 EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1)); | 387 EXPECT_TRUE( |
386 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); | 388 provider_->GetExtensionDetails(info->extension_id, NULL, &v1)); |
389 EXPECT_STREQ(info->version->GetString().c_str(), v1->GetString().c_str()); | |
387 | 390 |
388 scoped_ptr<Version> v2; | 391 scoped_ptr<Version> v2; |
389 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location, &v2)); | 392 EXPECT_TRUE( |
390 EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str()); | 393 provider_->GetExtensionDetails(info->extension_id, &location, &v2)); |
391 EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str()); | 394 EXPECT_STREQ(info->version->GetString().c_str(), v1->GetString().c_str()); |
395 EXPECT_STREQ(info->version->GetString().c_str(), v2->GetString().c_str()); | |
392 EXPECT_EQ(Manifest::EXTERNAL_PREF, location); | 396 EXPECT_EQ(Manifest::EXTERNAL_PREF, location); |
393 | 397 |
394 // Remove it so we won't count it ever again. | 398 // Remove it so we won't count it ever again. |
395 prefs_->Remove(id, NULL); | 399 prefs_->Remove(info->extension_id, NULL); |
396 } | 400 } |
397 return true; | 401 return true; |
398 } | 402 } |
399 | 403 |
400 bool OnExternalExtensionUpdateUrlFound(const std::string& id, | 404 bool OnExternalExtensionUpdateUrlFound( |
401 const std::string& install_parameter, | 405 ExternalExtensionInstallInfoUpdateUrl* info, |
402 const GURL& update_url, | 406 bool is_initial_load) override { |
403 Manifest::Location location, | |
404 int creation_flags, | |
405 bool mark_acknowledged) override { | |
406 ++ids_found_; | 407 ++ids_found_; |
407 base::DictionaryValue* pref; | 408 base::DictionaryValue* pref; |
408 // This tests is to make sure that the provider only notifies us of the | 409 // This tests is to make sure that the provider only notifies us of the |
409 // values we gave it. So if the id we doesn't exist in our internal | 410 // values we gave it. So if the id we doesn't exist in our internal |
410 // dictionary then something is wrong. | 411 // dictionary then something is wrong. |
411 EXPECT_TRUE(prefs_->GetDictionary(id, &pref)) | 412 EXPECT_TRUE(prefs_->GetDictionary(info->extension_id, &pref)) |
412 << L"Got back ID (" << id.c_str() << ") we weren't expecting"; | 413 << L"Got back ID (" << info->extension_id.c_str() |
413 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location); | 414 << ") we weren't expecting"; |
415 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, info->download_location); | |
414 | 416 |
415 if (pref) { | 417 if (pref) { |
416 EXPECT_TRUE(provider_->HasExtension(id)); | 418 EXPECT_TRUE(provider_->HasExtension(info->extension_id)); |
417 | 419 |
418 // External extensions with update URLs do not have versions. | 420 // External extensions with update URLs do not have versions. |
419 scoped_ptr<Version> v1; | 421 scoped_ptr<Version> v1; |
420 Manifest::Location location1 = Manifest::INVALID_LOCATION; | 422 Manifest::Location location1 = Manifest::INVALID_LOCATION; |
421 EXPECT_TRUE(provider_->GetExtensionDetails(id, &location1, &v1)); | 423 EXPECT_TRUE( |
424 provider_->GetExtensionDetails(info->extension_id, &location1, &v1)); | |
422 EXPECT_FALSE(v1.get()); | 425 EXPECT_FALSE(v1.get()); |
423 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); | 426 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); |
424 | 427 |
425 std::string parsed_install_parameter; | 428 std::string parsed_install_parameter; |
426 pref->GetString("install_parameter", &parsed_install_parameter); | 429 pref->GetString("install_parameter", &parsed_install_parameter); |
427 EXPECT_EQ(parsed_install_parameter, install_parameter); | 430 EXPECT_EQ(parsed_install_parameter, info->install_parameter); |
428 | 431 |
429 // Remove it so we won't count it again. | 432 // Remove it so we won't count it again. |
430 prefs_->Remove(id, NULL); | 433 prefs_->Remove(info->extension_id, NULL); |
431 } | 434 } |
432 return true; | 435 return true; |
433 } | 436 } |
434 | 437 |
438 void OnExternalProviderUpdateComplete( | |
439 const ExternalProviderInterface* provider, | |
440 const ScopedVector<ExternalExtensionInstallInfoUpdateUrl>& | |
441 update_url_extensions, | |
442 const ScopedVector<ExternalExtensionInstallInfoFile>& file_extensions, | |
443 const std::set<std::string>& removed_extensions) override { | |
444 ADD_FAILURE() << "Not tested path yet."; | |
asargent_no_longer_on_chrome
2016/01/25 18:50:52
You should add a test for this =)
lazyboy
2016/01/26 05:20:04
Done.
I've added a different provider since this o
asargent_no_longer_on_chrome
2016/01/26 17:48:07
I think what you've added is fine
| |
445 } | |
446 | |
435 void OnExternalProviderReady( | 447 void OnExternalProviderReady( |
436 const extensions::ExternalProviderInterface* provider) override { | 448 const extensions::ExternalProviderInterface* provider) override { |
437 EXPECT_EQ(provider, provider_.get()); | 449 EXPECT_EQ(provider, provider_.get()); |
438 EXPECT_TRUE(provider->IsReady()); | 450 EXPECT_TRUE(provider->IsReady()); |
439 } | 451 } |
440 | 452 |
441 Profile* profile() { return profile_.get(); } | 453 Profile* profile() { return profile_.get(); } |
442 | 454 |
443 private: | 455 private: |
444 int ids_found_; | 456 int ids_found_; |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1022 // extension object. | 1034 // extension object. |
1023 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { | 1035 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { |
1024 const char kPrefFromBookmark[] = "from_bookmark"; | 1036 const char kPrefFromBookmark[] = "from_bookmark"; |
1025 | 1037 |
1026 InitializeEmptyExtensionService(); | 1038 InitializeEmptyExtensionService(); |
1027 | 1039 |
1028 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1040 base::FilePath path = data_dir().AppendASCII("good.crx"); |
1029 service()->set_extensions_enabled(true); | 1041 service()->set_extensions_enabled(true); |
1030 | 1042 |
1031 // Register and install an external extension. | 1043 // Register and install an external extension. |
1032 Version version("1.0.0.0"); | 1044 scoped_ptr<Version> version(new Version("1.0.0.0")); |
1033 content::WindowedNotificationObserver observer( | 1045 content::WindowedNotificationObserver observer( |
1034 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1046 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1035 content::NotificationService::AllSources()); | 1047 content::NotificationService::AllSources()); |
1036 if (service()->OnExternalExtensionFileFound( | 1048 scoped_ptr<ExternalExtensionInstallInfoFile> info( |
1037 good_crx, | 1049 new ExternalExtensionInstallInfoFile( |
1038 &version, | 1050 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF, |
1039 path, | 1051 Extension::FROM_BOOKMARK, false /* mark_acknowledged */, |
1040 Manifest::EXTERNAL_PREF, | 1052 false /* install_immediately */)); |
1041 Extension::FROM_BOOKMARK, | 1053 if (service()->OnExternalExtensionFileFound(info.get())) |
1042 false /* mark_acknowledged */, | |
1043 false /* install_immediately */)) { | |
1044 observer.Wait(); | 1054 observer.Wait(); |
1045 } | |
1046 | 1055 |
1047 const Extension* extension = service()->GetExtensionById(good_crx, false); | 1056 const Extension* extension = service()->GetExtensionById(good_crx, false); |
1048 ASSERT_TRUE(extension); | 1057 ASSERT_TRUE(extension); |
1049 ASSERT_TRUE(extension->from_bookmark()); | 1058 ASSERT_TRUE(extension->from_bookmark()); |
1050 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); | 1059 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
1051 | 1060 |
1052 // Upgrade to version 2.0, the flag should be preserved. | 1061 // Upgrade to version 2.0, the flag should be preserved. |
1053 path = data_dir().AppendASCII("good2.crx"); | 1062 path = data_dir().AppendASCII("good2.crx"); |
1054 UpdateExtension(good_crx, path, ENABLED); | 1063 UpdateExtension(good_crx, path, ENABLED); |
1055 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); | 1064 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); |
1056 extension = service()->GetExtensionById(good_crx, false); | 1065 extension = service()->GetExtensionById(good_crx, false); |
1057 ASSERT_TRUE(extension); | 1066 ASSERT_TRUE(extension); |
1058 ASSERT_TRUE(extension->from_bookmark()); | 1067 ASSERT_TRUE(extension->from_bookmark()); |
1059 } | 1068 } |
1060 | 1069 |
1061 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED | 1070 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED |
1062 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { | 1071 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { |
1063 InitializeEmptyExtensionService(); | 1072 InitializeEmptyExtensionService(); |
1064 | 1073 |
1065 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1074 base::FilePath path = data_dir().AppendASCII("good.crx"); |
1066 service()->set_extensions_enabled(true); | 1075 service()->set_extensions_enabled(true); |
1067 | 1076 |
1068 // Install an external extension. | 1077 // Install an external extension. |
1069 Version version("1.0.0.0"); | |
1070 content::WindowedNotificationObserver observer( | 1078 content::WindowedNotificationObserver observer( |
1071 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1079 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1072 content::NotificationService::AllSources()); | 1080 content::NotificationService::AllSources()); |
1073 if (service()->OnExternalExtensionFileFound(good_crx, | 1081 scoped_ptr<Version> version(new Version("1.0.0.0")); |
1074 &version, | 1082 scoped_ptr<ExternalExtensionInstallInfoFile> info( |
1075 path, | 1083 new ExternalExtensionInstallInfoFile(good_crx, std::move(version), path, |
1076 Manifest::EXTERNAL_PREF, | 1084 Manifest::EXTERNAL_PREF, |
1077 Extension::NO_FLAGS, | 1085 Extension::NO_FLAGS, false, false)); |
1078 false, | 1086 if (service()->OnExternalExtensionFileFound(info.get())) |
1079 false)) { | |
1080 observer.Wait(); | 1087 observer.Wait(); |
1081 } | |
1082 | 1088 |
1083 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); | 1089 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
1084 | 1090 |
1085 // Uninstall it and check that its killbit gets set. | 1091 // Uninstall it and check that its killbit gets set. |
1086 UninstallExtension(good_crx, false); | 1092 UninstallExtension(good_crx, false); |
1087 ValidateIntegerPref(good_crx, "state", | 1093 ValidateIntegerPref(good_crx, "state", |
1088 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1094 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1089 | 1095 |
1090 // Try to re-install it externally. This should fail because of the killbit. | 1096 service()->OnExternalExtensionFileFound(info.get()); |
1091 service()->OnExternalExtensionFileFound(good_crx, | |
1092 &version, | |
1093 path, | |
1094 Manifest::EXTERNAL_PREF, | |
1095 Extension::NO_FLAGS, | |
1096 false, | |
1097 false); | |
1098 base::RunLoop().RunUntilIdle(); | 1097 base::RunLoop().RunUntilIdle(); |
1099 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); | 1098 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); |
1100 ValidateIntegerPref(good_crx, "state", | 1099 ValidateIntegerPref(good_crx, "state", |
1101 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1100 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1102 | 1101 |
1103 version = Version("1.0.0.1"); | 1102 version.reset(new Version("1.0.0.0")); |
1104 // Repeat the same thing with a newer version of the extension. | 1103 // Repeat the same thing with a newer version of the extension. |
1105 path = data_dir().AppendASCII("good2.crx"); | 1104 path = data_dir().AppendASCII("good2.crx"); |
1106 service()->OnExternalExtensionFileFound(good_crx, | 1105 info.reset(new ExternalExtensionInstallInfoFile( |
1107 &version, | 1106 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF, |
1108 path, | 1107 Extension::NO_FLAGS, false, false)); |
1109 Manifest::EXTERNAL_PREF, | 1108 service()->OnExternalExtensionFileFound(info.get()); |
1110 Extension::NO_FLAGS, | |
1111 false, | |
1112 false); | |
1113 base::RunLoop().RunUntilIdle(); | 1109 base::RunLoop().RunUntilIdle(); |
1114 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); | 1110 ASSERT_TRUE(NULL == service()->GetExtensionById(good_crx, false)); |
1115 ValidateIntegerPref(good_crx, "state", | 1111 ValidateIntegerPref(good_crx, "state", |
1116 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1112 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
1117 | 1113 |
1118 // Try adding the same extension from an external update URL. | 1114 // Try adding the same extension from an external update URL. |
1119 ASSERT_FALSE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( | 1115 ASSERT_FALSE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( |
1120 good_crx, | 1116 good_crx, |
1121 std::string(), | 1117 std::string(), |
1122 GURL("http:://fake.update/url"), | 1118 GURL("http:://fake.update/url"), |
(...skipping 30 matching lines...) Expand all Loading... | |
1153 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); | 1149 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); |
1154 service()->OnExternalProviderReady(&provider); | 1150 service()->OnExternalProviderReady(&provider); |
1155 } | 1151 } |
1156 | 1152 |
1157 // Test that external extensions with incorrect IDs are not installed. | 1153 // Test that external extensions with incorrect IDs are not installed. |
1158 TEST_F(ExtensionServiceTest, FailOnWrongId) { | 1154 TEST_F(ExtensionServiceTest, FailOnWrongId) { |
1159 InitializeEmptyExtensionService(); | 1155 InitializeEmptyExtensionService(); |
1160 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1156 base::FilePath path = data_dir().AppendASCII("good.crx"); |
1161 service()->set_extensions_enabled(true); | 1157 service()->set_extensions_enabled(true); |
1162 | 1158 |
1163 Version version("1.0.0.0"); | 1159 scoped_ptr<Version> version(new Version("1.0.0.0")); |
1164 | 1160 |
1165 const std::string wrong_id = all_zero; | 1161 const std::string wrong_id = all_zero; |
1166 const std::string correct_id = good_crx; | 1162 const std::string correct_id = good_crx; |
1167 ASSERT_NE(correct_id, wrong_id); | 1163 ASSERT_NE(correct_id, wrong_id); |
1168 | 1164 |
1169 // Install an external extension with an ID from the external | 1165 // Install an external extension with an ID from the external |
1170 // source that is not equal to the ID in the extension manifest. | 1166 // source that is not equal to the ID in the extension manifest. |
1171 content::WindowedNotificationObserver observer( | 1167 content::WindowedNotificationObserver observer( |
1172 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1168 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1173 content::NotificationService::AllSources()); | 1169 content::NotificationService::AllSources()); |
1174 service()->OnExternalExtensionFileFound(wrong_id, | 1170 scoped_ptr<ExternalExtensionInstallInfoFile> info( |
1175 &version, | 1171 new ExternalExtensionInstallInfoFile(wrong_id, std::move(version), path, |
1176 path, | 1172 Manifest::EXTERNAL_PREF, |
1177 Manifest::EXTERNAL_PREF, | 1173 Extension::NO_FLAGS, false, false)); |
1178 Extension::NO_FLAGS, | 1174 service()->OnExternalExtensionFileFound(info.get()); |
1179 false, | |
1180 false); | |
1181 | 1175 |
1182 observer.Wait(); | 1176 observer.Wait(); |
1183 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); | 1177 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); |
1184 | 1178 |
1185 // Try again with the right ID. Expect success. | 1179 // Try again with the right ID. Expect success. |
1186 content::WindowedNotificationObserver observer2( | 1180 content::WindowedNotificationObserver observer2( |
1187 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1181 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1188 content::NotificationService::AllSources()); | 1182 content::NotificationService::AllSources()); |
1189 if (service()->OnExternalExtensionFileFound(correct_id, | 1183 info->extension_id = correct_id; |
1190 &version, | 1184 if (service()->OnExternalExtensionFileFound(info.get())) |
1191 path, | |
1192 Manifest::EXTERNAL_PREF, | |
1193 Extension::NO_FLAGS, | |
1194 false, | |
1195 false)) { | |
1196 observer2.Wait(); | 1185 observer2.Wait(); |
1197 } | |
1198 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); | 1186 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
1199 } | 1187 } |
1200 | 1188 |
1201 // Test that external extensions with incorrect versions are not installed. | 1189 // Test that external extensions with incorrect versions are not installed. |
1202 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { | 1190 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { |
1203 InitializeEmptyExtensionService(); | 1191 InitializeEmptyExtensionService(); |
1204 base::FilePath path = data_dir().AppendASCII("good.crx"); | 1192 base::FilePath path = data_dir().AppendASCII("good.crx"); |
1205 service()->set_extensions_enabled(true); | 1193 service()->set_extensions_enabled(true); |
1206 | 1194 |
1207 // Install an external extension with a version from the external | 1195 // Install an external extension with a version from the external |
1208 // source that is not equal to the version in the extension manifest. | 1196 // source that is not equal to the version in the extension manifest. |
1209 Version wrong_version("1.2.3.4"); | |
1210 content::WindowedNotificationObserver observer( | 1197 content::WindowedNotificationObserver observer( |
1211 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1198 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1212 content::NotificationService::AllSources()); | 1199 content::NotificationService::AllSources()); |
1213 service()->OnExternalExtensionFileFound(good_crx, | 1200 scoped_ptr<Version> wrong_version(new Version("1.2.3.4")); |
1214 &wrong_version, | 1201 scoped_ptr<ExternalExtensionInstallInfoFile> info( |
1215 path, | 1202 new ExternalExtensionInstallInfoFile(good_crx, std::move(wrong_version), |
1216 Manifest::EXTERNAL_PREF, | 1203 path, Manifest::EXTERNAL_PREF, |
1217 Extension::NO_FLAGS, | 1204 Extension::NO_FLAGS, false, false)); |
1218 false, | 1205 service()->OnExternalExtensionFileFound(info.get()); |
1219 false); | |
1220 | 1206 |
1221 observer.Wait(); | 1207 observer.Wait(); |
1222 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); | 1208 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); |
1223 | 1209 |
1224 // Try again with the right version. Expect success. | 1210 // Try again with the right version. Expect success. |
1225 service()->pending_extension_manager()->Remove(good_crx); | 1211 service()->pending_extension_manager()->Remove(good_crx); |
1226 Version correct_version("1.0.0.0"); | 1212 scoped_ptr<Version> correct_version(new Version("1.0.0.0")); |
1213 info->version = std::move(correct_version); | |
1227 content::WindowedNotificationObserver observer2( | 1214 content::WindowedNotificationObserver observer2( |
1228 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 1215 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
1229 content::NotificationService::AllSources()); | 1216 content::NotificationService::AllSources()); |
1230 if (service()->OnExternalExtensionFileFound(good_crx, | 1217 if (service()->OnExternalExtensionFileFound(info.get())) |
1231 &correct_version, | |
1232 path, | |
1233 Manifest::EXTERNAL_PREF, | |
1234 Extension::NO_FLAGS, | |
1235 false, | |
1236 false)) { | |
1237 observer2.Wait(); | 1218 observer2.Wait(); |
1238 } | |
1239 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); | 1219 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); |
1240 } | 1220 } |
1241 | 1221 |
1242 // Install a user script (they get converted automatically to an extension) | 1222 // Install a user script (they get converted automatically to an extension) |
1243 TEST_F(ExtensionServiceTest, InstallUserScript) { | 1223 TEST_F(ExtensionServiceTest, InstallUserScript) { |
1244 // The details of script conversion are tested elsewhere, this just tests | 1224 // The details of script conversion are tested elsewhere, this just tests |
1245 // integration with ExtensionService. | 1225 // integration with ExtensionService. |
1246 InitializeEmptyExtensionService(); | 1226 InitializeEmptyExtensionService(); |
1247 | 1227 |
1248 base::FilePath path = data_dir().AppendASCII("user_script_basic.user.js"); | 1228 base::FilePath path = data_dir().AppendASCII("user_script_basic.user.js"); |
(...skipping 4039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5288 InstallCRX(path, INSTALL_NEW); | 5268 InstallCRX(path, INSTALL_NEW); |
5289 ValidatePrefKeyCount(1u); | 5269 ValidatePrefKeyCount(1u); |
5290 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 5270 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
5291 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); | 5271 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
5292 | 5272 |
5293 extensions::PendingExtensionManager* pending = | 5273 extensions::PendingExtensionManager* pending = |
5294 service()->pending_extension_manager(); | 5274 service()->pending_extension_manager(); |
5295 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5275 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5296 | 5276 |
5297 // Skip install when the location is the same. | 5277 // Skip install when the location is the same. |
5298 EXPECT_FALSE( | 5278 scoped_ptr<GURL> good_update_url(new GURL(kGoodUpdateURL)); |
5299 service()->OnExternalExtensionUpdateUrlFound(kGoodId, | 5279 scoped_ptr<ExternalExtensionInstallInfoUpdateUrl> info( |
5300 std::string(), | 5280 new ExternalExtensionInstallInfoUpdateUrl( |
5301 GURL(kGoodUpdateURL), | 5281 kGoodId, std::string(), std::move(good_update_url), |
5302 Manifest::INTERNAL, | 5282 Manifest::INTERNAL, Extension::NO_FLAGS, false)); |
5303 Extension::NO_FLAGS, | 5283 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(info.get(), true)); |
5304 false)); | |
5305 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5284 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5306 | 5285 |
5307 // Install when the location has higher priority. | 5286 // Install when the location has higher priority. |
5308 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound( | 5287 info->download_location = Manifest::EXTERNAL_POLICY_DOWNLOAD; |
5309 kGoodId, | 5288 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(info.get(), true)); |
5310 std::string(), | |
5311 GURL(kGoodUpdateURL), | |
5312 Manifest::EXTERNAL_POLICY_DOWNLOAD, | |
5313 Extension::NO_FLAGS, | |
5314 false)); | |
5315 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5289 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5316 | 5290 |
5317 // Try the low priority again. Should be rejected. | 5291 // Try the low priority again. Should be rejected. |
5318 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound( | 5292 info->download_location = Manifest::EXTERNAL_PREF_DOWNLOAD; |
5319 kGoodId, | 5293 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(info.get(), true)); |
5320 std::string(), | |
5321 GURL(kGoodUpdateURL), | |
5322 Manifest::EXTERNAL_PREF_DOWNLOAD, | |
5323 Extension::NO_FLAGS, | |
5324 false)); | |
5325 // The existing record should still be present in the pending extension | 5294 // The existing record should still be present in the pending extension |
5326 // manager. | 5295 // manager. |
5327 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5296 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5328 | 5297 |
5329 pending->Remove(kGoodId); | 5298 pending->Remove(kGoodId); |
5330 | 5299 |
5331 // Skip install when the location has the same priority as the installed | 5300 // Skip install when the location has the same priority as the installed |
5332 // location. | 5301 // location. |
5333 EXPECT_FALSE( | 5302 info->download_location = Manifest::INTERNAL; |
5334 service()->OnExternalExtensionUpdateUrlFound(kGoodId, | 5303 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(info.get(), true)); |
5335 std::string(), | |
5336 GURL(kGoodUpdateURL), | |
5337 Manifest::INTERNAL, | |
5338 Extension::NO_FLAGS, | |
5339 false)); | |
5340 | 5304 |
5341 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5305 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5342 } | 5306 } |
5343 | 5307 |
5344 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { | 5308 TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) { |
5345 Version older_version("0.1.0.0"); | 5309 Version older_version("0.1.0.0"); |
5346 Version newer_version("2.0.0.0"); | 5310 Version newer_version("2.0.0.0"); |
5347 | 5311 |
5348 // We don't want the extension to be installed. A path that doesn't | 5312 // We don't want the extension to be installed. A path that doesn't |
5349 // point to a valid CRX ensures this. | 5313 // point to a valid CRX ensures this. |
(...skipping 17 matching lines...) Expand all Loading... | |
5367 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, | 5331 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, |
5368 Manifest::INTERNAL)); | 5332 Manifest::INTERNAL)); |
5369 ASSERT_EQ(Manifest::EXTERNAL_PREF, | 5333 ASSERT_EQ(Manifest::EXTERNAL_PREF, |
5370 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, | 5334 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, |
5371 Manifest::INTERNAL)); | 5335 Manifest::INTERNAL)); |
5372 | 5336 |
5373 extensions::PendingExtensionManager* pending = | 5337 extensions::PendingExtensionManager* pending = |
5374 service()->pending_extension_manager(); | 5338 service()->pending_extension_manager(); |
5375 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5339 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5376 | 5340 |
5341 scoped_ptr<Version> older_version_ptr(new Version(older_version)); | |
5342 scoped_ptr<ExternalExtensionInstallInfoFile> info( | |
5343 new ExternalExtensionInstallInfoFile( | |
5344 kGoodId, std::move(older_version_ptr), kInvalidPathToCrx, | |
5345 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged, | |
5346 kDontInstallImmediately)); | |
5377 { | 5347 { |
5378 // Simulate an external source adding the extension as INTERNAL. | 5348 // Simulate an external source adding the extension as INTERNAL. |
5379 content::WindowedNotificationObserver observer( | 5349 content::WindowedNotificationObserver observer( |
5380 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 5350 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
5381 content::NotificationService::AllSources()); | 5351 content::NotificationService::AllSources()); |
5382 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5352 EXPECT_TRUE(service()->OnExternalExtensionFileFound(info.get())); |
5383 kGoodId, | |
5384 &older_version, | |
5385 kInvalidPathToCrx, | |
5386 Manifest::INTERNAL, | |
5387 kCreationFlags, | |
5388 kDontMarkAcknowledged, | |
5389 kDontInstallImmediately)); | |
5390 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5353 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5391 observer.Wait(); | 5354 observer.Wait(); |
5392 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); | 5355 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
5393 } | 5356 } |
5394 | 5357 |
5395 { | 5358 { |
5396 // Simulate an external source adding the extension as EXTERNAL_PREF. | 5359 // Simulate an external source adding the extension as EXTERNAL_PREF. |
5397 content::WindowedNotificationObserver observer( | 5360 content::WindowedNotificationObserver observer( |
5398 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 5361 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
5399 content::NotificationService::AllSources()); | 5362 content::NotificationService::AllSources()); |
5400 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5363 info->crx_location = Manifest::EXTERNAL_PREF; |
5401 kGoodId, | 5364 EXPECT_TRUE(service()->OnExternalExtensionFileFound(info.get())); |
5402 &older_version, | |
5403 kInvalidPathToCrx, | |
5404 Manifest::EXTERNAL_PREF, | |
5405 kCreationFlags, | |
5406 kDontMarkAcknowledged, | |
5407 kDontInstallImmediately)); | |
5408 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5365 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5409 observer.Wait(); | 5366 observer.Wait(); |
5410 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); | 5367 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
5411 } | 5368 } |
5412 | 5369 |
5413 // Simulate an external source adding as EXTERNAL_PREF again. | 5370 // Simulate an external source adding as EXTERNAL_PREF again. |
5414 // This is rejected because the version and the location are the same as | 5371 // This is rejected because the version and the location are the same as |
5415 // the previous installation, which is still pending. | 5372 // the previous installation, which is still pending. |
5416 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5373 EXPECT_FALSE(service()->OnExternalExtensionFileFound(info.get())); |
5417 kGoodId, | |
5418 &older_version, | |
5419 kInvalidPathToCrx, | |
5420 Manifest::EXTERNAL_PREF, | |
5421 kCreationFlags, | |
5422 kDontMarkAcknowledged, | |
5423 kDontInstallImmediately)); | |
5424 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5374 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5425 | 5375 |
5426 // Try INTERNAL again. Should fail. | 5376 // Try INTERNAL again. Should fail. |
5427 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5377 info->crx_location = Manifest::INTERNAL; |
5428 kGoodId, | 5378 EXPECT_FALSE(service()->OnExternalExtensionFileFound(info.get())); |
5429 &older_version, | |
5430 kInvalidPathToCrx, | |
5431 Manifest::INTERNAL, | |
5432 kCreationFlags, | |
5433 kDontMarkAcknowledged, | |
5434 kDontInstallImmediately)); | |
5435 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5379 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5436 | 5380 |
5437 { | 5381 { |
5438 // Now the registry adds the extension. | 5382 // Now the registry adds the extension. |
5439 content::WindowedNotificationObserver observer( | 5383 content::WindowedNotificationObserver observer( |
5440 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 5384 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
5441 content::NotificationService::AllSources()); | 5385 content::NotificationService::AllSources()); |
5442 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5386 info->crx_location = Manifest::EXTERNAL_REGISTRY; |
5443 kGoodId, | 5387 EXPECT_TRUE(service()->OnExternalExtensionFileFound(info.get())); |
5444 &older_version, | |
5445 kInvalidPathToCrx, | |
5446 Manifest::EXTERNAL_REGISTRY, | |
5447 kCreationFlags, | |
5448 kDontMarkAcknowledged, | |
5449 kDontInstallImmediately)); | |
5450 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5388 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5451 observer.Wait(); | 5389 observer.Wait(); |
5452 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); | 5390 VerifyCrxInstall(kInvalidPathToCrx, INSTALL_FAILED); |
5453 } | 5391 } |
5454 | 5392 |
5455 // Registry outranks both external pref and internal, so both fail. | 5393 // Registry outranks both external pref and internal, so both fail. |
5456 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5394 info->crx_location = Manifest::EXTERNAL_PREF; |
5457 kGoodId, | 5395 EXPECT_FALSE(service()->OnExternalExtensionFileFound(info.get())); |
5458 &older_version, | |
5459 kInvalidPathToCrx, | |
5460 Manifest::EXTERNAL_PREF, | |
5461 kCreationFlags, | |
5462 kDontMarkAcknowledged, | |
5463 kDontInstallImmediately)); | |
5464 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5396 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5465 | 5397 |
5466 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5398 info->crx_location = Manifest::INTERNAL; |
5467 kGoodId, | 5399 EXPECT_FALSE(service()->OnExternalExtensionFileFound(info.get())); |
5468 &older_version, | |
5469 kInvalidPathToCrx, | |
5470 Manifest::INTERNAL, | |
5471 kCreationFlags, | |
5472 kDontMarkAcknowledged, | |
5473 kDontInstallImmediately)); | |
5474 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5400 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5475 | 5401 |
5476 pending->Remove(kGoodId); | 5402 pending->Remove(kGoodId); |
5477 | 5403 |
5478 // Install the extension. | 5404 // Install the extension. |
5479 base::FilePath path = data_dir().AppendASCII("good.crx"); | 5405 base::FilePath path = data_dir().AppendASCII("good.crx"); |
5480 const Extension* ext = InstallCRX(path, INSTALL_NEW); | 5406 const Extension* ext = InstallCRX(path, INSTALL_NEW); |
5481 ValidatePrefKeyCount(1u); | 5407 ValidatePrefKeyCount(1u); |
5482 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 5408 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
5483 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); | 5409 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); |
5484 | 5410 |
5485 // Now test the logic of OnExternalExtensionFileFound() when the extension | 5411 // Now test the logic of OnExternalExtensionFileFound() when the extension |
5486 // being added is already installed. | 5412 // being added is already installed. |
5487 | 5413 |
5488 // Tests assume |older_version| is less than the installed version, and | 5414 // Tests assume |older_version| is less than the installed version, and |
5489 // |newer_version| is greater. Verify this: | 5415 // |newer_version| is greater. Verify this: |
5490 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); | 5416 ASSERT_TRUE(older_version.IsOlderThan(ext->VersionString())); |
5491 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); | 5417 ASSERT_TRUE(ext->version()->IsOlderThan(newer_version.GetString())); |
5492 | 5418 |
5493 // An external install for the same location should fail if the version is | 5419 // An external install for the same location should fail if the version is |
5494 // older, or the same, and succeed if the version is newer. | 5420 // older, or the same, and succeed if the version is newer. |
5495 | 5421 |
5496 // Older than the installed version... | 5422 // Older than the installed version... |
5497 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5423 info->version.reset(new Version(older_version)); |
5498 kGoodId, | 5424 EXPECT_FALSE(service()->OnExternalExtensionFileFound(info.get())); |
5499 &older_version, | |
5500 kInvalidPathToCrx, | |
5501 Manifest::INTERNAL, | |
5502 kCreationFlags, | |
5503 kDontMarkAcknowledged, | |
5504 kDontInstallImmediately)); | |
5505 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5425 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5506 | 5426 |
5507 // Same version as the installed version... | 5427 // Same version as the installed version... |
5508 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5428 info->version.reset(new Version(ext->VersionString())); |
5509 kGoodId, | 5429 EXPECT_FALSE(service()->OnExternalExtensionFileFound(info.get())); |
5510 ext->version(), | |
5511 kInvalidPathToCrx, | |
5512 Manifest::INTERNAL, | |
5513 kCreationFlags, | |
5514 kDontMarkAcknowledged, | |
5515 kDontInstallImmediately)); | |
5516 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5430 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5517 | 5431 |
5518 // Newer than the installed version... | 5432 // Newer than the installed version... |
5519 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5433 info->version.reset(new Version(newer_version)); |
5520 kGoodId, | 5434 EXPECT_TRUE(service()->OnExternalExtensionFileFound(info.get())); |
5521 &newer_version, | |
5522 kInvalidPathToCrx, | |
5523 Manifest::INTERNAL, | |
5524 kCreationFlags, | |
5525 kDontMarkAcknowledged, | |
5526 kDontInstallImmediately)); | |
5527 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5435 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5528 | 5436 |
5529 // An external install for a higher priority install source should succeed | 5437 // An external install for a higher priority install source should succeed |
5530 // if the version is greater. |older_version| is not... | 5438 // if the version is greater. |older_version| is not... |
5531 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5439 info->version.reset(new Version(older_version)); |
5532 kGoodId, | 5440 info->crx_location = Manifest::EXTERNAL_PREF; |
5533 &older_version, | 5441 EXPECT_FALSE(service()->OnExternalExtensionFileFound(info.get())); |
5534 kInvalidPathToCrx, | |
5535 Manifest::EXTERNAL_PREF, | |
5536 kCreationFlags, | |
5537 kDontMarkAcknowledged, | |
5538 kDontInstallImmediately)); | |
5539 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5442 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5540 | 5443 |
5541 // |newer_version| is newer. | 5444 // |newer_version| is newer. |
5542 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5445 info->version.reset(new Version(newer_version)); |
5543 kGoodId, | 5446 EXPECT_TRUE(service()->OnExternalExtensionFileFound(info.get())); |
5544 &newer_version, | |
5545 kInvalidPathToCrx, | |
5546 Manifest::EXTERNAL_PREF, | |
5547 kCreationFlags, | |
5548 kDontMarkAcknowledged, | |
5549 kDontInstallImmediately)); | |
5550 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5447 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5551 | 5448 |
5552 // An external install for an even higher priority install source should | 5449 // An external install for an even higher priority install source should |
5553 // succeed if the version is greater. | 5450 // succeed if the version is greater. |
5554 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5451 info->crx_location = Manifest::EXTERNAL_REGISTRY; |
5555 kGoodId, | 5452 EXPECT_TRUE(service()->OnExternalExtensionFileFound(info.get())); |
5556 &newer_version, | |
5557 kInvalidPathToCrx, | |
5558 Manifest::EXTERNAL_REGISTRY, | |
5559 kCreationFlags, | |
5560 kDontMarkAcknowledged, | |
5561 kDontInstallImmediately)); | |
5562 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5453 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5563 | 5454 |
5564 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, | 5455 // Because EXTERNAL_PREF is a lower priority source than EXTERNAL_REGISTRY, |
5565 // adding from external pref will now fail. | 5456 // adding from external pref will now fail. |
5566 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5457 info->crx_location = Manifest::EXTERNAL_PREF; |
5567 kGoodId, | 5458 EXPECT_FALSE(service()->OnExternalExtensionFileFound(info.get())); |
5568 &newer_version, | |
5569 kInvalidPathToCrx, | |
5570 Manifest::EXTERNAL_PREF, | |
5571 kCreationFlags, | |
5572 kDontMarkAcknowledged, | |
5573 kDontInstallImmediately)); | |
5574 EXPECT_TRUE(pending->IsIdPending(kGoodId)); | 5459 EXPECT_TRUE(pending->IsIdPending(kGoodId)); |
5575 } | 5460 } |
5576 | 5461 |
5577 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { | 5462 TEST_F(ExtensionServiceTest, ConcurrentExternalLocalFile) { |
5578 Version kVersion123("1.2.3"); | 5463 Version kVersion123("1.2.3"); |
5579 Version kVersion124("1.2.4"); | 5464 Version kVersion124("1.2.4"); |
5580 Version kVersion125("1.2.5"); | 5465 Version kVersion125("1.2.5"); |
5581 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path")); | 5466 const base::FilePath kInvalidPathToCrx(FILE_PATH_LITERAL("invalid_path")); |
5582 const int kCreationFlags = 0; | 5467 const int kCreationFlags = 0; |
5583 const bool kDontMarkAcknowledged = false; | 5468 const bool kDontMarkAcknowledged = false; |
5584 const bool kDontInstallImmediately = false; | 5469 const bool kDontInstallImmediately = false; |
5585 | 5470 |
5586 InitializeEmptyExtensionService(); | 5471 InitializeEmptyExtensionService(); |
5587 | 5472 |
5588 extensions::PendingExtensionManager* pending = | 5473 extensions::PendingExtensionManager* pending = |
5589 service()->pending_extension_manager(); | 5474 service()->pending_extension_manager(); |
5590 EXPECT_FALSE(pending->IsIdPending(kGoodId)); | 5475 EXPECT_FALSE(pending->IsIdPending(kGoodId)); |
5591 | 5476 |
5592 // An external provider starts installing from a local crx. | 5477 // An external provider starts installing from a local crx. |
5593 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5478 scoped_ptr<ExternalExtensionInstallInfoFile> info( |
5594 kGoodId, | 5479 new ExternalExtensionInstallInfoFile( |
5595 &kVersion123, | 5480 kGoodId, make_scoped_ptr(new Version(kVersion123)), kInvalidPathToCrx, |
5596 kInvalidPathToCrx, | 5481 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged, |
5597 Manifest::EXTERNAL_PREF, | 5482 kDontInstallImmediately)); |
5598 kCreationFlags, | 5483 EXPECT_TRUE(service()->OnExternalExtensionFileFound(info.get())); |
5599 kDontMarkAcknowledged, | 5484 const extensions::PendingExtensionInfo* pending_info; |
5600 kDontInstallImmediately)); | 5485 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
5601 const extensions::PendingExtensionInfo* info; | 5486 EXPECT_TRUE(pending_info->version().IsValid()); |
5602 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5487 EXPECT_TRUE(pending_info->version().Equals(kVersion123)); |
5603 EXPECT_TRUE(info->version().IsValid()); | |
5604 EXPECT_TRUE(info->version().Equals(kVersion123)); | |
5605 | 5488 |
5606 // Adding a newer version overrides the currently pending version. | 5489 // Adding a newer version overrides the currently pending version. |
5607 EXPECT_TRUE(service()->OnExternalExtensionFileFound( | 5490 info->version.reset(new Version(kVersion124)); |
5608 kGoodId, | 5491 EXPECT_TRUE(service()->OnExternalExtensionFileFound(info.get())); |
5609 &kVersion124, | 5492 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
5610 kInvalidPathToCrx, | 5493 EXPECT_TRUE(pending_info->version().IsValid()); |
5611 Manifest::EXTERNAL_PREF, | 5494 EXPECT_TRUE(pending_info->version().Equals(kVersion124)); |
5612 kCreationFlags, | |
5613 kDontMarkAcknowledged, | |
5614 kDontInstallImmediately)); | |
5615 EXPECT_TRUE((info = pending->GetById(kGoodId))); | |
5616 EXPECT_TRUE(info->version().IsValid()); | |
5617 EXPECT_TRUE(info->version().Equals(kVersion124)); | |
5618 | 5495 |
5619 // Adding an older version fails. | 5496 // Adding an older version fails. |
5620 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5497 info->version.reset(new Version(kVersion123)); |
5621 kGoodId, | 5498 EXPECT_FALSE(service()->OnExternalExtensionFileFound(info.get())); |
5622 &kVersion123, | 5499 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
5623 kInvalidPathToCrx, | 5500 EXPECT_TRUE(pending_info->version().IsValid()); |
5624 Manifest::EXTERNAL_PREF, | 5501 EXPECT_TRUE(pending_info->version().Equals(kVersion124)); |
5625 kCreationFlags, | |
5626 kDontMarkAcknowledged, | |
5627 kDontInstallImmediately)); | |
5628 EXPECT_TRUE((info = pending->GetById(kGoodId))); | |
5629 EXPECT_TRUE(info->version().IsValid()); | |
5630 EXPECT_TRUE(info->version().Equals(kVersion124)); | |
5631 | 5502 |
5632 // Adding an older version fails even when coming from a higher-priority | 5503 // Adding an older version fails even when coming from a higher-priority |
5633 // location. | 5504 // location. |
5634 EXPECT_FALSE(service()->OnExternalExtensionFileFound( | 5505 info->crx_location = Manifest::EXTERNAL_REGISTRY; |
5635 kGoodId, | 5506 EXPECT_FALSE(service()->OnExternalExtensionFileFound(info.get())); |
5636 &kVersion123, | 5507 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
5637 kInvalidPathToCrx, | 5508 EXPECT_TRUE(pending_info->version().IsValid()); |
5638 Manifest::EXTERNAL_REGISTRY, | 5509 EXPECT_TRUE(pending_info->version().Equals(kVersion124)); |
5639 kCreationFlags, | |
5640 kDontMarkAcknowledged, | |
5641 kDontInstallImmediately)); | |
5642 EXPECT_TRUE((info = pending->GetById(kGoodId))); | |
5643 EXPECT_TRUE(info->version().IsValid()); | |
5644 EXPECT_TRUE(info->version().Equals(kVersion124)); | |
5645 | 5510 |
5646 // Adding the latest version from the webstore overrides a specific version. | 5511 // Adding the latest version from the webstore overrides a specific version. |
5647 GURL kUpdateUrl("http://example.com/update"); | 5512 GURL kUpdateUrl("http://example.com/update"); |
5648 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound( | 5513 scoped_ptr<ExternalExtensionInstallInfoUpdateUrl> update_info( |
5649 kGoodId, | 5514 new ExternalExtensionInstallInfoUpdateUrl( |
5650 std::string(), | 5515 kGoodId, std::string(), make_scoped_ptr(new GURL(kUpdateUrl)), |
5651 kUpdateUrl, | 5516 Manifest::EXTERNAL_POLICY_DOWNLOAD, Extension::NO_FLAGS, false)); |
5652 Manifest::EXTERNAL_POLICY_DOWNLOAD, | 5517 EXPECT_TRUE( |
5653 Extension::NO_FLAGS, | 5518 service()->OnExternalExtensionUpdateUrlFound(update_info.get(), true)); |
5654 false)); | 5519 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); |
5655 EXPECT_TRUE((info = pending->GetById(kGoodId))); | 5520 EXPECT_FALSE(pending_info->version().IsValid()); |
5656 EXPECT_FALSE(info->version().IsValid()); | |
5657 } | 5521 } |
5658 | 5522 |
5659 // This makes sure we can package and install CRX files that use whitelisted | 5523 // This makes sure we can package and install CRX files that use whitelisted |
5660 // permissions. | 5524 // permissions. |
5661 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { | 5525 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { |
5662 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; | 5526 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; |
5663 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 5527 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
5664 extensions::switches::kWhitelistedExtensionID, test_id); | 5528 extensions::switches::kWhitelistedExtensionID, test_id); |
5665 | 5529 |
5666 InitializeEmptyExtensionService(); | 5530 InitializeEmptyExtensionService(); |
(...skipping 30 matching lines...) Expand all Loading... | |
5697 crx_id_, | 5561 crx_id_, |
5698 std::string(), | 5562 std::string(), |
5699 GURL(), | 5563 GURL(), |
5700 Manifest::EXTERNAL_PREF_DOWNLOAD, | 5564 Manifest::EXTERNAL_PREF_DOWNLOAD, |
5701 Extension::NO_FLAGS, | 5565 Extension::NO_FLAGS, |
5702 false); | 5566 false); |
5703 } | 5567 } |
5704 | 5568 |
5705 // Fake an external file from external_extensions.json. | 5569 // Fake an external file from external_extensions.json. |
5706 bool AddPendingExternalPrefFileInstall() { | 5570 bool AddPendingExternalPrefFileInstall() { |
5707 Version version("1.0.0.0"); | 5571 scoped_ptr<Version> version(new Version("1.0.0.0")); |
5708 | 5572 scoped_ptr<ExternalExtensionInstallInfoFile> info( |
5709 return service()->OnExternalExtensionFileFound(crx_id_, | 5573 new ExternalExtensionInstallInfoFile( |
5710 &version, | 5574 crx_id_, std::move(version), crx_path_, Manifest::EXTERNAL_PREF, |
5711 crx_path_, | 5575 Extension::NO_FLAGS, false, false)); |
5712 Manifest::EXTERNAL_PREF, | 5576 return service()->OnExternalExtensionFileFound(info.get()); |
5713 Extension::NO_FLAGS, | |
5714 false, | |
5715 false); | |
5716 } | 5577 } |
5717 | 5578 |
5718 // Fake a request from sync to install an extension. | 5579 // Fake a request from sync to install an extension. |
5719 bool AddPendingSyncInstall() { | 5580 bool AddPendingSyncInstall() { |
5720 return service()->pending_extension_manager()->AddFromSync( | 5581 return service()->pending_extension_manager()->AddFromSync( |
5721 crx_id_, | 5582 crx_id_, |
5722 GURL(kGoodUpdateURL), | 5583 GURL(kGoodUpdateURL), |
5723 base::Version(), | 5584 base::Version(), |
5724 &IsExtension, | 5585 &IsExtension, |
5725 kGoodRemoteInstall, | 5586 kGoodRemoteInstall, |
5726 kGoodInstalledByCustodian); | 5587 kGoodInstalledByCustodian); |
5727 } | 5588 } |
5728 | 5589 |
5729 // Fake a policy install. | 5590 // Fake a policy install. |
5730 bool AddPendingPolicyInstall() { | 5591 bool AddPendingPolicyInstall() { |
5731 // Get path to the CRX with id |kGoodId|. | 5592 // Get path to the CRX with id |kGoodId|. |
5732 return service()->OnExternalExtensionUpdateUrlFound( | 5593 scoped_ptr<GURL> empty_url(new GURL()); |
5733 crx_id_, | 5594 scoped_ptr<ExternalExtensionInstallInfoUpdateUrl> info( |
5734 std::string(), | 5595 new ExternalExtensionInstallInfoUpdateUrl( |
5735 GURL(), | 5596 crx_id_, std::string(), std::move(empty_url), |
5736 Manifest::EXTERNAL_POLICY_DOWNLOAD, | 5597 Manifest::EXTERNAL_POLICY_DOWNLOAD, Extension::NO_FLAGS, false)); |
5737 Extension::NO_FLAGS, | 5598 return service()->OnExternalExtensionUpdateUrlFound(info.get(), true); |
5738 false); | |
5739 } | 5599 } |
5740 | 5600 |
5741 // Get the install source of a pending extension. | 5601 // Get the install source of a pending extension. |
5742 Manifest::Location GetPendingLocation() { | 5602 Manifest::Location GetPendingLocation() { |
5743 const extensions::PendingExtensionInfo* info; | 5603 const extensions::PendingExtensionInfo* info; |
5744 EXPECT_TRUE( | 5604 EXPECT_TRUE( |
5745 (info = service()->pending_extension_manager()->GetById(crx_id_))); | 5605 (info = service()->pending_extension_manager()->GetById(crx_id_))); |
5746 return info->install_source(); | 5606 return info->install_source(); |
5747 } | 5607 } |
5748 | 5608 |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6262 | 6122 |
6263 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 6123 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
6264 content::Source<Profile>(profile()), | 6124 content::Source<Profile>(profile()), |
6265 content::NotificationService::NoDetails()); | 6125 content::NotificationService::NoDetails()); |
6266 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 6126 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
6267 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 6127 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
6268 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 6128 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
6269 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 6129 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
6270 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 6130 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
6271 } | 6131 } |
OLD | NEW |