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

Unified Diff: content/browser/appcache/chrome_appcache_service_unittest.cc

Issue 7210006: AppCaches which belong to hosted apps are not protected from deletion (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Moving test helpers to webkit/appcache. Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/appcache/chrome_appcache_service.cc ('k') | webkit/appcache/appcache_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/appcache/chrome_appcache_service_unittest.cc
diff --git a/content/browser/appcache/chrome_appcache_service_unittest.cc b/content/browser/appcache/chrome_appcache_service_unittest.cc
index 7f99286c83e963e1c3ccddd812d54acd42855c65..da9451a6587be5e87ecfcf01a8a9889f747a9608 100644
--- a/content/browser/appcache/chrome_appcache_service_unittest.cc
+++ b/content/browser/appcache/chrome_appcache_service_unittest.cc
@@ -11,12 +11,23 @@
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/appcache/appcache_database.h"
#include "webkit/appcache/appcache_storage_impl.h"
+#include "webkit/appcache/appcache_test_helper.h"
+#include "webkit/quota/mock_special_storage_policy.h"
+
+#include <set>
namespace {
const FilePath::CharType kTestingAppCacheDirname[] =
FILE_PATH_LITERAL("Application Cache");
-}
+
+// Examples of a protected and an unprotected origin, to be used througout the
+// test.
+const char kProtectedManifest[] = "http://www.protected.com/cache.manifest";
+const char kNormalManifest[] = "http://www.normal.com/cache.manifest";
+
+} // namespace
namespace appcache {
@@ -24,6 +35,8 @@ class ChromeAppCacheServiceTest : public TestingBrowserProcessTest {
public:
ChromeAppCacheServiceTest()
: message_loop_(MessageLoop::TYPE_IO),
+ kProtectedManifestURL(kProtectedManifest),
+ kNormalManifestURL(kNormalManifest),
db_thread_(BrowserThread::DB, &message_loop_),
file_thread_(BrowserThread::FILE, &message_loop_),
cache_thread_(BrowserThread::CACHE, &message_loop_),
@@ -31,8 +44,15 @@ class ChromeAppCacheServiceTest : public TestingBrowserProcessTest {
}
protected:
+ scoped_refptr<ChromeAppCacheService> CreateAppCacheService(
+ const FilePath& appcache_path,
+ bool init_storage);
+ void InsertDataIntoAppCache(ChromeAppCacheService* appcache_service);
+
MessageLoop message_loop_;
ScopedTempDir temp_dir_;
+ const GURL kProtectedManifestURL;
+ const GURL kNormalManifestURL;
private:
BrowserThread db_thread_;
@@ -41,68 +61,111 @@ class ChromeAppCacheServiceTest : public TestingBrowserProcessTest {
BrowserThread io_thread_;
};
-TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) {
- ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
- FilePath appcache_path = temp_dir_.path().Append(kTestingAppCacheDirname);
+scoped_refptr<ChromeAppCacheService>
+ChromeAppCacheServiceTest::CreateAppCacheService(
+ const FilePath& appcache_path,
+ bool init_storage) {
scoped_refptr<ChromeAppCacheService> appcache_service =
new ChromeAppCacheService(NULL);
const content::ResourceContext* resource_context = NULL;
+ scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy =
+ new quota::MockSpecialStoragePolicy;
+ mock_policy->AddProtected(kProtectedManifestURL.GetOrigin());
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(appcache_service.get(),
&ChromeAppCacheService::InitializeOnIOThread,
appcache_path,
resource_context,
- scoped_refptr<quota::SpecialStoragePolicy>(NULL),
- false));
- // Make the steps needed to initialize the storage of AppCache data.
- message_loop_.RunAllPending();
- appcache::AppCacheStorageImpl* storage =
- static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage());
- ASSERT_TRUE(storage->database_->db_connection());
- ASSERT_EQ(1, storage->NewCacheId());
- storage->disk_cache();
+ mock_policy));
+ // Steps needed to initialize the storage of AppCache data.
message_loop_.RunAllPending();
+ if (init_storage) {
+ appcache::AppCacheStorageImpl* storage =
+ static_cast<appcache::AppCacheStorageImpl*>(
+ appcache_service->storage());
+ storage->database_->db_connection();
+ storage->disk_cache();
+ message_loop_.RunAllPending();
+ }
+ return appcache_service;
+}
+
+void ChromeAppCacheServiceTest::InsertDataIntoAppCache(
+ ChromeAppCacheService* appcache_service) {
+ AppCacheTestHelper appcache_helper;
+ appcache_helper.AddGroupAndCache(appcache_service, kNormalManifestURL);
+ appcache_helper.AddGroupAndCache(appcache_service, kProtectedManifestURL);
+
+ // Verify that adding the data succeeded
+ std::set<GURL> origins;
+ appcache_helper.GetOriginsWithCaches(appcache_service, &origins);
+ ASSERT_EQ(2UL, origins.size());
+ ASSERT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end());
+ ASSERT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end());
+}
+
+TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath appcache_path = temp_dir_.path().Append(kTestingAppCacheDirname);
+ // Create a ChromeAppCacheService and insert data into it
+ scoped_refptr<ChromeAppCacheService> appcache_service =
+ CreateAppCacheService(appcache_path, true);
ASSERT_TRUE(file_util::PathExists(appcache_path));
ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index")));
+ InsertDataIntoAppCache(appcache_service);
+ // Test: delete the ChromeAppCacheService
+ appcache_service->set_clear_local_state_on_exit(false);
appcache_service = NULL;
message_loop_.RunAllPending();
+ // Recreate the appcache (for reading the data back)
+ appcache_service = CreateAppCacheService(appcache_path, false);
+
+ // The directory is still there
ASSERT_TRUE(file_util::PathExists(appcache_path));
+
+ // The appcache data is also there
+ AppCacheTestHelper appcache_helper;
+ std::set<GURL> origins;
+ appcache_helper.GetOriginsWithCaches(appcache_service, &origins);
+ EXPECT_EQ(2UL, origins.size());
+ EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end());
+ EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end());
}
TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
FilePath appcache_path = temp_dir_.path().Append(kTestingAppCacheDirname);
- scoped_refptr<ChromeAppCacheService> appcache_service =
- new ChromeAppCacheService(NULL);
- const content::ResourceContext* resource_context = NULL;
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(appcache_service.get(),
- &ChromeAppCacheService::InitializeOnIOThread,
- appcache_path,
- resource_context,
- scoped_refptr<quota::SpecialStoragePolicy>(NULL),
- true));
- // Make the steps needed to initialize the storage of AppCache data.
- message_loop_.RunAllPending();
- appcache::AppCacheStorageImpl* storage =
- static_cast<appcache::AppCacheStorageImpl*>(appcache_service->storage());
- ASSERT_TRUE(storage->database_->db_connection());
- ASSERT_EQ(1, storage->NewCacheId());
- storage->disk_cache();
- message_loop_.RunAllPending();
+ // Create a ChromeAppCacheService and insert data into it
+ scoped_refptr<ChromeAppCacheService> appcache_service =
+ CreateAppCacheService(appcache_path, true);
ASSERT_TRUE(file_util::PathExists(appcache_path));
ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index")));
+ InsertDataIntoAppCache(appcache_service);
+ // Test: delete the ChromeAppCacheService
+ appcache_service->set_clear_local_state_on_exit(true);
appcache_service = NULL;
message_loop_.RunAllPending();
- ASSERT_FALSE(file_util::PathExists(appcache_path));
+ // Recreate the appcache (for reading the data back)
+ appcache_service = CreateAppCacheService(appcache_path, false);
+
+ // The directory is still there
+ ASSERT_TRUE(file_util::PathExists(appcache_path));
+
+ // The appcache data for the protected origin is there, and the data for the
+ // unprotected origin was deleted.
+ AppCacheTestHelper appcache_helper;
+ std::set<GURL> origins;
+ appcache_helper.GetOriginsWithCaches(appcache_service, &origins);
+ EXPECT_EQ(1UL, origins.size());
+ EXPECT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end());
+ EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) == origins.end());
}
} // namespace appcache
« no previous file with comments | « content/browser/appcache/chrome_appcache_service.cc ('k') | webkit/appcache/appcache_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698