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

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

Issue 10695158: IndexedDB: Close open databases when user requests browsing data deletion (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove const from iterator (not sure how this slipped through) Created 8 years, 3 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/scoped_temp_dir.h" 6 #include "base/scoped_temp_dir.h"
7 #include "content/browser/browser_thread_impl.h" 7 #include "content/browser/browser_thread_impl.h"
8 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" 8 #include "content/browser/in_process_webkit/indexed_db_context_impl.h"
9 #include "content/public/common/url_constants.h" 9 #include "content/public/common/url_constants.h"
10 #include "content/public/test/test_browser_context.h" 10 #include "content/public/test/test_browser_context.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h"
12 #include "webkit/database/database_util.h" 13 #include "webkit/database/database_util.h"
13 #include "webkit/quota/mock_special_storage_policy.h" 14 #include "webkit/quota/mock_special_storage_policy.h"
15 #include "webkit/quota/quota_manager.h"
14 #include "webkit/quota/special_storage_policy.h" 16 #include "webkit/quota/special_storage_policy.h"
15 17
16 using content::BrowserContext; 18 using content::BrowserContext;
17 using content::BrowserThread; 19 using content::BrowserThread;
18 using content::BrowserThreadImpl; 20 using content::BrowserThreadImpl;
19 using webkit_database::DatabaseUtil; 21 using webkit_database::DatabaseUtil;
20 22
21 class IndexedDBTest : public testing::Test { 23 class IndexedDBTest : public testing::Test {
22 public: 24 public:
23 IndexedDBTest() 25 IndexedDBTest()
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 message_loop_.RunAllPending(); 121 message_loop_.RunAllPending();
120 } 122 }
121 123
122 // Make sure we wait until the destructor has run. 124 // Make sure we wait until the destructor has run.
123 message_loop_.RunAllPending(); 125 message_loop_.RunAllPending();
124 126
125 // No data was cleared because of SetForceKeepSessionState. 127 // No data was cleared because of SetForceKeepSessionState.
126 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); 128 EXPECT_TRUE(file_util::DirectoryExists(normal_path));
127 EXPECT_TRUE(file_util::DirectoryExists(session_only_path)); 129 EXPECT_TRUE(file_util::DirectoryExists(session_only_path));
128 } 130 }
131
132 class MockWebIDBDatabase : public WebKit::WebIDBDatabase
133 {
134 public:
135 MockWebIDBDatabase(bool expect_force_close)
136 : expect_force_close_(expect_force_close),
137 force_close_called_(false) {}
138
139 ~MockWebIDBDatabase()
140 {
141 EXPECT_TRUE(force_close_called_ == expect_force_close_);
142 }
143
144 virtual void forceClose()
145 {
146 ASSERT_TRUE(expect_force_close_);
147 force_close_called_ = true;
148 }
149
150 private:
151 bool expect_force_close_;
152 bool force_close_called_;
153 };
154
155
156 TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) {
157 ScopedTempDir temp_dir;
158 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
159
160 FilePath test_path;
161
162 // Create the scope which will ensure we run the destructor of the webkit
163 // context.
164 {
165 content::TestBrowserContext browser_context;
166
167 const GURL kTestOrigin("http://test/");
168
169 IndexedDBContextImpl* idb_context =
170 static_cast<IndexedDBContextImpl*>(
171 BrowserContext::GetIndexedDBContext(&browser_context));
172
173 idb_context->quota_manager_proxy_ = NULL;
174 idb_context->set_data_path_for_testing(temp_dir.path());
175
176 test_path = idb_context->GetFilePathForTesting(
177 DatabaseUtil::GetOriginIdentifier(kTestOrigin));
178 ASSERT_TRUE(file_util::CreateDirectory(test_path));
179
180 const bool kExpectForceClose = true;
181
182 MockWebIDBDatabase connection1(kExpectForceClose);
183 idb_context->ConnectionOpened(kTestOrigin, &connection1);
184
185 MockWebIDBDatabase connection2(!kExpectForceClose);
186 idb_context->ConnectionOpened(kTestOrigin, &connection2);
187 idb_context->ConnectionClosed(kTestOrigin, &connection2);
188
189 idb_context->DeleteForOrigin(kTestOrigin);
190
191 message_loop_.RunAllPending();
192 }
193
194 // Make sure we wait until the destructor has run.
195 message_loop_.RunAllPending();
196
197 EXPECT_FALSE(file_util::DirectoryExists(test_path));
198 }
OLDNEW
« no previous file with comments | « content/browser/in_process_webkit/indexed_db_dispatcher_host.cc ('k') | content/common/indexed_db/indexed_db_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698