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

Unified Diff: content/browser/indexed_db/indexed_db_database_unittest.cc

Issue 308103004: IndexedDB: Using a mock IndexedDBFactory for unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Forgot to add mock_indexed_db_factory.* files in last patch set. Created 6 years, 6 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/indexed_db/indexed_db_database.cc ('k') | content/browser/indexed_db/indexed_db_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/indexed_db/indexed_db_database_unittest.cc
diff --git a/content/browser/indexed_db/indexed_db_database_unittest.cc b/content/browser/indexed_db/indexed_db_database_unittest.cc
index 307cf5144444160be7458114faa91d1d4598713f..32320b81fb51e4b5c13f57bc127e39e6a186c9bf 100644
--- a/content/browser/indexed_db/indexed_db_database_unittest.cc
+++ b/content/browser/indexed_db/indexed_db_database_unittest.cc
@@ -21,13 +21,79 @@
#include "content/browser/indexed_db/indexed_db_value.h"
#include "content/browser/indexed_db/mock_indexed_db_callbacks.h"
#include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::ASCIIToUTF16;
namespace {
const int kFakeChildProcessId = 0;
-}
+
+class MockIDBFactory : public content::IndexedDBFactory {
+ public:
+ MOCK_METHOD2(ReleaseDatabase,
+ void(const content::IndexedDBDatabase::Identifier& identifier,
+ bool forcedClose));
+ MOCK_METHOD4(GetDatabaseNames,
+ void(scoped_refptr<content::IndexedDBCallbacks> callbacks,
+ const GURL& origin_url,
+ const base::FilePath& data_directory,
+ net::URLRequestContext* request_context));
+ MOCK_METHOD5(Open,
+ void(const base::string16& name,
+ const content::IndexedDBPendingConnection& connection,
+ net::URLRequestContext* request_context,
+ const GURL& origin_url,
+ const base::FilePath& data_directory));
+ MOCK_METHOD5(DeleteDatabase,
+ void(const base::string16& name,
+ net::URLRequestContext* request_context,
+ scoped_refptr<content::IndexedDBCallbacks> callbacks,
+ const GURL& origin_url,
+ const base::FilePath& data_directory));
+ MOCK_METHOD1(HandleBackingStoreFailure, void(const GURL& origin_url));
+ MOCK_METHOD2(HandleBackingStoreCorruption,
+ void(const GURL& origin_url,
+ const content::IndexedDBDatabaseError& error));
+ // mock template gets confused and needs typedef to compile.
+ typedef std::pair<OriginDBMapIterator, OriginDBMapIterator> OriginDBs;
+ MOCK_CONST_METHOD1(GetOpenDatabasesForOrigin,
+ OriginDBs(const GURL& origin_url));
+ MOCK_METHOD1(ForceClose, void(const GURL& origin_url));
+ MOCK_METHOD0(ContextDestroyed, void());
+ MOCK_METHOD1(DatabaseDeleted,
+ void(const content::IndexedDBDatabase::Identifier& identifier));
+ MOCK_CONST_METHOD1(GetConnectionCount, size_t(const GURL& origin_url));
+ MOCK_METHOD2(ReportOutstandingBlobs,
+ void(const GURL& origin_url, bool blobs_outstanding));
+
+ protected:
+ virtual ~MockIDBFactory() {}
+
+ MOCK_METHOD6(OpenBackingStore,
+ scoped_refptr<content::IndexedDBBackingStore>(
+ const GURL& origin_url,
+ const base::FilePath& data_directory,
+ net::URLRequestContext* request_context,
+ blink::WebIDBDataLoss* data_loss,
+ std::string* data_loss_reason,
+ bool* disk_full));
+
+ MOCK_METHOD7(OpenBackingStoreHelper,
+ scoped_refptr<content::IndexedDBBackingStore>(
+ const GURL& origin_url,
+ const base::FilePath& data_directory,
+ net::URLRequestContext* request_context,
+ blink::WebIDBDataLoss* data_loss,
+ std::string* data_loss_message,
+ bool* disk_full,
+ bool first_time));
+
+ private:
+ MOCK_CONST_METHOD1(IsBackingStoreOpen, bool(const GURL& origin_url));
+};
+
+} // anonymous namespace
namespace content {
@@ -36,7 +102,7 @@ TEST(IndexedDBDatabaseTest, BackingStoreRetention) {
new IndexedDBFakeBackingStore();
EXPECT_TRUE(backing_store->HasOneRef());
- IndexedDBFactory* factory = 0;
+ scoped_refptr<MockIDBFactory> factory = new MockIDBFactory();
leveldb::Status s;
scoped_refptr<IndexedDBDatabase> db =
IndexedDBDatabase::Create(ASCIIToUTF16("db"),
@@ -55,7 +121,7 @@ TEST(IndexedDBDatabaseTest, ConnectionLifecycle) {
new IndexedDBFakeBackingStore();
EXPECT_TRUE(backing_store->HasOneRef()); // local
- IndexedDBFactory* factory = 0;
+ scoped_refptr<MockIDBFactory> factory = new MockIDBFactory();
leveldb::Status s;
scoped_refptr<IndexedDBDatabase> db =
IndexedDBDatabase::Create(ASCIIToUTF16("db"),
@@ -113,7 +179,7 @@ TEST(IndexedDBDatabaseTest, ForcedClose) {
new IndexedDBFakeBackingStore();
EXPECT_TRUE(backing_store->HasOneRef());
- IndexedDBFactory* factory = 0;
+ scoped_refptr<MockIDBFactory> factory = new MockIDBFactory();
leveldb::Status s;
scoped_refptr<IndexedDBDatabase> database =
IndexedDBDatabase::Create(ASCIIToUTF16("db"),
@@ -179,7 +245,7 @@ TEST(IndexedDBDatabaseTest, PendingDelete) {
new IndexedDBFakeBackingStore();
EXPECT_TRUE(backing_store->HasOneRef()); // local
- IndexedDBFactory* factory = 0;
+ scoped_refptr<MockIDBFactory> factory = new MockIDBFactory();
leveldb::Status s;
scoped_refptr<IndexedDBDatabase> db =
IndexedDBDatabase::Create(ASCIIToUTF16("db"),
@@ -222,14 +288,16 @@ void DummyOperation(IndexedDBTransaction* transaction) {
class IndexedDBDatabaseOperationTest : public testing::Test {
public:
- IndexedDBDatabaseOperationTest() : commit_success_(leveldb::Status::OK()) {}
+ IndexedDBDatabaseOperationTest()
+ : commit_success_(leveldb::Status::OK()),
+ factory_(new MockIDBFactory()) {}
virtual void SetUp() {
backing_store_ = new IndexedDBFakeBackingStore();
leveldb::Status s;
db_ = IndexedDBDatabase::Create(ASCIIToUTF16("db"),
backing_store_,
- NULL /*factory*/,
+ factory_,
IndexedDBDatabase::Identifier(),
&s);
ASSERT_TRUE(s.ok());
@@ -274,6 +342,7 @@ class IndexedDBDatabaseOperationTest : public testing::Test {
private:
base::MessageLoop message_loop_;
+ scoped_refptr<MockIDBFactory> factory_;
DISALLOW_COPY_AND_ASSIGN(IndexedDBDatabaseOperationTest);
};
« no previous file with comments | « content/browser/indexed_db/indexed_db_database.cc ('k') | content/browser/indexed_db/indexed_db_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698