| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 3735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3746 ExtensionCookieCallback callback; | 3746 ExtensionCookieCallback callback; |
| 3747 | 3747 |
| 3748 // Load a test extension. | 3748 // Load a test extension. |
| 3749 FilePath path = data_dir_; | 3749 FilePath path = data_dir_; |
| 3750 path = path.AppendASCII("good.crx"); | 3750 path = path.AppendASCII("good.crx"); |
| 3751 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 3751 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
| 3752 ASSERT_TRUE(extension); | 3752 ASSERT_TRUE(extension); |
| 3753 GURL ext_url(extension->url()); | 3753 GURL ext_url(extension->url()); |
| 3754 string16 origin_id = | 3754 string16 origin_id = |
| 3755 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); | 3755 webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); |
| 3756 // For extensions, the extension's base URL is always the site. |
| 3757 content::StoragePartition* partition = |
| 3758 BrowserContext::GetStoragePartition(profile_.get(), ext_url); |
| 3756 | 3759 |
| 3757 // Set a cookie for the extension. | 3760 // Set a cookie for the extension. |
| 3758 net::CookieMonster* cookie_monster = | 3761 net::CookieMonster* cookie_monster = |
| 3759 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> | 3762 profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> |
| 3760 cookie_store()->GetCookieMonster(); | 3763 cookie_store()->GetCookieMonster(); |
| 3761 ASSERT_TRUE(cookie_monster); | 3764 ASSERT_TRUE(cookie_monster); |
| 3762 net::CookieOptions options; | 3765 net::CookieOptions options; |
| 3763 cookie_monster->SetCookieWithOptionsAsync( | 3766 cookie_monster->SetCookieWithOptionsAsync( |
| 3764 ext_url, "dummy=value", options, | 3767 ext_url, "dummy=value", options, |
| 3765 base::Bind(&ExtensionCookieCallback::SetCookieCallback, | 3768 base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 3766 base::Unretained(&callback))); | 3769 base::Unretained(&callback))); |
| 3767 loop_.RunAllPending(); | 3770 loop_.RunAllPending(); |
| 3768 EXPECT_TRUE(callback.result_); | 3771 EXPECT_TRUE(callback.result_); |
| 3769 | 3772 |
| 3770 cookie_monster->GetAllCookiesForURLAsync( | 3773 cookie_monster->GetAllCookiesForURLAsync( |
| 3771 ext_url, | 3774 ext_url, |
| 3772 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 3775 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 3773 base::Unretained(&callback))); | 3776 base::Unretained(&callback))); |
| 3774 loop_.RunAllPending(); | 3777 loop_.RunAllPending(); |
| 3775 EXPECT_EQ(1U, callback.list_.size()); | 3778 EXPECT_EQ(1U, callback.list_.size()); |
| 3776 | 3779 |
| 3777 // Open a database. | 3780 // Open a database. |
| 3778 webkit_database::DatabaseTracker* db_tracker = | 3781 webkit_database::DatabaseTracker* db_tracker = |
| 3779 BrowserContext::GetDefaultStoragePartition(profile_.get())-> | 3782 partition->GetDatabaseTracker(); |
| 3780 GetDatabaseTracker(); | |
| 3781 string16 db_name = UTF8ToUTF16("db"); | 3783 string16 db_name = UTF8ToUTF16("db"); |
| 3782 string16 description = UTF8ToUTF16("db_description"); | 3784 string16 description = UTF8ToUTF16("db_description"); |
| 3783 int64 size; | 3785 int64 size; |
| 3784 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); | 3786 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
| 3785 db_tracker->DatabaseClosed(origin_id, db_name); | 3787 db_tracker->DatabaseClosed(origin_id, db_name); |
| 3786 std::vector<webkit_database::OriginInfo> origins; | 3788 std::vector<webkit_database::OriginInfo> origins; |
| 3787 db_tracker->GetAllOriginsInfo(&origins); | 3789 db_tracker->GetAllOriginsInfo(&origins); |
| 3788 EXPECT_EQ(1U, origins.size()); | 3790 EXPECT_EQ(1U, origins.size()); |
| 3789 EXPECT_EQ(origin_id, origins[0].GetOrigin()); | 3791 EXPECT_EQ(origin_id, origins[0].GetOrigin()); |
| 3790 | 3792 |
| 3791 // Create local storage. We only simulate this by creating the backing files. | 3793 // Create local storage. We only simulate this by creating the backing files. |
| 3792 // Note: This test depends on details of how the dom_storage library | 3794 // Note: This test depends on details of how the dom_storage library |
| 3793 // stores data in the host file system. | 3795 // stores data in the host file system. |
| 3794 FilePath lso_dir_path = profile_->GetPath().AppendASCII("Local Storage"); | 3796 FilePath lso_dir_path = partition->GetPath().AppendASCII("Local Storage"); |
| 3795 FilePath lso_file_path = lso_dir_path.AppendASCII( | 3797 FilePath lso_file_path = lso_dir_path.AppendASCII( |
| 3796 UTF16ToUTF8(origin_id) + ".localstorage"); | 3798 UTF16ToUTF8(origin_id) + ".localstorage"); |
| 3797 EXPECT_TRUE(file_util::CreateDirectory(lso_dir_path)); | 3799 EXPECT_TRUE(file_util::CreateDirectory(lso_dir_path)); |
| 3798 EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); | 3800 EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); |
| 3799 EXPECT_TRUE(file_util::PathExists(lso_file_path)); | 3801 EXPECT_TRUE(file_util::PathExists(lso_file_path)); |
| 3800 | 3802 |
| 3801 // Create indexed db. Similarly, it is enough to only simulate this by | 3803 // Create indexed db. Similarly, it is enough to only simulate this by |
| 3802 // creating the directory on the disk. | 3804 // creating the directory on the disk. |
| 3803 IndexedDBContext* idb_context = | 3805 IndexedDBContext* idb_context = partition->GetIndexedDBContext(); |
| 3804 BrowserContext::GetDefaultStoragePartition(profile_.get())-> | |
| 3805 GetIndexedDBContext(); | |
| 3806 FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); | 3806 FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
| 3807 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); | 3807 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); |
| 3808 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); | 3808 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); |
| 3809 | 3809 |
| 3810 // Uninstall the extension. | 3810 // Uninstall the extension. |
| 3811 service_->UninstallExtension(good_crx, false, NULL); | 3811 service_->UninstallExtension(good_crx, false, NULL); |
| 3812 loop_.RunAllPending(); | 3812 loop_.RunAllPending(); |
| 3813 | 3813 |
| 3814 // Check that the cookie is gone. | 3814 // Check that the cookie is gone. |
| 3815 cookie_monster->GetAllCookiesForURLAsync( | 3815 cookie_monster->GetAllCookiesForURLAsync( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3845 ValidatePrefKeyCount(++pref_count); | 3845 ValidatePrefKeyCount(++pref_count); |
| 3846 ASSERT_EQ(1u, service_->extensions()->size()); | 3846 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3847 const std::string id1 = extension->id(); | 3847 const std::string id1 = extension->id(); |
| 3848 EXPECT_TRUE(extension->HasAPIPermission( | 3848 EXPECT_TRUE(extension->HasAPIPermission( |
| 3849 APIPermission::kUnlimitedStorage)); | 3849 APIPermission::kUnlimitedStorage)); |
| 3850 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); | 3850 const GURL origin1(extension->GetFullLaunchURL().GetOrigin()); |
| 3851 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 3851 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 3852 IsStorageUnlimited(origin1)); | 3852 IsStorageUnlimited(origin1)); |
| 3853 string16 origin_id = | 3853 string16 origin_id = |
| 3854 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1); | 3854 webkit_database::DatabaseUtil::GetOriginIdentifier(origin1); |
| 3855 // For extensions, the extension's base URL is always the site. |
| 3856 content::StoragePartition* partition = |
| 3857 BrowserContext::GetStoragePartition(profile_.get(), extension->url()); |
| 3855 | 3858 |
| 3856 // Install app2 from the same origin with unlimited storage. | 3859 // Install app2 from the same origin with unlimited storage. |
| 3857 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); | 3860 extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW); |
| 3858 ValidatePrefKeyCount(++pref_count); | 3861 ValidatePrefKeyCount(++pref_count); |
| 3859 ASSERT_EQ(2u, service_->extensions()->size()); | 3862 ASSERT_EQ(2u, service_->extensions()->size()); |
| 3860 const std::string id2 = extension->id(); | 3863 const std::string id2 = extension->id(); |
| 3861 EXPECT_TRUE(extension->HasAPIPermission( | 3864 EXPECT_TRUE(extension->HasAPIPermission( |
| 3862 APIPermission::kUnlimitedStorage)); | 3865 APIPermission::kUnlimitedStorage)); |
| 3863 EXPECT_TRUE(extension->web_extent().MatchesURL( | 3866 EXPECT_TRUE(extension->web_extent().MatchesURL( |
| 3864 extension->GetFullLaunchURL())); | 3867 extension->GetFullLaunchURL())); |
| 3865 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); | 3868 const GURL origin2(extension->GetFullLaunchURL().GetOrigin()); |
| 3866 EXPECT_EQ(origin1, origin2); | 3869 EXPECT_EQ(origin1, origin2); |
| 3867 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 3870 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 3868 IsStorageUnlimited(origin2)); | 3871 IsStorageUnlimited(origin2)); |
| 3872 // Neither apps here have isolated storage, so they should share the same |
| 3873 // partition. |
| 3869 | 3874 |
| 3870 // Set a cookie for the extension. | 3875 // Set a cookie for the extension. |
| 3871 net::CookieMonster* cookie_monster = | 3876 net::CookieMonster* cookie_monster = |
| 3872 profile_->GetRequestContext()->GetURLRequestContext()-> | 3877 partition->GetRequestContext()->GetURLRequestContext()-> |
| 3873 cookie_store()->GetCookieMonster(); | 3878 cookie_store()->GetCookieMonster(); |
| 3874 ASSERT_TRUE(cookie_monster); | 3879 ASSERT_TRUE(cookie_monster); |
| 3875 net::CookieOptions options; | 3880 net::CookieOptions options; |
| 3876 cookie_monster->SetCookieWithOptionsAsync( | 3881 cookie_monster->SetCookieWithOptionsAsync( |
| 3877 origin1, "dummy=value", options, | 3882 origin1, "dummy=value", options, |
| 3878 base::Bind(&ExtensionCookieCallback::SetCookieCallback, | 3883 base::Bind(&ExtensionCookieCallback::SetCookieCallback, |
| 3879 base::Unretained(&callback))); | 3884 base::Unretained(&callback))); |
| 3880 loop_.RunAllPending(); | 3885 loop_.RunAllPending(); |
| 3881 EXPECT_TRUE(callback.result_); | 3886 EXPECT_TRUE(callback.result_); |
| 3882 | 3887 |
| 3883 cookie_monster->GetAllCookiesForURLAsync( | 3888 cookie_monster->GetAllCookiesForURLAsync( |
| 3884 origin1, | 3889 origin1, |
| 3885 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 3890 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 3886 base::Unretained(&callback))); | 3891 base::Unretained(&callback))); |
| 3887 loop_.RunAllPending(); | 3892 loop_.RunAllPending(); |
| 3888 EXPECT_EQ(1U, callback.list_.size()); | 3893 EXPECT_EQ(1U, callback.list_.size()); |
| 3889 | 3894 |
| 3890 // Open a database. | 3895 // Open a database. |
| 3891 webkit_database::DatabaseTracker* db_tracker = | 3896 webkit_database::DatabaseTracker* db_tracker = |
| 3892 BrowserContext::GetDefaultStoragePartition(profile_.get())-> | 3897 partition->GetDatabaseTracker(); |
| 3893 GetDatabaseTracker(); | |
| 3894 string16 db_name = UTF8ToUTF16("db"); | 3898 string16 db_name = UTF8ToUTF16("db"); |
| 3895 string16 description = UTF8ToUTF16("db_description"); | 3899 string16 description = UTF8ToUTF16("db_description"); |
| 3896 int64 size; | 3900 int64 size; |
| 3897 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); | 3901 db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size); |
| 3898 db_tracker->DatabaseClosed(origin_id, db_name); | 3902 db_tracker->DatabaseClosed(origin_id, db_name); |
| 3899 std::vector<webkit_database::OriginInfo> origins; | 3903 std::vector<webkit_database::OriginInfo> origins; |
| 3900 db_tracker->GetAllOriginsInfo(&origins); | 3904 db_tracker->GetAllOriginsInfo(&origins); |
| 3901 EXPECT_EQ(1U, origins.size()); | 3905 EXPECT_EQ(1U, origins.size()); |
| 3902 EXPECT_EQ(origin_id, origins[0].GetOrigin()); | 3906 EXPECT_EQ(origin_id, origins[0].GetOrigin()); |
| 3903 | 3907 |
| 3904 // Create local storage. We only simulate this by creating the backing files. | 3908 // Create local storage. We only simulate this by creating the backing files. |
| 3905 // Note: This test depends on details of how the dom_storage library | 3909 // Note: This test depends on details of how the dom_storage library |
| 3906 // stores data in the host file system. | 3910 // stores data in the host file system. |
| 3907 FilePath lso_dir_path = profile_->GetPath().AppendASCII("Local Storage"); | 3911 FilePath lso_dir_path = partition->GetPath().AppendASCII("Local Storage"); |
| 3908 FilePath lso_file_path = lso_dir_path.AppendASCII( | 3912 FilePath lso_file_path = lso_dir_path.AppendASCII( |
| 3909 UTF16ToUTF8(origin_id) + ".localstorage"); | 3913 UTF16ToUTF8(origin_id) + ".localstorage"); |
| 3910 EXPECT_TRUE(file_util::CreateDirectory(lso_dir_path)); | 3914 EXPECT_TRUE(file_util::CreateDirectory(lso_dir_path)); |
| 3911 EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); | 3915 EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); |
| 3912 EXPECT_TRUE(file_util::PathExists(lso_file_path)); | 3916 EXPECT_TRUE(file_util::PathExists(lso_file_path)); |
| 3913 | 3917 |
| 3914 // Create indexed db. Similarly, it is enough to only simulate this by | 3918 // Create indexed db. Similarly, it is enough to only simulate this by |
| 3915 // creating the directory on the disk. | 3919 // creating the directory on the disk. |
| 3916 IndexedDBContext* idb_context = | 3920 IndexedDBContext* idb_context = partition->GetIndexedDBContext(); |
| 3917 BrowserContext::GetDefaultStoragePartition(profile_.get())-> | |
| 3918 GetIndexedDBContext(); | |
| 3919 FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); | 3921 FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
| 3920 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); | 3922 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); |
| 3921 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); | 3923 EXPECT_TRUE(file_util::DirectoryExists(idb_path)); |
| 3922 | 3924 |
| 3923 // Uninstall one of them, unlimited storage should still be granted | 3925 // Uninstall one of them, unlimited storage should still be granted |
| 3924 // to the origin. | 3926 // to the origin. |
| 3925 UninstallExtension(id1, false); | 3927 UninstallExtension(id1, false); |
| 3926 EXPECT_EQ(1u, service_->extensions()->size()); | 3928 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3927 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 3929 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 3928 IsStorageUnlimited(origin1)); | 3930 IsStorageUnlimited(origin1)); |
| (...skipping 1889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5818 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 5820 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5819 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 5821 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 5820 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); | 5822 EXPECT_TRUE(service_->IsExtensionEnabled(page_action)); |
| 5821 | 5823 |
| 5822 ExtensionPrefs* prefs = service_->extension_prefs(); | 5824 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 5823 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & | 5825 EXPECT_NE(0, prefs->GetDisableReasons(good_crx) & |
| 5824 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5826 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5825 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & | 5827 EXPECT_EQ(0, prefs->GetDisableReasons(page_action) & |
| 5826 Extension::DISABLE_SIDELOAD_WIPEOUT); | 5828 Extension::DISABLE_SIDELOAD_WIPEOUT); |
| 5827 } | 5829 } |
| OLD | NEW |