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

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

Issue 15659013: Revert "Migrate the IndexedDB backend from Blink to Chromium" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "content/browser/browser_thread_impl.h" 7 #include "content/browser/browser_thread_impl.h"
8 #include "content/browser/indexed_db/indexed_db_context_impl.h" 8 #include "content/browser/indexed_db/indexed_db_context_impl.h"
9 #include "content/public/browser/storage_partition.h" 9 #include "content/public/browser/storage_partition.h"
10 #include "content/public/common/url_constants.h" 10 #include "content/public/common/url_constants.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 TestBrowserContext browser_context; 48 TestBrowserContext browser_context;
49 49
50 const GURL kNormalOrigin("http://normal/"); 50 const GURL kNormalOrigin("http://normal/");
51 const GURL kSessionOnlyOrigin("http://session-only/"); 51 const GURL kSessionOnlyOrigin("http://session-only/");
52 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 52 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
53 new quota::MockSpecialStoragePolicy; 53 new quota::MockSpecialStoragePolicy;
54 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); 54 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin);
55 55
56 // Create some indexedDB paths. 56 // Create some indexedDB paths.
57 // With the levelDB backend, these are directories. 57 // With the levelDB backend, these are directories.
58 IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>( 58 IndexedDBContextImpl* idb_context =
59 BrowserContext::GetDefaultStoragePartition(&browser_context) 59 static_cast<IndexedDBContextImpl*>(
60 ->GetIndexedDBContext()); 60 BrowserContext::GetDefaultStoragePartition(&browser_context)->
61 GetIndexedDBContext());
61 62
62 // Override the storage policy with our own. 63 // Override the storage policy with our own.
63 idb_context->special_storage_policy_ = special_storage_policy; 64 idb_context->special_storage_policy_ = special_storage_policy;
64 idb_context->set_data_path_for_testing(temp_dir.path()); 65 idb_context->set_data_path_for_testing(temp_dir.path());
65 66
66 normal_path = idb_context->GetFilePathForTesting( 67 normal_path = idb_context->GetFilePathForTesting(
67 webkit_base::GetOriginIdentifierFromURL(kNormalOrigin)); 68 webkit_base::GetOriginIdentifierFromURL(kNormalOrigin));
68 session_only_path = idb_context->GetFilePathForTesting( 69 session_only_path = idb_context->GetFilePathForTesting(
69 webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin)); 70 webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin));
70 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); 71 ASSERT_TRUE(file_util::CreateDirectory(normal_path));
(...skipping 20 matching lines...) Expand all
91 TestBrowserContext browser_context; 92 TestBrowserContext browser_context;
92 93
93 const GURL kNormalOrigin("http://normal/"); 94 const GURL kNormalOrigin("http://normal/");
94 const GURL kSessionOnlyOrigin("http://session-only/"); 95 const GURL kSessionOnlyOrigin("http://session-only/");
95 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 96 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
96 new quota::MockSpecialStoragePolicy; 97 new quota::MockSpecialStoragePolicy;
97 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); 98 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin);
98 99
99 // Create some indexedDB paths. 100 // Create some indexedDB paths.
100 // With the levelDB backend, these are directories. 101 // With the levelDB backend, these are directories.
101 IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>( 102 IndexedDBContextImpl* idb_context =
102 BrowserContext::GetDefaultStoragePartition(&browser_context) 103 static_cast<IndexedDBContextImpl*>(
103 ->GetIndexedDBContext()); 104 BrowserContext::GetDefaultStoragePartition(&browser_context)->
105 GetIndexedDBContext());
104 106
105 // Override the storage policy with our own. 107 // Override the storage policy with our own.
106 idb_context->special_storage_policy_ = special_storage_policy; 108 idb_context->special_storage_policy_ = special_storage_policy;
107 idb_context->set_data_path_for_testing(temp_dir.path()); 109 idb_context->set_data_path_for_testing(temp_dir.path());
108 110
109 // Save session state. This should bypass the destruction-time deletion. 111 // Save session state. This should bypass the destruction-time deletion.
110 idb_context->SetForceKeepSessionState(); 112 idb_context->SetForceKeepSessionState();
111 113
112 normal_path = idb_context->GetFilePathForTesting( 114 normal_path = idb_context->GetFilePathForTesting(
113 webkit_base::GetOriginIdentifierFromURL(kNormalOrigin)); 115 webkit_base::GetOriginIdentifierFromURL(kNormalOrigin));
114 session_only_path = idb_context->GetFilePathForTesting( 116 session_only_path = idb_context->GetFilePathForTesting(
115 webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin)); 117 webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin));
116 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); 118 ASSERT_TRUE(file_util::CreateDirectory(normal_path));
117 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); 119 ASSERT_TRUE(file_util::CreateDirectory(session_only_path));
118 message_loop_.RunUntilIdle(); 120 message_loop_.RunUntilIdle();
119 } 121 }
120 122
121 // Make sure we wait until the destructor has run. 123 // Make sure we wait until the destructor has run.
122 message_loop_.RunUntilIdle(); 124 message_loop_.RunUntilIdle();
123 125
124 // No data was cleared because of SetForceKeepSessionState. 126 // No data was cleared because of SetForceKeepSessionState.
125 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); 127 EXPECT_TRUE(file_util::DirectoryExists(normal_path));
126 EXPECT_TRUE(file_util::DirectoryExists(session_only_path)); 128 EXPECT_TRUE(file_util::DirectoryExists(session_only_path));
127 } 129 }
128 130
129 class MockWebIDBDatabase : public WebKit::WebIDBDatabase { 131 class MockWebIDBDatabase : public WebKit::WebIDBDatabase
132 {
130 public: 133 public:
131 MockWebIDBDatabase(bool expect_force_close) 134 MockWebIDBDatabase(bool expect_force_close)
132 : expect_force_close_(expect_force_close), force_close_called_(false) {} 135 : expect_force_close_(expect_force_close),
136 force_close_called_(false) {}
133 137
134 virtual ~MockWebIDBDatabase() { 138 virtual ~MockWebIDBDatabase()
139 {
135 EXPECT_TRUE(force_close_called_ == expect_force_close_); 140 EXPECT_TRUE(force_close_called_ == expect_force_close_);
136 } 141 }
137 142
138 virtual void forceClose() { 143 virtual void forceClose()
144 {
139 ASSERT_TRUE(expect_force_close_); 145 ASSERT_TRUE(expect_force_close_);
140 force_close_called_ = true; 146 force_close_called_ = true;
141 } 147 }
142 148
143 private: 149 private:
144 bool expect_force_close_; 150 bool expect_force_close_;
145 bool force_close_called_; 151 bool force_close_called_;
146 }; 152 };
147 153
154
148 TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) { 155 TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) {
149 base::ScopedTempDir temp_dir; 156 base::ScopedTempDir temp_dir;
150 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 157 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
151 158
152 base::FilePath test_path; 159 base::FilePath test_path;
153 160
154 // Create the scope which will ensure we run the destructor of the webkit 161 // Create the scope which will ensure we run the destructor of the webkit
155 // context. 162 // context.
156 { 163 {
157 TestBrowserContext browser_context; 164 TestBrowserContext browser_context;
158 165
159 const GURL kTestOrigin("http://test/"); 166 const GURL kTestOrigin("http://test/");
160 167
161 IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>( 168 IndexedDBContextImpl* idb_context =
162 BrowserContext::GetDefaultStoragePartition(&browser_context) 169 static_cast<IndexedDBContextImpl*>(
163 ->GetIndexedDBContext()); 170 BrowserContext::GetDefaultStoragePartition(&browser_context)->
171 GetIndexedDBContext());
164 172
165 idb_context->quota_manager_proxy_ = NULL; 173 idb_context->quota_manager_proxy_ = NULL;
166 idb_context->set_data_path_for_testing(temp_dir.path()); 174 idb_context->set_data_path_for_testing(temp_dir.path());
167 175
168 test_path = idb_context->GetFilePathForTesting( 176 test_path = idb_context->GetFilePathForTesting(
169 webkit_base::GetOriginIdentifierFromURL(kTestOrigin)); 177 webkit_base::GetOriginIdentifierFromURL(kTestOrigin));
170 ASSERT_TRUE(file_util::CreateDirectory(test_path)); 178 ASSERT_TRUE(file_util::CreateDirectory(test_path));
171 179
172 const bool kExpectForceClose = true; 180 const bool kExpectForceClose = true;
173 181
174 MockWebIDBDatabase connection1(kExpectForceClose); 182 MockWebIDBDatabase connection1(kExpectForceClose);
175 idb_context->ConnectionOpened(kTestOrigin, &connection1); 183 idb_context->ConnectionOpened(kTestOrigin, &connection1);
176 184
177 MockWebIDBDatabase connection2(!kExpectForceClose); 185 MockWebIDBDatabase connection2(!kExpectForceClose);
178 idb_context->ConnectionOpened(kTestOrigin, &connection2); 186 idb_context->ConnectionOpened(kTestOrigin, &connection2);
179 idb_context->ConnectionClosed(kTestOrigin, &connection2); 187 idb_context->ConnectionClosed(kTestOrigin, &connection2);
180 188
181 idb_context->DeleteForOrigin(kTestOrigin); 189 idb_context->DeleteForOrigin(kTestOrigin);
182 190
183 message_loop_.RunUntilIdle(); 191 message_loop_.RunUntilIdle();
184 } 192 }
185 193
186 // Make sure we wait until the destructor has run. 194 // Make sure we wait until the destructor has run.
187 message_loop_.RunUntilIdle(); 195 message_loop_.RunUntilIdle();
188 196
189 EXPECT_FALSE(file_util::DirectoryExists(test_path)); 197 EXPECT_FALSE(file_util::DirectoryExists(test_path));
190 } 198 }
191 199
192 } // namespace content 200 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_transaction_coordinator.cc ('k') | content/browser/indexed_db/leveldb/avltree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698