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

Side by Side Diff: content/browser/indexed_db/indexed_db_cleanup_on_io_error_unittest.cc

Issue 2773823002: Use a two-part data format version in IndexedDB metadata. (Closed)
Patch Set: jsbell, cmumford Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cerrno> 5 #include <cerrno>
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "content/browser/indexed_db/indexed_db_backing_store.h" 14 #include "content/browser/indexed_db/indexed_db_backing_store.h"
15 #include "content/browser/indexed_db/indexed_db_data_loss_info.h" 15 #include "content/browser/indexed_db/indexed_db_data_loss_info.h"
16 #include "content/browser/indexed_db/leveldb/leveldb_database.h" 16 #include "content/browser/indexed_db/leveldb/leveldb_database.h"
17 #include "content/browser/indexed_db/leveldb/mock_leveldb_factory.h" 17 #include "content/browser/indexed_db/leveldb/mock_leveldb_factory.h"
18 #include "content/common/indexed_db/indexed_db_data_format_version.h"
18 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/leveldatabase/env_chromium.h" 22 #include "third_party/leveldatabase/env_chromium.h"
22 23
23 using base::StringPiece; 24 using base::StringPiece;
24 using content::IndexedDBBackingStore; 25 using content::IndexedDBBackingStore;
26 using content::IndexedDBDataFormatVersion;
25 using content::LevelDBComparator; 27 using content::LevelDBComparator;
26 using content::LevelDBDatabase; 28 using content::LevelDBDatabase;
27 using content::LevelDBFactory; 29 using content::LevelDBFactory;
28 using content::LevelDBSnapshot; 30 using content::LevelDBSnapshot;
29 using testing::_; 31 using testing::_;
30 using testing::Exactly; 32 using testing::Exactly;
31 using testing::Invoke; 33 using testing::Invoke;
32 34
33 namespace base { 35 namespace base {
34 class TaskRunner; 36 class TaskRunner;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 100
99 EXPECT_CALL(mock_leveldb_factory, OpenLevelDB(_, _, _, _)).Times(Exactly(1)); 101 EXPECT_CALL(mock_leveldb_factory, OpenLevelDB(_, _, _, _)).Times(Exactly(1));
100 EXPECT_CALL(mock_leveldb_factory, DestroyLevelDB(_)).Times(Exactly(1)); 102 EXPECT_CALL(mock_leveldb_factory, DestroyLevelDB(_)).Times(Exactly(1));
101 content::IndexedDBDataLossInfo data_loss_info; 103 content::IndexedDBDataLossInfo data_loss_info;
102 bool disk_full = false; 104 bool disk_full = false;
103 base::SequencedTaskRunner* task_runner = NULL; 105 base::SequencedTaskRunner* task_runner = NULL;
104 bool clean_journal = false; 106 bool clean_journal = false;
105 leveldb::Status s; 107 leveldb::Status s;
106 scoped_refptr<IndexedDBBackingStore> backing_store = 108 scoped_refptr<IndexedDBBackingStore> backing_store =
107 IndexedDBBackingStore::Open( 109 IndexedDBBackingStore::Open(
108 factory, origin, path, request_context_getter, &data_loss_info, 110 factory, origin, path, IndexedDBDataFormatVersion(),
109 &disk_full, &mock_leveldb_factory, task_runner, clean_journal, &s); 111 request_context_getter, &data_loss_info, &disk_full,
112 &mock_leveldb_factory, task_runner, clean_journal, &s);
110 } 113 }
111 114
112 TEST(IndexedDBNonRecoverableIOErrorTest, NuancedCleanupTest) { 115 TEST(IndexedDBNonRecoverableIOErrorTest, NuancedCleanupTest) {
113 content::IndexedDBFactory* factory = NULL; 116 content::IndexedDBFactory* factory = NULL;
114 const url::Origin origin(GURL("http://localhost:81")); 117 const url::Origin origin(GURL("http://localhost:81"));
115 scoped_refptr<net::URLRequestContextGetter> request_context_getter; 118 scoped_refptr<net::URLRequestContextGetter> request_context_getter;
116 base::ScopedTempDir temp_directory; 119 base::ScopedTempDir temp_directory;
117 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 120 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
118 const base::FilePath path = temp_directory.GetPath(); 121 const base::FilePath path = temp_directory.GetPath();
119 content::IndexedDBDataLossInfo data_loss_info; 122 content::IndexedDBDataLossInfo data_loss_info;
(...skipping 10 matching lines...) Expand all
130 Invoke(&busted_factory, &BustedLevelDBFactory::DestroyLevelDB)); 133 Invoke(&busted_factory, &BustedLevelDBFactory::DestroyLevelDB));
131 134
132 EXPECT_CALL(mock_leveldb_factory, OpenLevelDB(_, _, _, _)).Times(Exactly(4)); 135 EXPECT_CALL(mock_leveldb_factory, OpenLevelDB(_, _, _, _)).Times(Exactly(4));
133 EXPECT_CALL(mock_leveldb_factory, DestroyLevelDB(_)).Times(Exactly(0)); 136 EXPECT_CALL(mock_leveldb_factory, DestroyLevelDB(_)).Times(Exactly(0));
134 137
135 busted_factory.SetOpenError(MakeIOError("some filename", "some message", 138 busted_factory.SetOpenError(MakeIOError("some filename", "some message",
136 leveldb_env::kNewLogger, 139 leveldb_env::kNewLogger,
137 base::File::FILE_ERROR_NO_SPACE)); 140 base::File::FILE_ERROR_NO_SPACE));
138 scoped_refptr<IndexedDBBackingStore> backing_store = 141 scoped_refptr<IndexedDBBackingStore> backing_store =
139 IndexedDBBackingStore::Open( 142 IndexedDBBackingStore::Open(
140 factory, origin, path, request_context_getter, &data_loss_info, 143 factory, origin, path, IndexedDBDataFormatVersion(),
141 &disk_full, &mock_leveldb_factory, task_runner, clean_journal, &s); 144 request_context_getter, &data_loss_info, &disk_full,
145 &mock_leveldb_factory, task_runner, clean_journal, &s);
142 ASSERT_TRUE(s.IsIOError()); 146 ASSERT_TRUE(s.IsIOError());
143 147
144 busted_factory.SetOpenError(MakeIOError("some filename", 148 busted_factory.SetOpenError(MakeIOError("some filename",
145 "some message", 149 "some message",
146 leveldb_env::kNewLogger, 150 leveldb_env::kNewLogger,
147 base::File::FILE_ERROR_NO_MEMORY)); 151 base::File::FILE_ERROR_NO_MEMORY));
148 scoped_refptr<IndexedDBBackingStore> backing_store2 = 152 scoped_refptr<IndexedDBBackingStore> backing_store2 =
149 IndexedDBBackingStore::Open( 153 IndexedDBBackingStore::Open(
150 factory, origin, path, request_context_getter, &data_loss_info, 154 factory, origin, path, IndexedDBDataFormatVersion(),
151 &disk_full, &mock_leveldb_factory, task_runner, clean_journal, &s); 155 request_context_getter, &data_loss_info, &disk_full,
156 &mock_leveldb_factory, task_runner, clean_journal, &s);
152 ASSERT_TRUE(s.IsIOError()); 157 ASSERT_TRUE(s.IsIOError());
153 158
154 busted_factory.SetOpenError(MakeIOError("some filename", "some message", 159 busted_factory.SetOpenError(MakeIOError("some filename", "some message",
155 leveldb_env::kNewLogger, 160 leveldb_env::kNewLogger,
156 base::File::FILE_ERROR_IO)); 161 base::File::FILE_ERROR_IO));
157 scoped_refptr<IndexedDBBackingStore> backing_store3 = 162 scoped_refptr<IndexedDBBackingStore> backing_store3 =
158 IndexedDBBackingStore::Open( 163 IndexedDBBackingStore::Open(
159 factory, origin, path, request_context_getter, &data_loss_info, 164 factory, origin, path, IndexedDBDataFormatVersion(),
160 &disk_full, &mock_leveldb_factory, task_runner, clean_journal, &s); 165 request_context_getter, &data_loss_info, &disk_full,
166 &mock_leveldb_factory, task_runner, clean_journal, &s);
161 ASSERT_TRUE(s.IsIOError()); 167 ASSERT_TRUE(s.IsIOError());
162 168
163 busted_factory.SetOpenError(MakeIOError("some filename", 169 busted_factory.SetOpenError(MakeIOError("some filename",
164 "some message", 170 "some message",
165 leveldb_env::kNewLogger, 171 leveldb_env::kNewLogger,
166 base::File::FILE_ERROR_FAILED)); 172 base::File::FILE_ERROR_FAILED));
167 scoped_refptr<IndexedDBBackingStore> backing_store4 = 173 scoped_refptr<IndexedDBBackingStore> backing_store4 =
168 IndexedDBBackingStore::Open( 174 IndexedDBBackingStore::Open(
169 factory, origin, path, request_context_getter, &data_loss_info, 175 factory, origin, path, IndexedDBDataFormatVersion(),
170 &disk_full, &mock_leveldb_factory, task_runner, clean_journal, &s); 176 request_context_getter, &data_loss_info, &disk_full,
177 &mock_leveldb_factory, task_runner, clean_journal, &s);
171 ASSERT_TRUE(s.IsIOError()); 178 ASSERT_TRUE(s.IsIOError());
172 } 179 }
173 180
174 } // namespace 181 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698