Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
9 #include <algorithm> 10 #include <algorithm>
10 #include <map> 11 #include <map>
12 #include <memory>
11 #include <set> 13 #include <set>
12 #include <string> 14 #include <string>
13 #include <utility> 15 #include <utility>
14 #include <vector> 16 #include <vector>
15 17
16 #include "base/at_exit.h" 18 #include "base/at_exit.h"
17 #include "base/bind.h" 19 #include "base/bind.h"
18 #include "base/command_line.h" 20 #include "base/command_line.h"
19 #include "base/files/file_enumerator.h" 21 #include "base/files/file_enumerator.h"
20 #include "base/files/file_util.h" 22 #include "base/files/file_util.h"
21 #include "base/files/scoped_temp_dir.h" 23 #include "base/files/scoped_temp_dir.h"
22 #include "base/json/json_file_value_serializer.h" 24 #include "base/json/json_file_value_serializer.h"
23 #include "base/json/json_reader.h" 25 #include "base/json/json_reader.h"
24 #include "base/json/json_string_value_serializer.h" 26 #include "base/json/json_string_value_serializer.h"
25 #include "base/location.h" 27 #include "base/location.h"
26 #include "base/macros.h" 28 #include "base/macros.h"
27 #include "base/memory/scoped_ptr.h" 29 #include "base/memory/ptr_util.h"
28 #include "base/memory/weak_ptr.h" 30 #include "base/memory/weak_ptr.h"
29 #include "base/single_thread_task_runner.h" 31 #include "base/single_thread_task_runner.h"
30 #include "base/stl_util.h" 32 #include "base/stl_util.h"
31 #include "base/strings/pattern.h" 33 #include "base/strings/pattern.h"
32 #include "base/strings/string16.h" 34 #include "base/strings/string16.h"
33 #include "base/strings/string_number_conversions.h" 35 #include "base/strings/string_number_conversions.h"
34 #include "base/strings/string_util.h" 36 #include "base/strings/string_util.h"
35 #include "base/strings/utf_string_conversions.h" 37 #include "base/strings/utf_string_conversions.h"
36 #include "base/thread_task_runner_handle.h" 38 #include "base/thread_task_runner_handle.h"
37 #include "base/version.h" 39 #include "base/version.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 277
276 void RemoveExtension(const std::string& id) { 278 void RemoveExtension(const std::string& id) {
277 extension_map_.erase(id); 279 extension_map_.erase(id);
278 } 280 }
279 281
280 // ExternalProvider implementation: 282 // ExternalProvider implementation:
281 void VisitRegisteredExtension() override { 283 void VisitRegisteredExtension() override {
282 visit_count_++; 284 visit_count_++;
283 for (DataMap::const_iterator i = extension_map_.begin(); 285 for (DataMap::const_iterator i = extension_map_.begin();
284 i != extension_map_.end(); ++i) { 286 i != extension_map_.end(); ++i) {
285 scoped_ptr<Version> version(new Version(i->second.first)); 287 std::unique_ptr<Version> version(new Version(i->second.first));
286 288
287 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 289 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
288 i->first, std::move(version), i->second.second, location_, 290 i->first, std::move(version), i->second.second, location_,
289 Extension::NO_FLAGS, false, false)); 291 Extension::NO_FLAGS, false, false));
290 visitor_->OnExternalExtensionFileFound(*info); 292 visitor_->OnExternalExtensionFileFound(*info);
291 } 293 }
292 visitor_->OnExternalProviderReady(this); 294 visitor_->OnExternalProviderReady(this);
293 } 295 }
294 296
295 bool HasExtension(const std::string& id) const override { 297 bool HasExtension(const std::string& id) const override {
296 return extension_map_.find(id) != extension_map_.end(); 298 return extension_map_.find(id) != extension_map_.end();
297 } 299 }
298 300
299 bool GetExtensionDetails(const std::string& id, 301 bool GetExtensionDetails(const std::string& id,
300 Manifest::Location* location, 302 Manifest::Location* location,
301 scoped_ptr<Version>* version) const override { 303 std::unique_ptr<Version>* version) const override {
302 DataMap::const_iterator it = extension_map_.find(id); 304 DataMap::const_iterator it = extension_map_.find(id);
303 if (it == extension_map_.end()) 305 if (it == extension_map_.end())
304 return false; 306 return false;
305 307
306 if (version) 308 if (version)
307 version->reset(new Version(it->second.first)); 309 version->reset(new Version(it->second.first));
308 310
309 if (location) 311 if (location)
310 *location = location_; 312 *location = location_;
311 313
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 401
400 EXPECT_TRUE(info.path.IsAbsolute()); 402 EXPECT_TRUE(info.path.IsAbsolute());
401 if (!fake_base_path_.empty()) 403 if (!fake_base_path_.empty())
402 EXPECT_TRUE(fake_base_path_.IsParent(info.path)); 404 EXPECT_TRUE(fake_base_path_.IsParent(info.path));
403 405
404 if (pref) { 406 if (pref) {
405 EXPECT_TRUE(provider_->HasExtension(info.extension_id)); 407 EXPECT_TRUE(provider_->HasExtension(info.extension_id));
406 408
407 // Ask provider if the extension we got back is registered. 409 // Ask provider if the extension we got back is registered.
408 Manifest::Location location = Manifest::INVALID_LOCATION; 410 Manifest::Location location = Manifest::INVALID_LOCATION;
409 scoped_ptr<Version> v1; 411 std::unique_ptr<Version> v1;
410 base::FilePath crx_path; 412 base::FilePath crx_path;
411 413
412 EXPECT_TRUE(provider_->GetExtensionDetails(info.extension_id, NULL, &v1)); 414 EXPECT_TRUE(provider_->GetExtensionDetails(info.extension_id, NULL, &v1));
413 EXPECT_STREQ(info.version->GetString().c_str(), v1->GetString().c_str()); 415 EXPECT_STREQ(info.version->GetString().c_str(), v1->GetString().c_str());
414 416
415 scoped_ptr<Version> v2; 417 std::unique_ptr<Version> v2;
416 EXPECT_TRUE( 418 EXPECT_TRUE(
417 provider_->GetExtensionDetails(info.extension_id, &location, &v2)); 419 provider_->GetExtensionDetails(info.extension_id, &location, &v2));
418 EXPECT_STREQ(info.version->GetString().c_str(), v1->GetString().c_str()); 420 EXPECT_STREQ(info.version->GetString().c_str(), v1->GetString().c_str());
419 EXPECT_STREQ(info.version->GetString().c_str(), v2->GetString().c_str()); 421 EXPECT_STREQ(info.version->GetString().c_str(), v2->GetString().c_str());
420 EXPECT_EQ(crx_location_, location); 422 EXPECT_EQ(crx_location_, location);
421 423
422 // Remove it so we won't count it ever again. 424 // Remove it so we won't count it ever again.
423 prefs_->Remove(info.extension_id, NULL); 425 prefs_->Remove(info.extension_id, NULL);
424 } 426 }
425 return true; 427 return true;
426 } 428 }
427 429
428 bool OnExternalExtensionUpdateUrlFound( 430 bool OnExternalExtensionUpdateUrlFound(
429 const ExternalInstallInfoUpdateUrl& info, 431 const ExternalInstallInfoUpdateUrl& info,
430 bool is_initial_load) override { 432 bool is_initial_load) override {
431 ++ids_found_; 433 ++ids_found_;
432 base::DictionaryValue* pref; 434 base::DictionaryValue* pref;
433 // This tests is to make sure that the provider only notifies us of the 435 // This tests is to make sure that the provider only notifies us of the
434 // values we gave it. So if the id we doesn't exist in our internal 436 // values we gave it. So if the id we doesn't exist in our internal
435 // dictionary then something is wrong. 437 // dictionary then something is wrong.
436 EXPECT_TRUE(prefs_->GetDictionary(info.extension_id, &pref)) 438 EXPECT_TRUE(prefs_->GetDictionary(info.extension_id, &pref))
437 << L"Got back ID (" << info.extension_id.c_str() 439 << L"Got back ID (" << info.extension_id.c_str()
438 << ") we weren't expecting"; 440 << ") we weren't expecting";
439 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, info.download_location); 441 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, info.download_location);
440 442
441 if (pref) { 443 if (pref) {
442 EXPECT_TRUE(provider_->HasExtension(info.extension_id)); 444 EXPECT_TRUE(provider_->HasExtension(info.extension_id));
443 445
444 // External extensions with update URLs do not have versions. 446 // External extensions with update URLs do not have versions.
445 scoped_ptr<Version> v1; 447 std::unique_ptr<Version> v1;
446 Manifest::Location location1 = Manifest::INVALID_LOCATION; 448 Manifest::Location location1 = Manifest::INVALID_LOCATION;
447 EXPECT_TRUE( 449 EXPECT_TRUE(
448 provider_->GetExtensionDetails(info.extension_id, &location1, &v1)); 450 provider_->GetExtensionDetails(info.extension_id, &location1, &v1));
449 EXPECT_FALSE(v1.get()); 451 EXPECT_FALSE(v1.get());
450 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1); 452 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, location1);
451 453
452 std::string parsed_install_parameter; 454 std::string parsed_install_parameter;
453 pref->GetString("install_parameter", &parsed_install_parameter); 455 pref->GetString("install_parameter", &parsed_install_parameter);
454 EXPECT_EQ(parsed_install_parameter, info.install_parameter); 456 EXPECT_EQ(parsed_install_parameter, info.install_parameter);
455 457
(...skipping 14 matching lines...) Expand all
470 472
471 void OnExternalProviderReady( 473 void OnExternalProviderReady(
472 const extensions::ExternalProviderInterface* provider) override { 474 const extensions::ExternalProviderInterface* provider) override {
473 EXPECT_EQ(provider, provider_.get()); 475 EXPECT_EQ(provider, provider_.get());
474 EXPECT_TRUE(provider->IsReady()); 476 EXPECT_TRUE(provider->IsReady());
475 } 477 }
476 478
477 Profile* profile() { return profile_.get(); } 479 Profile* profile() { return profile_.get(); }
478 480
479 protected: 481 protected:
480 scoped_ptr<extensions::ExternalProviderImpl> provider_; 482 std::unique_ptr<extensions::ExternalProviderImpl> provider_;
481 483
482 scoped_ptr<base::DictionaryValue> GetDictionaryFromJSON( 484 std::unique_ptr<base::DictionaryValue> GetDictionaryFromJSON(
483 const std::string& json_data) { 485 const std::string& json_data) {
484 // We also parse the file into a dictionary to compare what we get back 486 // We also parse the file into a dictionary to compare what we get back
485 // from the provider. 487 // from the provider.
486 JSONStringValueDeserializer deserializer(json_data); 488 JSONStringValueDeserializer deserializer(json_data);
487 scoped_ptr<base::Value> json_value = deserializer.Deserialize(NULL, NULL); 489 std::unique_ptr<base::Value> json_value =
490 deserializer.Deserialize(NULL, NULL);
488 491
489 if (!json_value || !json_value->IsType(base::Value::TYPE_DICTIONARY)) { 492 if (!json_value || !json_value->IsType(base::Value::TYPE_DICTIONARY)) {
490 ADD_FAILURE() << "Unable to deserialize json data"; 493 ADD_FAILURE() << "Unable to deserialize json data";
491 return scoped_ptr<base::DictionaryValue>(); 494 return std::unique_ptr<base::DictionaryValue>();
492 } else { 495 } else {
493 return base::DictionaryValue::From(std::move(json_value)); 496 return base::DictionaryValue::From(std::move(json_value));
494 } 497 }
495 } 498 }
496 499
497 private: 500 private:
498 int ids_found_; 501 int ids_found_;
499 base::FilePath fake_base_path_; 502 base::FilePath fake_base_path_;
500 int expected_creation_flags_; 503 int expected_creation_flags_;
501 Manifest::Location crx_location_; 504 Manifest::Location crx_location_;
502 scoped_ptr<base::DictionaryValue> prefs_; 505 std::unique_ptr<base::DictionaryValue> prefs_;
503 scoped_ptr<TestingProfile> profile_; 506 std::unique_ptr<TestingProfile> profile_;
504 507
505 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 508 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
506 }; 509 };
507 510
508 // Mock provider that can simulate incremental update like 511 // Mock provider that can simulate incremental update like
509 // ExternalRegistryLoader. 512 // ExternalRegistryLoader.
510 class MockUpdateProviderVisitor : public MockProviderVisitor { 513 class MockUpdateProviderVisitor : public MockProviderVisitor {
511 public: 514 public:
512 // The provider will return |fake_base_path| from 515 // The provider will return |fake_base_path| from
513 // GetBaseCrxFilePath(). User can test the behavior with 516 // GetBaseCrxFilePath(). User can test the behavior with
514 // and without an empty path using this parameter. 517 // and without an empty path using this parameter.
515 explicit MockUpdateProviderVisitor(base::FilePath fake_base_path) 518 explicit MockUpdateProviderVisitor(base::FilePath fake_base_path)
516 : MockProviderVisitor(fake_base_path) {} 519 : MockProviderVisitor(fake_base_path) {}
517 520
518 void VisitDueToUpdate(const std::string& json_data) { 521 void VisitDueToUpdate(const std::string& json_data) {
519 update_url_extension_ids_.clear(); 522 update_url_extension_ids_.clear();
520 file_extension_ids_.clear(); 523 file_extension_ids_.clear();
521 removed_extension_ids_.clear(); 524 removed_extension_ids_.clear();
522 525
523 scoped_ptr<base::DictionaryValue> new_prefs = 526 std::unique_ptr<base::DictionaryValue> new_prefs =
524 GetDictionaryFromJSON(json_data); 527 GetDictionaryFromJSON(json_data);
525 if (!new_prefs) 528 if (!new_prefs)
526 return; 529 return;
527 provider_->UpdatePrefs(new_prefs.release()); 530 provider_->UpdatePrefs(new_prefs.release());
528 } 531 }
529 532
530 void OnExternalProviderUpdateComplete( 533 void OnExternalProviderUpdateComplete(
531 const ExternalProviderInterface* provider, 534 const ExternalProviderInterface* provider,
532 const ScopedVector<ExternalInstallInfoUpdateUrl>& update_url_extensions, 535 const ScopedVector<ExternalInstallInfoUpdateUrl>& update_url_extensions,
533 const ScopedVector<ExternalInstallInfoFile>& file_extensions, 536 const ScopedVector<ExternalInstallInfoFile>& file_extensions,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 // set for extension |id|. 629 // set for extension |id|.
627 void GrantAllOptionalPermissions(const std::string& id) { 630 void GrantAllOptionalPermissions(const std::string& id) {
628 const Extension* extension = service()->GetInstalledExtension(id); 631 const Extension* extension = service()->GetInstalledExtension(id);
629 const PermissionSet& all_optional_permissions = 632 const PermissionSet& all_optional_permissions =
630 extensions::PermissionsParser::GetOptionalPermissions(extension); 633 extensions::PermissionsParser::GetOptionalPermissions(extension);
631 extensions::PermissionsUpdater perms_updater(profile()); 634 extensions::PermissionsUpdater perms_updater(profile());
632 perms_updater.AddPermissions(extension, all_optional_permissions); 635 perms_updater.AddPermissions(extension, all_optional_permissions);
633 } 636 }
634 637
635 testing::AssertionResult IsBlocked(const std::string& id) { 638 testing::AssertionResult IsBlocked(const std::string& id) {
636 scoped_ptr<extensions::ExtensionSet> all_unblocked_extensions = 639 std::unique_ptr<extensions::ExtensionSet> all_unblocked_extensions =
637 registry()->GenerateInstalledExtensionsSet( 640 registry()->GenerateInstalledExtensionsSet(
638 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::BLOCKED); 641 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::BLOCKED);
639 if (all_unblocked_extensions.get()->Contains(id)) 642 if (all_unblocked_extensions.get()->Contains(id))
640 return testing::AssertionFailure() << id << " is still unblocked!"; 643 return testing::AssertionFailure() << id << " is still unblocked!";
641 if (!registry()->blocked_extensions().Contains(id)) 644 if (!registry()->blocked_extensions().Contains(id))
642 return testing::AssertionFailure() << id << " is not blocked!"; 645 return testing::AssertionFailure() << id << " is not blocked!";
643 return testing::AssertionSuccess(); 646 return testing::AssertionSuccess();
644 } 647 }
645 648
646 // Helper method to test that an extension moves through being blocked and 649 // Helper method to test that an extension moves through being blocked and
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 // extension object. 1142 // extension object.
1140 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { 1143 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) {
1141 const char kPrefFromBookmark[] = "from_bookmark"; 1144 const char kPrefFromBookmark[] = "from_bookmark";
1142 1145
1143 InitializeEmptyExtensionService(); 1146 InitializeEmptyExtensionService();
1144 1147
1145 base::FilePath path = data_dir().AppendASCII("good.crx"); 1148 base::FilePath path = data_dir().AppendASCII("good.crx");
1146 service()->set_extensions_enabled(true); 1149 service()->set_extensions_enabled(true);
1147 1150
1148 // Register and install an external extension. 1151 // Register and install an external extension.
1149 scoped_ptr<Version> version(new Version("1.0.0.0")); 1152 std::unique_ptr<Version> version(new Version("1.0.0.0"));
1150 content::WindowedNotificationObserver observer( 1153 content::WindowedNotificationObserver observer(
1151 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1154 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1152 content::NotificationService::AllSources()); 1155 content::NotificationService::AllSources());
1153 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 1156 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
1154 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF, 1157 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF,
1155 Extension::FROM_BOOKMARK, false /* mark_acknowledged */, 1158 Extension::FROM_BOOKMARK, false /* mark_acknowledged */,
1156 false /* install_immediately */)); 1159 false /* install_immediately */));
1157 if (service()->OnExternalExtensionFileFound(*info)) 1160 if (service()->OnExternalExtensionFileFound(*info))
1158 observer.Wait(); 1161 observer.Wait();
1159 1162
1160 const Extension* extension = service()->GetExtensionById(good_crx, false); 1163 const Extension* extension = service()->GetExtensionById(good_crx, false);
1161 ASSERT_TRUE(extension); 1164 ASSERT_TRUE(extension);
1162 ASSERT_TRUE(extension->from_bookmark()); 1165 ASSERT_TRUE(extension->from_bookmark());
1163 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true)); 1166 ASSERT_TRUE(ValidateBooleanPref(good_crx, kPrefFromBookmark, true));
(...skipping 11 matching lines...) Expand all
1175 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { 1178 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) {
1176 InitializeEmptyExtensionService(); 1179 InitializeEmptyExtensionService();
1177 1180
1178 base::FilePath path = data_dir().AppendASCII("good.crx"); 1181 base::FilePath path = data_dir().AppendASCII("good.crx");
1179 service()->set_extensions_enabled(true); 1182 service()->set_extensions_enabled(true);
1180 1183
1181 // Install an external extension. 1184 // Install an external extension.
1182 content::WindowedNotificationObserver observer( 1185 content::WindowedNotificationObserver observer(
1183 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1186 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1184 content::NotificationService::AllSources()); 1187 content::NotificationService::AllSources());
1185 scoped_ptr<Version> version(new Version("1.0.0.0")); 1188 std::unique_ptr<Version> version(new Version("1.0.0.0"));
1186 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 1189 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
1187 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF, 1190 good_crx, std::move(version), path, Manifest::EXTERNAL_PREF,
1188 Extension::NO_FLAGS, false, false)); 1191 Extension::NO_FLAGS, false, false));
1189 if (service()->OnExternalExtensionFileFound(*info)) 1192 if (service()->OnExternalExtensionFileFound(*info))
1190 observer.Wait(); 1193 observer.Wait();
1191 1194
1192 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); 1195 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1193 1196
1194 // Uninstall it and check that its killbit gets set. 1197 // Uninstall it and check that its killbit gets set.
1195 UninstallExtension(good_crx, false); 1198 UninstallExtension(good_crx, false);
1196 ValidateIntegerPref(good_crx, "state", 1199 ValidateIntegerPref(good_crx, "state",
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY); 1256 MockExtensionProvider provider(NULL, Manifest::EXTERNAL_REGISTRY);
1254 service()->OnExternalProviderReady(&provider); 1257 service()->OnExternalProviderReady(&provider);
1255 } 1258 }
1256 1259
1257 // Test that external extensions with incorrect IDs are not installed. 1260 // Test that external extensions with incorrect IDs are not installed.
1258 TEST_F(ExtensionServiceTest, FailOnWrongId) { 1261 TEST_F(ExtensionServiceTest, FailOnWrongId) {
1259 InitializeEmptyExtensionService(); 1262 InitializeEmptyExtensionService();
1260 base::FilePath path = data_dir().AppendASCII("good.crx"); 1263 base::FilePath path = data_dir().AppendASCII("good.crx");
1261 service()->set_extensions_enabled(true); 1264 service()->set_extensions_enabled(true);
1262 1265
1263 scoped_ptr<Version> version(new Version("1.0.0.0")); 1266 std::unique_ptr<Version> version(new Version("1.0.0.0"));
1264 1267
1265 const std::string wrong_id = all_zero; 1268 const std::string wrong_id = all_zero;
1266 const std::string correct_id = good_crx; 1269 const std::string correct_id = good_crx;
1267 ASSERT_NE(correct_id, wrong_id); 1270 ASSERT_NE(correct_id, wrong_id);
1268 1271
1269 // Install an external extension with an ID from the external 1272 // Install an external extension with an ID from the external
1270 // source that is not equal to the ID in the extension manifest. 1273 // source that is not equal to the ID in the extension manifest.
1271 content::WindowedNotificationObserver observer( 1274 content::WindowedNotificationObserver observer(
1272 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1275 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1273 content::NotificationService::AllSources()); 1276 content::NotificationService::AllSources());
1274 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 1277 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
1275 wrong_id, std::move(version), path, Manifest::EXTERNAL_PREF, 1278 wrong_id, std::move(version), path, Manifest::EXTERNAL_PREF,
1276 Extension::NO_FLAGS, false, false)); 1279 Extension::NO_FLAGS, false, false));
1277 service()->OnExternalExtensionFileFound(*info); 1280 service()->OnExternalExtensionFileFound(*info);
1278 1281
1279 observer.Wait(); 1282 observer.Wait();
1280 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); 1283 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
1281 1284
1282 // Try again with the right ID. Expect success. 1285 // Try again with the right ID. Expect success.
1283 content::WindowedNotificationObserver observer2( 1286 content::WindowedNotificationObserver observer2(
1284 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1287 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1285 content::NotificationService::AllSources()); 1288 content::NotificationService::AllSources());
1286 info->extension_id = correct_id; 1289 info->extension_id = correct_id;
1287 if (service()->OnExternalExtensionFileFound(*info)) 1290 if (service()->OnExternalExtensionFileFound(*info))
1288 observer2.Wait(); 1291 observer2.Wait();
1289 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); 1292 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1290 } 1293 }
1291 1294
1292 // Test that external extensions with incorrect versions are not installed. 1295 // Test that external extensions with incorrect versions are not installed.
1293 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { 1296 TEST_F(ExtensionServiceTest, FailOnWrongVersion) {
1294 InitializeEmptyExtensionService(); 1297 InitializeEmptyExtensionService();
1295 base::FilePath path = data_dir().AppendASCII("good.crx"); 1298 base::FilePath path = data_dir().AppendASCII("good.crx");
1296 service()->set_extensions_enabled(true); 1299 service()->set_extensions_enabled(true);
1297 1300
1298 // Install an external extension with a version from the external 1301 // Install an external extension with a version from the external
1299 // source that is not equal to the version in the extension manifest. 1302 // source that is not equal to the version in the extension manifest.
1300 content::WindowedNotificationObserver observer( 1303 content::WindowedNotificationObserver observer(
1301 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1304 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1302 content::NotificationService::AllSources()); 1305 content::NotificationService::AllSources());
1303 scoped_ptr<Version> wrong_version(new Version("1.2.3.4")); 1306 std::unique_ptr<Version> wrong_version(new Version("1.2.3.4"));
1304 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 1307 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
1305 good_crx, std::move(wrong_version), path, Manifest::EXTERNAL_PREF, 1308 good_crx, std::move(wrong_version), path, Manifest::EXTERNAL_PREF,
1306 Extension::NO_FLAGS, false, false)); 1309 Extension::NO_FLAGS, false, false));
1307 service()->OnExternalExtensionFileFound(*info); 1310 service()->OnExternalExtensionFileFound(*info);
1308 1311
1309 observer.Wait(); 1312 observer.Wait();
1310 ASSERT_FALSE(service()->GetExtensionById(good_crx, false)); 1313 ASSERT_FALSE(service()->GetExtensionById(good_crx, false));
1311 1314
1312 // Try again with the right version. Expect success. 1315 // Try again with the right version. Expect success.
1313 service()->pending_extension_manager()->Remove(good_crx); 1316 service()->pending_extension_manager()->Remove(good_crx);
1314 scoped_ptr<Version> correct_version(new Version("1.0.0.0")); 1317 std::unique_ptr<Version> correct_version(new Version("1.0.0.0"));
1315 info->version = std::move(correct_version); 1318 info->version = std::move(correct_version);
1316 content::WindowedNotificationObserver observer2( 1319 content::WindowedNotificationObserver observer2(
1317 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 1320 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
1318 content::NotificationService::AllSources()); 1321 content::NotificationService::AllSources());
1319 if (service()->OnExternalExtensionFileFound(*info)) 1322 if (service()->OnExternalExtensionFileFound(*info))
1320 observer2.Wait(); 1323 observer2.Wait();
1321 ASSERT_TRUE(service()->GetExtensionById(good_crx, false)); 1324 ASSERT_TRUE(service()->GetExtensionById(good_crx, false));
1322 } 1325 }
1323 1326
1324 // Install a user script (they get converted automatically to an extension) 1327 // Install a user script (they get converted automatically to an extension)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 EXPECT_EQ(permissions_crx, extension->id()); 1401 EXPECT_EQ(permissions_crx, extension->id());
1399 1402
1400 // Verify that the valid API permissions have been recognized. 1403 // Verify that the valid API permissions have been recognized.
1401 expected_api_perms.insert(APIPermission::kTab); 1404 expected_api_perms.insert(APIPermission::kTab);
1402 1405
1403 AddPattern(&expected_host_perms, "http://*.google.com/*"); 1406 AddPattern(&expected_host_perms, "http://*.google.com/*");
1404 AddPattern(&expected_host_perms, "https://*.google.com/*"); 1407 AddPattern(&expected_host_perms, "https://*.google.com/*");
1405 AddPattern(&expected_host_perms, "http://*.google.com.hk/*"); 1408 AddPattern(&expected_host_perms, "http://*.google.com.hk/*");
1406 AddPattern(&expected_host_perms, "http://www.example.com/*"); 1409 AddPattern(&expected_host_perms, "http://www.example.com/*");
1407 1410
1408 scoped_ptr<const PermissionSet> known_perms = 1411 std::unique_ptr<const PermissionSet> known_perms =
1409 prefs->GetGrantedPermissions(extension->id()); 1412 prefs->GetGrantedPermissions(extension->id());
1410 EXPECT_TRUE(known_perms.get()); 1413 EXPECT_TRUE(known_perms.get());
1411 EXPECT_FALSE(known_perms->IsEmpty()); 1414 EXPECT_FALSE(known_perms->IsEmpty());
1412 EXPECT_EQ(expected_api_perms, known_perms->apis()); 1415 EXPECT_EQ(expected_api_perms, known_perms->apis());
1413 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); 1416 EXPECT_FALSE(known_perms->HasEffectiveFullAccess());
1414 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); 1417 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts());
1415 } 1418 }
1416 1419
1417 1420
1418 #if !defined(OS_CHROMEOS) 1421 #if !defined(OS_CHROMEOS)
(...skipping 21 matching lines...) Expand all
1440 const Extension* extension = PackAndInstallCRX( 1443 const Extension* extension = PackAndInstallCRX(
1441 path, pem_path, INSTALL_NEW, Extension::WAS_INSTALLED_BY_DEFAULT); 1444 path, pem_path, INSTALL_NEW, Extension::WAS_INSTALLED_BY_DEFAULT);
1442 1445
1443 EXPECT_EQ(0u, GetErrors().size()); 1446 EXPECT_EQ(0u, GetErrors().size());
1444 ASSERT_EQ(1u, registry()->enabled_extensions().size()); 1447 ASSERT_EQ(1u, registry()->enabled_extensions().size());
1445 EXPECT_EQ(permissions_crx, extension->id()); 1448 EXPECT_EQ(permissions_crx, extension->id());
1446 1449
1447 // Verify that the valid API permissions have been recognized. 1450 // Verify that the valid API permissions have been recognized.
1448 expected_api_perms.insert(APIPermission::kTab); 1451 expected_api_perms.insert(APIPermission::kTab);
1449 1452
1450 scoped_ptr<const PermissionSet> known_perms = 1453 std::unique_ptr<const PermissionSet> known_perms =
1451 prefs->GetGrantedPermissions(extension->id()); 1454 prefs->GetGrantedPermissions(extension->id());
1452 EXPECT_TRUE(known_perms.get()); 1455 EXPECT_TRUE(known_perms.get());
1453 EXPECT_FALSE(known_perms->IsEmpty()); 1456 EXPECT_FALSE(known_perms->IsEmpty());
1454 EXPECT_EQ(expected_api_perms, known_perms->apis()); 1457 EXPECT_EQ(expected_api_perms, known_perms->apis());
1455 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); 1458 EXPECT_FALSE(known_perms->HasEffectiveFullAccess());
1456 } 1459 }
1457 #endif 1460 #endif
1458 1461
1459 #if !defined(OS_POSIX) || defined(OS_MACOSX) 1462 #if !defined(OS_POSIX) || defined(OS_MACOSX)
1460 // Tests that the granted permissions full_access bit gets set correctly when 1463 // Tests that the granted permissions full_access bit gets set correctly when
1461 // an extension contains an NPAPI plugin. 1464 // an extension contains an NPAPI plugin.
1462 // Only run this on platforms that support NPAPI plugins. 1465 // Only run this on platforms that support NPAPI plugins.
1463 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { 1466 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) {
1464 InitPluginService(); 1467 InitPluginService();
1465 1468
1466 InitializeEmptyExtensionService(); 1469 InitializeEmptyExtensionService();
1467 1470
1468 ASSERT_TRUE(base::PathExists(good1_path())); 1471 ASSERT_TRUE(base::PathExists(good1_path()));
1469 const Extension* extension = PackAndInstallCRX(good1_path(), INSTALL_NEW); 1472 const Extension* extension = PackAndInstallCRX(good1_path(), INSTALL_NEW);
1470 EXPECT_EQ(0u, GetErrors().size()); 1473 EXPECT_EQ(0u, GetErrors().size());
1471 EXPECT_EQ(1u, registry()->enabled_extensions().size()); 1474 EXPECT_EQ(1u, registry()->enabled_extensions().size());
1472 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); 1475 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
1473 1476
1474 scoped_ptr<const PermissionSet> permissions = 1477 std::unique_ptr<const PermissionSet> permissions =
1475 prefs->GetGrantedPermissions(extension->id()); 1478 prefs->GetGrantedPermissions(extension->id());
1476 EXPECT_FALSE(permissions->IsEmpty()); 1479 EXPECT_FALSE(permissions->IsEmpty());
1477 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); 1480 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
1478 EXPECT_FALSE(permissions->apis().empty()); 1481 EXPECT_FALSE(permissions->apis().empty());
1479 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); 1482 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin));
1480 1483
1481 // Full access implies full host access too... 1484 // Full access implies full host access too...
1482 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); 1485 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts());
1483 } 1486 }
1484 #endif 1487 #endif
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id)); 1530 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id));
1528 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); 1531 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
1529 1532
1530 // Now grant and re-enable the extension, making sure the prefs are updated. 1533 // Now grant and re-enable the extension, making sure the prefs are updated.
1531 service()->GrantPermissionsAndEnableExtension(extension); 1534 service()->GrantPermissionsAndEnableExtension(extension);
1532 1535
1533 ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id)); 1536 ASSERT_FALSE(prefs->IsExtensionDisabled(extension_id));
1534 ASSERT_TRUE(service()->IsExtensionEnabled(extension_id)); 1537 ASSERT_TRUE(service()->IsExtensionEnabled(extension_id));
1535 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id)); 1538 ASSERT_FALSE(prefs->DidExtensionEscalatePermissions(extension_id));
1536 1539
1537 scoped_ptr<const PermissionSet> current_perms = 1540 std::unique_ptr<const PermissionSet> current_perms =
1538 prefs->GetGrantedPermissions(extension_id); 1541 prefs->GetGrantedPermissions(extension_id);
1539 ASSERT_TRUE(current_perms.get()); 1542 ASSERT_TRUE(current_perms.get());
1540 ASSERT_FALSE(current_perms->IsEmpty()); 1543 ASSERT_FALSE(current_perms->IsEmpty());
1541 ASSERT_FALSE(current_perms->HasEffectiveFullAccess()); 1544 ASSERT_FALSE(current_perms->HasEffectiveFullAccess());
1542 ASSERT_EQ(expected_api_permissions, current_perms->apis()); 1545 ASSERT_EQ(expected_api_permissions, current_perms->apis());
1543 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts()); 1546 ASSERT_EQ(expected_host_permissions, current_perms->effective_hosts());
1544 1547
1545 // Tests that the extension is disabled when a host permission is missing from 1548 // Tests that the extension is disabled when a host permission is missing from
1546 // the extension's granted host permissions preference. (This simulates 1549 // the extension's granted host permissions preference. (This simulates
1547 // updating the browser to a version which recognizes additional host 1550 // updating the browser to a version which recognizes additional host
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 1597 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
1595 .AppendASCII("1.0.0.0"); 1598 .AppendASCII("1.0.0.0");
1596 1599
1597 base::ScopedTempDir temp_dir; 1600 base::ScopedTempDir temp_dir;
1598 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1601 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1599 base::FilePath output_directory = temp_dir.path(); 1602 base::FilePath output_directory = temp_dir.path();
1600 1603
1601 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); 1604 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
1602 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); 1605 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem"));
1603 1606
1604 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 1607 std::unique_ptr<ExtensionCreator> creator(new ExtensionCreator());
1605 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), 1608 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(),
1606 privkey_path, ExtensionCreator::kNoRunFlags)); 1609 privkey_path, ExtensionCreator::kNoRunFlags));
1607 ASSERT_TRUE(base::PathExists(crx_path)); 1610 ASSERT_TRUE(base::PathExists(crx_path));
1608 ASSERT_TRUE(base::PathExists(privkey_path)); 1611 ASSERT_TRUE(base::PathExists(privkey_path));
1609 1612
1610 // Repeat the run with the pem file gone, and no special flags 1613 // Repeat the run with the pem file gone, and no special flags
1611 // Should refuse to overwrite the existing crx. 1614 // Should refuse to overwrite the existing crx.
1612 base::DeleteFile(privkey_path, false); 1615 base::DeleteFile(privkey_path, false);
1613 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), 1616 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(),
1614 privkey_path, ExtensionCreator::kNoRunFlags)); 1617 privkey_path, ExtensionCreator::kNoRunFlags));
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 /*recursive=*/true)); 1744 /*recursive=*/true));
1742 1745
1743 base::ScopedTempDir output_temp_dir; 1746 base::ScopedTempDir output_temp_dir;
1744 ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir()); 1747 ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir());
1745 base::FilePath output_directory = output_temp_dir.path(); 1748 base::FilePath output_directory = output_temp_dir.path();
1746 1749
1747 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); 1750 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
1748 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); 1751 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem"));
1749 1752
1750 // Pack the extension once to get a private key. 1753 // Pack the extension once to get a private key.
1751 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 1754 std::unique_ptr<ExtensionCreator> creator(new ExtensionCreator());
1752 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), 1755 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(),
1753 privkey_path, ExtensionCreator::kNoRunFlags)) 1756 privkey_path, ExtensionCreator::kNoRunFlags))
1754 << creator->error_message(); 1757 << creator->error_message();
1755 ASSERT_TRUE(base::PathExists(crx_path)); 1758 ASSERT_TRUE(base::PathExists(crx_path));
1756 ASSERT_TRUE(base::PathExists(privkey_path)); 1759 ASSERT_TRUE(base::PathExists(privkey_path));
1757 1760
1758 base::DeleteFile(crx_path, false); 1761 base::DeleteFile(crx_path, false);
1759 // Move the pem file into the extension. 1762 // Move the pem file into the extension.
1760 base::Move(privkey_path, 1763 base::Move(privkey_path,
1761 input_directory.AppendASCII("privkey.pem")); 1764 input_directory.AppendASCII("privkey.pem"));
(...skipping 23 matching lines...) Expand all
1785 base::FilePath privkey_path( 1788 base::FilePath privkey_path(
1786 data_dir().AppendASCII("openssl_privkey_asn1.pem")); 1789 data_dir().AppendASCII("openssl_privkey_asn1.pem"));
1787 ASSERT_TRUE(base::PathExists(privkey_path)); 1790 ASSERT_TRUE(base::PathExists(privkey_path));
1788 1791
1789 base::ScopedTempDir temp_dir; 1792 base::ScopedTempDir temp_dir;
1790 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1793 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1791 base::FilePath output_directory = temp_dir.path(); 1794 base::FilePath output_directory = temp_dir.path();
1792 1795
1793 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx")); 1796 base::FilePath crx_path(output_directory.AppendASCII("ex1.crx"));
1794 1797
1795 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); 1798 std::unique_ptr<ExtensionCreator> creator(new ExtensionCreator());
1796 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, 1799 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path,
1797 base::FilePath(), ExtensionCreator::kOverwriteCRX)); 1800 base::FilePath(), ExtensionCreator::kOverwriteCRX));
1798 1801
1799 InstallCRX(crx_path, INSTALL_NEW); 1802 InstallCRX(crx_path, INSTALL_NEW);
1800 } 1803 }
1801 1804
1802 #if defined(THREAD_SANITIZER) 1805 #if defined(THREAD_SANITIZER)
1803 // Flaky under Tsan. http://crbug.com/377702 1806 // Flaky under Tsan. http://crbug.com/377702
1804 #define MAYBE_InstallTheme DISABLED_InstallTheme 1807 #define MAYBE_InstallTheme DISABLED_InstallTheme
1805 #else 1808 #else
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 // Only run this on platforms that support NPAPI plugins. 2387 // Only run this on platforms that support NPAPI plugins.
2385 TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) { 2388 TEST_F(ExtensionServiceTest, LoadExtensionsWithPlugins) {
2386 base::FilePath extension_with_plugin_path = good1_path(); 2389 base::FilePath extension_with_plugin_path = good1_path();
2387 base::FilePath extension_no_plugin_path = good2_path(); 2390 base::FilePath extension_no_plugin_path = good2_path();
2388 2391
2389 InitPluginService(); 2392 InitPluginService();
2390 InitializeEmptyExtensionService(); 2393 InitializeEmptyExtensionService();
2391 service()->set_show_extensions_prompts(true); 2394 service()->set_show_extensions_prompts(true);
2392 2395
2393 // Start by canceling any install prompts. 2396 // Start by canceling any install prompts.
2394 scoped_ptr<extensions::ScopedTestDialogAutoConfirm> auto_confirm( 2397 std::unique_ptr<extensions::ScopedTestDialogAutoConfirm> auto_confirm(
2395 new extensions::ScopedTestDialogAutoConfirm( 2398 new extensions::ScopedTestDialogAutoConfirm(
2396 extensions::ScopedTestDialogAutoConfirm::CANCEL)); 2399 extensions::ScopedTestDialogAutoConfirm::CANCEL));
2397 2400
2398 // The extension that has a plugin should not install. 2401 // The extension that has a plugin should not install.
2399 extensions::UnpackedInstaller::Create(service()) 2402 extensions::UnpackedInstaller::Create(service())
2400 ->Load(extension_with_plugin_path); 2403 ->Load(extension_with_plugin_path);
2401 base::RunLoop().RunUntilIdle(); 2404 base::RunLoop().RunUntilIdle();
2402 EXPECT_EQ(0u, GetErrors().size()); 2405 EXPECT_EQ(0u, GetErrors().size());
2403 EXPECT_EQ(0u, loaded_.size()); 2406 EXPECT_EQ(0u, loaded_.size());
2404 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 2407 EXPECT_EQ(0u, registry()->enabled_extensions().size());
(...skipping 20 matching lines...) Expand all
2425 ->Load(extension_with_plugin_path); 2428 ->Load(extension_with_plugin_path);
2426 content::RunAllBlockingPoolTasksUntilIdle(); 2429 content::RunAllBlockingPoolTasksUntilIdle();
2427 EXPECT_EQ(0u, GetErrors().size()); 2430 EXPECT_EQ(0u, GetErrors().size());
2428 EXPECT_EQ(2u, loaded_.size()); 2431 EXPECT_EQ(2u, loaded_.size());
2429 EXPECT_EQ(2u, registry()->enabled_extensions().size()); 2432 EXPECT_EQ(2u, registry()->enabled_extensions().size());
2430 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 2433 EXPECT_EQ(0u, registry()->disabled_extensions().size());
2431 EXPECT_TRUE(registry()->enabled_extensions().Contains(good1)); 2434 EXPECT_TRUE(registry()->enabled_extensions().Contains(good1));
2432 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2)); 2435 EXPECT_TRUE(registry()->enabled_extensions().Contains(good2));
2433 2436
2434 // Make sure the granted permissions have been setup. 2437 // Make sure the granted permissions have been setup.
2435 scoped_ptr<const PermissionSet> permissions = 2438 std::unique_ptr<const PermissionSet> permissions =
2436 ExtensionPrefs::Get(profile())->GetGrantedPermissions(good1); 2439 ExtensionPrefs::Get(profile())->GetGrantedPermissions(good1);
2437 ASSERT_TRUE(permissions); 2440 ASSERT_TRUE(permissions);
2438 EXPECT_FALSE(permissions->IsEmpty()); 2441 EXPECT_FALSE(permissions->IsEmpty());
2439 EXPECT_TRUE(permissions->HasEffectiveFullAccess()); 2442 EXPECT_TRUE(permissions->HasEffectiveFullAccess());
2440 EXPECT_FALSE(permissions->apis().empty()); 2443 EXPECT_FALSE(permissions->apis().empty());
2441 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin)); 2444 EXPECT_TRUE(permissions->HasAPIPermission(APIPermission::kPlugin));
2442 2445
2443 // We should be able to reload the extension without getting another prompt. 2446 // We should be able to reload the extension without getting another prompt.
2444 loaded_.clear(); 2447 loaded_.clear();
2445 auto_confirm.reset(); 2448 auto_confirm.reset();
(...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after
3815 // Verify all three extensions are installed and enabled. 3818 // Verify all three extensions are installed and enabled.
3816 ASSERT_TRUE(registry->enabled_extensions().GetByID(ext1)); 3819 ASSERT_TRUE(registry->enabled_extensions().GetByID(ext1));
3817 ASSERT_TRUE(registry->enabled_extensions().GetByID(ext2)); 3820 ASSERT_TRUE(registry->enabled_extensions().GetByID(ext2));
3818 ASSERT_TRUE(registry->enabled_extensions().GetByID(ext2_forced)); 3821 ASSERT_TRUE(registry->enabled_extensions().GetByID(ext2_forced));
3819 3822
3820 // Grant all optional permissions to each extension. 3823 // Grant all optional permissions to each extension.
3821 GrantAllOptionalPermissions(ext1); 3824 GrantAllOptionalPermissions(ext1);
3822 GrantAllOptionalPermissions(ext2); 3825 GrantAllOptionalPermissions(ext2);
3823 GrantAllOptionalPermissions(ext2_forced); 3826 GrantAllOptionalPermissions(ext2_forced);
3824 3827
3825 scoped_ptr<const PermissionSet> active_permissions = 3828 std::unique_ptr<const PermissionSet> active_permissions =
3826 ExtensionPrefs::Get(profile())->GetActivePermissions(ext1); 3829 ExtensionPrefs::Get(profile())->GetActivePermissions(ext1);
3827 EXPECT_TRUE(active_permissions->HasAPIPermission( 3830 EXPECT_TRUE(active_permissions->HasAPIPermission(
3828 extensions::APIPermission::kDownloads)); 3831 extensions::APIPermission::kDownloads));
3829 3832
3830 // Set policy to block 'downloads' permission. 3833 // Set policy to block 'downloads' permission.
3831 { 3834 {
3832 ManagementPrefUpdater pref(profile_->GetTestingPrefService()); 3835 ManagementPrefUpdater pref(profile_->GetTestingPrefService());
3833 pref.AddBlockedPermission("*", "downloads"); 3836 pref.AddBlockedPermission("*", "downloads");
3834 } 3837 }
3835 3838
(...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after
5288 5291
5289 TEST_F(ExtensionServiceTestSimple, Enabledness) { 5292 TEST_F(ExtensionServiceTestSimple, Enabledness) {
5290 // Make sure the PluginService singleton is destroyed at the end of the test. 5293 // Make sure the PluginService singleton is destroyed at the end of the test.
5291 base::ShadowingAtExitManager at_exit_manager; 5294 base::ShadowingAtExitManager at_exit_manager;
5292 #if defined(ENABLE_PLUGINS) 5295 #if defined(ENABLE_PLUGINS)
5293 content::PluginService::GetInstance()->Init(); 5296 content::PluginService::GetInstance()->Init();
5294 #endif 5297 #endif
5295 5298
5296 ExtensionErrorReporter::Init(false); // no noisy errors 5299 ExtensionErrorReporter::Init(false); // no noisy errors
5297 ExtensionsReadyRecorder recorder; 5300 ExtensionsReadyRecorder recorder;
5298 scoped_ptr<TestingProfile> profile(new TestingProfile()); 5301 std::unique_ptr<TestingProfile> profile(new TestingProfile());
5299 #if defined OS_CHROMEOS 5302 #if defined OS_CHROMEOS
5300 chromeos::ScopedTestDeviceSettingsService device_settings_service; 5303 chromeos::ScopedTestDeviceSettingsService device_settings_service;
5301 chromeos::ScopedTestCrosSettings cros_settings; 5304 chromeos::ScopedTestCrosSettings cros_settings;
5302 scoped_ptr<chromeos::ScopedTestUserManager> user_manager( 5305 std::unique_ptr<chromeos::ScopedTestUserManager> user_manager(
5303 new chromeos::ScopedTestUserManager); 5306 new chromeos::ScopedTestUserManager);
5304 #endif 5307 #endif
5305 scoped_ptr<base::CommandLine> command_line; 5308 std::unique_ptr<base::CommandLine> command_line;
5306 base::FilePath install_dir = profile->GetPath() 5309 base::FilePath install_dir = profile->GetPath()
5307 .AppendASCII(extensions::kInstallDirectoryName); 5310 .AppendASCII(extensions::kInstallDirectoryName);
5308 5311
5309 // By default, we are enabled. 5312 // By default, we are enabled.
5310 command_line.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); 5313 command_line.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM));
5311 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>( 5314 ExtensionService* service = static_cast<extensions::TestExtensionSystem*>(
5312 ExtensionSystem::Get(profile.get()))-> 5315 ExtensionSystem::Get(profile.get()))->
5313 CreateExtensionService( 5316 CreateExtensionService(
5314 command_line.get(), 5317 command_line.get(),
5315 install_dir, 5318 install_dir,
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
5454 InstallCRX(path, INSTALL_NEW); 5457 InstallCRX(path, INSTALL_NEW);
5455 ValidatePrefKeyCount(1u); 5458 ValidatePrefKeyCount(1u);
5456 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 5459 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
5457 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL); 5460 ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
5458 5461
5459 extensions::PendingExtensionManager* pending = 5462 extensions::PendingExtensionManager* pending =
5460 service()->pending_extension_manager(); 5463 service()->pending_extension_manager();
5461 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 5464 EXPECT_FALSE(pending->IsIdPending(kGoodId));
5462 5465
5463 // Skip install when the location is the same. 5466 // Skip install when the location is the same.
5464 scoped_ptr<GURL> good_update_url(new GURL(kGoodUpdateURL)); 5467 std::unique_ptr<GURL> good_update_url(new GURL(kGoodUpdateURL));
5465 scoped_ptr<ExternalInstallInfoUpdateUrl> info( 5468 std::unique_ptr<ExternalInstallInfoUpdateUrl> info(
5466 new ExternalInstallInfoUpdateUrl( 5469 new ExternalInstallInfoUpdateUrl(
5467 kGoodId, std::string(), std::move(good_update_url), 5470 kGoodId, std::string(), std::move(good_update_url),
5468 Manifest::INTERNAL, Extension::NO_FLAGS, false)); 5471 Manifest::INTERNAL, Extension::NO_FLAGS, false));
5469 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(*info, true)); 5472 EXPECT_FALSE(service()->OnExternalExtensionUpdateUrlFound(*info, true));
5470 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 5473 EXPECT_FALSE(pending->IsIdPending(kGoodId));
5471 5474
5472 // Install when the location has higher priority. 5475 // Install when the location has higher priority.
5473 info->download_location = Manifest::EXTERNAL_POLICY_DOWNLOAD; 5476 info->download_location = Manifest::EXTERNAL_POLICY_DOWNLOAD;
5474 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(*info, true)); 5477 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(*info, true));
5475 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 5478 EXPECT_TRUE(pending->IsIdPending(kGoodId));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
5517 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY, 5520 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_REGISTRY,
5518 Manifest::INTERNAL)); 5521 Manifest::INTERNAL));
5519 ASSERT_EQ(Manifest::EXTERNAL_PREF, 5522 ASSERT_EQ(Manifest::EXTERNAL_PREF,
5520 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF, 5523 Manifest::GetHigherPriorityLocation(Manifest::EXTERNAL_PREF,
5521 Manifest::INTERNAL)); 5524 Manifest::INTERNAL));
5522 5525
5523 extensions::PendingExtensionManager* pending = 5526 extensions::PendingExtensionManager* pending =
5524 service()->pending_extension_manager(); 5527 service()->pending_extension_manager();
5525 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 5528 EXPECT_FALSE(pending->IsIdPending(kGoodId));
5526 5529
5527 scoped_ptr<Version> older_version_ptr(new Version(older_version)); 5530 std::unique_ptr<Version> older_version_ptr(new Version(older_version));
5528 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 5531 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
5529 kGoodId, std::move(older_version_ptr), kInvalidPathToCrx, 5532 kGoodId, std::move(older_version_ptr), kInvalidPathToCrx,
5530 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged, 5533 Manifest::INTERNAL, kCreationFlags, kDontMarkAcknowledged,
5531 kDontInstallImmediately)); 5534 kDontInstallImmediately));
5532 { 5535 {
5533 // Simulate an external source adding the extension as INTERNAL. 5536 // Simulate an external source adding the extension as INTERNAL.
5534 content::WindowedNotificationObserver observer( 5537 content::WindowedNotificationObserver observer(
5535 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 5538 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
5536 content::NotificationService::AllSources()); 5539 content::NotificationService::AllSources());
5537 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); 5540 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info));
5538 EXPECT_TRUE(pending->IsIdPending(kGoodId)); 5541 EXPECT_TRUE(pending->IsIdPending(kGoodId));
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
5653 const bool kDontMarkAcknowledged = false; 5656 const bool kDontMarkAcknowledged = false;
5654 const bool kDontInstallImmediately = false; 5657 const bool kDontInstallImmediately = false;
5655 5658
5656 InitializeEmptyExtensionService(); 5659 InitializeEmptyExtensionService();
5657 5660
5658 extensions::PendingExtensionManager* pending = 5661 extensions::PendingExtensionManager* pending =
5659 service()->pending_extension_manager(); 5662 service()->pending_extension_manager();
5660 EXPECT_FALSE(pending->IsIdPending(kGoodId)); 5663 EXPECT_FALSE(pending->IsIdPending(kGoodId));
5661 5664
5662 // An external provider starts installing from a local crx. 5665 // An external provider starts installing from a local crx.
5663 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 5666 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
5664 kGoodId, make_scoped_ptr(new Version(kVersion123)), kInvalidPathToCrx, 5667 kGoodId, base::WrapUnique(new Version(kVersion123)), kInvalidPathToCrx,
5665 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged, 5668 Manifest::EXTERNAL_PREF, kCreationFlags, kDontMarkAcknowledged,
5666 kDontInstallImmediately)); 5669 kDontInstallImmediately));
5667 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info)); 5670 EXPECT_TRUE(service()->OnExternalExtensionFileFound(*info));
5668 5671
5669 const extensions::PendingExtensionInfo* pending_info; 5672 const extensions::PendingExtensionInfo* pending_info;
5670 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); 5673 EXPECT_TRUE((pending_info = pending->GetById(kGoodId)));
5671 EXPECT_TRUE(pending_info->version().IsValid()); 5674 EXPECT_TRUE(pending_info->version().IsValid());
5672 EXPECT_EQ(pending_info->version(), kVersion123); 5675 EXPECT_EQ(pending_info->version(), kVersion123);
5673 5676
5674 // Adding a newer version overrides the currently pending version. 5677 // Adding a newer version overrides the currently pending version.
(...skipping 13 matching lines...) Expand all
5688 // Adding an older version fails even when coming from a higher-priority 5691 // Adding an older version fails even when coming from a higher-priority
5689 // location. 5692 // location.
5690 info->crx_location = Manifest::EXTERNAL_REGISTRY; 5693 info->crx_location = Manifest::EXTERNAL_REGISTRY;
5691 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info)); 5694 EXPECT_FALSE(service()->OnExternalExtensionFileFound(*info));
5692 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); 5695 EXPECT_TRUE((pending_info = pending->GetById(kGoodId)));
5693 EXPECT_TRUE(pending_info->version().IsValid()); 5696 EXPECT_TRUE(pending_info->version().IsValid());
5694 EXPECT_EQ(pending_info->version(), kVersion124); 5697 EXPECT_EQ(pending_info->version(), kVersion124);
5695 5698
5696 // Adding the latest version from the webstore overrides a specific version. 5699 // Adding the latest version from the webstore overrides a specific version.
5697 GURL kUpdateUrl("http://example.com/update"); 5700 GURL kUpdateUrl("http://example.com/update");
5698 scoped_ptr<ExternalInstallInfoUpdateUrl> update_info( 5701 std::unique_ptr<ExternalInstallInfoUpdateUrl> update_info(
5699 new ExternalInstallInfoUpdateUrl( 5702 new ExternalInstallInfoUpdateUrl(
5700 kGoodId, std::string(), make_scoped_ptr(new GURL(kUpdateUrl)), 5703 kGoodId, std::string(), base::WrapUnique(new GURL(kUpdateUrl)),
5701 Manifest::EXTERNAL_POLICY_DOWNLOAD, Extension::NO_FLAGS, false)); 5704 Manifest::EXTERNAL_POLICY_DOWNLOAD, Extension::NO_FLAGS, false));
5702 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(*update_info, true)); 5705 EXPECT_TRUE(service()->OnExternalExtensionUpdateUrlFound(*update_info, true));
5703 EXPECT_TRUE((pending_info = pending->GetById(kGoodId))); 5706 EXPECT_TRUE((pending_info = pending->GetById(kGoodId)));
5704 EXPECT_FALSE(pending_info->version().IsValid()); 5707 EXPECT_FALSE(pending_info->version().IsValid());
5705 } 5708 }
5706 5709
5707 // This makes sure we can package and install CRX files that use whitelisted 5710 // This makes sure we can package and install CRX files that use whitelisted
5708 // permissions. 5711 // permissions.
5709 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) { 5712 TEST_F(ExtensionServiceTest, InstallWhitelistedExtension) {
5710 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk"; 5713 std::string test_id = "hdkklepkcpckhnpgjnmbdfhehckloojk";
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
5745 crx_id_, 5748 crx_id_,
5746 std::string(), 5749 std::string(),
5747 GURL(), 5750 GURL(),
5748 Manifest::EXTERNAL_PREF_DOWNLOAD, 5751 Manifest::EXTERNAL_PREF_DOWNLOAD,
5749 Extension::NO_FLAGS, 5752 Extension::NO_FLAGS,
5750 false); 5753 false);
5751 } 5754 }
5752 5755
5753 // Fake an external file from external_extensions.json. 5756 // Fake an external file from external_extensions.json.
5754 bool AddPendingExternalPrefFileInstall() { 5757 bool AddPendingExternalPrefFileInstall() {
5755 scoped_ptr<Version> version(new Version("1.0.0.0")); 5758 std::unique_ptr<Version> version(new Version("1.0.0.0"));
5756 scoped_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile( 5759 std::unique_ptr<ExternalInstallInfoFile> info(new ExternalInstallInfoFile(
5757 crx_id_, std::move(version), crx_path_, Manifest::EXTERNAL_PREF, 5760 crx_id_, std::move(version), crx_path_, Manifest::EXTERNAL_PREF,
5758 Extension::NO_FLAGS, false, false)); 5761 Extension::NO_FLAGS, false, false));
5759 return service()->OnExternalExtensionFileFound(*info); 5762 return service()->OnExternalExtensionFileFound(*info);
5760 } 5763 }
5761 5764
5762 // Fake a request from sync to install an extension. 5765 // Fake a request from sync to install an extension.
5763 bool AddPendingSyncInstall() { 5766 bool AddPendingSyncInstall() {
5764 return service()->pending_extension_manager()->AddFromSync( 5767 return service()->pending_extension_manager()->AddFromSync(
5765 crx_id_, 5768 crx_id_,
5766 GURL(kGoodUpdateURL), 5769 GURL(kGoodUpdateURL),
5767 base::Version(), 5770 base::Version(),
5768 &IsExtension, 5771 &IsExtension,
5769 kGoodRemoteInstall, 5772 kGoodRemoteInstall,
5770 kGoodInstalledByCustodian); 5773 kGoodInstalledByCustodian);
5771 } 5774 }
5772 5775
5773 // Fake a policy install. 5776 // Fake a policy install.
5774 bool AddPendingPolicyInstall() { 5777 bool AddPendingPolicyInstall() {
5775 // Get path to the CRX with id |kGoodId|. 5778 // Get path to the CRX with id |kGoodId|.
5776 scoped_ptr<GURL> empty_url(new GURL()); 5779 std::unique_ptr<GURL> empty_url(new GURL());
5777 scoped_ptr<ExternalInstallInfoUpdateUrl> info( 5780 std::unique_ptr<ExternalInstallInfoUpdateUrl> info(
5778 new ExternalInstallInfoUpdateUrl( 5781 new ExternalInstallInfoUpdateUrl(
5779 crx_id_, std::string(), std::move(empty_url), 5782 crx_id_, std::string(), std::move(empty_url),
5780 Manifest::EXTERNAL_POLICY_DOWNLOAD, Extension::NO_FLAGS, false)); 5783 Manifest::EXTERNAL_POLICY_DOWNLOAD, Extension::NO_FLAGS, false));
5781 return service()->OnExternalExtensionUpdateUrlFound(*info, true); 5784 return service()->OnExternalExtensionUpdateUrlFound(*info, true);
5782 } 5785 }
5783 5786
5784 // Get the install source of a pending extension. 5787 // Get the install source of a pending extension.
5785 Manifest::Location GetPendingLocation() { 5788 Manifest::Location GetPendingLocation() {
5786 const extensions::PendingExtensionInfo* info; 5789 const extensions::PendingExtensionInfo* info;
5787 EXPECT_TRUE( 5790 EXPECT_TRUE(
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
6520 6523
6521 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 6524 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
6522 content::Source<Profile>(profile()), 6525 content::Source<Profile>(profile()),
6523 content::NotificationService::NoDetails()); 6526 content::NotificationService::NoDetails());
6524 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 6527 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
6525 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 6528 EXPECT_EQ(0u, registry()->enabled_extensions().size());
6526 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 6529 EXPECT_EQ(0u, registry()->disabled_extensions().size());
6527 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 6530 EXPECT_EQ(0u, registry()->terminated_extensions().size());
6528 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 6531 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
6529 } 6532 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698