| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_service_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 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 } | 552 } |
| 553 | 553 |
| 554 void ExtensionServiceTestBase::InitializeInstalledExtensionService( | 554 void ExtensionServiceTestBase::InitializeInstalledExtensionService( |
| 555 const base::FilePath& prefs_file, | 555 const base::FilePath& prefs_file, |
| 556 const base::FilePath& source_install_dir) { | 556 const base::FilePath& source_install_dir) { |
| 557 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 557 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 558 base::FilePath path = temp_dir_.path(); | 558 base::FilePath path = temp_dir_.path(); |
| 559 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); | 559 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
| 560 EXPECT_TRUE(base::DeleteFile(path, true)); | 560 EXPECT_TRUE(base::DeleteFile(path, true)); |
| 561 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 561 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 562 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(path, &error)) << error; | 562 EXPECT_TRUE(base::CreateDirectoryAndGetError(path, &error)) << error; |
| 563 base::FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences")); | 563 base::FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences")); |
| 564 EXPECT_TRUE(base::CopyFile(prefs_file, temp_prefs)); | 564 EXPECT_TRUE(base::CopyFile(prefs_file, temp_prefs)); |
| 565 | 565 |
| 566 base::FilePath extensions_install_dir = | 566 base::FilePath extensions_install_dir = |
| 567 path.Append(FILE_PATH_LITERAL("Extensions")); | 567 path.Append(FILE_PATH_LITERAL("Extensions")); |
| 568 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); | 568 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); |
| 569 EXPECT_TRUE( | 569 EXPECT_TRUE( |
| 570 base::CopyDirectory(source_install_dir, extensions_install_dir, true)); | 570 base::CopyDirectory(source_install_dir, extensions_install_dir, true)); |
| 571 | 571 |
| 572 ExtensionServiceInitParams params; | 572 ExtensionServiceInitParams params; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 // static | 630 // static |
| 631 ExtensionServiceTestBase::ExtensionServiceInitParams | 631 ExtensionServiceTestBase::ExtensionServiceInitParams |
| 632 ExtensionServiceTestBase::CreateDefaultInitParamsInTempDir( | 632 ExtensionServiceTestBase::CreateDefaultInitParamsInTempDir( |
| 633 base::ScopedTempDir* temp_dir) { | 633 base::ScopedTempDir* temp_dir) { |
| 634 ExtensionServiceInitParams params; | 634 ExtensionServiceInitParams params; |
| 635 EXPECT_TRUE(temp_dir->CreateUniqueTempDir()); | 635 EXPECT_TRUE(temp_dir->CreateUniqueTempDir()); |
| 636 base::FilePath path = temp_dir->path(); | 636 base::FilePath path = temp_dir->path(); |
| 637 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); | 637 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
| 638 EXPECT_TRUE(base::DeleteFile(path, true)); | 638 EXPECT_TRUE(base::DeleteFile(path, true)); |
| 639 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 639 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 640 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(path, &error)) << error; | 640 EXPECT_TRUE(base::CreateDirectoryAndGetError(path, &error)) << error; |
| 641 base::FilePath prefs_filename = | 641 base::FilePath prefs_filename = |
| 642 path.Append(FILE_PATH_LITERAL("TestPreferences")); | 642 path.Append(FILE_PATH_LITERAL("TestPreferences")); |
| 643 base::FilePath extensions_install_dir = | 643 base::FilePath extensions_install_dir = |
| 644 path.Append(FILE_PATH_LITERAL("Extensions")); | 644 path.Append(FILE_PATH_LITERAL("Extensions")); |
| 645 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); | 645 EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); |
| 646 EXPECT_TRUE(file_util::CreateDirectoryAndGetError(extensions_install_dir, | 646 EXPECT_TRUE(base::CreateDirectoryAndGetError(extensions_install_dir, |
| 647 &error)) << error; | 647 &error)) << error; |
| 648 | 648 |
| 649 params.profile_path = path; | 649 params.profile_path = path; |
| 650 params.pref_file = prefs_filename; | 650 params.pref_file = prefs_filename; |
| 651 params.extensions_install_dir = extensions_install_dir; | 651 params.extensions_install_dir = extensions_install_dir; |
| 652 return params; | 652 return params; |
| 653 } | 653 } |
| 654 | 654 |
| 655 class ExtensionServiceTest | 655 class ExtensionServiceTest |
| 656 : public ExtensionServiceTestBase, public content::NotificationObserver { | 656 : public ExtensionServiceTestBase, public content::NotificationObserver { |
| 657 public: | 657 public: |
| (...skipping 3617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4275 EXPECT_EQ(1U, origins.size()); | 4275 EXPECT_EQ(1U, origins.size()); |
| 4276 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); | 4276 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); |
| 4277 | 4277 |
| 4278 // Create local storage. We only simulate this by creating the backing files. | 4278 // Create local storage. We only simulate this by creating the backing files. |
| 4279 // Note: This test depends on details of how the dom_storage library | 4279 // Note: This test depends on details of how the dom_storage library |
| 4280 // stores data in the host file system. | 4280 // stores data in the host file system. |
| 4281 base::FilePath lso_dir_path = | 4281 base::FilePath lso_dir_path = |
| 4282 profile_->GetPath().AppendASCII("Local Storage"); | 4282 profile_->GetPath().AppendASCII("Local Storage"); |
| 4283 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) | 4283 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) |
| 4284 .AddExtension(FILE_PATH_LITERAL(".localstorage")); | 4284 .AddExtension(FILE_PATH_LITERAL(".localstorage")); |
| 4285 EXPECT_TRUE(file_util::CreateDirectory(lso_dir_path)); | 4285 EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); |
| 4286 EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); | 4286 EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); |
| 4287 EXPECT_TRUE(base::PathExists(lso_file_path)); | 4287 EXPECT_TRUE(base::PathExists(lso_file_path)); |
| 4288 | 4288 |
| 4289 // Create indexed db. Similarly, it is enough to only simulate this by | 4289 // Create indexed db. Similarly, it is enough to only simulate this by |
| 4290 // creating the directory on the disk. | 4290 // creating the directory on the disk. |
| 4291 IndexedDBContext* idb_context = | 4291 IndexedDBContext* idb_context = |
| 4292 BrowserContext::GetDefaultStoragePartition(profile_.get())-> | 4292 BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 4293 GetIndexedDBContext(); | 4293 GetIndexedDBContext(); |
| 4294 idb_context->SetTaskRunnerForTesting( | 4294 idb_context->SetTaskRunnerForTesting( |
| 4295 base::MessageLoop::current()->message_loop_proxy().get()); | 4295 base::MessageLoop::current()->message_loop_proxy().get()); |
| 4296 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); | 4296 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
| 4297 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); | 4297 EXPECT_TRUE(base::CreateDirectory(idb_path)); |
| 4298 EXPECT_TRUE(base::DirectoryExists(idb_path)); | 4298 EXPECT_TRUE(base::DirectoryExists(idb_path)); |
| 4299 | 4299 |
| 4300 // Uninstall the extension. | 4300 // Uninstall the extension. |
| 4301 service_->UninstallExtension(good_crx, false, NULL); | 4301 service_->UninstallExtension(good_crx, false, NULL); |
| 4302 base::RunLoop().RunUntilIdle(); | 4302 base::RunLoop().RunUntilIdle(); |
| 4303 | 4303 |
| 4304 // Check that the cookie is gone. | 4304 // Check that the cookie is gone. |
| 4305 cookie_monster->GetAllCookiesForURLAsync( | 4305 cookie_monster->GetAllCookiesForURLAsync( |
| 4306 ext_url, | 4306 ext_url, |
| 4307 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 4307 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4391 EXPECT_EQ(1U, origins.size()); | 4391 EXPECT_EQ(1U, origins.size()); |
| 4392 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); | 4392 EXPECT_EQ(origin_id, origins[0].GetOriginIdentifier()); |
| 4393 | 4393 |
| 4394 // Create local storage. We only simulate this by creating the backing files. | 4394 // Create local storage. We only simulate this by creating the backing files. |
| 4395 // Note: This test depends on details of how the dom_storage library | 4395 // Note: This test depends on details of how the dom_storage library |
| 4396 // stores data in the host file system. | 4396 // stores data in the host file system. |
| 4397 base::FilePath lso_dir_path = | 4397 base::FilePath lso_dir_path = |
| 4398 profile_->GetPath().AppendASCII("Local Storage"); | 4398 profile_->GetPath().AppendASCII("Local Storage"); |
| 4399 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) | 4399 base::FilePath lso_file_path = lso_dir_path.AppendASCII(origin_id) |
| 4400 .AddExtension(FILE_PATH_LITERAL(".localstorage")); | 4400 .AddExtension(FILE_PATH_LITERAL(".localstorage")); |
| 4401 EXPECT_TRUE(file_util::CreateDirectory(lso_dir_path)); | 4401 EXPECT_TRUE(base::CreateDirectory(lso_dir_path)); |
| 4402 EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); | 4402 EXPECT_EQ(0, file_util::WriteFile(lso_file_path, NULL, 0)); |
| 4403 EXPECT_TRUE(base::PathExists(lso_file_path)); | 4403 EXPECT_TRUE(base::PathExists(lso_file_path)); |
| 4404 | 4404 |
| 4405 // Create indexed db. Similarly, it is enough to only simulate this by | 4405 // Create indexed db. Similarly, it is enough to only simulate this by |
| 4406 // creating the directory on the disk. | 4406 // creating the directory on the disk. |
| 4407 IndexedDBContext* idb_context = | 4407 IndexedDBContext* idb_context = |
| 4408 BrowserContext::GetDefaultStoragePartition(profile_.get())-> | 4408 BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 4409 GetIndexedDBContext(); | 4409 GetIndexedDBContext(); |
| 4410 idb_context->SetTaskRunnerForTesting( | 4410 idb_context->SetTaskRunnerForTesting( |
| 4411 base::MessageLoop::current()->message_loop_proxy().get()); | 4411 base::MessageLoop::current()->message_loop_proxy().get()); |
| 4412 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); | 4412 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
| 4413 EXPECT_TRUE(file_util::CreateDirectory(idb_path)); | 4413 EXPECT_TRUE(base::CreateDirectory(idb_path)); |
| 4414 EXPECT_TRUE(base::DirectoryExists(idb_path)); | 4414 EXPECT_TRUE(base::DirectoryExists(idb_path)); |
| 4415 | 4415 |
| 4416 // Uninstall one of them, unlimited storage should still be granted | 4416 // Uninstall one of them, unlimited storage should still be granted |
| 4417 // to the origin. | 4417 // to the origin. |
| 4418 UninstallExtension(id1, false); | 4418 UninstallExtension(id1, false); |
| 4419 EXPECT_EQ(1u, service_->extensions()->size()); | 4419 EXPECT_EQ(1u, service_->extensions()->size()); |
| 4420 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 4420 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 4421 IsStorageUnlimited(origin1)); | 4421 IsStorageUnlimited(origin1)); |
| 4422 | 4422 |
| 4423 // Check that the cookie is still there. | 4423 // Check that the cookie is still there. |
| (...skipping 2334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6758 service_->ReconcileKnownDisabled(); | 6758 service_->ReconcileKnownDisabled(); |
| 6759 expected_extensions.insert(good2); | 6759 expected_extensions.insert(good2); |
| 6760 expected_disabled_extensions.erase(good2); | 6760 expected_disabled_extensions.erase(good2); |
| 6761 | 6761 |
| 6762 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); | 6762 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); |
| 6763 EXPECT_EQ(expected_disabled_extensions, | 6763 EXPECT_EQ(expected_disabled_extensions, |
| 6764 service_->disabled_extensions()->GetIDs()); | 6764 service_->disabled_extensions()->GetIDs()); |
| 6765 } | 6765 } |
| 6766 | 6766 |
| 6767 #endif // #if !(defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS)) | 6767 #endif // #if !(defined(OS_LINUX) && defined(USE_AURA) && !defined(OS_CHROMEOS)) |
| OLD | NEW |