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

Unified Diff: content/browser/in_process_webkit/indexed_db_browsertest.cc

Issue 11196029: Test for destroying leveldb directory when we detect a schema downgrade (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix initializer Created 8 years, 1 month 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 | « no previous file | content/test/data/indexeddb/open_bad_db.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/in_process_webkit/indexed_db_browsertest.cc
diff --git a/content/browser/in_process_webkit/indexed_db_browsertest.cc b/content/browser/in_process_webkit/indexed_db_browsertest.cc
index afacd3fe7b5bdf207c8f96f72ee2a9e3894f076f..5d7d794f5348c324100799146681139c694cf17d 100644
--- a/content/browser/in_process_webkit/indexed_db_browsertest.cc
+++ b/content/browser/in_process_webkit/indexed_db_browsertest.cc
@@ -7,6 +7,7 @@
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/memory/ref_counted.h"
+#include "base/message_loop.h"
#include "base/process_util.h"
#include "base/test/thread_test_helper.h"
#include "base/utf_string_conversions.h"
@@ -68,6 +69,13 @@ class IndexedDBBrowserTest : public ContentBrowserTest {
NavigateToURL(shell, url);
EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
}
+
+ scoped_refptr<IndexedDBContext> GetContext() {
+ StoragePartition* partition =
+ BrowserContext::GetDefaultStoragePartition(
+ shell()->web_contents()->GetBrowserContext());
+ return partition->GetIndexedDBContext();
+ };
};
IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorTest) {
@@ -192,41 +200,73 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed,
SimpleTest(GetTestUrl("indexeddb", "database_callbacks_first.html"));
}
-class IndexedDBBrowserTestWithVersion0Schema : public IndexedDBBrowserTest {
+static void CopyLevelDBToProfile(Shell* shell,
+ scoped_refptr<IndexedDBContext> context,
+ const std::string& test_directory) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
+ FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb"));
+ FilePath test_data_dir =
+ GetTestFilePath("indexeddb", test_directory.c_str()).Append(leveldb_dir);
+ IndexedDBContextImpl* context_impl =
+ static_cast<IndexedDBContextImpl*>(context.get());
+ FilePath dest = context_impl->data_path().Append(leveldb_dir);
+ // If we don't create the destination directory first, the contents of the
+ // leveldb directory are copied directly into profile/IndexedDB instead of
+ // profile/IndexedDB/file__0.xxx/
+ ASSERT_TRUE(file_util::CreateDirectory(dest));
+ const bool kRecursive = true;
+ ASSERT_TRUE(file_util::CopyDirectory(test_data_dir,
+ context_impl->data_path(),
+ kRecursive));
+}
+
+class IndexedDBBrowserTestWithPreexistingLevelDB : public IndexedDBBrowserTest {
public:
+ IndexedDBBrowserTestWithPreexistingLevelDB() : disk_usage_(-1) { }
+
virtual void SetUpOnMainThread() {
- scoped_refptr<IndexedDBContext> context =
- BrowserContext::GetDefaultStoragePartition(
- shell()->web_contents()->GetBrowserContext())->
- GetIndexedDBContext();
+ scoped_refptr<IndexedDBContext> context = GetContext();
BrowserThread::PostTask(
BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
- base::Bind(
- &IndexedDBBrowserTestWithVersion0Schema::CopyLevelDBToProfile,
- shell(),
- context));
+ base::Bind(&CopyLevelDBToProfile, shell(), context,
+ EnclosingLevelDBDir()));
scoped_refptr<base::ThreadTestHelper> helper(
new base::ThreadTestHelper(BrowserThread::GetMessageLoopProxyForThread(
BrowserThread::WEBKIT_DEPRECATED)));
ASSERT_TRUE(helper->Run());
}
- static void CopyLevelDBToProfile(Shell* shell,
- scoped_refptr<IndexedDBContext> context) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb"));
- FilePath test_data_dir =
- GetTestFilePath("indexeddb", "migration_from_0").Append(leveldb_dir);
- IndexedDBContextImpl* context_impl =
- static_cast<IndexedDBContextImpl*>(context.get());
- FilePath dest = context_impl->data_path().Append(leveldb_dir);
- // If we don't create the destination directory first, the contents of the
- // leveldb directory are copied directly into profile/IndexedDB instead of
- // profile/IndexedDB/file__0.xxx/
- ASSERT_TRUE(file_util::CreateDirectory(dest));
- const bool kRecursive = true;
- ASSERT_TRUE(file_util::CopyDirectory(test_data_dir,
- context_impl->data_path(),
- kRecursive));
+
+ virtual std::string EnclosingLevelDBDir() = 0;
+
+ protected:
+ virtual int64 RequestDiskUsage() {
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
+ base::Bind(&IndexedDBContext::GetOriginDiskUsage, GetContext(),
+ GURL("file:///")), base::Bind(
+ &IndexedDBBrowserTestWithPreexistingLevelDB::DidGetDiskUsage,
+ this));
+ scoped_refptr<base::ThreadTestHelper> helper(
+ new base::ThreadTestHelper(BrowserThread::GetMessageLoopProxyForThread(
+ BrowserThread::WEBKIT_DEPRECATED)));
+ EXPECT_TRUE(helper->Run());
+ // Wait for DidGetDiskUsage to be called.
+ MessageLoop::current()->RunUntilIdle();
+ return disk_usage_;
+ }
+ private:
+ virtual void DidGetDiskUsage(int64 bytes) {
+ EXPECT_GT(bytes, 0);
+ disk_usage_ = bytes;
+ }
+
+ int64 disk_usage_;
+};
+
+class IndexedDBBrowserTestWithVersion0Schema : public
+ IndexedDBBrowserTestWithPreexistingLevelDB {
+ virtual std::string EnclosingLevelDBDir() {
+ return "migration_from_0";
}
};
@@ -234,6 +274,38 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithVersion0Schema, MigrationTest) {
SimpleTest(GetTestUrl("indexeddb", "migration_test.html"));
}
+class IndexedDBBrowserTestWithVersion123456Schema : public
+ IndexedDBBrowserTestWithPreexistingLevelDB {
+ virtual std::string EnclosingLevelDBDir() {
+ return "schema_version_123456";
+ }
+};
+
+IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithVersion123456Schema,
+ DestroyTest) {
+ int64 original_size = RequestDiskUsage();
+ EXPECT_GT(original_size, 0);
+ SimpleTest(GetTestUrl("indexeddb", "open_bad_db.html"));
+ int64 new_size = RequestDiskUsage();
+ EXPECT_NE(original_size, new_size);
+}
+
+class IndexedDBBrowserTestWithCorruptLevelDB : public
+ IndexedDBBrowserTestWithPreexistingLevelDB {
+ virtual std::string EnclosingLevelDBDir() {
+ return "corrupt_leveldb";
+ }
+};
+
+IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithCorruptLevelDB,
+ DestroyTest) {
+ int64 original_size = RequestDiskUsage();
+ EXPECT_GT(original_size, 0);
+ SimpleTest(GetTestUrl("indexeddb", "open_bad_db.html"));
+ int64 new_size = RequestDiskUsage();
+ EXPECT_NE(original_size, new_size);
+}
+
IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, LevelDBLogFileTest) {
// Any page that opens an IndexedDB will work here.
SimpleTest(GetTestUrl("indexeddb", "database_test.html"));
« no previous file with comments | « no previous file | content/test/data/indexeddb/open_bad_db.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698