Commit d51f69bd authored by dgrogan@chromium.org's avatar dgrogan@chromium.org

IndexedDB browser test for migrating from leveldb schema v0 to v1.

It doesn't check that the integer version was actually added
to leveldb though, which is unfortunate.  It ensures that
opening a v0 database doesn't fail an assert, which is what
would happen if you opened an unmigrated database with code
that expects to find a stored integer version.

BUG=108223

Review URL: https://chromiumcodereview.appspot.com/10826159

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150458 0039d316-1c4b-4281-b951-d872f2087c98
parent 8f640511
......@@ -177,4 +177,42 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed,
SimpleTest(GetTestUrl("indexeddb", "database_callbacks_first.html"));
}
class IndexedDBBrowserTestWithVersion0Schema : public IndexedDBBrowserTest {
public:
virtual void SetUpOnMainThread() {
BrowserThread::PostTask(
BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
base::Bind(
&IndexedDBBrowserTestWithVersion0Schema::CopyLevelDBToProfile,
shell()));
scoped_refptr<base::ThreadTestHelper> helper(
new base::ThreadTestHelper(BrowserThread::GetMessageLoopProxyForThread(
BrowserThread::WEBKIT_DEPRECATED)));
ASSERT_TRUE(helper->Run());
}
static void CopyLevelDBToProfile(Shell* shell) {
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);
IndexedDBContext* context = BrowserContext::GetIndexedDBContext(
shell->web_contents()->GetBrowserContext());
IndexedDBContextImpl* context_impl =
static_cast<IndexedDBContextImpl*>(context);
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));
}
};
IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithVersion0Schema, MigrationTest) {
SimpleTest(GetTestUrl("indexeddb", "migration_test.html"));
}
} // namespace content
......@@ -52,6 +52,11 @@ function unexpectedErrorCallback()
fail('unexpectedErrorCallback');
}
function unexpectedBlockedCallback()
{
fail('unexpectedBlockedCallback');
}
function deleteAllObjectStores(db)
{
objectStoreNames = db.objectStoreNames;
......
<html>
<head>
<title>IndexedDB migration test</title>
<script type="text/javascript" src="common.js"></script>
<script type="text/javascript" src="migration_test.js"></script>
</head>
<body onLoad="test()">
<div id="status">Starting...</div>
</body>
</html>
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function test() {
request = webkitIndexedDB.open('open-close-version-test1');
request.onsuccess = openTest2;
request.onerror = unexpectedErrorCallback;
request.onblocked = unexpectedBlockedCallback;
}
function openTest2(event) {
db = event.target.result;
debug("Ensure that the existing leveldb files are used. If they are not, " +
"this script will create a new database that has no object stores");
shouldBe("db.objectStoreNames.length", "1");
shouldBeEqualToString("typeof db.version", "string");
request = webkitIndexedDB.open('open-close-version-test2');
request.onsuccess = done;
request.onerror = unexpectedErrorCallback;
request.onblocked = unexpectedBlockedCallback;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment