diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 14:38:32 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 14:38:32 +0000 |
commit | c10da4b052a8ba91fc76455d3cc2e50e3bc2b08d (patch) | |
tree | 25fdd97cc5c3366ff50093088f7531f403f6c9b9 /chrome/browser/extensions/extensions_service_unittest.cc | |
parent | 11abcfcb82657d248355fa2f5215a29b3e41a9ae (diff) | |
download | chromium_src-c10da4b052a8ba91fc76455d3cc2e50e3bc2b08d.zip chromium_src-c10da4b052a8ba91fc76455d3cc2e50e3bc2b08d.tar.gz chromium_src-c10da4b052a8ba91fc76455d3cc2e50e3bc2b08d.tar.bz2 |
Reland r42467. Clear cookies, local storage and databases when an extension gets uninstalled.
BUG=27938,39177
TEST=Unittest in extension_service_unitttest.cc
Review URL: http://codereview.chromium.org/1257005
Patch from Mattias Nissler.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42611 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extensions_service_unittest.cc')
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 79 |
1 files changed, 75 insertions, 4 deletions
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index a142ca4..ff9a2b6 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -39,6 +39,8 @@ #include "testing/platform_test.h" #include "webkit/database/database_tracker.h" #include "webkit/database/database_util.h" +#include "net/base/cookie_monster.h" +#include "net/base/cookie_options.h" namespace keys = extension_manifest_keys; @@ -221,14 +223,17 @@ class ExtensionTestingProfile : public TestingProfile { ExtensionsServiceTestBase::ExtensionsServiceTestBase() : loop_(MessageLoop::TYPE_IO), ui_thread_(ChromeThread::UI, &loop_), - file_thread_(ChromeThread::FILE, &loop_) { + webkit_thread_(ChromeThread::WEBKIT, &loop_), + file_thread_(ChromeThread::FILE, &loop_), + io_thread_(ChromeThread::IO, &loop_) { } ExtensionsServiceTestBase::~ExtensionsServiceTestBase() { - // Drop our reference to ExtensionsService now, so that it can be destroyed - // while ChromeThreads and MessageLoop are still around (they are used - // in the ExtensionsService destruction process). + // Drop our reference to ExtensionsService and TestingProfile, so that they + // can be destroyed while ChromeThreads and MessageLoop are still around (they + // are used in the destruction process). service_ = NULL; + profile_.reset(NULL); MessageLoop::current()->RunAllPending(); } @@ -1260,6 +1265,72 @@ TEST_F(ExtensionsServiceTest, UninstallExtension) { EXPECT_FALSE(file_util::PathExists(extension_path)); } +// Verifies extension state is removed upon uninstall +TEST_F(ExtensionsServiceTest, ClearExtensionData) { + InitializeEmptyExtensionsService(); + + // Load a test extension. + FilePath path; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); + path = path.AppendASCII("extensions"); + path = path.AppendASCII("good.crx"); + InstallExtension(path, true); + Extension* extension = service_->GetExtensionById(good_crx, false); + ASSERT_TRUE(extension); + GURL ext_url(extension->url()); + string16 origin_id = + webkit_database::DatabaseUtil::GetOriginIdentifier(ext_url); + + // Set a cookie for the extension. + net::CookieMonster* cookie_monster = profile_ + ->GetRequestContextForExtensions()->GetCookieStore()->GetCookieMonster(); + ASSERT_TRUE(cookie_monster); + net::CookieOptions options; + cookie_monster->SetCookieWithOptions(ext_url, "dummy=value", options); + net::CookieMonster::CookieList list = + cookie_monster->GetAllCookiesForURL(ext_url); + EXPECT_EQ(1U, list.size()); + + // Open a database. + webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker(); + string16 db_name = UTF8ToUTF16("db"); + string16 description = UTF8ToUTF16("db_description"); + int64 size; + int64 available; + db_tracker->DatabaseOpened(origin_id, db_name, description, 1, &size, + &available); + db_tracker->DatabaseClosed(origin_id, db_name); + std::vector<webkit_database::OriginInfo> origins; + db_tracker->GetAllOriginsInfo(&origins); + EXPECT_EQ(1U, origins.size()); + EXPECT_EQ(origin_id, origins[0].GetOrigin()); + + // Create local storage. We only simulate this by creating the backing file + // since webkit is not initialized. + DOMStorageContext* context = + profile_->GetWebKitContext()->dom_storage_context(); + FilePath lso_path = context->GetLocalStorageFilePath(origin_id); + EXPECT_TRUE(file_util::CreateDirectory(lso_path.DirName())); + EXPECT_EQ(0, file_util::WriteFile(lso_path, NULL, 0)); + EXPECT_TRUE(file_util::PathExists(lso_path)); + + // Uninstall the extension. + service_->UninstallExtension(good_crx, false); + loop_.RunAllPending(); + + // Check that the cookie is gone. + list = cookie_monster->GetAllCookiesForURL(ext_url); + EXPECT_EQ(0U, list.size()); + + // The database should have vanished as well. + origins.clear(); + db_tracker->GetAllOriginsInfo(&origins); + EXPECT_EQ(0U, origins.size()); + + // Check that the LSO file has been removed. + EXPECT_FALSE(file_util::PathExists(lso_path)); +} + // Tests loading single extensions (like --load-extension) TEST_F(ExtensionsServiceTest, LoadExtension) { InitializeEmptyExtensionsService(); |