| Index: content/browser/indexed_db/indexed_db_cleanup_on_io_error_unittest.cc
|
| diff --git a/content/browser/indexed_db/indexed_db_cleanup_on_io_error_unittest.cc b/content/browser/indexed_db/indexed_db_cleanup_on_io_error_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3a9ef35dbdfc4d96203665f832c565c0e6f0b6d8
|
| --- /dev/null
|
| +++ b/content/browser/indexed_db/indexed_db_cleanup_on_io_error_unittest.cc
|
| @@ -0,0 +1,72 @@
|
| +// Copyright (c) 2013 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.
|
| +
|
| +#include "base/files/scoped_temp_dir.h"
|
| +#include "base/string16.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "content/browser/indexed_db/indexed_db_backing_store.h"
|
| +#include "content/browser/indexed_db/leveldb/leveldb_database.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
|
| +
|
| +using WebKit::WebSecurityOrigin;
|
| +using content::IndexedDBBackingStore;
|
| +using content::LevelDBComparator;
|
| +using content::LevelDBDatabase;
|
| +using content::LevelDBFactory;
|
| +using content::LevelDBSlice;
|
| +using content::LevelDBSnapshot;
|
| +
|
| +namespace {
|
| +
|
| +class BustedLevelDBDatabase : public LevelDBDatabase {
|
| + public:
|
| + static scoped_ptr<LevelDBDatabase> Open(const string16& file_name,
|
| + const LevelDBComparator*) {
|
| + return scoped_ptr<LevelDBDatabase>(new BustedLevelDBDatabase);
|
| + }
|
| + virtual bool Get(const LevelDBSlice& key,
|
| + std::vector<char>& value,
|
| + bool& found,
|
| + const LevelDBSnapshot* = 0) OVERRIDE {
|
| + // false means IO error.
|
| + return false;
|
| + }
|
| +};
|
| +
|
| +class MockLevelDBFactory : public LevelDBFactory {
|
| + public:
|
| + MockLevelDBFactory() : destroy_called_(false) {}
|
| + virtual scoped_ptr<LevelDBDatabase> OpenLevelDB(
|
| + const string16& file_name,
|
| + const LevelDBComparator* comparator) OVERRIDE {
|
| + return BustedLevelDBDatabase::Open(file_name, comparator);
|
| + }
|
| + virtual bool DestroyLevelDB(const string16& file_name) OVERRIDE {
|
| + EXPECT_FALSE(destroy_called_);
|
| + destroy_called_ = true;
|
| + return false;
|
| + }
|
| + virtual ~MockLevelDBFactory() { EXPECT_TRUE(destroy_called_); }
|
| +
|
| + private:
|
| + bool destroy_called_;
|
| +};
|
| +
|
| +TEST(IndexedDBIOErrorTest, CleanUpTest) {
|
| + WebSecurityOrigin origin(
|
| + WebSecurityOrigin::createFromString("http://localhost:81"));
|
| + base::ScopedTempDir temp_directory;
|
| + DCHECK(temp_directory.CreateUniqueTempDir());
|
| + const base::FilePath path = temp_directory.path();
|
| + string16 dummy_file_identifier;
|
| + MockLevelDBFactory mock_leveldb_factory;
|
| + scoped_refptr<IndexedDBBackingStore> backing_store =
|
| + IndexedDBBackingStore::Open(origin.databaseIdentifier(),
|
| + UTF8ToUTF16(path.AsUTF8Unsafe()),
|
| + dummy_file_identifier,
|
| + &mock_leveldb_factory);
|
| +}
|
| +
|
| +} // namespace
|
|
|