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

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

Issue 2756793003: Move GPU blacklist and driver bug workaround list from json to data struct. (Closed)
Patch Set: pure rebase Created 3 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
10 #include <algorithm> 10 #include <algorithm>
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 #include "extensions/common/extension_resource.h" 121 #include "extensions/common/extension_resource.h"
122 #include "extensions/common/manifest_constants.h" 122 #include "extensions/common/manifest_constants.h"
123 #include "extensions/common/manifest_handlers/background_info.h" 123 #include "extensions/common/manifest_handlers/background_info.h"
124 #include "extensions/common/manifest_handlers/permissions_parser.h" 124 #include "extensions/common/manifest_handlers/permissions_parser.h"
125 #include "extensions/common/manifest_url_handlers.h" 125 #include "extensions/common/manifest_url_handlers.h"
126 #include "extensions/common/permissions/permission_set.h" 126 #include "extensions/common/permissions/permission_set.h"
127 #include "extensions/common/permissions/permissions_data.h" 127 #include "extensions/common/permissions/permissions_data.h"
128 #include "extensions/common/switches.h" 128 #include "extensions/common/switches.h"
129 #include "extensions/common/url_pattern.h" 129 #include "extensions/common/url_pattern.h"
130 #include "extensions/common/value_builder.h" 130 #include "extensions/common/value_builder.h"
131 #include "gpu/config/gpu_info.h"
132 #include "net/cookies/cookie_options.h" 131 #include "net/cookies/cookie_options.h"
133 #include "net/cookies/cookie_store.h" 132 #include "net/cookies/cookie_store.h"
134 #include "net/url_request/url_request_context.h" 133 #include "net/url_request/url_request_context.h"
135 #include "net/url_request/url_request_context_getter.h" 134 #include "net/url_request/url_request_context_getter.h"
136 #include "ppapi/features/features.h" 135 #include "ppapi/features/features.h"
137 #include "storage/browser/database/database_tracker.h" 136 #include "storage/browser/database/database_tracker.h"
138 #include "storage/browser/quota/quota_manager.h" 137 #include "storage/browser/quota/quota_manager.h"
139 #include "storage/common/database/database_identifier.h" 138 #include "storage/common/database/database_identifier.h"
140 #include "testing/gmock/include/gmock/gmock.h" 139 #include "testing/gmock/include/gmock/gmock.h"
141 #include "testing/gtest/include/gtest/gtest.h" 140 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 return data_dir() 630 return data_dir()
632 .AppendASCII("good") 631 .AppendASCII("good")
633 .AppendASCII("Extensions") 632 .AppendASCII("Extensions")
634 .AppendASCII(good2) 633 .AppendASCII(good2)
635 .AppendASCII("1.0"); 634 .AppendASCII("1.0");
636 } 635 }
637 636
638 void TestExternalProvider(MockExtensionProvider* provider, 637 void TestExternalProvider(MockExtensionProvider* provider,
639 Manifest::Location location); 638 Manifest::Location location);
640 639
641 void BlackListWebGL() {
642 static const std::string json_blacklist =
643 "{\n"
644 " \"name\": \"gpu blacklist\",\n"
645 " \"version\": \"1.0\",\n"
646 " \"entries\": [\n"
647 " {\n"
648 " \"id\": 1,\n"
649 " \"features\": [\"accelerated_webgl\"]\n"
650 " }\n"
651 " ]\n"
652 "}";
653 gpu::GPUInfo gpu_info;
654 content::GpuDataManager::GetInstance()->InitializeForTesting(
655 json_blacklist, gpu_info);
656 }
657
658 // Grants all optional permissions stated in manifest to active permission 640 // Grants all optional permissions stated in manifest to active permission
659 // set for extension |id|. 641 // set for extension |id|.
660 void GrantAllOptionalPermissions(const std::string& id) { 642 void GrantAllOptionalPermissions(const std::string& id) {
661 const Extension* extension = service()->GetInstalledExtension(id); 643 const Extension* extension = service()->GetInstalledExtension(id);
662 const PermissionSet& all_optional_permissions = 644 const PermissionSet& all_optional_permissions =
663 extensions::PermissionsParser::GetOptionalPermissions(extension); 645 extensions::PermissionsParser::GetOptionalPermissions(extension);
664 extensions::PermissionsUpdater perms_updater(profile()); 646 extensions::PermissionsUpdater perms_updater(profile());
665 perms_updater.AddPermissions(extension, all_optional_permissions); 647 perms_updater.AddPermissions(extension, all_optional_permissions);
666 } 648 }
667 649
(...skipping 3892 matching lines...) Expand 10 before | Expand all | Expand 10 after
4560 TerminateExtension(good_crx); 4542 TerminateExtension(good_crx);
4561 UninstallExtension(good_crx, true); 4543 UninstallExtension(good_crx, true);
4562 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_); 4544 EXPECT_EQ(UnloadedExtensionInfo::REASON_TERMINATE, unloaded_reason_);
4563 } 4545 }
4564 4546
4565 // An extension disabled because of unsupported requirements should re-enabled 4547 // An extension disabled because of unsupported requirements should re-enabled
4566 // if updated to a version with supported requirements as long as there are no 4548 // if updated to a version with supported requirements as long as there are no
4567 // other disable reasons. 4549 // other disable reasons.
4568 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) { 4550 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) {
4569 InitializeEmptyExtensionService(); 4551 InitializeEmptyExtensionService();
4570 BlackListWebGL(); 4552 content::GpuDataManager::GetInstance()->BlacklistWebGLForTesting();
4571 4553
4572 base::FilePath path = data_dir().AppendASCII("requirements"); 4554 base::FilePath path = data_dir().AppendASCII("requirements");
4573 base::FilePath pem_path = 4555 base::FilePath pem_path =
4574 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem"); 4556 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
4575 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), 4557 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4576 pem_path, 4558 pem_path,
4577 INSTALL_NEW); 4559 INSTALL_NEW);
4578 std::string id = extension_v1->id(); 4560 std::string id = extension_v1->id();
4579 EXPECT_TRUE(service()->IsExtensionEnabled(id)); 4561 EXPECT_TRUE(service()->IsExtensionEnabled(id));
4580 4562
4581 base::FilePath v2_bad_requirements_crx = GetTemporaryFile(); 4563 base::FilePath v2_bad_requirements_crx = GetTemporaryFile();
4582 4564
4583 PackCRX(path.AppendASCII("v2_bad_requirements"), 4565 PackCRX(path.AppendASCII("v2_bad_requirements"),
4584 pem_path, 4566 pem_path,
4585 v2_bad_requirements_crx); 4567 v2_bad_requirements_crx);
4586 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED); 4568 UpdateExtension(id, v2_bad_requirements_crx, INSTALLED);
4587 EXPECT_FALSE(service()->IsExtensionEnabled(id)); 4569 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4588 4570
4589 base::FilePath v3_good_crx = GetTemporaryFile(); 4571 base::FilePath v3_good_crx = GetTemporaryFile();
4590 4572
4591 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); 4573 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx);
4592 UpdateExtension(id, v3_good_crx, ENABLED); 4574 UpdateExtension(id, v3_good_crx, ENABLED);
4593 EXPECT_TRUE(service()->IsExtensionEnabled(id)); 4575 EXPECT_TRUE(service()->IsExtensionEnabled(id));
4594 } 4576 }
4595 4577
4596 // Extensions disabled through user action should stay disabled. 4578 // Extensions disabled through user action should stay disabled.
4597 TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) { 4579 TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) {
4598 InitializeEmptyExtensionService(); 4580 InitializeEmptyExtensionService();
4599 BlackListWebGL(); 4581 content::GpuDataManager::GetInstance()->BlacklistWebGLForTesting();
4600 4582
4601 base::FilePath path = data_dir().AppendASCII("requirements"); 4583 base::FilePath path = data_dir().AppendASCII("requirements");
4602 base::FilePath pem_path = 4584 base::FilePath pem_path =
4603 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem"); 4585 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
4604 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), 4586 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4605 pem_path, 4587 pem_path,
4606 INSTALL_NEW); 4588 INSTALL_NEW);
4607 std::string id = extension_v1->id(); 4589 std::string id = extension_v1->id();
4608 service()->DisableExtension(id, Extension::DISABLE_USER_ACTION); 4590 service()->DisableExtension(id, Extension::DISABLE_USER_ACTION);
4609 EXPECT_FALSE(service()->IsExtensionEnabled(id)); 4591 EXPECT_FALSE(service()->IsExtensionEnabled(id));
(...skipping 10 matching lines...) Expand all
4620 4602
4621 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx); 4603 PackCRX(path.AppendASCII("v3_good"), pem_path, v3_good_crx);
4622 UpdateExtension(id, v3_good_crx, INSTALLED); 4604 UpdateExtension(id, v3_good_crx, INSTALLED);
4623 EXPECT_FALSE(service()->IsExtensionEnabled(id)); 4605 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4624 } 4606 }
4625 4607
4626 // The extension should not re-enabled because it was disabled from a 4608 // The extension should not re-enabled because it was disabled from a
4627 // permission increase. 4609 // permission increase.
4628 TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) { 4610 TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) {
4629 InitializeEmptyExtensionService(); 4611 InitializeEmptyExtensionService();
4630 BlackListWebGL(); 4612 content::GpuDataManager::GetInstance()->BlacklistWebGLForTesting();
4631 4613
4632 base::FilePath path = data_dir().AppendASCII("requirements"); 4614 base::FilePath path = data_dir().AppendASCII("requirements");
4633 base::FilePath pem_path = 4615 base::FilePath pem_path =
4634 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem"); 4616 data_dir().AppendASCII("requirements").AppendASCII("v1_good.pem");
4635 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), 4617 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"),
4636 pem_path, 4618 pem_path,
4637 INSTALL_NEW); 4619 INSTALL_NEW);
4638 std::string id = extension_v1->id(); 4620 std::string id = extension_v1->id();
4639 EXPECT_TRUE(service()->IsExtensionEnabled(id)); 4621 EXPECT_TRUE(service()->IsExtensionEnabled(id));
4640 4622
(...skipping 11 matching lines...) Expand all
4652 pem_path, 4634 pem_path,
4653 v3_bad_permissions_crx); 4635 v3_bad_permissions_crx);
4654 UpdateExtension(id, v3_bad_permissions_crx, INSTALLED); 4636 UpdateExtension(id, v3_bad_permissions_crx, INSTALLED);
4655 EXPECT_FALSE(service()->IsExtensionEnabled(id)); 4637 EXPECT_FALSE(service()->IsExtensionEnabled(id));
4656 } 4638 }
4657 4639
4658 // Unpacked extensions are not allowed to be installed if they have unsupported 4640 // Unpacked extensions are not allowed to be installed if they have unsupported
4659 // requirements. 4641 // requirements.
4660 TEST_F(ExtensionServiceTest, UnpackedRequirements) { 4642 TEST_F(ExtensionServiceTest, UnpackedRequirements) {
4661 InitializeEmptyExtensionService(); 4643 InitializeEmptyExtensionService();
4662 BlackListWebGL(); 4644 content::GpuDataManager::GetInstance()->BlacklistWebGLForTesting();
4663 4645
4664 base::FilePath path = 4646 base::FilePath path =
4665 data_dir().AppendASCII("requirements").AppendASCII("v2_bad_requirements"); 4647 data_dir().AppendASCII("requirements").AppendASCII("v2_bad_requirements");
4666 extensions::UnpackedInstaller::Create(service())->Load(path); 4648 extensions::UnpackedInstaller::Create(service())->Load(path);
4667 base::RunLoop().RunUntilIdle(); 4649 base::RunLoop().RunUntilIdle();
4668 EXPECT_EQ(1u, GetErrors().size()); 4650 EXPECT_EQ(1u, GetErrors().size());
4669 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 4651 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4670 } 4652 }
4671 4653
4672 class ExtensionCookieCallback { 4654 class ExtensionCookieCallback {
(...skipping 2483 matching lines...) Expand 10 before | Expand all | Expand 10 after
7156 shared_module->manifest()->type()); 7138 shared_module->manifest()->type());
7157 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); 7139 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId));
7158 7140
7159 // Reload the extension and wait for it to complete. This previously crashed 7141 // Reload the extension and wait for it to complete. This previously crashed
7160 // (see crbug.com/676815). 7142 // (see crbug.com/676815).
7161 service()->ReloadExtension(kExtensionId); 7143 service()->ReloadExtension(kExtensionId);
7162 base::RunLoop().RunUntilIdle(); 7144 base::RunLoop().RunUntilIdle();
7163 // The shared module should be enabled. 7145 // The shared module should be enabled.
7164 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); 7146 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId));
7165 } 7147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698